Mercurial > hg > CbC > CbC_llvm
comparison lld/MachO/LTO.cpp @ 223:5f17cb93ff66 llvm-original
LLVM13 (2021/7/18)
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 18 Jul 2021 22:43:00 +0900 |
parents | 79ff65ed7e25 |
children | c4bab56944e8 |
comparison
equal
deleted
inserted
replaced
222:81f6424ef0e3 | 223:5f17cb93ff66 |
---|---|
11 #include "Driver.h" | 11 #include "Driver.h" |
12 #include "InputFiles.h" | 12 #include "InputFiles.h" |
13 #include "Symbols.h" | 13 #include "Symbols.h" |
14 #include "Target.h" | 14 #include "Target.h" |
15 | 15 |
16 #include "lld/Common/Args.h" | |
16 #include "lld/Common/ErrorHandler.h" | 17 #include "lld/Common/ErrorHandler.h" |
17 #include "lld/Common/Strings.h" | 18 #include "lld/Common/Strings.h" |
18 #include "lld/Common/TargetOptionsCommandFlags.h" | 19 #include "lld/Common/TargetOptionsCommandFlags.h" |
20 #include "llvm/LTO/Caching.h" | |
21 #include "llvm/LTO/Config.h" | |
19 #include "llvm/LTO/LTO.h" | 22 #include "llvm/LTO/LTO.h" |
20 #include "llvm/Support/FileSystem.h" | 23 #include "llvm/Support/FileSystem.h" |
21 #include "llvm/Support/Path.h" | 24 #include "llvm/Support/Path.h" |
22 #include "llvm/Support/raw_ostream.h" | 25 #include "llvm/Support/raw_ostream.h" |
23 #include "llvm/Transforms/ObjCARC.h" | 26 #include "llvm/Transforms/ObjCARC.h" |
38 c.PreCodeGenPassesHook = [](legacy::PassManager &pm) { | 41 c.PreCodeGenPassesHook = [](legacy::PassManager &pm) { |
39 pm.add(createObjCARCContractPass()); | 42 pm.add(createObjCARCContractPass()); |
40 }; | 43 }; |
41 c.TimeTraceEnabled = config->timeTraceEnabled; | 44 c.TimeTraceEnabled = config->timeTraceEnabled; |
42 c.TimeTraceGranularity = config->timeTraceGranularity; | 45 c.TimeTraceGranularity = config->timeTraceGranularity; |
46 c.OptLevel = config->ltoo; | |
47 c.CGOptLevel = args::getCGOptLevel(config->ltoo); | |
43 if (config->saveTemps) | 48 if (config->saveTemps) |
44 checkError(c.addSaveTemps(config->outputFile.str() + ".", | 49 checkError(c.addSaveTemps(config->outputFile.str() + ".", |
45 /*UseInputModulePath=*/true)); | 50 /*UseInputModulePath=*/true)); |
46 return c; | 51 return c; |
47 } | 52 } |
71 // be removed. | 76 // be removed. |
72 r.Prevailing = !objSym.isUndefined() && sym->getFile() == &f; | 77 r.Prevailing = !objSym.isUndefined() && sym->getFile() == &f; |
73 | 78 |
74 // FIXME: What about other output types? And we can probably be less | 79 // FIXME: What about other output types? And we can probably be less |
75 // restrictive with -flat_namespace, but it's an infrequent use case. | 80 // restrictive with -flat_namespace, but it's an infrequent use case. |
81 // FIXME: Honor config->exportDynamic. | |
76 r.VisibleToRegularObj = config->outputType != MH_EXECUTE || | 82 r.VisibleToRegularObj = config->outputType != MH_EXECUTE || |
77 config->namespaceKind == NamespaceKind::flat || | 83 config->namespaceKind == NamespaceKind::flat || |
78 sym->isUsedInRegularObj; | 84 sym->isUsedInRegularObj; |
79 | 85 |
80 // Un-define the symbol so that we don't get duplicate symbol errors when we | 86 // Un-define the symbol so that we don't get duplicate symbol errors when we |
91 // Merge all the bitcode files we have seen, codegen the result | 97 // Merge all the bitcode files we have seen, codegen the result |
92 // and return the resulting ObjectFile(s). | 98 // and return the resulting ObjectFile(s). |
93 std::vector<ObjFile *> BitcodeCompiler::compile() { | 99 std::vector<ObjFile *> BitcodeCompiler::compile() { |
94 unsigned maxTasks = ltoObj->getMaxTasks(); | 100 unsigned maxTasks = ltoObj->getMaxTasks(); |
95 buf.resize(maxTasks); | 101 buf.resize(maxTasks); |
102 files.resize(maxTasks); | |
96 | 103 |
97 checkError(ltoObj->run([&](size_t task) { | 104 // The -cache_path_lto option specifies the path to a directory in which |
98 return std::make_unique<lto::NativeObjectStream>( | 105 // to cache native object files for ThinLTO incremental builds. If a path was |
99 std::make_unique<raw_svector_ostream>(buf[task])); | 106 // specified, configure LTO to use it as the cache directory. |
100 })); | 107 lto::NativeObjectCache cache; |
108 if (!config->thinLTOCacheDir.empty()) | |
109 cache = check( | |
110 lto::localCache(config->thinLTOCacheDir, | |
111 [&](size_t task, std::unique_ptr<MemoryBuffer> mb) { | |
112 files[task] = std::move(mb); | |
113 })); | |
114 | |
115 checkError(ltoObj->run( | |
116 [&](size_t task) { | |
117 return std::make_unique<lto::NativeObjectStream>( | |
118 std::make_unique<raw_svector_ostream>(buf[task])); | |
119 }, | |
120 cache)); | |
121 | |
122 if (!config->thinLTOCacheDir.empty()) | |
123 pruneCache(config->thinLTOCacheDir, config->thinLTOCachePolicy); | |
101 | 124 |
102 if (config->saveTemps) { | 125 if (config->saveTemps) { |
103 if (!buf[0].empty()) | 126 if (!buf[0].empty()) |
104 saveBuffer(buf[0], config->outputFile + ".lto.o"); | 127 saveBuffer(buf[0], config->outputFile + ".lto.o"); |
105 for (unsigned i = 1; i != maxTasks; ++i) | 128 for (unsigned i = 1; i != maxTasks; ++i) |
124 modTime = getModTime(filePath); | 147 modTime = getModTime(filePath); |
125 } | 148 } |
126 ret.push_back(make<ObjFile>( | 149 ret.push_back(make<ObjFile>( |
127 MemoryBufferRef(buf[i], saver.save(filePath.str())), modTime, "")); | 150 MemoryBufferRef(buf[i], saver.save(filePath.str())), modTime, "")); |
128 } | 151 } |
129 | 152 for (std::unique_ptr<MemoryBuffer> &file : files) |
153 if (file) | |
154 ret.push_back(make<ObjFile>(*file, 0, "")); | |
130 return ret; | 155 return ret; |
131 } | 156 } |