[llvm-commits] CVS: llvm/lib/Target/PowerPC/PPCCodeEmitter.cpp PPCJITInfo.cpp PPCJITInfo.h PPCRelocations.h

Evan Cheng evan.cheng at apple.com
Thu Jul 27 11:20:46 PDT 2006



Changes in directory llvm/lib/Target/PowerPC:

PPCCodeEmitter.cpp updated: 1.64 -> 1.65
PPCJITInfo.cpp updated: 1.26 -> 1.27
PPCJITInfo.h updated: 1.11 -> 1.12
PPCRelocations.h updated: 1.8 -> 1.9
---
Log message:

Resolve BB references with relocation.

---
Diffs of the changes:  (+22 -27)

 PPCCodeEmitter.cpp |   12 ++++++++++--
 PPCJITInfo.cpp     |   31 ++++++++-----------------------
 PPCJITInfo.h       |    2 --
 PPCRelocations.h   |    4 ++++
 4 files changed, 22 insertions(+), 27 deletions(-)


Index: llvm/lib/Target/PowerPC/PPCCodeEmitter.cpp
diff -u llvm/lib/Target/PowerPC/PPCCodeEmitter.cpp:1.64 llvm/lib/Target/PowerPC/PPCCodeEmitter.cpp:1.65
--- llvm/lib/Target/PowerPC/PPCCodeEmitter.cpp:1.64	Tue Jul 25 15:40:54 2006
+++ llvm/lib/Target/PowerPC/PPCCodeEmitter.cpp	Thu Jul 27 13:20:32 2006
@@ -180,8 +180,16 @@
       MCE.addRelocation(MachineRelocation::getExtSym(MCE.getCurrentPCOffset(),
                                           Reloc, MO.getSymbolName(), 0));
   } else if (MO.isMachineBasicBlock()) {
-    unsigned* CurrPC = (unsigned*)(intptr_t)MCE.getCurrentPCValue();
-    TM.getJITInfo()->addBBRef(MO.getMachineBasicBlock(), (intptr_t)CurrPC);
+    unsigned Reloc = 0;
+    unsigned Opcode = MI.getOpcode();
+    if (Opcode == PPC::B || Opcode == PPC::BL || Opcode == PPC::BLA)
+      Reloc = PPC::reloc_pcrel_bx;
+    else
+      // BLT,BLE,BEQ,BGE,BGT,BNE, or other bcx instruction
+      Reloc = PPC::reloc_pcrel_bcx;
+    MCE.addRelocation(MachineRelocation::getBB(MCE.getCurrentPCOffset(),
+                                               Reloc,
+                                               MO.getMachineBasicBlock()));
   } else if (MO.isConstantPoolIndex() || MO.isJumpTableIndex()) {
     if (MO.isConstantPoolIndex())
       rv = MCE.getConstantPoolEntryAddress(MO.getConstantPoolIndex());


Index: llvm/lib/Target/PowerPC/PPCJITInfo.cpp
diff -u llvm/lib/Target/PowerPC/PPCJITInfo.cpp:1.26 llvm/lib/Target/PowerPC/PPCJITInfo.cpp:1.27
--- llvm/lib/Target/PowerPC/PPCJITInfo.cpp:1.26	Thu Jul 27 12:33:48 2006
+++ llvm/lib/Target/PowerPC/PPCJITInfo.cpp	Thu Jul 27 13:20:32 2006
@@ -206,6 +206,14 @@
              "Relocation out of range!");
       *RelocPos |= (ResultPtr & ((1 << 24)-1))  << 2;
       break;
+    case PPC::reloc_pcrel_bcx:
+      // PC-relative relocation for BLT,BLE,BEQ,BGE,BGT,BNE, or other
+      // bcx instructions.
+      ResultPtr = (ResultPtr-(intptr_t)RelocPos) >> 2;
+      assert(ResultPtr >= -(1 << 13) && ResultPtr < (1 << 13) &&
+             "Relocation out of range!");
+      *RelocPos |= (ResultPtr & ((1 << 14)-1))  << 2;
+      break;
     case PPC::reloc_absolute_ptr_high: // Pointer relocations.
     case PPC::reloc_absolute_ptr_low:
     case PPC::reloc_absolute_high:     // high bits of ref -> low 16 of instr
@@ -245,26 +253,3 @@
 void PPCJITInfo::replaceMachineCodeForFunction(void *Old, void *New) {
   EmitBranchToAt(Old, New, false);
 }
-
-void PPCJITInfo::resolveBBRefs(MachineCodeEmitter &MCE) {
-  // Resolve branches to BasicBlocks for the entire function
-  for (unsigned i = 0, e = BBRefs.size(); i != e; ++i) {
-    intptr_t Location = MCE.getMachineBasicBlockAddress(BBRefs[i].first);
-    unsigned *Ref = (unsigned *)BBRefs[i].second;
-    DEBUG(std::cerr << "Fixup @ " << (void*)Ref << " to " << (void*)Location
-                    << "\n");
-    unsigned Instr = *Ref;
-    intptr_t BranchTargetDisp = (Location - (intptr_t)Ref) >> 2;
-
-    switch (Instr >> 26) {
-    default: assert(0 && "Unknown branch user!");
-    case 18:  // This is B or BL
-      *Ref |= (BranchTargetDisp & ((1 << 24)-1)) << 2;
-      break;
-    case 16:  // This is BLT,BLE,BEQ,BGE,BGT,BNE, or other bcx instruction
-      *Ref |= (BranchTargetDisp & ((1 << 14)-1)) << 2;
-      break;
-    }
-  }
-  BBRefs.clear();
-}


Index: llvm/lib/Target/PowerPC/PPCJITInfo.h
diff -u llvm/lib/Target/PowerPC/PPCJITInfo.h:1.11 llvm/lib/Target/PowerPC/PPCJITInfo.h:1.12
--- llvm/lib/Target/PowerPC/PPCJITInfo.h:1.11	Thu Jul 27 12:33:48 2006
+++ llvm/lib/Target/PowerPC/PPCJITInfo.h	Thu Jul 27 13:20:32 2006
@@ -42,8 +42,6 @@
     /// code.
     ///
     virtual void replaceMachineCodeForFunction(void *Old, void *New);
-
-    virtual void resolveBBRefs(MachineCodeEmitter &MCE);
   };
 }
 


Index: llvm/lib/Target/PowerPC/PPCRelocations.h
diff -u llvm/lib/Target/PowerPC/PPCRelocations.h:1.8 llvm/lib/Target/PowerPC/PPCRelocations.h:1.9
--- llvm/lib/Target/PowerPC/PPCRelocations.h:1.8	Wed Jul 12 16:23:20 2006
+++ llvm/lib/Target/PowerPC/PPCRelocations.h	Thu Jul 27 13:20:32 2006
@@ -28,6 +28,10 @@
       // reloc_pcrel_bx - PC relative relocation, for the b or bl instructions.
       reloc_pcrel_bx,
 
+      // reloc_pcrel_bcx - PC relative relocation, for BLT,BLE,BEQ,BGE,BGT,BNE,
+      // and other bcx instructions.
+      reloc_pcrel_bcx,
+
       // reloc_absolute_high - Absolute relocation, for the loadhi instruction
       // (which is really addis).  Add the high 16-bits of the specified global
       // address into the low 16-bits of the instruction.






More information about the llvm-commits mailing list