1 //===-- llvm/Target/TargetLowering.h - Target Lowering Info -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes how to lower LLVM code to machine code. This has two
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.
17 // In addition it has a few other components, like information about FP
20 //===----------------------------------------------------------------------===//
22 #ifndef LLVM_TARGET_TARGETLOWERING_H
23 #define LLVM_TARGET_TARGETLOWERING_H
25 #include "llvm/Constants.h"
26 #include "llvm/InlineAsm.h"
27 #include "llvm/CodeGen/SelectionDAGNodes.h"
28 #include "llvm/CodeGen/RuntimeLibcalls.h"
29 #include "llvm/ADT/APFloat.h"
30 #include "llvm/ADT/DenseMap.h"
31 #include "llvm/ADT/SmallSet.h"
32 #include "llvm/ADT/STLExtras.h"
40 class MachineBasicBlock;
41 class MachineFunction;
42 class MachineFrameInfo;
44 class MachineModuleInfo;
50 class TargetRegisterClass;
51 class TargetSubtarget;
55 //===----------------------------------------------------------------------===//
56 /// TargetLowering - This class defines information used to lower LLVM code to
57 /// legal SelectionDAG operators that the target instruction selector can accept
60 /// This class also defines callbacks that targets must implement to lower
61 /// target-specific constructs to SelectionDAG operators.
63 class TargetLowering {
65 /// LegalizeAction - This enum indicates whether operations are valid for a
66 /// target, and if not, what action should be used to make them valid.
68 Legal, // The target natively supports this operation.
69 Promote, // This operation should be executed in a larger type.
70 Expand, // Try to expand this to other ops, otherwise use a libcall.
71 Custom // Use the LowerOperation hook to implement custom lowering.
74 enum OutOfRangeShiftAmount {
75 Undefined, // Oversized shift amounts are undefined (default).
76 Mask, // Shift amounts are auto masked (anded) to value size.
77 Extend // Oversized shift pulls in zeros or sign bits.
80 enum SetCCResultValue {
81 UndefinedSetCCResult, // SetCC returns a garbage/unknown extend.
82 ZeroOrOneSetCCResult, // SetCC returns a zero extended result.
83 ZeroOrNegativeOneSetCCResult // SetCC returns a sign extended result.
86 enum SchedPreference {
87 SchedulingForLatency, // Scheduling for shortest total latency.
88 SchedulingForRegPressure // Scheduling for lowest register pressure.
91 explicit TargetLowering(TargetMachine &TM);
92 virtual ~TargetLowering();
94 TargetMachine &getTargetMachine() const { return TM; }
95 const TargetData *getTargetData() const { return TD; }
97 bool isBigEndian() const { return !IsLittleEndian; }
98 bool isLittleEndian() const { return IsLittleEndian; }
99 MVT getPointerTy() const { return PointerTy; }
100 MVT getShiftAmountTy() const { return ShiftAmountTy; }
101 OutOfRangeShiftAmount getShiftAmountFlavor() const {return ShiftAmtHandling; }
103 /// usesGlobalOffsetTable - Return true if this target uses a GOT for PIC
105 bool usesGlobalOffsetTable() const { return UsesGlobalOffsetTable; }
107 /// isSelectExpensive - Return true if the select operation is expensive for
109 bool isSelectExpensive() const { return SelectIsExpensive; }
111 /// isIntDivCheap() - Return true if integer divide is usually cheaper than
112 /// a sequence of several shifts, adds, and multiplies for this target.
113 bool isIntDivCheap() const { return IntDivIsCheap; }
115 /// isPow2DivCheap() - Return true if pow2 div is cheaper than a chain of
117 bool isPow2DivCheap() const { return Pow2DivIsCheap; }
119 /// getSetCCResultType - Return the ValueType of the result of setcc
121 virtual MVT getSetCCResultType(const SDValue &) const;
123 /// getSetCCResultContents - For targets without boolean registers, this flag
124 /// returns information about the contents of the high-bits in the setcc
126 SetCCResultValue getSetCCResultContents() const { return SetCCResultContents;}
128 /// getSchedulingPreference - Return target scheduling preference.
129 SchedPreference getSchedulingPreference() const {
130 return SchedPreferenceInfo;
133 /// getRegClassFor - Return the register class that should be used for the
134 /// specified value type. This may only be called on legal types.
135 TargetRegisterClass *getRegClassFor(MVT VT) const {
136 assert((unsigned)VT.getSimpleVT() < array_lengthof(RegClassForVT));
137 TargetRegisterClass *RC = RegClassForVT[VT.getSimpleVT()];
138 assert(RC && "This value type is not natively supported!");
142 /// isTypeLegal - Return true if the target has native support for the
143 /// specified value type. This means that it has a register that directly
144 /// holds it without promotions or expansions.
145 bool isTypeLegal(MVT VT) const {
146 assert(!VT.isSimple() ||
147 (unsigned)VT.getSimpleVT() < array_lengthof(RegClassForVT));
148 return VT.isSimple() && RegClassForVT[VT.getSimpleVT()] != 0;
151 class ValueTypeActionImpl {
152 /// ValueTypeActions - This is a bitvector that contains two bits for each
153 /// value type, where the two bits correspond to the LegalizeAction enum.
154 /// This can be queried with "getTypeAction(VT)".
155 uint32_t ValueTypeActions[2];
157 ValueTypeActionImpl() {
158 ValueTypeActions[0] = ValueTypeActions[1] = 0;
160 ValueTypeActionImpl(const ValueTypeActionImpl &RHS) {
161 ValueTypeActions[0] = RHS.ValueTypeActions[0];
162 ValueTypeActions[1] = RHS.ValueTypeActions[1];
165 LegalizeAction getTypeAction(MVT VT) const {
166 if (VT.isExtended()) {
167 if (VT.isVector()) return Expand;
169 // First promote to a power-of-two size, then expand if necessary.
170 return VT == VT.getRoundIntegerType() ? Expand : Promote;
171 assert(0 && "Unsupported extended type!");
174 unsigned I = VT.getSimpleVT();
175 assert(I<4*array_lengthof(ValueTypeActions)*sizeof(ValueTypeActions[0]));
176 return (LegalizeAction)((ValueTypeActions[I>>4] >> ((2*I) & 31)) & 3);
178 void setTypeAction(MVT VT, LegalizeAction Action) {
179 unsigned I = VT.getSimpleVT();
180 assert(I<4*array_lengthof(ValueTypeActions)*sizeof(ValueTypeActions[0]));
181 ValueTypeActions[I>>4] |= Action << ((I*2) & 31);
185 const ValueTypeActionImpl &getValueTypeActions() const {
186 return ValueTypeActions;
189 /// getTypeAction - Return how we should legalize values of this type, either
190 /// it is already legal (return 'Legal') or we need to promote it to a larger
191 /// type (return 'Promote'), or we need to expand it into multiple registers
192 /// of smaller integer type (return 'Expand'). 'Custom' is not an option.
193 LegalizeAction getTypeAction(MVT VT) const {
194 return ValueTypeActions.getTypeAction(VT);
197 /// getTypeToTransformTo - For types supported by the target, this is an
198 /// identity function. For types that must be promoted to larger types, this
199 /// returns the larger type to promote to. For integer types that are larger
200 /// than the largest integer register, this contains one step in the expansion
201 /// to get to the smaller register. For illegal floating point types, this
202 /// returns the integer type to transform to.
203 MVT getTypeToTransformTo(MVT VT) const {
205 assert((unsigned)VT.getSimpleVT() < array_lengthof(TransformToType));
206 MVT NVT = TransformToType[VT.getSimpleVT()];
207 assert(getTypeAction(NVT) != Promote &&
208 "Promote may not follow Expand or Promote");
213 return MVT::getVectorVT(VT.getVectorElementType(),
214 VT.getVectorNumElements() / 2);
215 if (VT.isInteger()) {
216 MVT NVT = VT.getRoundIntegerType();
218 // Size is a power of two - expand to half the size.
219 return MVT::getIntegerVT(VT.getSizeInBits() / 2);
221 // Promote to a power of two size, avoiding multi-step promotion.
222 return getTypeAction(NVT) == Promote ? getTypeToTransformTo(NVT) : NVT;
224 assert(0 && "Unsupported extended type!");
225 return MVT(); // Not reached
228 /// getTypeToExpandTo - For types supported by the target, this is an
229 /// identity function. For types that must be expanded (i.e. integer types
230 /// that are larger than the largest integer register or illegal floating
231 /// point types), this returns the largest legal type it will be expanded to.
232 MVT getTypeToExpandTo(MVT VT) const {
233 assert(!VT.isVector());
235 switch (getTypeAction(VT)) {
239 VT = getTypeToTransformTo(VT);
242 assert(false && "Type is not legal nor is it to be expanded!");
249 /// getVectorTypeBreakdown - Vector types are broken down into some number of
250 /// legal first class types. For example, MVT::v8f32 maps to 2 MVT::v4f32
251 /// with Altivec or SSE1, or 8 promoted MVT::f64 values with the X86 FP stack.
252 /// Similarly, MVT::v2i64 turns into 4 MVT::i32 values with both PPC and X86.
254 /// This method returns the number of registers needed, and the VT for each
255 /// register. It also returns the VT and quantity of the intermediate values
256 /// before they are promoted/expanded.
258 unsigned getVectorTypeBreakdown(MVT VT,
260 unsigned &NumIntermediates,
261 MVT &RegisterVT) const;
263 typedef std::vector<APFloat>::const_iterator legal_fpimm_iterator;
264 legal_fpimm_iterator legal_fpimm_begin() const {
265 return LegalFPImmediates.begin();
267 legal_fpimm_iterator legal_fpimm_end() const {
268 return LegalFPImmediates.end();
271 /// isShuffleMaskLegal - Targets can use this to indicate that they only
272 /// support *some* VECTOR_SHUFFLE operations, those with specific masks.
273 /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values
274 /// are assumed to be legal.
275 virtual bool isShuffleMaskLegal(SDValue Mask, MVT VT) const {
279 /// isVectorClearMaskLegal - Similar to isShuffleMaskLegal. This is
280 /// used by Targets can use this to indicate if there is a suitable
281 /// VECTOR_SHUFFLE that can be used to replace a VAND with a constant
283 virtual bool isVectorClearMaskLegal(const std::vector<SDValue> &BVOps,
285 SelectionDAG &DAG) const {
289 /// getOperationAction - Return how this operation should be treated: either
290 /// it is legal, needs to be promoted to a larger size, needs to be
291 /// expanded to some other code sequence, or the target has a custom expander
293 LegalizeAction getOperationAction(unsigned Op, MVT VT) const {
294 if (VT.isExtended()) return Expand;
295 assert(Op < array_lengthof(OpActions) &&
296 (unsigned)VT.getSimpleVT() < sizeof(OpActions[0])*4 &&
297 "Table isn't big enough!");
298 return (LegalizeAction)((OpActions[Op] >> (2*VT.getSimpleVT())) & 3);
301 /// isOperationLegal - Return true if the specified operation is legal on this
303 bool isOperationLegal(unsigned Op, MVT VT) const {
304 return (VT == MVT::Other || isTypeLegal(VT)) &&
305 (getOperationAction(Op, VT) == Legal ||
306 getOperationAction(Op, VT) == Custom);
309 /// getLoadExtAction - Return how this load with extension should be treated:
310 /// either it is legal, needs to be promoted to a larger size, needs to be
311 /// expanded to some other code sequence, or the target has a custom expander
313 LegalizeAction getLoadExtAction(unsigned LType, MVT VT) const {
314 assert(LType < array_lengthof(LoadExtActions) &&
315 (unsigned)VT.getSimpleVT() < sizeof(LoadExtActions[0])*4 &&
316 "Table isn't big enough!");
317 return (LegalizeAction)((LoadExtActions[LType] >> (2*VT.getSimpleVT())) & 3);
320 /// isLoadExtLegal - Return true if the specified load with extension is legal
322 bool isLoadExtLegal(unsigned LType, MVT VT) const {
323 return VT.isSimple() &&
324 (getLoadExtAction(LType, VT) == Legal ||
325 getLoadExtAction(LType, VT) == Custom);
328 /// getTruncStoreAction - Return how this store with truncation should be
329 /// treated: either it is legal, needs to be promoted to a larger size, needs
330 /// to be expanded to some other code sequence, or the target has a custom
332 LegalizeAction getTruncStoreAction(MVT ValVT,
334 assert((unsigned)ValVT.getSimpleVT() < array_lengthof(TruncStoreActions) &&
335 (unsigned)MemVT.getSimpleVT() < sizeof(TruncStoreActions[0])*4 &&
336 "Table isn't big enough!");
337 return (LegalizeAction)((TruncStoreActions[ValVT.getSimpleVT()] >>
338 (2*MemVT.getSimpleVT())) & 3);
341 /// isTruncStoreLegal - Return true if the specified store with truncation is
342 /// legal on this target.
343 bool isTruncStoreLegal(MVT ValVT, MVT MemVT) const {
344 return isTypeLegal(ValVT) && MemVT.isSimple() &&
345 (getTruncStoreAction(ValVT, MemVT) == Legal ||
346 getTruncStoreAction(ValVT, MemVT) == Custom);
349 /// getIndexedLoadAction - Return how the indexed load should be treated:
350 /// either it is legal, needs to be promoted to a larger size, needs to be
351 /// expanded to some other code sequence, or the target has a custom expander
354 getIndexedLoadAction(unsigned IdxMode, MVT VT) const {
355 assert(IdxMode < array_lengthof(IndexedModeActions[0]) &&
356 (unsigned)VT.getSimpleVT() < sizeof(IndexedModeActions[0][0])*4 &&
357 "Table isn't big enough!");
358 return (LegalizeAction)((IndexedModeActions[0][IdxMode] >>
359 (2*VT.getSimpleVT())) & 3);
362 /// isIndexedLoadLegal - Return true if the specified indexed load is legal
364 bool isIndexedLoadLegal(unsigned IdxMode, MVT VT) const {
365 return VT.isSimple() &&
366 (getIndexedLoadAction(IdxMode, VT) == Legal ||
367 getIndexedLoadAction(IdxMode, VT) == Custom);
370 /// getIndexedStoreAction - Return how the indexed store should be treated:
371 /// either it is legal, needs to be promoted to a larger size, needs to be
372 /// expanded to some other code sequence, or the target has a custom expander
375 getIndexedStoreAction(unsigned IdxMode, MVT VT) const {
376 assert(IdxMode < array_lengthof(IndexedModeActions[1]) &&
377 (unsigned)VT.getSimpleVT() < sizeof(IndexedModeActions[1][0])*4 &&
378 "Table isn't big enough!");
379 return (LegalizeAction)((IndexedModeActions[1][IdxMode] >>
380 (2*VT.getSimpleVT())) & 3);
383 /// isIndexedStoreLegal - Return true if the specified indexed load is legal
385 bool isIndexedStoreLegal(unsigned IdxMode, MVT VT) const {
386 return VT.isSimple() &&
387 (getIndexedStoreAction(IdxMode, VT) == Legal ||
388 getIndexedStoreAction(IdxMode, VT) == Custom);
391 /// getConvertAction - Return how the conversion should be treated:
392 /// either it is legal, needs to be promoted to a larger size, needs to be
393 /// expanded to some other code sequence, or the target has a custom expander
396 getConvertAction(MVT FromVT, MVT ToVT) const {
397 assert((unsigned)FromVT.getSimpleVT() < array_lengthof(ConvertActions) &&
398 (unsigned)ToVT.getSimpleVT() < sizeof(ConvertActions[0])*4 &&
399 "Table isn't big enough!");
400 return (LegalizeAction)((ConvertActions[FromVT.getSimpleVT()] >>
401 (2*ToVT.getSimpleVT())) & 3);
404 /// isConvertLegal - Return true if the specified conversion is legal
406 bool isConvertLegal(MVT FromVT, MVT ToVT) const {
407 return isTypeLegal(FromVT) && isTypeLegal(ToVT) &&
408 (getConvertAction(FromVT, ToVT) == Legal ||
409 getConvertAction(FromVT, ToVT) == Custom);
412 /// getCondCodeAction - Return how the condition code should be treated:
413 /// either it is legal, needs to be expanded to some other code sequence,
414 /// or the target has a custom expander for it.
416 getCondCodeAction(ISD::CondCode CC, MVT VT) const {
417 assert((unsigned)CC < array_lengthof(CondCodeActions) &&
418 (unsigned)VT.getSimpleVT() < sizeof(CondCodeActions[0])*4 &&
419 "Table isn't big enough!");
420 LegalizeAction Action = (LegalizeAction)
421 ((CondCodeActions[CC] >> (2*VT.getSimpleVT())) & 3);
422 assert(Action != Promote && "Can't promote condition code!");
426 /// isCondCodeLegal - Return true if the specified condition code is legal
428 bool isCondCodeLegal(ISD::CondCode CC, MVT VT) const {
429 return getCondCodeAction(CC, VT) == Legal ||
430 getCondCodeAction(CC, VT) == Custom;
434 /// getTypeToPromoteTo - If the action for this operation is to promote, this
435 /// method returns the ValueType to promote to.
436 MVT getTypeToPromoteTo(unsigned Op, MVT VT) const {
437 assert(getOperationAction(Op, VT) == Promote &&
438 "This operation isn't promoted!");
440 // See if this has an explicit type specified.
441 std::map<std::pair<unsigned, MVT::SimpleValueType>,
442 MVT::SimpleValueType>::const_iterator PTTI =
443 PromoteToType.find(std::make_pair(Op, VT.getSimpleVT()));
444 if (PTTI != PromoteToType.end()) return PTTI->second;
446 assert((VT.isInteger() || VT.isFloatingPoint()) &&
447 "Cannot autopromote this type, add it with AddPromotedToType.");
451 NVT = (MVT::SimpleValueType)(NVT.getSimpleVT()+1);
452 assert(NVT.isInteger() == VT.isInteger() && NVT != MVT::isVoid &&
453 "Didn't find type to promote to!");
454 } while (!isTypeLegal(NVT) ||
455 getOperationAction(Op, NVT) == Promote);
459 /// getValueType - Return the MVT corresponding to this LLVM type.
460 /// This is fixed by the LLVM operations except for the pointer size. If
461 /// AllowUnknown is true, this will return MVT::Other for types with no MVT
462 /// counterpart (e.g. structs), otherwise it will assert.
463 MVT getValueType(const Type *Ty, bool AllowUnknown = false) const {
464 MVT VT = MVT::getMVT(Ty, AllowUnknown);
465 return VT == MVT::iPTR ? PointerTy : VT;
468 /// getByValTypeAlignment - Return the desired alignment for ByVal aggregate
469 /// function arguments in the caller parameter area. This is the actual
470 /// alignment, not its logarithm.
471 virtual unsigned getByValTypeAlignment(const Type *Ty) const;
473 /// getRegisterType - Return the type of registers that this ValueType will
474 /// eventually require.
475 MVT getRegisterType(MVT VT) const {
477 assert((unsigned)VT.getSimpleVT() < array_lengthof(RegisterTypeForVT));
478 return RegisterTypeForVT[VT.getSimpleVT()];
482 unsigned NumIntermediates;
483 (void)getVectorTypeBreakdown(VT, VT1, NumIntermediates, RegisterVT);
486 if (VT.isInteger()) {
487 return getRegisterType(getTypeToTransformTo(VT));
489 assert(0 && "Unsupported extended type!");
490 return MVT(); // Not reached
493 /// getNumRegisters - Return the number of registers that this ValueType will
494 /// eventually require. This is one for any types promoted to live in larger
495 /// registers, but may be more than one for types (like i64) that are split
496 /// into pieces. For types like i140, which are first promoted then expanded,
497 /// it is the number of registers needed to hold all the bits of the original
498 /// type. For an i140 on a 32 bit machine this means 5 registers.
499 unsigned getNumRegisters(MVT VT) const {
501 assert((unsigned)VT.getSimpleVT() < array_lengthof(NumRegistersForVT));
502 return NumRegistersForVT[VT.getSimpleVT()];
506 unsigned NumIntermediates;
507 return getVectorTypeBreakdown(VT, VT1, NumIntermediates, VT2);
509 if (VT.isInteger()) {
510 unsigned BitWidth = VT.getSizeInBits();
511 unsigned RegWidth = getRegisterType(VT).getSizeInBits();
512 return (BitWidth + RegWidth - 1) / RegWidth;
514 assert(0 && "Unsupported extended type!");
515 return 0; // Not reached
518 /// ShouldShrinkFPConstant - If true, then instruction selection should
519 /// seek to shrink the FP constant of the specified type to a smaller type
520 /// in order to save space and / or reduce runtime.
521 virtual bool ShouldShrinkFPConstant(MVT VT) const { return true; }
523 /// hasTargetDAGCombine - If true, the target has custom DAG combine
524 /// transformations that it can perform for the specified node.
525 bool hasTargetDAGCombine(ISD::NodeType NT) const {
526 assert(unsigned(NT >> 3) < array_lengthof(TargetDAGCombineArray));
527 return TargetDAGCombineArray[NT >> 3] & (1 << (NT&7));
530 /// This function returns the maximum number of store operations permitted
531 /// to replace a call to llvm.memset. The value is set by the target at the
532 /// performance threshold for such a replacement.
533 /// @brief Get maximum # of store operations permitted for llvm.memset
534 unsigned getMaxStoresPerMemset() const { return maxStoresPerMemset; }
536 /// This function returns the maximum number of store operations permitted
537 /// to replace a call to llvm.memcpy. The value is set by the target at the
538 /// performance threshold for such a replacement.
539 /// @brief Get maximum # of store operations permitted for llvm.memcpy
540 unsigned getMaxStoresPerMemcpy() const { return maxStoresPerMemcpy; }
542 /// This function returns the maximum number of store operations permitted
543 /// to replace a call to llvm.memmove. The value is set by the target at the
544 /// performance threshold for such a replacement.
545 /// @brief Get maximum # of store operations permitted for llvm.memmove
546 unsigned getMaxStoresPerMemmove() const { return maxStoresPerMemmove; }
548 /// This function returns true if the target allows unaligned memory accesses.
549 /// This is used, for example, in situations where an array copy/move/set is
550 /// converted to a sequence of store operations. It's use helps to ensure that
551 /// such replacements don't generate code that causes an alignment error
552 /// (trap) on the target machine.
553 /// @brief Determine if the target supports unaligned memory accesses.
554 bool allowsUnalignedMemoryAccesses() const {
555 return allowUnalignedMemoryAccesses;
558 /// getOptimalMemOpType - Returns the target specific optimal type for load
559 /// and store operations as a result of memset, memcpy, and memmove lowering.
560 /// It returns MVT::iAny if SelectionDAG should be responsible for
562 virtual MVT getOptimalMemOpType(uint64_t Size, unsigned Align,
563 bool isSrcConst, bool isSrcStr) const {
567 /// usesUnderscoreSetJmp - Determine if we should use _setjmp or setjmp
568 /// to implement llvm.setjmp.
569 bool usesUnderscoreSetJmp() const {
570 return UseUnderscoreSetJmp;
573 /// usesUnderscoreLongJmp - Determine if we should use _longjmp or longjmp
574 /// to implement llvm.longjmp.
575 bool usesUnderscoreLongJmp() const {
576 return UseUnderscoreLongJmp;
579 /// getStackPointerRegisterToSaveRestore - If a physical register, this
580 /// specifies the register that llvm.savestack/llvm.restorestack should save
582 unsigned getStackPointerRegisterToSaveRestore() const {
583 return StackPointerRegisterToSaveRestore;
586 /// getExceptionAddressRegister - If a physical register, this returns
587 /// the register that receives the exception address on entry to a landing
589 unsigned getExceptionAddressRegister() const {
590 return ExceptionPointerRegister;
593 /// getExceptionSelectorRegister - If a physical register, this returns
594 /// the register that receives the exception typeid on entry to a landing
596 unsigned getExceptionSelectorRegister() const {
597 return ExceptionSelectorRegister;
600 /// getJumpBufSize - returns the target's jmp_buf size in bytes (if never
601 /// set, the default is 200)
602 unsigned getJumpBufSize() const {
606 /// getJumpBufAlignment - returns the target's jmp_buf alignment in bytes
607 /// (if never set, the default is 0)
608 unsigned getJumpBufAlignment() const {
609 return JumpBufAlignment;
612 /// getIfCvtBlockLimit - returns the target specific if-conversion block size
613 /// limit. Any block whose size is greater should not be predicated.
614 unsigned getIfCvtBlockSizeLimit() const {
615 return IfCvtBlockSizeLimit;
618 /// getIfCvtDupBlockLimit - returns the target specific size limit for a
619 /// block to be considered for duplication. Any block whose size is greater
620 /// should not be duplicated to facilitate its predication.
621 unsigned getIfCvtDupBlockSizeLimit() const {
622 return IfCvtDupBlockSizeLimit;
625 /// getPrefLoopAlignment - return the preferred loop alignment.
627 unsigned getPrefLoopAlignment() const {
628 return PrefLoopAlignment;
631 /// getPreIndexedAddressParts - returns true by value, base pointer and
632 /// offset pointer and addressing mode by reference if the node's address
633 /// can be legally represented as pre-indexed load / store address.
634 virtual bool getPreIndexedAddressParts(SDNode *N, SDValue &Base,
636 ISD::MemIndexedMode &AM,
641 /// getPostIndexedAddressParts - returns true by value, base pointer and
642 /// offset pointer and addressing mode by reference if this node can be
643 /// combined with a load / store to form a post-indexed load / store.
644 virtual bool getPostIndexedAddressParts(SDNode *N, SDNode *Op,
645 SDValue &Base, SDValue &Offset,
646 ISD::MemIndexedMode &AM,
651 /// getPICJumpTableRelocaBase - Returns relocation base for the given PIC
653 virtual SDValue getPICJumpTableRelocBase(SDValue Table,
654 SelectionDAG &DAG) const;
656 //===--------------------------------------------------------------------===//
657 // TargetLowering Optimization Methods
660 /// TargetLoweringOpt - A convenience struct that encapsulates a DAG, and two
661 /// SDValues for returning information from TargetLowering to its clients
662 /// that want to combine
663 struct TargetLoweringOpt {
669 explicit TargetLoweringOpt(SelectionDAG &InDAG, bool afterLegalize)
670 : DAG(InDAG), AfterLegalize(afterLegalize) {}
672 bool CombineTo(SDValue O, SDValue N) {
678 /// ShrinkDemandedConstant - Check to see if the specified operand of the
679 /// specified instruction is a constant integer. If so, check to see if
680 /// there are any bits set in the constant that are not demanded. If so,
681 /// shrink the constant and return true.
682 bool ShrinkDemandedConstant(SDValue Op, const APInt &Demanded);
685 /// SimplifyDemandedBits - Look at Op. At this point, we know that only the
686 /// DemandedMask bits of the result of Op are ever used downstream. If we can
687 /// use this information to simplify Op, create a new simplified DAG node and
688 /// return true, returning the original and new nodes in Old and New.
689 /// Otherwise, analyze the expression and return a mask of KnownOne and
690 /// KnownZero bits for the expression (used to simplify the caller).
691 /// The KnownZero/One bits may only be accurate for those bits in the
693 bool SimplifyDemandedBits(SDValue Op, const APInt &DemandedMask,
694 APInt &KnownZero, APInt &KnownOne,
695 TargetLoweringOpt &TLO, unsigned Depth = 0) const;
697 /// computeMaskedBitsForTargetNode - Determine which of the bits specified in
698 /// Mask are known to be either zero or one and return them in the
699 /// KnownZero/KnownOne bitsets.
700 virtual void computeMaskedBitsForTargetNode(const SDValue Op,
704 const SelectionDAG &DAG,
705 unsigned Depth = 0) const;
707 /// ComputeNumSignBitsForTargetNode - This method can be implemented by
708 /// targets that want to expose additional information about sign bits to the
710 virtual unsigned ComputeNumSignBitsForTargetNode(SDValue Op,
711 unsigned Depth = 0) const;
713 struct DAGCombinerInfo {
714 void *DC; // The DAG Combiner object.
716 bool CalledByLegalizer;
720 DAGCombinerInfo(SelectionDAG &dag, bool bl, bool cl, void *dc)
721 : DC(dc), BeforeLegalize(bl), CalledByLegalizer(cl), DAG(dag) {}
723 bool isBeforeLegalize() const { return BeforeLegalize; }
724 bool isCalledByLegalizer() const { return CalledByLegalizer; }
726 void AddToWorklist(SDNode *N);
727 SDValue CombineTo(SDNode *N, const std::vector<SDValue> &To);
728 SDValue CombineTo(SDNode *N, SDValue Res);
729 SDValue CombineTo(SDNode *N, SDValue Res0, SDValue Res1);
732 /// SimplifySetCC - Try to simplify a setcc built with the specified operands
733 /// and cc. If it is unable to simplify it, return a null SDValue.
734 SDValue SimplifySetCC(MVT VT, SDValue N0, SDValue N1,
735 ISD::CondCode Cond, bool foldBooleans,
736 DAGCombinerInfo &DCI) const;
738 /// isGAPlusOffset - Returns true (and the GlobalValue and the offset) if the
739 /// node is a GlobalAddress + offset.
741 isGAPlusOffset(SDNode *N, GlobalValue* &GA, int64_t &Offset) const;
743 /// isConsecutiveLoad - Return true if LD (which must be a LoadSDNode) is
744 /// loading 'Bytes' bytes from a location that is 'Dist' units away from the
745 /// location that the 'Base' load is loading from.
746 bool isConsecutiveLoad(SDNode *LD, SDNode *Base, unsigned Bytes, int Dist,
747 const MachineFrameInfo *MFI) const;
749 /// PerformDAGCombine - This method will be invoked for all target nodes and
750 /// for any target-independent nodes that the target has registered with
753 /// The semantics are as follows:
755 /// SDValue.Val == 0 - No change was made
756 /// SDValue.Val == N - N was replaced, is dead, and is already handled.
757 /// otherwise - N should be replaced by the returned Operand.
759 /// In addition, methods provided by DAGCombinerInfo may be used to perform
760 /// more complex transformations.
762 virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
764 //===--------------------------------------------------------------------===//
765 // TargetLowering Configuration Methods - These methods should be invoked by
766 // the derived class constructor to configure this object for the target.
770 /// setUsesGlobalOffsetTable - Specify that this target does or doesn't use a
771 /// GOT for PC-relative code.
772 void setUsesGlobalOffsetTable(bool V) { UsesGlobalOffsetTable = V; }
774 /// setShiftAmountType - Describe the type that should be used for shift
775 /// amounts. This type defaults to the pointer type.
776 void setShiftAmountType(MVT VT) { ShiftAmountTy = VT; }
778 /// setSetCCResultContents - Specify how the target extends the result of a
779 /// setcc operation in a register.
780 void setSetCCResultContents(SetCCResultValue Ty) { SetCCResultContents = Ty; }
782 /// setSchedulingPreference - Specify the target scheduling preference.
783 void setSchedulingPreference(SchedPreference Pref) {
784 SchedPreferenceInfo = Pref;
787 /// setShiftAmountFlavor - Describe how the target handles out of range shift
789 void setShiftAmountFlavor(OutOfRangeShiftAmount OORSA) {
790 ShiftAmtHandling = OORSA;
793 /// setUseUnderscoreSetJmp - Indicate whether this target prefers to
794 /// use _setjmp to implement llvm.setjmp or the non _ version.
795 /// Defaults to false.
796 void setUseUnderscoreSetJmp(bool Val) {
797 UseUnderscoreSetJmp = Val;
800 /// setUseUnderscoreLongJmp - Indicate whether this target prefers to
801 /// use _longjmp to implement llvm.longjmp or the non _ version.
802 /// Defaults to false.
803 void setUseUnderscoreLongJmp(bool Val) {
804 UseUnderscoreLongJmp = Val;
807 /// setStackPointerRegisterToSaveRestore - If set to a physical register, this
808 /// specifies the register that llvm.savestack/llvm.restorestack should save
810 void setStackPointerRegisterToSaveRestore(unsigned R) {
811 StackPointerRegisterToSaveRestore = R;
814 /// setExceptionPointerRegister - If set to a physical register, this sets
815 /// the register that receives the exception address on entry to a landing
817 void setExceptionPointerRegister(unsigned R) {
818 ExceptionPointerRegister = R;
821 /// setExceptionSelectorRegister - If set to a physical register, this sets
822 /// the register that receives the exception typeid on entry to a landing
824 void setExceptionSelectorRegister(unsigned R) {
825 ExceptionSelectorRegister = R;
828 /// SelectIsExpensive - Tells the code generator not to expand operations
829 /// into sequences that use the select operations if possible.
830 void setSelectIsExpensive() { SelectIsExpensive = true; }
832 /// setIntDivIsCheap - Tells the code generator that integer divide is
833 /// expensive, and if possible, should be replaced by an alternate sequence
834 /// of instructions not containing an integer divide.
835 void setIntDivIsCheap(bool isCheap = true) { IntDivIsCheap = isCheap; }
837 /// setPow2DivIsCheap - Tells the code generator that it shouldn't generate
838 /// srl/add/sra for a signed divide by power of two, and let the target handle
840 void setPow2DivIsCheap(bool isCheap = true) { Pow2DivIsCheap = isCheap; }
842 /// addRegisterClass - Add the specified register class as an available
843 /// regclass for the specified value type. This indicates the selector can
844 /// handle values of that class natively.
845 void addRegisterClass(MVT VT, TargetRegisterClass *RC) {
846 assert((unsigned)VT.getSimpleVT() < array_lengthof(RegClassForVT));
847 AvailableRegClasses.push_back(std::make_pair(VT, RC));
848 RegClassForVT[VT.getSimpleVT()] = RC;
851 /// computeRegisterProperties - Once all of the register classes are added,
852 /// this allows us to compute derived properties we expose.
853 void computeRegisterProperties();
855 /// setOperationAction - Indicate that the specified operation does not work
856 /// with the specified type and indicate what to do about it.
857 void setOperationAction(unsigned Op, MVT VT,
858 LegalizeAction Action) {
859 assert((unsigned)VT.getSimpleVT() < sizeof(OpActions[0])*4 &&
860 Op < array_lengthof(OpActions) && "Table isn't big enough!");
861 OpActions[Op] &= ~(uint64_t(3UL) << VT.getSimpleVT()*2);
862 OpActions[Op] |= (uint64_t)Action << VT.getSimpleVT()*2;
865 /// setLoadExtAction - Indicate that the specified load with extension does
866 /// not work with the with specified type and indicate what to do about it.
867 void setLoadExtAction(unsigned ExtType, MVT VT,
868 LegalizeAction Action) {
869 assert((unsigned)VT.getSimpleVT() < sizeof(LoadExtActions[0])*4 &&
870 ExtType < array_lengthof(LoadExtActions) &&
871 "Table isn't big enough!");
872 LoadExtActions[ExtType] &= ~(uint64_t(3UL) << VT.getSimpleVT()*2);
873 LoadExtActions[ExtType] |= (uint64_t)Action << VT.getSimpleVT()*2;
876 /// setTruncStoreAction - Indicate that the specified truncating store does
877 /// not work with the with specified type and indicate what to do about it.
878 void setTruncStoreAction(MVT ValVT, MVT MemVT,
879 LegalizeAction Action) {
880 assert((unsigned)ValVT.getSimpleVT() < array_lengthof(TruncStoreActions) &&
881 (unsigned)MemVT.getSimpleVT() < sizeof(TruncStoreActions[0])*4 &&
882 "Table isn't big enough!");
883 TruncStoreActions[ValVT.getSimpleVT()] &= ~(uint64_t(3UL) <<
884 MemVT.getSimpleVT()*2);
885 TruncStoreActions[ValVT.getSimpleVT()] |= (uint64_t)Action <<
886 MemVT.getSimpleVT()*2;
889 /// setIndexedLoadAction - Indicate that the specified indexed load does or
890 /// does not work with the with specified type and indicate what to do abort
891 /// it. NOTE: All indexed mode loads are initialized to Expand in
892 /// TargetLowering.cpp
893 void setIndexedLoadAction(unsigned IdxMode, MVT VT,
894 LegalizeAction Action) {
895 assert((unsigned)VT.getSimpleVT() < sizeof(IndexedModeActions[0])*4 &&
896 IdxMode < array_lengthof(IndexedModeActions[0]) &&
897 "Table isn't big enough!");
898 IndexedModeActions[0][IdxMode] &= ~(uint64_t(3UL) << VT.getSimpleVT()*2);
899 IndexedModeActions[0][IdxMode] |= (uint64_t)Action << VT.getSimpleVT()*2;
902 /// setIndexedStoreAction - Indicate that the specified indexed store does or
903 /// does not work with the with specified type and indicate what to do about
904 /// it. NOTE: All indexed mode stores are initialized to Expand in
905 /// TargetLowering.cpp
906 void setIndexedStoreAction(unsigned IdxMode, MVT VT,
907 LegalizeAction Action) {
908 assert((unsigned)VT.getSimpleVT() < sizeof(IndexedModeActions[1][0])*4 &&
909 IdxMode < array_lengthof(IndexedModeActions[1]) &&
910 "Table isn't big enough!");
911 IndexedModeActions[1][IdxMode] &= ~(uint64_t(3UL) << VT.getSimpleVT()*2);
912 IndexedModeActions[1][IdxMode] |= (uint64_t)Action << VT.getSimpleVT()*2;
915 /// setConvertAction - Indicate that the specified conversion does or does
916 /// not work with the with specified type and indicate what to do about it.
917 void setConvertAction(MVT FromVT, MVT ToVT,
918 LegalizeAction Action) {
919 assert((unsigned)FromVT.getSimpleVT() < array_lengthof(ConvertActions) &&
920 (unsigned)ToVT.getSimpleVT() < sizeof(ConvertActions[0])*4 &&
921 "Table isn't big enough!");
922 ConvertActions[FromVT.getSimpleVT()] &= ~(uint64_t(3UL) <<
923 ToVT.getSimpleVT()*2);
924 ConvertActions[FromVT.getSimpleVT()] |= (uint64_t)Action <<
925 ToVT.getSimpleVT()*2;
928 /// setCondCodeAction - Indicate that the specified condition code is or isn't
929 /// supported on the target and indicate what to do about it.
930 void setCondCodeAction(ISD::CondCode CC, MVT VT, LegalizeAction Action) {
931 assert((unsigned)VT.getSimpleVT() < sizeof(CondCodeActions[0])*4 &&
932 (unsigned)CC < array_lengthof(CondCodeActions) &&
933 "Table isn't big enough!");
934 CondCodeActions[(unsigned)CC] &= ~(uint64_t(3UL) << VT.getSimpleVT()*2);
935 CondCodeActions[(unsigned)CC] |= (uint64_t)Action << VT.getSimpleVT()*2;
938 /// AddPromotedToType - If Opc/OrigVT is specified as being promoted, the
939 /// promotion code defaults to trying a larger integer/fp until it can find
940 /// one that works. If that default is insufficient, this method can be used
941 /// by the target to override the default.
942 void AddPromotedToType(unsigned Opc, MVT OrigVT, MVT DestVT) {
943 PromoteToType[std::make_pair(Opc, OrigVT.getSimpleVT())] =
944 DestVT.getSimpleVT();
947 /// addLegalFPImmediate - Indicate that this target can instruction select
948 /// the specified FP immediate natively.
949 void addLegalFPImmediate(const APFloat& Imm) {
950 LegalFPImmediates.push_back(Imm);
953 /// setTargetDAGCombine - Targets should invoke this method for each target
954 /// independent node that they want to provide a custom DAG combiner for by
955 /// implementing the PerformDAGCombine virtual method.
956 void setTargetDAGCombine(ISD::NodeType NT) {
957 assert(unsigned(NT >> 3) < array_lengthof(TargetDAGCombineArray));
958 TargetDAGCombineArray[NT >> 3] |= 1 << (NT&7);
961 /// setJumpBufSize - Set the target's required jmp_buf buffer size (in
962 /// bytes); default is 200
963 void setJumpBufSize(unsigned Size) {
967 /// setJumpBufAlignment - Set the target's required jmp_buf buffer
968 /// alignment (in bytes); default is 0
969 void setJumpBufAlignment(unsigned Align) {
970 JumpBufAlignment = Align;
973 /// setIfCvtBlockSizeLimit - Set the target's if-conversion block size
974 /// limit (in number of instructions); default is 2.
975 void setIfCvtBlockSizeLimit(unsigned Limit) {
976 IfCvtBlockSizeLimit = Limit;
979 /// setIfCvtDupBlockSizeLimit - Set the target's block size limit (in number
980 /// of instructions) to be considered for code duplication during
981 /// if-conversion; default is 2.
982 void setIfCvtDupBlockSizeLimit(unsigned Limit) {
983 IfCvtDupBlockSizeLimit = Limit;
986 /// setPrefLoopAlignment - Set the target's preferred loop alignment. Default
987 /// alignment is zero, it means the target does not care about loop alignment.
988 void setPrefLoopAlignment(unsigned Align) {
989 PrefLoopAlignment = Align;
994 virtual const TargetSubtarget *getSubtarget() {
995 assert(0 && "Not Implemented");
996 return NULL; // this is here to silence compiler errors
998 //===--------------------------------------------------------------------===//
999 // Lowering methods - These methods must be implemented by targets so that
1000 // the SelectionDAGLowering code knows how to lower these.
1003 /// LowerArguments - This hook must be implemented to indicate how we should
1004 /// lower the arguments for the specified function, into the specified DAG.
1006 LowerArguments(Function &F, SelectionDAG &DAG,
1007 SmallVectorImpl<SDValue>& ArgValues);
1009 /// LowerCallTo - This hook lowers an abstract call to a function into an
1010 /// actual call. This returns a pair of operands. The first element is the
1011 /// return value for the function (if RetTy is not VoidTy). The second
1012 /// element is the outgoing token chain.
1013 struct ArgListEntry {
1024 ArgListEntry() : isSExt(false), isZExt(false), isInReg(false),
1025 isSRet(false), isNest(false), isByVal(false), Alignment(0) { }
1027 typedef std::vector<ArgListEntry> ArgListTy;
1028 virtual std::pair<SDValue, SDValue>
1029 LowerCallTo(SDValue Chain, const Type *RetTy, bool RetSExt, bool RetZExt,
1030 bool isVarArg, bool isInreg, unsigned CallingConv,
1031 bool isTailCall, SDValue Callee, ArgListTy &Args,
1034 /// EmitTargetCodeForMemcpy - Emit target-specific code that performs a
1035 /// memcpy. This can be used by targets to provide code sequences for cases
1036 /// that don't fit the target's parameters for simple loads/stores and can be
1037 /// more efficient than using a library call. This function can return a null
1038 /// SDValue if the target declines to use custom code and a different
1039 /// lowering strategy should be used.
1041 /// If AlwaysInline is true, the size is constant and the target should not
1042 /// emit any calls and is strongly encouraged to attempt to emit inline code
1043 /// even if it is beyond the usual threshold because this intrinsic is being
1044 /// expanded in a place where calls are not feasible (e.g. within the prologue
1045 /// for another call). If the target chooses to decline an AlwaysInline
1046 /// request here, legalize will resort to using simple loads and stores.
1048 EmitTargetCodeForMemcpy(SelectionDAG &DAG,
1050 SDValue Op1, SDValue Op2,
1051 SDValue Op3, unsigned Align,
1053 const Value *DstSV, uint64_t DstOff,
1054 const Value *SrcSV, uint64_t SrcOff) {
1058 /// EmitTargetCodeForMemmove - Emit target-specific code that performs a
1059 /// memmove. This can be used by targets to provide code sequences for cases
1060 /// that don't fit the target's parameters for simple loads/stores and can be
1061 /// more efficient than using a library call. This function can return a null
1062 /// SDValue if the target declines to use custom code and a different
1063 /// lowering strategy should be used.
1065 EmitTargetCodeForMemmove(SelectionDAG &DAG,
1067 SDValue Op1, SDValue Op2,
1068 SDValue Op3, unsigned Align,
1069 const Value *DstSV, uint64_t DstOff,
1070 const Value *SrcSV, uint64_t SrcOff) {
1074 /// EmitTargetCodeForMemset - Emit target-specific code that performs a
1075 /// memset. This can be used by targets to provide code sequences for cases
1076 /// that don't fit the target's parameters for simple stores and can be more
1077 /// efficient than using a library call. This function can return a null
1078 /// SDValue if the target declines to use custom code and a different
1079 /// lowering strategy should be used.
1081 EmitTargetCodeForMemset(SelectionDAG &DAG,
1083 SDValue Op1, SDValue Op2,
1084 SDValue Op3, unsigned Align,
1085 const Value *DstSV, uint64_t DstOff) {
1089 /// LowerOperation - This callback is invoked for operations that are
1090 /// unsupported by the target, which are registered to use 'custom' lowering,
1091 /// and whose defined values are all legal.
1092 /// If the target has no operations that require custom lowering, it need not
1093 /// implement this. The default implementation of this aborts.
1094 virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG);
1096 /// ReplaceNodeResults - This callback is invoked for operations that are
1097 /// unsupported by the target, which are registered to use 'custom' lowering,
1098 /// and whose result type is illegal. This must return a node whose results
1099 /// precisely match the results of the input node. This typically involves a
1100 /// MERGE_VALUES node and/or BUILD_PAIR.
1102 /// If the target has no operations that require custom lowering, it need not
1103 /// implement this. The default implementation aborts.
1104 virtual SDNode *ReplaceNodeResults(SDNode *N, SelectionDAG &DAG) {
1105 assert(0 && "ReplaceNodeResults not implemented for this target!");
1109 /// IsEligibleForTailCallOptimization - Check whether the call is eligible for
1110 /// tail call optimization. Targets which want to do tail call optimization
1111 /// should override this function.
1112 virtual bool IsEligibleForTailCallOptimization(CallSDNode *Call,
1114 SelectionDAG &DAG) const {
1118 /// CheckTailCallReturnConstraints - Check whether CALL node immediatly
1119 /// preceeds the RET node and whether the return uses the result of the node
1120 /// or is a void return. This function can be used by the target to determine
1121 /// eligiblity of tail call optimization.
1122 static bool CheckTailCallReturnConstraints(CallSDNode *TheCall, SDValue Ret) {
1123 unsigned NumOps = Ret.getNumOperands();
1125 (Ret.getOperand(0) == SDValue(TheCall,1) ||
1126 Ret.getOperand(0) == SDValue(TheCall,0))) ||
1128 Ret.getOperand(0) == SDValue(TheCall,
1129 TheCall->getNumValues()-1) &&
1130 Ret.getOperand(1) == SDValue(TheCall,0)))
1135 /// GetPossiblePreceedingTailCall - Get preceeding TailCallNodeOpCode node if
1136 /// it exists skip possible ISD:TokenFactor.
1137 static SDValue GetPossiblePreceedingTailCall(SDValue Chain,
1138 unsigned TailCallNodeOpCode) {
1139 if (Chain.getOpcode() == TailCallNodeOpCode) {
1141 } else if (Chain.getOpcode() == ISD::TokenFactor) {
1142 if (Chain.getNumOperands() &&
1143 Chain.getOperand(0).getOpcode() == TailCallNodeOpCode)
1144 return Chain.getOperand(0);
1149 /// getTargetNodeName() - This method returns the name of a target specific
1151 virtual const char *getTargetNodeName(unsigned Opcode) const;
1153 /// createFastISel - This method returns a target specific FastISel object,
1154 /// or null if the target does not support "fast" ISel.
1156 createFastISel(MachineFunction &,
1157 MachineModuleInfo *,
1158 DenseMap<const Value *, unsigned> &,
1159 DenseMap<const BasicBlock *, MachineBasicBlock *> &,
1160 DenseMap<const AllocaInst *, int> &
1162 , SmallSet<Instruction*, 8> &CatchInfoLost
1168 //===--------------------------------------------------------------------===//
1169 // Inline Asm Support hooks
1172 enum ConstraintType {
1173 C_Register, // Constraint represents a single register.
1174 C_RegisterClass, // Constraint represents one or more registers.
1175 C_Memory, // Memory constraint.
1176 C_Other, // Something else.
1177 C_Unknown // Unsupported constraint.
1180 /// AsmOperandInfo - This contains information for each constraint that we are
1182 struct AsmOperandInfo : public InlineAsm::ConstraintInfo {
1183 /// ConstraintCode - This contains the actual string for the code, like "m".
1184 std::string ConstraintCode;
1186 /// ConstraintType - Information about the constraint code, e.g. Register,
1187 /// RegisterClass, Memory, Other, Unknown.
1188 TargetLowering::ConstraintType ConstraintType;
1190 /// CallOperandval - If this is the result output operand or a
1191 /// clobber, this is null, otherwise it is the incoming operand to the
1192 /// CallInst. This gets modified as the asm is processed.
1193 Value *CallOperandVal;
1195 /// ConstraintVT - The ValueType for the operand value.
1198 AsmOperandInfo(const InlineAsm::ConstraintInfo &info)
1199 : InlineAsm::ConstraintInfo(info),
1200 ConstraintType(TargetLowering::C_Unknown),
1201 CallOperandVal(0), ConstraintVT(MVT::Other) {
1205 /// ComputeConstraintToUse - Determines the constraint code and constraint
1206 /// type to use for the specific AsmOperandInfo, setting
1207 /// OpInfo.ConstraintCode and OpInfo.ConstraintType. If the actual operand
1208 /// being passed in is available, it can be passed in as Op, otherwise an
1209 /// empty SDValue can be passed. If hasMemory is true it means one of the asm
1210 /// constraint of the inline asm instruction being processed is 'm'.
1211 virtual void ComputeConstraintToUse(AsmOperandInfo &OpInfo,
1214 SelectionDAG *DAG = 0) const;
1216 /// getConstraintType - Given a constraint, return the type of constraint it
1217 /// is for this target.
1218 virtual ConstraintType getConstraintType(const std::string &Constraint) const;
1220 /// getRegClassForInlineAsmConstraint - Given a constraint letter (e.g. "r"),
1221 /// return a list of registers that can be used to satisfy the constraint.
1222 /// This should only be used for C_RegisterClass constraints.
1223 virtual std::vector<unsigned>
1224 getRegClassForInlineAsmConstraint(const std::string &Constraint,
1227 /// getRegForInlineAsmConstraint - Given a physical register constraint (e.g.
1228 /// {edx}), return the register number and the register class for the
1231 /// Given a register class constraint, like 'r', if this corresponds directly
1232 /// to an LLVM register class, return a register of 0 and the register class
1235 /// This should only be used for C_Register constraints. On error,
1236 /// this returns a register number of 0 and a null register class pointer..
1237 virtual std::pair<unsigned, const TargetRegisterClass*>
1238 getRegForInlineAsmConstraint(const std::string &Constraint,
1241 /// LowerXConstraint - try to replace an X constraint, which matches anything,
1242 /// with another that has more specific requirements based on the type of the
1243 /// corresponding operand. This returns null if there is no replacement to
1245 virtual const char *LowerXConstraint(MVT ConstraintVT) const;
1247 /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
1248 /// vector. If it is invalid, don't add anything to Ops. If hasMemory is true
1249 /// it means one of the asm constraint of the inline asm instruction being
1250 /// processed is 'm'.
1251 virtual void LowerAsmOperandForConstraint(SDValue Op, char ConstraintLetter,
1253 std::vector<SDValue> &Ops,
1254 SelectionDAG &DAG) const;
1256 //===--------------------------------------------------------------------===//
1260 // EmitInstrWithCustomInserter - This method should be implemented by targets
1261 // that mark instructions with the 'usesCustomDAGSchedInserter' flag. These
1262 // instructions are special in various ways, which require special support to
1263 // insert. The specified MachineInstr is created but not inserted into any
1264 // basic blocks, and the scheduler passes ownership of it to this method.
1265 virtual MachineBasicBlock *EmitInstrWithCustomInserter(MachineInstr *MI,
1266 MachineBasicBlock *MBB);
1268 //===--------------------------------------------------------------------===//
1269 // Addressing mode description hooks (used by LSR etc).
1272 /// AddrMode - This represents an addressing mode of:
1273 /// BaseGV + BaseOffs + BaseReg + Scale*ScaleReg
1274 /// If BaseGV is null, there is no BaseGV.
1275 /// If BaseOffs is zero, there is no base offset.
1276 /// If HasBaseReg is false, there is no base register.
1277 /// If Scale is zero, there is no ScaleReg. Scale of 1 indicates a reg with
1281 GlobalValue *BaseGV;
1285 AddrMode() : BaseGV(0), BaseOffs(0), HasBaseReg(false), Scale(0) {}
1288 /// isLegalAddressingMode - Return true if the addressing mode represented by
1289 /// AM is legal for this target, for a load/store of the specified type.
1290 /// TODO: Handle pre/postinc as well.
1291 virtual bool isLegalAddressingMode(const AddrMode &AM, const Type *Ty) const;
1293 /// isTruncateFree - Return true if it's free to truncate a value of
1294 /// type Ty1 to type Ty2. e.g. On x86 it's free to truncate a i32 value in
1295 /// register EAX to i16 by referencing its sub-register AX.
1296 virtual bool isTruncateFree(const Type *Ty1, const Type *Ty2) const {
1300 virtual bool isTruncateFree(MVT VT1, MVT VT2) const {
1304 //===--------------------------------------------------------------------===//
1305 // Div utility functions
1307 SDValue BuildSDIV(SDNode *N, SelectionDAG &DAG,
1308 std::vector<SDNode*>* Created) const;
1309 SDValue BuildUDIV(SDNode *N, SelectionDAG &DAG,
1310 std::vector<SDNode*>* Created) const;
1313 //===--------------------------------------------------------------------===//
1314 // Runtime Library hooks
1317 /// setLibcallName - Rename the default libcall routine name for the specified
1319 void setLibcallName(RTLIB::Libcall Call, const char *Name) {
1320 LibcallRoutineNames[Call] = Name;
1323 /// getLibcallName - Get the libcall routine name for the specified libcall.
1325 const char *getLibcallName(RTLIB::Libcall Call) const {
1326 return LibcallRoutineNames[Call];
1329 /// setCmpLibcallCC - Override the default CondCode to be used to test the
1330 /// result of the comparison libcall against zero.
1331 void setCmpLibcallCC(RTLIB::Libcall Call, ISD::CondCode CC) {
1332 CmpLibcallCCs[Call] = CC;
1335 /// getCmpLibcallCC - Get the CondCode that's to be used to test the result of
1336 /// the comparison libcall against zero.
1337 ISD::CondCode getCmpLibcallCC(RTLIB::Libcall Call) const {
1338 return CmpLibcallCCs[Call];
1343 const TargetData *TD;
1345 /// PointerTy - The type to use for pointers, usually i32 or i64.
1349 /// IsLittleEndian - True if this is a little endian target.
1351 bool IsLittleEndian;
1353 /// UsesGlobalOffsetTable - True if this target uses a GOT for PIC codegen.
1355 bool UsesGlobalOffsetTable;
1357 /// SelectIsExpensive - Tells the code generator not to expand operations
1358 /// into sequences that use the select operations if possible.
1359 bool SelectIsExpensive;
1361 /// IntDivIsCheap - Tells the code generator not to expand integer divides by
1362 /// constants into a sequence of muls, adds, and shifts. This is a hack until
1363 /// a real cost model is in place. If we ever optimize for size, this will be
1364 /// set to true unconditionally.
1367 /// Pow2DivIsCheap - Tells the code generator that it shouldn't generate
1368 /// srl/add/sra for a signed divide by power of two, and let the target handle
1370 bool Pow2DivIsCheap;
1372 /// UseUnderscoreSetJmp - This target prefers to use _setjmp to implement
1373 /// llvm.setjmp. Defaults to false.
1374 bool UseUnderscoreSetJmp;
1376 /// UseUnderscoreLongJmp - This target prefers to use _longjmp to implement
1377 /// llvm.longjmp. Defaults to false.
1378 bool UseUnderscoreLongJmp;
1380 /// ShiftAmountTy - The type to use for shift amounts, usually i8 or whatever
1384 OutOfRangeShiftAmount ShiftAmtHandling;
1386 /// SetCCResultContents - Information about the contents of the high-bits in
1387 /// the result of a setcc comparison operation.
1388 SetCCResultValue SetCCResultContents;
1390 /// SchedPreferenceInfo - The target scheduling preference: shortest possible
1391 /// total cycles or lowest register usage.
1392 SchedPreference SchedPreferenceInfo;
1394 /// JumpBufSize - The size, in bytes, of the target's jmp_buf buffers
1395 unsigned JumpBufSize;
1397 /// JumpBufAlignment - The alignment, in bytes, of the target's jmp_buf
1399 unsigned JumpBufAlignment;
1401 /// IfCvtBlockSizeLimit - The maximum allowed size for a block to be
1403 unsigned IfCvtBlockSizeLimit;
1405 /// IfCvtDupBlockSizeLimit - The maximum allowed size for a block to be
1406 /// duplicated during if-conversion.
1407 unsigned IfCvtDupBlockSizeLimit;
1409 /// PrefLoopAlignment - The perferred loop alignment.
1411 unsigned PrefLoopAlignment;
1413 /// StackPointerRegisterToSaveRestore - If set to a physical register, this
1414 /// specifies the register that llvm.savestack/llvm.restorestack should save
1416 unsigned StackPointerRegisterToSaveRestore;
1418 /// ExceptionPointerRegister - If set to a physical register, this specifies
1419 /// the register that receives the exception address on entry to a landing
1421 unsigned ExceptionPointerRegister;
1423 /// ExceptionSelectorRegister - If set to a physical register, this specifies
1424 /// the register that receives the exception typeid on entry to a landing
1426 unsigned ExceptionSelectorRegister;
1428 /// RegClassForVT - This indicates the default register class to use for
1429 /// each ValueType the target supports natively.
1430 TargetRegisterClass *RegClassForVT[MVT::LAST_VALUETYPE];
1431 unsigned char NumRegistersForVT[MVT::LAST_VALUETYPE];
1432 MVT RegisterTypeForVT[MVT::LAST_VALUETYPE];
1434 /// TransformToType - For any value types we are promoting or expanding, this
1435 /// contains the value type that we are changing to. For Expanded types, this
1436 /// contains one step of the expand (e.g. i64 -> i32), even if there are
1437 /// multiple steps required (e.g. i64 -> i16). For types natively supported
1438 /// by the system, this holds the same type (e.g. i32 -> i32).
1439 MVT TransformToType[MVT::LAST_VALUETYPE];
1441 // Defines the capacity of the TargetLowering::OpActions table
1442 static const int OpActionsCapacity = 212;
1444 /// OpActions - For each operation and each value type, keep a LegalizeAction
1445 /// that indicates how instruction selection should deal with the operation.
1446 /// Most operations are Legal (aka, supported natively by the target), but
1447 /// operations that are not should be described. Note that operations on
1448 /// non-legal value types are not described here.
1449 uint64_t OpActions[OpActionsCapacity];
1451 /// LoadExtActions - For each load of load extension type and each value type,
1452 /// keep a LegalizeAction that indicates how instruction selection should deal
1454 uint64_t LoadExtActions[ISD::LAST_LOADEXT_TYPE];
1456 /// TruncStoreActions - For each truncating store, keep a LegalizeAction that
1457 /// indicates how instruction selection should deal with the store.
1458 uint64_t TruncStoreActions[MVT::LAST_VALUETYPE];
1460 /// IndexedModeActions - For each indexed mode and each value type, keep a
1461 /// pair of LegalizeAction that indicates how instruction selection should
1462 /// deal with the load / store.
1463 uint64_t IndexedModeActions[2][ISD::LAST_INDEXED_MODE];
1465 /// ConvertActions - For each conversion from source type to destination type,
1466 /// keep a LegalizeAction that indicates how instruction selection should
1467 /// deal with the conversion.
1468 /// Currently, this is used only for floating->floating conversions
1469 /// (FP_EXTEND and FP_ROUND).
1470 uint64_t ConvertActions[MVT::LAST_VALUETYPE];
1472 /// CondCodeActions - For each condition code (ISD::CondCode) keep a
1473 /// LegalizeAction that indicates how instruction selection should
1474 /// deal with the condition code.
1475 uint64_t CondCodeActions[ISD::SETCC_INVALID];
1477 ValueTypeActionImpl ValueTypeActions;
1479 std::vector<APFloat> LegalFPImmediates;
1481 std::vector<std::pair<MVT, TargetRegisterClass*> > AvailableRegClasses;
1483 /// TargetDAGCombineArray - Targets can specify ISD nodes that they would
1484 /// like PerformDAGCombine callbacks for by calling setTargetDAGCombine(),
1485 /// which sets a bit in this array.
1487 TargetDAGCombineArray[OpActionsCapacity/(sizeof(unsigned char)*8)];
1489 /// PromoteToType - For operations that must be promoted to a specific type,
1490 /// this holds the destination type. This map should be sparse, so don't hold
1493 /// Targets add entries to this map with AddPromotedToType(..), clients access
1494 /// this with getTypeToPromoteTo(..).
1495 std::map<std::pair<unsigned, MVT::SimpleValueType>, MVT::SimpleValueType>
1498 /// LibcallRoutineNames - Stores the name each libcall.
1500 const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL];
1502 /// CmpLibcallCCs - The ISD::CondCode that should be used to test the result
1503 /// of each of the comparison libcall against zero.
1504 ISD::CondCode CmpLibcallCCs[RTLIB::UNKNOWN_LIBCALL];
1507 /// When lowering @llvm.memset this field specifies the maximum number of
1508 /// store operations that may be substituted for the call to memset. Targets
1509 /// must set this value based on the cost threshold for that target. Targets
1510 /// should assume that the memset will be done using as many of the largest
1511 /// store operations first, followed by smaller ones, if necessary, per
1512 /// alignment restrictions. For example, storing 9 bytes on a 32-bit machine
1513 /// with 16-bit alignment would result in four 2-byte stores and one 1-byte
1514 /// store. This only applies to setting a constant array of a constant size.
1515 /// @brief Specify maximum number of store instructions per memset call.
1516 unsigned maxStoresPerMemset;
1518 /// When lowering @llvm.memcpy this field specifies the maximum number of
1519 /// store operations that may be substituted for a call to memcpy. Targets
1520 /// must set this value based on the cost threshold for that target. Targets
1521 /// should assume that the memcpy will be done using as many of the largest
1522 /// store operations first, followed by smaller ones, if necessary, per
1523 /// alignment restrictions. For example, storing 7 bytes on a 32-bit machine
1524 /// with 32-bit alignment would result in one 4-byte store, a one 2-byte store
1525 /// and one 1-byte store. This only applies to copying a constant array of
1527 /// @brief Specify maximum bytes of store instructions per memcpy call.
1528 unsigned maxStoresPerMemcpy;
1530 /// When lowering @llvm.memmove this field specifies the maximum number of
1531 /// store instructions that may be substituted for a call to memmove. Targets
1532 /// must set this value based on the cost threshold for that target. Targets
1533 /// should assume that the memmove will be done using as many of the largest
1534 /// store operations first, followed by smaller ones, if necessary, per
1535 /// alignment restrictions. For example, moving 9 bytes on a 32-bit machine
1536 /// with 8-bit alignment would result in nine 1-byte stores. This only
1537 /// applies to copying a constant array of constant size.
1538 /// @brief Specify maximum bytes of store instructions per memmove call.
1539 unsigned maxStoresPerMemmove;
1541 /// This field specifies whether the target machine permits unaligned memory
1542 /// accesses. This is used, for example, to determine the size of store
1543 /// operations when copying small arrays and other similar tasks.
1544 /// @brief Indicate whether the target permits unaligned memory accesses.
1545 bool allowUnalignedMemoryAccesses;
1547 } // end llvm namespace