[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
This commit is contained in:
Lang Hames 2016-09-04 17:53:30 +00:00
parent fa79defc96
commit b80c6300c5
5 changed files with 40 additions and 10 deletions

View File

@ -364,10 +364,11 @@ private:
assert(!EC && "Error generating stubs");
}
// If this module doesn't contain any globals or aliases we can bail out
// early and avoid the overhead of creating and managing an empty globals
// module.
if (SrcM.global_empty() && SrcM.alias_empty())
// If this module doesn't contain any globals, aliases, or module flags then
// we can bail out early and avoid the overhead of creating and managing an
// empty globals module.
if (SrcM.global_empty() && SrcM.alias_empty() &&
!SrcM.getModuleFlagsMetadata())
return;
// Create the GlobalValues module.
@ -387,6 +388,9 @@ private:
if (!VMap.count(&A))
cloneGlobalAliasDecl(*GVsM, A, VMap);
// Clone the module flags.
cloneModuleFlagsMetadata(*GVsM, SrcM, VMap);
// Now we need to clone the GV and alias initializers.
// Initializers may refer to functions declared (but not defined) in this

View File

@ -415,6 +415,10 @@ void moveGlobalVariableInitializer(GlobalVariable &OrigGV,
GlobalAlias *cloneGlobalAliasDecl(Module &Dst, const GlobalAlias &OrigA,
ValueToValueMapTy &VMap);
/// @brief Clone module flags metadata into the destination module.
void cloneModuleFlagsMetadata(Module &Dst, const Module &Src,
ValueToValueMapTy &VMap);
} // End namespace orc.
} // End namespace llvm.

View File

@ -241,5 +241,14 @@ GlobalAlias* cloneGlobalAliasDecl(Module &Dst, const GlobalAlias &OrigA,
return NewA;
}
void cloneModuleFlagsMetadata(Module &Dst, const Module &Src,
ValueToValueMapTy &VMap) {
auto *MFs = Src.getModuleFlagsMetadata();
if (!MFs)
return;
for (auto *MF : MFs->operands())
Dst.addModuleFlag(MapMetadata(MF, VMap));
}
} // End namespace orc.
} // End namespace llvm.

View File

@ -0,0 +1,13 @@
; RUN: lli -jit-kind=orc-lazy -orc-lazy-debug=mods-to-stdout %s | FileCheck %s
;
; CHECK: module-flags.ll.globals
; CHECK-NOT: Module End
; CHECK: The Answer is {{.*}}42
define i32 @main() {
ret i32 0
}
!llvm.module.flags = !{!0}
!0 = !{i32 1, !"The Answer is ", i32 42}

View File

@ -18,7 +18,7 @@ using namespace llvm;
namespace {
enum class DumpKind { NoDump, DumpFuncsToStdOut, DumpModsToStdErr,
enum class DumpKind { NoDump, DumpFuncsToStdOut, DumpModsToStdOut,
DumpModsToDisk };
cl::opt<DumpKind> OrcDumpKind("orc-lazy-debug",
@ -30,9 +30,9 @@ namespace {
clEnumValN(DumpKind::DumpFuncsToStdOut,
"funcs-to-stdout",
"Dump function names to stdout."),
clEnumValN(DumpKind::DumpModsToStdErr,
"mods-to-stderr",
"Dump modules to stderr."),
clEnumValN(DumpKind::DumpModsToStdOut,
"mods-to-stdout",
"Dump modules to stdout."),
clEnumValN(DumpKind::DumpModsToDisk,
"mods-to-disk",
"Dump modules to the current "
@ -71,9 +71,9 @@ OrcLazyJIT::TransformFtor OrcLazyJIT::createDebugDumper() {
return M;
};
case DumpKind::DumpModsToStdErr:
case DumpKind::DumpModsToStdOut:
return [](std::unique_ptr<Module> M) {
dbgs() << "----- Module Start -----\n" << *M
outs() << "----- Module Start -----\n" << *M
<< "----- Module End -----\n";
return M;