|
36 | 36 | #include "llvm/ADT/StringRef.h"
|
37 | 37 | #include "llvm/BinaryFormat/MachO.h"
|
38 | 38 | #include "llvm/BinaryFormat/Magic.h"
|
| 39 | +#include "llvm/CGData/CodeGenDataWriter.h" |
39 | 40 | #include "llvm/Config/llvm-config.h"
|
40 | 41 | #include "llvm/LTO/LTO.h"
|
41 | 42 | #include "llvm/Object/Archive.h"
|
@@ -1322,6 +1323,37 @@ static void gatherInputSections() {
|
1322 | 1323 | }
|
1323 | 1324 | }
|
1324 | 1325 |
|
| 1326 | +static void codegenDataGenerate() { |
| 1327 | + TimeTraceScope timeScope("Generating codegen data"); |
| 1328 | + |
| 1329 | + OutlinedHashTreeRecord globalOutlineRecord; |
| 1330 | + for (ConcatInputSection *isec : inputSections) |
| 1331 | + if (isec->getSegName() == segment_names::data && |
| 1332 | + isec->getName() == section_names::outlinedHashTree) { |
| 1333 | + // Read outlined hash tree from each section. |
| 1334 | + OutlinedHashTreeRecord localOutlineRecord; |
| 1335 | + auto *data = isec->data.data(); |
| 1336 | + localOutlineRecord.deserialize(data); |
| 1337 | + |
| 1338 | + // Merge it to the global hash tree. |
| 1339 | + globalOutlineRecord.merge(localOutlineRecord); |
| 1340 | + } |
| 1341 | + |
| 1342 | + CodeGenDataWriter Writer; |
| 1343 | + if (!globalOutlineRecord.empty()) |
| 1344 | + Writer.addRecord(globalOutlineRecord); |
| 1345 | + |
| 1346 | + std::error_code EC; |
| 1347 | + auto fileName = config->codegenDataGeneratePath; |
| 1348 | + assert(!fileName.empty()); |
| 1349 | + raw_fd_ostream Output(fileName, EC, sys::fs::OF_None); |
| 1350 | + if (EC) |
| 1351 | + error("fail to create " + fileName + ": " + EC.message()); |
| 1352 | + |
| 1353 | + if (auto E = Writer.write(Output)) |
| 1354 | + error("fail to write CGData: " + toString(std::move(E))); |
| 1355 | +} |
| 1356 | + |
1325 | 1357 | static void foldIdenticalLiterals() {
|
1326 | 1358 | TimeTraceScope timeScope("Fold identical literals");
|
1327 | 1359 | // We always create a cStringSection, regardless of whether dedupLiterals is
|
@@ -1759,6 +1791,8 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
|
1759 | 1791 | config->ignoreAutoLinkOptions.insert(arg->getValue());
|
1760 | 1792 | config->strictAutoLink = args.hasArg(OPT_strict_auto_link);
|
1761 | 1793 | config->ltoDebugPassManager = args.hasArg(OPT_lto_debug_pass_manager);
|
| 1794 | + config->codegenDataGeneratePath = |
| 1795 | + args.getLastArgValue(OPT_codegen_data_generate_path); |
1762 | 1796 | config->csProfileGenerate = args.hasArg(OPT_cs_profile_generate);
|
1763 | 1797 | config->csProfilePath = args.getLastArgValue(OPT_cs_profile_path);
|
1764 | 1798 | config->pgoWarnMismatch =
|
@@ -2103,6 +2137,10 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
|
2103 | 2137 | }
|
2104 | 2138 |
|
2105 | 2139 | gatherInputSections();
|
| 2140 | + |
| 2141 | + if (!config->codegenDataGeneratePath.empty()) |
| 2142 | + codegenDataGenerate(); |
| 2143 | + |
2106 | 2144 | if (config->callGraphProfileSort)
|
2107 | 2145 | priorityBuilder.extractCallGraphProfile();
|
2108 | 2146 |
|
|
0 commit comments