[llvm-commits] [llvm] r55398 - in /llvm/trunk: include/llvm/CodeGen/FastISel.h lib/CodeGen/SelectionDAG/FastISel.cpp

Owen Anderson resistor at mac.com
Tue Aug 26 16:46:32 PDT 2008


Author: resistor
Date: Tue Aug 26 18:46:32 2008
New Revision: 55398

URL: http://llvm.org/viewvc/llvm-project?rev=55398&view=rev
Log:
Factor out a large amoutn of the cast handling code in fast isel into helper methods.
This simultaneously makes the code simpler and adds support for sext as well.

Modified:
    llvm/trunk/include/llvm/CodeGen/FastISel.h
    llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp

Modified: llvm/trunk/include/llvm/CodeGen/FastISel.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/FastISel.h?rev=55398&r1=55397&r2=55398&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/FastISel.h (original)
+++ llvm/trunk/include/llvm/CodeGen/FastISel.h Tue Aug 26 18:46:32 2008
@@ -170,6 +170,14 @@
 
   bool SelectBitCast(Instruction *I,
                      DenseMap<const Value*, unsigned> &ValueMap);
+  
+  bool SelectCast(Instruction *I, ISD::NodeType Opcode,
+                  DenseMap<const Value*, unsigned> &ValueMap);
+  
+  bool SelectConstantCast(Instruction *I, ISD::NodeType Opcode,
+                          DenseMap<const Value*, unsigned> &ValueMap);
+  bool SelectConstantFPCast(Instruction *I, ISD::NodeType Opcode,
+                            DenseMap<const Value*, unsigned> &ValueMap);
 };
 
 }

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp?rev=55398&r1=55397&r2=55398&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp Tue Aug 26 18:46:32 2008
@@ -149,6 +149,70 @@
   return true;
 }
 
+bool FastISel::SelectCast(Instruction *I, ISD::NodeType Opcode,
+                          DenseMap<const Value*, unsigned> &ValueMap) {
+  MVT SrcVT = MVT::getMVT(I->getOperand(0)->getType());
+  MVT DstVT = MVT::getMVT(I->getType());
+    
+  if (SrcVT == MVT::Other || !SrcVT.isSimple() ||
+      DstVT == MVT::Other || !DstVT.isSimple() ||
+      !TLI.isTypeLegal(SrcVT) || !TLI.isTypeLegal(DstVT))
+    // Unhandled type. Halt "fast" selection and bail.
+    return false;
+    
+  unsigned InputReg = ValueMap[I->getOperand(0)];
+  if (!InputReg)
+    // Unhandled operand.  Halt "fast" selection and bail.
+    return false;
+    
+  unsigned ResultReg = FastEmit_r(SrcVT.getSimpleVT(),
+                                  DstVT.getSimpleVT(),
+                                  Opcode,
+                                  InputReg);
+  if (!ResultReg)
+    return false;
+    
+  ValueMap[I] = ResultReg;
+  return true;
+}
+
+bool FastISel::SelectConstantCast(Instruction* I, ISD::NodeType Opcode,
+                                  DenseMap<const Value*, unsigned> &ValueMap) {
+  // Materialize constant and convert.
+  ConstantInt* CI = cast<ConstantInt>(I->getOperand(0));
+  MVT SrcVT = MVT::getMVT(CI->getType());
+  MVT DstVT = MVT::getMVT(I->getType());
+  
+  if (SrcVT == MVT::Other || !SrcVT.isSimple() ||
+      DstVT == MVT::Other || !DstVT.isSimple() ||
+      !TLI.isTypeLegal(SrcVT) || !TLI.isTypeLegal(DstVT))
+    // Unhandled type. Halt "fast" selection and bail.
+    return false;
+  
+  unsigned ResultReg1 = FastEmit_i(SrcVT.getSimpleVT(),
+                                   SrcVT.getSimpleVT(),
+                                   ISD::Constant, CI->getZExtValue());
+  if (!ResultReg1)
+    return false;
+  
+  unsigned ResultReg2 = FastEmit_r(SrcVT.getSimpleVT(),
+                                   DstVT.getSimpleVT(),
+                                   Opcode,
+                                   ResultReg1);
+  if (!ResultReg2)
+    return false;
+  
+  ValueMap[I] = ResultReg2;
+  return true;
+}
+
+bool FastISel::SelectConstantFPCast(Instruction* I, ISD::NodeType Opcode,
+                                  DenseMap<const Value*, unsigned> &ValueMap) {
+  // TODO: Implement casting of FP constants by materialization
+  // followed by conversion.
+  return false;
+}
+
 bool FastISel::SelectBitCast(Instruction *I,
                              DenseMap<const Value*, unsigned> &ValueMap) {
   // BitCast consists of either an immediate to register move
@@ -297,122 +361,32 @@
       break;
       
     case Instruction::BitCast:
-      if (!SelectBitCast(I, ValueMap)) return I;
-      break;
+      if (!SelectBitCast(I, ValueMap)) return I; break;
 
     case Instruction::FPToSI:
       if (!isa<ConstantFP>(I->getOperand(0))) {
-        MVT SrcVT = MVT::getMVT(I->getOperand(0)->getType());
-        MVT DstVT = MVT::getMVT(I->getType());
-        
-        if (SrcVT == MVT::Other || !SrcVT.isSimple() ||
-            DstVT == MVT::Other || !DstVT.isSimple() ||
-            !TLI.isTypeLegal(SrcVT) || !TLI.isTypeLegal(DstVT))
-          // Unhandled type. Halt "fast" selection and bail.
-          return I;
-        
-        unsigned InputReg = ValueMap[I->getOperand(0)];
-        if (!InputReg)
-          // Unhandled operand.  Halt "fast" selection and bail.
-          return I;
-        
-        unsigned ResultReg = FastEmit_r(SrcVT.getSimpleVT(),
-                                        DstVT.getSimpleVT(),
-                                        ISD::FP_TO_SINT,
-                                        InputReg);
-        if (!ResultReg)
-          return I;
-        
-        ValueMap[I] = ResultReg;
-        break;
+        if (!SelectCast(I, ISD::FP_TO_SINT, ValueMap)) return I; 
       } else
-        // TODO: Materialize the FP constant and then convert,
-        // or attempt constant folding.
-        return I;
-
+        if (!SelectConstantFPCast(I, ISD::FP_TO_SINT, ValueMap)) return I;
+      break;
     case Instruction::ZExt:
       if (!isa<ConstantInt>(I->getOperand(0))) {
-        MVT SrcVT = MVT::getMVT(I->getOperand(0)->getType());
-        MVT DstVT = MVT::getMVT(I->getType());
-        
-        if (SrcVT == MVT::Other || !SrcVT.isSimple() ||
-            DstVT == MVT::Other || !DstVT.isSimple() ||
-            !TLI.isTypeLegal(SrcVT) || !TLI.isTypeLegal(DstVT))
-          // Unhandled type. Halt "fast" selection and bail.
-          return I;
-        
-        unsigned InputReg = ValueMap[I->getOperand(0)];
-        if (!InputReg)
-          // Unhandled operand.  Halt "fast" selection and bail.
-          return I;
-        
-        unsigned ResultReg = FastEmit_r(SrcVT.getSimpleVT(),
-                                        DstVT.getSimpleVT(),
-                                        ISD::ZERO_EXTEND,
-                                        InputReg);
-        if (!ResultReg)
-          return I;
-        
-        ValueMap[I] = ResultReg;
-        break;
+        if (!SelectCast(I, ISD::ZERO_EXTEND, ValueMap)) return I;
       } else
-        // TODO: Support constant operands
-        return I;
-
+        if (!SelectConstantCast(I, ISD::ZERO_EXTEND, ValueMap)) return I;
+      break;
+    case Instruction::SExt:
+      if (!isa<ConstantInt>(I->getOperand(0))) {
+        if (!SelectCast(I, ISD::SIGN_EXTEND, ValueMap)) return I;
+      } else
+        if (!SelectConstantCast(I, ISD::SIGN_EXTEND, ValueMap)) return I;
+      break;
     case Instruction::SIToFP:
       if (!isa<ConstantInt>(I->getOperand(0))) {
-        MVT SrcVT = MVT::getMVT(I->getOperand(0)->getType());
-        MVT DstVT = MVT::getMVT(I->getType());
-        
-        if (SrcVT == MVT::Other || !SrcVT.isSimple() ||
-            DstVT == MVT::Other || !DstVT.isSimple() ||
-            !TLI.isTypeLegal(SrcVT) || !TLI.isTypeLegal(DstVT))
-          // Unhandled type. Halt "fast" selection and bail.
-          return I;
-        
-        unsigned InputReg = ValueMap[I->getOperand(0)];
-        if (!InputReg)
-          // Unhandled operan.  Halt "fast" selection and bail.
-          return I;
-        
-        unsigned ResultReg = FastEmit_r(SrcVT.getSimpleVT(),
-                                        DstVT.getSimpleVT(),
-                                        ISD::SINT_TO_FP,
-                                        InputReg);
-        if (!ResultReg)
-          return I;
-        
-        ValueMap[I] = ResultReg;
-        break;
-      } else {
-        // Materialize constant and convert to FP.
-        // TODO: Attempt constant folding?
-        ConstantInt* CI = cast<ConstantInt>(I->getOperand(0));
-        MVT SrcVT = MVT::getMVT(CI->getType());
-        MVT DstVT = MVT::getMVT(I->getType());
-        
-        if (SrcVT == MVT::Other || !SrcVT.isSimple() ||
-            DstVT == MVT::Other || !DstVT.isSimple() ||
-            !TLI.isTypeLegal(SrcVT) || !TLI.isTypeLegal(DstVT))
-          // Unhandled type. Halt "fast" selection and bail.
-          return I;
-        
-        unsigned ResultReg1 = FastEmit_i(SrcVT.getSimpleVT(),
-                                         SrcVT.getSimpleVT(),
-                                         ISD::Constant, CI->getZExtValue());
-        if (!ResultReg1)
-          return I;
-        
-        unsigned ResultReg2 = FastEmit_r(SrcVT.getSimpleVT(),
-                                         DstVT.getSimpleVT(),
-                                         ISD::SINT_TO_FP,
-                                         ResultReg1);
-        if (!ResultReg2)
-          return I;
-        
-        ValueMap[I] = ResultReg2;
-        break;
-      }
+        if (!SelectCast(I, ISD::SINT_TO_FP, ValueMap)) return I;
+      } else
+        if (!SelectConstantCast(I, ISD::SINT_TO_FP, ValueMap)) return I;
+      break;
 
     default:
       // Unhandled instruction. Halt "fast" selection and bail.





More information about the llvm-commits mailing list