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