[llvm-commits] CVS: llvm/lib/Target/TargetLowering.cpp

Chris Lattner lattner at cs.uiuc.edu
Sat Jan 15 17:11:11 PST 2005



Changes in directory llvm/lib/Target:

TargetLowering.cpp updated: 1.2 -> 1.3
---
Log message:

Move some information out of LegalizeDAG into the generic Target interface.



---
Diffs of the changes:  (+55 -2)

Index: llvm/lib/Target/TargetLowering.cpp
diff -u llvm/lib/Target/TargetLowering.cpp:1.2 llvm/lib/Target/TargetLowering.cpp:1.3
--- llvm/lib/Target/TargetLowering.cpp:1.2	Tue Jan 11 14:25:26 2005
+++ llvm/lib/Target/TargetLowering.cpp	Sat Jan 15 19:10:58 2005
@@ -17,7 +17,7 @@
 using namespace llvm;
 
 TargetLowering::TargetLowering(TargetMachine &tm)
-  : TM(tm), TD(TM.getTargetData()) {
+  : TM(tm), TD(TM.getTargetData()), ValueTypeActions(0) {
   assert(ISD::BUILTIN_OP_END <= 128 &&
          "Fixed size array in TargetLowering is not large enough!");
 
@@ -27,9 +27,47 @@
   memset(RegClassForVT, 0,MVT::LAST_VALUETYPE*sizeof(TargetRegisterClass*));
 }
 
+/// setValueTypeAction - Set the action for a particular value type.  This
+/// assumes an action has not already been set for this value type.
+static void SetValueTypeAction(MVT::ValueType VT, unsigned Action,
+                               TargetLowering &TLI,
+                               MVT::ValueType *TransformToType,
+                               unsigned &ValueTypeActions) {
+  ValueTypeActions |= Action << (VT*2);
+  if (Action == 1 /*promote*/) {
+    MVT::ValueType PromoteTo;
+    if (VT == MVT::f32)
+      PromoteTo = MVT::f64;
+    else {
+      unsigned LargerReg = VT+1;
+      while (!TLI.hasNativeSupportFor((MVT::ValueType)LargerReg)) {
+        ++LargerReg;
+        assert(MVT::isInteger((MVT::ValueType)LargerReg) &&
+               "Nothing to promote to??");
+      }
+      PromoteTo = (MVT::ValueType)LargerReg;
+    }
+
+    assert(MVT::isInteger(VT) == MVT::isInteger(PromoteTo) &&
+           MVT::isFloatingPoint(VT) == MVT::isFloatingPoint(PromoteTo) &&
+           "Can only promote from int->int or fp->fp!");
+    assert(VT < PromoteTo && "Must promote to a larger type!");
+    TransformToType[VT] = PromoteTo;
+  } else if (Action == 2) {
+    assert(MVT::isInteger(VT) && VT > MVT::i8 &&
+           "Cannot expand this type: target must support SOME integer reg!");
+    // Expand to the next smaller integer type!
+    TransformToType[VT] = (MVT::ValueType)(VT-1);
+  }
+}
+
+
 /// computeRegisterProperties - Once all of the register classes are added,
 /// this allows us to compute derived properties we expose.
 void TargetLowering::computeRegisterProperties() {
+  assert(MVT::LAST_VALUETYPE <= 16 &&
+         "Too many value types for ValueTypeActions to hold!");
+
   // Everything defaults to one.
   for (unsigned i = 0; i != MVT::LAST_VALUETYPE; ++i)
     NumElementsForVT[i] = 1;
@@ -44,5 +82,20 @@
   unsigned ExpandedReg = LargestIntReg; ++LargestIntReg;
   for (++ExpandedReg; MVT::isInteger((MVT::ValueType)ExpandedReg);++ExpandedReg)
     NumElementsForVT[ExpandedReg] = 2*NumElementsForVT[ExpandedReg-1];
-}
 
+  // Inspect all of the ValueType's possible, deciding how to process them.
+  for (unsigned IntReg = MVT::i1; IntReg <= MVT::i128; ++IntReg)
+    // If we are expanding this type, expand it!
+    if (getNumElements((MVT::ValueType)IntReg) != 1)
+      SetValueTypeAction((MVT::ValueType)IntReg, 2, *this, TransformToType,
+                         ValueTypeActions);
+    else if (!hasNativeSupportFor((MVT::ValueType)IntReg))
+      // Otherwise, if we don't have native support, we must promote to a
+      // larger type.
+      SetValueTypeAction((MVT::ValueType)IntReg, 1, *this, TransformToType,
+                         ValueTypeActions);
+  
+  // If the target does not have native support for F32, promote it to F64.
+  if (!hasNativeSupportFor(MVT::f32))
+    SetValueTypeAction(MVT::f32, 1, *this, TransformToType, ValueTypeActions);
+}






More information about the llvm-commits mailing list