initialize an instance var, apparently I forgot to commit this long ago
[oota-llvm.git] / lib / CodeGen / SelectionDAG / TargetLowering.cpp
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)
20   : TM(tm), TD(TM.getTargetData()), ValueTypeActions(0) {
21   assert(ISD::BUILTIN_OP_END <= 128 &&
22          "Fixed size array in TargetLowering is not large enough!");
23   // All operations default to being supported.
24   memset(OpActions, 0, sizeof(OpActions));
25
26   IsLittleEndian = TD.isLittleEndian();
27   ShiftAmountTy = SetCCResultTy = PointerTy = getValueType(TD.getIntPtrType());
28   ShiftAmtHandling = Undefined;
29   memset(RegClassForVT, 0,MVT::LAST_VALUETYPE*sizeof(TargetRegisterClass*));
30   maxStoresPerMemSet = maxStoresPerMemCpy = maxStoresPerMemMove = 8;
31   allowUnalignedMemoryAccesses = false;
32   UseUnderscoreSetJmpLongJmp = false;
33   IntDivIsCheap = false;
34   Pow2DivIsCheap = false;
35   StackPointerRegisterToSaveRestore = 0;
36   SchedPreferenceInfo = SchedulingForLatency;
37 }
38
39 TargetLowering::~TargetLowering() {}
40
41 /// setValueTypeAction - Set the action for a particular value type.  This
42 /// assumes an action has not already been set for this value type.
43 static void SetValueTypeAction(MVT::ValueType VT,
44                                TargetLowering::LegalizeAction Action,
45                                TargetLowering &TLI,
46                                MVT::ValueType *TransformToType,
47                                unsigned long long &ValueTypeActions) {
48   ValueTypeActions |= (unsigned long long)Action << (VT*2);
49   if (Action == TargetLowering::Promote) {
50     MVT::ValueType PromoteTo;
51     if (VT == MVT::f32)
52       PromoteTo = MVT::f64;
53     else {
54       unsigned LargerReg = VT+1;
55       while (!TLI.isTypeLegal((MVT::ValueType)LargerReg)) {
56         ++LargerReg;
57         assert(MVT::isInteger((MVT::ValueType)LargerReg) &&
58                "Nothing to promote to??");
59       }
60       PromoteTo = (MVT::ValueType)LargerReg;
61     }
62
63     assert(MVT::isInteger(VT) == MVT::isInteger(PromoteTo) &&
64            MVT::isFloatingPoint(VT) == MVT::isFloatingPoint(PromoteTo) &&
65            "Can only promote from int->int or fp->fp!");
66     assert(VT < PromoteTo && "Must promote to a larger type!");
67     TransformToType[VT] = PromoteTo;
68   } else if (Action == TargetLowering::Expand) {
69     assert((VT == MVT::Vector || MVT::isInteger(VT)) && VT > MVT::i8 &&
70            "Cannot expand this type: target must support SOME integer reg!");
71     // Expand to the next smaller integer type!
72     TransformToType[VT] = (MVT::ValueType)(VT-1);
73   }
74 }
75
76
77 /// computeRegisterProperties - Once all of the register classes are added,
78 /// this allows us to compute derived properties we expose.
79 void TargetLowering::computeRegisterProperties() {
80   assert(MVT::LAST_VALUETYPE <= 32 &&
81          "Too many value types for ValueTypeActions to hold!");
82
83   // Everything defaults to one.
84   for (unsigned i = 0; i != MVT::LAST_VALUETYPE; ++i)
85     NumElementsForVT[i] = 1;
86
87   // Find the largest integer register class.
88   unsigned LargestIntReg = MVT::i128;
89   for (; RegClassForVT[LargestIntReg] == 0; --LargestIntReg)
90     assert(LargestIntReg != MVT::i1 && "No integer registers defined!");
91
92   // Every integer value type larger than this largest register takes twice as
93   // many registers to represent as the previous ValueType.
94   unsigned ExpandedReg = LargestIntReg; ++LargestIntReg;
95   for (++ExpandedReg; MVT::isInteger((MVT::ValueType)ExpandedReg);++ExpandedReg)
96     NumElementsForVT[ExpandedReg] = 2*NumElementsForVT[ExpandedReg-1];
97
98   // Inspect all of the ValueType's possible, deciding how to process them.
99   for (unsigned IntReg = MVT::i1; IntReg <= MVT::i128; ++IntReg)
100     // If we are expanding this type, expand it!
101     if (getNumElements((MVT::ValueType)IntReg) != 1)
102       SetValueTypeAction((MVT::ValueType)IntReg, Expand, *this, TransformToType,
103                          ValueTypeActions);
104     else if (!isTypeLegal((MVT::ValueType)IntReg))
105       // Otherwise, if we don't have native support, we must promote to a
106       // larger type.
107       SetValueTypeAction((MVT::ValueType)IntReg, Promote, *this,
108                          TransformToType, ValueTypeActions);
109     else
110       TransformToType[(MVT::ValueType)IntReg] = (MVT::ValueType)IntReg;
111
112   // If the target does not have native support for F32, promote it to F64.
113   if (!isTypeLegal(MVT::f32))
114     SetValueTypeAction(MVT::f32, Promote, *this,
115                        TransformToType, ValueTypeActions);
116   else
117     TransformToType[MVT::f32] = MVT::f32;
118   
119   // Set MVT::Vector to always be Expanded
120   SetValueTypeAction(MVT::Vector, Expand, *this, TransformToType, 
121                      ValueTypeActions);
122
123   assert(isTypeLegal(MVT::f64) && "Target does not support FP?");
124   TransformToType[MVT::f64] = MVT::f64;
125 }
126
127 const char *TargetLowering::getTargetNodeName(unsigned Opcode) const {
128   return NULL;
129 }
130
131 bool TargetLowering::isMaskedValueZeroForTargetNode(const SDOperand &Op,
132                                                     uint64_t Mask) const {
133   return false;
134 }