Chris Lattner | 310968c | 2005-01-07 07:44:53 +0000 | [diff] [blame] | 1 | //===-- TargetLowering.cpp - Implement the TargetLowering class -----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This implements the TargetLowering class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/Target/TargetLowering.h" |
| 15 | #include "llvm/Target/TargetMachine.h" |
| 16 | #include "llvm/CodeGen/SelectionDAG.h" |
| 17 | using namespace llvm; |
| 18 | |
| 19 | TargetLowering::TargetLowering(TargetMachine &tm) |
Chris Lattner | bb97d81 | 2005-01-16 01:10:58 +0000 | [diff] [blame] | 20 | : TM(tm), TD(TM.getTargetData()), ValueTypeActions(0) { |
Chris Lattner | 310968c | 2005-01-07 07:44:53 +0000 | [diff] [blame] | 21 | assert(ISD::BUILTIN_OP_END <= 128 && |
| 22 | "Fixed size array in TargetLowering is not large enough!"); |
Chris Lattner | cba82f9 | 2005-01-16 07:28:11 +0000 | [diff] [blame] | 23 | // All operations default to being supported. |
| 24 | memset(OpActions, 0, sizeof(OpActions)); |
Chris Lattner | 310968c | 2005-01-07 07:44:53 +0000 | [diff] [blame] | 25 | |
| 26 | IsLittleEndian = TD.isLittleEndian(); |
Chris Lattner | 714b69d | 2005-01-16 23:59:48 +0000 | [diff] [blame] | 27 | ShiftAmountTy = SetCCResultTy = PointerTy = getValueType(TD.getIntPtrType()); |
Chris Lattner | d6e4967 | 2005-01-19 03:36:14 +0000 | [diff] [blame^] | 28 | ShiftAmtHandling = Undefined; |
Chris Lattner | 310968c | 2005-01-07 07:44:53 +0000 | [diff] [blame] | 29 | memset(RegClassForVT, 0,MVT::LAST_VALUETYPE*sizeof(TargetRegisterClass*)); |
| 30 | } |
| 31 | |
Chris Lattner | cba82f9 | 2005-01-16 07:28:11 +0000 | [diff] [blame] | 32 | TargetLowering::~TargetLowering() {} |
| 33 | |
Chris Lattner | bb97d81 | 2005-01-16 01:10:58 +0000 | [diff] [blame] | 34 | /// setValueTypeAction - Set the action for a particular value type. This |
| 35 | /// assumes an action has not already been set for this value type. |
Chris Lattner | cba82f9 | 2005-01-16 07:28:11 +0000 | [diff] [blame] | 36 | static void SetValueTypeAction(MVT::ValueType VT, |
| 37 | TargetLowering::LegalizeAction Action, |
Chris Lattner | bb97d81 | 2005-01-16 01:10:58 +0000 | [diff] [blame] | 38 | TargetLowering &TLI, |
| 39 | MVT::ValueType *TransformToType, |
| 40 | unsigned &ValueTypeActions) { |
| 41 | ValueTypeActions |= Action << (VT*2); |
Chris Lattner | cba82f9 | 2005-01-16 07:28:11 +0000 | [diff] [blame] | 42 | if (Action == TargetLowering::Promote) { |
Chris Lattner | bb97d81 | 2005-01-16 01:10:58 +0000 | [diff] [blame] | 43 | MVT::ValueType PromoteTo; |
| 44 | if (VT == MVT::f32) |
| 45 | PromoteTo = MVT::f64; |
| 46 | else { |
| 47 | unsigned LargerReg = VT+1; |
| 48 | while (!TLI.hasNativeSupportFor((MVT::ValueType)LargerReg)) { |
| 49 | ++LargerReg; |
| 50 | assert(MVT::isInteger((MVT::ValueType)LargerReg) && |
| 51 | "Nothing to promote to??"); |
| 52 | } |
| 53 | PromoteTo = (MVT::ValueType)LargerReg; |
| 54 | } |
| 55 | |
| 56 | assert(MVT::isInteger(VT) == MVT::isInteger(PromoteTo) && |
| 57 | MVT::isFloatingPoint(VT) == MVT::isFloatingPoint(PromoteTo) && |
| 58 | "Can only promote from int->int or fp->fp!"); |
| 59 | assert(VT < PromoteTo && "Must promote to a larger type!"); |
| 60 | TransformToType[VT] = PromoteTo; |
Chris Lattner | cba82f9 | 2005-01-16 07:28:11 +0000 | [diff] [blame] | 61 | } else if (Action == TargetLowering::Expand) { |
Chris Lattner | bb97d81 | 2005-01-16 01:10:58 +0000 | [diff] [blame] | 62 | assert(MVT::isInteger(VT) && VT > MVT::i8 && |
| 63 | "Cannot expand this type: target must support SOME integer reg!"); |
| 64 | // Expand to the next smaller integer type! |
| 65 | TransformToType[VT] = (MVT::ValueType)(VT-1); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | |
Chris Lattner | 310968c | 2005-01-07 07:44:53 +0000 | [diff] [blame] | 70 | /// computeRegisterProperties - Once all of the register classes are added, |
| 71 | /// this allows us to compute derived properties we expose. |
| 72 | void TargetLowering::computeRegisterProperties() { |
Chris Lattner | bb97d81 | 2005-01-16 01:10:58 +0000 | [diff] [blame] | 73 | assert(MVT::LAST_VALUETYPE <= 16 && |
| 74 | "Too many value types for ValueTypeActions to hold!"); |
| 75 | |
Chris Lattner | 310968c | 2005-01-07 07:44:53 +0000 | [diff] [blame] | 76 | // Everything defaults to one. |
| 77 | for (unsigned i = 0; i != MVT::LAST_VALUETYPE; ++i) |
| 78 | NumElementsForVT[i] = 1; |
| 79 | |
| 80 | // Find the largest integer register class. |
| 81 | unsigned LargestIntReg = MVT::i128; |
| 82 | for (; RegClassForVT[LargestIntReg] == 0; --LargestIntReg) |
| 83 | assert(LargestIntReg != MVT::i1 && "No integer registers defined!"); |
| 84 | |
| 85 | // Every integer value type larger than this largest register takes twice as |
| 86 | // many registers to represent as the previous ValueType. |
| 87 | unsigned ExpandedReg = LargestIntReg; ++LargestIntReg; |
| 88 | for (++ExpandedReg; MVT::isInteger((MVT::ValueType)ExpandedReg);++ExpandedReg) |
| 89 | NumElementsForVT[ExpandedReg] = 2*NumElementsForVT[ExpandedReg-1]; |
Chris Lattner | 310968c | 2005-01-07 07:44:53 +0000 | [diff] [blame] | 90 | |
Chris Lattner | bb97d81 | 2005-01-16 01:10:58 +0000 | [diff] [blame] | 91 | // Inspect all of the ValueType's possible, deciding how to process them. |
| 92 | for (unsigned IntReg = MVT::i1; IntReg <= MVT::i128; ++IntReg) |
| 93 | // If we are expanding this type, expand it! |
| 94 | if (getNumElements((MVT::ValueType)IntReg) != 1) |
Chris Lattner | cba82f9 | 2005-01-16 07:28:11 +0000 | [diff] [blame] | 95 | SetValueTypeAction((MVT::ValueType)IntReg, Expand, *this, TransformToType, |
Chris Lattner | bb97d81 | 2005-01-16 01:10:58 +0000 | [diff] [blame] | 96 | ValueTypeActions); |
| 97 | else if (!hasNativeSupportFor((MVT::ValueType)IntReg)) |
| 98 | // Otherwise, if we don't have native support, we must promote to a |
| 99 | // larger type. |
Chris Lattner | cba82f9 | 2005-01-16 07:28:11 +0000 | [diff] [blame] | 100 | SetValueTypeAction((MVT::ValueType)IntReg, Promote, *this, |
| 101 | TransformToType, ValueTypeActions); |
Chris Lattner | cfdfe4c | 2005-01-16 01:20:18 +0000 | [diff] [blame] | 102 | else |
| 103 | TransformToType[(MVT::ValueType)IntReg] = (MVT::ValueType)IntReg; |
Chris Lattner | bb97d81 | 2005-01-16 01:10:58 +0000 | [diff] [blame] | 104 | |
| 105 | // If the target does not have native support for F32, promote it to F64. |
| 106 | if (!hasNativeSupportFor(MVT::f32)) |
Chris Lattner | cba82f9 | 2005-01-16 07:28:11 +0000 | [diff] [blame] | 107 | SetValueTypeAction(MVT::f32, Promote, *this, |
| 108 | TransformToType, ValueTypeActions); |
Chris Lattner | cfdfe4c | 2005-01-16 01:20:18 +0000 | [diff] [blame] | 109 | else |
| 110 | TransformToType[MVT::f32] = MVT::f32; |
| 111 | |
| 112 | assert(hasNativeSupportFor(MVT::f64) && "Target does not support FP?"); |
| 113 | TransformToType[MVT::f64] = MVT::f64; |
Chris Lattner | bb97d81 | 2005-01-16 01:10:58 +0000 | [diff] [blame] | 114 | } |
Chris Lattner | cba82f9 | 2005-01-16 07:28:11 +0000 | [diff] [blame] | 115 | |