[llvm-commits] CVS: llvm/lib/Target/Sparc/SparcV9CodeEmitter.cpp

Brian Gaeke gaeke at cs.uiuc.edu
Fri Oct 17 13:28:13 PDT 2003


Changes in directory llvm/lib/Target/Sparc:

SparcV9CodeEmitter.cpp updated: 1.35 -> 1.36

---
Log message:

Refactor jump insertion code from CompilationCallback() into insertJumpAtAddr().
Make insertFarJumpAtAddr() return void, because nothing uses its return value.
Remove some commented-out code.
Implement replaceMachineCodeForFunction() for SPARC.


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

Index: llvm/lib/Target/Sparc/SparcV9CodeEmitter.cpp
diff -u llvm/lib/Target/Sparc/SparcV9CodeEmitter.cpp:1.35 llvm/lib/Target/Sparc/SparcV9CodeEmitter.cpp:1.36
--- llvm/lib/Target/Sparc/SparcV9CodeEmitter.cpp:1.35	Mon Oct 13 14:51:20 2003
+++ llvm/lib/Target/Sparc/SparcV9CodeEmitter.cpp	Fri Oct 17 13:27:37 2003
@@ -88,7 +88,8 @@
       return SparcV9.getBinaryCodeForInstr(MI);
     }
 
-    inline uint64_t insertFarJumpAtAddr(int64_t Value, uint64_t Addr);
+    inline void insertFarJumpAtAddr(int64_t Value, uint64_t Addr);
+    void insertJumpAtAddr(int64_t Value, uint64_t &Addr);
 
   private:
     uint64_t emitStubForFunction(Function *F);
@@ -138,15 +139,34 @@
   std::map<Function*, uint64_t>::iterator I = LazyResolverMap.lower_bound(F);
   if (I != LazyResolverMap.end() && I->first == F) return I->second;
   
-//std::cerr << "Getting lazy resolver for : " << ((Value*)F)->getName() << "\n";
-
   uint64_t Stub = emitStubForFunction(F);
   LazyResolverMap.insert(I, std::make_pair(F, Stub));
   return Stub;
 }
 
-uint64_t JITResolver::insertFarJumpAtAddr(int64_t Target, uint64_t Addr) {
+void JITResolver::insertJumpAtAddr(int64_t JumpTarget, uint64_t &Addr) {
+  DEBUG(std::cerr << "Emitting a jump to 0x" << std::hex << JumpTarget << "\n");
+
+  // If the target function is close enough to fit into the 19bit disp of
+  // BA, we should use this version, as it's much cheaper to generate.
+  int64_t BranchTarget = (JumpTarget-Addr) >> 2;
+  if (BranchTarget >= (1 << 19) || BranchTarget <= -(1 << 19)) {
+    TheJITResolver->insertFarJumpAtAddr(JumpTarget, Addr);
+  } else {
+    // ba <target>
+    MachineInstr *I = BuildMI(V9::BA, 1).addSImm(BranchTarget);
+    *((unsigned*)(intptr_t)Addr) = getBinaryCodeForInstr(*I);
+    Addr += 4;
+    delete I;
+
+    // nop
+    I = BuildMI(V9::NOP, 0);
+    *((unsigned*)(intptr_t)Addr) = getBinaryCodeForInstr(*I);
+    delete I;
+  }
+}
 
+void JITResolver::insertFarJumpAtAddr(int64_t Target, uint64_t Addr) {
   static const unsigned 
     o6 = SparcIntRegClass::o6, g0 = SparcIntRegClass::g0,
     g1 = SparcIntRegClass::g1, g5 = SparcIntRegClass::g5;
@@ -178,8 +198,6 @@
     delete BinaryCode[i];
     Addr += 4;
   }
-
-  return Addr;
 }
 
 void JITResolver::SaveRegisters(uint64_t DoubleFP[], uint64_t &FSR, 
@@ -350,27 +368,8 @@
     std::cerr << "About to overwrite smthg not a save instr!";
     abort();
   }
-  DEBUG(std::cerr << "Emitting a jump to 0x" << std::hex << Target << "\n");
-
-  // If the target function is close enough to fit into the 19bit disp of
-  // BA, we should use this version, as its much cheaper to generate.
-  int64_t BranchTarget = (Target-CodeBegin) >> 2;
-  if (BranchTarget >= (1 << 19) || BranchTarget <= -(1 << 19)) {
-    TheJITResolver->insertFarJumpAtAddr(Target, CodeBegin);
-  } else {
-    // ba <target>
-    MachineInstr *I = BuildMI(V9::BA, 1).addSImm(BranchTarget);
-    *((unsigned*)(intptr_t)CodeBegin) = 
-      TheJITResolver->getBinaryCodeForInstr(*I);
-    CodeBegin += 4;
-    delete I;
-
-    // nop
-    I = BuildMI(V9::NOP, 0);
-    *((unsigned*)(intptr_t)CodeBegin) = 
-      TheJITResolver->getBinaryCodeForInstr(*I);
-    delete I;
-  }
+  // Overwrite it
+  TheJITResolver->insertJumpAtAddr(Target, CodeBegin);
 
   RestoreRegisters(DoubleFP, FSR, FPRS, CCR);
 
@@ -563,6 +562,13 @@
   }
 }
 
+bool UltraSparc::replaceMachineCodeForFunction (void *Old, void *New) {
+  if (!TheJITResolver) return true; // fail if not in JIT.
+  uint64_t Target = (uint64_t)(intptr_t)New;
+  uint64_t CodeBegin = (uint64_t)(intptr_t)Old;
+  TheJITResolver->insertJumpAtAddr(Target, CodeBegin);
+  return false;
+}
 
 int64_t SparcV9CodeEmitter::getMachineOpValue(MachineInstr &MI,
                                               MachineOperand &MO) {





More information about the llvm-commits mailing list