llvm.org GIT mirror llvm / 9758b4a
Simplify the Mangler interface now that DataLayout is mandatory. We only need to pass in a DataLayout when mangling a raw string, not when constructing the mangler. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240405 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 4 years ago
19 changed file(s) with 51 addition(s) and 71 deletion(s). Raw diff Collapse all Expand all
11671167
11681168 KaleidoscopeJIT(SessionContext &Session)
11691169 : Session(Session),
1170 Mang(Session.getTarget().getDataLayout()),
11711170 CompileLayer(ObjectLayer, SimpleCompiler(Session.getTarget())),
11721171 LazyEmitLayer(CompileLayer),
11731172 CompileCallbacks(LazyEmitLayer, CCMgrMemMgr, Session.getLLVMContext(),
11781177 std::string MangledName;
11791178 {
11801179 raw_string_ostream MangledNameStream(MangledName);
1181 Mang.getNameWithPrefix(MangledNameStream, Name);
1180 Mangler::getNameWithPrefix(MangledNameStream, Name,
1181 *Session.getTarget().getDataLayout());
11821182 }
11831183 return MangledName;
11841184 }
13051305 }
13061306
13071307 SessionContext &Session;
1308 Mangler Mang;
13091308 SectionMemoryManager CCMgrMemMgr;
13101309 ObjLayerT ObjectLayer;
13111310 CompileLayerT CompileLayer;
11591159 typedef CompileLayerT::ModuleSetHandleT ModuleHandleT;
11601160
11611161 KaleidoscopeJIT(SessionContext &Session)
1162 : Mang(Session.getTarget().getDataLayout()),
1163 CompileLayer(ObjectLayer, SimpleCompiler(Session.getTarget())) {}
1162 : DL(*Session.getTarget().getDataLayout()),
1163 CompileLayer(ObjectLayer, SimpleCompiler(Session.getTarget())) {}
11641164
11651165 std::string mangle(const std::string &Name) {
11661166 std::string MangledName;
11671167 {
11681168 raw_string_ostream MangledNameStream(MangledName);
1169 Mang.getNameWithPrefix(MangledNameStream, Name);
1169 Mangler::getNameWithPrefix(MangledNameStream, Name, DL);
11701170 }
11711171 return MangledName;
11721172 }
12001200 }
12011201
12021202 private:
1203
1204 Mangler Mang;
1203 const DataLayout &DL;
12051204 ObjLayerT ObjectLayer;
12061205 CompileLayerT CompileLayer;
12071206 };
11611161 typedef LazyEmitLayerT::ModuleSetHandleT ModuleHandleT;
11621162
11631163 KaleidoscopeJIT(SessionContext &Session)
1164 : Mang(Session.getTarget().getDataLayout()),
1165 CompileLayer(ObjectLayer, SimpleCompiler(Session.getTarget())),
1166 LazyEmitLayer(CompileLayer) {}
1164 : DL(*Session.getTarget().getDataLayout()),
1165 CompileLayer(ObjectLayer, SimpleCompiler(Session.getTarget())),
1166 LazyEmitLayer(CompileLayer) {}
11671167
11681168 std::string mangle(const std::string &Name) {
11691169 std::string MangledName;
11701170 {
11711171 raw_string_ostream MangledNameStream(MangledName);
1172 Mang.getNameWithPrefix(MangledNameStream, Name);
1172 Mangler::getNameWithPrefix(MangledNameStream, Name, DL);
11731173 }
11741174 return MangledName;
11751175 }
12031203 }
12041204
12051205 private:
1206
1207 Mangler Mang;
1206 const DataLayout &DL;
12081207 ObjLayerT ObjectLayer;
12091208 CompileLayerT CompileLayer;
12101209 LazyEmitLayerT LazyEmitLayer;
11611161
11621162 KaleidoscopeJIT(SessionContext &Session)
11631163 : Session(Session),
1164 Mang(Session.getTarget().getDataLayout()),
11651164 CompileLayer(ObjectLayer, SimpleCompiler(Session.getTarget())),
11661165 LazyEmitLayer(CompileLayer) {}
11671166
11691168 std::string MangledName;
11701169 {
11711170 raw_string_ostream MangledNameStream(MangledName);
1172 Mang.getNameWithPrefix(MangledNameStream, Name);
1171 Mangler::getNameWithPrefix(MangledNameStream, Name,
1172 *Session.getTarget().getDataLayout());
11731173 }
11741174 return MangledName;
11751175 }
12351235 }
12361236
12371237 SessionContext &Session;
1238 Mangler Mang;
12391238 ObjLayerT ObjectLayer;
12401239 CompileLayerT CompileLayer;
12411240 LazyEmitLayerT LazyEmitLayer;
240240 }
241241
242242 static std::string Mangle(StringRef Name, const DataLayout &DL) {
243 Mangler M(&DL);
244243 std::string MangledName;
245244 {
246245 raw_string_ostream MangledNameStream(MangledName);
247 M.getNameWithPrefix(MangledNameStream, Name);
246 Mangler::getNameWithPrefix(MangledNameStream, Name, DL);
248247 }
249248 return MangledName;
250249 }
192192 auto Symbols = llvm::make_unique>();
193193
194194 for (const auto &M : Ms) {
195 Mangler Mang(&M->getDataLayout());
195 Mangler Mang;
196196
197197 for (const auto &V : M->globals())
198198 if (auto GV = addGlobalValue(*Symbols, V, Mang, SearchName,
3232 };
3333
3434 private:
35 const DataLayout *DL;
36
3735 /// We need to give global values the same name every time they are mangled.
3836 /// This keeps track of the number we give to anonymous ones.
3937 mutable DenseMap AnonGlobalIDs;
4240 mutable unsigned NextAnonGlobalID;
4341
4442 public:
45 Mangler(const DataLayout *DL) : DL(DL), NextAnonGlobalID(1) {}
43 Mangler() : NextAnonGlobalID(1) {}
4644
4745 /// Print the appropriate prefix and the specified global variable's name.
4846 /// If the global variable doesn't have a name, this fills in a unique name
4947 /// for the global.
50
51 static void getNameWithPrefix(SmallVectorImpl &OutName,
52 const Twine &GVName, const DataLayout &DL);
53
5448 void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV,
5549 bool CannotUsePrivateLabel) const;
5650 void getNameWithPrefix(SmallVectorImpl &OutName, const GlobalValue *GV,
5852
5953 /// Print the appropriate prefix and the specified name as the global variable
6054 /// name. GVName must not be empty.
61 void getNameWithPrefix(raw_ostream &OS, const Twine &GVName,
62 ManglerPrefixTy PrefixTy = Mangler::Default) const;
63 void getNameWithPrefix(SmallVectorImpl &OutName, const Twine &GVName,
64 ManglerPrefixTy PrefixTy = Mangler::Default) const;
55 static void getNameWithPrefix(raw_ostream &OS, const Twine &GVName,
56 const DataLayout &DL,
57 ManglerPrefixTy PrefixTy = Mangler::Default);
58 static void getNameWithPrefix(SmallVectorImpl &OutName,
59 const Twine &GVName, const DataLayout &DL,
60 ManglerPrefixTy PrefixTy = Mangler::Default);
6561 };
6662
6763 } // End llvm namespace
178178
179179 OutStreamer->InitSections(false);
180180
181 Mang = new Mangler(TM.getDataLayout());
181 Mang = new Mangler();
182182
183183 // Emit the version-min deplyment target directive if needed.
184184 //
22912291 TM);
22922292 }
22932293
2294 /// GetExternalSymbolSymbol - Return the MCSymbol for the specified
2295 /// ExternalSymbol.
2294 /// Return the MCSymbol for the specified ExternalSymbol.
22962295 MCSymbol *AsmPrinter::GetExternalSymbolSymbol(StringRef Sym) const {
22972296 SmallString<60> NameStr;
2298 Mang->getNameWithPrefix(NameStr, Sym);
2297 Mangler::getNameWithPrefix(NameStr, Sym, *TM.getDataLayout());
22992298 return OutContext.getOrCreateSymbol(NameStr);
23002299 }
23012300
5757 SymName[Letter] = toupper(SymName[Letter]);
5858
5959 SmallString<128> TmpStr;
60 AP.Mang->getNameWithPrefix(TmpStr, SymName);
60 Mangler::getNameWithPrefix(TmpStr, SymName, M.getDataLayout());
6161
6262 MCSymbol *Sym = AP.OutContext.getOrCreateSymbol(TmpStr);
6363
180180
181181 std::string ExecutionEngine::getMangledName(const GlobalValue *GV) {
182182 MutexGuard locked(lock);
183 Mangler Mang(DL);
183 Mangler Mang;
184184 SmallString<128> FullName;
185 Mang.getNameWithPrefix(FullName, GV->getName());
185 Mang.getNameWithPrefix(FullName, GV, false);
186186 return FullName.str();
187187 }
188188
263263 }
264264
265265 RuntimeDyld::SymbolInfo MCJIT::findExistingSymbol(const std::string &Name) {
266 Mangler Mang(TM->getDataLayout());
267266 SmallString<128> FullName;
268 Mang.getNameWithPrefix(FullName, Name);
267 Mangler::getNameWithPrefix(FullName, Name, *TM->getDataLayout());
269268 return Dyld.getSymbol(FullName);
270269 }
271270
368367 void *MCJIT::getPointerToFunction(Function *F) {
369368 MutexGuard locked(lock);
370369
371 Mangler Mang(TM->getDataLayout());
370 Mangler Mang;
372371 SmallString<128> Name;
373372 TM->getNameWithPrefix(Name, F, Mang);
374373
141141 std::unique_ptr TM)
142142 : TM(std::move(TM)), MemMgr(*this, std::move(MemMgr)),
143143 Resolver(*this), ClientResolver(std::move(ClientResolver)),
144 Mang(this->TM->getDataLayout()),
145144 NotifyObjectLoaded(*this), NotifyFinalized(*this),
146145 ObjectLayer(NotifyObjectLoaded, NotifyFinalized),
147146 CompileLayer(ObjectLayer, SimpleCompiler(*this->TM)),
310309 std::string MangledName;
311310 {
312311 raw_string_ostream MangledNameStream(MangledName);
313 Mang.getNameWithPrefix(MangledNameStream, Name);
312 Mang.getNameWithPrefix(MangledNameStream, Name, *TM->getDataLayout());
314313 }
315314 return MangledName;
316315 }
1616 #include "llvm/IR/DataLayout.h"
1717 #include "llvm/IR/DerivedTypes.h"
1818 #include "llvm/IR/Function.h"
19 #include "llvm/IR/Module.h"
1920 #include "llvm/Support/raw_ostream.h"
2021 using namespace llvm;
2122
4647 }
4748
4849 void Mangler::getNameWithPrefix(raw_ostream &OS, const Twine &GVName,
49 ManglerPrefixTy PrefixTy) const {
50 char Prefix = DL->getGlobalPrefix();
51 return getNameWithPrefixImpl(OS, GVName, PrefixTy, *DL, Prefix);
50 const DataLayout &DL,
51 ManglerPrefixTy PrefixTy) {
52 char Prefix = DL.getGlobalPrefix();
53 return getNameWithPrefixImpl(OS, GVName, PrefixTy, DL, Prefix);
5254 }
5355
5456 void Mangler::getNameWithPrefix(SmallVectorImpl &OutName,
55 const Twine &GVName, const DataLayout &DL) {
57 const Twine &GVName, const DataLayout &DL,
58 ManglerPrefixTy PrefixTy) {
5659 raw_svector_ostream OS(OutName);
5760 char Prefix = DL.getGlobalPrefix();
58 return getNameWithPrefixImpl(OS, GVName, Mangler::Default, DL, Prefix);
59 }
60
61 void Mangler::getNameWithPrefix(SmallVectorImpl &OutName,
62 const Twine &GVName,
63 ManglerPrefixTy PrefixTy) const {
64 raw_svector_ostream OS(OutName);
65 char Prefix = DL->getGlobalPrefix();
66 return getNameWithPrefixImpl(OS, GVName, PrefixTy, *DL, Prefix);
61 return getNameWithPrefixImpl(OS, GVName, PrefixTy, DL, Prefix);
6762 }
6863
6964 static bool hasByteCountSuffix(CallingConv::ID CC) {
107102 PrefixTy = Mangler::Private;
108103 }
109104
105 const DataLayout &DL = GV->getParent()->getDataLayout();
110106 if (!GV->hasName()) {
111107 // Get the ID for the global, assigning a new one if we haven't got one
112108 // already.
115111 ID = NextAnonGlobalID++;
116112
117113 // Must mangle the global into a unique ID.
118 getNameWithPrefix(OS, "__unnamed_" + Twine(ID), PrefixTy);
114 getNameWithPrefix(OS, "__unnamed_" + Twine(ID), DL, PrefixTy);
119115 return;
120116 }
121117
122118 StringRef Name = GV->getName();
123 char Prefix = DL->getGlobalPrefix();
119 char Prefix = DL.getGlobalPrefix();
124120
125121 // Mangle functions with Microsoft calling conventions specially. Only do
126122 // this mangling for x86_64 vectorcall and 32-bit x86.
129125 MSFunc = nullptr; // Don't mangle when \01 is present.
130126 CallingConv::ID CC =
131127 MSFunc ? MSFunc->getCallingConv() : (unsigned)CallingConv::C;
132 if (!DL->hasMicrosoftFastStdCallMangling() &&
128 if (!DL.hasMicrosoftFastStdCallMangling() &&
133129 CC != CallingConv::X86_VectorCall)
134130 MSFunc = nullptr;
135131 if (MSFunc) {
139135 Prefix = '\0'; // vectorcall functions have no prefix.
140136 }
141137
142 getNameWithPrefixImpl(OS, Name, PrefixTy, *DL, Prefix);
138 getNameWithPrefixImpl(OS, Name, PrefixTy, DL, Prefix);
143139
144140 if (!MSFunc)
145141 return;
154150 // "Pure" variadic functions do not receive @0 suffix.
155151 (!FT->isVarArg() || FT->getNumParams() == 0 ||
156152 (FT->getNumParams() == 1 && MSFunc->hasStructRetAttr())))
157 addByteCountSuffix(OS, MSFunc, *DL);
153 addByteCountSuffix(OS, MSFunc, DL);
158154 }
159155
160156 void Mangler::getNameWithPrefix(SmallVectorImpl &OutName,
452452 passes.add(createVerifierPass());
453453
454454 // mark which symbols can not be internalized
455 Mangler Mangler(TargetMach->getDataLayout());
455 Mangler Mangler;
456456 std::vector MustPreserveList;
457457 SmallPtrSet AsmUsed;
458458 std::vector Libcalls;
3636
3737 IRObjectFile::IRObjectFile(MemoryBufferRef Object, std::unique_ptr Mod)
3838 : SymbolicFile(Binary::ID_IR, Object), M(std::move(Mod)) {
39 // Setup a mangler with the DataLayout.
40 const DataLayout &DL = M->getDataLayout();
41 Mang.reset(new Mangler(&DL));
39 Mang.reset(new Mangler());
4240
4341 const std::string &InlineAsm = M->getModuleInlineAsm();
4442 if (InlineAsm.empty())
825825 const_cast(getObjFileLowering())
826826 .Initialize(OutContext, TM);
827827
828 Mang = new Mangler(TM.getDataLayout());
828 Mang = new Mangler();
829829
830830 // Emit header before any dwarf directives are emitted below.
831831 emitHeader(M, OS1, STI);
5656
5757 if (!MO.isGlobal()) {
5858 assert(MO.isSymbol() && "Isn't a symbol reference");
59 Mang->getNameWithPrefix(Name, MO.getSymbolName());
59 Mangler::getNameWithPrefix(Name, MO.getSymbolName(), *DL);
6060 } else {
6161 const GlobalValue *GV = MO.getGlobal();
6262 TM.getNameWithPrefix(Name, GV, *Mang);
158158 const GlobalValue *GV = MO.getGlobal();
159159 AsmPrinter.getNameWithPrefix(Name, GV);
160160 } else if (MO.isSymbol()) {
161 getMang()->getNameWithPrefix(Name, MO.getSymbolName());
161 Mangler::getNameWithPrefix(Name, MO.getSymbolName(), *DL);
162162 } else if (MO.isMBB()) {
163163 assert(Suffix.empty());
164164 Sym = MO.getMBB()->getSymbol();
4949 OrcLazyJIT(std::unique_ptr TM, LLVMContext &Context,
5050 CallbackManagerBuilder &BuildCallbackMgr)
5151 : TM(std::move(TM)),
52 Mang(this->TM->getDataLayout()),
5352 ObjectLayer(),
5453 CompileLayer(ObjectLayer, orc::SimpleCompiler(*this->TM)),
5554 IRDumpLayer(CompileLayer, createDebugDumper()),
136135 std::string MangledName;
137136 {
138137 raw_string_ostream MangledNameStream(MangledName);
139 Mang.getNameWithPrefix(MangledNameStream, Name);
138 Mangler::getNameWithPrefix(MangledNameStream, Name, *TM->getDataLayout());
140139 }
141140 return MangledName;
142141 }
144143 static TransformFtor createDebugDumper();
145144
146145 std::unique_ptr TM;
147 Mangler Mang;
148146 SectionMemoryManager CCMgrMemMgr;
149147
150148 ObjLayerT ObjectLayer;