[llvm-commits] CVS: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp

Brian Gaeke gaeke at cs.uiuc.edu
Sun May 30 03:45:06 PDT 2004


Changes in directory reopt/lib/LightWtProfiling:

UnpackTraceFunction.cpp updated: 1.73 -> 1.74

---
Log message:

Bunch of simple clean-ups...

Fold insertBranchMachineInstrs() into its only call-site.

Move def of getValueAllocState below its helper functions.  Remove forward
decls of its helper functions.  Untabify portions of
getValueAllocStateFromModule().  Fix an incorrect comment in
getValueAllocStateFromGlobal().  Add forward decl of getValueAllocState() just
before rewriteProlog().

Remove unnecessary parens from stackOffsetForReg().

Use three-operand form of BuildMI(MBB,...) instead of
MBB.push_back(BuildMI(...)).


---
Diffs of the changes:  (+35 -52)

Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.73 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.74
--- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.73	Wed May 26 04:43:49 2004
+++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp	Sun May 30 03:43:11 2004
@@ -114,25 +114,6 @@
     B.push_back (*i);
 }
 
-/// Append to B a branch from the end of B to TargetAddr.
-///
-void UnpackTraceFunction::insertBranchMachineInstrs (uint64_t Target,
-                                                     MachineBasicBlock &B) {
-  // If the target is close enough to fit into the 19-bit disp of a "ba"
-  // instruction, then we really DO get a "ba" instruction.  We get the backend
-  // to calculate the PC-relative address from the absolute address upon
-  // emitting it to memory, by handing it a Constant and telling the backend
-  // it's a PC-relative MachineOperand. If the target is NOT close enough to
-  // fit in a "ba" instruction, the SparcV9CodeEmitter will automatically turn
-  // it into an indirect jump through a register.
-  
-  // ba <target>
-  Constant *TargetAsConstant = (ConstantUInt::get (Type::ULongTy, Target));
-  B.push_back (BuildMI (V9::BA, 1).addPCDisp (TargetAsConstant));
-  // nop
-  B.push_back (BuildMI (V9::NOP, 0));
-}
-
 /// Returns a pointer to the return instruction in B, if B contains
 /// one, or null otherwise.
 ///
@@ -147,9 +128,6 @@
   return 0;
 }
 
-static AllocInfo getValueAllocStateFromModule (Function *F, Value *V);
-static AllocInfo getValueAllocStateFromGlobal (Function *F, Value *V);
-
 /// Fill in the set of registers used in this function, which is kept in
 /// 'RegsToRestore' in the UnpackTraceFunction Pass object, and is used by
 /// rewriteProlog() and rewriteEpilog(). Registers are
@@ -200,20 +178,14 @@
         std::cerr << " )\n");
 }
 
-/// getValueAllocState - Returns a pair <MatrixState,TraceState> containing the
-/// saved register allocator state for a value.
-///
-static std::pair<AllocInfo, AllocInfo>
-getValueAllocState (TraceFunction *TF, Value *V, bool preferLiveIn = true) {
-  return std::make_pair (getValueAllocStateFromModule (TF->MatrixFn, V),
-    getValueAllocStateFromGlobal (TF->TraceFn,
-                                  TF->getCorrespondingValue (V, preferLiveIn)));
-}
 
 unsigned UnpackTraceFunction::stackOffsetForReg (unsigned R) {
-  return (2047 + StaticStackSize + 176 + (R) * 8);
+  return 2047 + StaticStackSize + 176 + R * 8;
 }
 
+static std::pair<AllocInfo, AllocInfo>
+getValueAllocState (TraceFunction *TF, Value *V, bool preferLiveIn = true);
+
 void UnpackTraceFunction::rewriteProlog (MachineFunction &MF,
                                          MachineBasicBlock &E) {
   const TargetRegInfo &TRI = TM->getRegInfo ();
@@ -226,12 +198,12 @@
   E.clear ();
 
   // 0. Save caller's stack pointer in %g1.
-  E.push_back (BuildMI (V9::ORr, 3).addMReg (sp).addZImm (0).addMReg (g1,
-    MachineOperand::Def));
+  BuildMI (&E, V9::ORr, 3).addMReg (sp).addZImm (0)
+    .addMReg (g1, MachineOperand::Def);
 
   // 1. Emit ADD instruction to allocate the right amount of stack space.
-  E.push_back (BuildMI (V9::ADDi, 3).addMReg (sp).addSImm (-TotalStackSize)
-    .addMReg (sp, MachineOperand::Def));
+  BuildMI (&E, V9::ADDi, 3).addMReg (sp).addSImm (-TotalStackSize)
+    .addMReg (sp, MachineOperand::Def);
 
   // 2. Get the saved register allocator state for all live-in variables.
   // We are going to need to save live-in values which reside in registers
@@ -280,8 +252,8 @@
   }
 
   // Caller's stack pointer becomes our frame pointer.
-  E.push_back (BuildMI (V9::ORr, 3).addMReg (g1).addZImm (0).addMReg (fp,
-    MachineOperand::Def));
+  BuildMI (&E, V9::ORr, 3).addMReg (g1).addZImm (0)
+    .addMReg (fp, MachineOperand::Def);
 
   // 4. Insert a copy for each live-in variable to copy it from the stack
   // to the register that was allocated for it in the TraceFn.
@@ -392,16 +364,15 @@
   // _llvm_regAllocState.functions[FI] for a tuple that starts with
   // (InstructionKey, OperandKey, ...):
   for (unsigned i = 0; i < FAllocState->numTuples; ++i) {
-	OperandAllocState &T = FAllocState->tuples[i];
-        if (T.Instruction == InstructionKey && T.Operand == OperandKey) {
-          AllocInfo AI (T.Instruction, T.Operand,
-                        (AllocInfo::AllocStateTy) T.AllocState, T.Placement);
-          DEBUG (std::cerr << "Alloc state saved in module for "
-                 << F->getName () << ":" << V->getName () << " (key = "
-                 << InstructionKey << "," << OperandKey << ") is " << AI
-                 << "\n");
-          return AI;
-        }
+    OperandAllocState &T = FAllocState->tuples[i];
+    if (T.Instruction == InstructionKey && T.Operand == OperandKey) {
+      AllocInfo AI (T.Instruction, T.Operand,
+                    (AllocInfo::AllocStateTy) T.AllocState, T.Placement);
+      DEBUG (std::cerr << "Alloc state saved in module for " << F->getName ()
+             << ":" << V->getName () << " (key = " << InstructionKey << ","
+             << OperandKey << ") is " << AI << "\n");
+      return AI;
+    }
   }
   // By this time we had better have found it, otherwise we are about to do bad
   // things.
@@ -431,7 +402,7 @@
       abort ();
     }
     // Figure out the indices (VI, VO) that can be used to look up V,
-    // which is an operand of some instruction in F, in FState:
+    // which is some instruction producing a value in F, in FState:
     Instruction *Instr = cast<Instruction> (V);
     InstructionKey = getSavedStateIndexOfInstruction (F, Instr);
   }
@@ -454,6 +425,16 @@
   abort ();
 }
 
+/// getValueAllocState - Returns a pair <MatrixState,TraceState> containing the
+/// saved register allocator state for a value.
+///
+static std::pair<AllocInfo, AllocInfo>
+getValueAllocState (TraceFunction *TF, Value *V, bool preferLiveIn) {
+  return std::make_pair (getValueAllocStateFromModule (TF->MatrixFn, V),
+    getValueAllocStateFromGlobal (TF->TraceFn,
+                                  TF->getCorrespondingValue (V, preferLiveIn)));
+}
+
 void UnpackTraceFunction::rewriteEpilog (MachineFunction &MF,
                                          MachineBasicBlock &MBB) {
   const TargetRegInfo &TRI = TM->getRegInfo ();
@@ -518,8 +499,8 @@
   }
 
   // Restore stack pointer.
-  MBB.push_back (BuildMI (V9::ADDi, 3).addMReg (sp).addSImm (TotalStackSize)
-    .addMReg (sp, MachineOperand::Def));
+  BuildMI (&MBB, V9::ADDi, 3).addMReg (sp).addSImm (TotalStackSize)
+    .addMReg (sp, MachineOperand::Def);
 
   // Let ReturnAddress be the address in memory of the compiled
   // code for the MachineBasicBlock in MatrixF that RI would have
@@ -537,7 +518,9 @@
          << " 0x" << std::hex << BlockAddrs.first << ", end of block = 0x"
          << BlockAddrs.second << std::dec << "\n");
   // Insert a branch back to the return BasicBlock of the matrix fn.
-  insertBranchMachineInstrs (ReturnAddress, MBB);
+  BuildMI (&MBB, V9::BA, 1)
+    .addPCDisp (ConstantUInt::get (Type::ULongTy, ReturnAddress));
+  BuildMI (&MBB, V9::NOP, 0);
 }
 
 /// runOnMachineFunction - Prepare MF, which is the machine code for





More information about the llvm-commits mailing list