c4cb100508eb6325e812098e0c8a6369928ad2c8
[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/Support/CallSite.h"
29 #include "llvm/CodeGen/SelectionDAGNodes.h"
30 #include "llvm/CodeGen/RuntimeLibcalls.h"
31 #include "llvm/Support/DebugLoc.h"
32 #include "llvm/Target/TargetCallingConv.h"
33 #include "llvm/Target/TargetMachine.h"
34 #include <climits>
35 #include <map>
36 #include <vector>
37
38 namespace llvm {
39   class CallInst;
40   class CCState;
41   class FastISel;
42   class FunctionLoweringInfo;
43   class ImmutableCallSite;
44   class IntrinsicInst;
45   class MachineBasicBlock;
46   class MachineFunction;
47   class MachineInstr;
48   class MachineJumpTableInfo;
49   class MCContext;
50   class MCExpr;
51   template<typename T> class SmallVectorImpl;
52   class TargetData;
53   class TargetRegisterClass;
54   class TargetLoweringObjectFile;
55   class Value;
56
57   namespace Sched {
58     enum Preference {
59       None,             // No preference
60       Source,           // Follow source order.
61       RegPressure,      // Scheduling for lowest register pressure.
62       Hybrid,           // Scheduling for both latency and register pressure.
63       ILP,              // Scheduling for ILP in low register pressure mode.
64       VLIW              // Scheduling for VLIW targets.
65     };
66   }
67
68
69 //===----------------------------------------------------------------------===//
70 /// TargetLowering - This class defines information used to lower LLVM code to
71 /// legal SelectionDAG operators that the target instruction selector can accept
72 /// natively.
73 ///
74 /// This class also defines callbacks that targets must implement to lower
75 /// target-specific constructs to SelectionDAG operators.
76 ///
77 class TargetLowering {
78   TargetLowering(const TargetLowering&);  // DO NOT IMPLEMENT
79   void operator=(const TargetLowering&);  // DO NOT IMPLEMENT
80 public:
81   /// LegalizeAction - This enum indicates whether operations are valid for a
82   /// target, and if not, what action should be used to make them valid.
83   enum LegalizeAction {
84     Legal,      // The target natively supports this operation.
85     Promote,    // This operation should be executed in a larger type.
86     Expand,     // Try to expand this to other ops, otherwise use a libcall.
87     Custom      // Use the LowerOperation hook to implement custom lowering.
88   };
89
90   /// LegalizeTypeAction - This enum indicates whether a types are legal for a
91   /// target, and if not, what action should be used to make them valid.
92   enum LegalizeTypeAction {
93     TypeLegal,           // The target natively supports this type.
94     TypePromoteInteger,  // Replace this integer with a larger one.
95     TypeExpandInteger,   // Split this integer into two of half the size.
96     TypeSoftenFloat,     // Convert this float to a same size integer type.
97     TypeExpandFloat,     // Split this float into two of half the size.
98     TypeScalarizeVector, // Replace this one-element vector with its element.
99     TypeSplitVector,     // Split this vector into two of half the size.
100     TypeWidenVector      // This vector should be widened into a larger vector.
101   };
102
103   enum BooleanContent { // How the target represents true/false values.
104     UndefinedBooleanContent,    // Only bit 0 counts, the rest can hold garbage.
105     ZeroOrOneBooleanContent,        // All bits zero except for bit 0.
106     ZeroOrNegativeOneBooleanContent // All bits equal to bit 0.
107   };
108
109   static ISD::NodeType getExtendForContent(BooleanContent Content) {
110     switch (Content) {
111     case UndefinedBooleanContent:
112       // Extend by adding rubbish bits.
113       return ISD::ANY_EXTEND;
114     case ZeroOrOneBooleanContent:
115       // Extend by adding zero bits.
116       return ISD::ZERO_EXTEND;
117     case ZeroOrNegativeOneBooleanContent:
118       // Extend by copying the sign bit.
119       return ISD::SIGN_EXTEND;
120     }
121     llvm_unreachable("Invalid content kind");
122   }
123
124   /// NOTE: The constructor takes ownership of TLOF.
125   explicit TargetLowering(const TargetMachine &TM,
126                           const TargetLoweringObjectFile *TLOF);
127   virtual ~TargetLowering();
128
129   const TargetMachine &getTargetMachine() const { return TM; }
130   const TargetData *getTargetData() const { return TD; }
131   const TargetLoweringObjectFile &getObjFileLowering() const { return TLOF; }
132
133   bool isBigEndian() const { return !IsLittleEndian; }
134   bool isLittleEndian() const { return IsLittleEndian; }
135   MVT getPointerTy() const { return PointerTy; }
136   virtual MVT getShiftAmountTy(EVT LHSTy) const;
137
138   /// isSelectExpensive - Return true if the select operation is expensive for
139   /// this target.
140   bool isSelectExpensive() const { return SelectIsExpensive; }
141
142   /// isIntDivCheap() - Return true if integer divide is usually cheaper than
143   /// a sequence of several shifts, adds, and multiplies for this target.
144   bool isIntDivCheap() const { return IntDivIsCheap; }
145
146   /// isPow2DivCheap() - Return true if pow2 div is cheaper than a chain of
147   /// srl/add/sra.
148   bool isPow2DivCheap() const { return Pow2DivIsCheap; }
149
150   /// isJumpExpensive() - Return true if Flow Control is an expensive operation
151   /// that should be avoided.
152   bool isJumpExpensive() const { return JumpIsExpensive; }
153
154   /// isPredictableSelectExpensive - Return true if selects are only cheaper
155   /// than branches if the branch is unlikely to be predicted right.
156   bool isPredictableSelectExpensive() const {
157     return predictableSelectIsExpensive;
158   }
159
160   /// getSetCCResultType - Return the ValueType of the result of SETCC
161   /// operations.  Also used to obtain the target's preferred type for
162   /// the condition operand of SELECT and BRCOND nodes.  In the case of
163   /// BRCOND the argument passed is MVT::Other since there are no other
164   /// operands to get a type hint from.
165   virtual EVT getSetCCResultType(EVT VT) const;
166
167   /// getCmpLibcallReturnType - Return the ValueType for comparison
168   /// libcalls. Comparions libcalls include floating point comparion calls,
169   /// and Ordered/Unordered check calls on floating point numbers.
170   virtual
171   MVT::SimpleValueType getCmpLibcallReturnType() const;
172
173   /// getBooleanContents - For targets without i1 registers, this gives the
174   /// nature of the high-bits of boolean values held in types wider than i1.
175   /// "Boolean values" are special true/false values produced by nodes like
176   /// SETCC and consumed (as the condition) by nodes like SELECT and BRCOND.
177   /// Not to be confused with general values promoted from i1.
178   /// Some cpus distinguish between vectors of boolean and scalars; the isVec
179   /// parameter selects between the two kinds.  For example on X86 a scalar
180   /// boolean should be zero extended from i1, while the elements of a vector
181   /// of booleans should be sign extended from i1.
182   BooleanContent getBooleanContents(bool isVec) const {
183     return isVec ? BooleanVectorContents : BooleanContents;
184   }
185
186   /// getSchedulingPreference - Return target scheduling preference.
187   Sched::Preference getSchedulingPreference() const {
188     return SchedPreferenceInfo;
189   }
190
191   /// getSchedulingPreference - Some scheduler, e.g. hybrid, can switch to
192   /// different scheduling heuristics for different nodes. This function returns
193   /// the preference (or none) for the given node.
194   virtual Sched::Preference getSchedulingPreference(SDNode *) const {
195     return Sched::None;
196   }
197
198   /// getRegClassFor - Return the register class that should be used for the
199   /// specified value type.
200   virtual const TargetRegisterClass *getRegClassFor(EVT VT) const {
201     assert(VT.isSimple() && "getRegClassFor called on illegal type!");
202     const TargetRegisterClass *RC = RegClassForVT[VT.getSimpleVT().SimpleTy];
203     assert(RC && "This value type is not natively supported!");
204     return RC;
205   }
206
207   /// getRepRegClassFor - Return the 'representative' register class for the
208   /// specified value type. The 'representative' register class is the largest
209   /// legal super-reg register class for the register class of the value type.
210   /// For example, on i386 the rep register class for i8, i16, and i32 are GR32;
211   /// while the rep register class is GR64 on x86_64.
212   virtual const TargetRegisterClass *getRepRegClassFor(EVT VT) const {
213     assert(VT.isSimple() && "getRepRegClassFor called on illegal type!");
214     const TargetRegisterClass *RC = RepRegClassForVT[VT.getSimpleVT().SimpleTy];
215     return RC;
216   }
217
218   /// getRepRegClassCostFor - Return the cost of the 'representative' register
219   /// class for the specified value type.
220   virtual uint8_t getRepRegClassCostFor(EVT VT) const {
221     assert(VT.isSimple() && "getRepRegClassCostFor called on illegal type!");
222     return RepRegClassCostForVT[VT.getSimpleVT().SimpleTy];
223   }
224
225   /// isTypeLegal - Return true if the target has native support for the
226   /// specified value type.  This means that it has a register that directly
227   /// holds it without promotions or expansions.
228   bool isTypeLegal(EVT VT) const {
229     assert(!VT.isSimple() ||
230            (unsigned)VT.getSimpleVT().SimpleTy < array_lengthof(RegClassForVT));
231     return VT.isSimple() && RegClassForVT[VT.getSimpleVT().SimpleTy] != 0;
232   }
233
234   class ValueTypeActionImpl {
235     /// ValueTypeActions - For each value type, keep a LegalizeTypeAction enum
236     /// that indicates how instruction selection should deal with the type.
237     uint8_t ValueTypeActions[MVT::LAST_VALUETYPE];
238
239   public:
240     ValueTypeActionImpl() {
241       std::fill(ValueTypeActions, array_endof(ValueTypeActions), 0);
242     }
243
244     LegalizeTypeAction getTypeAction(MVT VT) const {
245       return (LegalizeTypeAction)ValueTypeActions[VT.SimpleTy];
246     }
247
248     void setTypeAction(EVT VT, LegalizeTypeAction Action) {
249       unsigned I = VT.getSimpleVT().SimpleTy;
250       ValueTypeActions[I] = Action;
251     }
252   };
253
254   const ValueTypeActionImpl &getValueTypeActions() const {
255     return ValueTypeActions;
256   }
257
258   /// getTypeAction - Return how we should legalize values of this type, either
259   /// it is already legal (return 'Legal') or we need to promote it to a larger
260   /// type (return 'Promote'), or we need to expand it into multiple registers
261   /// of smaller integer type (return 'Expand').  'Custom' is not an option.
262   LegalizeTypeAction getTypeAction(LLVMContext &Context, EVT VT) const {
263     return getTypeConversion(Context, VT).first;
264   }
265   LegalizeTypeAction getTypeAction(MVT VT) const {
266     return ValueTypeActions.getTypeAction(VT);
267   }
268
269   /// getTypeToTransformTo - For types supported by the target, this is an
270   /// identity function.  For types that must be promoted to larger types, this
271   /// returns the larger type to promote to.  For integer types that are larger
272   /// than the largest integer register, this contains one step in the expansion
273   /// to get to the smaller register. For illegal floating point types, this
274   /// returns the integer type to transform to.
275   EVT getTypeToTransformTo(LLVMContext &Context, EVT VT) const {
276     return getTypeConversion(Context, VT).second;
277   }
278
279   /// getTypeToExpandTo - For types supported by the target, this is an
280   /// identity function.  For types that must be expanded (i.e. integer types
281   /// that are larger than the largest integer register or illegal floating
282   /// point types), this returns the largest legal type it will be expanded to.
283   EVT getTypeToExpandTo(LLVMContext &Context, EVT VT) const {
284     assert(!VT.isVector());
285     while (true) {
286       switch (getTypeAction(Context, VT)) {
287       case TypeLegal:
288         return VT;
289       case TypeExpandInteger:
290         VT = getTypeToTransformTo(Context, VT);
291         break;
292       default:
293         llvm_unreachable("Type is not legal nor is it to be expanded!");
294       }
295     }
296   }
297
298   /// getVectorTypeBreakdown - Vector types are broken down into some number of
299   /// legal first class types.  For example, EVT::v8f32 maps to 2 EVT::v4f32
300   /// with Altivec or SSE1, or 8 promoted EVT::f64 values with the X86 FP stack.
301   /// Similarly, EVT::v2i64 turns into 4 EVT::i32 values with both PPC and X86.
302   ///
303   /// This method returns the number of registers needed, and the VT for each
304   /// register.  It also returns the VT and quantity of the intermediate values
305   /// before they are promoted/expanded.
306   ///
307   unsigned getVectorTypeBreakdown(LLVMContext &Context, EVT VT,
308                                   EVT &IntermediateVT,
309                                   unsigned &NumIntermediates,
310                                   EVT &RegisterVT) const;
311
312   /// getTgtMemIntrinsic: Given an intrinsic, checks if on the target the
313   /// intrinsic will need to map to a MemIntrinsicNode (touches memory). If
314   /// this is the case, it returns true and store the intrinsic
315   /// information into the IntrinsicInfo that was passed to the function.
316   struct IntrinsicInfo {
317     unsigned     opc;         // target opcode
318     EVT          memVT;       // memory VT
319     const Value* ptrVal;      // value representing memory location
320     int          offset;      // offset off of ptrVal
321     unsigned     align;       // alignment
322     bool         vol;         // is volatile?
323     bool         readMem;     // reads memory?
324     bool         writeMem;    // writes memory?
325   };
326
327   virtual bool getTgtMemIntrinsic(IntrinsicInfo &, const CallInst &,
328                                   unsigned /*Intrinsic*/) const {
329     return false;
330   }
331
332   /// isFPImmLegal - Returns true if the target can instruction select the
333   /// specified FP immediate natively. If false, the legalizer will materialize
334   /// the FP immediate as a load from a constant pool.
335   virtual bool isFPImmLegal(const APFloat &/*Imm*/, EVT /*VT*/) const {
336     return false;
337   }
338
339   /// isShuffleMaskLegal - Targets can use this to indicate that they only
340   /// support *some* VECTOR_SHUFFLE operations, those with specific masks.
341   /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values
342   /// are assumed to be legal.
343   virtual bool isShuffleMaskLegal(const SmallVectorImpl<int> &/*Mask*/,
344                                   EVT /*VT*/) const {
345     return true;
346   }
347
348   /// canOpTrap - Returns true if the operation can trap for the value type.
349   /// VT must be a legal type. By default, we optimistically assume most
350   /// operations don't trap except for divide and remainder.
351   virtual bool canOpTrap(unsigned Op, EVT VT) const;
352
353   /// isVectorClearMaskLegal - Similar to isShuffleMaskLegal. This is
354   /// used by Targets can use this to indicate if there is a suitable
355   /// VECTOR_SHUFFLE that can be used to replace a VAND with a constant
356   /// pool entry.
357   virtual bool isVectorClearMaskLegal(const SmallVectorImpl<int> &/*Mask*/,
358                                       EVT /*VT*/) const {
359     return false;
360   }
361
362   /// getOperationAction - Return how this operation should be treated: either
363   /// it is legal, needs to be promoted to a larger size, needs to be
364   /// expanded to some other code sequence, or the target has a custom expander
365   /// for it.
366   LegalizeAction getOperationAction(unsigned Op, EVT VT) const {
367     if (VT.isExtended()) return Expand;
368     assert(Op < array_lengthof(OpActions[0]) && "Table isn't big enough!");
369     unsigned I = (unsigned) VT.getSimpleVT().SimpleTy;
370     return (LegalizeAction)OpActions[I][Op];
371   }
372
373   /// isOperationLegalOrCustom - Return true if the specified operation is
374   /// legal on this target or can be made legal with custom lowering. This
375   /// is used to help guide high-level lowering decisions.
376   bool isOperationLegalOrCustom(unsigned Op, EVT VT) const {
377     return (VT == MVT::Other || isTypeLegal(VT)) &&
378       (getOperationAction(Op, VT) == Legal ||
379        getOperationAction(Op, VT) == Custom);
380   }
381
382   /// isOperationLegal - Return true if the specified operation is legal on this
383   /// target.
384   bool isOperationLegal(unsigned Op, EVT VT) const {
385     return (VT == MVT::Other || isTypeLegal(VT)) &&
386            getOperationAction(Op, VT) == Legal;
387   }
388
389   /// getLoadExtAction - Return how this load with extension should be treated:
390   /// either it is legal, needs to be promoted to a larger size, needs to be
391   /// expanded to some other code sequence, or the target has a custom expander
392   /// for it.
393   LegalizeAction getLoadExtAction(unsigned ExtType, EVT VT) const {
394     assert(ExtType < ISD::LAST_LOADEXT_TYPE &&
395            VT.getSimpleVT() < MVT::LAST_VALUETYPE &&
396            "Table isn't big enough!");
397     return (LegalizeAction)LoadExtActions[VT.getSimpleVT().SimpleTy][ExtType];
398   }
399
400   /// isLoadExtLegal - Return true if the specified load with extension is legal
401   /// on this target.
402   bool isLoadExtLegal(unsigned ExtType, EVT VT) const {
403     return VT.isSimple() && getLoadExtAction(ExtType, VT) == Legal;
404   }
405
406   /// getTruncStoreAction - Return how this store with truncation should be
407   /// treated: either it is legal, needs to be promoted to a larger size, needs
408   /// to be expanded to some other code sequence, or the target has a custom
409   /// expander for it.
410   LegalizeAction getTruncStoreAction(EVT ValVT, EVT MemVT) const {
411     assert(ValVT.getSimpleVT() < MVT::LAST_VALUETYPE &&
412            MemVT.getSimpleVT() < MVT::LAST_VALUETYPE &&
413            "Table isn't big enough!");
414     return (LegalizeAction)TruncStoreActions[ValVT.getSimpleVT().SimpleTy]
415                                             [MemVT.getSimpleVT().SimpleTy];
416   }
417
418   /// isTruncStoreLegal - Return true if the specified store with truncation is
419   /// legal on this target.
420   bool isTruncStoreLegal(EVT ValVT, EVT MemVT) const {
421     return isTypeLegal(ValVT) && MemVT.isSimple() &&
422            getTruncStoreAction(ValVT, MemVT) == Legal;
423   }
424
425   /// getIndexedLoadAction - Return how the indexed load should be treated:
426   /// either it is legal, needs to be promoted to a larger size, needs to be
427   /// expanded to some other code sequence, or the target has a custom expander
428   /// for it.
429   LegalizeAction
430   getIndexedLoadAction(unsigned IdxMode, EVT VT) const {
431     assert(IdxMode < ISD::LAST_INDEXED_MODE &&
432            VT.getSimpleVT() < MVT::LAST_VALUETYPE &&
433            "Table isn't big enough!");
434     unsigned Ty = (unsigned)VT.getSimpleVT().SimpleTy;
435     return (LegalizeAction)((IndexedModeActions[Ty][IdxMode] & 0xf0) >> 4);
436   }
437
438   /// isIndexedLoadLegal - Return true if the specified indexed load is legal
439   /// on this target.
440   bool isIndexedLoadLegal(unsigned IdxMode, EVT VT) const {
441     return VT.isSimple() &&
442       (getIndexedLoadAction(IdxMode, VT) == Legal ||
443        getIndexedLoadAction(IdxMode, VT) == Custom);
444   }
445
446   /// getIndexedStoreAction - Return how the indexed store should be treated:
447   /// either it is legal, needs to be promoted to a larger size, needs to be
448   /// expanded to some other code sequence, or the target has a custom expander
449   /// for it.
450   LegalizeAction
451   getIndexedStoreAction(unsigned IdxMode, EVT VT) const {
452     assert(IdxMode < ISD::LAST_INDEXED_MODE &&
453            VT.getSimpleVT() < MVT::LAST_VALUETYPE &&
454            "Table isn't big enough!");
455     unsigned Ty = (unsigned)VT.getSimpleVT().SimpleTy;
456     return (LegalizeAction)(IndexedModeActions[Ty][IdxMode] & 0x0f);
457   }
458
459   /// isIndexedStoreLegal - Return true if the specified indexed load is legal
460   /// on this target.
461   bool isIndexedStoreLegal(unsigned IdxMode, EVT VT) const {
462     return VT.isSimple() &&
463       (getIndexedStoreAction(IdxMode, VT) == Legal ||
464        getIndexedStoreAction(IdxMode, VT) == Custom);
465   }
466
467   /// getCondCodeAction - Return how the condition code should be treated:
468   /// either it is legal, needs to be expanded to some other code sequence,
469   /// or the target has a custom expander for it.
470   LegalizeAction
471   getCondCodeAction(ISD::CondCode CC, EVT VT) const {
472     assert((unsigned)CC < array_lengthof(CondCodeActions) &&
473            (unsigned)VT.getSimpleVT().SimpleTy < sizeof(CondCodeActions[0])*4 &&
474            "Table isn't big enough!");
475     LegalizeAction Action = (LegalizeAction)
476       ((CondCodeActions[CC] >> (2*VT.getSimpleVT().SimpleTy)) & 3);
477     assert(Action != Promote && "Can't promote condition code!");
478     return Action;
479   }
480
481   /// isCondCodeLegal - Return true if the specified condition code is legal
482   /// on this target.
483   bool isCondCodeLegal(ISD::CondCode CC, EVT VT) const {
484     return getCondCodeAction(CC, VT) == Legal ||
485            getCondCodeAction(CC, VT) == Custom;
486   }
487
488
489   /// getTypeToPromoteTo - If the action for this operation is to promote, this
490   /// method returns the ValueType to promote to.
491   EVT getTypeToPromoteTo(unsigned Op, EVT VT) const {
492     assert(getOperationAction(Op, VT) == Promote &&
493            "This operation isn't promoted!");
494
495     // See if this has an explicit type specified.
496     std::map<std::pair<unsigned, MVT::SimpleValueType>,
497              MVT::SimpleValueType>::const_iterator PTTI =
498       PromoteToType.find(std::make_pair(Op, VT.getSimpleVT().SimpleTy));
499     if (PTTI != PromoteToType.end()) return PTTI->second;
500
501     assert((VT.isInteger() || VT.isFloatingPoint()) &&
502            "Cannot autopromote this type, add it with AddPromotedToType.");
503
504     EVT NVT = VT;
505     do {
506       NVT = (MVT::SimpleValueType)(NVT.getSimpleVT().SimpleTy+1);
507       assert(NVT.isInteger() == VT.isInteger() && NVT != MVT::isVoid &&
508              "Didn't find type to promote to!");
509     } while (!isTypeLegal(NVT) ||
510               getOperationAction(Op, NVT) == Promote);
511     return NVT;
512   }
513
514   /// getValueType - Return the EVT corresponding to this LLVM type.
515   /// This is fixed by the LLVM operations except for the pointer size.  If
516   /// AllowUnknown is true, this will return MVT::Other for types with no EVT
517   /// counterpart (e.g. structs), otherwise it will assert.
518   EVT getValueType(Type *Ty, bool AllowUnknown = false) const {
519     // Lower scalar pointers to native pointer types.
520     if (Ty->isPointerTy()) return PointerTy;
521
522     if (Ty->isVectorTy()) {
523       VectorType *VTy = cast<VectorType>(Ty);
524       Type *Elm = VTy->getElementType();
525       // Lower vectors of pointers to native pointer types.
526       if (Elm->isPointerTy()) 
527         Elm = EVT(PointerTy).getTypeForEVT(Ty->getContext());
528       return EVT::getVectorVT(Ty->getContext(), EVT::getEVT(Elm, false),
529                        VTy->getNumElements());
530     }
531     return EVT::getEVT(Ty, AllowUnknown);
532   }
533
534   /// getByValTypeAlignment - Return the desired alignment for ByVal aggregate
535   /// function arguments in the caller parameter area.  This is the actual
536   /// alignment, not its logarithm.
537   virtual unsigned getByValTypeAlignment(Type *Ty) const;
538
539   /// getRegisterType - Return the type of registers that this ValueType will
540   /// eventually require.
541   EVT getRegisterType(MVT VT) const {
542     assert((unsigned)VT.SimpleTy < array_lengthof(RegisterTypeForVT));
543     return RegisterTypeForVT[VT.SimpleTy];
544   }
545
546   /// getRegisterType - Return the type of registers that this ValueType will
547   /// eventually require.
548   EVT getRegisterType(LLVMContext &Context, EVT VT) const {
549     if (VT.isSimple()) {
550       assert((unsigned)VT.getSimpleVT().SimpleTy <
551                 array_lengthof(RegisterTypeForVT));
552       return RegisterTypeForVT[VT.getSimpleVT().SimpleTy];
553     }
554     if (VT.isVector()) {
555       EVT VT1, RegisterVT;
556       unsigned NumIntermediates;
557       (void)getVectorTypeBreakdown(Context, VT, VT1,
558                                    NumIntermediates, RegisterVT);
559       return RegisterVT;
560     }
561     if (VT.isInteger()) {
562       return getRegisterType(Context, getTypeToTransformTo(Context, VT));
563     }
564     llvm_unreachable("Unsupported extended type!");
565   }
566
567   /// getNumRegisters - Return the number of registers that this ValueType will
568   /// eventually require.  This is one for any types promoted to live in larger
569   /// registers, but may be more than one for types (like i64) that are split
570   /// into pieces.  For types like i140, which are first promoted then expanded,
571   /// it is the number of registers needed to hold all the bits of the original
572   /// type.  For an i140 on a 32 bit machine this means 5 registers.
573   unsigned getNumRegisters(LLVMContext &Context, EVT VT) const {
574     if (VT.isSimple()) {
575       assert((unsigned)VT.getSimpleVT().SimpleTy <
576                 array_lengthof(NumRegistersForVT));
577       return NumRegistersForVT[VT.getSimpleVT().SimpleTy];
578     }
579     if (VT.isVector()) {
580       EVT VT1, VT2;
581       unsigned NumIntermediates;
582       return getVectorTypeBreakdown(Context, VT, VT1, NumIntermediates, VT2);
583     }
584     if (VT.isInteger()) {
585       unsigned BitWidth = VT.getSizeInBits();
586       unsigned RegWidth = getRegisterType(Context, VT).getSizeInBits();
587       return (BitWidth + RegWidth - 1) / RegWidth;
588     }
589     llvm_unreachable("Unsupported extended type!");
590   }
591
592   /// ShouldShrinkFPConstant - If true, then instruction selection should
593   /// seek to shrink the FP constant of the specified type to a smaller type
594   /// in order to save space and / or reduce runtime.
595   virtual bool ShouldShrinkFPConstant(EVT) const { return true; }
596
597   /// hasTargetDAGCombine - If true, the target has custom DAG combine
598   /// transformations that it can perform for the specified node.
599   bool hasTargetDAGCombine(ISD::NodeType NT) const {
600     assert(unsigned(NT >> 3) < array_lengthof(TargetDAGCombineArray));
601     return TargetDAGCombineArray[NT >> 3] & (1 << (NT&7));
602   }
603
604   /// This function returns the maximum number of store operations permitted
605   /// to replace a call to llvm.memset. The value is set by the target at the
606   /// performance threshold for such a replacement. If OptSize is true,
607   /// return the limit for functions that have OptSize attribute.
608   /// @brief Get maximum # of store operations permitted for llvm.memset
609   unsigned getMaxStoresPerMemset(bool OptSize) const {
610     return OptSize ? maxStoresPerMemsetOptSize : maxStoresPerMemset;
611   }
612
613   /// This function returns the maximum number of store operations permitted
614   /// to replace a call to llvm.memcpy. The value is set by the target at the
615   /// performance threshold for such a replacement. If OptSize is true,
616   /// return the limit for functions that have OptSize attribute.
617   /// @brief Get maximum # of store operations permitted for llvm.memcpy
618   unsigned getMaxStoresPerMemcpy(bool OptSize) const {
619     return OptSize ? maxStoresPerMemcpyOptSize : maxStoresPerMemcpy;
620   }
621
622   /// This function returns the maximum number of store operations permitted
623   /// to replace a call to llvm.memmove. The value is set by the target at the
624   /// performance threshold for such a replacement. If OptSize is true,
625   /// return the limit for functions that have OptSize attribute.
626   /// @brief Get maximum # of store operations permitted for llvm.memmove
627   unsigned getMaxStoresPerMemmove(bool OptSize) const {
628     return OptSize ? maxStoresPerMemmoveOptSize : maxStoresPerMemmove;
629   }
630
631   /// This function returns true if the target allows unaligned memory accesses.
632   /// of the specified type. This is used, for example, in situations where an
633   /// array copy/move/set is  converted to a sequence of store operations. It's
634   /// use helps to ensure that such replacements don't generate code that causes
635   /// an alignment error  (trap) on the target machine.
636   /// @brief Determine if the target supports unaligned memory accesses.
637   virtual bool allowsUnalignedMemoryAccesses(EVT) const {
638     return false;
639   }
640
641   /// This function returns true if the target would benefit from code placement
642   /// optimization.
643   /// @brief Determine if the target should perform code placement optimization.
644   bool shouldOptimizeCodePlacement() const {
645     return benefitFromCodePlacementOpt;
646   }
647
648   /// getOptimalMemOpType - Returns the target specific optimal type for load
649   /// and store operations as a result of memset, memcpy, and memmove
650   /// lowering. If DstAlign is zero that means it's safe to destination
651   /// alignment can satisfy any constraint. Similarly if SrcAlign is zero it
652   /// means there isn't a need to check it against alignment requirement,
653   /// probably because the source does not need to be loaded. If
654   /// 'IsZeroVal' is true, that means it's safe to return a
655   /// non-scalar-integer type, e.g. empty string source, constant, or loaded
656   /// from memory. 'MemcpyStrSrc' indicates whether the memcpy source is
657   /// constant so it does not need to be loaded.
658   /// It returns EVT::Other if the type should be determined using generic
659   /// target-independent logic.
660   virtual EVT getOptimalMemOpType(uint64_t /*Size*/,
661                                   unsigned /*DstAlign*/, unsigned /*SrcAlign*/,
662                                   bool /*IsZeroVal*/,
663                                   bool /*MemcpyStrSrc*/,
664                                   MachineFunction &/*MF*/) const {
665     return MVT::Other;
666   }
667
668   /// usesUnderscoreSetJmp - Determine if we should use _setjmp or setjmp
669   /// to implement llvm.setjmp.
670   bool usesUnderscoreSetJmp() const {
671     return UseUnderscoreSetJmp;
672   }
673
674   /// usesUnderscoreLongJmp - Determine if we should use _longjmp or longjmp
675   /// to implement llvm.longjmp.
676   bool usesUnderscoreLongJmp() const {
677     return UseUnderscoreLongJmp;
678   }
679
680   /// supportJumpTables - return whether the target can generate code for
681   /// jump tables.
682   bool supportJumpTables() const {
683     return SupportJumpTables;
684   }
685
686   /// getStackPointerRegisterToSaveRestore - If a physical register, this
687   /// specifies the register that llvm.savestack/llvm.restorestack should save
688   /// and restore.
689   unsigned getStackPointerRegisterToSaveRestore() const {
690     return StackPointerRegisterToSaveRestore;
691   }
692
693   /// getExceptionPointerRegister - If a physical register, this returns
694   /// the register that receives the exception address on entry to a landing
695   /// pad.
696   unsigned getExceptionPointerRegister() const {
697     return ExceptionPointerRegister;
698   }
699
700   /// getExceptionSelectorRegister - If a physical register, this returns
701   /// the register that receives the exception typeid on entry to a landing
702   /// pad.
703   unsigned getExceptionSelectorRegister() const {
704     return ExceptionSelectorRegister;
705   }
706
707   /// getJumpBufSize - returns the target's jmp_buf size in bytes (if never
708   /// set, the default is 200)
709   unsigned getJumpBufSize() const {
710     return JumpBufSize;
711   }
712
713   /// getJumpBufAlignment - returns the target's jmp_buf alignment in bytes
714   /// (if never set, the default is 0)
715   unsigned getJumpBufAlignment() const {
716     return JumpBufAlignment;
717   }
718
719   /// getMinStackArgumentAlignment - return the minimum stack alignment of an
720   /// argument.
721   unsigned getMinStackArgumentAlignment() const {
722     return MinStackArgumentAlignment;
723   }
724
725   /// getMinFunctionAlignment - return the minimum function alignment.
726   ///
727   unsigned getMinFunctionAlignment() const {
728     return MinFunctionAlignment;
729   }
730
731   /// getPrefFunctionAlignment - return the preferred function alignment.
732   ///
733   unsigned getPrefFunctionAlignment() const {
734     return PrefFunctionAlignment;
735   }
736
737   /// getPrefLoopAlignment - return the preferred loop alignment.
738   ///
739   unsigned getPrefLoopAlignment() const {
740     return PrefLoopAlignment;
741   }
742
743   /// getShouldFoldAtomicFences - return whether the combiner should fold
744   /// fence MEMBARRIER instructions into the atomic intrinsic instructions.
745   ///
746   bool getShouldFoldAtomicFences() const {
747     return ShouldFoldAtomicFences;
748   }
749
750   /// getInsertFencesFor - return whether the DAG builder should automatically
751   /// insert fences and reduce ordering for atomics.
752   ///
753   bool getInsertFencesForAtomic() const {
754     return InsertFencesForAtomic;
755   }
756
757   /// getPreIndexedAddressParts - returns true by value, base pointer and
758   /// offset pointer and addressing mode by reference if the node's address
759   /// can be legally represented as pre-indexed load / store address.
760   virtual bool getPreIndexedAddressParts(SDNode * /*N*/, SDValue &/*Base*/,
761                                          SDValue &/*Offset*/,
762                                          ISD::MemIndexedMode &/*AM*/,
763                                          SelectionDAG &/*DAG*/) const {
764     return false;
765   }
766
767   /// getPostIndexedAddressParts - returns true by value, base pointer and
768   /// offset pointer and addressing mode by reference if this node can be
769   /// combined with a load / store to form a post-indexed load / store.
770   virtual bool getPostIndexedAddressParts(SDNode * /*N*/, SDNode * /*Op*/,
771                                           SDValue &/*Base*/, SDValue &/*Offset*/,
772                                           ISD::MemIndexedMode &/*AM*/,
773                                           SelectionDAG &/*DAG*/) const {
774     return false;
775   }
776
777   /// getJumpTableEncoding - Return the entry encoding for a jump table in the
778   /// current function.  The returned value is a member of the
779   /// MachineJumpTableInfo::JTEntryKind enum.
780   virtual unsigned getJumpTableEncoding() const;
781
782   virtual const MCExpr *
783   LowerCustomJumpTableEntry(const MachineJumpTableInfo * /*MJTI*/,
784                             const MachineBasicBlock * /*MBB*/, unsigned /*uid*/,
785                             MCContext &/*Ctx*/) const {
786     llvm_unreachable("Need to implement this hook if target has custom JTIs");
787   }
788
789   /// getPICJumpTableRelocaBase - Returns relocation base for the given PIC
790   /// jumptable.
791   virtual SDValue getPICJumpTableRelocBase(SDValue Table,
792                                            SelectionDAG &DAG) const;
793
794   /// getPICJumpTableRelocBaseExpr - This returns the relocation base for the
795   /// given PIC jumptable, the same as getPICJumpTableRelocBase, but as an
796   /// MCExpr.
797   virtual const MCExpr *
798   getPICJumpTableRelocBaseExpr(const MachineFunction *MF,
799                                unsigned JTI, MCContext &Ctx) const;
800
801   /// isOffsetFoldingLegal - Return true if folding a constant offset
802   /// with the given GlobalAddress is legal.  It is frequently not legal in
803   /// PIC relocation models.
804   virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const;
805
806   /// getStackCookieLocation - Return true if the target stores stack
807   /// protector cookies at a fixed offset in some non-standard address
808   /// space, and populates the address space and offset as
809   /// appropriate.
810   virtual bool getStackCookieLocation(unsigned &/*AddressSpace*/,
811                                       unsigned &/*Offset*/) const {
812     return false;
813   }
814
815   /// getMaximalGlobalOffset - Returns the maximal possible offset which can be
816   /// used for loads / stores from the global.
817   virtual unsigned getMaximalGlobalOffset() const {
818     return 0;
819   }
820
821   //===--------------------------------------------------------------------===//
822   // TargetLowering Optimization Methods
823   //
824
825   /// TargetLoweringOpt - A convenience struct that encapsulates a DAG, and two
826   /// SDValues for returning information from TargetLowering to its clients
827   /// that want to combine
828   struct TargetLoweringOpt {
829     SelectionDAG &DAG;
830     bool LegalTys;
831     bool LegalOps;
832     SDValue Old;
833     SDValue New;
834
835     explicit TargetLoweringOpt(SelectionDAG &InDAG,
836                                bool LT, bool LO) :
837       DAG(InDAG), LegalTys(LT), LegalOps(LO) {}
838
839     bool LegalTypes() const { return LegalTys; }
840     bool LegalOperations() const { return LegalOps; }
841
842     bool CombineTo(SDValue O, SDValue N) {
843       Old = O;
844       New = N;
845       return true;
846     }
847
848     /// ShrinkDemandedConstant - Check to see if the specified operand of the
849     /// specified instruction is a constant integer.  If so, check to see if
850     /// there are any bits set in the constant that are not demanded.  If so,
851     /// shrink the constant and return true.
852     bool ShrinkDemandedConstant(SDValue Op, const APInt &Demanded);
853
854     /// ShrinkDemandedOp - Convert x+y to (VT)((SmallVT)x+(SmallVT)y) if the
855     /// casts are free.  This uses isZExtFree and ZERO_EXTEND for the widening
856     /// cast, but it could be generalized for targets with other types of
857     /// implicit widening casts.
858     bool ShrinkDemandedOp(SDValue Op, unsigned BitWidth, const APInt &Demanded,
859                           DebugLoc dl);
860   };
861
862   /// SimplifyDemandedBits - Look at Op.  At this point, we know that only the
863   /// DemandedMask bits of the result of Op are ever used downstream.  If we can
864   /// use this information to simplify Op, create a new simplified DAG node and
865   /// return true, returning the original and new nodes in Old and New.
866   /// Otherwise, analyze the expression and return a mask of KnownOne and
867   /// KnownZero bits for the expression (used to simplify the caller).
868   /// The KnownZero/One bits may only be accurate for those bits in the
869   /// DemandedMask.
870   bool SimplifyDemandedBits(SDValue Op, const APInt &DemandedMask,
871                             APInt &KnownZero, APInt &KnownOne,
872                             TargetLoweringOpt &TLO, unsigned Depth = 0) const;
873
874   /// computeMaskedBitsForTargetNode - Determine which of the bits specified in
875   /// Mask are known to be either zero or one and return them in the
876   /// KnownZero/KnownOne bitsets.
877   virtual void computeMaskedBitsForTargetNode(const SDValue Op,
878                                               APInt &KnownZero,
879                                               APInt &KnownOne,
880                                               const SelectionDAG &DAG,
881                                               unsigned Depth = 0) const;
882
883   /// ComputeNumSignBitsForTargetNode - This method can be implemented by
884   /// targets that want to expose additional information about sign bits to the
885   /// DAG Combiner.
886   virtual unsigned ComputeNumSignBitsForTargetNode(SDValue Op,
887                                                    unsigned Depth = 0) const;
888
889   struct DAGCombinerInfo {
890     void *DC;  // The DAG Combiner object.
891     bool BeforeLegalize;
892     bool BeforeLegalizeOps;
893     bool CalledByLegalizer;
894   public:
895     SelectionDAG &DAG;
896
897     DAGCombinerInfo(SelectionDAG &dag, bool bl, bool blo, bool cl, void *dc)
898       : DC(dc), BeforeLegalize(bl), BeforeLegalizeOps(blo),
899         CalledByLegalizer(cl), DAG(dag) {}
900
901     bool isBeforeLegalize() const { return BeforeLegalize; }
902     bool isBeforeLegalizeOps() const { return BeforeLegalizeOps; }
903     bool isCalledByLegalizer() const { return CalledByLegalizer; }
904
905     void AddToWorklist(SDNode *N);
906     void RemoveFromWorklist(SDNode *N);
907     SDValue CombineTo(SDNode *N, const std::vector<SDValue> &To,
908                       bool AddTo = true);
909     SDValue CombineTo(SDNode *N, SDValue Res, bool AddTo = true);
910     SDValue CombineTo(SDNode *N, SDValue Res0, SDValue Res1, bool AddTo = true);
911
912     void CommitTargetLoweringOpt(const TargetLoweringOpt &TLO);
913   };
914
915   /// SimplifySetCC - Try to simplify a setcc built with the specified operands
916   /// and cc. If it is unable to simplify it, return a null SDValue.
917   SDValue SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
918                           ISD::CondCode Cond, bool foldBooleans,
919                           DAGCombinerInfo &DCI, DebugLoc dl) const;
920
921   /// isGAPlusOffset - Returns true (and the GlobalValue and the offset) if the
922   /// node is a GlobalAddress + offset.
923   virtual bool
924   isGAPlusOffset(SDNode *N, const GlobalValue* &GA, int64_t &Offset) const;
925
926   /// PerformDAGCombine - This method will be invoked for all target nodes and
927   /// for any target-independent nodes that the target has registered with
928   /// invoke it for.
929   ///
930   /// The semantics are as follows:
931   /// Return Value:
932   ///   SDValue.Val == 0   - No change was made
933   ///   SDValue.Val == N   - N was replaced, is dead, and is already handled.
934   ///   otherwise          - N should be replaced by the returned Operand.
935   ///
936   /// In addition, methods provided by DAGCombinerInfo may be used to perform
937   /// more complex transformations.
938   ///
939   virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
940
941   /// isTypeDesirableForOp - Return true if the target has native support for
942   /// the specified value type and it is 'desirable' to use the type for the
943   /// given node type. e.g. On x86 i16 is legal, but undesirable since i16
944   /// instruction encodings are longer and some i16 instructions are slow.
945   virtual bool isTypeDesirableForOp(unsigned /*Opc*/, EVT VT) const {
946     // By default, assume all legal types are desirable.
947     return isTypeLegal(VT);
948   }
949
950   /// isDesirableToPromoteOp - Return true if it is profitable for dag combiner
951   /// to transform a floating point op of specified opcode to a equivalent op of
952   /// an integer type. e.g. f32 load -> i32 load can be profitable on ARM.
953   virtual bool isDesirableToTransformToIntegerOp(unsigned /*Opc*/,
954                                                  EVT /*VT*/) const {
955     return false;
956   }
957
958   /// IsDesirableToPromoteOp - This method query the target whether it is
959   /// beneficial for dag combiner to promote the specified node. If true, it
960   /// should return the desired promotion type by reference.
961   virtual bool IsDesirableToPromoteOp(SDValue /*Op*/, EVT &/*PVT*/) const {
962     return false;
963   }
964
965   //===--------------------------------------------------------------------===//
966   // TargetLowering Configuration Methods - These methods should be invoked by
967   // the derived class constructor to configure this object for the target.
968   //
969
970 protected:
971   /// setBooleanContents - Specify how the target extends the result of a
972   /// boolean value from i1 to a wider type.  See getBooleanContents.
973   void setBooleanContents(BooleanContent Ty) { BooleanContents = Ty; }
974   /// setBooleanVectorContents - Specify how the target extends the result
975   /// of a vector boolean value from a vector of i1 to a wider type.  See
976   /// getBooleanContents.
977   void setBooleanVectorContents(BooleanContent Ty) {
978     BooleanVectorContents = Ty;
979   }
980
981   /// setSchedulingPreference - Specify the target scheduling preference.
982   void setSchedulingPreference(Sched::Preference Pref) {
983     SchedPreferenceInfo = Pref;
984   }
985
986   /// setUseUnderscoreSetJmp - Indicate whether this target prefers to
987   /// use _setjmp to implement llvm.setjmp or the non _ version.
988   /// Defaults to false.
989   void setUseUnderscoreSetJmp(bool Val) {
990     UseUnderscoreSetJmp = Val;
991   }
992
993   /// setUseUnderscoreLongJmp - Indicate whether this target prefers to
994   /// use _longjmp to implement llvm.longjmp or the non _ version.
995   /// Defaults to false.
996   void setUseUnderscoreLongJmp(bool Val) {
997     UseUnderscoreLongJmp = Val;
998   }
999
1000   /// setSupportJumpTables - Indicate whether the target can generate code for
1001   /// jump tables.
1002   void setSupportJumpTables(bool Val) {
1003     SupportJumpTables = Val;
1004   }
1005
1006   /// setStackPointerRegisterToSaveRestore - If set to a physical register, this
1007   /// specifies the register that llvm.savestack/llvm.restorestack should save
1008   /// and restore.
1009   void setStackPointerRegisterToSaveRestore(unsigned R) {
1010     StackPointerRegisterToSaveRestore = R;
1011   }
1012
1013   /// setExceptionPointerRegister - If set to a physical register, this sets
1014   /// the register that receives the exception address on entry to a landing
1015   /// pad.
1016   void setExceptionPointerRegister(unsigned R) {
1017     ExceptionPointerRegister = R;
1018   }
1019
1020   /// setExceptionSelectorRegister - If set to a physical register, this sets
1021   /// the register that receives the exception typeid on entry to a landing
1022   /// pad.
1023   void setExceptionSelectorRegister(unsigned R) {
1024     ExceptionSelectorRegister = R;
1025   }
1026
1027   /// SelectIsExpensive - Tells the code generator not to expand operations
1028   /// into sequences that use the select operations if possible.
1029   void setSelectIsExpensive(bool isExpensive = true) {
1030     SelectIsExpensive = isExpensive;
1031   }
1032
1033   /// JumpIsExpensive - Tells the code generator not to expand sequence of
1034   /// operations into a separate sequences that increases the amount of
1035   /// flow control.
1036   void setJumpIsExpensive(bool isExpensive = true) {
1037     JumpIsExpensive = isExpensive;
1038   }
1039
1040   /// setIntDivIsCheap - Tells the code generator that integer divide is
1041   /// expensive, and if possible, should be replaced by an alternate sequence
1042   /// of instructions not containing an integer divide.
1043   void setIntDivIsCheap(bool isCheap = true) { IntDivIsCheap = isCheap; }
1044
1045   /// setPow2DivIsCheap - Tells the code generator that it shouldn't generate
1046   /// srl/add/sra for a signed divide by power of two, and let the target handle
1047   /// it.
1048   void setPow2DivIsCheap(bool isCheap = true) { Pow2DivIsCheap = isCheap; }
1049
1050   /// addRegisterClass - Add the specified register class as an available
1051   /// regclass for the specified value type.  This indicates the selector can
1052   /// handle values of that class natively.
1053   void addRegisterClass(EVT VT, const TargetRegisterClass *RC) {
1054     assert((unsigned)VT.getSimpleVT().SimpleTy < array_lengthof(RegClassForVT));
1055     AvailableRegClasses.push_back(std::make_pair(VT, RC));
1056     RegClassForVT[VT.getSimpleVT().SimpleTy] = RC;
1057   }
1058
1059   /// findRepresentativeClass - Return the largest legal super-reg register class
1060   /// of the register class for the specified type and its associated "cost".
1061   virtual std::pair<const TargetRegisterClass*, uint8_t>
1062   findRepresentativeClass(EVT VT) const;
1063
1064   /// computeRegisterProperties - Once all of the register classes are added,
1065   /// this allows us to compute derived properties we expose.
1066   void computeRegisterProperties();
1067
1068   /// setOperationAction - Indicate that the specified operation does not work
1069   /// with the specified type and indicate what to do about it.
1070   void setOperationAction(unsigned Op, MVT VT,
1071                           LegalizeAction Action) {
1072     assert(Op < array_lengthof(OpActions[0]) && "Table isn't big enough!");
1073     OpActions[(unsigned)VT.SimpleTy][Op] = (uint8_t)Action;
1074   }
1075
1076   /// setLoadExtAction - Indicate that the specified load with extension does
1077   /// not work with the specified type and indicate what to do about it.
1078   void setLoadExtAction(unsigned ExtType, MVT VT,
1079                         LegalizeAction Action) {
1080     assert(ExtType < ISD::LAST_LOADEXT_TYPE && VT < MVT::LAST_VALUETYPE &&
1081            "Table isn't big enough!");
1082     LoadExtActions[VT.SimpleTy][ExtType] = (uint8_t)Action;
1083   }
1084
1085   /// setTruncStoreAction - Indicate that the specified truncating store does
1086   /// not work with the specified type and indicate what to do about it.
1087   void setTruncStoreAction(MVT ValVT, MVT MemVT,
1088                            LegalizeAction Action) {
1089     assert(ValVT < MVT::LAST_VALUETYPE && MemVT < MVT::LAST_VALUETYPE &&
1090            "Table isn't big enough!");
1091     TruncStoreActions[ValVT.SimpleTy][MemVT.SimpleTy] = (uint8_t)Action;
1092   }
1093
1094   /// setIndexedLoadAction - Indicate that the specified indexed load does or
1095   /// does not work with the specified type and indicate what to do abort
1096   /// it. NOTE: All indexed mode loads are initialized to Expand in
1097   /// TargetLowering.cpp
1098   void setIndexedLoadAction(unsigned IdxMode, MVT VT,
1099                             LegalizeAction Action) {
1100     assert(VT < MVT::LAST_VALUETYPE && IdxMode < ISD::LAST_INDEXED_MODE &&
1101            (unsigned)Action < 0xf && "Table isn't big enough!");
1102     // Load action are kept in the upper half.
1103     IndexedModeActions[(unsigned)VT.SimpleTy][IdxMode] &= ~0xf0;
1104     IndexedModeActions[(unsigned)VT.SimpleTy][IdxMode] |= ((uint8_t)Action) <<4;
1105   }
1106
1107   /// setIndexedStoreAction - Indicate that the specified indexed store does or
1108   /// does not work with the specified type and indicate what to do about
1109   /// it. NOTE: All indexed mode stores are initialized to Expand in
1110   /// TargetLowering.cpp
1111   void setIndexedStoreAction(unsigned IdxMode, MVT VT,
1112                              LegalizeAction Action) {
1113     assert(VT < MVT::LAST_VALUETYPE && IdxMode < ISD::LAST_INDEXED_MODE &&
1114            (unsigned)Action < 0xf && "Table isn't big enough!");
1115     // Store action are kept in the lower half.
1116     IndexedModeActions[(unsigned)VT.SimpleTy][IdxMode] &= ~0x0f;
1117     IndexedModeActions[(unsigned)VT.SimpleTy][IdxMode] |= ((uint8_t)Action);
1118   }
1119
1120   /// setCondCodeAction - Indicate that the specified condition code is or isn't
1121   /// supported on the target and indicate what to do about it.
1122   void setCondCodeAction(ISD::CondCode CC, MVT VT,
1123                          LegalizeAction Action) {
1124     assert(VT < MVT::LAST_VALUETYPE &&
1125            (unsigned)CC < array_lengthof(CondCodeActions) &&
1126            "Table isn't big enough!");
1127     CondCodeActions[(unsigned)CC] &= ~(uint64_t(3UL)  << VT.SimpleTy*2);
1128     CondCodeActions[(unsigned)CC] |= (uint64_t)Action << VT.SimpleTy*2;
1129   }
1130
1131   /// AddPromotedToType - If Opc/OrigVT is specified as being promoted, the
1132   /// promotion code defaults to trying a larger integer/fp until it can find
1133   /// one that works.  If that default is insufficient, this method can be used
1134   /// by the target to override the default.
1135   void AddPromotedToType(unsigned Opc, MVT OrigVT, MVT DestVT) {
1136     PromoteToType[std::make_pair(Opc, OrigVT.SimpleTy)] = DestVT.SimpleTy;
1137   }
1138
1139   /// setTargetDAGCombine - Targets should invoke this method for each target
1140   /// independent node that they want to provide a custom DAG combiner for by
1141   /// implementing the PerformDAGCombine virtual method.
1142   void setTargetDAGCombine(ISD::NodeType NT) {
1143     assert(unsigned(NT >> 3) < array_lengthof(TargetDAGCombineArray));
1144     TargetDAGCombineArray[NT >> 3] |= 1 << (NT&7);
1145   }
1146
1147   /// setJumpBufSize - Set the target's required jmp_buf buffer size (in
1148   /// bytes); default is 200
1149   void setJumpBufSize(unsigned Size) {
1150     JumpBufSize = Size;
1151   }
1152
1153   /// setJumpBufAlignment - Set the target's required jmp_buf buffer
1154   /// alignment (in bytes); default is 0
1155   void setJumpBufAlignment(unsigned Align) {
1156     JumpBufAlignment = Align;
1157   }
1158
1159   /// setMinFunctionAlignment - Set the target's minimum function alignment (in
1160   /// log2(bytes))
1161   void setMinFunctionAlignment(unsigned Align) {
1162     MinFunctionAlignment = Align;
1163   }
1164
1165   /// setPrefFunctionAlignment - Set the target's preferred function alignment.
1166   /// This should be set if there is a performance benefit to
1167   /// higher-than-minimum alignment (in log2(bytes))
1168   void setPrefFunctionAlignment(unsigned Align) {
1169     PrefFunctionAlignment = Align;
1170   }
1171
1172   /// setPrefLoopAlignment - Set the target's preferred loop alignment. Default
1173   /// alignment is zero, it means the target does not care about loop alignment.
1174   /// The alignment is specified in log2(bytes).
1175   void setPrefLoopAlignment(unsigned Align) {
1176     PrefLoopAlignment = Align;
1177   }
1178
1179   /// setMinStackArgumentAlignment - Set the minimum stack alignment of an
1180   /// argument (in log2(bytes)).
1181   void setMinStackArgumentAlignment(unsigned Align) {
1182     MinStackArgumentAlignment = Align;
1183   }
1184
1185   /// setShouldFoldAtomicFences - Set if the target's implementation of the
1186   /// atomic operation intrinsics includes locking. Default is false.
1187   void setShouldFoldAtomicFences(bool fold) {
1188     ShouldFoldAtomicFences = fold;
1189   }
1190
1191   /// setInsertFencesForAtomic - Set if the the DAG builder should
1192   /// automatically insert fences and reduce the order of atomic memory
1193   /// operations to Monotonic.
1194   void setInsertFencesForAtomic(bool fence) {
1195     InsertFencesForAtomic = fence;
1196   }
1197
1198 public:
1199   //===--------------------------------------------------------------------===//
1200   // Lowering methods - These methods must be implemented by targets so that
1201   // the SelectionDAGLowering code knows how to lower these.
1202   //
1203
1204   /// LowerFormalArguments - This hook must be implemented to lower the
1205   /// incoming (formal) arguments, described by the Ins array, into the
1206   /// specified DAG. The implementation should fill in the InVals array
1207   /// with legal-type argument values, and return the resulting token
1208   /// chain value.
1209   ///
1210   virtual SDValue
1211     LowerFormalArguments(SDValue /*Chain*/, CallingConv::ID /*CallConv*/,
1212                          bool /*isVarArg*/,
1213                          const SmallVectorImpl<ISD::InputArg> &/*Ins*/,
1214                          DebugLoc /*dl*/, SelectionDAG &/*DAG*/,
1215                          SmallVectorImpl<SDValue> &/*InVals*/) const {
1216     llvm_unreachable("Not Implemented");
1217   }
1218
1219   struct ArgListEntry {
1220     SDValue Node;
1221     Type* Ty;
1222     bool isSExt  : 1;
1223     bool isZExt  : 1;
1224     bool isInReg : 1;
1225     bool isSRet  : 1;
1226     bool isNest  : 1;
1227     bool isByVal : 1;
1228     uint16_t Alignment;
1229
1230     ArgListEntry() : isSExt(false), isZExt(false), isInReg(false),
1231       isSRet(false), isNest(false), isByVal(false), Alignment(0) { }
1232   };
1233   typedef std::vector<ArgListEntry> ArgListTy;
1234
1235   /// CallLoweringInfo - This structure contains all information that is
1236   /// necessary for lowering calls. It is passed to TLI::LowerCallTo when the
1237   /// SelectionDAG builder needs to lower a call, and targets will see this
1238   /// struct in their LowerCall implementation.
1239   struct CallLoweringInfo {
1240     SDValue Chain;
1241     Type *RetTy;
1242     bool RetSExt           : 1;
1243     bool RetZExt           : 1;
1244     bool IsVarArg          : 1;
1245     bool IsInReg           : 1;
1246     bool DoesNotReturn     : 1;
1247     bool IsReturnValueUsed : 1;
1248
1249     // IsTailCall should be modified by implementations of
1250     // TargetLowering::LowerCall that perform tail call conversions.
1251     bool IsTailCall;
1252
1253     unsigned NumFixedArgs;
1254     CallingConv::ID CallConv;
1255     SDValue Callee;
1256     ArgListTy &Args;
1257     SelectionDAG &DAG;
1258     DebugLoc DL;
1259     ImmutableCallSite *CS;
1260     SmallVector<ISD::OutputArg, 32> Outs;
1261     SmallVector<SDValue, 32> OutVals;
1262     SmallVector<ISD::InputArg, 32> Ins;
1263
1264
1265     /// CallLoweringInfo - Constructs a call lowering context based on the
1266     /// ImmutableCallSite \p cs.
1267     CallLoweringInfo(SDValue chain, Type *retTy,
1268                      FunctionType *FTy, bool isTailCall, SDValue callee,
1269                      ArgListTy &args, SelectionDAG &dag, DebugLoc dl,
1270                      ImmutableCallSite &cs)
1271     : Chain(chain), RetTy(retTy), RetSExt(cs.paramHasAttr(0, Attribute::SExt)),
1272       RetZExt(cs.paramHasAttr(0, Attribute::ZExt)), IsVarArg(FTy->isVarArg()),
1273       IsInReg(cs.paramHasAttr(0, Attribute::InReg)),
1274       DoesNotReturn(cs.doesNotReturn()),
1275       IsReturnValueUsed(!cs.getInstruction()->use_empty()),
1276       IsTailCall(isTailCall), NumFixedArgs(FTy->getNumParams()),
1277       CallConv(cs.getCallingConv()), Callee(callee), Args(args), DAG(dag),
1278       DL(dl), CS(&cs) {}
1279
1280     /// CallLoweringInfo - Constructs a call lowering context based on the
1281     /// provided call information.
1282     CallLoweringInfo(SDValue chain, Type *retTy, bool retSExt, bool retZExt,
1283                      bool isVarArg, bool isInReg, unsigned numFixedArgs,
1284                      CallingConv::ID callConv, bool isTailCall,
1285                      bool doesNotReturn, bool isReturnValueUsed, SDValue callee,
1286                      ArgListTy &args, SelectionDAG &dag, DebugLoc dl)
1287     : Chain(chain), RetTy(retTy), RetSExt(retSExt), RetZExt(retZExt),
1288       IsVarArg(isVarArg), IsInReg(isInReg), DoesNotReturn(doesNotReturn),
1289       IsReturnValueUsed(isReturnValueUsed), IsTailCall(isTailCall),
1290       NumFixedArgs(numFixedArgs), CallConv(callConv), Callee(callee),
1291       Args(args), DAG(dag), DL(dl), CS(NULL) {}
1292   };
1293
1294   /// LowerCallTo - This function lowers an abstract call to a function into an
1295   /// actual call.  This returns a pair of operands.  The first element is the
1296   /// return value for the function (if RetTy is not VoidTy).  The second
1297   /// element is the outgoing token chain. It calls LowerCall to do the actual
1298   /// lowering.
1299   std::pair<SDValue, SDValue> LowerCallTo(CallLoweringInfo &CLI) const;
1300
1301   /// LowerCall - This hook must be implemented to lower calls into the
1302   /// the specified DAG. The outgoing arguments to the call are described
1303   /// by the Outs array, and the values to be returned by the call are
1304   /// described by the Ins array. The implementation should fill in the
1305   /// InVals array with legal-type return values from the call, and return
1306   /// the resulting token chain value.
1307   virtual SDValue
1308     LowerCall(CallLoweringInfo &/*CLI*/,
1309               SmallVectorImpl<SDValue> &/*InVals*/) const {
1310     llvm_unreachable("Not Implemented");
1311   }
1312
1313   /// HandleByVal - Target-specific cleanup for formal ByVal parameters.
1314   virtual void HandleByVal(CCState *, unsigned &) const {}
1315
1316   /// CanLowerReturn - This hook should be implemented to check whether the
1317   /// return values described by the Outs array can fit into the return
1318   /// registers.  If false is returned, an sret-demotion is performed.
1319   ///
1320   virtual bool CanLowerReturn(CallingConv::ID /*CallConv*/,
1321                               MachineFunction &/*MF*/, bool /*isVarArg*/,
1322                const SmallVectorImpl<ISD::OutputArg> &/*Outs*/,
1323                LLVMContext &/*Context*/) const
1324   {
1325     // Return true by default to get preexisting behavior.
1326     return true;
1327   }
1328
1329   /// LowerReturn - This hook must be implemented to lower outgoing
1330   /// return values, described by the Outs array, into the specified
1331   /// DAG. The implementation should return the resulting token chain
1332   /// value.
1333   ///
1334   virtual SDValue
1335     LowerReturn(SDValue /*Chain*/, CallingConv::ID /*CallConv*/,
1336                 bool /*isVarArg*/,
1337                 const SmallVectorImpl<ISD::OutputArg> &/*Outs*/,
1338                 const SmallVectorImpl<SDValue> &/*OutVals*/,
1339                 DebugLoc /*dl*/, SelectionDAG &/*DAG*/) const {
1340     llvm_unreachable("Not Implemented");
1341   }
1342
1343   /// isUsedByReturnOnly - Return true if result of the specified node is used
1344   /// by a return node only. It also compute and return the input chain for the
1345   /// tail call.
1346   /// This is used to determine whether it is possible
1347   /// to codegen a libcall as tail call at legalization time.
1348   virtual bool isUsedByReturnOnly(SDNode *, SDValue &Chain) const {
1349     return false;
1350   }
1351
1352   /// mayBeEmittedAsTailCall - Return true if the target may be able emit the
1353   /// call instruction as a tail call. This is used by optimization passes to
1354   /// determine if it's profitable to duplicate return instructions to enable
1355   /// tailcall optimization.
1356   virtual bool mayBeEmittedAsTailCall(CallInst *) const {
1357     return false;
1358   }
1359
1360   /// getTypeForExtArgOrReturn - Return the type that should be used to zero or
1361   /// sign extend a zeroext/signext integer argument or return value.
1362   /// FIXME: Most C calling convention requires the return type to be promoted,
1363   /// but this is not true all the time, e.g. i1 on x86-64. It is also not
1364   /// necessary for non-C calling conventions. The frontend should handle this
1365   /// and include all of the necessary information.
1366   virtual EVT getTypeForExtArgOrReturn(LLVMContext &Context, EVT VT,
1367                                        ISD::NodeType /*ExtendKind*/) const {
1368     EVT MinVT = getRegisterType(Context, MVT::i32);
1369     return VT.bitsLT(MinVT) ? MinVT : VT;
1370   }
1371
1372   /// LowerOperationWrapper - This callback is invoked by the type legalizer
1373   /// to legalize nodes with an illegal operand type but legal result types.
1374   /// It replaces the LowerOperation callback in the type Legalizer.
1375   /// The reason we can not do away with LowerOperation entirely is that
1376   /// LegalizeDAG isn't yet ready to use this callback.
1377   /// TODO: Consider merging with ReplaceNodeResults.
1378
1379   /// The target places new result values for the node in Results (their number
1380   /// and types must exactly match those of the original return values of
1381   /// the node), or leaves Results empty, which indicates that the node is not
1382   /// to be custom lowered after all.
1383   /// The default implementation calls LowerOperation.
1384   virtual void LowerOperationWrapper(SDNode *N,
1385                                      SmallVectorImpl<SDValue> &Results,
1386                                      SelectionDAG &DAG) const;
1387
1388   /// LowerOperation - This callback is invoked for operations that are
1389   /// unsupported by the target, which are registered to use 'custom' lowering,
1390   /// and whose defined values are all legal.
1391   /// If the target has no operations that require custom lowering, it need not
1392   /// implement this.  The default implementation of this aborts.
1393   virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const;
1394
1395   /// ReplaceNodeResults - This callback is invoked when a node result type is
1396   /// illegal for the target, and the operation was registered to use 'custom'
1397   /// lowering for that result type.  The target places new result values for
1398   /// the node in Results (their number and types must exactly match those of
1399   /// the original return values of the node), or leaves Results empty, which
1400   /// indicates that the node is not to be custom lowered after all.
1401   ///
1402   /// If the target has no operations that require custom lowering, it need not
1403   /// implement this.  The default implementation aborts.
1404   virtual void ReplaceNodeResults(SDNode * /*N*/,
1405                                   SmallVectorImpl<SDValue> &/*Results*/,
1406                                   SelectionDAG &/*DAG*/) const {
1407     llvm_unreachable("ReplaceNodeResults not implemented for this target!");
1408   }
1409
1410   /// getTargetNodeName() - This method returns the name of a target specific
1411   /// DAG node.
1412   virtual const char *getTargetNodeName(unsigned Opcode) const;
1413
1414   /// createFastISel - This method returns a target specific FastISel object,
1415   /// or null if the target does not support "fast" ISel.
1416   virtual FastISel *createFastISel(FunctionLoweringInfo &) const {
1417     return 0;
1418   }
1419
1420   //===--------------------------------------------------------------------===//
1421   // Inline Asm Support hooks
1422   //
1423
1424   /// ExpandInlineAsm - This hook allows the target to expand an inline asm
1425   /// call to be explicit llvm code if it wants to.  This is useful for
1426   /// turning simple inline asms into LLVM intrinsics, which gives the
1427   /// compiler more information about the behavior of the code.
1428   virtual bool ExpandInlineAsm(CallInst *) const {
1429     return false;
1430   }
1431
1432   enum ConstraintType {
1433     C_Register,            // Constraint represents specific register(s).
1434     C_RegisterClass,       // Constraint represents any of register(s) in class.
1435     C_Memory,              // Memory constraint.
1436     C_Other,               // Something else.
1437     C_Unknown              // Unsupported constraint.
1438   };
1439
1440   enum ConstraintWeight {
1441     // Generic weights.
1442     CW_Invalid  = -1,     // No match.
1443     CW_Okay     = 0,      // Acceptable.
1444     CW_Good     = 1,      // Good weight.
1445     CW_Better   = 2,      // Better weight.
1446     CW_Best     = 3,      // Best weight.
1447
1448     // Well-known weights.
1449     CW_SpecificReg  = CW_Okay,    // Specific register operands.
1450     CW_Register     = CW_Good,    // Register operands.
1451     CW_Memory       = CW_Better,  // Memory operands.
1452     CW_Constant     = CW_Best,    // Constant operand.
1453     CW_Default      = CW_Okay     // Default or don't know type.
1454   };
1455
1456   /// AsmOperandInfo - This contains information for each constraint that we are
1457   /// lowering.
1458   struct AsmOperandInfo : public InlineAsm::ConstraintInfo {
1459     /// ConstraintCode - This contains the actual string for the code, like "m".
1460     /// TargetLowering picks the 'best' code from ConstraintInfo::Codes that
1461     /// most closely matches the operand.
1462     std::string ConstraintCode;
1463
1464     /// ConstraintType - Information about the constraint code, e.g. Register,
1465     /// RegisterClass, Memory, Other, Unknown.
1466     TargetLowering::ConstraintType ConstraintType;
1467
1468     /// CallOperandval - If this is the result output operand or a
1469     /// clobber, this is null, otherwise it is the incoming operand to the
1470     /// CallInst.  This gets modified as the asm is processed.
1471     Value *CallOperandVal;
1472
1473     /// ConstraintVT - The ValueType for the operand value.
1474     EVT ConstraintVT;
1475
1476     /// isMatchingInputConstraint - Return true of this is an input operand that
1477     /// is a matching constraint like "4".
1478     bool isMatchingInputConstraint() const;
1479
1480     /// getMatchedOperand - If this is an input matching constraint, this method
1481     /// returns the output operand it matches.
1482     unsigned getMatchedOperand() const;
1483
1484     /// Copy constructor for copying from an AsmOperandInfo.
1485     AsmOperandInfo(const AsmOperandInfo &info)
1486       : InlineAsm::ConstraintInfo(info),
1487         ConstraintCode(info.ConstraintCode),
1488         ConstraintType(info.ConstraintType),
1489         CallOperandVal(info.CallOperandVal),
1490         ConstraintVT(info.ConstraintVT) {
1491     }
1492
1493     /// Copy constructor for copying from a ConstraintInfo.
1494     AsmOperandInfo(const InlineAsm::ConstraintInfo &info)
1495       : InlineAsm::ConstraintInfo(info),
1496         ConstraintType(TargetLowering::C_Unknown),
1497         CallOperandVal(0), ConstraintVT(MVT::Other) {
1498     }
1499   };
1500
1501   typedef std::vector<AsmOperandInfo> AsmOperandInfoVector;
1502
1503   /// ParseConstraints - Split up the constraint string from the inline
1504   /// assembly value into the specific constraints and their prefixes,
1505   /// and also tie in the associated operand values.
1506   /// If this returns an empty vector, and if the constraint string itself
1507   /// isn't empty, there was an error parsing.
1508   virtual AsmOperandInfoVector ParseConstraints(ImmutableCallSite CS) const;
1509
1510   /// Examine constraint type and operand type and determine a weight value.
1511   /// The operand object must already have been set up with the operand type.
1512   virtual ConstraintWeight getMultipleConstraintMatchWeight(
1513       AsmOperandInfo &info, int maIndex) const;
1514
1515   /// Examine constraint string and operand type and determine a weight value.
1516   /// The operand object must already have been set up with the operand type.
1517   virtual ConstraintWeight getSingleConstraintMatchWeight(
1518       AsmOperandInfo &info, const char *constraint) const;
1519
1520   /// ComputeConstraintToUse - Determines the constraint code and constraint
1521   /// type to use for the specific AsmOperandInfo, setting
1522   /// OpInfo.ConstraintCode and OpInfo.ConstraintType.  If the actual operand
1523   /// being passed in is available, it can be passed in as Op, otherwise an
1524   /// empty SDValue can be passed.
1525   virtual void ComputeConstraintToUse(AsmOperandInfo &OpInfo,
1526                                       SDValue Op,
1527                                       SelectionDAG *DAG = 0) const;
1528
1529   /// getConstraintType - Given a constraint, return the type of constraint it
1530   /// is for this target.
1531   virtual ConstraintType getConstraintType(const std::string &Constraint) const;
1532
1533   /// getRegForInlineAsmConstraint - Given a physical register constraint (e.g.
1534   /// {edx}), return the register number and the register class for the
1535   /// register.
1536   ///
1537   /// Given a register class constraint, like 'r', if this corresponds directly
1538   /// to an LLVM register class, return a register of 0 and the register class
1539   /// pointer.
1540   ///
1541   /// This should only be used for C_Register constraints.  On error,
1542   /// this returns a register number of 0 and a null register class pointer..
1543   virtual std::pair<unsigned, const TargetRegisterClass*>
1544     getRegForInlineAsmConstraint(const std::string &Constraint,
1545                                  EVT VT) const;
1546
1547   /// LowerXConstraint - try to replace an X constraint, which matches anything,
1548   /// with another that has more specific requirements based on the type of the
1549   /// corresponding operand.  This returns null if there is no replacement to
1550   /// make.
1551   virtual const char *LowerXConstraint(EVT ConstraintVT) const;
1552
1553   /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
1554   /// vector.  If it is invalid, don't add anything to Ops.
1555   virtual void LowerAsmOperandForConstraint(SDValue Op, std::string &Constraint,
1556                                             std::vector<SDValue> &Ops,
1557                                             SelectionDAG &DAG) const;
1558
1559   //===--------------------------------------------------------------------===//
1560   // Instruction Emitting Hooks
1561   //
1562
1563   // EmitInstrWithCustomInserter - This method should be implemented by targets
1564   // that mark instructions with the 'usesCustomInserter' flag.  These
1565   // instructions are special in various ways, which require special support to
1566   // insert.  The specified MachineInstr is created but not inserted into any
1567   // basic blocks, and this method is called to expand it into a sequence of
1568   // instructions, potentially also creating new basic blocks and control flow.
1569   virtual MachineBasicBlock *
1570     EmitInstrWithCustomInserter(MachineInstr *MI, MachineBasicBlock *MBB) const;
1571
1572   /// AdjustInstrPostInstrSelection - This method should be implemented by
1573   /// targets that mark instructions with the 'hasPostISelHook' flag. These
1574   /// instructions must be adjusted after instruction selection by target hooks.
1575   /// e.g. To fill in optional defs for ARM 's' setting instructions.
1576   virtual void
1577   AdjustInstrPostInstrSelection(MachineInstr *MI, SDNode *Node) const;
1578
1579   //===--------------------------------------------------------------------===//
1580   // Addressing mode description hooks (used by LSR etc).
1581   //
1582
1583   /// AddrMode - This represents an addressing mode of:
1584   ///    BaseGV + BaseOffs + BaseReg + Scale*ScaleReg
1585   /// If BaseGV is null,  there is no BaseGV.
1586   /// If BaseOffs is zero, there is no base offset.
1587   /// If HasBaseReg is false, there is no base register.
1588   /// If Scale is zero, there is no ScaleReg.  Scale of 1 indicates a reg with
1589   /// no scale.
1590   ///
1591   struct AddrMode {
1592     GlobalValue *BaseGV;
1593     int64_t      BaseOffs;
1594     bool         HasBaseReg;
1595     int64_t      Scale;
1596     AddrMode() : BaseGV(0), BaseOffs(0), HasBaseReg(false), Scale(0) {}
1597   };
1598
1599   /// GetAddrModeArguments - CodeGenPrepare sinks address calculations into the
1600   /// same BB as Load/Store instructions reading the address.  This allows as
1601   /// much computation as possible to be done in the address mode for that
1602   /// operand.  This hook lets targets also pass back when this should be done
1603   /// on intrinsics which load/store.
1604   virtual bool GetAddrModeArguments(IntrinsicInst *I,
1605                                     SmallVectorImpl<Value*> &Ops,
1606                                     Type *&AccessTy) const {
1607     return false;
1608   }
1609
1610   /// isLegalAddressingMode - Return true if the addressing mode represented by
1611   /// AM is legal for this target, for a load/store of the specified type.
1612   /// The type may be VoidTy, in which case only return true if the addressing
1613   /// mode is legal for a load/store of any legal type.
1614   /// TODO: Handle pre/postinc as well.
1615   virtual bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const;
1616
1617   /// isLegalICmpImmediate - Return true if the specified immediate is legal
1618   /// icmp immediate, that is the target has icmp instructions which can compare
1619   /// a register against the immediate without having to materialize the
1620   /// immediate into a register.
1621   virtual bool isLegalICmpImmediate(int64_t) const {
1622     return true;
1623   }
1624
1625   /// isLegalAddImmediate - Return true if the specified immediate is legal
1626   /// add immediate, that is the target has add instructions which can add
1627   /// a register with the immediate without having to materialize the
1628   /// immediate into a register.
1629   virtual bool isLegalAddImmediate(int64_t) const {
1630     return true;
1631   }
1632
1633   /// isTruncateFree - Return true if it's free to truncate a value of
1634   /// type Ty1 to type Ty2. e.g. On x86 it's free to truncate a i32 value in
1635   /// register EAX to i16 by referencing its sub-register AX.
1636   virtual bool isTruncateFree(Type * /*Ty1*/, Type * /*Ty2*/) const {
1637     return false;
1638   }
1639
1640   virtual bool isTruncateFree(EVT /*VT1*/, EVT /*VT2*/) const {
1641     return false;
1642   }
1643
1644   /// isZExtFree - Return true if any actual instruction that defines a
1645   /// value of type Ty1 implicitly zero-extends the value to Ty2 in the result
1646   /// register. This does not necessarily include registers defined in
1647   /// unknown ways, such as incoming arguments, or copies from unknown
1648   /// virtual registers. Also, if isTruncateFree(Ty2, Ty1) is true, this
1649   /// does not necessarily apply to truncate instructions. e.g. on x86-64,
1650   /// all instructions that define 32-bit values implicit zero-extend the
1651   /// result out to 64 bits.
1652   virtual bool isZExtFree(Type * /*Ty1*/, Type * /*Ty2*/) const {
1653     return false;
1654   }
1655
1656   virtual bool isZExtFree(EVT /*VT1*/, EVT /*VT2*/) const {
1657     return false;
1658   }
1659
1660   /// isFNegFree - Return true if an fneg operation is free to the point where
1661   /// it is never worthwhile to replace it with a bitwise operation.
1662   virtual bool isFNegFree(EVT) const {
1663     return false;
1664   }
1665
1666   /// isFAbsFree - Return true if an fneg operation is free to the point where
1667   /// it is never worthwhile to replace it with a bitwise operation.
1668   virtual bool isFAbsFree(EVT) const {
1669     return false;
1670   }
1671
1672   /// isFMAFasterThanMulAndAdd - Return true if an FMA operation is faster than
1673   /// a pair of mul and add instructions. fmuladd intrinsics will be expanded to
1674   /// FMAs when this method returns true (and FMAs are legal), otherwise fmuladd
1675   /// is expanded to mul + add.
1676   virtual bool isFMAFasterThanMulAndAdd(EVT) const {
1677     return false;
1678   }
1679
1680   /// isNarrowingProfitable - Return true if it's profitable to narrow
1681   /// operations of type VT1 to VT2. e.g. on x86, it's profitable to narrow
1682   /// from i32 to i8 but not from i32 to i16.
1683   virtual bool isNarrowingProfitable(EVT /*VT1*/, EVT /*VT2*/) const {
1684     return false;
1685   }
1686
1687   //===--------------------------------------------------------------------===//
1688   // Div utility functions
1689   //
1690   SDValue BuildExactSDIV(SDValue Op1, SDValue Op2, DebugLoc dl,
1691                          SelectionDAG &DAG) const;
1692   SDValue BuildSDIV(SDNode *N, SelectionDAG &DAG, bool IsAfterLegalization,
1693                       std::vector<SDNode*>* Created) const;
1694   SDValue BuildUDIV(SDNode *N, SelectionDAG &DAG, bool IsAfterLegalization,
1695                       std::vector<SDNode*>* Created) const;
1696
1697
1698   //===--------------------------------------------------------------------===//
1699   // Runtime Library hooks
1700   //
1701
1702   /// setLibcallName - Rename the default libcall routine name for the specified
1703   /// libcall.
1704   void setLibcallName(RTLIB::Libcall Call, const char *Name) {
1705     LibcallRoutineNames[Call] = Name;
1706   }
1707
1708   /// getLibcallName - Get the libcall routine name for the specified libcall.
1709   ///
1710   const char *getLibcallName(RTLIB::Libcall Call) const {
1711     return LibcallRoutineNames[Call];
1712   }
1713
1714   /// setCmpLibcallCC - Override the default CondCode to be used to test the
1715   /// result of the comparison libcall against zero.
1716   void setCmpLibcallCC(RTLIB::Libcall Call, ISD::CondCode CC) {
1717     CmpLibcallCCs[Call] = CC;
1718   }
1719
1720   /// getCmpLibcallCC - Get the CondCode that's to be used to test the result of
1721   /// the comparison libcall against zero.
1722   ISD::CondCode getCmpLibcallCC(RTLIB::Libcall Call) const {
1723     return CmpLibcallCCs[Call];
1724   }
1725
1726   /// setLibcallCallingConv - Set the CallingConv that should be used for the
1727   /// specified libcall.
1728   void setLibcallCallingConv(RTLIB::Libcall Call, CallingConv::ID CC) {
1729     LibcallCallingConvs[Call] = CC;
1730   }
1731
1732   /// getLibcallCallingConv - Get the CallingConv that should be used for the
1733   /// specified libcall.
1734   CallingConv::ID getLibcallCallingConv(RTLIB::Libcall Call) const {
1735     return LibcallCallingConvs[Call];
1736   }
1737
1738 private:
1739   const TargetMachine &TM;
1740   const TargetData *TD;
1741   const TargetLoweringObjectFile &TLOF;
1742
1743   /// PointerTy - The type to use for pointers, usually i32 or i64.
1744   ///
1745   MVT PointerTy;
1746
1747   /// IsLittleEndian - True if this is a little endian target.
1748   ///
1749   bool IsLittleEndian;
1750
1751   /// SelectIsExpensive - Tells the code generator not to expand operations
1752   /// into sequences that use the select operations if possible.
1753   bool SelectIsExpensive;
1754
1755   /// IntDivIsCheap - Tells the code generator not to expand integer divides by
1756   /// constants into a sequence of muls, adds, and shifts.  This is a hack until
1757   /// a real cost model is in place.  If we ever optimize for size, this will be
1758   /// set to true unconditionally.
1759   bool IntDivIsCheap;
1760
1761   /// Pow2DivIsCheap - Tells the code generator that it shouldn't generate
1762   /// srl/add/sra for a signed divide by power of two, and let the target handle
1763   /// it.
1764   bool Pow2DivIsCheap;
1765
1766   /// JumpIsExpensive - Tells the code generator that it shouldn't generate
1767   /// extra flow control instructions and should attempt to combine flow
1768   /// control instructions via predication.
1769   bool JumpIsExpensive;
1770
1771   /// UseUnderscoreSetJmp - This target prefers to use _setjmp to implement
1772   /// llvm.setjmp.  Defaults to false.
1773   bool UseUnderscoreSetJmp;
1774
1775   /// UseUnderscoreLongJmp - This target prefers to use _longjmp to implement
1776   /// llvm.longjmp.  Defaults to false.
1777   bool UseUnderscoreLongJmp;
1778
1779   /// SupportJumpTables - Whether the target can generate code for jumptables.
1780   /// If it's not true, then each jumptable must be lowered into if-then-else's.
1781   bool SupportJumpTables;
1782
1783   /// BooleanContents - Information about the contents of the high-bits in
1784   /// boolean values held in a type wider than i1.  See getBooleanContents.
1785   BooleanContent BooleanContents;
1786   /// BooleanVectorContents - Information about the contents of the high-bits
1787   /// in boolean vector values when the element type is wider than i1.  See
1788   /// getBooleanContents.
1789   BooleanContent BooleanVectorContents;
1790
1791   /// SchedPreferenceInfo - The target scheduling preference: shortest possible
1792   /// total cycles or lowest register usage.
1793   Sched::Preference SchedPreferenceInfo;
1794
1795   /// JumpBufSize - The size, in bytes, of the target's jmp_buf buffers
1796   unsigned JumpBufSize;
1797
1798   /// JumpBufAlignment - The alignment, in bytes, of the target's jmp_buf
1799   /// buffers
1800   unsigned JumpBufAlignment;
1801
1802   /// MinStackArgumentAlignment - The minimum alignment that any argument
1803   /// on the stack needs to have.
1804   ///
1805   unsigned MinStackArgumentAlignment;
1806
1807   /// MinFunctionAlignment - The minimum function alignment (used when
1808   /// optimizing for size, and to prevent explicitly provided alignment
1809   /// from leading to incorrect code).
1810   ///
1811   unsigned MinFunctionAlignment;
1812
1813   /// PrefFunctionAlignment - The preferred function alignment (used when
1814   /// alignment unspecified and optimizing for speed).
1815   ///
1816   unsigned PrefFunctionAlignment;
1817
1818   /// PrefLoopAlignment - The preferred loop alignment.
1819   ///
1820   unsigned PrefLoopAlignment;
1821
1822   /// ShouldFoldAtomicFences - Whether fencing MEMBARRIER instructions should
1823   /// be folded into the enclosed atomic intrinsic instruction by the
1824   /// combiner.
1825   bool ShouldFoldAtomicFences;
1826
1827   /// InsertFencesForAtomic - Whether the DAG builder should automatically
1828   /// insert fences and reduce ordering for atomics.  (This will be set for
1829   /// for most architectures with weak memory ordering.)
1830   bool InsertFencesForAtomic;
1831
1832   /// StackPointerRegisterToSaveRestore - If set to a physical register, this
1833   /// specifies the register that llvm.savestack/llvm.restorestack should save
1834   /// and restore.
1835   unsigned StackPointerRegisterToSaveRestore;
1836
1837   /// ExceptionPointerRegister - If set to a physical register, this specifies
1838   /// the register that receives the exception address on entry to a landing
1839   /// pad.
1840   unsigned ExceptionPointerRegister;
1841
1842   /// ExceptionSelectorRegister - If set to a physical register, this specifies
1843   /// the register that receives the exception typeid on entry to a landing
1844   /// pad.
1845   unsigned ExceptionSelectorRegister;
1846
1847   /// RegClassForVT - This indicates the default register class to use for
1848   /// each ValueType the target supports natively.
1849   const TargetRegisterClass *RegClassForVT[MVT::LAST_VALUETYPE];
1850   unsigned char NumRegistersForVT[MVT::LAST_VALUETYPE];
1851   EVT RegisterTypeForVT[MVT::LAST_VALUETYPE];
1852
1853   /// RepRegClassForVT - This indicates the "representative" register class to
1854   /// use for each ValueType the target supports natively. This information is
1855   /// used by the scheduler to track register pressure. By default, the
1856   /// representative register class is the largest legal super-reg register
1857   /// class of the register class of the specified type. e.g. On x86, i8, i16,
1858   /// and i32's representative class would be GR32.
1859   const TargetRegisterClass *RepRegClassForVT[MVT::LAST_VALUETYPE];
1860
1861   /// RepRegClassCostForVT - This indicates the "cost" of the "representative"
1862   /// register class for each ValueType. The cost is used by the scheduler to
1863   /// approximate register pressure.
1864   uint8_t RepRegClassCostForVT[MVT::LAST_VALUETYPE];
1865
1866   /// TransformToType - For any value types we are promoting or expanding, this
1867   /// contains the value type that we are changing to.  For Expanded types, this
1868   /// contains one step of the expand (e.g. i64 -> i32), even if there are
1869   /// multiple steps required (e.g. i64 -> i16).  For types natively supported
1870   /// by the system, this holds the same type (e.g. i32 -> i32).
1871   EVT TransformToType[MVT::LAST_VALUETYPE];
1872
1873   /// OpActions - For each operation and each value type, keep a LegalizeAction
1874   /// that indicates how instruction selection should deal with the operation.
1875   /// Most operations are Legal (aka, supported natively by the target), but
1876   /// operations that are not should be described.  Note that operations on
1877   /// non-legal value types are not described here.
1878   uint8_t OpActions[MVT::LAST_VALUETYPE][ISD::BUILTIN_OP_END];
1879
1880   /// LoadExtActions - For each load extension type and each value type,
1881   /// keep a LegalizeAction that indicates how instruction selection should deal
1882   /// with a load of a specific value type and extension type.
1883   uint8_t LoadExtActions[MVT::LAST_VALUETYPE][ISD::LAST_LOADEXT_TYPE];
1884
1885   /// TruncStoreActions - For each value type pair keep a LegalizeAction that
1886   /// indicates whether a truncating store of a specific value type and
1887   /// truncating type is legal.
1888   uint8_t TruncStoreActions[MVT::LAST_VALUETYPE][MVT::LAST_VALUETYPE];
1889
1890   /// IndexedModeActions - For each indexed mode and each value type,
1891   /// keep a pair of LegalizeAction that indicates how instruction
1892   /// selection should deal with the load / store.  The first dimension is the
1893   /// value_type for the reference. The second dimension represents the various
1894   /// modes for load store.
1895   uint8_t IndexedModeActions[MVT::LAST_VALUETYPE][ISD::LAST_INDEXED_MODE];
1896
1897   /// CondCodeActions - For each condition code (ISD::CondCode) keep a
1898   /// LegalizeAction that indicates how instruction selection should
1899   /// deal with the condition code.
1900   uint64_t CondCodeActions[ISD::SETCC_INVALID];
1901
1902   ValueTypeActionImpl ValueTypeActions;
1903
1904   typedef std::pair<LegalizeTypeAction, EVT> LegalizeKind;
1905
1906   LegalizeKind
1907   getTypeConversion(LLVMContext &Context, EVT VT) const {
1908     // If this is a simple type, use the ComputeRegisterProp mechanism.
1909     if (VT.isSimple()) {
1910       assert((unsigned)VT.getSimpleVT().SimpleTy <
1911              array_lengthof(TransformToType));
1912       EVT NVT = TransformToType[VT.getSimpleVT().SimpleTy];
1913       LegalizeTypeAction LA = ValueTypeActions.getTypeAction(VT.getSimpleVT());
1914
1915       assert(
1916         (!(NVT.isSimple() && LA != TypeLegal) ||
1917          ValueTypeActions.getTypeAction(NVT.getSimpleVT()) != TypePromoteInteger)
1918          && "Promote may not follow Expand or Promote");
1919
1920       return LegalizeKind(LA, NVT);
1921     }
1922
1923     // Handle Extended Scalar Types.
1924     if (!VT.isVector()) {
1925       assert(VT.isInteger() && "Float types must be simple");
1926       unsigned BitSize = VT.getSizeInBits();
1927       // First promote to a power-of-two size, then expand if necessary.
1928       if (BitSize < 8 || !isPowerOf2_32(BitSize)) {
1929         EVT NVT = VT.getRoundIntegerType(Context);
1930         assert(NVT != VT && "Unable to round integer VT");
1931         LegalizeKind NextStep = getTypeConversion(Context, NVT);
1932         // Avoid multi-step promotion.
1933         if (NextStep.first == TypePromoteInteger) return NextStep;
1934         // Return rounded integer type.
1935         return LegalizeKind(TypePromoteInteger, NVT);
1936       }
1937
1938       return LegalizeKind(TypeExpandInteger,
1939                           EVT::getIntegerVT(Context, VT.getSizeInBits()/2));
1940     }
1941
1942     // Handle vector types.
1943     unsigned NumElts = VT.getVectorNumElements();
1944     EVT EltVT = VT.getVectorElementType();
1945
1946     // Vectors with only one element are always scalarized.
1947     if (NumElts == 1)
1948       return LegalizeKind(TypeScalarizeVector, EltVT);
1949
1950     // Try to widen vector elements until a legal type is found.
1951     if (EltVT.isInteger()) {
1952       // Vectors with a number of elements that is not a power of two are always
1953       // widened, for example <3 x float> -> <4 x float>.
1954       if (!VT.isPow2VectorType()) {
1955         NumElts = (unsigned)NextPowerOf2(NumElts);
1956         EVT NVT = EVT::getVectorVT(Context, EltVT, NumElts);
1957         return LegalizeKind(TypeWidenVector, NVT);
1958       }
1959
1960       // Examine the element type.
1961       LegalizeKind LK = getTypeConversion(Context, EltVT);
1962
1963       // If type is to be expanded, split the vector.
1964       //  <4 x i140> -> <2 x i140>
1965       if (LK.first == TypeExpandInteger)
1966         return LegalizeKind(TypeSplitVector,
1967                             EVT::getVectorVT(Context, EltVT, NumElts / 2));
1968
1969       // Promote the integer element types until a legal vector type is found
1970       // or until the element integer type is too big. If a legal type was not
1971       // found, fallback to the usual mechanism of widening/splitting the
1972       // vector.
1973       while (1) {
1974         // Increase the bitwidth of the element to the next pow-of-two
1975         // (which is greater than 8 bits).
1976         EltVT = EVT::getIntegerVT(Context, 1 + EltVT.getSizeInBits()
1977                                  ).getRoundIntegerType(Context);
1978
1979         // Stop trying when getting a non-simple element type.
1980         // Note that vector elements may be greater than legal vector element
1981         // types. Example: X86 XMM registers hold 64bit element on 32bit systems.
1982         if (!EltVT.isSimple()) break;
1983
1984         // Build a new vector type and check if it is legal.
1985         MVT NVT = MVT::getVectorVT(EltVT.getSimpleVT(), NumElts);
1986         // Found a legal promoted vector type.
1987         if (NVT != MVT() && ValueTypeActions.getTypeAction(NVT) == TypeLegal)
1988           return LegalizeKind(TypePromoteInteger,
1989                               EVT::getVectorVT(Context, EltVT, NumElts));
1990       }
1991     }
1992
1993     // Try to widen the vector until a legal type is found.
1994     // If there is no wider legal type, split the vector.
1995     while (1) {
1996       // Round up to the next power of 2.
1997       NumElts = (unsigned)NextPowerOf2(NumElts);
1998
1999       // If there is no simple vector type with this many elements then there
2000       // cannot be a larger legal vector type.  Note that this assumes that
2001       // there are no skipped intermediate vector types in the simple types.
2002       if (!EltVT.isSimple()) break;
2003       MVT LargerVector = MVT::getVectorVT(EltVT.getSimpleVT(), NumElts);
2004       if (LargerVector == MVT()) break;
2005
2006       // If this type is legal then widen the vector.
2007       if (ValueTypeActions.getTypeAction(LargerVector) == TypeLegal)
2008         return LegalizeKind(TypeWidenVector, LargerVector);
2009     }
2010
2011     // Widen odd vectors to next power of two.
2012     if (!VT.isPow2VectorType()) {
2013       EVT NVT = VT.getPow2VectorType(Context);
2014       return LegalizeKind(TypeWidenVector, NVT);
2015     }
2016
2017     // Vectors with illegal element types are expanded.
2018     EVT NVT = EVT::getVectorVT(Context, EltVT, VT.getVectorNumElements() / 2);
2019     return LegalizeKind(TypeSplitVector, NVT);
2020   }
2021
2022   std::vector<std::pair<EVT, const TargetRegisterClass*> > AvailableRegClasses;
2023
2024   /// TargetDAGCombineArray - Targets can specify ISD nodes that they would
2025   /// like PerformDAGCombine callbacks for by calling setTargetDAGCombine(),
2026   /// which sets a bit in this array.
2027   unsigned char
2028   TargetDAGCombineArray[(ISD::BUILTIN_OP_END+CHAR_BIT-1)/CHAR_BIT];
2029
2030   /// PromoteToType - For operations that must be promoted to a specific type,
2031   /// this holds the destination type.  This map should be sparse, so don't hold
2032   /// it as an array.
2033   ///
2034   /// Targets add entries to this map with AddPromotedToType(..), clients access
2035   /// this with getTypeToPromoteTo(..).
2036   std::map<std::pair<unsigned, MVT::SimpleValueType>, MVT::SimpleValueType>
2037     PromoteToType;
2038
2039   /// LibcallRoutineNames - Stores the name each libcall.
2040   ///
2041   const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL];
2042
2043   /// CmpLibcallCCs - The ISD::CondCode that should be used to test the result
2044   /// of each of the comparison libcall against zero.
2045   ISD::CondCode CmpLibcallCCs[RTLIB::UNKNOWN_LIBCALL];
2046
2047   /// LibcallCallingConvs - Stores the CallingConv that should be used for each
2048   /// libcall.
2049   CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL];
2050
2051 protected:
2052   /// When lowering \@llvm.memset this field specifies the maximum number of
2053   /// store operations that may be substituted for the call to memset. Targets
2054   /// must set this value based on the cost threshold for that target. Targets
2055   /// should assume that the memset will be done using as many of the largest
2056   /// store operations first, followed by smaller ones, if necessary, per
2057   /// alignment restrictions. For example, storing 9 bytes on a 32-bit machine
2058   /// with 16-bit alignment would result in four 2-byte stores and one 1-byte
2059   /// store.  This only applies to setting a constant array of a constant size.
2060   /// @brief Specify maximum number of store instructions per memset call.
2061   unsigned maxStoresPerMemset;
2062
2063   /// Maximum number of stores operations that may be substituted for the call
2064   /// to memset, used for functions with OptSize attribute.
2065   unsigned maxStoresPerMemsetOptSize;
2066
2067   /// When lowering \@llvm.memcpy this field specifies the maximum number of
2068   /// store operations that may be substituted for a call to memcpy. Targets
2069   /// must set this value based on the cost threshold for that target. Targets
2070   /// should assume that the memcpy will be done using as many of the largest
2071   /// store operations first, followed by smaller ones, if necessary, per
2072   /// alignment restrictions. For example, storing 7 bytes on a 32-bit machine
2073   /// with 32-bit alignment would result in one 4-byte store, a one 2-byte store
2074   /// and one 1-byte store. This only applies to copying a constant array of
2075   /// constant size.
2076   /// @brief Specify maximum bytes of store instructions per memcpy call.
2077   unsigned maxStoresPerMemcpy;
2078
2079   /// Maximum number of store operations that may be substituted for a call
2080   /// to memcpy, used for functions with OptSize attribute.
2081   unsigned maxStoresPerMemcpyOptSize;
2082
2083   /// When lowering \@llvm.memmove this field specifies the maximum number of
2084   /// store instructions that may be substituted for a call to memmove. Targets
2085   /// must set this value based on the cost threshold for that target. Targets
2086   /// should assume that the memmove will be done using as many of the largest
2087   /// store operations first, followed by smaller ones, if necessary, per
2088   /// alignment restrictions. For example, moving 9 bytes on a 32-bit machine
2089   /// with 8-bit alignment would result in nine 1-byte stores.  This only
2090   /// applies to copying a constant array of constant size.
2091   /// @brief Specify maximum bytes of store instructions per memmove call.
2092   unsigned maxStoresPerMemmove;
2093
2094   /// Maximum number of store instructions that may be substituted for a call
2095   /// to memmove, used for functions with OpSize attribute.
2096   unsigned maxStoresPerMemmoveOptSize;
2097
2098   /// This field specifies whether the target can benefit from code placement
2099   /// optimization.
2100   bool benefitFromCodePlacementOpt;
2101
2102   /// predictableSelectIsExpensive - Tells the code generator that select is
2103   /// more expensive than a branch if the branch is usually predicted right.
2104   bool predictableSelectIsExpensive;
2105
2106 private:
2107   /// isLegalRC - Return true if the value types that can be represented by the
2108   /// specified register class are all legal.
2109   bool isLegalRC(const TargetRegisterClass *RC) const;
2110 };
2111
2112 /// GetReturnInfo - Given an LLVM IR type and return type attributes,
2113 /// compute the return value EVTs and flags, and optionally also
2114 /// the offsets, if the return value is being lowered to memory.
2115 void GetReturnInfo(Type* ReturnType, Attributes attr,
2116                    SmallVectorImpl<ISD::OutputArg> &Outs,
2117                    const TargetLowering &TLI);
2118
2119 } // end llvm namespace
2120
2121 #endif