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

Nate Begeman natebegeman at mac.com
Mon Dec 5 22:19:07 PST 2005



Changes in directory llvm/lib/CodeGen/SelectionDAG:

LegalizeDAG.cpp updated: 1.222 -> 1.223
SelectionDAG.cpp updated: 1.222 -> 1.223
SelectionDAGISel.cpp updated: 1.110 -> 1.111
---
Log message:

Teach the SelectionDAG ISel how to turn ConstantPacked values into 
constant nodes with vector types.  Also teach the asm printer how to print
ConstantPacked constant pool entries.  This allows us to generate altivec
code such as the following, which adds a vector constantto a packed float.

LCPI1_0:  <4 x float> < float 0.0e+0, float 0.0e+0, float 0.0e+0, float 1.0e+0 >
        .space  4
        .space  4
        .space  4
        .long   1065353216      ; float 1
        .text
        .align  4
        .globl  _foo
_foo:
        lis r2, ha16(LCPI1_0)
        la r2, lo16(LCPI1_0)(r2)
        li r4, 0
        lvx v0, r4, r2
        lvx v1, r4, r3
        vaddfp v0, v1, v0
        stvx v0, r4, r3
        blr

For the llvm code:

void %foo(<4 x float> * %a) {
entry:
  %tmp1 = load <4 x float> * %a;
  %tmp2 = add <4 x float> %tmp1, < float 0.0, float 0.0, float 0.0, float 1.0 >
  store <4 x float> %tmp2, <4 x float> *%a
  ret void
}



---
Diffs of the changes:  (+54 -5)

 LegalizeDAG.cpp      |   26 ++++++++++++++++++++++++++
 SelectionDAG.cpp     |    3 +--
 SelectionDAGISel.cpp |   30 +++++++++++++++++++++++++++---
 3 files changed, 54 insertions(+), 5 deletions(-)


Index: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.222 llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.223
--- llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.222	Fri Dec  2 00:08:08 2005
+++ llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp	Tue Dec  6 00:18:55 2005
@@ -690,6 +690,32 @@
     }
     break;
   }
+  case ISD::ConstantVec: {
+    // We assume that vector constants are not legal, and will be immediately
+    // spilled to the constant pool.
+    //
+    // FIXME: revisit this when we have some kind of mechanism by which targets
+    // can decided legality of vector constants, of which there may be very
+    // many.
+    //
+    // Create a ConstantPacked, and put it in the constant pool.
+    std::vector<Constant*> CV;
+    MVT::ValueType VT = Node->getValueType(0);
+    for (unsigned I = 0, E = Node->getNumOperands(); I < E; ++I) {
+      SDOperand OpN = Node->getOperand(I);
+      const Type* OpNTy = MVT::getTypeForValueType(OpN.getValueType());
+      if (MVT::isFloatingPoint(VT))
+        CV.push_back(ConstantFP::get(OpNTy, 
+                                     cast<ConstantFPSDNode>(OpN)->getValue()));
+      else
+        CV.push_back(ConstantUInt::get(OpNTy,
+                                       cast<ConstantSDNode>(OpN)->getValue()));
+    }
+    Constant *CP = ConstantPacked::get(CV);
+    SDOperand CPIdx = DAG.getConstantPool(CP, Node->getValueType(0));
+    Result = DAG.getLoad(VT, DAG.getEntryNode(), CPIdx, DAG.getSrcValue(NULL));
+    break;
+  }
   case ISD::TokenFactor:
     if (Node->getNumOperands() == 2) {
       bool Changed = false;


Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.222 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.223
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.222	Thu Dec  1 17:14:50 2005
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp	Tue Dec  6 00:18:55 2005
@@ -501,8 +501,6 @@
   return SDOperand(N, 0);
 }
 
-
-
 SDOperand SelectionDAG::getGlobalAddress(const GlobalValue *GV,
                                          MVT::ValueType VT, int offset) {
   SDNode *&N = GlobalValues[std::make_pair(GV, offset)];
@@ -1837,6 +1835,7 @@
   case ISD::Constant:      return "Constant";
   case ISD::TargetConstant: return "TargetConstant";
   case ISD::ConstantFP:    return "ConstantFP";
+  case ISD::ConstantVec:   return "ConstantVec";
   case ISD::GlobalAddress: return "GlobalAddress";
   case ISD::TargetGlobalAddress: return "TargetGlobalAddress";
   case ISD::FrameIndex:    return "FrameIndex";


Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.110 llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.111
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.110	Mon Dec  5 01:10:48 2005
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp	Tue Dec  6 00:18:55 2005
@@ -282,7 +282,8 @@
     SDOperand &N = NodeMap[V];
     if (N.Val) return N;
 
-    MVT::ValueType VT = TLI.getValueType(V->getType());
+    const Type *VTy = V->getType();
+    MVT::ValueType VT = TLI.getValueType(VTy);
     if (Constant *C = const_cast<Constant*>(dyn_cast<Constant>(V)))
       if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
         visit(CE->getOpcode(), *CE);
@@ -296,6 +297,30 @@
         return N = DAG.getNode(ISD::UNDEF, VT);
       } else if (ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
         return N = DAG.getConstantFP(CFP->getValue(), VT);
+      } else if (const PackedType *PTy = dyn_cast<PackedType>(VTy)) {
+        unsigned NumElements = PTy->getNumElements();
+        MVT::ValueType PVT = TLI.getValueType(PTy->getElementType());
+        MVT::ValueType TVT = MVT::getVectorType(PVT, NumElements);
+        
+        // Now that we know the number and type of the elements, push a
+        // Constant or ConstantFP node onto the ops list for each element of
+        // the packed constant.
+        std::vector<SDOperand> Ops;
+        for (unsigned i = 0; i < NumElements; ++i) {
+          const Constant *CEl = C->getOperand(i);
+          if (MVT::isFloatingPoint(PVT))
+            Ops.push_back(DAG.getConstantFP(cast<ConstantFP>(CEl)->getValue(), 
+                          PVT));
+          else
+            Ops.push_back(
+                    DAG.getConstant(cast<ConstantIntegral>(CEl)->getRawValue(),
+                          PVT));
+        }
+        // Handle the case where we have a 1-element vector, in which
+        // case we want to immediately turn it into a scalar constant.
+        if (Ops.size() == 1)
+          return N = Ops[0];
+        return N = DAG.getNode(ISD::ConstantVec, TVT, Ops);
       } else {
         // Canonicalize all constant ints to be unsigned.
         return N = DAG.getConstant(cast<ConstantIntegral>(C)->getRawValue(),VT);
@@ -784,8 +809,7 @@
   const Type *Ty = I.getType();
   SDOperand L;
   
-  if (Type::PackedTyID == Ty->getTypeID()) {
-    const PackedType *PTy = cast<PackedType>(Ty);
+  if (const PackedType *PTy = dyn_cast<PackedType>(Ty)) {
     unsigned NumElements = PTy->getNumElements();
     MVT::ValueType PVT = TLI.getValueType(PTy->getElementType());
     MVT::ValueType TVT = MVT::getVectorType(PVT, NumElements);






More information about the llvm-commits mailing list