Don't reach into the middle of TargetMachine and cache one of its ivars.
authorBill Wendling <isanbard@gmail.com>
Wed, 29 May 2013 20:37:19 +0000 (20:37 +0000)
committerBill Wendling <isanbard@gmail.com>
Wed, 29 May 2013 20:37:19 +0000 (20:37 +0000)
Not only does this break encapsulation, it's gross.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182876 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/Mangler.h
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/Target/Mangler.cpp
lib/Target/NVPTX/NVPTXAsmPrinter.cpp
tools/lto/LTOCodeGenerator.cpp
tools/lto/LTOModule.cpp

index 9500f1cc8f48b8d915287277d8e16c2836f908c8..986244f53e5ff3daaffa4fef459785d0be73ae8a 100644 (file)
 #include "llvm/ADT/DenseMap.h"
 
 namespace llvm {
-class Twine;
+
 class GlobalValue;
-template <typename T> class SmallVectorImpl;
 class MCContext;
 class MCSymbol;
-class DataLayout;
+template <typename T> class SmallVectorImpl;
+class TargetMachine;
+class Twine;
 
 class Mangler {
 public:
@@ -34,7 +35,7 @@ public:
 
 private:
   MCContext &Context;
-  const DataLayout &TD;
+  const TargetMachine *TM;
 
   /// 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
@@ -47,8 +48,8 @@ private:
   unsigned NextAnonGlobalID;
 
 public:
-  Mangler(MCContext &context, const DataLayout &td)
-    : Context(context), TD(td), NextAnonGlobalID(1) {}
+  Mangler(MCContext &Context, const TargetMachine *TM)
+    : Context(Context), TM(TM), NextAnonGlobalID(1) {}
 
   /// getSymbol - Return the MCSymbol for the specified global value.  This
   /// symbol is the main label that is the address of the global.
index 7ad4f57f75a131c907976f8f8d71c0c5a5df4a70..5a83ed680876308f6049e510c157abf68bc2fa83 100644 (file)
@@ -163,7 +163,7 @@ bool AsmPrinter::doInitialization(Module &M) {
   const_cast<TargetLoweringObjectFile&>(getObjFileLowering())
     .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.
   EmitStartOfAsmFile(M);
index d31efa86b34d75eaf6254cb6eabcbfa2dd5a63a1..2269b739d83360cab5b2427d84fb5ba747a32e3c 100644 (file)
@@ -19,6 +19,7 @@
 #include "llvm/IR/Function.h"
 #include "llvm/MC/MCAsmInfo.h"
 #include "llvm/MC/MCContext.h"
+#include "llvm/Target/TargetMachine.h"
 #include "llvm/Support/raw_ostream.h"
 using namespace llvm;
 
@@ -226,7 +227,7 @@ void Mangler::getNameWithPrefix(SmallVectorImpl<char> &OutName,
           // "Pure" variadic functions do not receive @0 suffix.
           (!FT->isVarArg() || FT->getNumParams() == 0 ||
            (FT->getNumParams() == 1 && F->hasStructRetAttr())))
-        AddFastCallStdCallSuffix(OutName, F, TD);
+        AddFastCallStdCallSuffix(OutName, F, *TM->getDataLayout());
     }
   }
 }
index 229e4e5980dfe1edb983e8a46b0e98487dfe6b57..6cc52bda98d9b4ff0cf51a45fee61bdd9d54204f 100644 (file)
@@ -912,7 +912,7 @@ bool NVPTXAsmPrinter::doInitialization(Module &M) {
   const_cast<TargetLoweringObjectFile &>(getObjFileLowering())
       .Initialize(OutContext, TM);
 
-  Mang = new Mangler(OutContext, *TM.getDataLayout());
+  Mang = new Mangler(OutContext, &TM);
 
   // Emit header before any dwarf directives are emitted below.
   emitHeader(M, OS1);
index 8b339ee32f2168a145469d5729ffb581a028b4dc..465ccb4f2cb57b34bfe5e3497eb8935ac6b68c28 100644 (file)
@@ -310,7 +310,7 @@ void LTOCodeGenerator::applyScopeRestrictions() {
 
   // mark which symbols can not be internalized
   MCContext Context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(),NULL);
-  Mangler mangler(Context, *_target->getDataLayout());
+  Mangler mangler(Context, _target);
   std::vector<const char*> mustPreserveList;
   SmallPtrSet<GlobalValue*, 8> asmUsed;
 
index 21cf4a63ce027f6bd358def1fac3238f5fac35e3..2c308b6d61c570075db1a63297479c96110ebfdb 100644 (file)
@@ -158,7 +158,7 @@ SSPBufferSize("stack-protector-buffer-size", cl::init(8),
 LTOModule::LTOModule(llvm::Module *m, llvm::TargetMachine *t)
   : _module(m), _target(t),
     _context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(), NULL),
-    _mangler(_context, *_target->getDataLayout()) {}
+    _mangler(_context, t) {}
 
 /// isBitcodeFile - Returns 'true' if the file (or memory contents) is LLVM
 /// bitcode.