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

Brian Gaeke gaeke at cs.uiuc.edu
Fri Jun 25 01:09:14 PDT 2004


Changes in directory reopt/lib/LightWtProfiling:

UnpackTraceFunction.cpp updated: 1.86 -> 1.87

---
Log message:

Make copyConstantToRegister smarter enough so that it can do double constants.
(This is a first, untested draft.)


---
Diffs of the changes:  (+59 -12)

Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.86 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.87
--- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.86	Wed Jun 23 15:06:34 2004
+++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp	Fri Jun 25 01:07:40 2004
@@ -260,28 +260,75 @@
   }
 }
 
+static void regAllocConstORi (std::vector<MachineInstr *> &mvec, unsigned DestReg, unsigned SpareReg) { 
+  MachineInstr &theInst = *mvec.back();
+  assert (theInst.getOpcode () == V9::ORi
+          && theInst.getNumOperands () == 3
+          && theInst.getOperand (2).isDef ()
+          && theInst.getOperand (2).getType () == MachineOperand::MO_VirtualRegister
+          && "wrong machineInstr passed to regAllocConstORi");
+  theInst.SetRegForOperand (2, DestReg);
+}
+
+// sethi %hh(<cp#0>), %A<d>
+// or    %A, %hm(<cp#0>), %A<d>
+// sllx  %A, 32, %A<d>
+// sethi %lm(<cp#0>), %B<d>
+// or    %B, %A, %B<d>
+// or    %B, %lo(<cp#0>), %B<d>
+// ldd   %B, 0, %C<d>
+static void regAllocConstLDDFi (std::vector<MachineInstr *> &mvec,  unsigned DestReg, unsigned SpareReg) {
+  std::vector<MachineInstr *>::iterator first = mvec.begin (),
+  last = mvec.end ();
+  Value *TopHalfVReg = (*first)->getOperand(1).getVRegValue (),
+    *BottomHalfVReg = (*last)->getOperand (0).getVRegValue (),
+    *DestVReg = (*last)->getOperand (2).getVRegValue ();
+  
+  for (std::vector<MachineInstr *>::iterator i = first; i != last; ++i) {
+    MachineInstr &MInst = **i;
+    for (unsigned opNum=0, last=MInst.getNumOperands (); opNum != last;
+         ++opNum) {
+      MachineOperand &Op = MInst.getOperand (opNum);
+      if (Op.getType() == MachineOperand::MO_VirtualRegister) {
+        const Value *const Val = Op.getVRegValue();
+        
+        if (Val == DestVReg || Val == BottomHalfVReg)
+          MInst.SetRegForOperand (opNum, DestReg);
+        else if (Val == TopHalfVReg)
+          MInst.SetRegForOperand (opNum, SpareReg);
+        else
+          assert (0 && "Unknown virtual register found in regAllocConstLDDFi");
+      }
+    }
+  }
+}
+
 void UnpackTraceFunction::copyConstantToRegister (MachineFunction &MF,
                                                   Constant *C, unsigned Reg,
+                                                  unsigned SpareReg,
                                                   std::vector<MachineInstr *> &mvec) {
   const TargetInstrInfo &TII = *TM->getInstrInfo ();
   TmpInstruction *tmp = new TmpInstruction (C);
   TII.CreateCodeToLoadConst (*TM, const_cast<Function *> (MF.getFunction ()), C, tmp, mvec,
                              MachineCodeForInstruction::get (tmp));
+                             
   DEBUG (for (std::vector<MachineInstr *>::iterator i = mvec.begin (), e = mvec.end ();
-       i != e; ++i)
-    std::cerr << "copyConstantToRegister Input: " << **i << "\n");
-  assert (mvec.size() == 1);
-  MachineInstr &theInst = *mvec.back();
+              i != e; ++i)
+         std::cerr << "copyConstantToRegister Input: " << **i << "\n");
+         
   // note: this is pretty seriously hardwired for now. the problem is that in full
   // generality, this is a little tiny episode of register allocation
-  assert (theInst.getOpcode () == V9::ORi
-          && theInst.getNumOperands () == 3
-          && theInst.getOperand (2).isDef ()
-          && theInst.getOperand (2).getType () == MachineOperand::MO_VirtualRegister);
-  theInst.SetRegForOperand (2, Reg);
+  if (mvec.size() == 1 && mvec.back()->getOpcode() == V9::ORi) {
+    regAllocConstORi (mvec,Reg,SpareReg);
+  } else if (mvec.size() == 7 && mvec.back()->getOpcode() == V9::LDDFi) {
+    regAllocConstLDDFi (mvec,Reg,SpareReg);
+  } else {
+    assert (0 && "unknown sequence coming out of CreateCodeToLoadConst");
+  }
+  
   DEBUG (for (std::vector<MachineInstr *>::iterator i = mvec.begin (), e = mvec.end ();
-       i != e; ++i)
-    std::cerr << "copyConstantToRegister Output: " << **i << "\n");
+              i != e; ++i)
+         std::cerr << "copyConstantToRegister Output: " << **i << "\n");
 }
 
 void UnpackTraceFunction::addLiveOutCopy (MachineFunction &MF, MachineBasicBlock &MBB,
@@ -303,7 +350,7 @@
     assert (liveOutValue);
     assert (isa<Constant> (liveOutTraceValue)
             && "Can't handle non-constant, non-allocated live-out value in traceFn");
-    copyConstantToRegister (MF, cast<Constant> (liveOutTraceValue), g1, mvec);
+    copyConstantToRegister (MF, cast<Constant> (liveOutTraceValue), g1, g2, mvec);
     unsigned R = g1;
     unsigned RegType = TRI.getRegType (R);
     DEBUG (std::cerr << "addLiveOutCopy: " << liveOutValue->getName()





More information about the llvm-commits mailing list