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 scalar types. For example, <8 x float> maps to 2 MVT::v2f32 values
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 /// getOperationAction - Return how this operation should be treated: either
196 /// it is legal, needs to be promoted to a larger size, needs to be
197 /// expanded to some other code sequence, or the target has a custom expander
199 LegalizeAction getOperationAction(unsigned Op, MVT::ValueType VT) const {
200 return (LegalizeAction)((OpActions[Op] >> (2*VT)) & 3);
203 /// isOperationLegal - Return true if the specified operation is legal on this
205 bool isOperationLegal(unsigned Op, MVT::ValueType VT) const {
206 return getOperationAction(Op, VT) == Legal ||
207 getOperationAction(Op, VT) == Custom;
211 /// isVectorShuffleLegal - Return true if a vector shuffle is legal with the
212 /// specified mask and type. Targets can specify exactly which masks they
213 /// support and the code generator is tasked with not creating illegal masks.
214 bool isShuffleLegal(MVT::ValueType VT, SDOperand Mask) const {
215 return isOperationLegal(ISD::VECTOR_SHUFFLE, VT) &&
216 isShuffleMaskLegal(Mask, VT);
219 /// getTypeToPromoteTo - If the action for this operation is to promote, this
220 /// method returns the ValueType to promote to.
221 MVT::ValueType getTypeToPromoteTo(unsigned Op, MVT::ValueType VT) const {
222 assert(getOperationAction(Op, VT) == Promote &&
223 "This operation isn't promoted!");
225 // See if this has an explicit type specified.
226 std::map<std::pair<unsigned, MVT::ValueType>,
227 MVT::ValueType>::const_iterator PTTI =
228 PromoteToType.find(std::make_pair(Op, VT));
229 if (PTTI != PromoteToType.end()) return PTTI->second;
231 assert((MVT::isInteger(VT) || MVT::isFloatingPoint(VT)) &&
232 "Cannot autopromote this type, add it with AddPromotedToType.");
234 MVT::ValueType NVT = VT;
236 NVT = (MVT::ValueType)(NVT+1);
237 assert(MVT::isInteger(NVT) == MVT::isInteger(VT) && NVT != MVT::isVoid &&
238 "Didn't find type to promote to!");
239 } while (!isTypeLegal(NVT) ||
240 getOperationAction(Op, NVT) == Promote);
244 /// getValueType - Return the MVT::ValueType corresponding to this LLVM type.
245 /// This is fixed by the LLVM operations except for the pointer size.
246 MVT::ValueType getValueType(const Type *Ty) const {
247 switch (Ty->getTypeID()) {
248 default: assert(0 && "Unknown type!");
249 case Type::VoidTyID: return MVT::isVoid;
250 case Type::BoolTyID: return MVT::i1;
251 case Type::UByteTyID:
252 case Type::SByteTyID: return MVT::i8;
253 case Type::ShortTyID:
254 case Type::UShortTyID: return MVT::i16;
256 case Type::UIntTyID: return MVT::i32;
258 case Type::ULongTyID: return MVT::i64;
259 case Type::FloatTyID: return MVT::f32;
260 case Type::DoubleTyID: return MVT::f64;
261 case Type::PointerTyID: return PointerTy;
262 case Type::PackedTyID: return MVT::Vector;
266 /// getNumElements - Return the number of registers that this ValueType will
267 /// eventually require. This is always one for all non-integer types, is
268 /// one for any types promoted to live in larger registers, but may be more
269 /// than one for types (like i64) that are split into pieces.
270 unsigned getNumElements(MVT::ValueType VT) const {
271 return NumElementsForVT[VT];
274 /// hasTargetDAGCombine - If true, the target has custom DAG combine
275 /// transformations that it can perform for the specified node.
276 bool hasTargetDAGCombine(ISD::NodeType NT) const {
277 return TargetDAGCombineArray[NT >> 3] & (1 << (NT&7));
280 /// This function returns the maximum number of store operations permitted
281 /// to replace a call to llvm.memset. The value is set by the target at the
282 /// performance threshold for such a replacement.
283 /// @brief Get maximum # of store operations permitted for llvm.memset
284 unsigned getMaxStoresPerMemset() const { return maxStoresPerMemset; }
286 /// This function returns the maximum number of store operations permitted
287 /// to replace a call to llvm.memcpy. The value is set by the target at the
288 /// performance threshold for such a replacement.
289 /// @brief Get maximum # of store operations permitted for llvm.memcpy
290 unsigned getMaxStoresPerMemcpy() const { return maxStoresPerMemcpy; }
292 /// This function returns the maximum number of store operations permitted
293 /// to replace a call to llvm.memmove. The value is set by the target at the
294 /// performance threshold for such a replacement.
295 /// @brief Get maximum # of store operations permitted for llvm.memmove
296 unsigned getMaxStoresPerMemmove() const { return maxStoresPerMemmove; }
298 /// This function returns true if the target allows unaligned memory accesses.
299 /// This is used, for example, in situations where an array copy/move/set is
300 /// converted to a sequence of store operations. It's use helps to ensure that
301 /// such replacements don't generate code that causes an alignment error
302 /// (trap) on the target machine.
303 /// @brief Determine if the target supports unaligned memory accesses.
304 bool allowsUnalignedMemoryAccesses() const {
305 return allowUnalignedMemoryAccesses;
308 /// usesUnderscoreSetJmpLongJmp - Determine if we should use _setjmp or setjmp
309 /// to implement llvm.setjmp.
310 bool usesUnderscoreSetJmpLongJmp() const {
311 return UseUnderscoreSetJmpLongJmp;
314 /// getStackPointerRegisterToSaveRestore - If a physical register, this
315 /// specifies the register that llvm.savestack/llvm.restorestack should save
317 unsigned getStackPointerRegisterToSaveRestore() const {
318 return StackPointerRegisterToSaveRestore;
321 //===--------------------------------------------------------------------===//
322 // TargetLowering Optimization Methods
325 /// TargetLoweringOpt - A convenience struct that encapsulates a DAG, and two
326 /// SDOperands for returning information from TargetLowering to its clients
327 /// that want to combine
328 struct TargetLoweringOpt {
333 TargetLoweringOpt(SelectionDAG &InDAG) : DAG(InDAG) {}
335 bool CombineTo(SDOperand O, SDOperand N) {
341 /// ShrinkDemandedConstant - Check to see if the specified operand of the
342 /// specified instruction is a constant integer. If so, check to see if there
343 /// are any bits set in the constant that are not demanded. If so, shrink the
344 /// constant and return true.
345 bool ShrinkDemandedConstant(SDOperand Op, uint64_t Demanded);
348 /// MaskedValueIsZero - Return true if 'Op & Mask' is known to be zero. We
349 /// use this predicate to simplify operations downstream. Op and Mask are
350 /// known to be the same type.
351 bool MaskedValueIsZero(SDOperand Op, uint64_t Mask, unsigned Depth = 0)
354 /// ComputeMaskedBits - Determine which of the bits specified in Mask are
355 /// known to be either zero or one and return them in the KnownZero/KnownOne
356 /// bitsets. This code only analyzes bits in Mask, in order to short-circuit
357 /// processing. Targets can implement the computeMaskedBitsForTargetNode
358 /// method, to allow target nodes to be understood.
359 void ComputeMaskedBits(SDOperand Op, uint64_t Mask, uint64_t &KnownZero,
360 uint64_t &KnownOne, unsigned Depth = 0) const;
362 /// SimplifyDemandedBits - Look at Op. At this point, we know that only the
363 /// DemandedMask bits of the result of Op are ever used downstream. If we can
364 /// use this information to simplify Op, create a new simplified DAG node and
365 /// return true, returning the original and new nodes in Old and New.
366 /// Otherwise, analyze the expression and return a mask of KnownOne and
367 /// KnownZero bits for the expression (used to simplify the caller).
368 /// The KnownZero/One bits may only be accurate for those bits in the
370 bool SimplifyDemandedBits(SDOperand Op, uint64_t DemandedMask,
371 uint64_t &KnownZero, uint64_t &KnownOne,
372 TargetLoweringOpt &TLO, unsigned Depth = 0) const;
374 /// computeMaskedBitsForTargetNode - Determine which of the bits specified in
375 /// Mask are known to be either zero or one and return them in the
376 /// KnownZero/KnownOne bitsets.
377 virtual void computeMaskedBitsForTargetNode(const SDOperand Op,
381 unsigned Depth = 0) const;
383 struct DAGCombinerInfo {
384 void *DC; // The DAG Combiner object.
389 DAGCombinerInfo(SelectionDAG &dag, bool bl, void *dc)
390 : DC(dc), BeforeLegalize(bl), DAG(dag) {}
392 bool isBeforeLegalize() const { return BeforeLegalize; }
394 void AddToWorklist(SDNode *N);
395 SDOperand CombineTo(SDNode *N, const std::vector<SDOperand> &To);
396 SDOperand CombineTo(SDNode *N, SDOperand Res);
397 SDOperand CombineTo(SDNode *N, SDOperand Res0, SDOperand Res1);
400 /// PerformDAGCombine - This method will be invoked for all target nodes and
401 /// for any target-independent nodes that the target has registered with
404 /// The semantics are as follows:
406 /// SDOperand.Val == 0 - No change was made
407 /// SDOperand.Val == N - N was replaced, is dead, and is already handled.
408 /// otherwise - N should be replaced by the returned Operand.
410 /// In addition, methods provided by DAGCombinerInfo may be used to perform
411 /// more complex transformations.
413 virtual SDOperand PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
415 //===--------------------------------------------------------------------===//
416 // TargetLowering Configuration Methods - These methods should be invoked by
417 // the derived class constructor to configure this object for the target.
422 /// setShiftAmountType - Describe the type that should be used for shift
423 /// amounts. This type defaults to the pointer type.
424 void setShiftAmountType(MVT::ValueType VT) { ShiftAmountTy = VT; }
426 /// setSetCCResultType - Describe the type that shoudl be used as the result
427 /// of a setcc operation. This defaults to the pointer type.
428 void setSetCCResultType(MVT::ValueType VT) { SetCCResultTy = VT; }
430 /// setSetCCResultContents - Specify how the target extends the result of a
431 /// setcc operation in a register.
432 void setSetCCResultContents(SetCCResultValue Ty) { SetCCResultContents = Ty; }
434 /// setSchedulingPreference - Specify the target scheduling preference.
435 void setSchedulingPreference(SchedPreference Pref) {
436 SchedPreferenceInfo = Pref;
439 /// setShiftAmountFlavor - Describe how the target handles out of range shift
441 void setShiftAmountFlavor(OutOfRangeShiftAmount OORSA) {
442 ShiftAmtHandling = OORSA;
445 /// setUseUnderscoreSetJmpLongJmp - Indicate whether this target prefers to
446 /// use _setjmp and _longjmp to or implement llvm.setjmp/llvm.longjmp or
447 /// the non _ versions. Defaults to false.
448 void setUseUnderscoreSetJmpLongJmp(bool Val) {
449 UseUnderscoreSetJmpLongJmp = Val;
452 /// setStackPointerRegisterToSaveRestore - If set to a physical register, this
453 /// specifies the register that llvm.savestack/llvm.restorestack should save
455 void setStackPointerRegisterToSaveRestore(unsigned R) {
456 StackPointerRegisterToSaveRestore = R;
459 /// setSetCCIxExpensive - This is a short term hack for targets that codegen
460 /// setcc as a conditional branch. This encourages the code generator to fold
461 /// setcc operations into other operations if possible.
462 void setSetCCIsExpensive() { SetCCIsExpensive = true; }
464 /// setIntDivIsCheap - Tells the code generator that integer divide is
465 /// expensive, and if possible, should be replaced by an alternate sequence
466 /// of instructions not containing an integer divide.
467 void setIntDivIsCheap(bool isCheap = true) { IntDivIsCheap = isCheap; }
469 /// setPow2DivIsCheap - Tells the code generator that it shouldn't generate
470 /// srl/add/sra for a signed divide by power of two, and let the target handle
472 void setPow2DivIsCheap(bool isCheap = true) { Pow2DivIsCheap = isCheap; }
474 /// addRegisterClass - Add the specified register class as an available
475 /// regclass for the specified value type. This indicates the selector can
476 /// handle values of that class natively.
477 void addRegisterClass(MVT::ValueType VT, TargetRegisterClass *RC) {
478 AvailableRegClasses.push_back(std::make_pair(VT, RC));
479 RegClassForVT[VT] = RC;
482 /// computeRegisterProperties - Once all of the register classes are added,
483 /// this allows us to compute derived properties we expose.
484 void computeRegisterProperties();
486 /// setOperationAction - Indicate that the specified operation does not work
487 /// with the specified type and indicate what to do about it.
488 void setOperationAction(unsigned Op, MVT::ValueType VT,
489 LegalizeAction Action) {
490 assert(VT < 32 && Op < sizeof(OpActions)/sizeof(OpActions[0]) &&
491 "Table isn't big enough!");
492 OpActions[Op] &= ~(3ULL << VT*2);
493 OpActions[Op] |= (uint64_t)Action << VT*2;
496 /// AddPromotedToType - If Opc/OrigVT is specified as being promoted, the
497 /// promotion code defaults to trying a larger integer/fp until it can find
498 /// one that works. If that default is insufficient, this method can be used
499 /// by the target to override the default.
500 void AddPromotedToType(unsigned Opc, MVT::ValueType OrigVT,
501 MVT::ValueType DestVT) {
502 PromoteToType[std::make_pair(Opc, OrigVT)] = DestVT;
505 /// addLegalFPImmediate - Indicate that this target can instruction select
506 /// the specified FP immediate natively.
507 void addLegalFPImmediate(double Imm) {
508 LegalFPImmediates.push_back(Imm);
511 /// setTargetDAGCombine - Targets should invoke this method for each target
512 /// independent node that they want to provide a custom DAG combiner for by
513 /// implementing the PerformDAGCombine virtual method.
514 void setTargetDAGCombine(ISD::NodeType NT) {
515 TargetDAGCombineArray[NT >> 3] |= 1 << (NT&7);
518 /// isShuffleMaskLegal - Targets can use this to indicate that they only
519 /// support *some* VECTOR_SHUFFLE operations, those with specific masks.
520 /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values
521 /// are assumed to be legal.
522 virtual bool isShuffleMaskLegal(SDOperand Mask, MVT::ValueType VT) const {
528 //===--------------------------------------------------------------------===//
529 // Lowering methods - These methods must be implemented by targets so that
530 // the SelectionDAGLowering code knows how to lower these.
533 /// LowerArguments - This hook must be implemented to indicate how we should
534 /// lower the arguments for the specified function, into the specified DAG.
535 virtual std::vector<SDOperand>
536 LowerArguments(Function &F, SelectionDAG &DAG) = 0;
538 /// LowerCallTo - This hook lowers an abstract call to a function into an
539 /// actual call. This returns a pair of operands. The first element is the
540 /// return value for the function (if RetTy is not VoidTy). The second
541 /// element is the outgoing token chain.
542 typedef std::vector<std::pair<SDOperand, const Type*> > ArgListTy;
543 virtual std::pair<SDOperand, SDOperand>
544 LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg,
545 unsigned CallingConv, bool isTailCall, SDOperand Callee,
546 ArgListTy &Args, SelectionDAG &DAG) = 0;
548 /// LowerFrameReturnAddress - This hook lowers a call to llvm.returnaddress or
549 /// llvm.frameaddress (depending on the value of the first argument). The
550 /// return values are the result pointer and the resultant token chain. If
551 /// not implemented, both of these intrinsics will return null.
552 virtual std::pair<SDOperand, SDOperand>
553 LowerFrameReturnAddress(bool isFrameAddr, SDOperand Chain, unsigned Depth,
556 /// LowerOperation - This callback is invoked for operations that are
557 /// unsupported by the target, which are registered to use 'custom' lowering,
558 /// and whose defined values are all legal.
559 /// If the target has no operations that require custom lowering, it need not
560 /// implement this. The default implementation of this aborts.
561 virtual SDOperand LowerOperation(SDOperand Op, SelectionDAG &DAG);
563 /// CustomPromoteOperation - This callback is invoked for operations that are
564 /// unsupported by the target, are registered to use 'custom' lowering, and
565 /// whose type needs to be promoted.
566 virtual SDOperand CustomPromoteOperation(SDOperand Op, SelectionDAG &DAG);
568 /// getTargetNodeName() - This method returns the name of a target specific
570 virtual const char *getTargetNodeName(unsigned Opcode) const;
572 //===--------------------------------------------------------------------===//
573 // Inline Asm Support hooks
576 enum ConstraintType {
577 C_Register, // Constraint represents a single register.
578 C_RegisterClass, // Constraint represents one or more registers.
579 C_Memory, // Memory constraint.
580 C_Other, // Something else.
581 C_Unknown // Unsupported constraint.
584 /// getConstraintType - Given a constraint letter, return the type of
585 /// constraint it is for this target.
586 virtual ConstraintType getConstraintType(char ConstraintLetter) const;
589 /// getRegClassForInlineAsmConstraint - Given a constraint letter (e.g. "r"),
590 /// return a list of registers that can be used to satisfy the constraint.
591 /// This should only be used for C_RegisterClass constraints.
592 virtual std::vector<unsigned>
593 getRegClassForInlineAsmConstraint(const std::string &Constraint,
594 MVT::ValueType VT) const;
596 /// getRegForInlineAsmConstraint - Given a physical register constraint (e.g.
597 /// {edx}), return the register number and the register class for the
598 /// register. This should only be used for C_Register constraints. On error,
599 /// this returns a register number of 0.
600 virtual std::pair<unsigned, const TargetRegisterClass*>
601 getRegForInlineAsmConstraint(const std::string &Constraint,
602 MVT::ValueType VT) const;
605 /// isOperandValidForConstraint - Return true if the specified SDOperand is
606 /// valid for the specified target constraint letter.
607 virtual bool isOperandValidForConstraint(SDOperand Op, char ConstraintLetter);
609 //===--------------------------------------------------------------------===//
613 // InsertAtEndOfBasicBlock - This method should be implemented by targets that
614 // mark instructions with the 'usesCustomDAGSchedInserter' flag. These
615 // instructions are special in various ways, which require special support to
616 // insert. The specified MachineInstr is created but not inserted into any
617 // basic blocks, and the scheduler passes ownership of it to this method.
618 virtual MachineBasicBlock *InsertAtEndOfBasicBlock(MachineInstr *MI,
619 MachineBasicBlock *MBB);
621 //===--------------------------------------------------------------------===//
622 // Loop Strength Reduction hooks
625 /// isLegalAddressImmediate - Return true if the integer value or GlobalValue
626 /// can be used as the offset of the target addressing mode.
627 virtual bool isLegalAddressImmediate(int64_t V) const;
628 virtual bool isLegalAddressImmediate(GlobalValue *GV) const;
630 typedef std::vector<unsigned>::const_iterator legal_am_scale_iterator;
631 legal_am_scale_iterator legal_am_scale_begin() const {
632 return LegalAddressScales.begin();
634 legal_am_scale_iterator legal_am_scale_end() const {
635 return LegalAddressScales.end();
639 /// addLegalAddressScale - Add a integer (> 1) value which can be used as
640 /// scale in the target addressing mode. Note: the ordering matters so the
641 /// least efficient ones should be entered first.
642 void addLegalAddressScale(unsigned Scale) {
643 LegalAddressScales.push_back(Scale);
647 std::vector<unsigned> LegalAddressScales;
650 const TargetData &TD;
652 /// IsLittleEndian - True if this is a little endian target.
656 /// PointerTy - The type to use for pointers, usually i32 or i64.
658 MVT::ValueType PointerTy;
660 /// ShiftAmountTy - The type to use for shift amounts, usually i8 or whatever
662 MVT::ValueType ShiftAmountTy;
664 OutOfRangeShiftAmount ShiftAmtHandling;
666 /// SetCCIsExpensive - This is a short term hack for targets that codegen
667 /// setcc as a conditional branch. This encourages the code generator to fold
668 /// setcc operations into other operations if possible.
669 bool SetCCIsExpensive;
671 /// IntDivIsCheap - Tells the code generator not to expand integer divides by
672 /// constants into a sequence of muls, adds, and shifts. This is a hack until
673 /// a real cost model is in place. If we ever optimize for size, this will be
674 /// set to true unconditionally.
677 /// Pow2DivIsCheap - Tells the code generator that it shouldn't generate
678 /// srl/add/sra for a signed divide by power of two, and let the target handle
682 /// SetCCResultTy - The type that SetCC operations use. This defaults to the
684 MVT::ValueType SetCCResultTy;
686 /// SetCCResultContents - Information about the contents of the high-bits in
687 /// the result of a setcc comparison operation.
688 SetCCResultValue SetCCResultContents;
690 /// SchedPreferenceInfo - The target scheduling preference: shortest possible
691 /// total cycles or lowest register usage.
692 SchedPreference SchedPreferenceInfo;
694 /// UseUnderscoreSetJmpLongJmp - This target prefers to use _setjmp and
695 /// _longjmp to implement llvm.setjmp/llvm.longjmp. Defaults to false.
696 bool UseUnderscoreSetJmpLongJmp;
698 /// StackPointerRegisterToSaveRestore - If set to a physical register, this
699 /// specifies the register that llvm.savestack/llvm.restorestack should save
701 unsigned StackPointerRegisterToSaveRestore;
703 /// RegClassForVT - This indicates the default register class to use for
704 /// each ValueType the target supports natively.
705 TargetRegisterClass *RegClassForVT[MVT::LAST_VALUETYPE];
706 unsigned char NumElementsForVT[MVT::LAST_VALUETYPE];
708 /// TransformToType - For any value types we are promoting or expanding, this
709 /// contains the value type that we are changing to. For Expanded types, this
710 /// contains one step of the expand (e.g. i64 -> i32), even if there are
711 /// multiple steps required (e.g. i64 -> i16). For types natively supported
712 /// by the system, this holds the same type (e.g. i32 -> i32).
713 MVT::ValueType TransformToType[MVT::LAST_VALUETYPE];
715 /// OpActions - For each operation and each value type, keep a LegalizeAction
716 /// that indicates how instruction selection should deal with the operation.
717 /// Most operations are Legal (aka, supported natively by the target), but
718 /// operations that are not should be described. Note that operations on
719 /// non-legal value types are not described here.
720 uint64_t OpActions[156];
722 ValueTypeActionImpl ValueTypeActions;
724 std::vector<double> LegalFPImmediates;
726 std::vector<std::pair<MVT::ValueType,
727 TargetRegisterClass*> > AvailableRegClasses;
729 /// TargetDAGCombineArray - Targets can specify ISD nodes that they would
730 /// like PerformDAGCombine callbacks for by calling setTargetDAGCombine(),
731 /// which sets a bit in this array.
732 unsigned char TargetDAGCombineArray[156/(sizeof(unsigned char)*8)];
734 /// PromoteToType - For operations that must be promoted to a specific type,
735 /// this holds the destination type. This map should be sparse, so don't hold
738 /// Targets add entries to this map with AddPromotedToType(..), clients access
739 /// this with getTypeToPromoteTo(..).
740 std::map<std::pair<unsigned, MVT::ValueType>, MVT::ValueType> PromoteToType;
743 /// When lowering %llvm.memset this field specifies the maximum number of
744 /// store operations that may be substituted for the call to memset. Targets
745 /// must set this value based on the cost threshold for that target. Targets
746 /// should assume that the memset will be done using as many of the largest
747 /// store operations first, followed by smaller ones, if necessary, per
748 /// alignment restrictions. For example, storing 9 bytes on a 32-bit machine
749 /// with 16-bit alignment would result in four 2-byte stores and one 1-byte
750 /// store. This only applies to setting a constant array of a constant size.
751 /// @brief Specify maximum number of store instructions per memset call.
752 unsigned maxStoresPerMemset;
754 /// When lowering %llvm.memcpy this field specifies the maximum number of
755 /// store operations that may be substituted for a call to memcpy. Targets
756 /// must set this value based on the cost threshold for that target. Targets
757 /// should assume that the memcpy will be done using as many of the largest
758 /// store operations first, followed by smaller ones, if necessary, per
759 /// alignment restrictions. For example, storing 7 bytes on a 32-bit machine
760 /// with 32-bit alignment would result in one 4-byte store, a one 2-byte store
761 /// and one 1-byte store. This only applies to copying a constant array of
763 /// @brief Specify maximum bytes of store instructions per memcpy call.
764 unsigned maxStoresPerMemcpy;
766 /// When lowering %llvm.memmove this field specifies the maximum number of
767 /// store instructions that may be substituted for a call to memmove. Targets
768 /// must set this value based on the cost threshold for that target. Targets
769 /// should assume that the memmove 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, moving 9 bytes on a 32-bit machine
772 /// with 8-bit alignment would result in nine 1-byte stores. This only
773 /// applies to copying a constant array of constant size.
774 /// @brief Specify maximum bytes of store instructions per memmove call.
775 unsigned maxStoresPerMemmove;
777 /// This field specifies whether the target machine permits unaligned memory
778 /// accesses. This is used, for example, to determine the size of store
779 /// operations when copying small arrays and other similar tasks.
780 /// @brief Indicate whether the target permits unaligned memory accesses.
781 bool allowUnalignedMemoryAccesses;
783 } // end llvm namespace