[llvm] r234707 - [Orc] During module partitioning, rename anonymous and asm-private globals.
Lang Hames
lhames at gmail.com
Sun Apr 12 13:05:51 PDT 2015
Author: lhames
Date: Sun Apr 12 15:05:51 2015
New Revision: 234707
URL: http://llvm.org/viewvc/llvm-project?rev=234707&view=rev
Log:
[Orc] During module partitioning, rename anonymous and asm-private globals.
If they're not (re)named, these globals will fail to resolve when the
partitioned modules are linked.
Added:
llvm/trunk/test/ExecutionEngine/OrcLazy/anonymous_globals.ll
Modified:
llvm/trunk/lib/ExecutionEngine/Orc/IndirectionUtils.cpp
Modified: llvm/trunk/lib/ExecutionEngine/Orc/IndirectionUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/IndirectionUtils.cpp?rev=234707&r1=234706&r2=234707&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/IndirectionUtils.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/IndirectionUtils.cpp Sun Apr 12 15:05:51 2015
@@ -14,6 +14,7 @@
#include "llvm/IR/CallSite.h"
#include "llvm/IR/IRBuilder.h"
#include <set>
+#include <sstream>
namespace llvm {
namespace orc {
@@ -51,32 +52,69 @@ void makeStub(Function &F, GlobalVariabl
Builder.CreateRet(Call);
}
+// Utility class for renaming global values and functions during partitioning.
+class GlobalRenamer {
+public:
+
+ static bool needsRenaming(const Value &New) {
+ if (!New.hasName() || New.getName().startswith("\01L"))
+ return true;
+ return false;
+ }
+
+ const std::string& getRename(const Value &Orig) {
+ // See if we have a name for this global.
+ {
+ auto I = Names.find(&Orig);
+ if (I != Names.end())
+ return I->second;
+ }
+
+ // Nope. Create a new one.
+ // FIXME: Use a more robust uniquing scheme. (This may blow up if the user
+ // writes a "__orc_anon[[:digit:]]* method).
+ unsigned ID = Names.size();
+ std::ostringstream NameStream;
+ NameStream << "__orc_anon" << ID++;
+ auto I = Names.insert(std::make_pair(&Orig, NameStream.str()));
+ return I.first->second;
+ }
+private:
+ DenseMap<const Value*, std::string> Names;
+};
+
void partition(Module &M, const ModulePartitionMap &PMap) {
+ GlobalRenamer Renamer;
+
for (auto &KVPair : PMap) {
auto ExtractGlobalVars =
[&](GlobalVariable &New, const GlobalVariable &Orig,
ValueToValueMapTy &VMap) {
- assert(Orig.hasName() && "Extracted globals must have names.");
if (KVPair.second.count(&Orig)) {
copyGVInitializer(New, Orig, VMap);
}
if (New.hasLocalLinkage()) {
+ if (Renamer.needsRenaming(New))
+ New.setName(Renamer.getRename(Orig));
New.setLinkage(GlobalValue::ExternalLinkage);
New.setVisibility(GlobalValue::HiddenVisibility);
}
+ assert(!Renamer.needsRenaming(New) && "Invalid global name.");
};
auto ExtractFunctions =
[&](Function &New, const Function &Orig, ValueToValueMapTy &VMap) {
- assert(Orig.hasName() && "Extracted functions must have names.");
if (KVPair.second.count(&Orig))
copyFunctionBody(New, Orig, VMap);
if (New.hasLocalLinkage()) {
+ if (Renamer.needsRenaming(New))
+ New.setName(Renamer.getRename(Orig));
New.setLinkage(GlobalValue::ExternalLinkage);
New.setVisibility(GlobalValue::HiddenVisibility);
}
+ assert(!Renamer.needsRenaming(New) && "Invalid function name.");
};
CloneSubModule(*KVPair.first, M, ExtractGlobalVars, ExtractFunctions,
Added: llvm/trunk/test/ExecutionEngine/OrcLazy/anonymous_globals.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/OrcLazy/anonymous_globals.ll?rev=234707&view=auto
==============================================================================
--- llvm/trunk/test/ExecutionEngine/OrcLazy/anonymous_globals.ll (added)
+++ llvm/trunk/test/ExecutionEngine/OrcLazy/anonymous_globals.ll Sun Apr 12 15:05:51 2015
@@ -0,0 +1,18 @@
+; RUN: lli -jit-kind=orc-lazy %s
+
+define private void @0() {
+entry:
+ ret void
+}
+
+define private void @"\01L_foo"() {
+entry:
+ ret void
+}
+
+define i32 @main(i32 %argc, i8** nocapture readnone %argv) {
+entry:
+ call void @0()
+ tail call void @"\01L_foo"()
+ ret i32 0
+}
More information about the llvm-commits
mailing list