Refactor TargetMachine, pushing handling of TargetData into the target-specific subcl...
authorOwen Anderson <resistor@mac.com>
Wed, 3 May 2006 01:29:57 +0000 (01:29 +0000)
committerOwen Anderson <resistor@mac.com>
Wed, 3 May 2006 01:29:57 +0000 (01:29 +0000)
This fixes PR 759.

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

38 files changed:
include/llvm/CodeGen/DwarfWriter.h
include/llvm/CodeGen/MachineConstantPool.h
include/llvm/CodeGen/MachineJumpTableInfo.h
include/llvm/ExecutionEngine/ExecutionEngine.h
include/llvm/Target/TargetData.h
include/llvm/Target/TargetLowering.h
include/llvm/Target/TargetMachine.h
lib/CodeGen/AsmPrinter.cpp
lib/CodeGen/DwarfWriter.cpp
lib/CodeGen/ELFWriter.cpp
lib/CodeGen/MachineFunction.cpp
lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
lib/CodeGen/SelectionDAG/ScheduleDAG.cpp
lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
lib/CodeGen/SelectionDAG/TargetLowering.cpp
lib/ExecutionEngine/ExecutionEngine.cpp
lib/ExecutionEngine/Interpreter/Interpreter.cpp
lib/ExecutionEngine/JIT/JIT.cpp
lib/ExecutionEngine/JIT/JITEmitter.cpp
lib/Target/Alpha/AlphaAsmPrinter.cpp
lib/Target/Alpha/AlphaTargetMachine.cpp
lib/Target/Alpha/AlphaTargetMachine.h
lib/Target/CBackend/CTargetMachine.h
lib/Target/IA64/IA64AsmPrinter.cpp
lib/Target/IA64/IA64TargetMachine.cpp
lib/Target/IA64/IA64TargetMachine.h
lib/Target/PowerPC/PPCAsmPrinter.cpp
lib/Target/PowerPC/PPCTargetMachine.cpp
lib/Target/PowerPC/PPCTargetMachine.h
lib/Target/Sparc/SparcAsmPrinter.cpp
lib/Target/Sparc/SparcTargetMachine.cpp
lib/Target/Sparc/SparcTargetMachine.h
lib/Target/TargetMachine.cpp
lib/Target/X86/X86AsmPrinter.cpp
lib/Target/X86/X86ISelLowering.cpp
lib/Target/X86/X86TargetMachine.cpp
lib/Target/X86/X86TargetMachine.h
tools/llc/llc.cpp

index e5882777db491098effdda03f397822b24105ae5..c08cf4ebecbbcc3c95a6e460cdb8ff669f572f5e 100644 (file)
@@ -85,7 +85,7 @@ protected:
   AsmPrinter *Asm;
   
   /// TD - Target data.
-  const TargetData &TD;
+  const TargetData *TD;
   
   /// RI - Register Information.
   const MRegisterInfo *RI;
index bb88a86d15f2102b836acca8128b744c8b3bb214..bccb1467a4408df34c600c456018429d036281d6 100644 (file)
@@ -42,11 +42,11 @@ struct MachineConstantPoolEntry {
 };
   
 class MachineConstantPool {
-  const TargetData &TD;
+  const TargetData *TD;
   unsigned PoolAlignment;
   std::vector<MachineConstantPoolEntry> Constants;
 public:
-  MachineConstantPool(const TargetData &td) : TD(td), PoolAlignment(1) {}
+  MachineConstantPool(const TargetData *td) : TD(td), PoolAlignment(1) {}
     
   /// getConstantPoolAlignment - Return the log2 of the alignment required by
   /// the whole constant pool, of which the first element must be aligned.
index 2cb268ad539921460e8a672671e2a3a214cd7deb..c0f4af34c226b4845e6996a051aba334518c59d5 100644 (file)
@@ -37,10 +37,10 @@ struct MachineJumpTableEntry {
 };
   
 class MachineJumpTableInfo {
-  const TargetData &TD;
+  const TargetData *TD;
   std::vector<MachineJumpTableEntry> JumpTables;
 public:
-  MachineJumpTableInfo(const TargetData &td) : TD(td) {}
+  MachineJumpTableInfo(const TargetData *td) : TD(td) {}
     
   /// getJumpTableIndex - Create a new jump table or return an existing one.
   ///
index 051d83962898e9db30cff02bb626706ce5e7fb00..0974915154d2380b6bb1408919cb66c576ef44e3 100644 (file)
@@ -67,8 +67,8 @@ class ExecutionEngine {
 protected:
   ModuleProvider *MP;
 
-  void setTargetData(const TargetData &td) {
-    TD = &td;
+  void setTargetData(const TargetData *td) {
+    TD = td;
   }
 
   // To avoid having libexecutionengine depend on the JIT and interpreter
@@ -88,7 +88,7 @@ public:
   virtual ~ExecutionEngine();
 
   Module &getModule() const { return CurMod; }
-  const TargetData &getTargetData() const { return *TD; }
+  const TargetData *getTargetData() const { return TD; }
 
   /// create - This is the factory method for creating an execution engine which
   /// is appropriate for the current machine.
index 1f031f2cc9130a4db759a3acf487c73ec0f45564..32f05725466a3aff8111f24aebe988f8856c15ab 100644 (file)
@@ -54,18 +54,18 @@ public:
              unsigned char ByteAl  = 1, unsigned char BoolAl   = 1);
 
   // Copy constructor
-  TargetData (const TargetData &TD) :
+  TargetData (const TargetData *TD) :
     ImmutablePass(),
-    LittleEndian(TD.isLittleEndian()),
-    BoolAlignment(TD.getBoolAlignment()),
-    ByteAlignment(TD.getByteAlignment()),
-    ShortAlignment(TD.getShortAlignment()),
-    IntAlignment(TD.getIntAlignment()),
-    LongAlignment(TD.getLongAlignment()),
-    FloatAlignment(TD.getFloatAlignment()),
-    DoubleAlignment(TD.getDoubleAlignment()),
-    PointerSize(TD.getPointerSize()),
-    PointerAlignment(TD.getPointerAlignment()) {
+    LittleEndian(TD->isLittleEndian()),
+    BoolAlignment(TD->getBoolAlignment()),
+    ByteAlignment(TD->getByteAlignment()),
+    ShortAlignment(TD->getShortAlignment()),
+    IntAlignment(TD->getIntAlignment()),
+    LongAlignment(TD->getLongAlignment()),
+    FloatAlignment(TD->getFloatAlignment()),
+    DoubleAlignment(TD->getDoubleAlignment()),
+    PointerSize(TD->getPointerSize()),
+    PointerAlignment(TD->getPointerAlignment()) {
   }
 
   TargetData(const std::string &ToolName, const Module *M);
index 0a3fb03ecedc40b049c50e870be2acdf3178680a..1b4960e6866acaa3a513ef2139e7c9c487315ade 100644 (file)
@@ -78,7 +78,7 @@ public:
   virtual ~TargetLowering();
 
   TargetMachine &getTargetMachine() const { return TM; }
-  const TargetData &getTargetData() const { return TD; }
+  const TargetData *getTargetData() const { return TD; }
 
   bool isLittleEndian() const { return IsLittleEndian; }
   MVT::ValueType getPointerTy() const { return PointerTy; }
@@ -648,7 +648,7 @@ private:
   std::vector<unsigned> LegalAddressScales;
   
   TargetMachine &TM;
-  const TargetData &TD;
+  const TargetData *TD;
 
   /// IsLittleEndian - True if this is a little endian target.
   ///
index dd30861b995ac72069d796468b7c2f46052125d5..31f5f3c91396952e3807f730a15097d6de7c90f7 100644 (file)
@@ -50,19 +50,11 @@ namespace Reloc {
 ///
 class TargetMachine {
   const std::string Name;
-  const TargetData DataLayout;       // Calculates type size & alignment
 
   TargetMachine(const TargetMachine&);   // DO NOT IMPLEMENT
   void operator=(const TargetMachine&);  // DO NOT IMPLEMENT
 protected: // Can only create subclasses...
-  TargetMachine(const std::string &name, bool LittleEndian = false,
-                unsigned char PtrSize = 8, unsigned char PtrAl = 8,
-                unsigned char DoubleAl = 8, unsigned char FloatAl = 4,
-                unsigned char LongAl = 8, unsigned char IntAl = 4,
-                unsigned char ShortAl = 2, unsigned char ByteAl = 1,
-                unsigned char BoolAl = 1);
-
-  TargetMachine(const std::string &name, const TargetData &TD);
+  TargetMachine(const std::string &name) : Name(name) { };
 
   /// This constructor is used for targets that support arbitrary TargetData
   /// layouts, like the C backend.  It initializes the TargetData to match that
@@ -101,7 +93,7 @@ public:
   virtual const TargetInstrInfo        *getInstrInfo() const { return 0; }
   virtual const TargetFrameInfo        *getFrameInfo() const { return 0; }
   virtual       TargetLowering    *getTargetLowering() const { return 0; }
-  const TargetData &getTargetData() const { return DataLayout; }
+  virtual const TargetData            *getTargetData() const { return 0; }
 
   /// getSubtarget - This method returns a pointer to the specified type of
   /// TargetSubtarget.  In debug builds, it verifies that the object being
index 1175ac683738485ff49c9b613e0bbd29dc9408e4..e1a4cf68a7ccf953c5768345c6d57887db2f25b1 100644 (file)
@@ -144,7 +144,7 @@ void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
 void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
   const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
   if (CP.empty()) return;
-  const TargetData &TD = TM.getTargetData();
+  const TargetData *TD = TM.getTargetData();
   
   SwitchSection(ConstantPoolSection, 0);
   EmitAlignment(MCP->getConstantPoolAlignment());
@@ -154,7 +154,7 @@ void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
     WriteTypeSymbolic(O, CP[i].Val->getType(), 0) << '\n';
     EmitGlobalConstant(CP[i].Val);
     if (i != e-1) {
-      unsigned EntSize = TM.getTargetData().getTypeSize(CP[i].Val->getType());
+      unsigned EntSize = TM.getTargetData()->getTypeSize(CP[i].Val->getType());
       unsigned ValEnd = CP[i].Offset + EntSize;
       // Emit inter-object padding for alignment.
       EmitZeros(CP[i+1].Offset-ValEnd);
@@ -168,7 +168,7 @@ void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
 void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI) {
   const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
   if (JT.empty()) return;
-  const TargetData &TD = TM.getTargetData();
+  const TargetData *TD = TM.getTargetData();
   
   // FIXME: someday we need to handle PIC jump tables
   assert((TM.getRelocationModel() == Reloc::Static ||
@@ -176,7 +176,7 @@ void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI) {
          "Unhandled relocation model emitting jump table information!");
   
   SwitchSection(JumpTableSection, 0);
-  EmitAlignment(Log2_32(TD.getPointerAlignment()));
+  EmitAlignment(Log2_32(TD->getPointerAlignment()));
   for (unsigned i = 0, e = JT.size(); i != e; ++i) {
     O << PrivateGlobalPrefix << "JTI" << getFunctionNumber() << '_' << i 
       << ":\n";
@@ -242,7 +242,7 @@ void AsmPrinter::EmitXXStructorList(Constant *List) {
 /// specified global, returned in log form.  This includes an explicitly
 /// requested alignment (if the global has one).
 unsigned AsmPrinter::getPreferredAlignmentLog(const GlobalVariable *GV) const {
-  unsigned Alignment = TM.getTargetData().getTypeAlignmentShift(GV->getType());
+  unsigned Alignment = TM.getTargetData()->getTypeAlignmentShift(GV->getType());
   if (GV->getAlignment() > (1U << Alignment))
     Alignment = Log2_32(GV->getAlignment());
   
@@ -253,7 +253,7 @@ unsigned AsmPrinter::getPreferredAlignmentLog(const GlobalVariable *GV) const {
     if (Alignment < 4) {
       // If the global is not external, see if it is large.  If so, give it a
       // larger alignment.
-      if (TM.getTargetData().getTypeSize(GV->getType()->getElementType()) > 128)
+      if (TM.getTargetData()->getTypeSize(GV->getType()->getElementType()) > 128)
         Alignment = 4;    // 16-byte alignment.
     }
   }
@@ -310,13 +310,13 @@ void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
     else
       O << GlobalVarAddrPrefix << Mang->getValueName(GV) << GlobalVarAddrSuffix;
   } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
-    const TargetData &TD = TM.getTargetData();
+    const TargetData *TD = TM.getTargetData();
     switch(CE->getOpcode()) {
     case Instruction::GetElementPtr: {
       // generate a symbolic expression for the byte address
       const Constant *ptrVal = CE->getOperand(0);
       std::vector<Value*> idxVec(CE->op_begin()+1, CE->op_end());
-      if (int64_t Offset = TD.getIndexedOffset(ptrVal->getType(), idxVec)) {
+      if (int64_t Offset = TD->getIndexedOffset(ptrVal->getType(), idxVec)) {
         if (Offset)
           O << "(";
         EmitConstantValueOnly(ptrVal);
@@ -344,7 +344,7 @@ void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
               || (isa<PointerType>(Ty)
                   && (OpTy == Type::LongTy || OpTy == Type::ULongTy
                       || OpTy == Type::IntTy || OpTy == Type::UIntTy))
-              || (((TD.getTypeSize(Ty) >= TD.getTypeSize(OpTy))
+              || (((TD->getTypeSize(Ty) >= TD->getTypeSize(OpTy))
                    && OpTy->isLosslesslyConvertibleTo(Ty))))
              && "FIXME: Don't yet support this kind of constant cast expr");
       EmitConstantValueOnly(Op);
@@ -426,10 +426,10 @@ void AsmPrinter::EmitString(const ConstantArray *CVA) const {
 /// EmitGlobalConstant - Print a general LLVM constant to the .s file.
 ///
 void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
-  const TargetData &TD = TM.getTargetData();
+  const TargetData *TD = TM.getTargetData();
 
   if (CV->isNullValue() || isa<UndefValue>(CV)) {
-    EmitZeros(TD.getTypeSize(CV->getType()));
+    EmitZeros(TD->getTypeSize(CV->getType()));
     return;
   } else if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
     if (CVA->isString()) {
@@ -441,13 +441,13 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
     return;
   } else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
     // Print the fields in successive locations. Pad to align if needed!
-    const StructLayout *cvsLayout = TD.getStructLayout(CVS->getType());
+    const StructLayout *cvsLayout = TD->getStructLayout(CVS->getType());
     uint64_t sizeSoFar = 0;
     for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) {
       const Constant* field = CVS->getOperand(i);
 
       // Check if padding is needed and insert one or more 0s.
-      uint64_t fieldSize = TD.getTypeSize(field->getType());
+      uint64_t fieldSize = TD->getTypeSize(field->getType());
       uint64_t padSize = ((i == e-1? cvsLayout->StructSize
                            : cvsLayout->MemberOffsets[i+1])
                           - cvsLayout->MemberOffsets[i]) - fieldSize;
@@ -470,7 +470,7 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
       if (Data64bitsDirective)
         O << Data64bitsDirective << DoubleToBits(Val) << "\t" << CommentString
           << " double value: " << Val << "\n";
-      else if (TD.isBigEndian()) {
+      else if (TD->isBigEndian()) {
         O << Data32bitsDirective << unsigned(DoubleToBits(Val) >> 32)
           << "\t" << CommentString << " double most significant word "
           << Val << "\n";
@@ -497,7 +497,7 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
 
       if (Data64bitsDirective)
         O << Data64bitsDirective << Val << "\n";
-      else if (TD.isBigEndian()) {
+      else if (TD->isBigEndian()) {
         O << Data32bitsDirective << unsigned(Val >> 32)
           << "\t" << CommentString << " Double-word most significant word "
           << Val << "\n";
@@ -533,7 +533,7 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
     O << Data16bitsDirective;
     break;
   case Type::PointerTyID:
-    if (TD.getPointerSize() == 8) {
+    if (TD->getPointerSize() == 8) {
       O << Data64bitsDirective;
       break;
     }
index bb41dc035487248f557a5d29615e71ad4b59d375..b7006182670bfdf52457b7ec6a6ff442dfe75dab 100644 (file)
@@ -1075,7 +1075,7 @@ void DwarfWriter::EmitInt64(uint64_t Value) const {
   if (Asm->Data64bitsDirective) {
     O << Asm->Data64bitsDirective << "0x" << std::hex << Value << std::dec;
   } else {
-    if (TD.isBigEndian()) {
+    if (TD->isBigEndian()) {
       EmitInt32(unsigned(Value >> 32)); O << "\n";
       EmitInt32(unsigned(Value));
     } else {
@@ -1361,7 +1361,7 @@ DIE *DwarfWriter::NewType(DIE *Context, TypeDesc *TyDesc, CompileUnit *Unit) {
           Offset -= FieldOffset;
           
           // Maybe we need to work from the other end.
-          if (TD.isLittleEndian()) Offset = FieldSize - (Offset + Size);
+          if (TD->isLittleEndian()) Offset = FieldSize - (Offset + Size);
           
           Member->AddUInt(DW_AT_byte_size, 0, FieldSize >> 3);
           Member->AddUInt(DW_AT_bit_size, 0, Size);
index 780ba543cdc3122a9fe75ca76842e26447415303..029cfe2b020f745feb5a4c481deabe6942f732f4 100644 (file)
@@ -158,8 +158,8 @@ ELFWriter::ELFWriter(std::ostream &o, TargetMachine &tm) : O(o), TM(tm) {
   e_machine = 0;  // e_machine defaults to 'No Machine'
   e_flags = 0;    // e_flags defaults to 0, no flags.
 
-  is64Bit = TM.getTargetData().getPointerSizeInBits() == 64;
-  isLittleEndian = TM.getTargetData().isLittleEndian();
+  is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64;
+  isLittleEndian = TM.getTargetData()->isLittleEndian();
 
   // Create the machine code emitter object for this target.
   MCE = new ELFCodeEmitter(*this);
@@ -233,8 +233,8 @@ void ELFWriter::EmitGlobal(GlobalVariable *GV) {
   }
 
   const Type *GVType = (const Type*)GV->getType();
-  unsigned Align = TM.getTargetData().getTypeAlignment(GVType);
-  unsigned Size  = TM.getTargetData().getTypeSize(GVType);
+  unsigned Align = TM.getTargetData()->getTypeAlignment(GVType);
+  unsigned Size  = TM.getTargetData()->getTypeSize(GVType);
 
   // If this global has a zero initializer, it is part of the .bss or common
   // section.
index 6d66839e2fb86420c5e65f054875909c1796a4f8..02646de18fd1610babe3205cfe12f3b1359e116a 100644 (file)
@@ -367,11 +367,11 @@ void MachineJumpTableInfo::print(std::ostream &OS) const {
 }
 
 unsigned MachineJumpTableInfo::getEntrySize() const { 
-  return TD.getPointerSize(); 
+  return TD->getPointerSize(); 
 }
 
 unsigned MachineJumpTableInfo::getAlignment() const { 
-  return TD.getPointerAlignment(); 
+  return TD->getPointerAlignment(); 
 }
 
 void MachineJumpTableInfo::dump() const { print(std::cerr); }
@@ -400,7 +400,7 @@ unsigned MachineConstantPool::getConstantPoolIndex(Constant *C,
   unsigned Offset = 0;
   if (!Constants.empty()) {
     Offset = Constants.back().Offset;
-    Offset += TD.getTypeSize(Constants.back().Val->getType());
+    Offset += TD->getTypeSize(Constants.back().Val->getType());
     Offset = (Offset+AlignMask)&~AlignMask;
   }
   
index 6f9e97748e8e6c9aad519d0db4c9f10159de2eaf..45c686b4cdc79c3074b6298dfb432c5166dbd4d0 100644 (file)
@@ -1986,7 +1986,7 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
       // Otherwise, the target does not support this operation.  Lower the
       // operation to an explicit libcall as appropriate.
       MVT::ValueType IntPtr = TLI.getPointerTy();
-      const Type *IntPtrTy = TLI.getTargetData().getIntPtrType();
+      const Type *IntPtrTy = TLI.getTargetData()->getIntPtrType();
       std::vector<std::pair<SDOperand, const Type*> > Args;
 
       const char *FnName = 0;
@@ -2781,8 +2781,8 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
         // slots and always reusing the same one.  We currently always create
         // new ones, as reuse may inhibit scheduling.
         const Type *Ty = MVT::getTypeForValueType(ExtraVT);
-        unsigned TySize = (unsigned)TLI.getTargetData().getTypeSize(Ty);
-        unsigned Align  = TLI.getTargetData().getTypeAlignment(Ty);
+        unsigned TySize = (unsigned)TLI.getTargetData()->getTypeSize(Ty);
+        unsigned Align  = TLI.getTargetData()->getTypeAlignment(Ty);
         MachineFunction &MF = DAG.getMachineFunction();
         int SSFI =
           MF.getFrameInfo()->CreateStackObject((unsigned)TySize, Align);
index bf95a92555afc73b02a4fdd7337a77f3da2abf6b..3509b16b6ab43ff16a8556a2f290781c7408063c 100644 (file)
@@ -130,10 +130,10 @@ void ScheduleDAG::AddOperand(MachineInstr *MI, SDOperand Op,
         Align = 3;  // always 8-byte align doubles.
       else {
         Align = TM.getTargetData()
-          .getTypeAlignmentShift(CP->get()->getType());
+          ->getTypeAlignmentShift(CP->get()->getType());
         if (Align == 0) {
           // Alignment of packed types.  FIXME!
-          Align = TM.getTargetData().getTypeSize(CP->get()->getType());
+          Align = TM.getTargetData()->getTypeSize(CP->get()->getType());
           Align = Log2_64(Align);
         }
       }
index d3991a6ad74a8758d968f60175f5fb270be30f34..c4ba6426d7312ffe5032f93a4af8cd62d542e1ff 100644 (file)
@@ -225,9 +225,9 @@ FunctionLoweringInfo::FunctionLoweringInfo(TargetLowering &tli,
     if (AllocaInst *AI = dyn_cast<AllocaInst>(I))
       if (ConstantUInt *CUI = dyn_cast<ConstantUInt>(AI->getArraySize())) {
         const Type *Ty = AI->getAllocatedType();
-        uint64_t TySize = TLI.getTargetData().getTypeSize(Ty);
+        uint64_t TySize = TLI.getTargetData()->getTypeSize(Ty);
         unsigned Align = 
-          std::max((unsigned)TLI.getTargetData().getTypeAlignment(Ty),
+          std::max((unsigned)TLI.getTargetData()->getTypeAlignment(Ty),
                    AI->getAlignment());
 
         // If the alignment of the value is smaller than the size of the value,
@@ -394,7 +394,7 @@ public:
   // implemented with a libcall, etc.
   TargetLowering &TLI;
   SelectionDAG &DAG;
-  const TargetData &TD;
+  const TargetData *TD;
 
   /// SwitchCases - Vector of CaseBlock structures used to communicate
   /// SwitchInst code generation information.
@@ -1202,7 +1202,7 @@ void SelectionDAGLowering::visitShuffleVector(User &I) {
 void SelectionDAGLowering::visitGetElementPtr(User &I) {
   SDOperand N = getValue(I.getOperand(0));
   const Type *Ty = I.getOperand(0)->getType();
-  const Type *UIntPtrTy = TD.getIntPtrType();
+  const Type *UIntPtrTy = TD->getIntPtrType();
 
   for (GetElementPtrInst::op_iterator OI = I.op_begin()+1, E = I.op_end();
        OI != E; ++OI) {
@@ -1211,7 +1211,7 @@ void SelectionDAGLowering::visitGetElementPtr(User &I) {
       unsigned Field = cast<ConstantUInt>(Idx)->getValue();
       if (Field) {
         // N = N + Offset
-        uint64_t Offset = TD.getStructLayout(StTy)->MemberOffsets[Field];
+        uint64_t Offset = TD->getStructLayout(StTy)->MemberOffsets[Field];
         N = DAG.getNode(ISD::ADD, N.getValueType(), N,
                         getIntPtrConstant(Offset));
       }
@@ -1225,15 +1225,15 @@ void SelectionDAGLowering::visitGetElementPtr(User &I) {
 
         uint64_t Offs;
         if (ConstantSInt *CSI = dyn_cast<ConstantSInt>(CI))
-          Offs = (int64_t)TD.getTypeSize(Ty)*CSI->getValue();
+          Offs = (int64_t)TD->getTypeSize(Ty)*CSI->getValue();
         else
-          Offs = TD.getTypeSize(Ty)*cast<ConstantUInt>(CI)->getValue();
+          Offs = TD->getTypeSize(Ty)*cast<ConstantUInt>(CI)->getValue();
         N = DAG.getNode(ISD::ADD, N.getValueType(), N, getIntPtrConstant(Offs));
         continue;
       }
       
       // N = N + Idx * ElementSize;
-      uint64_t ElementSize = TD.getTypeSize(Ty);
+      uint64_t ElementSize = TD->getTypeSize(Ty);
       SDOperand IdxN = getValue(Idx);
 
       // If the index is smaller or larger than intptr_t, truncate or extend
@@ -1271,8 +1271,8 @@ void SelectionDAGLowering::visitAlloca(AllocaInst &I) {
     return;   // getValue will auto-populate this.
 
   const Type *Ty = I.getAllocatedType();
-  uint64_t TySize = TLI.getTargetData().getTypeSize(Ty);
-  unsigned Align = std::max((unsigned)TLI.getTargetData().getTypeAlignment(Ty),
+  uint64_t TySize = TLI.getTargetData()->getTypeSize(Ty);
+  unsigned Align = std::max((unsigned)TLI.getTargetData()->getTypeAlignment(Ty),
                             I.getAlignment());
 
   SDOperand AllocSize = getValue(I.getArraySize());
@@ -2267,12 +2267,12 @@ void SelectionDAGLowering::visitMalloc(MallocInst &I) {
     Src = DAG.getNode(ISD::ZERO_EXTEND, IntPtr, Src);
 
   // Scale the source by the type size.
-  uint64_t ElementSize = TD.getTypeSize(I.getType()->getElementType());
+  uint64_t ElementSize = TD->getTypeSize(I.getType()->getElementType());
   Src = DAG.getNode(ISD::MUL, Src.getValueType(),
                     Src, getIntPtrConstant(ElementSize));
 
   std::vector<std::pair<SDOperand, const Type*> > Args;
-  Args.push_back(std::make_pair(Src, TLI.getTargetData().getIntPtrType()));
+  Args.push_back(std::make_pair(Src, TLI.getTargetData()->getIntPtrType()));
 
   std::pair<SDOperand,SDOperand> Result =
     TLI.LowerCallTo(getRoot(), I.getType(), false, CallingConv::C, true,
@@ -2285,7 +2285,7 @@ void SelectionDAGLowering::visitMalloc(MallocInst &I) {
 void SelectionDAGLowering::visitFree(FreeInst &I) {
   std::vector<std::pair<SDOperand, const Type*> > Args;
   Args.push_back(std::make_pair(getValue(I.getOperand(0)),
-                                TLI.getTargetData().getIntPtrType()));
+                                TLI.getTargetData()->getIntPtrType()));
   MVT::ValueType IntPtr = TLI.getPointerTy();
   std::pair<SDOperand,SDOperand> Result =
     TLI.LowerCallTo(getRoot(), Type::VoidTy, false, CallingConv::C, true,
@@ -2766,7 +2766,7 @@ static Value *InsertGEPComputeCode(Value *&V, BasicBlock *BB, Instruction *GEPI,
 /// stores that use it.  In this case, decompose the GEP and move constant
 /// indices into blocks that use it.
 static void OptimizeGEPExpression(GetElementPtrInst *GEPI,
-                                  const TargetData &TD) {
+                                  const TargetData *TD) {
   // If this GEP is only used inside the block it is defined in, there is no
   // need to rewrite it.
   bool isUsedOutsideDefBB = false;
@@ -2797,7 +2797,7 @@ static void OptimizeGEPExpression(GetElementPtrInst *GEPI,
   // Otherwise, decompose the GEP instruction into multiplies and adds.  Sum the
   // constant offset (which we now know is non-zero) and deal with it later.
   uint64_t ConstantOffset = 0;
-  const Type *UIntPtrTy = TD.getIntPtrType();
+  const Type *UIntPtrTy = TD->getIntPtrType();
   Value *Ptr = new CastInst(GEPI->getOperand(0), UIntPtrTy, "", GEPI);
   const Type *Ty = GEPI->getOperand(0)->getType();
 
@@ -2807,7 +2807,7 @@ static void OptimizeGEPExpression(GetElementPtrInst *GEPI,
     if (const StructType *StTy = dyn_cast<StructType>(Ty)) {
       unsigned Field = cast<ConstantUInt>(Idx)->getValue();
       if (Field)
-        ConstantOffset += TD.getStructLayout(StTy)->MemberOffsets[Field];
+        ConstantOffset += TD->getStructLayout(StTy)->MemberOffsets[Field];
       Ty = StTy->getElementType(Field);
     } else {
       Ty = cast<SequentialType>(Ty)->getElementType();
@@ -2817,9 +2817,9 @@ static void OptimizeGEPExpression(GetElementPtrInst *GEPI,
         if (CI->getRawValue() == 0) continue;
         
         if (ConstantSInt *CSI = dyn_cast<ConstantSInt>(CI))
-          ConstantOffset += (int64_t)TD.getTypeSize(Ty)*CSI->getValue();
+          ConstantOffset += (int64_t)TD->getTypeSize(Ty)*CSI->getValue();
         else
-          ConstantOffset+=TD.getTypeSize(Ty)*cast<ConstantUInt>(CI)->getValue();
+          ConstantOffset+=TD->getTypeSize(Ty)*cast<ConstantUInt>(CI)->getValue();
         continue;
       }
       
@@ -2828,7 +2828,7 @@ static void OptimizeGEPExpression(GetElementPtrInst *GEPI,
       // Cast Idx to UIntPtrTy if needed.
       Idx = new CastInst(Idx, UIntPtrTy, "", GEPI);
       
-      uint64_t ElementSize = TD.getTypeSize(Ty);
+      uint64_t ElementSize = TD->getTypeSize(Ty);
       // Mask off bits that should not be set.
       ElementSize &= ~0ULL >> (64-UIntPtrTy->getPrimitiveSizeInBits());
       Constant *SizeCst = ConstantUInt::get(UIntPtrTy, ElementSize);
index 392b489297514bdfbe34f3feedfd809aa6c7f986..041d91ee72a8b1f4939ad398594c3433c8f2271f 100644 (file)
@@ -27,8 +27,8 @@ TargetLowering::TargetLowering(TargetMachine &tm)
   // All operations default to being supported.
   memset(OpActions, 0, sizeof(OpActions));
 
-  IsLittleEndian = TD.isLittleEndian();
-  ShiftAmountTy = SetCCResultTy = PointerTy = getValueType(TD.getIntPtrType());
+  IsLittleEndian = TD->isLittleEndian();
+  ShiftAmountTy = SetCCResultTy = PointerTy = getValueType(TD->getIntPtrType());
   ShiftAmtHandling = Undefined;
   memset(RegClassForVT, 0,MVT::LAST_VALUETYPE*sizeof(TargetRegisterClass*));
   memset(TargetDAGCombineArray, 0, 
index b99497fd88be6adf1473729bcc6febb15f4c669f..b5ac6db0fd9c891f7b78d6cedd16623089a396da 100644 (file)
@@ -70,7 +70,7 @@ const GlobalValue *ExecutionEngine::getGlobalValueAtAddress(void *Addr) {
 //
 static void *CreateArgv(ExecutionEngine *EE,
                         const std::vector<std::string> &InputArgv) {
-  unsigned PtrSize = EE->getTargetData().getPointerSize();
+  unsigned PtrSize = EE->getTargetData()->getPointerSize();
   char *Result = new char[(InputArgv.size()+1)*PtrSize];
 
   DEBUG(std::cerr << "ARGV = " << (void*)Result << "\n");
@@ -218,7 +218,7 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
       uint64_t Offset =
         TD->getIndexedOffset(CE->getOperand(0)->getType(), Indexes);
 
-      if (getTargetData().getPointerSize() == 4)
+      if (getTargetData()->getPointerSize() == 4)
         Result.IntVal += Offset;
       else
         Result.LongVal += Offset;
@@ -335,7 +335,7 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
 ///
 void ExecutionEngine::StoreValueToMemory(GenericValue Val, GenericValue *Ptr,
                                          const Type *Ty) {
-  if (getTargetData().isLittleEndian()) {
+  if (getTargetData()->isLittleEndian()) {
     switch (Ty->getTypeID()) {
     case Type::BoolTyID:
     case Type::UByteTyID:
@@ -352,7 +352,7 @@ void ExecutionEngine::StoreValueToMemory(GenericValue Val, GenericValue *Ptr,
                             Ptr->Untyped[2] = (Val.UIntVal >> 16) & 255;
                             Ptr->Untyped[3] = (Val.UIntVal >> 24) & 255;
                             break;
-    case Type::PointerTyID: if (getTargetData().getPointerSize() == 4)
+    case Type::PointerTyID: if (getTargetData()->getPointerSize() == 4)
                               goto Store4BytesLittleEndian;
     case Type::DoubleTyID:
     case Type::ULongTyID:
@@ -386,7 +386,7 @@ void ExecutionEngine::StoreValueToMemory(GenericValue Val, GenericValue *Ptr,
                             Ptr->Untyped[1] = (Val.UIntVal >> 16) & 255;
                             Ptr->Untyped[0] = (Val.UIntVal >> 24) & 255;
                             break;
-    case Type::PointerTyID: if (getTargetData().getPointerSize() == 4)
+    case Type::PointerTyID: if (getTargetData()->getPointerSize() == 4)
                               goto Store4BytesBigEndian;
     case Type::DoubleTyID:
     case Type::ULongTyID:
@@ -411,7 +411,7 @@ void ExecutionEngine::StoreValueToMemory(GenericValue Val, GenericValue *Ptr,
 GenericValue ExecutionEngine::LoadValueFromMemory(GenericValue *Ptr,
                                                   const Type *Ty) {
   GenericValue Result;
-  if (getTargetData().isLittleEndian()) {
+  if (getTargetData()->isLittleEndian()) {
     switch (Ty->getTypeID()) {
     case Type::BoolTyID:
     case Type::UByteTyID:
@@ -428,7 +428,7 @@ GenericValue ExecutionEngine::LoadValueFromMemory(GenericValue *Ptr,
                                             ((unsigned)Ptr->Untyped[2] << 16) |
                                             ((unsigned)Ptr->Untyped[3] << 24);
                             break;
-    case Type::PointerTyID: if (getTargetData().getPointerSize() == 4)
+    case Type::PointerTyID: if (getTargetData()->getPointerSize() == 4)
                               goto Load4BytesLittleEndian;
     case Type::DoubleTyID:
     case Type::ULongTyID:
@@ -462,7 +462,7 @@ GenericValue ExecutionEngine::LoadValueFromMemory(GenericValue *Ptr,
                                             ((unsigned)Ptr->Untyped[1] << 16) |
                                             ((unsigned)Ptr->Untyped[0] << 24);
                             break;
-    case Type::PointerTyID: if (getTargetData().getPointerSize() == 4)
+    case Type::PointerTyID: if (getTargetData()->getPointerSize() == 4)
                               goto Load4BytesBigEndian;
     case Type::DoubleTyID:
     case Type::ULongTyID:
@@ -491,7 +491,7 @@ void ExecutionEngine::InitializeMemory(const Constant *Init, void *Addr) {
     return;
   } else if (const ConstantPacked *CP = dyn_cast<ConstantPacked>(Init)) {
     unsigned ElementSize =
-      getTargetData().getTypeSize(CP->getType()->getElementType());
+      getTargetData()->getTypeSize(CP->getType()->getElementType());
     for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
       InitializeMemory(CP->getOperand(i), (char*)Addr+i*ElementSize);
     return;
@@ -500,7 +500,7 @@ void ExecutionEngine::InitializeMemory(const Constant *Init, void *Addr) {
     StoreValueToMemory(Val, (GenericValue*)Addr, Init->getType());
     return;
   } else if (isa<ConstantAggregateZero>(Init)) {
-    memset(Addr, 0, (size_t)getTargetData().getTypeSize(Init->getType()));
+    memset(Addr, 0, (size_t)getTargetData()->getTypeSize(Init->getType()));
     return;
   }
 
@@ -508,7 +508,7 @@ void ExecutionEngine::InitializeMemory(const Constant *Init, void *Addr) {
   case Type::ArrayTyID: {
     const ConstantArray *CPA = cast<ConstantArray>(Init);
     unsigned ElementSize =
-      getTargetData().getTypeSize(CPA->getType()->getElementType());
+      getTargetData()->getTypeSize(CPA->getType()->getElementType());
     for (unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i)
       InitializeMemory(CPA->getOperand(i), (char*)Addr+i*ElementSize);
     return;
@@ -517,7 +517,7 @@ void ExecutionEngine::InitializeMemory(const Constant *Init, void *Addr) {
   case Type::StructTyID: {
     const ConstantStruct *CPS = cast<ConstantStruct>(Init);
     const StructLayout *SL =
-      getTargetData().getStructLayout(cast<StructType>(CPS->getType()));
+      getTargetData()->getStructLayout(cast<StructType>(CPS->getType()));
     for (unsigned i = 0, e = CPS->getNumOperands(); i != e; ++i)
       InitializeMemory(CPS->getOperand(i), (char*)Addr+SL->MemberOffsets[i]);
     return;
@@ -534,7 +534,7 @@ void ExecutionEngine::InitializeMemory(const Constant *Init, void *Addr) {
 /// their initializers into the memory.
 ///
 void ExecutionEngine::emitGlobals() {
-  const TargetData &TD = getTargetData();
+  const TargetData *TD = getTargetData();
 
   // Loop over all of the global variables in the program, allocating the memory
   // to hold them.
@@ -546,7 +546,7 @@ void ExecutionEngine::emitGlobals() {
       const Type *Ty = I->getType()->getElementType();
 
       // Allocate some memory for it!
-      unsigned Size = TD.getTypeSize(Ty);
+      unsigned Size = TD->getTypeSize(Ty);
       addGlobalMapping(I, new char[Size]);
     } else {
       // External variable reference. Try to use the dynamic loader to
@@ -577,7 +577,7 @@ void ExecutionEngine::EmitGlobalVariable(const GlobalVariable *GV) {
   DEBUG(std::cerr << "Global '" << GV->getName() << "' -> " << GA << "\n");
 
   const Type *ElTy = GV->getType()->getElementType();
-  size_t GVSize = (size_t)getTargetData().getTypeSize(ElTy);
+  size_t GVSize = (size_t)getTargetData()->getTypeSize(ElTy);
   if (GA == 0) {
     // If it's not already specified, allocate memory for the global.
     GA = new char[GVSize];
index c17e4d404116e122173fcd761e04857c99e5555e..63d88254484215d87d42b3e3f09d2a35d4dab98f 100644 (file)
@@ -71,7 +71,7 @@ Interpreter::Interpreter(Module *M, bool isLittleEndian, bool isLongPointer)
        isLongPointer ? 8 : 4) {
 
   memset(&ExitValue, 0, sizeof(ExitValue));
-  setTargetData(TD);
+  setTargetData(&TD);
   // Initialize the "backend"
   initializeExecutionEngine();
   initializeExternalFunctions();
index 4d3b5a349f7cb303fdfc283174c1ed15ee1c7905..91c8caf50c1e4bcd01aaeeb1bfdbcd1409b0ab40 100644 (file)
@@ -302,8 +302,8 @@ void *JIT::getOrEmitGlobalVariable(const GlobalVariable *GV) {
     // actually initialize the global after current function has finished
     // compilation.
     const Type *GlobalType = GV->getType()->getElementType();
-    size_t S = getTargetData().getTypeSize(GlobalType);
-    size_t A = getTargetData().getTypeAlignment(GlobalType);
+    size_t S = getTargetData()->getTypeSize(GlobalType);
+    size_t A = getTargetData()->getTypeAlignment(GlobalType);
     if (A <= 8) {
       Ptr = malloc(S);
     } else {
index bdc5f791e09dc5540f5262df2fbc1b2ed959dbd8..a8d9170d4517aa884532b123a30cf388cf18b379 100644 (file)
@@ -518,7 +518,7 @@ void JITEmitter::emitConstantPool(MachineConstantPool *MCP) {
   if (Constants.empty()) return;
 
   unsigned Size = Constants.back().Offset;
-  Size += TheJIT->getTargetData().getTypeSize(Constants.back().Val->getType());
+  Size += TheJIT->getTargetData()->getTypeSize(Constants.back().Val->getType());
 
   ConstantPoolBase = allocateSpace(Size, 1 << MCP->getConstantPoolAlignment());
   ConstantPool = MCP;
index b078b68bd7f978de34046cae136df87bc6e35e00..74af78e250a6595c7d7feff1421390825801a27e 100644 (file)
@@ -221,7 +221,7 @@ bool AlphaAsmPrinter::doInitialization(Module &M)
 }
 
 bool AlphaAsmPrinter::doFinalization(Module &M) {
-  const TargetData &TD = TM.getTargetData();
+  const TargetData *TD = TM.getTargetData();
 
   for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I)
     if (I->hasInitializer()) {   // External global require no code
@@ -232,8 +232,8 @@ bool AlphaAsmPrinter::doFinalization(Module &M) {
       O << "\n\n";
       std::string name = Mang->getValueName(I);
       Constant *C = I->getInitializer();
-      unsigned Size = TD.getTypeSize(C->getType());
-      //      unsigned Align = TD.getTypeAlignmentShift(C->getType());
+      unsigned Size = TD->getTypeSize(C->getType());
+      //      unsigned Align = TD->getTypeAlignmentShift(C->getType());
       unsigned Align = getPreferredAlignmentLog(I);
 
       if (C->isNullValue() &&
@@ -243,7 +243,7 @@ bool AlphaAsmPrinter::doFinalization(Module &M) {
         if (I->hasInternalLinkage())
           O << "\t.local " << name << "\n";
 
-        O << "\t.comm " << name << "," << TD.getTypeSize(C->getType())
+        O << "\t.comm " << name << "," << TD->getTypeSize(C->getType())
           << "," << (1 << Align)
           <<  "\n";
       } else {
index 709669ffd72cc44b4e53ef1f685029e2c757c9f1..2970f8201b27945b79cf043dee24cbf4cbbab6ef 100644 (file)
@@ -54,7 +54,8 @@ unsigned AlphaTargetMachine::getJITMatchQuality() {
 }
 
 AlphaTargetMachine::AlphaTargetMachine(const Module &M, const std::string &FS)
-  : TargetMachine("alpha", true),
+  : TargetMachine("alpha"),
+    DataLayout("alpha", true),
     FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
     JITInfo(*this),
     Subtarget(M, FS)
index 8f6caeb6c2189c413ccd3dcdec6e95e6d9259ffa..6e23868172c8e763ef241ee3db8e7014fec7b2f5 100644 (file)
@@ -26,11 +26,12 @@ namespace llvm {
 class GlobalValue;
 
 class AlphaTargetMachine : public TargetMachine {
+  const TargetData DataLayout;       // Calculates type size & alignment
   AlphaInstrInfo InstrInfo;
   TargetFrameInfo FrameInfo;
   AlphaJITInfo JITInfo;
   AlphaSubtarget Subtarget;
-
+  
 public:
   AlphaTargetMachine(const Module &M, const std::string &FS);
 
@@ -40,6 +41,7 @@ public:
   virtual const MRegisterInfo *getRegisterInfo() const {
     return &InstrInfo.getRegisterInfo();
   }
+  virtual const TargetData       *getTargetData() const { return &DataLayout; }
   virtual TargetJITInfo* getJITInfo() {
     return &JITInfo;
   }
index f947f650c6763e166196868541cf2ef06fd7c8ac..271a2bf653a6e4539985f91618e8dcb640db2e6e 100644 (file)
 namespace llvm {
 
 struct CTargetMachine : public TargetMachine {
+  const TargetData DataLayout;       // Calculates type size & alignment
+
   CTargetMachine(const Module &M, const std::string &FS)
-    : TargetMachine("CBackend", M) {}
+    : TargetMachine("CBackend", M),
+      DataLayout("CBackend") {}
 
   // This is the only thing that actually does anything here.
   virtual bool addPassesToEmitFile(PassManager &PM, std::ostream &Out,
@@ -28,6 +31,8 @@ struct CTargetMachine : public TargetMachine {
 
   // This class always works, but shouldn't be the default in most cases.
   static unsigned getModuleMatchQuality(const Module &M) { return 1; }
+  
+  virtual const TargetData       *getTargetData() const { return &DataLayout; }
 };
 
 } // End llvm namespace
index 7caf57362bf1df42daf1bb0fad6a5531d2c9af81..d7f2fe108333c6647cafba6ef0195a11fbc4a0c8 100644 (file)
@@ -277,7 +277,7 @@ bool IA64AsmPrinter::doInitialization(Module &M) {
 }
 
 bool IA64AsmPrinter::doFinalization(Module &M) {
-  const TargetData &TD = TM.getTargetData();
+  const TargetData *TD = TM.getTargetData();
   
   // Print out module-level global variables here.
   for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
@@ -290,19 +290,19 @@ bool IA64AsmPrinter::doFinalization(Module &M) {
       O << "\n\n";
       std::string name = Mang->getValueName(I);
       Constant *C = I->getInitializer();
-      unsigned Size = TD.getTypeSize(C->getType());
-      unsigned Align = TD.getTypeAlignmentShift(C->getType());
+      unsigned Size = TD->getTypeSize(C->getType());
+      unsigned Align = TD->getTypeAlignmentShift(C->getType());
       
       if (C->isNullValue() &&
           (I->hasLinkOnceLinkage() || I->hasInternalLinkage() ||
            I->hasWeakLinkage() /* FIXME: Verify correct */)) {
         SwitchSection(".data", I);
         if (I->hasInternalLinkage()) {
-          O << "\t.lcomm " << name << "#," << TD.getTypeSize(C->getType())
+          O << "\t.lcomm " << name << "#," << TD->getTypeSize(C->getType())
           << "," << (1 << Align);
           O << "\t\t// ";
         } else {
-          O << "\t.common " << name << "#," << TD.getTypeSize(C->getType())
+          O << "\t.common " << name << "#," << TD->getTypeSize(C->getType())
           << "," << (1 << Align);
           O << "\t\t// ";
         }
index a03bda7e091e9aa9f6284953cfabc353344f1942..8e31a3810faf185621ddf5d30be64adb2db1bdbc 100644 (file)
@@ -76,7 +76,7 @@ unsigned IA64TargetMachine::getModuleMatchQuality(const Module &M) {
 /// IA64TargetMachine ctor - Create an LP64 architecture model
 ///
 IA64TargetMachine::IA64TargetMachine(const Module &M, const std::string &FS)
-  : TargetMachine("IA64", true),
+  : TargetMachine("IA64"), DataLayout("IA64", true),
     FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
     TLInfo(*this) { // FIXME? check this stuff
 }
index 7b9342ece5ba652972dd18ad2e5637a5f39551c2..ad5c0575e97a7377c216cb561616cf5fd0dddcbd 100644 (file)
@@ -23,6 +23,7 @@
 namespace llvm {
 
 class IA64TargetMachine : public TargetMachine {
+  const TargetData DataLayout;       // Calculates type size & alignment
   IA64InstrInfo      InstrInfo;
   TargetFrameInfo    FrameInfo;
   //IA64JITInfo      JITInfo;
@@ -36,6 +37,7 @@ public:
   virtual const MRegisterInfo    *getRegisterInfo() const {
     return &InstrInfo.getRegisterInfo();
   }
+  virtual const TargetData       *getTargetData() const { return &DataLayout; }
 
   virtual bool addPassesToEmitFile(PassManager &PM, std::ostream &Out,
                                    CodeGenFileType FileType, bool Fast);
index f3a03114b250dad806475bf054814e231d7df121..cfcf4dfe2e3a84e6a4bf4b7415b22f8f8b7fbb19 100644 (file)
@@ -582,7 +582,7 @@ bool DarwinAsmPrinter::doInitialization(Module &M) {
 }
 
 bool DarwinAsmPrinter::doFinalization(Module &M) {
-  const TargetData &TD = TM.getTargetData();
+  const TargetData *TD = TM.getTargetData();
 
   // Print out module-level global variables here.
   for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
@@ -595,7 +595,7 @@ bool DarwinAsmPrinter::doFinalization(Module &M) {
     
     std::string name = Mang->getValueName(I);
     Constant *C = I->getInitializer();
-    unsigned Size = TD.getTypeSize(C->getType());
+    unsigned Size = TD->getTypeSize(C->getType());
     unsigned Align = getPreferredAlignmentLog(I);
 
     if (C->isNullValue() && /* FIXME: Verify correct */
@@ -761,7 +761,7 @@ bool AIXAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
 
 bool AIXAsmPrinter::doInitialization(Module &M) {
   SwitchSection("", 0);
-  const TargetData &TD = TM.getTargetData();
+  const TargetData *TD = TM.getTargetData();
 
   O << "\t.machine \"ppc64\"\n"
     << "\t.toc\n"
@@ -810,7 +810,7 @@ bool AIXAsmPrinter::doInitialization(Module &M) {
 }
 
 bool AIXAsmPrinter::doFinalization(Module &M) {
-  const TargetData &TD = TM.getTargetData();
+  const TargetData *TD = TM.getTargetData();
   // Print out module-level global variables
   for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
        I != E; ++I) {
@@ -821,8 +821,8 @@ bool AIXAsmPrinter::doFinalization(Module &M) {
     if (I->hasInternalLinkage()) {
       O << "\t.lcomm " << Name << ",16,_global.bss_c";
     } else {
-      O << "\t.comm " << Name << "," << TD.getTypeSize(I->getType())
-        << "," << Log2_32((unsigned)TD.getTypeAlignment(I->getType()));
+      O << "\t.comm " << Name << "," << TD->getTypeSize(I->getType())
+        << "," << Log2_32((unsigned)TD->getTypeAlignment(I->getType()));
     }
     O << "\t\t" << CommentString << " ";
     WriteAsOperand(O, I, false, true, &M);
index d35ceb15f6f6919afd41be07d5e20da088b15c99..fd9df20b77cf3a7f769e67709db4a0b448dd308f 100644 (file)
@@ -58,7 +58,8 @@ unsigned PPCTargetMachine::getModuleMatchQuality(const Module &M) {
 }
 
 PPCTargetMachine::PPCTargetMachine(const Module &M, const std::string &FS)
-: TargetMachine("PowerPC", false, 4, 4, 4, 4, 4, 4, 2, 1, 1),
+: TargetMachine("PowerPC"),
+  DataLayout("PowerPC", false, 4, 4, 4, 4, 4),
   Subtarget(M, FS), FrameInfo(*this, false), JITInfo(*this),
   TLInfo(*this), InstrItins(Subtarget.getInstrItineraryData()) {
   if (TargetDefault == PPCTarget) {
index 3b2e481c7b5fae0e5379b9d31468f043b9e4dd8b..e4893a86dd09673dd87e0fd4c54470402dc4d007 100644 (file)
@@ -26,6 +26,7 @@ class PassManager;
 class GlobalValue;
 
 class PPCTargetMachine : public TargetMachine {
+  const TargetData DataLayout;       // Calculates type size & alignment
   PPCInstrInfo           InstrInfo;
   PPCSubtarget           Subtarget;
   PPCFrameInfo           FrameInfo;
@@ -43,6 +44,7 @@ public:
   virtual const MRegisterInfo    *getRegisterInfo() const {
     return &InstrInfo.getRegisterInfo();
   }
+  virtual const TargetData       *getTargetData() const { return &DataLayout; }
   virtual const InstrItineraryData getInstrItineraryData() const {  
     return InstrItins;
   }
index b4c40f1844a25699596db4143bec46331a3e8f9e..7033ab9422b9ff42c98357d26ab3c32864d45a1a 100644 (file)
@@ -232,7 +232,7 @@ bool SparcAsmPrinter::doInitialization(Module &M) {
 }
 
 bool SparcAsmPrinter::doFinalization(Module &M) {
-  const TargetData &TD = TM.getTargetData();
+  const TargetData *TD = TM.getTargetData();
 
   // Print out module-level global variables here.
   for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
@@ -245,8 +245,8 @@ bool SparcAsmPrinter::doFinalization(Module &M) {
       O << "\n\n";
       std::string name = Mang->getValueName(I);
       Constant *C = I->getInitializer();
-      unsigned Size = TD.getTypeSize(C->getType());
-      unsigned Align = TD.getTypeAlignment(C->getType());
+      unsigned Size = TD->getTypeSize(C->getType());
+      unsigned Align = TD->getTypeAlignment(C->getType());
 
       if (C->isNullValue() &&
           (I->hasLinkOnceLinkage() || I->hasInternalLinkage() ||
@@ -255,8 +255,8 @@ bool SparcAsmPrinter::doFinalization(Module &M) {
         if (I->hasInternalLinkage())
           O << "\t.local " << name << "\n";
 
-        O << "\t.comm " << name << "," << TD.getTypeSize(C->getType())
-          << "," << (unsigned)TD.getTypeAlignment(C->getType());
+        O << "\t.comm " << name << "," << TD->getTypeSize(C->getType())
+          << "," << (unsigned)TD->getTypeAlignment(C->getType());
         O << "\t\t! ";
         WriteAsOperand(O, I, true, true, &M);
         O << "\n";
index 2b56be2cb9a1779b8d0ea0c71784e72900a33738..ad72cf7886ccbac3862a56198e740f59578b90dc 100644 (file)
@@ -31,7 +31,8 @@ namespace {
 /// SparcTargetMachine ctor - Create an ILP32 architecture model
 ///
 SparcTargetMachine::SparcTargetMachine(const Module &M, const std::string &FS)
-  : TargetMachine("Sparc", false, 4, 4),
+  : TargetMachine("Sparc"),
+    DataLayout("Sparc", false, 4, 4),
     Subtarget(M, FS), InstrInfo(Subtarget),
     FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) {
 }
index 0cad652f71daa1b287abeb6672e8f5d681e6ddeb..7d30dd829f3afd5d412547163afdbabdea12fe6b 100644 (file)
@@ -25,6 +25,7 @@ namespace llvm {
 class Module;
 
 class SparcTargetMachine : public TargetMachine {
+  const TargetData DataLayout;       // Calculates type size & alignment
   SparcSubtarget Subtarget;
   SparcInstrInfo InstrInfo;
   TargetFrameInfo FrameInfo;
@@ -37,7 +38,7 @@ public:
   virtual const MRegisterInfo *getRegisterInfo() const {
     return &InstrInfo.getRegisterInfo();
   }
-
+  virtual const TargetData       *getTargetData() const { return &DataLayout; }
   static unsigned getModuleMatchQuality(const Module &M);
 
   virtual bool addPassesToEmitFile(PassManager &PM, std::ostream &Out,
index 74c90ed54e2f2c96602fcc422436418cbaa70156..24e1e5a547a6e0f63267282f0429ec6df0f0cc7c 100644 (file)
@@ -69,23 +69,9 @@ namespace {
 //---------------------------------------------------------------------------
 // TargetMachine Class
 //
-TargetMachine::TargetMachine(const std::string &name, bool LittleEndian,
-                             unsigned char PtrSize, unsigned char PtrAl,
-                             unsigned char DoubleAl, unsigned char FloatAl,
-                             unsigned char LongAl, unsigned char IntAl,
-                             unsigned char ShortAl, unsigned char ByteAl,
-                             unsigned char BoolAl)
-  : Name(name), DataLayout(name, LittleEndian,
-                           PtrSize, PtrAl, DoubleAl, FloatAl, LongAl,
-                           IntAl, ShortAl, ByteAl, BoolAl) {
-}
-
-TargetMachine::TargetMachine(const std::string &name, const TargetData &TD)
-  : Name(name), DataLayout(TD) {
-}
 
 TargetMachine::TargetMachine(const std::string &name, const Module &M)
-  : Name(name), DataLayout(name, &M) {
+  : Name(name) {
 }
 
 TargetMachine::~TargetMachine() {
index f12ba51f1f3a96b437f55c2d05002f8ab6f28060..02df983fac7bc34351a3d34cff9fd69ab15a3637 100644 (file)
@@ -84,7 +84,7 @@ bool X86SharedAsmPrinter::doInitialization(Module &M) {
 }
 
 bool X86SharedAsmPrinter::doFinalization(Module &M) {
-  const TargetData &TD = TM.getTargetData();
+  const TargetData *TD = TM.getTargetData();
 
   // Print out module-level global variables here.
   for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
@@ -97,7 +97,7 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
     
     std::string name = Mang->getValueName(I);
     Constant *C = I->getInitializer();
-    unsigned Size = TD.getTypeSize(C->getType());
+    unsigned Size = TD->getTypeSize(C->getType());
     unsigned Align = getPreferredAlignmentLog(I);
 
     if (C->isNullValue() && /* FIXME: Verify correct */
index 9677645c01a326ceb5eb89a191db7829551f2429..7186fe51afcb68e01cfb7c45ce2d26780c15fe2a 100644 (file)
@@ -3522,7 +3522,7 @@ SDOperand X86TargetLowering::LowerMEMSET(SDOperand Op, SelectionDAG &DAG) {
   if ((Align & 3) != 0 ||
       (I && I->getValue() < Subtarget->getMinRepStrSizeThreshold())) {
     MVT::ValueType IntPtr = getPointerTy();
-    const Type *IntPtrTy = getTargetData().getIntPtrType();
+    const Type *IntPtrTy = getTargetData()->getIntPtrType();
     std::vector<std::pair<SDOperand, const Type*> > Args;
     Args.push_back(std::make_pair(Op.getOperand(1), IntPtrTy));
     // Extend the ubyte argument to be an int value for the call.
@@ -3655,7 +3655,7 @@ SDOperand X86TargetLowering::LowerMEMCPY(SDOperand Op, SelectionDAG &DAG) {
   if ((Align & 3) != 0 ||
       (I && I->getValue() < Subtarget->getMinRepStrSizeThreshold())) {
     MVT::ValueType IntPtr = getPointerTy();
-    const Type *IntPtrTy = getTargetData().getIntPtrType();
+    const Type *IntPtrTy = getTargetData()->getIntPtrType();
     std::vector<std::pair<SDOperand, const Type*> > Args;
     Args.push_back(std::make_pair(Op.getOperand(1), IntPtrTy));
     Args.push_back(std::make_pair(Op.getOperand(2), IntPtrTy));
index b9dea3bcf3059606089689c4bb440bdf321e7b87..4791f028ea99e4c6c0e053b422268ae952e95eab 100644 (file)
@@ -68,7 +68,8 @@ unsigned X86TargetMachine::getModuleMatchQuality(const Module &M) {
 /// X86TargetMachine ctor - Create an ILP32 architecture model
 ///
 X86TargetMachine::X86TargetMachine(const Module &M, const std::string &FS)
-  : TargetMachine("X86", true, 4, 4, 4, 4, 4),
+  : TargetMachine("X86"),
+    DataLayout("X86", true, 4, 4, 4, 4, 4),
     Subtarget(M, FS),
     FrameInfo(TargetFrameInfo::StackGrowsDown,
               Subtarget.getStackAlignment(), -4),
index 4ad0722354a17967056508f548b712283da24430..2fe01737788d3b85eb02fdd1612f1b07a2ca423b 100644 (file)
@@ -26,6 +26,7 @@
 namespace llvm {
 
 class X86TargetMachine : public TargetMachine {
+  const TargetData DataLayout;       // Calculates type size & alignment
   X86InstrInfo      InstrInfo;
   X86Subtarget      Subtarget;
   TargetFrameInfo   FrameInfo;
@@ -42,6 +43,7 @@ public:
   virtual const MRegisterInfo    *getRegisterInfo() const {
     return &InstrInfo.getRegisterInfo();
   }
+  virtual const TargetData       *getTargetData() const { return &DataLayout; }
 
   virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
                                           MachineCodeEmitter &MCE);
index d95aea77e674a282328633ee8b6b086086ff32bb..4d36e837e8dfc820d4f81398d95f5963c24e81c8 100644 (file)
@@ -143,7 +143,7 @@ int main(int argc, char **argv) {
     std::auto_ptr<TargetMachine> target(MArch->CtorFn(mod, FeaturesStr));
     assert(target.get() && "Could not allocate target machine!");
     TargetMachine &Target = *target.get();
-    const TargetData &TD = Target.getTargetData();
+    const TargetData *TD = Target.getTargetData();
 
     // Build up all of the passes that we want to do to the module...
     PassManager Passes;