Let each target decide byval alignment. For X86, it's 4-byte unless the aggregare...
[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/CodeGen/SelectionDAGNodes.h"
26 #include "llvm/CodeGen/RuntimeLibcalls.h"
27 #include "llvm/ADT/APFloat.h"
28 #include "llvm/ADT/STLExtras.h"
29 #include <map>
30 #include <vector>
31
32 namespace llvm {
33   class Value;
34   class Function;
35   class TargetMachine;
36   class TargetData;
37   class TargetRegisterClass;
38   class SDNode;
39   class SDOperand;
40   class SelectionDAG;
41   class MachineBasicBlock;
42   class MachineInstr;
43   class VectorType;
44   class TargetSubtarget;
45
46 //===----------------------------------------------------------------------===//
47 /// TargetLowering - This class defines information used to lower LLVM code to
48 /// legal SelectionDAG operators that the target instruction selector can accept
49 /// natively.
50 ///
51 /// This class also defines callbacks that targets must implement to lower
52 /// target-specific constructs to SelectionDAG operators.
53 ///
54 class TargetLowering {
55 public:
56   /// LegalizeAction - This enum indicates whether operations are valid for a
57   /// target, and if not, what action should be used to make them valid.
58   enum LegalizeAction {
59     Legal,      // The target natively supports this operation.
60     Promote,    // This operation should be executed in a larger type.
61     Expand,     // Try to expand this to other ops, otherwise use a libcall.
62     Custom      // Use the LowerOperation hook to implement custom lowering.
63   };
64
65   enum OutOfRangeShiftAmount {
66     Undefined,  // Oversized shift amounts are undefined (default).
67     Mask,       // Shift amounts are auto masked (anded) to value size.
68     Extend      // Oversized shift pulls in zeros or sign bits.
69   };
70
71   enum SetCCResultValue {
72     UndefinedSetCCResult,          // SetCC returns a garbage/unknown extend.
73     ZeroOrOneSetCCResult,          // SetCC returns a zero extended result.
74     ZeroOrNegativeOneSetCCResult   // SetCC returns a sign extended result.
75   };
76
77   enum SchedPreference {
78     SchedulingForLatency,          // Scheduling for shortest total latency.
79     SchedulingForRegPressure       // Scheduling for lowest register pressure.
80   };
81
82   explicit TargetLowering(TargetMachine &TM);
83   virtual ~TargetLowering();
84
85   TargetMachine &getTargetMachine() const { return TM; }
86   const TargetData *getTargetData() const { return TD; }
87
88   bool isLittleEndian() const { return IsLittleEndian; }
89   MVT::ValueType getPointerTy() const { return PointerTy; }
90   MVT::ValueType getShiftAmountTy() const { return ShiftAmountTy; }
91   OutOfRangeShiftAmount getShiftAmountFlavor() const {return ShiftAmtHandling; }
92
93   /// usesGlobalOffsetTable - Return true if this target uses a GOT for PIC
94   /// codegen.
95   bool usesGlobalOffsetTable() const { return UsesGlobalOffsetTable; }
96
97   /// isSelectExpensive - Return true if the select operation is expensive for
98   /// this target.
99   bool isSelectExpensive() const { return SelectIsExpensive; }
100   
101   /// isIntDivCheap() - Return true if integer divide is usually cheaper than
102   /// a sequence of several shifts, adds, and multiplies for this target.
103   bool isIntDivCheap() const { return IntDivIsCheap; }
104
105   /// isPow2DivCheap() - Return true if pow2 div is cheaper than a chain of
106   /// srl/add/sra.
107   bool isPow2DivCheap() const { return Pow2DivIsCheap; }
108
109   /// getSetCCResultTy - Return the ValueType of the result of setcc operations.
110   ///
111   MVT::ValueType getSetCCResultTy() const { return SetCCResultTy; }
112
113   /// getSetCCResultContents - For targets without boolean registers, this flag
114   /// returns information about the contents of the high-bits in the setcc
115   /// result register.
116   SetCCResultValue getSetCCResultContents() const { return SetCCResultContents;}
117
118   /// getSchedulingPreference - Return target scheduling preference.
119   SchedPreference getSchedulingPreference() const {
120     return SchedPreferenceInfo;
121   }
122
123   /// getRegClassFor - Return the register class that should be used for the
124   /// specified value type.  This may only be called on legal types.
125   TargetRegisterClass *getRegClassFor(MVT::ValueType VT) const {
126     assert(!MVT::isExtendedVT(VT));
127     TargetRegisterClass *RC = RegClassForVT[VT];
128     assert(RC && "This value type is not natively supported!");
129     return RC;
130   }
131   
132   /// isTypeLegal - Return true if the target has native support for the
133   /// specified value type.  This means that it has a register that directly
134   /// holds it without promotions or expansions.
135   bool isTypeLegal(MVT::ValueType VT) const {
136     return !MVT::isExtendedVT(VT) && RegClassForVT[VT] != 0;
137   }
138
139   class ValueTypeActionImpl {
140     /// ValueTypeActions - This is a bitvector that contains two bits for each
141     /// value type, where the two bits correspond to the LegalizeAction enum.
142     /// This can be queried with "getTypeAction(VT)".
143     uint32_t ValueTypeActions[2];
144   public:
145     ValueTypeActionImpl() {
146       ValueTypeActions[0] = ValueTypeActions[1] = 0;
147     }
148     ValueTypeActionImpl(const ValueTypeActionImpl &RHS) {
149       ValueTypeActions[0] = RHS.ValueTypeActions[0];
150       ValueTypeActions[1] = RHS.ValueTypeActions[1];
151     }
152     
153     LegalizeAction getTypeAction(MVT::ValueType VT) const {
154       if (MVT::isExtendedVT(VT)) {
155         if (MVT::isVector(VT)) return Expand;
156         if (MVT::isInteger(VT))
157           // First promote to a power-of-two size, then expand if necessary.
158           return VT == MVT::RoundIntegerType(VT) ? Expand : Promote;
159         assert(0 && "Unsupported extended type!");
160       }
161       return (LegalizeAction)((ValueTypeActions[VT>>4] >> ((2*VT) & 31)) & 3);
162     }
163     void setTypeAction(MVT::ValueType VT, LegalizeAction Action) {
164       assert(!MVT::isExtendedVT(VT));
165       assert(unsigned(VT >> 4) < array_lengthof(ValueTypeActions));
166       ValueTypeActions[VT>>4] |= Action << ((VT*2) & 31);
167     }
168   };
169   
170   const ValueTypeActionImpl &getValueTypeActions() const {
171     return ValueTypeActions;
172   }
173   
174   /// getTypeAction - Return how we should legalize values of this type, either
175   /// it is already legal (return 'Legal') or we need to promote it to a larger
176   /// type (return 'Promote'), or we need to expand it into multiple registers
177   /// of smaller integer type (return 'Expand').  'Custom' is not an option.
178   LegalizeAction getTypeAction(MVT::ValueType VT) const {
179     return ValueTypeActions.getTypeAction(VT);
180   }
181
182   /// getTypeToTransformTo - For types supported by the target, this is an
183   /// identity function.  For types that must be promoted to larger types, this
184   /// returns the larger type to promote to.  For integer types that are larger
185   /// than the largest integer register, this contains one step in the expansion
186   /// to get to the smaller register. For illegal floating point types, this
187   /// returns the integer type to transform to.
188   MVT::ValueType getTypeToTransformTo(MVT::ValueType VT) const {
189     if (!MVT::isExtendedVT(VT)) {
190       MVT::ValueType NVT = TransformToType[VT];
191       assert(getTypeAction(NVT) != Promote &&
192              "Promote may not follow Expand or Promote");
193       return NVT;
194     }
195
196     if (MVT::isVector(VT))
197       return MVT::getVectorType(MVT::getVectorElementType(VT),
198                                 MVT::getVectorNumElements(VT) / 2);
199     if (MVT::isInteger(VT)) {
200       MVT::ValueType NVT = MVT::RoundIntegerType(VT);
201       if (NVT == VT)
202         // Size is a power of two - expand to half the size.
203         return MVT::getIntegerType(MVT::getSizeInBits(VT) / 2);
204       else
205         // Promote to a power of two size, avoiding multi-step promotion.
206         return getTypeAction(NVT) == Promote ? getTypeToTransformTo(NVT) : NVT;
207     }
208     assert(0 && "Unsupported extended type!");
209   }
210
211   /// getTypeToExpandTo - For types supported by the target, this is an
212   /// identity function.  For types that must be expanded (i.e. integer types
213   /// that are larger than the largest integer register or illegal floating
214   /// point types), this returns the largest legal type it will be expanded to.
215   MVT::ValueType getTypeToExpandTo(MVT::ValueType VT) const {
216     assert(!MVT::isVector(VT));
217     while (true) {
218       switch (getTypeAction(VT)) {
219       case Legal:
220         return VT;
221       case Expand:
222         VT = getTypeToTransformTo(VT);
223         break;
224       default:
225         assert(false && "Type is not legal nor is it to be expanded!");
226         return VT;
227       }
228     }
229     return VT;
230   }
231
232   /// getVectorTypeBreakdown - Vector types are broken down into some number of
233   /// legal first class types.  For example, MVT::v8f32 maps to 2 MVT::v4f32
234   /// with Altivec or SSE1, or 8 promoted MVT::f64 values with the X86 FP stack.
235   /// Similarly, MVT::v2i64 turns into 4 MVT::i32 values with both PPC and X86.
236   ///
237   /// This method returns the number of registers needed, and the VT for each
238   /// register.  It also returns the VT and quantity of the intermediate values
239   /// before they are promoted/expanded.
240   ///
241   unsigned getVectorTypeBreakdown(MVT::ValueType VT, 
242                                   MVT::ValueType &IntermediateVT,
243                                   unsigned &NumIntermediates,
244                                   MVT::ValueType &RegisterVT) const;
245   
246   typedef std::vector<APFloat>::const_iterator legal_fpimm_iterator;
247   legal_fpimm_iterator legal_fpimm_begin() const {
248     return LegalFPImmediates.begin();
249   }
250   legal_fpimm_iterator legal_fpimm_end() const {
251     return LegalFPImmediates.end();
252   }
253   
254   /// isShuffleMaskLegal - Targets can use this to indicate that they only
255   /// support *some* VECTOR_SHUFFLE operations, those with specific masks.
256   /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values
257   /// are assumed to be legal.
258   virtual bool isShuffleMaskLegal(SDOperand Mask, MVT::ValueType VT) const {
259     return true;
260   }
261
262   /// isVectorClearMaskLegal - Similar to isShuffleMaskLegal. This is
263   /// used by Targets can use this to indicate if there is a suitable
264   /// VECTOR_SHUFFLE that can be used to replace a VAND with a constant
265   /// pool entry.
266   virtual bool isVectorClearMaskLegal(std::vector<SDOperand> &BVOps,
267                                       MVT::ValueType EVT,
268                                       SelectionDAG &DAG) const {
269     return false;
270   }
271
272   /// getOperationAction - Return how this operation should be treated: either
273   /// it is legal, needs to be promoted to a larger size, needs to be
274   /// expanded to some other code sequence, or the target has a custom expander
275   /// for it.
276   LegalizeAction getOperationAction(unsigned Op, MVT::ValueType VT) const {
277     if (MVT::isExtendedVT(VT)) return Expand;
278     return (LegalizeAction)((OpActions[Op] >> (2*VT)) & 3);
279   }
280   
281   /// isOperationLegal - Return true if the specified operation is legal on this
282   /// target.
283   bool isOperationLegal(unsigned Op, MVT::ValueType VT) const {
284     return getOperationAction(Op, VT) == Legal ||
285            getOperationAction(Op, VT) == Custom;
286   }
287   
288   /// getLoadXAction - Return how this load with extension should be treated:
289   /// either it is legal, needs to be promoted to a larger size, needs to be
290   /// expanded to some other code sequence, or the target has a custom expander
291   /// for it.
292   LegalizeAction getLoadXAction(unsigned LType, MVT::ValueType VT) const {
293     if (MVT::isExtendedVT(VT)) return getTypeAction(VT);
294     return (LegalizeAction)((LoadXActions[LType] >> (2*VT)) & 3);
295   }
296   
297   /// isLoadXLegal - Return true if the specified load with extension is legal
298   /// on this target.
299   bool isLoadXLegal(unsigned LType, MVT::ValueType VT) const {
300     return getLoadXAction(LType, VT) == Legal ||
301            getLoadXAction(LType, VT) == Custom;
302   }
303   
304   /// getTruncStoreAction - Return how this store with truncation should be
305   /// treated: either it is legal, needs to be promoted to a larger size, needs
306   /// to be expanded to some other code sequence, or the target has a custom
307   /// expander for it.
308   LegalizeAction getTruncStoreAction(MVT::ValueType ValVT, 
309                                      MVT::ValueType MemVT) const {
310     assert(ValVT < array_lengthof(TruncStoreActions) && 
311            MemVT < sizeof(TruncStoreActions[0])*4 && "Table isn't big enough!");
312     return (LegalizeAction)((TruncStoreActions[ValVT] >> (2*MemVT)) & 3);
313   }
314   
315   /// isTruncStoreLegal - Return true if the specified store with truncation is
316   /// legal on this target.
317   bool isTruncStoreLegal(MVT::ValueType ValVT, MVT::ValueType MemVT) const {
318     return getTruncStoreAction(ValVT, MemVT) == Legal ||
319            getTruncStoreAction(ValVT, MemVT) == Custom;
320   }
321
322   /// getIndexedLoadAction - Return how the indexed load should be treated:
323   /// either it is legal, needs to be promoted to a larger size, needs to be
324   /// expanded to some other code sequence, or the target has a custom expander
325   /// for it.
326   LegalizeAction
327   getIndexedLoadAction(unsigned IdxMode, MVT::ValueType VT) const {
328     if (MVT::isExtendedVT(VT)) return getTypeAction(VT);
329     return (LegalizeAction)((IndexedModeActions[0][IdxMode] >> (2*VT)) & 3);
330   }
331
332   /// isIndexedLoadLegal - Return true if the specified indexed load is legal
333   /// on this target.
334   bool isIndexedLoadLegal(unsigned IdxMode, MVT::ValueType VT) const {
335     return getIndexedLoadAction(IdxMode, VT) == Legal ||
336            getIndexedLoadAction(IdxMode, VT) == Custom;
337   }
338   
339   /// getIndexedStoreAction - Return how the indexed store should be treated:
340   /// either it is legal, needs to be promoted to a larger size, needs to be
341   /// expanded to some other code sequence, or the target has a custom expander
342   /// for it.
343   LegalizeAction
344   getIndexedStoreAction(unsigned IdxMode, MVT::ValueType VT) const {
345     if (MVT::isExtendedVT(VT)) return getTypeAction(VT);
346     return (LegalizeAction)((IndexedModeActions[1][IdxMode] >> (2*VT)) & 3);
347   }  
348   
349   /// isIndexedStoreLegal - Return true if the specified indexed load is legal
350   /// on this target.
351   bool isIndexedStoreLegal(unsigned IdxMode, MVT::ValueType VT) const {
352     return getIndexedStoreAction(IdxMode, VT) == Legal ||
353            getIndexedStoreAction(IdxMode, VT) == Custom;
354   }
355   
356   /// getConvertAction - Return how the conversion should be treated:
357   /// either it is legal, needs to be promoted to a larger size, needs to be
358   /// expanded to some other code sequence, or the target has a custom expander
359   /// for it.
360   LegalizeAction
361   getConvertAction(MVT::ValueType FromVT, MVT::ValueType ToVT) const {
362     assert(FromVT < array_lengthof(ConvertActions) && 
363            ToVT < sizeof(ConvertActions[0])*4 && "Table isn't big enough!");
364     return (LegalizeAction)((ConvertActions[FromVT] >> (2*ToVT)) & 3);
365   }
366
367   /// isConvertLegal - Return true if the specified conversion is legal
368   /// on this target.
369   bool isConvertLegal(MVT::ValueType FromVT, MVT::ValueType ToVT) const {
370     return getConvertAction(FromVT, ToVT) == Legal ||
371            getConvertAction(FromVT, ToVT) == Custom;
372   }
373
374   /// getTypeToPromoteTo - If the action for this operation is to promote, this
375   /// method returns the ValueType to promote to.
376   MVT::ValueType getTypeToPromoteTo(unsigned Op, MVT::ValueType VT) const {
377     assert(getOperationAction(Op, VT) == Promote &&
378            "This operation isn't promoted!");
379
380     // See if this has an explicit type specified.
381     std::map<std::pair<unsigned, MVT::ValueType>, 
382              MVT::ValueType>::const_iterator PTTI =
383       PromoteToType.find(std::make_pair(Op, VT));
384     if (PTTI != PromoteToType.end()) return PTTI->second;
385     
386     assert((MVT::isInteger(VT) || MVT::isFloatingPoint(VT)) &&
387            "Cannot autopromote this type, add it with AddPromotedToType.");
388     
389     MVT::ValueType NVT = VT;
390     do {
391       NVT = (MVT::ValueType)(NVT+1);
392       assert(MVT::isInteger(NVT) == MVT::isInteger(VT) && NVT != MVT::isVoid &&
393              "Didn't find type to promote to!");
394     } while (!isTypeLegal(NVT) ||
395               getOperationAction(Op, NVT) == Promote);
396     return NVT;
397   }
398
399   /// getValueType - Return the MVT::ValueType corresponding to this LLVM type.
400   /// This is fixed by the LLVM operations except for the pointer size.  If
401   /// AllowUnknown is true, this will return MVT::Other for types with no MVT
402   /// counterpart (e.g. structs), otherwise it will assert.
403   MVT::ValueType getValueType(const Type *Ty, bool AllowUnknown = false) const {
404     MVT::ValueType VT = MVT::getValueType(Ty, AllowUnknown);
405     return VT == MVT::iPTR ? PointerTy : VT;
406   }
407
408   /// getByValTypeAlignment - Return the desired alignment for ByVal aggregate
409   /// function arguments in the caller parameter area.
410   virtual unsigned getByValTypeAlignment(const Type *Ty) const;
411   
412   /// getRegisterType - Return the type of registers that this ValueType will
413   /// eventually require.
414   MVT::ValueType getRegisterType(MVT::ValueType VT) const {
415     if (!MVT::isExtendedVT(VT))
416       return RegisterTypeForVT[VT];
417     if (MVT::isVector(VT)) {
418       MVT::ValueType VT1, RegisterVT;
419       unsigned NumIntermediates;
420       (void)getVectorTypeBreakdown(VT, VT1, NumIntermediates, RegisterVT);
421       return RegisterVT;
422     }
423     assert(0 && "Unsupported extended type!");
424   }
425
426   /// getNumRegisters - Return the number of registers that this ValueType will
427   /// eventually require.  This is one for any types promoted to live in larger
428   /// registers, but may be more than one for types (like i64) that are split
429   /// into pieces.
430   unsigned getNumRegisters(MVT::ValueType VT) const {
431     if (!MVT::isExtendedVT(VT))
432       return NumRegistersForVT[VT];
433     if (MVT::isVector(VT)) {
434       MVT::ValueType VT1, VT2;
435       unsigned NumIntermediates;
436       return getVectorTypeBreakdown(VT, VT1, NumIntermediates, VT2);
437     }
438     assert(0 && "Unsupported extended type!");
439   }
440
441   /// hasTargetDAGCombine - If true, the target has custom DAG combine
442   /// transformations that it can perform for the specified node.
443   bool hasTargetDAGCombine(ISD::NodeType NT) const {
444     return TargetDAGCombineArray[NT >> 3] & (1 << (NT&7));
445   }
446
447   /// This function returns the maximum number of store operations permitted
448   /// to replace a call to llvm.memset. The value is set by the target at the
449   /// performance threshold for such a replacement.
450   /// @brief Get maximum # of store operations permitted for llvm.memset
451   unsigned getMaxStoresPerMemset() const { return maxStoresPerMemset; }
452
453   /// This function returns the maximum number of store operations permitted
454   /// to replace a call to llvm.memcpy. The value is set by the target at the
455   /// performance threshold for such a replacement.
456   /// @brief Get maximum # of store operations permitted for llvm.memcpy
457   unsigned getMaxStoresPerMemcpy() const { return maxStoresPerMemcpy; }
458
459   /// This function returns the maximum number of store operations permitted
460   /// to replace a call to llvm.memmove. The value is set by the target at the
461   /// performance threshold for such a replacement.
462   /// @brief Get maximum # of store operations permitted for llvm.memmove
463   unsigned getMaxStoresPerMemmove() const { return maxStoresPerMemmove; }
464
465   /// This function returns true if the target allows unaligned memory accesses.
466   /// This is used, for example, in situations where an array copy/move/set is 
467   /// converted to a sequence of store operations. It's use helps to ensure that
468   /// such replacements don't generate code that causes an alignment error 
469   /// (trap) on the target machine. 
470   /// @brief Determine if the target supports unaligned memory accesses.
471   bool allowsUnalignedMemoryAccesses() const {
472     return allowUnalignedMemoryAccesses;
473   }
474   
475   /// usesUnderscoreSetJmp - Determine if we should use _setjmp or setjmp
476   /// to implement llvm.setjmp.
477   bool usesUnderscoreSetJmp() const {
478     return UseUnderscoreSetJmp;
479   }
480
481   /// usesUnderscoreLongJmp - Determine if we should use _longjmp or longjmp
482   /// to implement llvm.longjmp.
483   bool usesUnderscoreLongJmp() const {
484     return UseUnderscoreLongJmp;
485   }
486
487   /// getStackPointerRegisterToSaveRestore - If a physical register, this
488   /// specifies the register that llvm.savestack/llvm.restorestack should save
489   /// and restore.
490   unsigned getStackPointerRegisterToSaveRestore() const {
491     return StackPointerRegisterToSaveRestore;
492   }
493
494   /// getExceptionAddressRegister - If a physical register, this returns
495   /// the register that receives the exception address on entry to a landing
496   /// pad.
497   unsigned getExceptionAddressRegister() const {
498     return ExceptionPointerRegister;
499   }
500
501   /// getExceptionSelectorRegister - If a physical register, this returns
502   /// the register that receives the exception typeid on entry to a landing
503   /// pad.
504   unsigned getExceptionSelectorRegister() const {
505     return ExceptionSelectorRegister;
506   }
507
508   /// getJumpBufSize - returns the target's jmp_buf size in bytes (if never
509   /// set, the default is 200)
510   unsigned getJumpBufSize() const {
511     return JumpBufSize;
512   }
513
514   /// getJumpBufAlignment - returns the target's jmp_buf alignment in bytes
515   /// (if never set, the default is 0)
516   unsigned getJumpBufAlignment() const {
517     return JumpBufAlignment;
518   }
519
520   /// getIfCvtBlockLimit - returns the target specific if-conversion block size
521   /// limit. Any block whose size is greater should not be predicated.
522   virtual unsigned getIfCvtBlockSizeLimit() const {
523     return IfCvtBlockSizeLimit;
524   }
525
526   /// getIfCvtDupBlockLimit - returns the target specific size limit for a
527   /// block to be considered for duplication. Any block whose size is greater
528   /// should not be duplicated to facilitate its predication.
529   virtual unsigned getIfCvtDupBlockSizeLimit() const {
530     return IfCvtDupBlockSizeLimit;
531   }
532
533   /// getPreIndexedAddressParts - returns true by value, base pointer and
534   /// offset pointer and addressing mode by reference if the node's address
535   /// can be legally represented as pre-indexed load / store address.
536   virtual bool getPreIndexedAddressParts(SDNode *N, SDOperand &Base,
537                                          SDOperand &Offset,
538                                          ISD::MemIndexedMode &AM,
539                                          SelectionDAG &DAG) {
540     return false;
541   }
542   
543   /// getPostIndexedAddressParts - returns true by value, base pointer and
544   /// offset pointer and addressing mode by reference if this node can be
545   /// combined with a load / store to form a post-indexed load / store.
546   virtual bool getPostIndexedAddressParts(SDNode *N, SDNode *Op,
547                                           SDOperand &Base, SDOperand &Offset,
548                                           ISD::MemIndexedMode &AM,
549                                           SelectionDAG &DAG) {
550     return false;
551   }
552   
553   /// getPICJumpTableRelocaBase - Returns relocation base for the given PIC
554   /// jumptable.
555   virtual SDOperand getPICJumpTableRelocBase(SDOperand Table,
556                                              SelectionDAG &DAG) const;
557   
558   //===--------------------------------------------------------------------===//
559   // TargetLowering Optimization Methods
560   //
561   
562   /// TargetLoweringOpt - A convenience struct that encapsulates a DAG, and two
563   /// SDOperands for returning information from TargetLowering to its clients
564   /// that want to combine 
565   struct TargetLoweringOpt {
566     SelectionDAG &DAG;
567     bool AfterLegalize;
568     SDOperand Old;
569     SDOperand New;
570
571     explicit TargetLoweringOpt(SelectionDAG &InDAG, bool afterLegalize)
572       : DAG(InDAG), AfterLegalize(afterLegalize) {}
573     
574     bool CombineTo(SDOperand O, SDOperand N) { 
575       Old = O; 
576       New = N; 
577       return true;
578     }
579     
580     /// ShrinkDemandedConstant - Check to see if the specified operand of the 
581     /// specified instruction is a constant integer.  If so, check to see if
582     /// there are any bits set in the constant that are not demanded.  If so,
583     /// shrink the constant and return true.
584     bool ShrinkDemandedConstant(SDOperand Op, uint64_t Demanded);
585   };
586                                                 
587   /// SimplifyDemandedBits - Look at Op.  At this point, we know that only the
588   /// DemandedMask bits of the result of Op are ever used downstream.  If we can
589   /// use this information to simplify Op, create a new simplified DAG node and
590   /// return true, returning the original and new nodes in Old and New. 
591   /// Otherwise, analyze the expression and return a mask of KnownOne and 
592   /// KnownZero bits for the expression (used to simplify the caller).  
593   /// The KnownZero/One bits may only be accurate for those bits in the 
594   /// DemandedMask.
595   bool SimplifyDemandedBits(SDOperand Op, uint64_t DemandedMask, 
596                             uint64_t &KnownZero, uint64_t &KnownOne,
597                             TargetLoweringOpt &TLO, unsigned Depth = 0) const;
598   
599   /// computeMaskedBitsForTargetNode - Determine which of the bits specified in
600   /// Mask are known to be either zero or one and return them in the 
601   /// KnownZero/KnownOne bitsets.
602   virtual void computeMaskedBitsForTargetNode(const SDOperand Op,
603                                               uint64_t Mask,
604                                               uint64_t &KnownZero, 
605                                               uint64_t &KnownOne,
606                                               const SelectionDAG &DAG,
607                                               unsigned Depth = 0) const;
608
609   /// ComputeNumSignBitsForTargetNode - This method can be implemented by
610   /// targets that want to expose additional information about sign bits to the
611   /// DAG Combiner.
612   virtual unsigned ComputeNumSignBitsForTargetNode(SDOperand Op,
613                                                    unsigned Depth = 0) const;
614   
615   struct DAGCombinerInfo {
616     void *DC;  // The DAG Combiner object.
617     bool BeforeLegalize;
618     bool CalledByLegalizer;
619   public:
620     SelectionDAG &DAG;
621     
622     DAGCombinerInfo(SelectionDAG &dag, bool bl, bool cl, void *dc)
623       : DC(dc), BeforeLegalize(bl), CalledByLegalizer(cl), DAG(dag) {}
624     
625     bool isBeforeLegalize() const { return BeforeLegalize; }
626     bool isCalledByLegalizer() const { return CalledByLegalizer; }
627     
628     void AddToWorklist(SDNode *N);
629     SDOperand CombineTo(SDNode *N, const std::vector<SDOperand> &To);
630     SDOperand CombineTo(SDNode *N, SDOperand Res);
631     SDOperand CombineTo(SDNode *N, SDOperand Res0, SDOperand Res1);
632   };
633
634   /// SimplifySetCC - Try to simplify a setcc built with the specified operands 
635   /// and cc. If it is unable to simplify it, return a null SDOperand.
636   SDOperand SimplifySetCC(MVT::ValueType VT, SDOperand N0, SDOperand N1,
637                           ISD::CondCode Cond, bool foldBooleans,
638                           DAGCombinerInfo &DCI) const;
639
640   /// PerformDAGCombine - This method will be invoked for all target nodes and
641   /// for any target-independent nodes that the target has registered with
642   /// invoke it for.
643   ///
644   /// The semantics are as follows:
645   /// Return Value:
646   ///   SDOperand.Val == 0   - No change was made
647   ///   SDOperand.Val == N   - N was replaced, is dead, and is already handled.
648   ///   otherwise            - N should be replaced by the returned Operand.
649   ///
650   /// In addition, methods provided by DAGCombinerInfo may be used to perform
651   /// more complex transformations.
652   ///
653   virtual SDOperand PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
654   
655   //===--------------------------------------------------------------------===//
656   // TargetLowering Configuration Methods - These methods should be invoked by
657   // the derived class constructor to configure this object for the target.
658   //
659
660 protected:
661   /// setUsesGlobalOffsetTable - Specify that this target does or doesn't use a
662   /// GOT for PC-relative code.
663   void setUsesGlobalOffsetTable(bool V) { UsesGlobalOffsetTable = V; }
664
665   /// setShiftAmountType - Describe the type that should be used for shift
666   /// amounts.  This type defaults to the pointer type.
667   void setShiftAmountType(MVT::ValueType VT) { ShiftAmountTy = VT; }
668
669   /// setSetCCResultType - Describe the type that shoudl be used as the result
670   /// of a setcc operation.  This defaults to the pointer type.
671   void setSetCCResultType(MVT::ValueType VT) { SetCCResultTy = VT; }
672
673   /// setSetCCResultContents - Specify how the target extends the result of a
674   /// setcc operation in a register.
675   void setSetCCResultContents(SetCCResultValue Ty) { SetCCResultContents = Ty; }
676
677   /// setSchedulingPreference - Specify the target scheduling preference.
678   void setSchedulingPreference(SchedPreference Pref) {
679     SchedPreferenceInfo = Pref;
680   }
681
682   /// setShiftAmountFlavor - Describe how the target handles out of range shift
683   /// amounts.
684   void setShiftAmountFlavor(OutOfRangeShiftAmount OORSA) {
685     ShiftAmtHandling = OORSA;
686   }
687
688   /// setUseUnderscoreSetJmp - Indicate whether this target prefers to
689   /// use _setjmp to implement llvm.setjmp or the non _ version.
690   /// Defaults to false.
691   void setUseUnderscoreSetJmp(bool Val) {
692     UseUnderscoreSetJmp = Val;
693   }
694
695   /// setUseUnderscoreLongJmp - Indicate whether this target prefers to
696   /// use _longjmp to implement llvm.longjmp or the non _ version.
697   /// Defaults to false.
698   void setUseUnderscoreLongJmp(bool Val) {
699     UseUnderscoreLongJmp = Val;
700   }
701
702   /// setStackPointerRegisterToSaveRestore - If set to a physical register, this
703   /// specifies the register that llvm.savestack/llvm.restorestack should save
704   /// and restore.
705   void setStackPointerRegisterToSaveRestore(unsigned R) {
706     StackPointerRegisterToSaveRestore = R;
707   }
708   
709   /// setExceptionPointerRegister - If set to a physical register, this sets
710   /// the register that receives the exception address on entry to a landing
711   /// pad.
712   void setExceptionPointerRegister(unsigned R) {
713     ExceptionPointerRegister = R;
714   }
715
716   /// setExceptionSelectorRegister - If set to a physical register, this sets
717   /// the register that receives the exception typeid on entry to a landing
718   /// pad.
719   void setExceptionSelectorRegister(unsigned R) {
720     ExceptionSelectorRegister = R;
721   }
722
723   /// SelectIsExpensive - Tells the code generator not to expand operations
724   /// into sequences that use the select operations if possible.
725   void setSelectIsExpensive() { SelectIsExpensive = true; }
726
727   /// setIntDivIsCheap - Tells the code generator that integer divide is
728   /// expensive, and if possible, should be replaced by an alternate sequence
729   /// of instructions not containing an integer divide.
730   void setIntDivIsCheap(bool isCheap = true) { IntDivIsCheap = isCheap; }
731   
732   /// setPow2DivIsCheap - Tells the code generator that it shouldn't generate
733   /// srl/add/sra for a signed divide by power of two, and let the target handle
734   /// it.
735   void setPow2DivIsCheap(bool isCheap = true) { Pow2DivIsCheap = isCheap; }
736   
737   /// addRegisterClass - Add the specified register class as an available
738   /// regclass for the specified value type.  This indicates the selector can
739   /// handle values of that class natively.
740   void addRegisterClass(MVT::ValueType VT, TargetRegisterClass *RC) {
741     assert(!MVT::isExtendedVT(VT));
742     AvailableRegClasses.push_back(std::make_pair(VT, RC));
743     RegClassForVT[VT] = RC;
744   }
745
746   /// computeRegisterProperties - Once all of the register classes are added,
747   /// this allows us to compute derived properties we expose.
748   void computeRegisterProperties();
749
750   /// setOperationAction - Indicate that the specified operation does not work
751   /// with the specified type and indicate what to do about it.
752   void setOperationAction(unsigned Op, MVT::ValueType VT,
753                           LegalizeAction Action) {
754     assert(VT < sizeof(OpActions[0])*4 && Op < array_lengthof(OpActions) &&
755            "Table isn't big enough!");
756     OpActions[Op] &= ~(uint64_t(3UL) << VT*2);
757     OpActions[Op] |= (uint64_t)Action << VT*2;
758   }
759   
760   /// setLoadXAction - Indicate that the specified load with extension does not
761   /// work with the with specified type and indicate what to do about it.
762   void setLoadXAction(unsigned ExtType, MVT::ValueType VT,
763                       LegalizeAction Action) {
764     assert(VT < sizeof(LoadXActions[0])*4 && 
765            ExtType < array_lengthof(LoadXActions) &&
766            "Table isn't big enough!");
767     LoadXActions[ExtType] &= ~(uint64_t(3UL) << VT*2);
768     LoadXActions[ExtType] |= (uint64_t)Action << VT*2;
769   }
770   
771   /// setTruncStoreAction - Indicate that the specified truncating store does
772   /// not work with the with specified type and indicate what to do about it.
773   void setTruncStoreAction(MVT::ValueType ValVT, MVT::ValueType MemVT,
774                            LegalizeAction Action) {
775     assert(ValVT < array_lengthof(TruncStoreActions) && 
776            MemVT < sizeof(TruncStoreActions[0])*4 && "Table isn't big enough!");
777     TruncStoreActions[ValVT] &= ~(uint64_t(3UL) << MemVT*2);
778     TruncStoreActions[ValVT] |= (uint64_t)Action << MemVT*2;
779   }
780
781   /// setIndexedLoadAction - Indicate that the specified indexed load does or
782   /// does not work with the with specified type and indicate what to do abort
783   /// it. NOTE: All indexed mode loads are initialized to Expand in
784   /// TargetLowering.cpp
785   void setIndexedLoadAction(unsigned IdxMode, MVT::ValueType VT,
786                             LegalizeAction Action) {
787     assert(VT < sizeof(IndexedModeActions[0])*4 && IdxMode <
788            array_lengthof(IndexedModeActions[0]) &&
789            "Table isn't big enough!");
790     IndexedModeActions[0][IdxMode] &= ~(uint64_t(3UL) << VT*2);
791     IndexedModeActions[0][IdxMode] |= (uint64_t)Action << VT*2;
792   }
793   
794   /// setIndexedStoreAction - Indicate that the specified indexed store does or
795   /// does not work with the with specified type and indicate what to do about
796   /// it. NOTE: All indexed mode stores are initialized to Expand in
797   /// TargetLowering.cpp
798   void setIndexedStoreAction(unsigned IdxMode, MVT::ValueType VT,
799                              LegalizeAction Action) {
800     assert(VT < sizeof(IndexedModeActions[1][0])*4 &&
801            IdxMode < array_lengthof(IndexedModeActions[1]) &&
802            "Table isn't big enough!");
803     IndexedModeActions[1][IdxMode] &= ~(uint64_t(3UL) << VT*2);
804     IndexedModeActions[1][IdxMode] |= (uint64_t)Action << VT*2;
805   }
806   
807   /// setConvertAction - Indicate that the specified conversion does or does
808   /// not work with the with specified type and indicate what to do about it.
809   void setConvertAction(MVT::ValueType FromVT, MVT::ValueType ToVT, 
810                         LegalizeAction Action) {
811     assert(FromVT < array_lengthof(ConvertActions) &&
812            ToVT < sizeof(ConvertActions[0])*4 && "Table isn't big enough!");
813     ConvertActions[FromVT] &= ~(uint64_t(3UL) << ToVT*2);
814     ConvertActions[FromVT] |= (uint64_t)Action << ToVT*2;
815   }
816
817   /// AddPromotedToType - If Opc/OrigVT is specified as being promoted, the
818   /// promotion code defaults to trying a larger integer/fp until it can find
819   /// one that works.  If that default is insufficient, this method can be used
820   /// by the target to override the default.
821   void AddPromotedToType(unsigned Opc, MVT::ValueType OrigVT, 
822                          MVT::ValueType DestVT) {
823     PromoteToType[std::make_pair(Opc, OrigVT)] = DestVT;
824   }
825
826   /// addLegalFPImmediate - Indicate that this target can instruction select
827   /// the specified FP immediate natively.
828   void addLegalFPImmediate(const APFloat& Imm) {
829     LegalFPImmediates.push_back(Imm);
830   }
831
832   /// setTargetDAGCombine - Targets should invoke this method for each target
833   /// independent node that they want to provide a custom DAG combiner for by
834   /// implementing the PerformDAGCombine virtual method.
835   void setTargetDAGCombine(ISD::NodeType NT) {
836     TargetDAGCombineArray[NT >> 3] |= 1 << (NT&7);
837   }
838   
839   /// setJumpBufSize - Set the target's required jmp_buf buffer size (in
840   /// bytes); default is 200
841   void setJumpBufSize(unsigned Size) {
842     JumpBufSize = Size;
843   }
844
845   /// setJumpBufAlignment - Set the target's required jmp_buf buffer
846   /// alignment (in bytes); default is 0
847   void setJumpBufAlignment(unsigned Align) {
848     JumpBufAlignment = Align;
849   }
850
851   /// setIfCvtBlockSizeLimit - Set the target's if-conversion block size
852   /// limit (in number of instructions); default is 2.
853   void setIfCvtBlockSizeLimit(unsigned Limit) {
854     IfCvtBlockSizeLimit = Limit;
855   }
856   
857   /// setIfCvtDupBlockSizeLimit - Set the target's block size limit (in number
858   /// of instructions) to be considered for code duplication during
859   /// if-conversion; default is 2.
860   void setIfCvtDupBlockSizeLimit(unsigned Limit) {
861     IfCvtDupBlockSizeLimit = Limit;
862   }
863   
864 public:
865
866   virtual const TargetSubtarget *getSubtarget() {
867     assert(0 && "Not Implemented");
868     return NULL;    // this is here to silence compiler errors
869   }
870   //===--------------------------------------------------------------------===//
871   // Lowering methods - These methods must be implemented by targets so that
872   // the SelectionDAGLowering code knows how to lower these.
873   //
874
875   /// LowerArguments - This hook must be implemented to indicate how we should
876   /// lower the arguments for the specified function, into the specified DAG.
877   virtual std::vector<SDOperand>
878   LowerArguments(Function &F, SelectionDAG &DAG);
879
880   /// LowerCallTo - This hook lowers an abstract call to a function into an
881   /// actual call.  This returns a pair of operands.  The first element is the
882   /// return value for the function (if RetTy is not VoidTy).  The second
883   /// element is the outgoing token chain.
884   struct ArgListEntry {
885     SDOperand Node;
886     const Type* Ty;
887     bool isSExt;
888     bool isZExt;
889     bool isInReg;
890     bool isSRet;
891     bool isNest;
892     bool isByVal;
893
894     ArgListEntry() : isSExt(false), isZExt(false), isInReg(false),
895       isSRet(false), isNest(false), isByVal(false) { }
896   };
897   typedef std::vector<ArgListEntry> ArgListTy;
898   virtual std::pair<SDOperand, SDOperand>
899   LowerCallTo(SDOperand Chain, const Type *RetTy, bool RetTyIsSigned, 
900               bool isVarArg, unsigned CallingConv, bool isTailCall, 
901               SDOperand Callee, ArgListTy &Args, SelectionDAG &DAG);
902
903
904   virtual SDOperand LowerMEMCPY(SDOperand Op, SelectionDAG &DAG);
905   virtual SDOperand LowerMEMCPYCall(SDOperand Chain, SDOperand Dest,
906                                     SDOperand Source, SDOperand Count,
907                                     SelectionDAG &DAG);
908   virtual SDOperand LowerMEMCPYInline(SDOperand Chain, SDOperand Dest,
909                                       SDOperand Source, unsigned Size,
910                                       unsigned Align, SelectionDAG &DAG) {
911     assert(0 && "Not Implemented");
912     return SDOperand();   // this is here to silence compiler errors
913   }
914
915
916   /// LowerOperation - This callback is invoked for operations that are 
917   /// unsupported by the target, which are registered to use 'custom' lowering,
918   /// and whose defined values are all legal.
919   /// If the target has no operations that require custom lowering, it need not
920   /// implement this.  The default implementation of this aborts.
921   virtual SDOperand LowerOperation(SDOperand Op, SelectionDAG &DAG);
922
923   /// ExpandOperationResult - This callback is invoked for operations that are 
924   /// unsupported by the target, which are registered to use 'custom' lowering,
925   /// and whose result type needs to be expanded.  This must return a node whose
926   /// results precisely match the results of the input node.  This typically
927   /// involves a MERGE_VALUES node and/or BUILD_PAIR.
928   ///
929   /// If the target has no operations that require custom lowering, it need not
930   /// implement this.  The default implementation of this aborts.
931   virtual SDNode *ExpandOperationResult(SDNode *N, SelectionDAG &DAG) {
932     assert(0 && "ExpandOperationResult not implemented for this target!");
933     return 0;
934   }
935   
936   /// IsEligibleForTailCallOptimization - Check whether the call is eligible for
937   /// tail call optimization. Targets which want to do tail call optimization
938   /// should override this function. 
939   virtual bool IsEligibleForTailCallOptimization(SDOperand Call, 
940                                                  SDOperand Ret, 
941                                                  SelectionDAG &DAG) const {
942     return false;
943   }
944
945   /// CustomPromoteOperation - This callback is invoked for operations that are
946   /// unsupported by the target, are registered to use 'custom' lowering, and
947   /// whose type needs to be promoted.
948   virtual SDOperand CustomPromoteOperation(SDOperand Op, SelectionDAG &DAG);
949   
950   /// getTargetNodeName() - This method returns the name of a target specific
951   /// DAG node.
952   virtual const char *getTargetNodeName(unsigned Opcode) const;
953
954   //===--------------------------------------------------------------------===//
955   // Inline Asm Support hooks
956   //
957   
958   enum ConstraintType {
959     C_Register,            // Constraint represents a single register.
960     C_RegisterClass,       // Constraint represents one or more registers.
961     C_Memory,              // Memory constraint.
962     C_Other,               // Something else.
963     C_Unknown              // Unsupported constraint.
964   };
965   
966   /// getConstraintType - Given a constraint, return the type of constraint it
967   /// is for this target.
968   virtual ConstraintType getConstraintType(const std::string &Constraint) const;
969   
970   
971   /// getRegClassForInlineAsmConstraint - Given a constraint letter (e.g. "r"),
972   /// return a list of registers that can be used to satisfy the constraint.
973   /// This should only be used for C_RegisterClass constraints.
974   virtual std::vector<unsigned> 
975   getRegClassForInlineAsmConstraint(const std::string &Constraint,
976                                     MVT::ValueType VT) const;
977
978   /// getRegForInlineAsmConstraint - Given a physical register constraint (e.g.
979   /// {edx}), return the register number and the register class for the
980   /// register.
981   ///
982   /// Given a register class constraint, like 'r', if this corresponds directly
983   /// to an LLVM register class, return a register of 0 and the register class
984   /// pointer.
985   ///
986   /// This should only be used for C_Register constraints.  On error,
987   /// this returns a register number of 0 and a null register class pointer..
988   virtual std::pair<unsigned, const TargetRegisterClass*> 
989     getRegForInlineAsmConstraint(const std::string &Constraint,
990                                  MVT::ValueType VT) const;
991   
992   
993   /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
994   /// vector.  If it is invalid, don't add anything to Ops.
995   virtual void LowerAsmOperandForConstraint(SDOperand Op, char ConstraintLetter,
996                                             std::vector<SDOperand> &Ops,
997                                             SelectionDAG &DAG);
998   
999   //===--------------------------------------------------------------------===//
1000   // Scheduler hooks
1001   //
1002   
1003   // InsertAtEndOfBasicBlock - This method should be implemented by targets that
1004   // mark instructions with the 'usesCustomDAGSchedInserter' flag.  These
1005   // instructions are special in various ways, which require special support to
1006   // insert.  The specified MachineInstr is created but not inserted into any
1007   // basic blocks, and the scheduler passes ownership of it to this method.
1008   virtual MachineBasicBlock *InsertAtEndOfBasicBlock(MachineInstr *MI,
1009                                                      MachineBasicBlock *MBB);
1010
1011   //===--------------------------------------------------------------------===//
1012   // Addressing mode description hooks (used by LSR etc).
1013   //
1014
1015   /// AddrMode - This represents an addressing mode of:
1016   ///    BaseGV + BaseOffs + BaseReg + Scale*ScaleReg
1017   /// If BaseGV is null,  there is no BaseGV.
1018   /// If BaseOffs is zero, there is no base offset.
1019   /// If HasBaseReg is false, there is no base register.
1020   /// If Scale is zero, there is no ScaleReg.  Scale of 1 indicates a reg with
1021   /// no scale.
1022   ///
1023   struct AddrMode {
1024     GlobalValue *BaseGV;
1025     int64_t      BaseOffs;
1026     bool         HasBaseReg;
1027     int64_t      Scale;
1028     AddrMode() : BaseGV(0), BaseOffs(0), HasBaseReg(false), Scale(0) {}
1029   };
1030   
1031   /// isLegalAddressingMode - Return true if the addressing mode represented by
1032   /// AM is legal for this target, for a load/store of the specified type.
1033   /// TODO: Handle pre/postinc as well.
1034   virtual bool isLegalAddressingMode(const AddrMode &AM, const Type *Ty) const;
1035
1036   /// isTruncateFree - Return true if it's free to truncate a value of
1037   /// type Ty1 to type Ty2. e.g. On x86 it's free to truncate a i32 value in
1038   /// register EAX to i16 by referencing its sub-register AX.
1039   virtual bool isTruncateFree(const Type *Ty1, const Type *Ty2) const {
1040     return false;
1041   }
1042
1043   virtual bool isTruncateFree(MVT::ValueType VT1, MVT::ValueType VT2) const {
1044     return false;
1045   }
1046   
1047   //===--------------------------------------------------------------------===//
1048   // Div utility functions
1049   //
1050   SDOperand BuildSDIV(SDNode *N, SelectionDAG &DAG, 
1051                       std::vector<SDNode*>* Created) const;
1052   SDOperand BuildUDIV(SDNode *N, SelectionDAG &DAG, 
1053                       std::vector<SDNode*>* Created) const;
1054
1055
1056   //===--------------------------------------------------------------------===//
1057   // Runtime Library hooks
1058   //
1059
1060   /// setLibcallName - Rename the default libcall routine name for the specified
1061   /// libcall.
1062   void setLibcallName(RTLIB::Libcall Call, const char *Name) {
1063     LibcallRoutineNames[Call] = Name;
1064   }
1065
1066   /// getLibcallName - Get the libcall routine name for the specified libcall.
1067   ///
1068   const char *getLibcallName(RTLIB::Libcall Call) const {
1069     return LibcallRoutineNames[Call];
1070   }
1071
1072   /// setCmpLibcallCC - Override the default CondCode to be used to test the
1073   /// result of the comparison libcall against zero.
1074   void setCmpLibcallCC(RTLIB::Libcall Call, ISD::CondCode CC) {
1075     CmpLibcallCCs[Call] = CC;
1076   }
1077
1078   /// getCmpLibcallCC - Get the CondCode that's to be used to test the result of
1079   /// the comparison libcall against zero.
1080   ISD::CondCode getCmpLibcallCC(RTLIB::Libcall Call) const {
1081     return CmpLibcallCCs[Call];
1082   }
1083
1084 private:
1085   TargetMachine &TM;
1086   const TargetData *TD;
1087
1088   /// IsLittleEndian - True if this is a little endian target.
1089   ///
1090   bool IsLittleEndian;
1091
1092   /// PointerTy - The type to use for pointers, usually i32 or i64.
1093   ///
1094   MVT::ValueType PointerTy;
1095
1096   /// UsesGlobalOffsetTable - True if this target uses a GOT for PIC codegen.
1097   ///
1098   bool UsesGlobalOffsetTable;
1099   
1100   /// ShiftAmountTy - The type to use for shift amounts, usually i8 or whatever
1101   /// PointerTy is.
1102   MVT::ValueType ShiftAmountTy;
1103
1104   OutOfRangeShiftAmount ShiftAmtHandling;
1105
1106   /// SelectIsExpensive - Tells the code generator not to expand operations
1107   /// into sequences that use the select operations if possible.
1108   bool SelectIsExpensive;
1109
1110   /// IntDivIsCheap - Tells the code generator not to expand integer divides by
1111   /// constants into a sequence of muls, adds, and shifts.  This is a hack until
1112   /// a real cost model is in place.  If we ever optimize for size, this will be
1113   /// set to true unconditionally.
1114   bool IntDivIsCheap;
1115   
1116   /// Pow2DivIsCheap - Tells the code generator that it shouldn't generate
1117   /// srl/add/sra for a signed divide by power of two, and let the target handle
1118   /// it.
1119   bool Pow2DivIsCheap;
1120   
1121   /// SetCCResultTy - The type that SetCC operations use.  This defaults to the
1122   /// PointerTy.
1123   MVT::ValueType SetCCResultTy;
1124
1125   /// SetCCResultContents - Information about the contents of the high-bits in
1126   /// the result of a setcc comparison operation.
1127   SetCCResultValue SetCCResultContents;
1128
1129   /// SchedPreferenceInfo - The target scheduling preference: shortest possible
1130   /// total cycles or lowest register usage.
1131   SchedPreference SchedPreferenceInfo;
1132   
1133   /// UseUnderscoreSetJmp - This target prefers to use _setjmp to implement
1134   /// llvm.setjmp.  Defaults to false.
1135   bool UseUnderscoreSetJmp;
1136
1137   /// UseUnderscoreLongJmp - This target prefers to use _longjmp to implement
1138   /// llvm.longjmp.  Defaults to false.
1139   bool UseUnderscoreLongJmp;
1140
1141   /// JumpBufSize - The size, in bytes, of the target's jmp_buf buffers
1142   unsigned JumpBufSize;
1143   
1144   /// JumpBufAlignment - The alignment, in bytes, of the target's jmp_buf
1145   /// buffers
1146   unsigned JumpBufAlignment;
1147
1148   /// IfCvtBlockSizeLimit - The maximum allowed size for a block to be
1149   /// if-converted.
1150   unsigned IfCvtBlockSizeLimit;
1151   
1152   /// IfCvtDupBlockSizeLimit - The maximum allowed size for a block to be
1153   /// duplicated during if-conversion.
1154   unsigned IfCvtDupBlockSizeLimit;
1155
1156   /// StackPointerRegisterToSaveRestore - If set to a physical register, this
1157   /// specifies the register that llvm.savestack/llvm.restorestack should save
1158   /// and restore.
1159   unsigned StackPointerRegisterToSaveRestore;
1160
1161   /// ExceptionPointerRegister - If set to a physical register, this specifies
1162   /// the register that receives the exception address on entry to a landing
1163   /// pad.
1164   unsigned ExceptionPointerRegister;
1165
1166   /// ExceptionSelectorRegister - If set to a physical register, this specifies
1167   /// the register that receives the exception typeid on entry to a landing
1168   /// pad.
1169   unsigned ExceptionSelectorRegister;
1170
1171   /// RegClassForVT - This indicates the default register class to use for
1172   /// each ValueType the target supports natively.
1173   TargetRegisterClass *RegClassForVT[MVT::LAST_VALUETYPE];
1174   unsigned char NumRegistersForVT[MVT::LAST_VALUETYPE];
1175   MVT::ValueType RegisterTypeForVT[MVT::LAST_VALUETYPE];
1176
1177   /// TransformToType - For any value types we are promoting or expanding, this
1178   /// contains the value type that we are changing to.  For Expanded types, this
1179   /// contains one step of the expand (e.g. i64 -> i32), even if there are
1180   /// multiple steps required (e.g. i64 -> i16).  For types natively supported
1181   /// by the system, this holds the same type (e.g. i32 -> i32).
1182   MVT::ValueType TransformToType[MVT::LAST_VALUETYPE];
1183
1184   /// OpActions - For each operation and each value type, keep a LegalizeAction
1185   /// that indicates how instruction selection should deal with the operation.
1186   /// Most operations are Legal (aka, supported natively by the target), but
1187   /// operations that are not should be described.  Note that operations on
1188   /// non-legal value types are not described here.
1189   uint64_t OpActions[156];
1190   
1191   /// LoadXActions - For each load of load extension type and each value type,
1192   /// keep a LegalizeAction that indicates how instruction selection should deal
1193   /// with the load.
1194   uint64_t LoadXActions[ISD::LAST_LOADX_TYPE];
1195   
1196   /// TruncStoreActions - For each truncating store, keep a LegalizeAction that
1197   /// indicates how instruction selection should deal with the store.
1198   uint64_t TruncStoreActions[MVT::LAST_VALUETYPE];
1199
1200   /// IndexedModeActions - For each indexed mode and each value type, keep a
1201   /// pair of LegalizeAction that indicates how instruction selection should
1202   /// deal with the load / store.
1203   uint64_t IndexedModeActions[2][ISD::LAST_INDEXED_MODE];
1204   
1205   /// ConvertActions - For each conversion from source type to destination type,
1206   /// keep a LegalizeAction that indicates how instruction selection should
1207   /// deal with the conversion.
1208   /// Currently, this is used only for floating->floating conversions
1209   /// (FP_EXTEND and FP_ROUND).
1210   uint64_t ConvertActions[MVT::LAST_VALUETYPE];
1211
1212   ValueTypeActionImpl ValueTypeActions;
1213
1214   std::vector<APFloat> LegalFPImmediates;
1215
1216   std::vector<std::pair<MVT::ValueType,
1217                         TargetRegisterClass*> > AvailableRegClasses;
1218
1219   /// TargetDAGCombineArray - Targets can specify ISD nodes that they would
1220   /// like PerformDAGCombine callbacks for by calling setTargetDAGCombine(),
1221   /// which sets a bit in this array.
1222   unsigned char TargetDAGCombineArray[156/(sizeof(unsigned char)*8)];
1223   
1224   /// PromoteToType - For operations that must be promoted to a specific type,
1225   /// this holds the destination type.  This map should be sparse, so don't hold
1226   /// it as an array.
1227   ///
1228   /// Targets add entries to this map with AddPromotedToType(..), clients access
1229   /// this with getTypeToPromoteTo(..).
1230   std::map<std::pair<unsigned, MVT::ValueType>, MVT::ValueType> PromoteToType;
1231
1232   /// LibcallRoutineNames - Stores the name each libcall.
1233   ///
1234   const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL];
1235
1236   /// CmpLibcallCCs - The ISD::CondCode that should be used to test the result
1237   /// of each of the comparison libcall against zero.
1238   ISD::CondCode CmpLibcallCCs[RTLIB::UNKNOWN_LIBCALL];
1239
1240 protected:
1241   /// When lowering %llvm.memset this field specifies the maximum number of
1242   /// store operations that may be substituted for the call to memset. Targets
1243   /// must set this value based on the cost threshold for that target. Targets
1244   /// should assume that the memset will be done using as many of the largest
1245   /// store operations first, followed by smaller ones, if necessary, per
1246   /// alignment restrictions. For example, storing 9 bytes on a 32-bit machine
1247   /// with 16-bit alignment would result in four 2-byte stores and one 1-byte
1248   /// store.  This only applies to setting a constant array of a constant size.
1249   /// @brief Specify maximum number of store instructions per memset call.
1250   unsigned maxStoresPerMemset;
1251
1252   /// When lowering %llvm.memcpy this field specifies the maximum number of
1253   /// store operations that may be substituted for a call to memcpy. Targets
1254   /// must set this value based on the cost threshold for that target. Targets
1255   /// should assume that the memcpy will be done using as many of the largest
1256   /// store operations first, followed by smaller ones, if necessary, per
1257   /// alignment restrictions. For example, storing 7 bytes on a 32-bit machine
1258   /// with 32-bit alignment would result in one 4-byte store, a one 2-byte store
1259   /// and one 1-byte store. This only applies to copying a constant array of
1260   /// constant size.
1261   /// @brief Specify maximum bytes of store instructions per memcpy call.
1262   unsigned maxStoresPerMemcpy;
1263
1264   /// When lowering %llvm.memmove this field specifies the maximum number of
1265   /// store instructions that may be substituted for a call to memmove. Targets
1266   /// must set this value based on the cost threshold for that target. Targets
1267   /// should assume that the memmove will be done using as many of the largest
1268   /// store operations first, followed by smaller ones, if necessary, per
1269   /// alignment restrictions. For example, moving 9 bytes on a 32-bit machine
1270   /// with 8-bit alignment would result in nine 1-byte stores.  This only
1271   /// applies to copying a constant array of constant size.
1272   /// @brief Specify maximum bytes of store instructions per memmove call.
1273   unsigned maxStoresPerMemmove;
1274
1275   /// This field specifies whether the target machine permits unaligned memory
1276   /// accesses.  This is used, for example, to determine the size of store 
1277   /// operations when copying small arrays and other similar tasks.
1278   /// @brief Indicate whether the target permits unaligned memory accesses.
1279   bool allowUnalignedMemoryAccesses;
1280 };
1281 } // end llvm namespace
1282
1283 #endif