llvm.org GIT mirror llvm / b80c630
[ORC] Clone module flags metadata into the globals module in the CompileOnDemandLayer. Also contains a tweak to the orc-lazy jit in LLI to enable the test case. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280632 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 3 years ago
5 changed file(s) with 40 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
363363 assert(!EC && "Error generating stubs");
364364 }
365365
366 // If this module doesn't contain any globals or aliases we can bail out
367 // early and avoid the overhead of creating and managing an empty globals
368 // module.
369 if (SrcM.global_empty() && SrcM.alias_empty())
366 // If this module doesn't contain any globals, aliases, or module flags then
367 // we can bail out early and avoid the overhead of creating and managing an
368 // empty globals module.
369 if (SrcM.global_empty() && SrcM.alias_empty() &&
370 !SrcM.getModuleFlagsMetadata())
370371 return;
371372
372373 // Create the GlobalValues module.
385386 for (auto &A : SrcM.aliases())
386387 if (!VMap.count(&A))
387388 cloneGlobalAliasDecl(*GVsM, A, VMap);
389
390 // Clone the module flags.
391 cloneModuleFlagsMetadata(*GVsM, SrcM, VMap);
388392
389393 // Now we need to clone the GV and alias initializers.
390394
414414 GlobalAlias *cloneGlobalAliasDecl(Module &Dst, const GlobalAlias &OrigA,
415415 ValueToValueMapTy &VMap);
416416
417 /// @brief Clone module flags metadata into the destination module.
418 void cloneModuleFlagsMetadata(Module &Dst, const Module &Src,
419 ValueToValueMapTy &VMap);
420
417421 } // End namespace orc.
418422 } // End namespace llvm.
419423
240240 return NewA;
241241 }
242242
243 void cloneModuleFlagsMetadata(Module &Dst, const Module &Src,
244 ValueToValueMapTy &VMap) {
245 auto *MFs = Src.getModuleFlagsMetadata();
246 if (!MFs)
247 return;
248 for (auto *MF : MFs->operands())
249 Dst.addModuleFlag(MapMetadata(MF, VMap));
250 }
251
243252 } // End namespace orc.
244253 } // End namespace llvm.
0 ; RUN: lli -jit-kind=orc-lazy -orc-lazy-debug=mods-to-stdout %s | FileCheck %s
1 ;
2 ; CHECK: module-flags.ll.globals
3 ; CHECK-NOT: Module End
4 ; CHECK: The Answer is {{.*}}42
5
6 define i32 @main() {
7 ret i32 0
8 }
9
10 !llvm.module.flags = !{!0}
11
12 !0 = !{i32 1, !"The Answer is ", i32 42}
1717
1818 namespace {
1919
20 enum class DumpKind { NoDump, DumpFuncsToStdOut, DumpModsToStdErr,
20 enum class DumpKind { NoDump, DumpFuncsToStdOut, DumpModsToStdOut,
2121 DumpModsToDisk };
2222
2323 cl::opt OrcDumpKind("orc-lazy-debug",
2929 clEnumValN(DumpKind::DumpFuncsToStdOut,
3030 "funcs-to-stdout",
3131 "Dump function names to stdout."),
32 clEnumValN(DumpKind::DumpModsToStdErr,
33 "mods-to-stderr",
34 "Dump modules to stderr."),
32 clEnumValN(DumpKind::DumpModsToStdOut,
33 "mods-to-stdout",
34 "Dump modules to stdout."),
3535 clEnumValN(DumpKind::DumpModsToDisk,
3636 "mods-to-disk",
3737 "Dump modules to the current "
7070 return M;
7171 };
7272
73 case DumpKind::DumpModsToStdErr:
73 case DumpKind::DumpModsToStdOut:
7474 return [](std::unique_ptr M) {
75 dbgs() << "----- Module Start -----\n" << *M
75 outs() << "----- Module Start -----\n" << *M
7676 << "----- Module End -----\n";
7777
7878 return M;