Change from using MachineRelocation ctors to using static methods
authorChris Lattner <sabre@nondot.org>
Wed, 3 May 2006 20:30:20 +0000 (20:30 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 3 May 2006 20:30:20 +0000 (20:30 +0000)
in MachineRelocation to create Relocations.

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

include/llvm/CodeGen/MachineRelocation.h
lib/Target/Alpha/AlphaCodeEmitter.cpp
lib/Target/PowerPC/PPCCodeEmitter.cpp
lib/Target/X86/X86CodeEmitter.cpp

index c43fcb64e0c3cbe74da40b21a0892f2b3e9d6497..c23b999e2ec916755576b6a1c3bac6c39670aaea 100644 (file)
@@ -45,7 +45,7 @@ class MachineRelocation {
   
   /// Offset - This is the offset from the start of the code buffer of the
   /// relocation to perform.
-  unsigned Offset;
+  intptr_t Offset;
   
   /// ConstantVal - A field that may be used by the target relocation type.
   intptr_t ConstantVal;
@@ -64,35 +64,62 @@ class MachineRelocation {
   bool GOTRelative        : 1; // Should this relocation be relative to the GOT?
 
 public:
-  MachineRelocation(unsigned offset, unsigned RelocationType, GlobalValue *GV,
-                    intptr_t cst = 0, bool DoesntNeedFunctionStub = 0,
-                    bool GOTrelative = 0)
-    : Offset(offset), ConstantVal(cst), TargetReloType(RelocationType),
-      AddrType(isGV), DoesntNeedFnStub(DoesntNeedFunctionStub),
-      GOTRelative(GOTrelative){
+  /// MachineRelocation::getGV - Return a relocation entry for a GlobalValue.
+  ///
+  static MachineRelocation getGV(intptr_t offset, unsigned RelocationType, 
+                                 GlobalValue *GV, intptr_t cst = 0,
+                                 bool DoesntNeedFunctionStub = 0,
+                                 bool GOTrelative = 0) {
     assert((RelocationType & ~63) == 0 && "Relocation type too large!");
-    Target.GV = GV;
-  }
-
-  MachineRelocation(unsigned offset, unsigned RelocationType, const char *ES,
-                    intptr_t cst = 0, bool GOTrelative = 0)
-    : Offset(offset), ConstantVal(cst), TargetReloType(RelocationType),
-      AddrType(isExtSym), DoesntNeedFnStub(false), GOTRelative(GOTrelative) {
+    MachineRelocation Result;
+    Result.Offset = offset;
+    Result.ConstantVal = cst;
+    Result.TargetReloType = RelocationType;
+    Result.AddrType = isGV;
+    Result.DoesntNeedFnStub = DoesntNeedFunctionStub;
+    Result.GOTRelative = GOTrelative;
+    Result.Target.GV = GV;
+    return Result;
+  }
+
+  /// MachineRelocation::getExtSym - Return a relocation entry for an external
+  /// symbol, like "free".
+  ///
+  static MachineRelocation getExtSym(intptr_t offset, unsigned RelocationType, 
+                                     const char *ES, intptr_t cst = 0,
+                                     bool GOTrelative = 0) {
     assert((RelocationType & ~63) == 0 && "Relocation type too large!");
-    Target.ExtSym = ES;
-  }
-
-  MachineRelocation(unsigned offset, unsigned RelocationType, unsigned CPI,
-                    intptr_t cst = 0)
-    : Offset(offset), ConstantVal(cst), TargetReloType(RelocationType),
-      AddrType(isConstPool), DoesntNeedFnStub(false), GOTRelative(0) {
+    MachineRelocation Result;
+    Result.Offset = offset;
+    Result.ConstantVal = cst;
+    Result.TargetReloType = RelocationType;
+    Result.AddrType = isExtSym;
+    Result.DoesntNeedFnStub = false;
+    Result.GOTRelative = GOTrelative;
+    Result.Target.ExtSym = ES;
+    return Result;
+  }
+
+  /// MachineRelocation::getConstPool - Return a relocation entry for a constant
+  /// pool entry.
+  ///
+  static MachineRelocation getConstPool(intptr_t offset,unsigned RelocationType,
+                                        unsigned CPI, intptr_t cst = 0) {
     assert((RelocationType & ~63) == 0 && "Relocation type too large!");
-    Target.ConstPool = CPI;
+    MachineRelocation Result;
+    Result.Offset = offset;
+    Result.ConstantVal = cst;
+    Result.TargetReloType = RelocationType;
+    Result.AddrType = isConstPool;
+    Result.DoesntNeedFnStub = false;
+    Result.GOTRelative = false;
+    Result.Target.ConstPool = CPI;
+    return Result;
   }
 
   /// getMachineCodeOffset - Return the offset into the code buffer that the
   /// relocation should be performed.
-  unsigned getMachineCodeOffset() const {
+  intptr_t getMachineCodeOffset() const {
     return Offset;
   }
 
index cd033204e32d1d1098477cfe2167fc98508fbfaa..d8cf7df45f387b988fd10544fa98a49672c72764 100644 (file)
@@ -215,15 +215,15 @@ int AlphaCodeEmitter::getMachineOpValue(MachineInstr &MI, MachineOperand &MO) {
       abort();
     }
     if (MO.isGlobalAddress())
-      MCE.addRelocation(MachineRelocation((unsigned)MCE.getCurrentPCOffset(),
+      MCE.addRelocation(MachineRelocation::getGV(MCE.getCurrentPCOffset(),
                                           Reloc, MO.getGlobal(), Offset,
                                           false, useGOT));
     else if (MO.isExternalSymbol())
-      MCE.addRelocation(MachineRelocation((unsigned)MCE.getCurrentPCOffset(),
+      MCE.addRelocation(MachineRelocation::getExtSym(MCE.getCurrentPCOffset(),
                                           Reloc, MO.getSymbolName(), Offset,
                                           true));
     else
-      MCE.addRelocation(MachineRelocation((unsigned)MCE.getCurrentPCOffset(),
+    MCE.addRelocation(MachineRelocation::getConstPool(MCE.getCurrentPCOffset(),
                                           Reloc, MO.getConstantPoolIndex(),
                                           Offset));
   } else if (MO.isMachineBasicBlock()) {
index 9be0f1041c06043a50dd92eb16de36598ffd3bbd..a530b1e32f219d9311fe012daa33ac784a87d3a2 100644 (file)
@@ -180,10 +180,10 @@ int PPCCodeEmitter::getMachineOpValue(MachineInstr &MI, MachineOperand &MO) {
       }
     }
     if (MO.isGlobalAddress())
-      MCE.addRelocation(MachineRelocation(MCE.getCurrentPCOffset(),
+      MCE.addRelocation(MachineRelocation::getGV(MCE.getCurrentPCOffset(),
                                           Reloc, MO.getGlobal(), 0));
     else
-      MCE.addRelocation(MachineRelocation(MCE.getCurrentPCOffset(),
+      MCE.addRelocation(MachineRelocation::getExtSym(MCE.getCurrentPCOffset(),
                                           Reloc, MO.getSymbolName(), 0));
   } else if (MO.isMachineBasicBlock()) {
     unsigned* CurrPC = (unsigned*)(intptr_t)MCE.getCurrentPCValue();
index d0f76931fb69b07ae16858ca6892731948d8daa6..37c60bdbc7a55b5ede1631acf9d3c9584e5c32e9 100644 (file)
@@ -123,7 +123,7 @@ void Emitter::emitPCRelativeBlockAddress(MachineBasicBlock *MBB) {
 /// assuming this is part of a function call, which is PC relative.
 ///
 void Emitter::emitGlobalAddressForCall(GlobalValue *GV, bool isTailCall) {
-  MCE.addRelocation(MachineRelocation(MCE.getCurrentPCOffset(),
+  MCE.addRelocation(MachineRelocation::getGV(MCE.getCurrentPCOffset(),
                                       X86::reloc_pcrel_word, GV, 0,
                                       !isTailCall /*Doesn'tNeedStub*/));
   MCE.emitWordLE(0);
@@ -134,7 +134,7 @@ void Emitter::emitGlobalAddressForCall(GlobalValue *GV, bool isTailCall) {
 /// PC relative.
 ///
 void Emitter::emitGlobalAddressForPtr(GlobalValue *GV, int Disp /* = 0 */) {
-  MCE.addRelocation(MachineRelocation(MCE.getCurrentPCOffset(),
+  MCE.addRelocation(MachineRelocation::getGV(MCE.getCurrentPCOffset(),
                                       X86::reloc_absolute_word, GV));
   MCE.emitWordLE(Disp); // The relocated value will be added to the displacement
 }
@@ -144,7 +144,7 @@ void Emitter::emitGlobalAddressForPtr(GlobalValue *GV, int Disp /* = 0 */) {
 /// relative.
 void Emitter::emitExternalSymbolAddress(const char *ES, bool isPCRelative,
                                         bool isTailCall) {
-  MCE.addRelocation(MachineRelocation(MCE.getCurrentPCOffset(),
+  MCE.addRelocation(MachineRelocation::getExtSym(MCE.getCurrentPCOffset(),
           isPCRelative ? X86::reloc_pcrel_word : X86::reloc_absolute_word, ES));
   MCE.emitWordLE(0);
 }