Teach bottom up pre-ra scheduler to track register pressure. Work in progress.
[oota-llvm.git] / include / llvm / Target / TargetLowering.h
1 //===-- llvm/Target/TargetLowering.h - Target Lowering Info -----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file describes how to lower LLVM code to machine code.  This has two
11 // main components:
12 //
13 //  1. Which ValueTypes are natively supported by the target.
14 //  2. Which operations are supported for supported ValueTypes.
15 //  3. Cost thresholds for alternative implementations of certain operations.
16 //
17 // In addition it has a few other components, like information about FP
18 // immediates.
19 //
20 //===----------------------------------------------------------------------===//
21
22 #ifndef LLVM_TARGET_TARGETLOWERING_H
23 #define LLVM_TARGET_TARGETLOWERING_H
24
25 #include "llvm/CallingConv.h"
26 #include "llvm/InlineAsm.h"
27 #include "llvm/Attributes.h"
28 #include "llvm/CodeGen/SelectionDAGNodes.h"
29 #include "llvm/CodeGen/RuntimeLibcalls.h"
30 #include "llvm/ADT/APFloat.h"
31 #include "llvm/ADT/DenseMap.h"
32 #include "llvm/ADT/SmallSet.h"
33 #include "llvm/ADT/SmallVector.h"
34 #include "llvm/ADT/STLExtras.h"
35 #include "llvm/Support/DebugLoc.h"
36 #include "llvm/Target/TargetCallingConv.h"
37 #include "llvm/Target/TargetMachine.h"
38 #include <climits>
39 #include <map>
40 #include <vector>
41
42 namespace llvm {
43   class AllocaInst;
44   class CallInst;
45   class Function;
46   class FastISel;
47   class FunctionLoweringInfo;
48   class MachineBasicBlock;
49   class MachineFunction;
50   class MachineFrameInfo;
51   class MachineInstr;
52   class MachineJumpTableInfo;
53   class MCContext;
54   class MCExpr;
55   class SDNode;
56   class SDValue;
57   class SelectionDAG;
58   class TargetData;
59   class TargetMachine;
60   class TargetRegisterClass;
61   class TargetLoweringObjectFile;
62   class Value;
63
64   // FIXME: should this be here?
65   namespace TLSModel {
66     enum Model {
67       GeneralDynamic,
68       LocalDynamic,
69       InitialExec,
70       LocalExec
71     };
72   }
73   TLSModel::Model getTLSModel(const GlobalValue *GV, Reloc::Model reloc);
74
75
76 //===----------------------------------------------------------------------===//
77 /// TargetLowering - This class defines information used to lower LLVM code to
78 /// legal SelectionDAG operators that the target instruction selector can accept
79 /// natively.
80 ///
81 /// This class also defines callbacks that targets must implement to lower
82 /// target-specific constructs to SelectionDAG operators.
83 ///
84 class TargetLowering {
85   TargetLowering(const TargetLowering&);  // DO NOT IMPLEMENT
86   void operator=(const TargetLowering&);  // DO NOT IMPLEMENT
87 public:
88   /// LegalizeAction - This enum indicates whether operations are valid for a
89   /// target, and if not, what action should be used to make them valid.
90   enum LegalizeAction {
91     Legal,      // The target natively supports this operation.
92     Promote,    // This operation should be executed in a larger type.
93     Expand,     // Try to expand this to other ops, otherwise use a libcall.
94     Custom      // Use the LowerOperation hook to implement custom lowering.
95   };
96
97   enum BooleanContent { // How the target represents true/false values.
98     UndefinedBooleanContent,    // Only bit 0 counts, the rest can hold garbage.
99     ZeroOrOneBooleanContent,        // All bits zero except for bit 0.
100     ZeroOrNegativeOneBooleanContent // All bits equal to bit 0.
101   };
102
103   /// NOTE: The constructor takes ownership of TLOF.
104   explicit TargetLowering(const TargetMachine &TM,
105                           const TargetLoweringObjectFile *TLOF);
106   virtual ~TargetLowering();
107
108   const TargetMachine &getTargetMachine() const { return TM; }
109   const TargetData *getTargetData() const { return TD; }
110   const TargetLoweringObjectFile &getObjFileLowering() const { return TLOF; }
111
112   bool isBigEndian() const { return !IsLittleEndian; }
113   bool isLittleEndian() const { return IsLittleEndian; }
114   MVT getPointerTy() const { return PointerTy; }
115   MVT getShiftAmountTy() const { return ShiftAmountTy; }
116
117   /// isSelectExpensive - Return true if the select operation is expensive for
118   /// this target.
119   bool isSelectExpensive() const { return SelectIsExpensive; }
120
121   /// isIntDivCheap() - Return true if integer divide is usually cheaper than
122   /// a sequence of several shifts, adds, and multiplies for this target.
123   bool isIntDivCheap() const { return IntDivIsCheap; }
124
125   /// isPow2DivCheap() - Return true if pow2 div is cheaper than a chain of
126   /// srl/add/sra.
127   bool isPow2DivCheap() const { return Pow2DivIsCheap; }
128
129   /// getSetCCResultType - Return the ValueType of the result of SETCC
130   /// operations.  Also used to obtain the target's preferred type for
131   /// the condition operand of SELECT and BRCOND nodes.  In the case of
132   /// BRCOND the argument passed is MVT::Other since there are no other
133   /// operands to get a type hint from.
134   virtual
135   MVT::SimpleValueType getSetCCResultType(EVT VT) const;
136
137   /// getCmpLibcallReturnType - Return the ValueType for comparison
138   /// libcalls. Comparions libcalls include floating point comparion calls,
139   /// and Ordered/Unordered check calls on floating point numbers.
140   virtual
141   MVT::SimpleValueType getCmpLibcallReturnType() const;
142
143   /// getBooleanContents - For targets without i1 registers, this gives the
144   /// nature of the high-bits of boolean values held in types wider than i1.
145   /// "Boolean values" are special true/false values produced by nodes like
146   /// SETCC and consumed (as the condition) by nodes like SELECT and BRCOND.
147   /// Not to be confused with general values promoted from i1.
148   BooleanContent getBooleanContents() const { return BooleanContents;}
149
150   /// getSchedulingPreference - Return target scheduling preference.
151   Sched::Preference getSchedulingPreference() const {
152     return SchedPreferenceInfo;
153   }
154
155   /// getSchedulingPreference - Some scheduler, e.g. hybrid, can switch to
156   /// different scheduling heuristics for different nodes. This function returns
157   /// the preference (or none) for the given node.
158   virtual Sched::Preference getSchedulingPreference(SDNode *N) const {
159     return Sched::None;
160   }
161
162   /// getRegClassFor - Return the register class that should be used for the
163   /// specified value type.
164   virtual TargetRegisterClass *getRegClassFor(EVT VT) const {
165     assert(VT.isSimple() && "getRegClassFor called on illegal type!");
166     TargetRegisterClass *RC = RegClassForVT[VT.getSimpleVT().SimpleTy];
167     assert(RC && "This value type is not natively supported!");
168     return RC;
169   }
170
171   /// getRepRegClassFor - Return the 'representative' register class for the
172   /// specified value type. The 'representative' register class is the largest
173   /// legal super-reg register class for the register class of the value type.
174   /// For example, on i386 the rep register class for i8, i16, and i32 are GR32;
175   /// while the rep register class is GR64 on x86_64.
176   virtual const TargetRegisterClass *getRepRegClassFor(EVT VT) const {
177     assert(VT.isSimple() && "getRepRegClassFor called on illegal type!");
178     const TargetRegisterClass *RC = RepRegClassForVT[VT.getSimpleVT().SimpleTy];
179     return RC;
180   }
181
182   /// getRepRegClassCostFor - Return the cost of the 'representative' register
183   /// class for the specified value type.
184   virtual uint8_t getRepRegClassCostFor(EVT VT) const {
185     assert(VT.isSimple() && "getRepRegClassCostFor called on illegal type!");
186     return RepRegClassCostForVT[VT.getSimpleVT().SimpleTy];
187   }
188
189   /// isTypeLegal - Return true if the target has native support for the
190   /// specified value type.  This means that it has a register that directly
191   /// holds it without promotions or expansions.
192   bool isTypeLegal(EVT VT) const {
193     assert(!VT.isSimple() ||
194            (unsigned)VT.getSimpleVT().SimpleTy < array_lengthof(RegClassForVT));
195     return VT.isSimple() && RegClassForVT[VT.getSimpleVT().SimpleTy] != 0;
196   }
197
198   /// isTypeSynthesizable - Return true if it's OK for the compiler to create
199   /// new operations of this type.  All Legal types are synthesizable except
200   /// MMX vector types on X86.  Non-Legal types are not synthesizable.
201   bool isTypeSynthesizable(EVT VT) const {
202     return isTypeLegal(VT) && Synthesizable[VT.getSimpleVT().SimpleTy];
203   }
204
205   class ValueTypeActionImpl {
206     /// ValueTypeActions - For each value type, keep a LegalizeAction enum
207     /// that indicates how instruction selection should deal with the type.
208     uint8_t ValueTypeActions[MVT::LAST_VALUETYPE];
209   public:
210     ValueTypeActionImpl() {
211       std::fill(ValueTypeActions, array_endof(ValueTypeActions), 0);
212     }
213     LegalizeAction getTypeAction(LLVMContext &Context, EVT VT) const {
214       if (VT.isExtended()) {
215         if (VT.isVector()) {
216           return VT.isPow2VectorType() ? Expand : Promote;
217         }
218         if (VT.isInteger())
219           // First promote to a power-of-two size, then expand if necessary.
220           return VT == VT.getRoundIntegerType(Context) ? Expand : Promote;
221         assert(0 && "Unsupported extended type!");
222         return Legal;
223       }
224       unsigned I = VT.getSimpleVT().SimpleTy;
225       return (LegalizeAction)ValueTypeActions[I];
226     }
227     void setTypeAction(EVT VT, LegalizeAction Action) {
228       unsigned I = VT.getSimpleVT().SimpleTy;
229       ValueTypeActions[I] = Action;
230     }
231   };
232
233   const ValueTypeActionImpl &getValueTypeActions() const {
234     return ValueTypeActions;
235   }
236
237   /// getTypeAction - Return how we should legalize values of this type, either
238   /// it is already legal (return 'Legal') or we need to promote it to a larger
239   /// type (return 'Promote'), or we need to expand it into multiple registers
240   /// of smaller integer type (return 'Expand').  'Custom' is not an option.
241   LegalizeAction getTypeAction(LLVMContext &Context, EVT VT) const {
242     return ValueTypeActions.getTypeAction(Context, VT);
243   }
244
245   /// getTypeToTransformTo - For types supported by the target, this is an
246   /// identity function.  For types that must be promoted to larger types, this
247   /// returns the larger type to promote to.  For integer types that are larger
248   /// than the largest integer register, this contains one step in the expansion
249   /// to get to the smaller register. For illegal floating point types, this
250   /// returns the integer type to transform to.
251   EVT getTypeToTransformTo(LLVMContext &Context, EVT VT) const {
252     if (VT.isSimple()) {
253       assert((unsigned)VT.getSimpleVT().SimpleTy <
254              array_lengthof(TransformToType));
255       EVT NVT = TransformToType[VT.getSimpleVT().SimpleTy];
256       assert(getTypeAction(Context, NVT) != Promote &&
257              "Promote may not follow Expand or Promote");
258       return NVT;
259     }
260
261     if (VT.isVector()) {
262       EVT NVT = VT.getPow2VectorType(Context);
263       if (NVT == VT) {
264         // Vector length is a power of 2 - split to half the size.
265         unsigned NumElts = VT.getVectorNumElements();
266         EVT EltVT = VT.getVectorElementType();
267         return (NumElts == 1) ?
268           EltVT : EVT::getVectorVT(Context, EltVT, NumElts / 2);
269       }
270       // Promote to a power of two size, avoiding multi-step promotion.
271       return getTypeAction(Context, NVT) == Promote ?
272         getTypeToTransformTo(Context, NVT) : NVT;
273     } else if (VT.isInteger()) {
274       EVT NVT = VT.getRoundIntegerType(Context);
275       if (NVT == VT)
276         // Size is a power of two - expand to half the size.
277         return EVT::getIntegerVT(Context, VT.getSizeInBits() / 2);
278       else
279         // Promote to a power of two size, avoiding multi-step promotion.
280         return getTypeAction(Context, NVT) == Promote ?
281           getTypeToTransformTo(Context, NVT) : NVT;
282     }
283     assert(0 && "Unsupported extended type!");
284     return MVT(MVT::Other); // Not reached
285   }
286
287   /// getTypeToExpandTo - For types supported by the target, this is an
288   /// identity function.  For types that must be expanded (i.e. integer types
289   /// that are larger than the largest integer register or illegal floating
290   /// point types), this returns the largest legal type it will be expanded to.
291   EVT getTypeToExpandTo(LLVMContext &Context, EVT VT) const {
292     assert(!VT.isVector());
293     while (true) {
294       switch (getTypeAction(Context, VT)) {
295       case Legal:
296         return VT;
297       case Expand:
298         VT = getTypeToTransformTo(Context, VT);
299         break;
300       default:
301         assert(false && "Type is not legal nor is it to be expanded!");
302         return VT;
303       }
304     }
305     return VT;
306   }
307
308   /// getVectorTypeBreakdown - Vector types are broken down into some number of
309   /// legal first class types.  For example, EVT::v8f32 maps to 2 EVT::v4f32
310   /// with Altivec or SSE1, or 8 promoted EVT::f64 values with the X86 FP stack.
311   /// Similarly, EVT::v2i64 turns into 4 EVT::i32 values with both PPC and X86.
312   ///
313   /// This method returns the number of registers needed, and the VT for each
314   /// register.  It also returns the VT and quantity of the intermediate values
315   /// before they are promoted/expanded.
316   ///
317   unsigned getVectorTypeBreakdown(LLVMContext &Context, EVT VT,
318                                   EVT &IntermediateVT,
319                                   unsigned &NumIntermediates,
320                                   EVT &RegisterVT) const;
321
322   /// getTgtMemIntrinsic: Given an intrinsic, checks if on the target the
323   /// intrinsic will need to map to a MemIntrinsicNode (touches memory). If
324   /// this is the case, it returns true and store the intrinsic
325   /// information into the IntrinsicInfo that was passed to the function.
326   struct IntrinsicInfo {
327     unsigned     opc;         // target opcode
328     EVT          memVT;       // memory VT
329     const Value* ptrVal;      // value representing memory location
330     int          offset;      // offset off of ptrVal
331     unsigned     align;       // alignment
332     bool         vol;         // is volatile?
333     bool         readMem;     // reads memory?
334     bool         writeMem;    // writes memory?
335   };
336
337   virtual bool getTgtMemIntrinsic(IntrinsicInfo &Info,
338                                   const CallInst &I, unsigned Intrinsic) const {
339     return false;
340   }
341
342   /// isFPImmLegal - Returns true if the target can instruction select the
343   /// specified FP immediate natively. If false, the legalizer will materialize
344   /// the FP immediate as a load from a constant pool.
345   virtual bool isFPImmLegal(const APFloat &Imm, EVT VT) const {
346     return false;
347   }
348
349   /// isShuffleMaskLegal - Targets can use this to indicate that they only
350   /// support *some* VECTOR_SHUFFLE operations, those with specific masks.
351   /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values
352   /// are assumed to be legal.
353   virtual bool isShuffleMaskLegal(const SmallVectorImpl<int> &Mask,
354                                   EVT VT) const {
355     return true;
356   }
357
358   /// canOpTrap - Returns true if the operation can trap for the value type.
359   /// VT must be a legal type. By default, we optimistically assume most
360   /// operations don't trap except for divide and remainder.
361   virtual bool canOpTrap(unsigned Op, EVT VT) const;
362
363   /// isVectorClearMaskLegal - Similar to isShuffleMaskLegal. This is
364   /// used by Targets can use this to indicate if there is a suitable
365   /// VECTOR_SHUFFLE that can be used to replace a VAND with a constant
366   /// pool entry.
367   virtual bool isVectorClearMaskLegal(const SmallVectorImpl<int> &Mask,
368                                       EVT VT) const {
369     return false;
370   }
371
372   /// getOperationAction - Return how this operation should be treated: either
373   /// it is legal, needs to be promoted to a larger size, needs to be
374   /// expanded to some other code sequence, or the target has a custom expander
375   /// for it.
376   LegalizeAction getOperationAction(unsigned Op, EVT VT) const {
377     if (VT.isExtended()) return Expand;
378     assert(Op < array_lengthof(OpActions[0]) && "Table isn't big enough!");
379     unsigned I = (unsigned) VT.getSimpleVT().SimpleTy;
380     return (LegalizeAction)OpActions[I][Op];
381   }
382
383   /// isOperationLegalOrCustom - Return true if the specified operation is
384   /// legal on this target or can be made legal with custom lowering. This
385   /// is used to help guide high-level lowering decisions.
386   bool isOperationLegalOrCustom(unsigned Op, EVT VT) const {
387     return (VT == MVT::Other || isTypeLegal(VT)) &&
388       (getOperationAction(Op, VT) == Legal ||
389        getOperationAction(Op, VT) == Custom);
390   }
391
392   /// isOperationLegal - Return true if the specified operation is legal on this
393   /// target.
394   bool isOperationLegal(unsigned Op, EVT VT) const {
395     return (VT == MVT::Other || isTypeLegal(VT)) &&
396            getOperationAction(Op, VT) == Legal;
397   }
398
399   /// getLoadExtAction - Return how this load with extension should be treated:
400   /// either it is legal, needs to be promoted to a larger size, needs to be
401   /// expanded to some other code sequence, or the target has a custom expander
402   /// for it.
403   LegalizeAction getLoadExtAction(unsigned ExtType, EVT VT) const {
404     assert(ExtType < ISD::LAST_LOADEXT_TYPE &&
405            (unsigned)VT.getSimpleVT().SimpleTy < MVT::LAST_VALUETYPE &&
406            "Table isn't big enough!");
407     return (LegalizeAction)LoadExtActions[VT.getSimpleVT().SimpleTy][ExtType];
408   }
409
410   /// isLoadExtLegal - Return true if the specified load with extension is legal
411   /// on this target.
412   bool isLoadExtLegal(unsigned ExtType, EVT VT) const {
413     return VT.isSimple() &&
414       (getLoadExtAction(ExtType, VT) == Legal ||
415        getLoadExtAction(ExtType, VT) == Custom);
416   }
417
418   /// getTruncStoreAction - Return how this store with truncation should be
419   /// treated: either it is legal, needs to be promoted to a larger size, needs
420   /// to be expanded to some other code sequence, or the target has a custom
421   /// expander for it.
422   LegalizeAction getTruncStoreAction(EVT ValVT, EVT MemVT) const {
423     assert((unsigned)ValVT.getSimpleVT().SimpleTy < MVT::LAST_VALUETYPE &&
424            (unsigned)MemVT.getSimpleVT().SimpleTy < MVT::LAST_VALUETYPE &&
425            "Table isn't big enough!");
426     return (LegalizeAction)TruncStoreActions[ValVT.getSimpleVT().SimpleTy]
427                                             [MemVT.getSimpleVT().SimpleTy];
428   }
429
430   /// isTruncStoreLegal - Return true if the specified store with truncation is
431   /// legal on this target.
432   bool isTruncStoreLegal(EVT ValVT, EVT MemVT) const {
433     return isTypeLegal(ValVT) && MemVT.isSimple() &&
434       (getTruncStoreAction(ValVT, MemVT) == Legal ||
435        getTruncStoreAction(ValVT, MemVT) == Custom);
436   }
437
438   /// getIndexedLoadAction - Return how the indexed load should be treated:
439   /// either it is legal, needs to be promoted to a larger size, needs to be
440   /// expanded to some other code sequence, or the target has a custom expander
441   /// for it.
442   LegalizeAction
443   getIndexedLoadAction(unsigned IdxMode, EVT VT) const {
444     assert( IdxMode < ISD::LAST_INDEXED_MODE &&
445            ((unsigned)VT.getSimpleVT().SimpleTy) < MVT::LAST_VALUETYPE &&
446            "Table isn't big enough!");
447     unsigned Ty = (unsigned)VT.getSimpleVT().SimpleTy;
448     return (LegalizeAction)((IndexedModeActions[Ty][IdxMode] & 0xf0) >> 4);
449   }
450
451   /// isIndexedLoadLegal - Return true if the specified indexed load is legal
452   /// on this target.
453   bool isIndexedLoadLegal(unsigned IdxMode, EVT VT) const {
454     return VT.isSimple() &&
455       (getIndexedLoadAction(IdxMode, VT) == Legal ||
456        getIndexedLoadAction(IdxMode, VT) == Custom);
457   }
458
459   /// getIndexedStoreAction - Return how the indexed store should be treated:
460   /// either it is legal, needs to be promoted to a larger size, needs to be
461   /// expanded to some other code sequence, or the target has a custom expander
462   /// for it.
463   LegalizeAction
464   getIndexedStoreAction(unsigned IdxMode, EVT VT) const {
465     assert( IdxMode < ISD::LAST_INDEXED_MODE &&
466            ((unsigned)VT.getSimpleVT().SimpleTy) < MVT::LAST_VALUETYPE &&
467            "Table isn't big enough!");
468     unsigned Ty = (unsigned)VT.getSimpleVT().SimpleTy;
469     return (LegalizeAction)(IndexedModeActions[Ty][IdxMode] & 0x0f);
470   }
471
472   /// isIndexedStoreLegal - Return true if the specified indexed load is legal
473   /// on this target.
474   bool isIndexedStoreLegal(unsigned IdxMode, EVT VT) const {
475     return VT.isSimple() &&
476       (getIndexedStoreAction(IdxMode, VT) == Legal ||
477        getIndexedStoreAction(IdxMode, VT) == Custom);
478   }
479
480   /// getCondCodeAction - Return how the condition code should be treated:
481   /// either it is legal, needs to be expanded to some other code sequence,
482   /// or the target has a custom expander for it.
483   LegalizeAction
484   getCondCodeAction(ISD::CondCode CC, EVT VT) const {
485     assert((unsigned)CC < array_lengthof(CondCodeActions) &&
486            (unsigned)VT.getSimpleVT().SimpleTy < sizeof(CondCodeActions[0])*4 &&
487            "Table isn't big enough!");
488     LegalizeAction Action = (LegalizeAction)
489       ((CondCodeActions[CC] >> (2*VT.getSimpleVT().SimpleTy)) & 3);
490     assert(Action != Promote && "Can't promote condition code!");
491     return Action;
492   }
493
494   /// isCondCodeLegal - Return true if the specified condition code is legal
495   /// on this target.
496   bool isCondCodeLegal(ISD::CondCode CC, EVT VT) const {
497     return getCondCodeAction(CC, VT) == Legal ||
498            getCondCodeAction(CC, VT) == Custom;
499   }
500
501
502   /// getTypeToPromoteTo - If the action for this operation is to promote, this
503   /// method returns the ValueType to promote to.
504   EVT getTypeToPromoteTo(unsigned Op, EVT VT) const {
505     assert(getOperationAction(Op, VT) == Promote &&
506            "This operation isn't promoted!");
507
508     // See if this has an explicit type specified.
509     std::map<std::pair<unsigned, MVT::SimpleValueType>,
510              MVT::SimpleValueType>::const_iterator PTTI =
511       PromoteToType.find(std::make_pair(Op, VT.getSimpleVT().SimpleTy));
512     if (PTTI != PromoteToType.end()) return PTTI->second;
513
514     assert((VT.isInteger() || VT.isFloatingPoint()) &&
515            "Cannot autopromote this type, add it with AddPromotedToType.");
516
517     EVT NVT = VT;
518     do {
519       NVT = (MVT::SimpleValueType)(NVT.getSimpleVT().SimpleTy+1);
520       assert(NVT.isInteger() == VT.isInteger() && NVT != MVT::isVoid &&
521              "Didn't find type to promote to!");
522     } while (!isTypeLegal(NVT) ||
523               getOperationAction(Op, NVT) == Promote);
524     return NVT;
525   }
526
527   /// getValueType - Return the EVT corresponding to this LLVM type.
528   /// This is fixed by the LLVM operations except for the pointer size.  If
529   /// AllowUnknown is true, this will return MVT::Other for types with no EVT
530   /// counterpart (e.g. structs), otherwise it will assert.
531   EVT getValueType(const Type *Ty, bool AllowUnknown = false) const {
532     EVT VT = EVT::getEVT(Ty, AllowUnknown);
533     return VT == MVT::iPTR ? PointerTy : VT;
534   }
535
536   /// getByValTypeAlignment - Return the desired alignment for ByVal aggregate
537   /// function arguments in the caller parameter area.  This is the actual
538   /// alignment, not its logarithm.
539   virtual unsigned getByValTypeAlignment(const Type *Ty) const;
540
541   /// getRegisterType - Return the type of registers that this ValueType will
542   /// eventually require.
543   EVT getRegisterType(MVT VT) const {
544     assert((unsigned)VT.SimpleTy < array_lengthof(RegisterTypeForVT));
545     return RegisterTypeForVT[VT.SimpleTy];
546   }
547
548   /// getRegisterType - Return the type of registers that this ValueType will
549   /// eventually require.
550   EVT getRegisterType(LLVMContext &Context, EVT VT) const {
551     if (VT.isSimple()) {
552       assert((unsigned)VT.getSimpleVT().SimpleTy <
553                 array_lengthof(RegisterTypeForVT));
554       return RegisterTypeForVT[VT.getSimpleVT().SimpleTy];
555     }
556     if (VT.isVector()) {
557       EVT VT1, RegisterVT;
558       unsigned NumIntermediates;
559       (void)getVectorTypeBreakdown(Context, VT, VT1,
560                                    NumIntermediates, RegisterVT);
561       return RegisterVT;
562     }
563     if (VT.isInteger()) {
564       return getRegisterType(Context, getTypeToTransformTo(Context, VT));
565     }
566     assert(0 && "Unsupported extended type!");
567     return EVT(MVT::Other); // Not reached
568   }
569
570   /// getNumRegisters - Return the number of registers that this ValueType will
571   /// eventually require.  This is one for any types promoted to live in larger
572   /// registers, but may be more than one for types (like i64) that are split
573   /// into pieces.  For types like i140, which are first promoted then expanded,
574   /// it is the number of registers needed to hold all the bits of the original
575   /// type.  For an i140 on a 32 bit machine this means 5 registers.
576   unsigned getNumRegisters(LLVMContext &Context, EVT VT) const {
577     if (VT.isSimple()) {
578       assert((unsigned)VT.getSimpleVT().SimpleTy <
579                 array_lengthof(NumRegistersForVT));
580       return NumRegistersForVT[VT.getSimpleVT().SimpleTy];
581     }
582     if (VT.isVector()) {
583       EVT VT1, VT2;
584       unsigned NumIntermediates;
585       return getVectorTypeBreakdown(Context, VT, VT1, NumIntermediates, VT2);
586     }
587     if (VT.isInteger()) {
588       unsigned BitWidth = VT.getSizeInBits();
589       unsigned RegWidth = getRegisterType(Context, VT).getSizeInBits();
590       return (BitWidth + RegWidth - 1) / RegWidth;
591     }
592     assert(0 && "Unsupported extended type!");
593     return 0; // Not reached
594   }
595
596   /// ShouldShrinkFPConstant - If true, then instruction selection should
597   /// seek to shrink the FP constant of the specified type to a smaller type
598   /// in order to save space and / or reduce runtime.
599   virtual bool ShouldShrinkFPConstant(EVT VT) const { return true; }
600
601   /// hasTargetDAGCombine - If true, the target has custom DAG combine
602   /// transformations that it can perform for the specified node.
603   bool hasTargetDAGCombine(ISD::NodeType NT) const {
604     assert(unsigned(NT >> 3) < array_lengthof(TargetDAGCombineArray));
605     return TargetDAGCombineArray[NT >> 3] & (1 << (NT&7));
606   }
607
608   /// This function returns the maximum number of store operations permitted
609   /// to replace a call to llvm.memset. The value is set by the target at the
610   /// performance threshold for such a replacement.
611   /// @brief Get maximum # of store operations permitted for llvm.memset
612   unsigned getMaxStoresPerMemset() const { return maxStoresPerMemset; }
613
614   /// This function returns the maximum number of store operations permitted
615   /// to replace a call to llvm.memcpy. The value is set by the target at the
616   /// performance threshold for such a replacement.
617   /// @brief Get maximum # of store operations permitted for llvm.memcpy
618   unsigned getMaxStoresPerMemcpy() const { return maxStoresPerMemcpy; }
619
620   /// This function returns the maximum number of store operations permitted
621   /// to replace a call to llvm.memmove. The value is set by the target at the
622   /// performance threshold for such a replacement.
623   /// @brief Get maximum # of store operations permitted for llvm.memmove
624   unsigned getMaxStoresPerMemmove() const { return maxStoresPerMemmove; }
625
626   /// This function returns true if the target allows unaligned memory accesses.
627   /// of the specified type. This is used, for example, in situations where an
628   /// array copy/move/set is  converted to a sequence of store operations. It's
629   /// use helps to ensure that such replacements don't generate code that causes
630   /// an alignment error  (trap) on the target machine.
631   /// @brief Determine if the target supports unaligned memory accesses.
632   virtual bool allowsUnalignedMemoryAccesses(EVT VT) const {
633     return false;
634   }
635
636   /// This function returns true if the target would benefit from code placement
637   /// optimization.
638   /// @brief Determine if the target should perform code placement optimization.
639   bool shouldOptimizeCodePlacement() const {
640     return benefitFromCodePlacementOpt;
641   }
642
643   /// getOptimalMemOpType - Returns the target specific optimal type for load
644   /// and store operations as a result of memset, memcpy, and memmove
645   /// lowering. If DstAlign is zero that means it's safe to destination
646   /// alignment can satisfy any constraint. Similarly if SrcAlign is zero it
647   /// means there isn't a need to check it against alignment requirement,
648   /// probably because the source does not need to be loaded. If
649   /// 'NonScalarIntSafe' is true, that means it's safe to return a
650   /// non-scalar-integer type, e.g. empty string source, constant, or loaded
651   /// from memory. 'MemcpyStrSrc' indicates whether the memcpy source is
652   /// constant so it does not need to be loaded.
653   /// It returns EVT::Other if the type should be determined using generic
654   /// target-independent logic.
655   virtual EVT getOptimalMemOpType(uint64_t Size,
656                                   unsigned DstAlign, unsigned SrcAlign,
657                                   bool NonScalarIntSafe, bool MemcpyStrSrc,
658                                   MachineFunction &MF) const {
659     return MVT::Other;
660   }
661
662   /// usesUnderscoreSetJmp - Determine if we should use _setjmp or setjmp
663   /// to implement llvm.setjmp.
664   bool usesUnderscoreSetJmp() const {
665     return UseUnderscoreSetJmp;
666   }
667
668   /// usesUnderscoreLongJmp - Determine if we should use _longjmp or longjmp
669   /// to implement llvm.longjmp.
670   bool usesUnderscoreLongJmp() const {
671     return UseUnderscoreLongJmp;
672   }
673
674   /// getStackPointerRegisterToSaveRestore - If a physical register, this
675   /// specifies the register that llvm.savestack/llvm.restorestack should save
676   /// and restore.
677   unsigned getStackPointerRegisterToSaveRestore() const {
678     return StackPointerRegisterToSaveRestore;
679   }
680
681   /// getExceptionAddressRegister - If a physical register, this returns
682   /// the register that receives the exception address on entry to a landing
683   /// pad.
684   unsigned getExceptionAddressRegister() const {
685     return ExceptionPointerRegister;
686   }
687
688   /// getExceptionSelectorRegister - If a physical register, this returns
689   /// the register that receives the exception typeid on entry to a landing
690   /// pad.
691   unsigned getExceptionSelectorRegister() const {
692     return ExceptionSelectorRegister;
693   }
694
695   /// getJumpBufSize - returns the target's jmp_buf size in bytes (if never
696   /// set, the default is 200)
697   unsigned getJumpBufSize() const {
698     return JumpBufSize;
699   }
700
701   /// getJumpBufAlignment - returns the target's jmp_buf alignment in bytes
702   /// (if never set, the default is 0)
703   unsigned getJumpBufAlignment() const {
704     return JumpBufAlignment;
705   }
706
707   /// getMinStackArgumentAlignment - return the minimum stack alignment of an
708   /// argument.
709   unsigned getMinStackArgumentAlignment() const {
710     return MinStackArgumentAlignment;
711   }
712
713   /// getPrefLoopAlignment - return the preferred loop alignment.
714   ///
715   unsigned getPrefLoopAlignment() const {
716     return PrefLoopAlignment;
717   }
718
719   /// getShouldFoldAtomicFences - return whether the combiner should fold
720   /// fence MEMBARRIER instructions into the atomic intrinsic instructions.
721   ///
722   bool getShouldFoldAtomicFences() const {
723     return ShouldFoldAtomicFences;
724   }
725
726   /// getPreIndexedAddressParts - returns true by value, base pointer and
727   /// offset pointer and addressing mode by reference if the node's address
728   /// can be legally represented as pre-indexed load / store address.
729   virtual bool getPreIndexedAddressParts(SDNode *N, SDValue &Base,
730                                          SDValue &Offset,
731                                          ISD::MemIndexedMode &AM,
732                                          SelectionDAG &DAG) const {
733     return false;
734   }
735
736   /// getPostIndexedAddressParts - returns true by value, base pointer and
737   /// offset pointer and addressing mode by reference if this node can be
738   /// combined with a load / store to form a post-indexed load / store.
739   virtual bool getPostIndexedAddressParts(SDNode *N, SDNode *Op,
740                                           SDValue &Base, SDValue &Offset,
741                                           ISD::MemIndexedMode &AM,
742                                           SelectionDAG &DAG) const {
743     return false;
744   }
745
746   /// getJumpTableEncoding - Return the entry encoding for a jump table in the
747   /// current function.  The returned value is a member of the
748   /// MachineJumpTableInfo::JTEntryKind enum.
749   virtual unsigned getJumpTableEncoding() const;
750
751   virtual const MCExpr *
752   LowerCustomJumpTableEntry(const MachineJumpTableInfo *MJTI,
753                             const MachineBasicBlock *MBB, unsigned uid,
754                             MCContext &Ctx) const {
755     assert(0 && "Need to implement this hook if target has custom JTIs");
756     return 0;
757   }
758
759   /// getPICJumpTableRelocaBase - Returns relocation base for the given PIC
760   /// jumptable.
761   virtual SDValue getPICJumpTableRelocBase(SDValue Table,
762                                            SelectionDAG &DAG) const;
763
764   /// getPICJumpTableRelocBaseExpr - This returns the relocation base for the
765   /// given PIC jumptable, the same as getPICJumpTableRelocBase, but as an
766   /// MCExpr.
767   virtual const MCExpr *
768   getPICJumpTableRelocBaseExpr(const MachineFunction *MF,
769                                unsigned JTI, MCContext &Ctx) const;
770
771   /// isOffsetFoldingLegal - Return true if folding a constant offset
772   /// with the given GlobalAddress is legal.  It is frequently not legal in
773   /// PIC relocation models.
774   virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const;
775
776   /// getFunctionAlignment - Return the Log2 alignment of this function.
777   virtual unsigned getFunctionAlignment(const Function *) const = 0;
778
779   /// getStackCookieLocation - Return true if the target stores stack
780   /// protector cookies at a fixed offset in some non-standard address
781   /// space, and populates the address space and offset as
782   /// appropriate.
783   virtual bool getStackCookieLocation(unsigned &AddressSpace, unsigned &Offset) const {
784     return false;
785   }
786
787   //===--------------------------------------------------------------------===//
788   // TargetLowering Optimization Methods
789   //
790
791   /// TargetLoweringOpt - A convenience struct that encapsulates a DAG, and two
792   /// SDValues for returning information from TargetLowering to its clients
793   /// that want to combine
794   struct TargetLoweringOpt {
795     SelectionDAG &DAG;
796     bool LegalTys;
797     bool LegalOps;
798     SDValue Old;
799     SDValue New;
800
801     explicit TargetLoweringOpt(SelectionDAG &InDAG,
802                                bool LT, bool LO) :
803       DAG(InDAG), LegalTys(LT), LegalOps(LO) {}
804
805     bool LegalTypes() const { return LegalTys; }
806     bool LegalOperations() const { return LegalOps; }
807
808     bool CombineTo(SDValue O, SDValue N) {
809       Old = O;
810       New = N;
811       return true;
812     }
813
814     /// ShrinkDemandedConstant - Check to see if the specified operand of the
815     /// specified instruction is a constant integer.  If so, check to see if
816     /// there are any bits set in the constant that are not demanded.  If so,
817     /// shrink the constant and return true.
818     bool ShrinkDemandedConstant(SDValue Op, const APInt &Demanded);
819
820     /// ShrinkDemandedOp - Convert x+y to (VT)((SmallVT)x+(SmallVT)y) if the
821     /// casts are free.  This uses isZExtFree and ZERO_EXTEND for the widening
822     /// cast, but it could be generalized for targets with other types of
823     /// implicit widening casts.
824     bool ShrinkDemandedOp(SDValue Op, unsigned BitWidth, const APInt &Demanded,
825                           DebugLoc dl);
826   };
827
828   /// SimplifyDemandedBits - Look at Op.  At this point, we know that only the
829   /// DemandedMask bits of the result of Op are ever used downstream.  If we can
830   /// use this information to simplify Op, create a new simplified DAG node and
831   /// return true, returning the original and new nodes in Old and New.
832   /// Otherwise, analyze the expression and return a mask of KnownOne and
833   /// KnownZero bits for the expression (used to simplify the caller).
834   /// The KnownZero/One bits may only be accurate for those bits in the
835   /// DemandedMask.
836   bool SimplifyDemandedBits(SDValue Op, const APInt &DemandedMask,
837                             APInt &KnownZero, APInt &KnownOne,
838                             TargetLoweringOpt &TLO, unsigned Depth = 0) const;
839
840   /// computeMaskedBitsForTargetNode - Determine which of the bits specified in
841   /// Mask are known to be either zero or one and return them in the
842   /// KnownZero/KnownOne bitsets.
843   virtual void computeMaskedBitsForTargetNode(const SDValue Op,
844                                               const APInt &Mask,
845                                               APInt &KnownZero,
846                                               APInt &KnownOne,
847                                               const SelectionDAG &DAG,
848                                               unsigned Depth = 0) const;
849
850   /// ComputeNumSignBitsForTargetNode - This method can be implemented by
851   /// targets that want to expose additional information about sign bits to the
852   /// DAG Combiner.
853   virtual unsigned ComputeNumSignBitsForTargetNode(SDValue Op,
854                                                    unsigned Depth = 0) const;
855
856   struct DAGCombinerInfo {
857     void *DC;  // The DAG Combiner object.
858     bool BeforeLegalize;
859     bool BeforeLegalizeOps;
860     bool CalledByLegalizer;
861   public:
862     SelectionDAG &DAG;
863
864     DAGCombinerInfo(SelectionDAG &dag, bool bl, bool blo, bool cl, void *dc)
865       : DC(dc), BeforeLegalize(bl), BeforeLegalizeOps(blo),
866         CalledByLegalizer(cl), DAG(dag) {}
867
868     bool isBeforeLegalize() const { return BeforeLegalize; }
869     bool isBeforeLegalizeOps() const { return BeforeLegalizeOps; }
870     bool isCalledByLegalizer() const { return CalledByLegalizer; }
871
872     void AddToWorklist(SDNode *N);
873     SDValue CombineTo(SDNode *N, const std::vector<SDValue> &To,
874                       bool AddTo = true);
875     SDValue CombineTo(SDNode *N, SDValue Res, bool AddTo = true);
876     SDValue CombineTo(SDNode *N, SDValue Res0, SDValue Res1, bool AddTo = true);
877
878     void CommitTargetLoweringOpt(const TargetLoweringOpt &TLO);
879   };
880
881   /// SimplifySetCC - Try to simplify a setcc built with the specified operands
882   /// and cc. If it is unable to simplify it, return a null SDValue.
883   SDValue SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
884                           ISD::CondCode Cond, bool foldBooleans,
885                           DAGCombinerInfo &DCI, DebugLoc dl) const;
886
887   /// isGAPlusOffset - Returns true (and the GlobalValue and the offset) if the
888   /// node is a GlobalAddress + offset.
889   virtual bool
890   isGAPlusOffset(SDNode *N, const GlobalValue* &GA, int64_t &Offset) const;
891
892   /// PerformDAGCombine - This method will be invoked for all target nodes and
893   /// for any target-independent nodes that the target has registered with
894   /// invoke it for.
895   ///
896   /// The semantics are as follows:
897   /// Return Value:
898   ///   SDValue.Val == 0   - No change was made
899   ///   SDValue.Val == N   - N was replaced, is dead, and is already handled.
900   ///   otherwise          - N should be replaced by the returned Operand.
901   ///
902   /// In addition, methods provided by DAGCombinerInfo may be used to perform
903   /// more complex transformations.
904   ///
905   virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
906
907   /// isTypeDesirableForOp - Return true if the target has native support for
908   /// the specified value type and it is 'desirable' to use the type for the
909   /// given node type. e.g. On x86 i16 is legal, but undesirable since i16
910   /// instruction encodings are longer and some i16 instructions are slow.
911   virtual bool isTypeDesirableForOp(unsigned Opc, EVT VT) const {
912     // By default, assume all legal types are desirable.
913     return isTypeLegal(VT);
914   }
915
916   /// IsDesirableToPromoteOp - This method query the target whether it is
917   /// beneficial for dag combiner to promote the specified node. If true, it
918   /// should return the desired promotion type by reference.
919   virtual bool IsDesirableToPromoteOp(SDValue Op, EVT &PVT) const {
920     return false;
921   }
922
923   //===--------------------------------------------------------------------===//
924   // TargetLowering Configuration Methods - These methods should be invoked by
925   // the derived class constructor to configure this object for the target.
926   //
927
928 protected:
929   /// setShiftAmountType - Describe the type that should be used for shift
930   /// amounts.  This type defaults to the pointer type.
931   void setShiftAmountType(MVT VT) { ShiftAmountTy = VT; }
932
933   /// setBooleanContents - Specify how the target extends the result of a
934   /// boolean value from i1 to a wider type.  See getBooleanContents.
935   void setBooleanContents(BooleanContent Ty) { BooleanContents = Ty; }
936
937   /// setSchedulingPreference - Specify the target scheduling preference.
938   void setSchedulingPreference(Sched::Preference Pref) {
939     SchedPreferenceInfo = Pref;
940   }
941
942   /// setUseUnderscoreSetJmp - Indicate whether this target prefers to
943   /// use _setjmp to implement llvm.setjmp or the non _ version.
944   /// Defaults to false.
945   void setUseUnderscoreSetJmp(bool Val) {
946     UseUnderscoreSetJmp = Val;
947   }
948
949   /// setUseUnderscoreLongJmp - Indicate whether this target prefers to
950   /// use _longjmp to implement llvm.longjmp or the non _ version.
951   /// Defaults to false.
952   void setUseUnderscoreLongJmp(bool Val) {
953     UseUnderscoreLongJmp = Val;
954   }
955
956   /// setStackPointerRegisterToSaveRestore - If set to a physical register, this
957   /// specifies the register that llvm.savestack/llvm.restorestack should save
958   /// and restore.
959   void setStackPointerRegisterToSaveRestore(unsigned R) {
960     StackPointerRegisterToSaveRestore = R;
961   }
962
963   /// setExceptionPointerRegister - If set to a physical register, this sets
964   /// the register that receives the exception address on entry to a landing
965   /// pad.
966   void setExceptionPointerRegister(unsigned R) {
967     ExceptionPointerRegister = R;
968   }
969
970   /// setExceptionSelectorRegister - If set to a physical register, this sets
971   /// the register that receives the exception typeid on entry to a landing
972   /// pad.
973   void setExceptionSelectorRegister(unsigned R) {
974     ExceptionSelectorRegister = R;
975   }
976
977   /// SelectIsExpensive - Tells the code generator not to expand operations
978   /// into sequences that use the select operations if possible.
979   void setSelectIsExpensive() { SelectIsExpensive = true; }
980
981   /// setIntDivIsCheap - Tells the code generator that integer divide is
982   /// expensive, and if possible, should be replaced by an alternate sequence
983   /// of instructions not containing an integer divide.
984   void setIntDivIsCheap(bool isCheap = true) { IntDivIsCheap = isCheap; }
985
986   /// setPow2DivIsCheap - Tells the code generator that it shouldn't generate
987   /// srl/add/sra for a signed divide by power of two, and let the target handle
988   /// it.
989   void setPow2DivIsCheap(bool isCheap = true) { Pow2DivIsCheap = isCheap; }
990
991   /// addRegisterClass - Add the specified register class as an available
992   /// regclass for the specified value type.  This indicates the selector can
993   /// handle values of that class natively.
994   void addRegisterClass(EVT VT, TargetRegisterClass *RC,
995                         bool isSynthesizable = true) {
996     assert((unsigned)VT.getSimpleVT().SimpleTy < array_lengthof(RegClassForVT));
997     AvailableRegClasses.push_back(std::make_pair(VT, RC));
998     RegClassForVT[VT.getSimpleVT().SimpleTy] = RC;
999     Synthesizable[VT.getSimpleVT().SimpleTy] = isSynthesizable;
1000   }
1001
1002   /// findRepresentativeClass - Return the largest legal super-reg register class
1003   /// of the register class for the specified type and its associated "cost".
1004   virtual std::pair<const TargetRegisterClass*, uint8_t>
1005   findRepresentativeClass(EVT VT) const;
1006
1007   /// computeRegisterProperties - Once all of the register classes are added,
1008   /// this allows us to compute derived properties we expose.
1009   void computeRegisterProperties();
1010
1011   /// setOperationAction - Indicate that the specified operation does not work
1012   /// with the specified type and indicate what to do about it.
1013   void setOperationAction(unsigned Op, MVT VT,
1014                           LegalizeAction Action) {
1015     assert(Op < array_lengthof(OpActions[0]) && "Table isn't big enough!");
1016     OpActions[(unsigned)VT.SimpleTy][Op] = (uint8_t)Action;
1017   }
1018
1019   /// setLoadExtAction - Indicate that the specified load with extension does
1020   /// not work with the specified type and indicate what to do about it.
1021   void setLoadExtAction(unsigned ExtType, MVT VT,
1022                         LegalizeAction Action) {
1023     assert(ExtType < ISD::LAST_LOADEXT_TYPE &&
1024            (unsigned)VT.SimpleTy < MVT::LAST_VALUETYPE &&
1025            "Table isn't big enough!");
1026     LoadExtActions[VT.SimpleTy][ExtType] = (uint8_t)Action;
1027   }
1028
1029   /// setTruncStoreAction - Indicate that the specified truncating store does
1030   /// not work with the specified type and indicate what to do about it.
1031   void setTruncStoreAction(MVT ValVT, MVT MemVT,
1032                            LegalizeAction Action) {
1033     assert((unsigned)ValVT.SimpleTy < MVT::LAST_VALUETYPE &&
1034            (unsigned)MemVT.SimpleTy < MVT::LAST_VALUETYPE &&
1035            "Table isn't big enough!");
1036     TruncStoreActions[ValVT.SimpleTy][MemVT.SimpleTy] = (uint8_t)Action;
1037   }
1038
1039   /// setIndexedLoadAction - Indicate that the specified indexed load does or
1040   /// does not work with the specified type and indicate what to do abort
1041   /// it. NOTE: All indexed mode loads are initialized to Expand in
1042   /// TargetLowering.cpp
1043   void setIndexedLoadAction(unsigned IdxMode, MVT VT,
1044                             LegalizeAction Action) {
1045     assert((unsigned)VT.SimpleTy < MVT::LAST_VALUETYPE &&
1046            IdxMode < ISD::LAST_INDEXED_MODE &&
1047            (unsigned)Action < 0xf &&
1048            "Table isn't big enough!");
1049     // Load action are kept in the upper half.
1050     IndexedModeActions[(unsigned)VT.SimpleTy][IdxMode] &= ~0xf0;
1051     IndexedModeActions[(unsigned)VT.SimpleTy][IdxMode] |= ((uint8_t)Action) <<4;
1052   }
1053
1054   /// setIndexedStoreAction - Indicate that the specified indexed store does or
1055   /// does not work with the specified type and indicate what to do about
1056   /// it. NOTE: All indexed mode stores are initialized to Expand in
1057   /// TargetLowering.cpp
1058   void setIndexedStoreAction(unsigned IdxMode, MVT VT,
1059                              LegalizeAction Action) {
1060     assert((unsigned)VT.SimpleTy < MVT::LAST_VALUETYPE &&
1061            IdxMode < ISD::LAST_INDEXED_MODE &&
1062            (unsigned)Action < 0xf &&
1063            "Table isn't big enough!");
1064     // Store action are kept in the lower half.
1065     IndexedModeActions[(unsigned)VT.SimpleTy][IdxMode] &= ~0x0f;
1066     IndexedModeActions[(unsigned)VT.SimpleTy][IdxMode] |= ((uint8_t)Action);
1067   }
1068
1069   /// setCondCodeAction - Indicate that the specified condition code is or isn't
1070   /// supported on the target and indicate what to do about it.
1071   void setCondCodeAction(ISD::CondCode CC, MVT VT,
1072                          LegalizeAction Action) {
1073     assert((unsigned)VT.SimpleTy < MVT::LAST_VALUETYPE &&
1074            (unsigned)CC < array_lengthof(CondCodeActions) &&
1075            "Table isn't big enough!");
1076     CondCodeActions[(unsigned)CC] &= ~(uint64_t(3UL)  << VT.SimpleTy*2);
1077     CondCodeActions[(unsigned)CC] |= (uint64_t)Action << VT.SimpleTy*2;
1078   }
1079
1080   /// AddPromotedToType - If Opc/OrigVT is specified as being promoted, the
1081   /// promotion code defaults to trying a larger integer/fp until it can find
1082   /// one that works.  If that default is insufficient, this method can be used
1083   /// by the target to override the default.
1084   void AddPromotedToType(unsigned Opc, MVT OrigVT, MVT DestVT) {
1085     PromoteToType[std::make_pair(Opc, OrigVT.SimpleTy)] = DestVT.SimpleTy;
1086   }
1087
1088   /// setTargetDAGCombine - Targets should invoke this method for each target
1089   /// independent node that they want to provide a custom DAG combiner for by
1090   /// implementing the PerformDAGCombine virtual method.
1091   void setTargetDAGCombine(ISD::NodeType NT) {
1092     assert(unsigned(NT >> 3) < array_lengthof(TargetDAGCombineArray));
1093     TargetDAGCombineArray[NT >> 3] |= 1 << (NT&7);
1094   }
1095
1096   /// setJumpBufSize - Set the target's required jmp_buf buffer size (in
1097   /// bytes); default is 200
1098   void setJumpBufSize(unsigned Size) {
1099     JumpBufSize = Size;
1100   }
1101
1102   /// setJumpBufAlignment - Set the target's required jmp_buf buffer
1103   /// alignment (in bytes); default is 0
1104   void setJumpBufAlignment(unsigned Align) {
1105     JumpBufAlignment = Align;
1106   }
1107
1108   /// setPrefLoopAlignment - Set the target's preferred loop alignment. Default
1109   /// alignment is zero, it means the target does not care about loop alignment.
1110   void setPrefLoopAlignment(unsigned Align) {
1111     PrefLoopAlignment = Align;
1112   }
1113
1114   /// setMinStackArgumentAlignment - Set the minimum stack alignment of an
1115   /// argument.
1116   void setMinStackArgumentAlignment(unsigned Align) {
1117     MinStackArgumentAlignment = Align;
1118   }
1119
1120   /// setShouldFoldAtomicFences - Set if the target's implementation of the
1121   /// atomic operation intrinsics includes locking. Default is false.
1122   void setShouldFoldAtomicFences(bool fold) {
1123     ShouldFoldAtomicFences = fold;
1124   }
1125
1126 public:
1127   //===--------------------------------------------------------------------===//
1128   // Lowering methods - These methods must be implemented by targets so that
1129   // the SelectionDAGLowering code knows how to lower these.
1130   //
1131
1132   /// LowerFormalArguments - This hook must be implemented to lower the
1133   /// incoming (formal) arguments, described by the Ins array, into the
1134   /// specified DAG. The implementation should fill in the InVals array
1135   /// with legal-type argument values, and return the resulting token
1136   /// chain value.
1137   ///
1138   virtual SDValue
1139     LowerFormalArguments(SDValue Chain,
1140                          CallingConv::ID CallConv, bool isVarArg,
1141                          const SmallVectorImpl<ISD::InputArg> &Ins,
1142                          DebugLoc dl, SelectionDAG &DAG,
1143                          SmallVectorImpl<SDValue> &InVals) const {
1144     assert(0 && "Not Implemented");
1145     return SDValue();    // this is here to silence compiler errors
1146   }
1147
1148   /// LowerCallTo - This function lowers an abstract call to a function into an
1149   /// actual call.  This returns a pair of operands.  The first element is the
1150   /// return value for the function (if RetTy is not VoidTy).  The second
1151   /// element is the outgoing token chain. It calls LowerCall to do the actual
1152   /// lowering.
1153   struct ArgListEntry {
1154     SDValue Node;
1155     const Type* Ty;
1156     bool isSExt  : 1;
1157     bool isZExt  : 1;
1158     bool isInReg : 1;
1159     bool isSRet  : 1;
1160     bool isNest  : 1;
1161     bool isByVal : 1;
1162     uint16_t Alignment;
1163
1164     ArgListEntry() : isSExt(false), isZExt(false), isInReg(false),
1165       isSRet(false), isNest(false), isByVal(false), Alignment(0) { }
1166   };
1167   typedef std::vector<ArgListEntry> ArgListTy;
1168   std::pair<SDValue, SDValue>
1169   LowerCallTo(SDValue Chain, const Type *RetTy, bool RetSExt, bool RetZExt,
1170               bool isVarArg, bool isInreg, unsigned NumFixedArgs,
1171               CallingConv::ID CallConv, bool isTailCall,
1172               bool isReturnValueUsed, SDValue Callee, ArgListTy &Args,
1173               SelectionDAG &DAG, DebugLoc dl) const;
1174
1175   /// LowerCall - This hook must be implemented to lower calls into the
1176   /// the specified DAG. The outgoing arguments to the call are described
1177   /// by the Outs array, and the values to be returned by the call are
1178   /// described by the Ins array. The implementation should fill in the
1179   /// InVals array with legal-type return values from the call, and return
1180   /// the resulting token chain value.
1181   virtual SDValue
1182     LowerCall(SDValue Chain, SDValue Callee,
1183               CallingConv::ID CallConv, bool isVarArg, bool &isTailCall,
1184               const SmallVectorImpl<ISD::OutputArg> &Outs,
1185               const SmallVectorImpl<SDValue> &OutVals,
1186               const SmallVectorImpl<ISD::InputArg> &Ins,
1187               DebugLoc dl, SelectionDAG &DAG,
1188               SmallVectorImpl<SDValue> &InVals) const {
1189     assert(0 && "Not Implemented");
1190     return SDValue();    // this is here to silence compiler errors
1191   }
1192
1193   /// CanLowerReturn - This hook should be implemented to check whether the
1194   /// return values described by the Outs array can fit into the return
1195   /// registers.  If false is returned, an sret-demotion is performed.
1196   ///
1197   virtual bool CanLowerReturn(CallingConv::ID CallConv, bool isVarArg,
1198                const SmallVectorImpl<ISD::OutputArg> &Outs,
1199                LLVMContext &Context) const
1200   {
1201     // Return true by default to get preexisting behavior.
1202     return true;
1203   }
1204
1205   /// LowerReturn - This hook must be implemented to lower outgoing
1206   /// return values, described by the Outs array, into the specified
1207   /// DAG. The implementation should return the resulting token chain
1208   /// value.
1209   ///
1210   virtual SDValue
1211     LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
1212                 const SmallVectorImpl<ISD::OutputArg> &Outs,
1213                 const SmallVectorImpl<SDValue> &OutVals,
1214                 DebugLoc dl, SelectionDAG &DAG) const {
1215     assert(0 && "Not Implemented");
1216     return SDValue();    // this is here to silence compiler errors
1217   }
1218
1219   /// LowerOperationWrapper - This callback is invoked by the type legalizer
1220   /// to legalize nodes with an illegal operand type but legal result types.
1221   /// It replaces the LowerOperation callback in the type Legalizer.
1222   /// The reason we can not do away with LowerOperation entirely is that
1223   /// LegalizeDAG isn't yet ready to use this callback.
1224   /// TODO: Consider merging with ReplaceNodeResults.
1225
1226   /// The target places new result values for the node in Results (their number
1227   /// and types must exactly match those of the original return values of
1228   /// the node), or leaves Results empty, which indicates that the node is not
1229   /// to be custom lowered after all.
1230   /// The default implementation calls LowerOperation.
1231   virtual void LowerOperationWrapper(SDNode *N,
1232                                      SmallVectorImpl<SDValue> &Results,
1233                                      SelectionDAG &DAG) const;
1234
1235   /// LowerOperation - This callback is invoked for operations that are
1236   /// unsupported by the target, which are registered to use 'custom' lowering,
1237   /// and whose defined values are all legal.
1238   /// If the target has no operations that require custom lowering, it need not
1239   /// implement this.  The default implementation of this aborts.
1240   virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const;
1241
1242   /// ReplaceNodeResults - This callback is invoked when a node result type is
1243   /// illegal for the target, and the operation was registered to use 'custom'
1244   /// lowering for that result type.  The target places new result values for
1245   /// the node in Results (their number and types must exactly match those of
1246   /// the original return values of the node), or leaves Results empty, which
1247   /// indicates that the node is not to be custom lowered after all.
1248   ///
1249   /// If the target has no operations that require custom lowering, it need not
1250   /// implement this.  The default implementation aborts.
1251   virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
1252                                   SelectionDAG &DAG) const {
1253     assert(0 && "ReplaceNodeResults not implemented for this target!");
1254   }
1255
1256   /// getTargetNodeName() - This method returns the name of a target specific
1257   /// DAG node.
1258   virtual const char *getTargetNodeName(unsigned Opcode) const;
1259
1260   /// createFastISel - This method returns a target specific FastISel object,
1261   /// or null if the target does not support "fast" ISel.
1262   virtual FastISel *createFastISel(FunctionLoweringInfo &funcInfo) const {
1263     return 0;
1264   }
1265
1266   //===--------------------------------------------------------------------===//
1267   // Inline Asm Support hooks
1268   //
1269
1270   /// ExpandInlineAsm - This hook allows the target to expand an inline asm
1271   /// call to be explicit llvm code if it wants to.  This is useful for
1272   /// turning simple inline asms into LLVM intrinsics, which gives the
1273   /// compiler more information about the behavior of the code.
1274   virtual bool ExpandInlineAsm(CallInst *CI) const {
1275     return false;
1276   }
1277
1278   enum ConstraintType {
1279     C_Register,            // Constraint represents specific register(s).
1280     C_RegisterClass,       // Constraint represents any of register(s) in class.
1281     C_Memory,              // Memory constraint.
1282     C_Other,               // Something else.
1283     C_Unknown              // Unsupported constraint.
1284   };
1285
1286   /// AsmOperandInfo - This contains information for each constraint that we are
1287   /// lowering.
1288   struct AsmOperandInfo : public InlineAsm::ConstraintInfo {
1289     /// ConstraintCode - This contains the actual string for the code, like "m".
1290     /// TargetLowering picks the 'best' code from ConstraintInfo::Codes that
1291     /// most closely matches the operand.
1292     std::string ConstraintCode;
1293
1294     /// ConstraintType - Information about the constraint code, e.g. Register,
1295     /// RegisterClass, Memory, Other, Unknown.
1296     TargetLowering::ConstraintType ConstraintType;
1297
1298     /// CallOperandval - If this is the result output operand or a
1299     /// clobber, this is null, otherwise it is the incoming operand to the
1300     /// CallInst.  This gets modified as the asm is processed.
1301     Value *CallOperandVal;
1302
1303     /// ConstraintVT - The ValueType for the operand value.
1304     EVT ConstraintVT;
1305
1306     /// isMatchingInputConstraint - Return true of this is an input operand that
1307     /// is a matching constraint like "4".
1308     bool isMatchingInputConstraint() const;
1309
1310     /// getMatchedOperand - If this is an input matching constraint, this method
1311     /// returns the output operand it matches.
1312     unsigned getMatchedOperand() const;
1313
1314     AsmOperandInfo(const InlineAsm::ConstraintInfo &info)
1315       : InlineAsm::ConstraintInfo(info),
1316         ConstraintType(TargetLowering::C_Unknown),
1317         CallOperandVal(0), ConstraintVT(MVT::Other) {
1318     }
1319   };
1320
1321   /// ComputeConstraintToUse - Determines the constraint code and constraint
1322   /// type to use for the specific AsmOperandInfo, setting
1323   /// OpInfo.ConstraintCode and OpInfo.ConstraintType.  If the actual operand
1324   /// being passed in is available, it can be passed in as Op, otherwise an
1325   /// empty SDValue can be passed. 
1326   virtual void ComputeConstraintToUse(AsmOperandInfo &OpInfo,
1327                                       SDValue Op,
1328                                       SelectionDAG *DAG = 0) const;
1329
1330   /// getConstraintType - Given a constraint, return the type of constraint it
1331   /// is for this target.
1332   virtual ConstraintType getConstraintType(const std::string &Constraint) const;
1333
1334   /// getRegClassForInlineAsmConstraint - Given a constraint letter (e.g. "r"),
1335   /// return a list of registers that can be used to satisfy the constraint.
1336   /// This should only be used for C_RegisterClass constraints.
1337   virtual std::vector<unsigned>
1338   getRegClassForInlineAsmConstraint(const std::string &Constraint,
1339                                     EVT VT) const;
1340
1341   /// getRegForInlineAsmConstraint - Given a physical register constraint (e.g.
1342   /// {edx}), return the register number and the register class for the
1343   /// register.
1344   ///
1345   /// Given a register class constraint, like 'r', if this corresponds directly
1346   /// to an LLVM register class, return a register of 0 and the register class
1347   /// pointer.
1348   ///
1349   /// This should only be used for C_Register constraints.  On error,
1350   /// this returns a register number of 0 and a null register class pointer..
1351   virtual std::pair<unsigned, const TargetRegisterClass*>
1352     getRegForInlineAsmConstraint(const std::string &Constraint,
1353                                  EVT VT) const;
1354
1355   /// LowerXConstraint - try to replace an X constraint, which matches anything,
1356   /// with another that has more specific requirements based on the type of the
1357   /// corresponding operand.  This returns null if there is no replacement to
1358   /// make.
1359   virtual const char *LowerXConstraint(EVT ConstraintVT) const;
1360
1361   /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
1362   /// vector.  If it is invalid, don't add anything to Ops.
1363   virtual void LowerAsmOperandForConstraint(SDValue Op, char ConstraintLetter,
1364                                             std::vector<SDValue> &Ops,
1365                                             SelectionDAG &DAG) const;
1366
1367   //===--------------------------------------------------------------------===//
1368   // Instruction Emitting Hooks
1369   //
1370
1371   // EmitInstrWithCustomInserter - This method should be implemented by targets
1372   // that mark instructions with the 'usesCustomInserter' flag.  These
1373   // instructions are special in various ways, which require special support to
1374   // insert.  The specified MachineInstr is created but not inserted into any
1375   // basic blocks, and this method is called to expand it into a sequence of
1376   // instructions, potentially also creating new basic blocks and control flow.
1377   virtual MachineBasicBlock *
1378     EmitInstrWithCustomInserter(MachineInstr *MI, MachineBasicBlock *MBB) const;
1379
1380   //===--------------------------------------------------------------------===//
1381   // Addressing mode description hooks (used by LSR etc).
1382   //
1383
1384   /// AddrMode - This represents an addressing mode of:
1385   ///    BaseGV + BaseOffs + BaseReg + Scale*ScaleReg
1386   /// If BaseGV is null,  there is no BaseGV.
1387   /// If BaseOffs is zero, there is no base offset.
1388   /// If HasBaseReg is false, there is no base register.
1389   /// If Scale is zero, there is no ScaleReg.  Scale of 1 indicates a reg with
1390   /// no scale.
1391   ///
1392   struct AddrMode {
1393     GlobalValue *BaseGV;
1394     int64_t      BaseOffs;
1395     bool         HasBaseReg;
1396     int64_t      Scale;
1397     AddrMode() : BaseGV(0), BaseOffs(0), HasBaseReg(false), Scale(0) {}
1398   };
1399
1400   /// isLegalAddressingMode - Return true if the addressing mode represented by
1401   /// AM is legal for this target, for a load/store of the specified type.
1402   /// The type may be VoidTy, in which case only return true if the addressing
1403   /// mode is legal for a load/store of any legal type.
1404   /// TODO: Handle pre/postinc as well.
1405   virtual bool isLegalAddressingMode(const AddrMode &AM, const Type *Ty) const;
1406
1407   /// isTruncateFree - Return true if it's free to truncate a value of
1408   /// type Ty1 to type Ty2. e.g. On x86 it's free to truncate a i32 value in
1409   /// register EAX to i16 by referencing its sub-register AX.
1410   virtual bool isTruncateFree(const Type *Ty1, const Type *Ty2) const {
1411     return false;
1412   }
1413
1414   virtual bool isTruncateFree(EVT VT1, EVT VT2) const {
1415     return false;
1416   }
1417
1418   /// isZExtFree - Return true if any actual instruction that defines a
1419   /// value of type Ty1 implicitly zero-extends the value to Ty2 in the result
1420   /// register. This does not necessarily include registers defined in
1421   /// unknown ways, such as incoming arguments, or copies from unknown
1422   /// virtual registers. Also, if isTruncateFree(Ty2, Ty1) is true, this
1423   /// does not necessarily apply to truncate instructions. e.g. on x86-64,
1424   /// all instructions that define 32-bit values implicit zero-extend the
1425   /// result out to 64 bits.
1426   virtual bool isZExtFree(const Type *Ty1, const Type *Ty2) const {
1427     return false;
1428   }
1429
1430   virtual bool isZExtFree(EVT VT1, EVT VT2) const {
1431     return false;
1432   }
1433
1434   /// isNarrowingProfitable - Return true if it's profitable to narrow
1435   /// operations of type VT1 to VT2. e.g. on x86, it's profitable to narrow
1436   /// from i32 to i8 but not from i32 to i16.
1437   virtual bool isNarrowingProfitable(EVT VT1, EVT VT2) const {
1438     return false;
1439   }
1440
1441   /// isLegalICmpImmediate - Return true if the specified immediate is legal
1442   /// icmp immediate, that is the target has icmp instructions which can compare
1443   /// a register against the immediate without having to materialize the
1444   /// immediate into a register.
1445   virtual bool isLegalICmpImmediate(int64_t Imm) const {
1446     return true;
1447   }
1448
1449   //===--------------------------------------------------------------------===//
1450   // Div utility functions
1451   //
1452   SDValue BuildSDIV(SDNode *N, SelectionDAG &DAG,
1453                       std::vector<SDNode*>* Created) const;
1454   SDValue BuildUDIV(SDNode *N, SelectionDAG &DAG,
1455                       std::vector<SDNode*>* Created) const;
1456
1457
1458   //===--------------------------------------------------------------------===//
1459   // Runtime Library hooks
1460   //
1461
1462   /// setLibcallName - Rename the default libcall routine name for the specified
1463   /// libcall.
1464   void setLibcallName(RTLIB::Libcall Call, const char *Name) {
1465     LibcallRoutineNames[Call] = Name;
1466   }
1467
1468   /// getLibcallName - Get the libcall routine name for the specified libcall.
1469   ///
1470   const char *getLibcallName(RTLIB::Libcall Call) const {
1471     return LibcallRoutineNames[Call];
1472   }
1473
1474   /// setCmpLibcallCC - Override the default CondCode to be used to test the
1475   /// result of the comparison libcall against zero.
1476   void setCmpLibcallCC(RTLIB::Libcall Call, ISD::CondCode CC) {
1477     CmpLibcallCCs[Call] = CC;
1478   }
1479
1480   /// getCmpLibcallCC - Get the CondCode that's to be used to test the result of
1481   /// the comparison libcall against zero.
1482   ISD::CondCode getCmpLibcallCC(RTLIB::Libcall Call) const {
1483     return CmpLibcallCCs[Call];
1484   }
1485
1486   /// setLibcallCallingConv - Set the CallingConv that should be used for the
1487   /// specified libcall.
1488   void setLibcallCallingConv(RTLIB::Libcall Call, CallingConv::ID CC) {
1489     LibcallCallingConvs[Call] = CC;
1490   }
1491
1492   /// getLibcallCallingConv - Get the CallingConv that should be used for the
1493   /// specified libcall.
1494   CallingConv::ID getLibcallCallingConv(RTLIB::Libcall Call) const {
1495     return LibcallCallingConvs[Call];
1496   }
1497
1498 private:
1499   const TargetMachine &TM;
1500   const TargetData *TD;
1501   const TargetLoweringObjectFile &TLOF;
1502
1503   /// PointerTy - The type to use for pointers, usually i32 or i64.
1504   ///
1505   MVT PointerTy;
1506
1507   /// IsLittleEndian - True if this is a little endian target.
1508   ///
1509   bool IsLittleEndian;
1510
1511   /// SelectIsExpensive - Tells the code generator not to expand operations
1512   /// into sequences that use the select operations if possible.
1513   bool SelectIsExpensive;
1514
1515   /// IntDivIsCheap - Tells the code generator not to expand integer divides by
1516   /// constants into a sequence of muls, adds, and shifts.  This is a hack until
1517   /// a real cost model is in place.  If we ever optimize for size, this will be
1518   /// set to true unconditionally.
1519   bool IntDivIsCheap;
1520
1521   /// Pow2DivIsCheap - Tells the code generator that it shouldn't generate
1522   /// srl/add/sra for a signed divide by power of two, and let the target handle
1523   /// it.
1524   bool Pow2DivIsCheap;
1525
1526   /// UseUnderscoreSetJmp - This target prefers to use _setjmp to implement
1527   /// llvm.setjmp.  Defaults to false.
1528   bool UseUnderscoreSetJmp;
1529
1530   /// UseUnderscoreLongJmp - This target prefers to use _longjmp to implement
1531   /// llvm.longjmp.  Defaults to false.
1532   bool UseUnderscoreLongJmp;
1533
1534   /// ShiftAmountTy - The type to use for shift amounts, usually i8 or whatever
1535   /// PointerTy is.
1536   MVT ShiftAmountTy;
1537
1538   /// BooleanContents - Information about the contents of the high-bits in
1539   /// boolean values held in a type wider than i1.  See getBooleanContents.
1540   BooleanContent BooleanContents;
1541
1542   /// SchedPreferenceInfo - The target scheduling preference: shortest possible
1543   /// total cycles or lowest register usage.
1544   Sched::Preference SchedPreferenceInfo;
1545
1546   /// JumpBufSize - The size, in bytes, of the target's jmp_buf buffers
1547   unsigned JumpBufSize;
1548
1549   /// JumpBufAlignment - The alignment, in bytes, of the target's jmp_buf
1550   /// buffers
1551   unsigned JumpBufAlignment;
1552
1553   /// MinStackArgumentAlignment - The minimum alignment that any argument
1554   /// on the stack needs to have.
1555   ///
1556   unsigned MinStackArgumentAlignment;
1557
1558   /// PrefLoopAlignment - The perferred loop alignment.
1559   ///
1560   unsigned PrefLoopAlignment;
1561
1562   /// ShouldFoldAtomicFences - Whether fencing MEMBARRIER instructions should
1563   /// be folded into the enclosed atomic intrinsic instruction by the
1564   /// combiner.
1565   bool ShouldFoldAtomicFences;
1566
1567   /// StackPointerRegisterToSaveRestore - If set to a physical register, this
1568   /// specifies the register that llvm.savestack/llvm.restorestack should save
1569   /// and restore.
1570   unsigned StackPointerRegisterToSaveRestore;
1571
1572   /// ExceptionPointerRegister - If set to a physical register, this specifies
1573   /// the register that receives the exception address on entry to a landing
1574   /// pad.
1575   unsigned ExceptionPointerRegister;
1576
1577   /// ExceptionSelectorRegister - If set to a physical register, this specifies
1578   /// the register that receives the exception typeid on entry to a landing
1579   /// pad.
1580   unsigned ExceptionSelectorRegister;
1581
1582   /// RegClassForVT - This indicates the default register class to use for
1583   /// each ValueType the target supports natively.
1584   TargetRegisterClass *RegClassForVT[MVT::LAST_VALUETYPE];
1585   unsigned char NumRegistersForVT[MVT::LAST_VALUETYPE];
1586   EVT RegisterTypeForVT[MVT::LAST_VALUETYPE];
1587
1588   /// RepRegClassForVT - This indicates the "representative" register class to
1589   /// use for each ValueType the target supports natively. This information is
1590   /// used by the scheduler to track register pressure. By default, the
1591   /// representative register class is the largest legal super-reg register
1592   /// class of the register class of the specified type. e.g. On x86, i8, i16,
1593   /// and i32's representative class would be GR32.
1594   const TargetRegisterClass *RepRegClassForVT[MVT::LAST_VALUETYPE];
1595
1596   /// RepRegClassCostForVT - This indicates the "cost" of the "representative"
1597   /// register class for each ValueType. The cost is used by the scheduler to
1598   /// approximate register pressure.
1599   uint8_t RepRegClassCostForVT[MVT::LAST_VALUETYPE];
1600
1601   /// Synthesizable indicates whether it is OK for the compiler to create new
1602   /// operations using this type.  All Legal types are Synthesizable except
1603   /// MMX types on X86.  Non-Legal types are not Synthesizable.
1604   bool Synthesizable[MVT::LAST_VALUETYPE];
1605
1606   /// TransformToType - For any value types we are promoting or expanding, this
1607   /// contains the value type that we are changing to.  For Expanded types, this
1608   /// contains one step of the expand (e.g. i64 -> i32), even if there are
1609   /// multiple steps required (e.g. i64 -> i16).  For types natively supported
1610   /// by the system, this holds the same type (e.g. i32 -> i32).
1611   EVT TransformToType[MVT::LAST_VALUETYPE];
1612
1613   /// OpActions - For each operation and each value type, keep a LegalizeAction
1614   /// that indicates how instruction selection should deal with the operation.
1615   /// Most operations are Legal (aka, supported natively by the target), but
1616   /// operations that are not should be described.  Note that operations on
1617   /// non-legal value types are not described here.
1618   uint8_t OpActions[MVT::LAST_VALUETYPE][ISD::BUILTIN_OP_END];
1619
1620   /// LoadExtActions - For each load extension type and each value type,
1621   /// keep a LegalizeAction that indicates how instruction selection should deal
1622   /// with a load of a specific value type and extension type.
1623   uint8_t LoadExtActions[MVT::LAST_VALUETYPE][ISD::LAST_LOADEXT_TYPE];
1624
1625   /// TruncStoreActions - For each value type pair keep a LegalizeAction that
1626   /// indicates whether a truncating store of a specific value type and
1627   /// truncating type is legal.
1628   uint8_t TruncStoreActions[MVT::LAST_VALUETYPE][MVT::LAST_VALUETYPE];
1629
1630   /// IndexedModeActions - For each indexed mode and each value type,
1631   /// keep a pair of LegalizeAction that indicates how instruction
1632   /// selection should deal with the load / store.  The first dimension is the
1633   /// value_type for the reference. The second dimension represents the various
1634   /// modes for load store.
1635   uint8_t IndexedModeActions[MVT::LAST_VALUETYPE][ISD::LAST_INDEXED_MODE];
1636
1637   /// CondCodeActions - For each condition code (ISD::CondCode) keep a
1638   /// LegalizeAction that indicates how instruction selection should
1639   /// deal with the condition code.
1640   uint64_t CondCodeActions[ISD::SETCC_INVALID];
1641
1642   ValueTypeActionImpl ValueTypeActions;
1643
1644   std::vector<std::pair<EVT, TargetRegisterClass*> > AvailableRegClasses;
1645
1646   /// TargetDAGCombineArray - Targets can specify ISD nodes that they would
1647   /// like PerformDAGCombine callbacks for by calling setTargetDAGCombine(),
1648   /// which sets a bit in this array.
1649   unsigned char
1650   TargetDAGCombineArray[(ISD::BUILTIN_OP_END+CHAR_BIT-1)/CHAR_BIT];
1651
1652   /// PromoteToType - For operations that must be promoted to a specific type,
1653   /// this holds the destination type.  This map should be sparse, so don't hold
1654   /// it as an array.
1655   ///
1656   /// Targets add entries to this map with AddPromotedToType(..), clients access
1657   /// this with getTypeToPromoteTo(..).
1658   std::map<std::pair<unsigned, MVT::SimpleValueType>, MVT::SimpleValueType>
1659     PromoteToType;
1660
1661   /// LibcallRoutineNames - Stores the name each libcall.
1662   ///
1663   const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL];
1664
1665   /// CmpLibcallCCs - The ISD::CondCode that should be used to test the result
1666   /// of each of the comparison libcall against zero.
1667   ISD::CondCode CmpLibcallCCs[RTLIB::UNKNOWN_LIBCALL];
1668
1669   /// LibcallCallingConvs - Stores the CallingConv that should be used for each
1670   /// libcall.
1671   CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL];
1672
1673 protected:
1674   /// When lowering \@llvm.memset this field specifies the maximum number of
1675   /// store operations that may be substituted for the call to memset. Targets
1676   /// must set this value based on the cost threshold for that target. Targets
1677   /// should assume that the memset will be done using as many of the largest
1678   /// store operations first, followed by smaller ones, if necessary, per
1679   /// alignment restrictions. For example, storing 9 bytes on a 32-bit machine
1680   /// with 16-bit alignment would result in four 2-byte stores and one 1-byte
1681   /// store.  This only applies to setting a constant array of a constant size.
1682   /// @brief Specify maximum number of store instructions per memset call.
1683   unsigned maxStoresPerMemset;
1684
1685   /// When lowering \@llvm.memcpy this field specifies the maximum number of
1686   /// store operations that may be substituted for a call to memcpy. Targets
1687   /// must set this value based on the cost threshold for that target. Targets
1688   /// should assume that the memcpy will be done using as many of the largest
1689   /// store operations first, followed by smaller ones, if necessary, per
1690   /// alignment restrictions. For example, storing 7 bytes on a 32-bit machine
1691   /// with 32-bit alignment would result in one 4-byte store, a one 2-byte store
1692   /// and one 1-byte store. This only applies to copying a constant array of
1693   /// constant size.
1694   /// @brief Specify maximum bytes of store instructions per memcpy call.
1695   unsigned maxStoresPerMemcpy;
1696
1697   /// When lowering \@llvm.memmove this field specifies the maximum number of
1698   /// store instructions that may be substituted for a call to memmove. Targets
1699   /// must set this value based on the cost threshold for that target. Targets
1700   /// should assume that the memmove will be done using as many of the largest
1701   /// store operations first, followed by smaller ones, if necessary, per
1702   /// alignment restrictions. For example, moving 9 bytes on a 32-bit machine
1703   /// with 8-bit alignment would result in nine 1-byte stores.  This only
1704   /// applies to copying a constant array of constant size.
1705   /// @brief Specify maximum bytes of store instructions per memmove call.
1706   unsigned maxStoresPerMemmove;
1707
1708   /// This field specifies whether the target can benefit from code placement
1709   /// optimization.
1710   bool benefitFromCodePlacementOpt;
1711
1712 private:
1713   /// isLegalRC - Return true if the value types that can be represented by the
1714   /// specified register class are all legal.
1715   bool isLegalRC(const TargetRegisterClass *RC) const;
1716
1717   /// hasLegalSuperRegRegClasses - Return true if the specified register class
1718   /// has one or more super-reg register classes that are legal.
1719   bool hasLegalSuperRegRegClasses(const TargetRegisterClass *RC) const;
1720 };
1721
1722 /// GetReturnInfo - Given an LLVM IR type and return type attributes,
1723 /// compute the return value EVTs and flags, and optionally also
1724 /// the offsets, if the return value is being lowered to memory.
1725 void GetReturnInfo(const Type* ReturnType, Attributes attr,
1726                    SmallVectorImpl<ISD::OutputArg> &Outs,
1727                    const TargetLowering &TLI,
1728                    SmallVectorImpl<uint64_t> *Offsets = 0);
1729
1730 } // end llvm namespace
1731
1732 #endif