[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp

Chris Lattner lattner at cs.uiuc.edu
Fri Aug 19 13:45:54 PDT 2005



Changes in directory llvm/lib/CodeGen/SelectionDAG:

ScheduleDAG.cpp updated: 1.4 -> 1.5
---
Log message:

Now that we have operand info for machine instructions, use it to create
temporary registers for things that define a register.  This allows dag->dag
isel to compile this:

int %test() { ret int 65535 }

into:

_test:
        lis r2, 0
        ori r2, r2, 65535
        blr

Next up, getting CopyFromReg to work, allowing arguments and cross-bb values.



---
Diffs of the changes:  (+21 -8)

 ScheduleDAG.cpp |   29 +++++++++++++++++++++--------
 1 files changed, 21 insertions(+), 8 deletions(-)


Index: llvm/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp:1.4 llvm/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp:1.5
--- llvm/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp:1.4	Thu Aug 18 20:01:34 2005
+++ llvm/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp	Fri Aug 19 15:45:43 2005
@@ -13,8 +13,10 @@
 //===----------------------------------------------------------------------===//
 
 #define DEBUG_TYPE "sched"
+#include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/CodeGen/SelectionDAGISel.h"
 #include "llvm/CodeGen/SelectionDAG.h"
+#include "llvm/CodeGen/SSARegMap.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetInstrInfo.h"
 #include "llvm/Support/CommandLine.h"
@@ -34,11 +36,13 @@
     MachineBasicBlock *BB;
     const TargetMachine &TM;
     const TargetInstrInfo &TII;
+    SSARegMap *RegMap;
     
     std::map<SDNode *, unsigned> EmittedOps;
   public:
     SimpleSched(SelectionDAG &D, MachineBasicBlock *bb)
-      : DAG(D), BB(bb), TM(D.getTarget()), TII(*TM.getInstrInfo()) {
+      : DAG(D), BB(bb), TM(D.getTarget()), TII(*TM.getInstrInfo()),
+        RegMap(BB->getParent()->getSSARegMap()) {
       assert(&TII && "Target doesn't provide instr info?");
     }
     
@@ -73,14 +77,14 @@
     // Target nodes have any register or immediate operands before any chain
     // nodes.  Check that the DAG matches the TD files's expectation of #
     // operands.
+    unsigned NumResults = Op.Val->getNumValues();
+    if (NumResults && Op.getOperand(NumResults-1).getValueType() == MVT::Other)
+      --NumResults;
 #ifndef _NDEBUG
     unsigned Operands = Op.getNumOperands();
     if (Operands && Op.getOperand(Operands-1).getValueType() == MVT::Other)
       --Operands;
-    unsigned Results = Op.Val->getNumValues();
-    if (Results && Op.getOperand(Results-1).getValueType() == MVT::Other)
-      --Results;
-    assert(unsigned(II.numOperands) == Operands+Results &&
+    assert(unsigned(II.numOperands) == Operands+NumResults &&
            "#operands for dag node doesn't match .td file!"); 
 #endif
 
@@ -89,9 +93,18 @@
     
     // Add result register values for things that are defined by this
     // instruction.
-    assert(Op.Val->getNumValues() == 1 &&
-           Op.getValue(0).getValueType() == MVT::Other &&
-           "Return values not implemented yet");
+    if (NumResults) {
+      // Create the result registers for this node and add the result regs to
+      // the machine instruction.
+      const TargetOperandInfo *OpInfo = II.OpInfo;
+      ResultReg = RegMap->createVirtualRegister(OpInfo[0].RegClass);
+      MI->addRegOperand(ResultReg, MachineOperand::Def);
+      for (unsigned i = 1; i != NumResults; ++i) {
+        assert(OpInfo[i].RegClass && "Isn't a register operand!");
+        MI->addRegOperand(RegMap->createVirtualRegister(OpInfo[0].RegClass),
+                          MachineOperand::Def);
+      }
+    }
     
     // Emit all of the operands of this instruction, adding them to the
     // instruction as appropriate.






More information about the llvm-commits mailing list