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
This commit is contained in:
Rafael Espindola 2015-06-23 13:59:29 +00:00
parent 7c5bf4d38a
commit 9758b4ae95
19 changed files with 51 additions and 71 deletions

View File

@ -1168,7 +1168,6 @@ public:
KaleidoscopeJIT(SessionContext &Session)
: Session(Session),
Mang(Session.getTarget().getDataLayout()),
CompileLayer(ObjectLayer, SimpleCompiler(Session.getTarget())),
LazyEmitLayer(CompileLayer),
CompileCallbacks(LazyEmitLayer, CCMgrMemMgr, Session.getLLVMContext(),
@ -1179,7 +1178,8 @@ public:
std::string MangledName;
{
raw_string_ostream MangledNameStream(MangledName);
Mang.getNameWithPrefix(MangledNameStream, Name);
Mangler::getNameWithPrefix(MangledNameStream, Name,
*Session.getTarget().getDataLayout());
}
return MangledName;
}
@ -1306,7 +1306,6 @@ private:
}
SessionContext &Session;
Mangler Mang;
SectionMemoryManager CCMgrMemMgr;
ObjLayerT ObjectLayer;
CompileLayerT CompileLayer;

View File

@ -1160,14 +1160,14 @@ public:
typedef CompileLayerT::ModuleSetHandleT ModuleHandleT;
KaleidoscopeJIT(SessionContext &Session)
: Mang(Session.getTarget().getDataLayout()),
CompileLayer(ObjectLayer, SimpleCompiler(Session.getTarget())) {}
: DL(*Session.getTarget().getDataLayout()),
CompileLayer(ObjectLayer, SimpleCompiler(Session.getTarget())) {}
std::string mangle(const std::string &Name) {
std::string MangledName;
{
raw_string_ostream MangledNameStream(MangledName);
Mang.getNameWithPrefix(MangledNameStream, Name);
Mangler::getNameWithPrefix(MangledNameStream, Name, DL);
}
return MangledName;
}
@ -1201,8 +1201,7 @@ public:
}
private:
Mangler Mang;
const DataLayout &DL;
ObjLayerT ObjectLayer;
CompileLayerT CompileLayer;
};

View File

@ -1162,15 +1162,15 @@ public:
typedef LazyEmitLayerT::ModuleSetHandleT ModuleHandleT;
KaleidoscopeJIT(SessionContext &Session)
: Mang(Session.getTarget().getDataLayout()),
CompileLayer(ObjectLayer, SimpleCompiler(Session.getTarget())),
LazyEmitLayer(CompileLayer) {}
: DL(*Session.getTarget().getDataLayout()),
CompileLayer(ObjectLayer, SimpleCompiler(Session.getTarget())),
LazyEmitLayer(CompileLayer) {}
std::string mangle(const std::string &Name) {
std::string MangledName;
{
raw_string_ostream MangledNameStream(MangledName);
Mang.getNameWithPrefix(MangledNameStream, Name);
Mangler::getNameWithPrefix(MangledNameStream, Name, DL);
}
return MangledName;
}
@ -1204,8 +1204,7 @@ public:
}
private:
Mangler Mang;
const DataLayout &DL;
ObjLayerT ObjectLayer;
CompileLayerT CompileLayer;
LazyEmitLayerT LazyEmitLayer;

View File

@ -1162,7 +1162,6 @@ public:
KaleidoscopeJIT(SessionContext &Session)
: Session(Session),
Mang(Session.getTarget().getDataLayout()),
CompileLayer(ObjectLayer, SimpleCompiler(Session.getTarget())),
LazyEmitLayer(CompileLayer) {}
@ -1170,7 +1169,8 @@ public:
std::string MangledName;
{
raw_string_ostream MangledNameStream(MangledName);
Mang.getNameWithPrefix(MangledNameStream, Name);
Mangler::getNameWithPrefix(MangledNameStream, Name,
*Session.getTarget().getDataLayout());
}
return MangledName;
}
@ -1236,7 +1236,6 @@ private:
}
SessionContext &Session;
Mangler Mang;
ObjLayerT ObjectLayer;
CompileLayerT CompileLayer;
LazyEmitLayerT LazyEmitLayer;

View File

@ -241,11 +241,10 @@ private:
}
static std::string Mangle(StringRef Name, const DataLayout &DL) {
Mangler M(&DL);
std::string MangledName;
{
raw_string_ostream MangledNameStream(MangledName);
M.getNameWithPrefix(MangledNameStream, Name);
Mangler::getNameWithPrefix(MangledNameStream, Name, DL);
}
return MangledName;
}

View File

@ -193,7 +193,7 @@ private:
auto Symbols = llvm::make_unique<StringMap<const GlobalValue*>>();
for (const auto &M : Ms) {
Mangler Mang(&M->getDataLayout());
Mangler Mang;
for (const auto &V : M->globals())
if (auto GV = addGlobalValue(*Symbols, V, Mang, SearchName,

View File

@ -33,8 +33,6 @@ public:
};
private:
const DataLayout *DL;
/// We need to give global values the same name every time they are mangled.
/// This keeps track of the number we give to anonymous ones.
mutable DenseMap<const GlobalValue*, unsigned> AnonGlobalIDs;
@ -43,15 +41,11 @@ private:
mutable unsigned NextAnonGlobalID;
public:
Mangler(const DataLayout *DL) : DL(DL), NextAnonGlobalID(1) {}
Mangler() : NextAnonGlobalID(1) {}
/// Print the appropriate prefix and the specified global variable's name.
/// If the global variable doesn't have a name, this fills in a unique name
/// for the global.
static void getNameWithPrefix(SmallVectorImpl<char> &OutName,
const Twine &GVName, const DataLayout &DL);
void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV,
bool CannotUsePrivateLabel) const;
void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
@ -59,10 +53,12 @@ public:
/// Print the appropriate prefix and the specified name as the global variable
/// name. GVName must not be empty.
void getNameWithPrefix(raw_ostream &OS, const Twine &GVName,
ManglerPrefixTy PrefixTy = Mangler::Default) const;
void getNameWithPrefix(SmallVectorImpl<char> &OutName, const Twine &GVName,
ManglerPrefixTy PrefixTy = Mangler::Default) const;
static void getNameWithPrefix(raw_ostream &OS, const Twine &GVName,
const DataLayout &DL,
ManglerPrefixTy PrefixTy = Mangler::Default);
static void getNameWithPrefix(SmallVectorImpl<char> &OutName,
const Twine &GVName, const DataLayout &DL,
ManglerPrefixTy PrefixTy = Mangler::Default);
};
} // End llvm namespace

View File

@ -179,7 +179,7 @@ bool AsmPrinter::doInitialization(Module &M) {
OutStreamer->InitSections(false);
Mang = new Mangler(TM.getDataLayout());
Mang = new Mangler();
// Emit the version-min deplyment target directive if needed.
//
@ -2292,11 +2292,10 @@ MCSymbol *AsmPrinter::getSymbolWithGlobalValueBase(const GlobalValue *GV,
TM);
}
/// GetExternalSymbolSymbol - Return the MCSymbol for the specified
/// ExternalSymbol.
/// Return the MCSymbol for the specified ExternalSymbol.
MCSymbol *AsmPrinter::GetExternalSymbolSymbol(StringRef Sym) const {
SmallString<60> NameStr;
Mang->getNameWithPrefix(NameStr, Sym);
Mangler::getNameWithPrefix(NameStr, Sym, *TM.getDataLayout());
return OutContext.getOrCreateSymbol(NameStr);
}

View File

@ -58,7 +58,7 @@ static void EmitCamlGlobal(const Module &M, AsmPrinter &AP, const char *Id) {
SymName[Letter] = toupper(SymName[Letter]);
SmallString<128> TmpStr;
AP.Mang->getNameWithPrefix(TmpStr, SymName);
Mangler::getNameWithPrefix(TmpStr, SymName, M.getDataLayout());
MCSymbol *Sym = AP.OutContext.getOrCreateSymbol(TmpStr);

View File

@ -181,9 +181,9 @@ uint64_t ExecutionEngineState::RemoveMapping(StringRef Name) {
std::string ExecutionEngine::getMangledName(const GlobalValue *GV) {
MutexGuard locked(lock);
Mangler Mang(DL);
Mangler Mang;
SmallString<128> FullName;
Mang.getNameWithPrefix(FullName, GV->getName());
Mang.getNameWithPrefix(FullName, GV, false);
return FullName.str();
}

View File

@ -264,9 +264,8 @@ void MCJIT::finalizeModule(Module *M) {
}
RuntimeDyld::SymbolInfo MCJIT::findExistingSymbol(const std::string &Name) {
Mangler Mang(TM->getDataLayout());
SmallString<128> FullName;
Mang.getNameWithPrefix(FullName, Name);
Mangler::getNameWithPrefix(FullName, Name, *TM->getDataLayout());
return Dyld.getSymbol(FullName);
}
@ -369,7 +368,7 @@ uint64_t MCJIT::getFunctionAddress(const std::string &Name) {
void *MCJIT::getPointerToFunction(Function *F) {
MutexGuard locked(lock);
Mangler Mang(TM->getDataLayout());
Mangler Mang;
SmallString<128> Name;
TM->getNameWithPrefix(Name, F, Mang);

View File

@ -142,7 +142,6 @@ public:
std::unique_ptr<TargetMachine> TM)
: TM(std::move(TM)), MemMgr(*this, std::move(MemMgr)),
Resolver(*this), ClientResolver(std::move(ClientResolver)),
Mang(this->TM->getDataLayout()),
NotifyObjectLoaded(*this), NotifyFinalized(*this),
ObjectLayer(NotifyObjectLoaded, NotifyFinalized),
CompileLayer(ObjectLayer, SimpleCompiler(*this->TM)),
@ -311,7 +310,7 @@ private:
std::string MangledName;
{
raw_string_ostream MangledNameStream(MangledName);
Mang.getNameWithPrefix(MangledNameStream, Name);
Mang.getNameWithPrefix(MangledNameStream, Name, *TM->getDataLayout());
}
return MangledName;
}

View File

@ -17,6 +17,7 @@
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
@ -47,24 +48,18 @@ static void getNameWithPrefixImpl(raw_ostream &OS, const Twine &GVName,
}
void Mangler::getNameWithPrefix(raw_ostream &OS, const Twine &GVName,
ManglerPrefixTy PrefixTy) const {
char Prefix = DL->getGlobalPrefix();
return getNameWithPrefixImpl(OS, GVName, PrefixTy, *DL, Prefix);
const DataLayout &DL,
ManglerPrefixTy PrefixTy) {
char Prefix = DL.getGlobalPrefix();
return getNameWithPrefixImpl(OS, GVName, PrefixTy, DL, Prefix);
}
void Mangler::getNameWithPrefix(SmallVectorImpl<char> &OutName,
const Twine &GVName, const DataLayout &DL) {
const Twine &GVName, const DataLayout &DL,
ManglerPrefixTy PrefixTy) {
raw_svector_ostream OS(OutName);
char Prefix = DL.getGlobalPrefix();
return getNameWithPrefixImpl(OS, GVName, Mangler::Default, DL, Prefix);
}
void Mangler::getNameWithPrefix(SmallVectorImpl<char> &OutName,
const Twine &GVName,
ManglerPrefixTy PrefixTy) const {
raw_svector_ostream OS(OutName);
char Prefix = DL->getGlobalPrefix();
return getNameWithPrefixImpl(OS, GVName, PrefixTy, *DL, Prefix);
return getNameWithPrefixImpl(OS, GVName, PrefixTy, DL, Prefix);
}
static bool hasByteCountSuffix(CallingConv::ID CC) {
@ -108,6 +103,7 @@ void Mangler::getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV,
PrefixTy = Mangler::Private;
}
const DataLayout &DL = GV->getParent()->getDataLayout();
if (!GV->hasName()) {
// Get the ID for the global, assigning a new one if we haven't got one
// already.
@ -116,12 +112,12 @@ void Mangler::getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV,
ID = NextAnonGlobalID++;
// Must mangle the global into a unique ID.
getNameWithPrefix(OS, "__unnamed_" + Twine(ID), PrefixTy);
getNameWithPrefix(OS, "__unnamed_" + Twine(ID), DL, PrefixTy);
return;
}
StringRef Name = GV->getName();
char Prefix = DL->getGlobalPrefix();
char Prefix = DL.getGlobalPrefix();
// Mangle functions with Microsoft calling conventions specially. Only do
// this mangling for x86_64 vectorcall and 32-bit x86.
@ -130,7 +126,7 @@ void Mangler::getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV,
MSFunc = nullptr; // Don't mangle when \01 is present.
CallingConv::ID CC =
MSFunc ? MSFunc->getCallingConv() : (unsigned)CallingConv::C;
if (!DL->hasMicrosoftFastStdCallMangling() &&
if (!DL.hasMicrosoftFastStdCallMangling() &&
CC != CallingConv::X86_VectorCall)
MSFunc = nullptr;
if (MSFunc) {
@ -140,7 +136,7 @@ void Mangler::getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV,
Prefix = '\0'; // vectorcall functions have no prefix.
}
getNameWithPrefixImpl(OS, Name, PrefixTy, *DL, Prefix);
getNameWithPrefixImpl(OS, Name, PrefixTy, DL, Prefix);
if (!MSFunc)
return;
@ -155,7 +151,7 @@ void Mangler::getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV,
// "Pure" variadic functions do not receive @0 suffix.
(!FT->isVarArg() || FT->getNumParams() == 0 ||
(FT->getNumParams() == 1 && MSFunc->hasStructRetAttr())))
addByteCountSuffix(OS, MSFunc, *DL);
addByteCountSuffix(OS, MSFunc, DL);
}
void Mangler::getNameWithPrefix(SmallVectorImpl<char> &OutName,

View File

@ -453,7 +453,7 @@ void LTOCodeGenerator::applyScopeRestrictions() {
passes.add(createVerifierPass());
// mark which symbols can not be internalized
Mangler Mangler(TargetMach->getDataLayout());
Mangler Mangler;
std::vector<const char*> MustPreserveList;
SmallPtrSet<GlobalValue*, 8> AsmUsed;
std::vector<StringRef> Libcalls;

View File

@ -37,9 +37,7 @@ using namespace object;
IRObjectFile::IRObjectFile(MemoryBufferRef Object, std::unique_ptr<Module> Mod)
: SymbolicFile(Binary::ID_IR, Object), M(std::move(Mod)) {
// Setup a mangler with the DataLayout.
const DataLayout &DL = M->getDataLayout();
Mang.reset(new Mangler(&DL));
Mang.reset(new Mangler());
const std::string &InlineAsm = M->getModuleInlineAsm();
if (InlineAsm.empty())

View File

@ -826,7 +826,7 @@ bool NVPTXAsmPrinter::doInitialization(Module &M) {
const_cast<TargetLoweringObjectFile &>(getObjFileLowering())
.Initialize(OutContext, TM);
Mang = new Mangler(TM.getDataLayout());
Mang = new Mangler();
// Emit header before any dwarf directives are emitted below.
emitHeader(M, OS1, STI);

View File

@ -57,7 +57,7 @@ static MCSymbol *GetSymbolFromOperand(const MachineOperand &MO, AsmPrinter &AP){
if (!MO.isGlobal()) {
assert(MO.isSymbol() && "Isn't a symbol reference");
Mang->getNameWithPrefix(Name, MO.getSymbolName());
Mangler::getNameWithPrefix(Name, MO.getSymbolName(), *DL);
} else {
const GlobalValue *GV = MO.getGlobal();
TM.getNameWithPrefix(Name, GV, *Mang);

View File

@ -159,7 +159,7 @@ GetSymbolFromOperand(const MachineOperand &MO) const {
const GlobalValue *GV = MO.getGlobal();
AsmPrinter.getNameWithPrefix(Name, GV);
} else if (MO.isSymbol()) {
getMang()->getNameWithPrefix(Name, MO.getSymbolName());
Mangler::getNameWithPrefix(Name, MO.getSymbolName(), *DL);
} else if (MO.isMBB()) {
assert(Suffix.empty());
Sym = MO.getMBB()->getSymbol();

View File

@ -50,7 +50,6 @@ public:
OrcLazyJIT(std::unique_ptr<TargetMachine> TM, LLVMContext &Context,
CallbackManagerBuilder &BuildCallbackMgr)
: TM(std::move(TM)),
Mang(this->TM->getDataLayout()),
ObjectLayer(),
CompileLayer(ObjectLayer, orc::SimpleCompiler(*this->TM)),
IRDumpLayer(CompileLayer, createDebugDumper()),
@ -137,7 +136,7 @@ private:
std::string MangledName;
{
raw_string_ostream MangledNameStream(MangledName);
Mang.getNameWithPrefix(MangledNameStream, Name);
Mangler::getNameWithPrefix(MangledNameStream, Name, *TM->getDataLayout());
}
return MangledName;
}
@ -145,7 +144,6 @@ private:
static TransformFtor createDebugDumper();
std::unique_ptr<TargetMachine> TM;
Mangler Mang;
SectionMemoryManager CCMgrMemMgr;
ObjLayerT ObjectLayer;