diff options
author | Chris Lattner <sabre@nondot.org> | 2005-01-16 01:10:58 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2005-01-16 01:10:58 +0000 |
commit | bb97d81cc873e2c0914f2ece43832723cc936d24 (patch) | |
tree | 4448ed507901b0d4f647bf4269abcc517cbf2b73 /lib/CodeGen/SelectionDAG/TargetLowering.cpp | |
parent | 1713e73b8ac53f045150cb2a7d7ba9781dc35ef8 (diff) |
Move some information out of LegalizeDAG into the generic Target interface.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19581 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/SelectionDAG/TargetLowering.cpp')
-rw-r--r-- | lib/CodeGen/SelectionDAG/TargetLowering.cpp | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/lib/CodeGen/SelectionDAG/TargetLowering.cpp index f2ce1308ca..624c5d1e8f 100644 --- a/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -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 @@ TargetLowering::TargetLowering(TargetMachine &tm) 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 @@ void TargetLowering::computeRegisterProperties() { 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); +} |