1 //===-- llvm/Target/TargetLowering.h - Target Lowering Info -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source 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/Type.h"
26 #include "llvm/CodeGen/SelectionDAGNodes.h"
34 class TargetRegisterClass;
38 class MachineBasicBlock;
41 //===----------------------------------------------------------------------===//
42 /// TargetLowering - This class defines information used to lower LLVM code to
43 /// legal SelectionDAG operators that the target instruction selector can accept
46 /// This class also defines callbacks that targets must implement to lower
47 /// target-specific constructs to SelectionDAG operators.
49 class TargetLowering {
51 /// LegalizeAction - This enum indicates whether operations are valid for a
52 /// target, and if not, what action should be used to make them valid.
54 Legal, // The target natively supports this operation.
55 Promote, // This operation should be executed in a larger type.
56 Expand, // Try to expand this to other ops, otherwise use a libcall.
57 Custom // Use the LowerOperation hook to implement custom lowering.
60 enum OutOfRangeShiftAmount {
61 Undefined, // Oversized shift amounts are undefined (default).
62 Mask, // Shift amounts are auto masked (anded) to value size.
63 Extend // Oversized shift pulls in zeros or sign bits.
66 enum SetCCResultValue {
67 UndefinedSetCCResult, // SetCC returns a garbage/unknown extend.
68 ZeroOrOneSetCCResult, // SetCC returns a zero extended result.
69 ZeroOrNegativeOneSetCCResult // SetCC returns a sign extended result.
72 enum SchedPreference {
73 SchedulingForLatency, // Scheduling for shortest total latency.
74 SchedulingForRegPressure // Scheduling for lowest register pressure.
77 TargetLowering(TargetMachine &TM);
78 virtual ~TargetLowering();
80 TargetMachine &getTargetMachine() const { return TM; }
81 const TargetData *getTargetData() const { return TD; }
83 bool isLittleEndian() const { return IsLittleEndian; }
84 MVT::ValueType getPointerTy() const { return PointerTy; }
85 MVT::ValueType getShiftAmountTy() const { return ShiftAmountTy; }
86 OutOfRangeShiftAmount getShiftAmountFlavor() const {return ShiftAmtHandling; }
88 /// isSetCCExpensive - Return true if the setcc operation is expensive for
90 bool isSetCCExpensive() const { return SetCCIsExpensive; }
92 /// isIntDivCheap() - Return true if integer divide is usually cheaper than
93 /// a sequence of several shifts, adds, and multiplies for this target.
94 bool isIntDivCheap() const { return IntDivIsCheap; }
96 /// isPow2DivCheap() - Return true if pow2 div is cheaper than a chain of
98 bool isPow2DivCheap() const { return Pow2DivIsCheap; }
100 /// getSetCCResultTy - Return the ValueType of the result of setcc operations.
102 MVT::ValueType getSetCCResultTy() const { return SetCCResultTy; }
104 /// getSetCCResultContents - For targets without boolean registers, this flag
105 /// returns information about the contents of the high-bits in the setcc
107 SetCCResultValue getSetCCResultContents() const { return SetCCResultContents;}
109 /// getSchedulingPreference - Return target scheduling preference.
110 SchedPreference getSchedulingPreference() const {
111 return SchedPreferenceInfo;
114 /// getRegClassFor - Return the register class that should be used for the
115 /// specified value type. This may only be called on legal types.
116 TargetRegisterClass *getRegClassFor(MVT::ValueType VT) const {
117 TargetRegisterClass *RC = RegClassForVT[VT];
118 assert(RC && "This value type is not natively supported!");
122 /// isTypeLegal - Return true if the target has native support for the
123 /// specified value type. This means that it has a register that directly
124 /// holds it without promotions or expansions.
125 bool isTypeLegal(MVT::ValueType VT) const {
126 return RegClassForVT[VT] != 0;
129 class ValueTypeActionImpl {
130 /// ValueTypeActions - This is a bitvector that contains two bits for each
131 /// value type, where the two bits correspond to the LegalizeAction enum.
132 /// This can be queried with "getTypeAction(VT)".
133 uint32_t ValueTypeActions[2];
135 ValueTypeActionImpl() {
136 ValueTypeActions[0] = ValueTypeActions[1] = 0;
138 ValueTypeActionImpl(const ValueTypeActionImpl &RHS) {
139 ValueTypeActions[0] = RHS.ValueTypeActions[0];
140 ValueTypeActions[1] = RHS.ValueTypeActions[1];
143 LegalizeAction getTypeAction(MVT::ValueType VT) const {
144 return (LegalizeAction)((ValueTypeActions[VT>>4] >> ((2*VT) & 31)) & 3);
146 void setTypeAction(MVT::ValueType VT, LegalizeAction Action) {
147 assert(unsigned(VT >> 4) <
148 sizeof(ValueTypeActions)/sizeof(ValueTypeActions[0]));
149 ValueTypeActions[VT>>4] |= Action << ((VT*2) & 31);
153 const ValueTypeActionImpl &getValueTypeActions() const {
154 return ValueTypeActions;
157 /// getTypeAction - Return how we should legalize values of this type, either
158 /// it is already legal (return 'Legal') or we need to promote it to a larger
159 /// type (return 'Promote'), or we need to expand it into multiple registers
160 /// of smaller integer type (return 'Expand'). 'Custom' is not an option.
161 LegalizeAction getTypeAction(MVT::ValueType VT) const {
162 return ValueTypeActions.getTypeAction(VT);
165 /// getTypeToTransformTo - For types supported by the target, this is an
166 /// identity function. For types that must be promoted to larger types, this
167 /// returns the larger type to promote to. For types that are larger than the
168 /// largest integer register, this contains one step in the expansion to get
169 /// to the smaller register.
170 MVT::ValueType getTypeToTransformTo(MVT::ValueType VT) const {
171 return TransformToType[VT];
174 /// getPackedTypeBreakdown - Packed types are broken down into some number of
175 /// legal first class types. For example, <8 x float> maps to 2 MVT::v4f32
176 /// with Altivec or SSE1, or 8 promoted MVT::f64 values with the X86 FP stack.
177 /// Similarly, <2 x long> turns into 4 MVT::i32 values with both PPC and X86.
179 /// This method returns the number of registers needed, and the VT for each
180 /// register. It also returns the VT of the PackedType elements before they
181 /// are promoted/expanded.
183 unsigned getPackedTypeBreakdown(const PackedType *PTy,
184 MVT::ValueType &PTyElementVT,
185 MVT::ValueType &PTyLegalElementVT) const;
187 typedef std::vector<double>::const_iterator legal_fpimm_iterator;
188 legal_fpimm_iterator legal_fpimm_begin() const {
189 return LegalFPImmediates.begin();
191 legal_fpimm_iterator legal_fpimm_end() const {
192 return LegalFPImmediates.end();
195 /// isShuffleMaskLegal - Targets can use this to indicate that they only
196 /// support *some* VECTOR_SHUFFLE operations, those with specific masks.
197 /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values
198 /// are assumed to be legal.
199 virtual bool isShuffleMaskLegal(SDOperand Mask, MVT::ValueType VT) const {
203 /// isVectorClearMaskLegal - Similar to isShuffleMaskLegal. This is
204 /// used by Targets can use this to indicate if there is a suitable
205 /// VECTOR_SHUFFLE that can be used to replace a VAND with a constant
207 virtual bool isVectorClearMaskLegal(std::vector<SDOperand> &BVOps,
209 SelectionDAG &DAG) const {
213 /// getOperationAction - Return how this operation should be treated: either
214 /// it is legal, needs to be promoted to a larger size, needs to be
215 /// expanded to some other code sequence, or the target has a custom expander
217 LegalizeAction getOperationAction(unsigned Op, MVT::ValueType VT) const {
218 return (LegalizeAction)((OpActions[Op] >> (2*VT)) & 3);
221 /// isOperationLegal - Return true if the specified operation is legal on this
223 bool isOperationLegal(unsigned Op, MVT::ValueType VT) const {
224 return getOperationAction(Op, VT) == Legal ||
225 getOperationAction(Op, VT) == Custom;
228 /// getTypeToPromoteTo - If the action for this operation is to promote, this
229 /// method returns the ValueType to promote to.
230 MVT::ValueType getTypeToPromoteTo(unsigned Op, MVT::ValueType VT) const {
231 assert(getOperationAction(Op, VT) == Promote &&
232 "This operation isn't promoted!");
234 // See if this has an explicit type specified.
235 std::map<std::pair<unsigned, MVT::ValueType>,
236 MVT::ValueType>::const_iterator PTTI =
237 PromoteToType.find(std::make_pair(Op, VT));
238 if (PTTI != PromoteToType.end()) return PTTI->second;
240 assert((MVT::isInteger(VT) || MVT::isFloatingPoint(VT)) &&
241 "Cannot autopromote this type, add it with AddPromotedToType.");
243 MVT::ValueType NVT = VT;
245 NVT = (MVT::ValueType)(NVT+1);
246 assert(MVT::isInteger(NVT) == MVT::isInteger(VT) && NVT != MVT::isVoid &&
247 "Didn't find type to promote to!");
248 } while (!isTypeLegal(NVT) ||
249 getOperationAction(Op, NVT) == Promote);
253 /// getValueType - Return the MVT::ValueType corresponding to this LLVM type.
254 /// This is fixed by the LLVM operations except for the pointer size.
255 MVT::ValueType getValueType(const Type *Ty) const {
256 switch (Ty->getTypeID()) {
257 default: assert(0 && "Unknown type!");
258 case Type::VoidTyID: return MVT::isVoid;
259 case Type::BoolTyID: return MVT::i1;
260 case Type::UByteTyID:
261 case Type::SByteTyID: return MVT::i8;
262 case Type::ShortTyID:
263 case Type::UShortTyID: return MVT::i16;
265 case Type::UIntTyID: return MVT::i32;
267 case Type::ULongTyID: return MVT::i64;
268 case Type::FloatTyID: return MVT::f32;
269 case Type::DoubleTyID: return MVT::f64;
270 case Type::PointerTyID: return PointerTy;
271 case Type::PackedTyID: return MVT::Vector;
275 /// getNumElements - Return the number of registers that this ValueType will
276 /// eventually require. This is always one for all non-integer types, is
277 /// one for any types promoted to live in larger registers, but may be more
278 /// than one for types (like i64) that are split into pieces.
279 unsigned getNumElements(MVT::ValueType VT) const {
280 return NumElementsForVT[VT];
283 /// hasTargetDAGCombine - If true, the target has custom DAG combine
284 /// transformations that it can perform for the specified node.
285 bool hasTargetDAGCombine(ISD::NodeType NT) const {
286 return TargetDAGCombineArray[NT >> 3] & (1 << (NT&7));
289 /// This function returns the maximum number of store operations permitted
290 /// to replace a call to llvm.memset. The value is set by the target at the
291 /// performance threshold for such a replacement.
292 /// @brief Get maximum # of store operations permitted for llvm.memset
293 unsigned getMaxStoresPerMemset() const { return maxStoresPerMemset; }
295 /// This function returns the maximum number of store operations permitted
296 /// to replace a call to llvm.memcpy. The value is set by the target at the
297 /// performance threshold for such a replacement.
298 /// @brief Get maximum # of store operations permitted for llvm.memcpy
299 unsigned getMaxStoresPerMemcpy() const { return maxStoresPerMemcpy; }
301 /// This function returns the maximum number of store operations permitted
302 /// to replace a call to llvm.memmove. The value is set by the target at the
303 /// performance threshold for such a replacement.
304 /// @brief Get maximum # of store operations permitted for llvm.memmove
305 unsigned getMaxStoresPerMemmove() const { return maxStoresPerMemmove; }
307 /// This function returns true if the target allows unaligned memory accesses.
308 /// This is used, for example, in situations where an array copy/move/set is
309 /// converted to a sequence of store operations. It's use helps to ensure that
310 /// such replacements don't generate code that causes an alignment error
311 /// (trap) on the target machine.
312 /// @brief Determine if the target supports unaligned memory accesses.
313 bool allowsUnalignedMemoryAccesses() const {
314 return allowUnalignedMemoryAccesses;
317 /// usesUnderscoreSetJmpLongJmp - Determine if we should use _setjmp or setjmp
318 /// to implement llvm.setjmp.
319 bool usesUnderscoreSetJmpLongJmp() const {
320 return UseUnderscoreSetJmpLongJmp;
323 /// getStackPointerRegisterToSaveRestore - If a physical register, this
324 /// specifies the register that llvm.savestack/llvm.restorestack should save
326 unsigned getStackPointerRegisterToSaveRestore() const {
327 return StackPointerRegisterToSaveRestore;
330 //===--------------------------------------------------------------------===//
331 // TargetLowering Optimization Methods
334 /// TargetLoweringOpt - A convenience struct that encapsulates a DAG, and two
335 /// SDOperands for returning information from TargetLowering to its clients
336 /// that want to combine
337 struct TargetLoweringOpt {
342 TargetLoweringOpt(SelectionDAG &InDAG) : DAG(InDAG) {}
344 bool CombineTo(SDOperand O, SDOperand N) {
350 /// ShrinkDemandedConstant - Check to see if the specified operand of the
351 /// specified instruction is a constant integer. If so, check to see if there
352 /// are any bits set in the constant that are not demanded. If so, shrink the
353 /// constant and return true.
354 bool ShrinkDemandedConstant(SDOperand Op, uint64_t Demanded);
357 /// MaskedValueIsZero - Return true if 'Op & Mask' is known to be zero. We
358 /// use this predicate to simplify operations downstream. Op and Mask are
359 /// known to be the same type.
360 bool MaskedValueIsZero(SDOperand Op, uint64_t Mask, unsigned Depth = 0)
363 /// ComputeMaskedBits - Determine which of the bits specified in Mask are
364 /// known to be either zero or one and return them in the KnownZero/KnownOne
365 /// bitsets. This code only analyzes bits in Mask, in order to short-circuit
366 /// processing. Targets can implement the computeMaskedBitsForTargetNode
367 /// method, to allow target nodes to be understood.
368 void ComputeMaskedBits(SDOperand Op, uint64_t Mask, uint64_t &KnownZero,
369 uint64_t &KnownOne, unsigned Depth = 0) const;
371 /// SimplifyDemandedBits - Look at Op. At this point, we know that only the
372 /// DemandedMask bits of the result of Op are ever used downstream. If we can
373 /// use this information to simplify Op, create a new simplified DAG node and
374 /// return true, returning the original and new nodes in Old and New.
375 /// Otherwise, analyze the expression and return a mask of KnownOne and
376 /// KnownZero bits for the expression (used to simplify the caller).
377 /// The KnownZero/One bits may only be accurate for those bits in the
379 bool SimplifyDemandedBits(SDOperand Op, uint64_t DemandedMask,
380 uint64_t &KnownZero, uint64_t &KnownOne,
381 TargetLoweringOpt &TLO, unsigned Depth = 0) const;
383 /// computeMaskedBitsForTargetNode - Determine which of the bits specified in
384 /// Mask are known to be either zero or one and return them in the
385 /// KnownZero/KnownOne bitsets.
386 virtual void computeMaskedBitsForTargetNode(const SDOperand Op,
390 unsigned Depth = 0) const;
392 /// ComputeNumSignBits - Return the number of times the sign bit of the
393 /// register is replicated into the other bits. We know that at least 1 bit
394 /// is always equal to the sign bit (itself), but other cases can give us
395 /// information. For example, immediately after an "SRA X, 2", we know that
396 /// the top 3 bits are all equal to each other, so we return 3.
397 unsigned ComputeNumSignBits(SDOperand Op, unsigned Depth = 0) const;
399 /// ComputeNumSignBitsForTargetNode - This method can be implemented by
400 /// targets that want to expose additional information about sign bits to the
402 virtual unsigned ComputeNumSignBitsForTargetNode(SDOperand Op,
403 unsigned Depth = 0) const;
405 struct DAGCombinerInfo {
406 void *DC; // The DAG Combiner object.
411 DAGCombinerInfo(SelectionDAG &dag, bool bl, void *dc)
412 : DC(dc), BeforeLegalize(bl), DAG(dag) {}
414 bool isBeforeLegalize() const { return BeforeLegalize; }
416 void AddToWorklist(SDNode *N);
417 SDOperand CombineTo(SDNode *N, const std::vector<SDOperand> &To);
418 SDOperand CombineTo(SDNode *N, SDOperand Res);
419 SDOperand CombineTo(SDNode *N, SDOperand Res0, SDOperand Res1);
422 /// PerformDAGCombine - This method will be invoked for all target nodes and
423 /// for any target-independent nodes that the target has registered with
426 /// The semantics are as follows:
428 /// SDOperand.Val == 0 - No change was made
429 /// SDOperand.Val == N - N was replaced, is dead, and is already handled.
430 /// otherwise - N should be replaced by the returned Operand.
432 /// In addition, methods provided by DAGCombinerInfo may be used to perform
433 /// more complex transformations.
435 virtual SDOperand PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
437 //===--------------------------------------------------------------------===//
438 // TargetLowering Configuration Methods - These methods should be invoked by
439 // the derived class constructor to configure this object for the target.
444 /// setShiftAmountType - Describe the type that should be used for shift
445 /// amounts. This type defaults to the pointer type.
446 void setShiftAmountType(MVT::ValueType VT) { ShiftAmountTy = VT; }
448 /// setSetCCResultType - Describe the type that shoudl be used as the result
449 /// of a setcc operation. This defaults to the pointer type.
450 void setSetCCResultType(MVT::ValueType VT) { SetCCResultTy = VT; }
452 /// setSetCCResultContents - Specify how the target extends the result of a
453 /// setcc operation in a register.
454 void setSetCCResultContents(SetCCResultValue Ty) { SetCCResultContents = Ty; }
456 /// setSchedulingPreference - Specify the target scheduling preference.
457 void setSchedulingPreference(SchedPreference Pref) {
458 SchedPreferenceInfo = Pref;
461 /// setShiftAmountFlavor - Describe how the target handles out of range shift
463 void setShiftAmountFlavor(OutOfRangeShiftAmount OORSA) {
464 ShiftAmtHandling = OORSA;
467 /// setUseUnderscoreSetJmpLongJmp - Indicate whether this target prefers to
468 /// use _setjmp and _longjmp to or implement llvm.setjmp/llvm.longjmp or
469 /// the non _ versions. Defaults to false.
470 void setUseUnderscoreSetJmpLongJmp(bool Val) {
471 UseUnderscoreSetJmpLongJmp = Val;
474 /// setStackPointerRegisterToSaveRestore - If set to a physical register, this
475 /// specifies the register that llvm.savestack/llvm.restorestack should save
477 void setStackPointerRegisterToSaveRestore(unsigned R) {
478 StackPointerRegisterToSaveRestore = R;
481 /// setSetCCIxExpensive - This is a short term hack for targets that codegen
482 /// setcc as a conditional branch. This encourages the code generator to fold
483 /// setcc operations into other operations if possible.
484 void setSetCCIsExpensive() { SetCCIsExpensive = true; }
486 /// setIntDivIsCheap - Tells the code generator that integer divide is
487 /// expensive, and if possible, should be replaced by an alternate sequence
488 /// of instructions not containing an integer divide.
489 void setIntDivIsCheap(bool isCheap = true) { IntDivIsCheap = isCheap; }
491 /// setPow2DivIsCheap - Tells the code generator that it shouldn't generate
492 /// srl/add/sra for a signed divide by power of two, and let the target handle
494 void setPow2DivIsCheap(bool isCheap = true) { Pow2DivIsCheap = isCheap; }
496 /// addRegisterClass - Add the specified register class as an available
497 /// regclass for the specified value type. This indicates the selector can
498 /// handle values of that class natively.
499 void addRegisterClass(MVT::ValueType VT, TargetRegisterClass *RC) {
500 AvailableRegClasses.push_back(std::make_pair(VT, RC));
501 RegClassForVT[VT] = RC;
504 /// computeRegisterProperties - Once all of the register classes are added,
505 /// this allows us to compute derived properties we expose.
506 void computeRegisterProperties();
508 /// setOperationAction - Indicate that the specified operation does not work
509 /// with the specified type and indicate what to do about it.
510 void setOperationAction(unsigned Op, MVT::ValueType VT,
511 LegalizeAction Action) {
512 assert(VT < 32 && Op < sizeof(OpActions)/sizeof(OpActions[0]) &&
513 "Table isn't big enough!");
514 OpActions[Op] &= ~(uint64_t(3UL) << VT*2);
515 OpActions[Op] |= (uint64_t)Action << VT*2;
518 /// AddPromotedToType - If Opc/OrigVT is specified as being promoted, the
519 /// promotion code defaults to trying a larger integer/fp until it can find
520 /// one that works. If that default is insufficient, this method can be used
521 /// by the target to override the default.
522 void AddPromotedToType(unsigned Opc, MVT::ValueType OrigVT,
523 MVT::ValueType DestVT) {
524 PromoteToType[std::make_pair(Opc, OrigVT)] = DestVT;
527 /// addLegalFPImmediate - Indicate that this target can instruction select
528 /// the specified FP immediate natively.
529 void addLegalFPImmediate(double Imm) {
530 LegalFPImmediates.push_back(Imm);
533 /// setTargetDAGCombine - Targets should invoke this method for each target
534 /// independent node that they want to provide a custom DAG combiner for by
535 /// implementing the PerformDAGCombine virtual method.
536 void setTargetDAGCombine(ISD::NodeType NT) {
537 TargetDAGCombineArray[NT >> 3] |= 1 << (NT&7);
542 //===--------------------------------------------------------------------===//
543 // Lowering methods - These methods must be implemented by targets so that
544 // the SelectionDAGLowering code knows how to lower these.
547 /// LowerArguments - This hook must be implemented to indicate how we should
548 /// lower the arguments for the specified function, into the specified DAG.
549 virtual std::vector<SDOperand>
550 LowerArguments(Function &F, SelectionDAG &DAG);
552 /// LowerCallTo - This hook lowers an abstract call to a function into an
553 /// actual call. This returns a pair of operands. The first element is the
554 /// return value for the function (if RetTy is not VoidTy). The second
555 /// element is the outgoing token chain.
556 typedef std::vector<std::pair<SDOperand, const Type*> > ArgListTy;
557 virtual std::pair<SDOperand, SDOperand>
558 LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg,
559 unsigned CallingConv, bool isTailCall, SDOperand Callee,
560 ArgListTy &Args, SelectionDAG &DAG);
562 /// LowerFrameReturnAddress - This hook lowers a call to llvm.returnaddress or
563 /// llvm.frameaddress (depending on the value of the first argument). The
564 /// return values are the result pointer and the resultant token chain. If
565 /// not implemented, both of these intrinsics will return null.
566 virtual std::pair<SDOperand, SDOperand>
567 LowerFrameReturnAddress(bool isFrameAddr, SDOperand Chain, unsigned Depth,
570 /// LowerOperation - This callback is invoked for operations that are
571 /// unsupported by the target, which are registered to use 'custom' lowering,
572 /// and whose defined values are all legal.
573 /// If the target has no operations that require custom lowering, it need not
574 /// implement this. The default implementation of this aborts.
575 virtual SDOperand LowerOperation(SDOperand Op, SelectionDAG &DAG);
577 /// CustomPromoteOperation - This callback is invoked for operations that are
578 /// unsupported by the target, are registered to use 'custom' lowering, and
579 /// whose type needs to be promoted.
580 virtual SDOperand CustomPromoteOperation(SDOperand Op, SelectionDAG &DAG);
582 /// getTargetNodeName() - This method returns the name of a target specific
584 virtual const char *getTargetNodeName(unsigned Opcode) const;
586 //===--------------------------------------------------------------------===//
587 // Inline Asm Support hooks
590 enum ConstraintType {
591 C_Register, // Constraint represents a single register.
592 C_RegisterClass, // Constraint represents one or more registers.
593 C_Memory, // Memory constraint.
594 C_Other, // Something else.
595 C_Unknown // Unsupported constraint.
598 /// getConstraintType - Given a constraint letter, return the type of
599 /// constraint it is for this target.
600 virtual ConstraintType getConstraintType(char ConstraintLetter) const;
603 /// getRegClassForInlineAsmConstraint - Given a constraint letter (e.g. "r"),
604 /// return a list of registers that can be used to satisfy the constraint.
605 /// This should only be used for C_RegisterClass constraints.
606 virtual std::vector<unsigned>
607 getRegClassForInlineAsmConstraint(const std::string &Constraint,
608 MVT::ValueType VT) const;
610 /// getRegForInlineAsmConstraint - Given a physical register constraint (e.g.
611 /// {edx}), return the register number and the register class for the
612 /// register. This should only be used for C_Register constraints. On error,
613 /// this returns a register number of 0.
614 virtual std::pair<unsigned, const TargetRegisterClass*>
615 getRegForInlineAsmConstraint(const std::string &Constraint,
616 MVT::ValueType VT) const;
619 /// isOperandValidForConstraint - Return true if the specified SDOperand is
620 /// valid for the specified target constraint letter.
621 virtual bool isOperandValidForConstraint(SDOperand Op, char ConstraintLetter);
623 //===--------------------------------------------------------------------===//
627 // InsertAtEndOfBasicBlock - This method should be implemented by targets that
628 // mark instructions with the 'usesCustomDAGSchedInserter' flag. These
629 // instructions are special in various ways, which require special support to
630 // insert. The specified MachineInstr is created but not inserted into any
631 // basic blocks, and the scheduler passes ownership of it to this method.
632 virtual MachineBasicBlock *InsertAtEndOfBasicBlock(MachineInstr *MI,
633 MachineBasicBlock *MBB);
635 //===--------------------------------------------------------------------===//
636 // Loop Strength Reduction hooks
639 /// isLegalAddressImmediate - Return true if the integer value or GlobalValue
640 /// can be used as the offset of the target addressing mode.
641 virtual bool isLegalAddressImmediate(int64_t V) const;
642 virtual bool isLegalAddressImmediate(GlobalValue *GV) const;
644 typedef std::vector<unsigned>::const_iterator legal_am_scale_iterator;
645 legal_am_scale_iterator legal_am_scale_begin() const {
646 return LegalAddressScales.begin();
648 legal_am_scale_iterator legal_am_scale_end() const {
649 return LegalAddressScales.end();
652 //===--------------------------------------------------------------------===//
653 // Div utility functions
655 SDOperand BuildSDIV(SDNode *N, SelectionDAG &DAG,
656 std::vector<SDNode*>* Created) const;
657 SDOperand BuildUDIV(SDNode *N, SelectionDAG &DAG,
658 std::vector<SDNode*>* Created) const;
662 /// addLegalAddressScale - Add a integer (> 1) value which can be used as
663 /// scale in the target addressing mode. Note: the ordering matters so the
664 /// least efficient ones should be entered first.
665 void addLegalAddressScale(unsigned Scale) {
666 LegalAddressScales.push_back(Scale);
670 std::vector<unsigned> LegalAddressScales;
673 const TargetData *TD;
675 /// IsLittleEndian - True if this is a little endian target.
679 /// PointerTy - The type to use for pointers, usually i32 or i64.
681 MVT::ValueType PointerTy;
683 /// ShiftAmountTy - The type to use for shift amounts, usually i8 or whatever
685 MVT::ValueType ShiftAmountTy;
687 OutOfRangeShiftAmount ShiftAmtHandling;
689 /// SetCCIsExpensive - This is a short term hack for targets that codegen
690 /// setcc as a conditional branch. This encourages the code generator to fold
691 /// setcc operations into other operations if possible.
692 bool SetCCIsExpensive;
694 /// IntDivIsCheap - Tells the code generator not to expand integer divides by
695 /// constants into a sequence of muls, adds, and shifts. This is a hack until
696 /// a real cost model is in place. If we ever optimize for size, this will be
697 /// set to true unconditionally.
700 /// Pow2DivIsCheap - Tells the code generator that it shouldn't generate
701 /// srl/add/sra for a signed divide by power of two, and let the target handle
705 /// SetCCResultTy - The type that SetCC operations use. This defaults to the
707 MVT::ValueType SetCCResultTy;
709 /// SetCCResultContents - Information about the contents of the high-bits in
710 /// the result of a setcc comparison operation.
711 SetCCResultValue SetCCResultContents;
713 /// SchedPreferenceInfo - The target scheduling preference: shortest possible
714 /// total cycles or lowest register usage.
715 SchedPreference SchedPreferenceInfo;
717 /// UseUnderscoreSetJmpLongJmp - This target prefers to use _setjmp and
718 /// _longjmp to implement llvm.setjmp/llvm.longjmp. Defaults to false.
719 bool UseUnderscoreSetJmpLongJmp;
721 /// StackPointerRegisterToSaveRestore - If set to a physical register, this
722 /// specifies the register that llvm.savestack/llvm.restorestack should save
724 unsigned StackPointerRegisterToSaveRestore;
726 /// RegClassForVT - This indicates the default register class to use for
727 /// each ValueType the target supports natively.
728 TargetRegisterClass *RegClassForVT[MVT::LAST_VALUETYPE];
729 unsigned char NumElementsForVT[MVT::LAST_VALUETYPE];
731 /// TransformToType - For any value types we are promoting or expanding, this
732 /// contains the value type that we are changing to. For Expanded types, this
733 /// contains one step of the expand (e.g. i64 -> i32), even if there are
734 /// multiple steps required (e.g. i64 -> i16). For types natively supported
735 /// by the system, this holds the same type (e.g. i32 -> i32).
736 MVT::ValueType TransformToType[MVT::LAST_VALUETYPE];
738 /// OpActions - For each operation and each value type, keep a LegalizeAction
739 /// that indicates how instruction selection should deal with the operation.
740 /// Most operations are Legal (aka, supported natively by the target), but
741 /// operations that are not should be described. Note that operations on
742 /// non-legal value types are not described here.
743 uint64_t OpActions[156];
745 ValueTypeActionImpl ValueTypeActions;
747 std::vector<double> LegalFPImmediates;
749 std::vector<std::pair<MVT::ValueType,
750 TargetRegisterClass*> > AvailableRegClasses;
752 /// TargetDAGCombineArray - Targets can specify ISD nodes that they would
753 /// like PerformDAGCombine callbacks for by calling setTargetDAGCombine(),
754 /// which sets a bit in this array.
755 unsigned char TargetDAGCombineArray[156/(sizeof(unsigned char)*8)];
757 /// PromoteToType - For operations that must be promoted to a specific type,
758 /// this holds the destination type. This map should be sparse, so don't hold
761 /// Targets add entries to this map with AddPromotedToType(..), clients access
762 /// this with getTypeToPromoteTo(..).
763 std::map<std::pair<unsigned, MVT::ValueType>, MVT::ValueType> PromoteToType;
766 /// When lowering %llvm.memset this field specifies the maximum number of
767 /// store operations that may be substituted for the call to memset. Targets
768 /// must set this value based on the cost threshold for that target. Targets
769 /// should assume that the memset will be done using as many of the largest
770 /// store operations first, followed by smaller ones, if necessary, per
771 /// alignment restrictions. For example, storing 9 bytes on a 32-bit machine
772 /// with 16-bit alignment would result in four 2-byte stores and one 1-byte
773 /// store. This only applies to setting a constant array of a constant size.
774 /// @brief Specify maximum number of store instructions per memset call.
775 unsigned maxStoresPerMemset;
777 /// When lowering %llvm.memcpy this field specifies the maximum number of
778 /// store operations that may be substituted for a call to memcpy. Targets
779 /// must set this value based on the cost threshold for that target. Targets
780 /// should assume that the memcpy will be done using as many of the largest
781 /// store operations first, followed by smaller ones, if necessary, per
782 /// alignment restrictions. For example, storing 7 bytes on a 32-bit machine
783 /// with 32-bit alignment would result in one 4-byte store, a one 2-byte store
784 /// and one 1-byte store. This only applies to copying a constant array of
786 /// @brief Specify maximum bytes of store instructions per memcpy call.
787 unsigned maxStoresPerMemcpy;
789 /// When lowering %llvm.memmove this field specifies the maximum number of
790 /// store instructions that may be substituted for a call to memmove. Targets
791 /// must set this value based on the cost threshold for that target. Targets
792 /// should assume that the memmove will be done using as many of the largest
793 /// store operations first, followed by smaller ones, if necessary, per
794 /// alignment restrictions. For example, moving 9 bytes on a 32-bit machine
795 /// with 8-bit alignment would result in nine 1-byte stores. This only
796 /// applies to copying a constant array of constant size.
797 /// @brief Specify maximum bytes of store instructions per memmove call.
798 unsigned maxStoresPerMemmove;
800 /// This field specifies whether the target machine permits unaligned memory
801 /// accesses. This is used, for example, to determine the size of store
802 /// operations when copying small arrays and other similar tasks.
803 /// @brief Indicate whether the target permits unaligned memory accesses.
804 bool allowUnalignedMemoryAccesses;
806 } // end llvm namespace