Don't reach into the middle of TargetMachine and cache one of its ivars.

Not only does this break encapsulation, it's gross.

llvm-svn: 182876
This commit is contained in:
Bill Wendling 2013-05-29 20:37:19 +00:00
parent 467441d511
commit 70b1400e6d
6 changed files with 13 additions and 11 deletions

View File

@ -17,12 +17,13 @@
#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMap.h"
namespace llvm { namespace llvm {
class Twine;
class GlobalValue; class GlobalValue;
template <typename T> class SmallVectorImpl;
class MCContext; class MCContext;
class MCSymbol; class MCSymbol;
class DataLayout; template <typename T> class SmallVectorImpl;
class TargetMachine;
class Twine;
class Mangler { class Mangler {
public: public:
@ -34,7 +35,7 @@ public:
private: private:
MCContext &Context; MCContext &Context;
const DataLayout &TD; const TargetMachine *TM;
/// 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
@ -47,8 +48,8 @@ private:
unsigned NextAnonGlobalID; unsigned NextAnonGlobalID;
public: public:
Mangler(MCContext &context, const DataLayout &td) Mangler(MCContext &Context, const TargetMachine *TM)
: Context(context), TD(td), NextAnonGlobalID(1) {} : Context(Context), TM(TM), NextAnonGlobalID(1) {}
/// getSymbol - Return the MCSymbol for the specified global value. This /// getSymbol - Return the MCSymbol for the specified global value. This
/// symbol is the main label that is the address of the global. /// symbol is the main label that is the address of the global.

View File

@ -163,7 +163,7 @@ bool AsmPrinter::doInitialization(Module &M) {
const_cast<TargetLoweringObjectFile&>(getObjFileLowering()) const_cast<TargetLoweringObjectFile&>(getObjFileLowering())
.Initialize(OutContext, TM); .Initialize(OutContext, TM);
Mang = new Mangler(OutContext, *TM.getDataLayout()); Mang = new Mangler(OutContext, &TM);
// 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

@ -19,6 +19,7 @@
#include "llvm/IR/Function.h" #include "llvm/IR/Function.h"
#include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h" #include "llvm/MC/MCContext.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
using namespace llvm; using namespace llvm;
@ -226,7 +227,7 @@ void Mangler::getNameWithPrefix(SmallVectorImpl<char> &OutName,
// "Pure" variadic functions do not receive @0 suffix. // "Pure" variadic functions do not receive @0 suffix.
(!FT->isVarArg() || FT->getNumParams() == 0 || (!FT->isVarArg() || FT->getNumParams() == 0 ||
(FT->getNumParams() == 1 && F->hasStructRetAttr()))) (FT->getNumParams() == 1 && F->hasStructRetAttr())))
AddFastCallStdCallSuffix(OutName, F, TD); AddFastCallStdCallSuffix(OutName, F, *TM->getDataLayout());
} }
} }
} }

View File

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

View File

@ -310,7 +310,7 @@ void LTOCodeGenerator::applyScopeRestrictions() {
// mark which symbols can not be internalized // mark which symbols can not be internalized
MCContext Context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(),NULL); MCContext Context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(),NULL);
Mangler mangler(Context, *_target->getDataLayout()); Mangler mangler(Context, _target);
std::vector<const char*> mustPreserveList; std::vector<const char*> mustPreserveList;
SmallPtrSet<GlobalValue*, 8> asmUsed; SmallPtrSet<GlobalValue*, 8> asmUsed;

View File

@ -158,7 +158,7 @@ SSPBufferSize("stack-protector-buffer-size", cl::init(8),
LTOModule::LTOModule(llvm::Module *m, llvm::TargetMachine *t) LTOModule::LTOModule(llvm::Module *m, llvm::TargetMachine *t)
: _module(m), _target(t), : _module(m), _target(t),
_context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(), NULL), _context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(), NULL),
_mangler(_context, *_target->getDataLayout()) {} _mangler(_context, t) {}
/// isBitcodeFile - Returns 'true' if the file (or memory contents) is LLVM /// isBitcodeFile - Returns 'true' if the file (or memory contents) is LLVM
/// bitcode. /// bitcode.