now that mangler is in libtarget, it can use MCAsmInfo instead of clients

having to pass various fields from it in.  Simplify.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93686 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2010-01-17 18:22:35 +00:00
parent b56bf581a3
commit c0dba723d1
7 changed files with 66 additions and 59 deletions

View File

@ -19,11 +19,10 @@
namespace llvm { namespace llvm {
class Twine; class Twine;
class Type;
class Module;
class Value; class Value;
class GlobalValue; class GlobalValue;
template <typename T> class SmallVectorImpl; template <typename T> class SmallVectorImpl;
class MCAsmInfo;
class Mangler { class Mangler {
public: public:
@ -34,17 +33,7 @@ public:
}; };
private: private:
/// Prefix - This string is added to each symbol that is emitted, unless the const MCAsmInfo &MAI;
/// symbol is marked as not needing this prefix.
const char *Prefix;
/// PrivatePrefix - This string is emitted before each symbol with private
/// linkage.
const char *PrivatePrefix;
/// LinkerPrivatePrefix - This string is emitted before each symbol with
/// "linker_private" linkage.
const char *LinkerPrivatePrefix;
/// AnonGlobalIDs - We need to give global values the same name every time /// AnonGlobalIDs - We need to give global values the same name every time
/// they are mangled. This keeps track of the number we give to anonymous /// they are mangled. This keeps track of the number we give to anonymous
@ -59,8 +48,7 @@ private:
public: public:
// Mangler ctor - if a prefix is specified, it will be prepended onto all // Mangler ctor - if a prefix is specified, it will be prepended onto all
// symbols. // symbols.
Mangler(Module &M, const char *Prefix = "", const char *privatePrefix = "", Mangler(const MCAsmInfo &mai) : MAI(mai) {}
const char *linkerPrivatePrefix = "");
/// getNameWithPrefix - Fill OutName with the name of the appropriate prefix /// getNameWithPrefix - Fill OutName with the name of the appropriate prefix
/// and the specified global variable's name. If the global variable doesn't /// and the specified global variable's name. If the global variable doesn't

View File

@ -101,8 +101,7 @@ bool AsmPrinter::doInitialization(Module &M) {
const_cast<TargetLoweringObjectFile&>(getObjFileLowering()) const_cast<TargetLoweringObjectFile&>(getObjFileLowering())
.Initialize(OutContext, TM); .Initialize(OutContext, TM);
Mang = new Mangler(M, MAI->getGlobalPrefix(), MAI->getPrivateGlobalPrefix(), Mang = new Mangler(*MAI);
MAI->getLinkerPrivateGlobalPrefix());
// Allow the target to emit any magic that it wants at the start of the file. // Allow the target to emit any magic that it wants at the start of the file.
EmitStartOfAsmFile(M); EmitStartOfAsmFile(M);

View File

@ -119,7 +119,7 @@ bool ELFWriter::doInitialization(Module &M) {
// Initialize TargetLoweringObjectFile. // Initialize TargetLoweringObjectFile.
const_cast<TargetLoweringObjectFile&>(TLOF).Initialize(OutContext, TM); const_cast<TargetLoweringObjectFile&>(TLOF).Initialize(OutContext, TM);
Mang = new Mangler(M); Mang = new Mangler(*MAI);
// ELF Header // ELF Header
// ---------- // ----------

View File

@ -58,6 +58,13 @@ extern "C" void LLVMInitializeCBackendTarget() {
} }
namespace { namespace {
class CBEMCAsmInfo : public MCAsmInfo {
public:
CBEMCAsmInfo() {
GlobalPrefix = "";
PrivateGlobalPrefix = "";
}
};
/// CBackendNameAllUsedStructsAndMergeFunctions - This pass inserts names for /// CBackendNameAllUsedStructsAndMergeFunctions - This pass inserts names for
/// any unnamed structure types that are used by the program, and merges /// any unnamed structure types that are used by the program, and merges
/// external functions with the same name. /// external functions with the same name.
@ -1869,8 +1876,17 @@ bool CWriter::doInitialization(Module &M) {
IL = new IntrinsicLowering(*TD); IL = new IntrinsicLowering(*TD);
IL->AddPrototypes(M); IL->AddPrototypes(M);
// Ensure that all structure types have names... #if 0
Mang = new Mangler(M); std::string Triple = TheModule->getTargetTriple();
if (Triple.empty())
Triple = llvm::sys::getHostTriple();
std::string E;
if (const Target *Match = TargetRegistry::lookupTarget(Triple, E))
TAsm = Match->createAsmInfo(Triple);
#endif
TAsm = new CBEMCAsmInfo();
Mang = new Mangler(*TAsm);
// Keep track of which functions are static ctors/dtors so they can have // Keep track of which functions are static ctors/dtors so they can have
// an attribute added to their prototypes. // an attribute added to their prototypes.
@ -3240,30 +3256,31 @@ bool CWriter::visitBuiltinCall(CallInst &I, Intrinsic::ID ID,
// of the per target tables // of the per target tables
// handle multiple constraint codes // handle multiple constraint codes
std::string CWriter::InterpretASMConstraint(InlineAsm::ConstraintInfo& c) { std::string CWriter::InterpretASMConstraint(InlineAsm::ConstraintInfo& c) {
assert(c.Codes.size() == 1 && "Too many asm constraint codes to handle"); assert(c.Codes.size() == 1 && "Too many asm constraint codes to handle");
const char *const *table = 0;
// Grab the translation table from MCAsmInfo if it exists. // Grab the translation table from MCAsmInfo if it exists.
if (!TAsm) { const MCAsmInfo *TargetAsm;
std::string Triple = TheModule->getTargetTriple(); std::string Triple = TheModule->getTargetTriple();
if (Triple.empty()) if (Triple.empty())
Triple = llvm::sys::getHostTriple(); Triple = llvm::sys::getHostTriple();
std::string E; std::string E;
if (const Target *Match = TargetRegistry::lookupTarget(Triple, E)) if (const Target *Match = TargetRegistry::lookupTarget(Triple, E))
TAsm = Match->createAsmInfo(Triple); TargetAsm = Match->createAsmInfo(Triple);
} else
if (TAsm) return c.Codes[0];
table = TAsm->getAsmCBE();
const char *const *table = TargetAsm->getAsmCBE();
// Search the translation table if it exists. // Search the translation table if it exists.
for (int i = 0; table && table[i]; i += 2) for (int i = 0; table && table[i]; i += 2)
if (c.Codes[0] == table[i]) if (c.Codes[0] == table[i]) {
delete TargetAsm;
return table[i+1]; return table[i+1];
}
// Default is identity. // Default is identity.
delete TargetAsm;
return c.Codes[0]; return c.Codes[0];
} }

View File

@ -13,6 +13,7 @@
#include "llvm/Target/Mangler.h" #include "llvm/Target/Mangler.h"
#include "llvm/GlobalValue.h" #include "llvm/GlobalValue.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallString.h"
#include "llvm/ADT/Twine.h" #include "llvm/ADT/Twine.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
@ -29,18 +30,21 @@ void Mangler::getNameWithPrefix(SmallVectorImpl<char> &OutName,
// If the global name is not led with \1, add the appropriate prefixes. // If the global name is not led with \1, add the appropriate prefixes.
if (Name[0] != '\1') { if (Name[0] != '\1') {
if (PrefixTy == Mangler::Private) if (PrefixTy == Mangler::Private) {
OutName.append(PrivatePrefix, PrivatePrefix+strlen(PrivatePrefix)); const char *Prefix = MAI.getPrivateGlobalPrefix();
else if (PrefixTy == Mangler::LinkerPrivate) OutName.append(Prefix, Prefix+strlen(Prefix));
OutName.append(LinkerPrivatePrefix, } else if (PrefixTy == Mangler::LinkerPrivate) {
LinkerPrivatePrefix+strlen(LinkerPrivatePrefix)); const char *Prefix = MAI.getLinkerPrivateGlobalPrefix();
OutName.append(Prefix, Prefix+strlen(Prefix));
}
const char *Prefix = MAI.getGlobalPrefix();
if (Prefix[0] == 0) if (Prefix[0] == 0)
; // Common noop, no prefix. ; // Common noop, no prefix.
else if (Prefix[1] == 0) else if (Prefix[1] == 0)
OutName.push_back(Prefix[0]); // Common, one character prefix. OutName.push_back(Prefix[0]); // Common, one character prefix.
else else
OutName.append(Prefix, Prefix+strlen(Prefix)); // Arbitrary prefix. OutName.append(Prefix, Prefix+strlen(Prefix)); // Arbitrary length prefix.
} else { } else {
Name = Name.substr(1); Name = Name.substr(1);
} }
@ -68,14 +72,21 @@ void Mangler::getNameWithPrefix(SmallVectorImpl<char> &OutName,
// If the global variable doesn't have a name, return a unique name for the // If the global variable doesn't have a name, return a unique name for the
// global based on a numbering. // global based on a numbering.
if (GV->hasPrivateLinkage() || isImplicitlyPrivate) {
const char *Prefix = MAI.getPrivateGlobalPrefix();
OutName.append(Prefix, Prefix+strlen(Prefix));
} else if (GV->hasLinkerPrivateLinkage()) {
const char *Prefix = MAI.getLinkerPrivateGlobalPrefix();
OutName.append(Prefix, Prefix+strlen(Prefix));
}
// Anonymous names always get prefixes. const char *Prefix = MAI.getGlobalPrefix();
if (GV->hasPrivateLinkage() || isImplicitlyPrivate) if (Prefix[0] == 0)
OutName.append(PrivatePrefix, PrivatePrefix+strlen(PrivatePrefix)); ; // Common noop, no prefix.
else if (GV->hasLinkerPrivateLinkage()) else if (Prefix[1] == 0)
OutName.append(LinkerPrivatePrefix, OutName.push_back(Prefix[0]); // Common, one character prefix.
LinkerPrivatePrefix+strlen(LinkerPrivatePrefix));; else
OutName.append(Prefix, Prefix+strlen(Prefix)); OutName.append(Prefix, Prefix+strlen(Prefix)); // Arbitrary length prefix.
// Get the ID for the global, assigning a new one if we haven't got one // Get the ID for the global, assigning a new one if we haven't got one
// already. // already.
@ -95,10 +106,3 @@ std::string Mangler::getNameWithPrefix(const GlobalValue *GV,
getNameWithPrefix(Buf, GV, isImplicitlyPrivate); getNameWithPrefix(Buf, GV, isImplicitlyPrivate);
return std::string(Buf.begin(), Buf.end()); return std::string(Buf.begin(), Buf.end());
} }
Mangler::Mangler(Module &M, const char *prefix, const char *privatePrefix,
const char *linkerPrivatePrefix)
: Prefix(prefix), PrivatePrefix(privatePrefix),
LinkerPrivatePrefix(linkerPrivatePrefix), NextAnonGlobalID(1) {
}

View File

@ -323,8 +323,7 @@ void LTOCodeGenerator::applyScopeRestrictions()
// mark which symbols can not be internalized // mark which symbols can not be internalized
if ( !_mustPreserveSymbols.empty() ) { if ( !_mustPreserveSymbols.empty() ) {
Mangler mangler(*mergedModule, Mangler mangler(*_target->getMCAsmInfo());
_target->getMCAsmInfo()->getGlobalPrefix());
std::vector<const char*> mustPreserveList; std::vector<const char*> mustPreserveList;
for (Module::iterator f = mergedModule->begin(), for (Module::iterator f = mergedModule->begin(),
e = mergedModule->end(); f != e; ++f) { e = mergedModule->end(); f != e; ++f) {

View File

@ -439,7 +439,7 @@ void LTOModule::lazyParseSymbols()
_symbolsParsed = true; _symbolsParsed = true;
// Use mangler to add GlobalPrefix to names to match linker names. // Use mangler to add GlobalPrefix to names to match linker names.
Mangler mangler(*_module, _target->getMCAsmInfo()->getGlobalPrefix()); Mangler mangler(*_target->getMCAsmInfo());
// add functions // add functions
for (Module::iterator f = _module->begin(); f != _module->end(); ++f) { for (Module::iterator f = _module->begin(); f != _module->end(); ++f) {