LLVM API Documentation
00001 //===-- llvm/Target/TargetLowering.h - Target Lowering Info -----*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file describes how to lower LLVM code to machine code. This has two 00011 // main components: 00012 // 00013 // 1. Which ValueTypes are natively supported by the target. 00014 // 2. Which operations are supported for supported ValueTypes. 00015 // 3. Cost thresholds for alternative implementations of certain operations. 00016 // 00017 // In addition it has a few other components, like information about FP 00018 // immediates. 00019 // 00020 //===----------------------------------------------------------------------===// 00021 00022 #ifndef LLVM_TARGET_TARGETLOWERING_H 00023 #define LLVM_TARGET_TARGETLOWERING_H 00024 00025 #include "llvm/ADT/DenseMap.h" 00026 #include "llvm/CodeGen/DAGCombine.h" 00027 #include "llvm/CodeGen/RuntimeLibcalls.h" 00028 #include "llvm/CodeGen/SelectionDAGNodes.h" 00029 #include "llvm/IR/Attributes.h" 00030 #include "llvm/IR/CallingConv.h" 00031 #include "llvm/IR/InlineAsm.h" 00032 #include "llvm/Support/CallSite.h" 00033 #include "llvm/Target/TargetCallingConv.h" 00034 #include "llvm/Target/TargetMachine.h" 00035 #include <climits> 00036 #include <map> 00037 #include <vector> 00038 00039 namespace llvm { 00040 class CallInst; 00041 class CCState; 00042 class FastISel; 00043 class FunctionLoweringInfo; 00044 class ImmutableCallSite; 00045 class IntrinsicInst; 00046 class MachineBasicBlock; 00047 class MachineFunction; 00048 class MachineInstr; 00049 class MachineJumpTableInfo; 00050 class MCContext; 00051 class MCExpr; 00052 template<typename T> class SmallVectorImpl; 00053 class DataLayout; 00054 class TargetRegisterClass; 00055 class TargetLibraryInfo; 00056 class TargetLoweringObjectFile; 00057 class Value; 00058 00059 namespace Sched { 00060 enum Preference { 00061 None, // No preference 00062 Source, // Follow source order. 00063 RegPressure, // Scheduling for lowest register pressure. 00064 Hybrid, // Scheduling for both latency and register pressure. 00065 ILP, // Scheduling for ILP in low register pressure mode. 00066 VLIW // Scheduling for VLIW targets. 00067 }; 00068 } 00069 00070 /// TargetLoweringBase - This base class for TargetLowering contains the 00071 /// SelectionDAG-independent parts that can be used from the rest of CodeGen. 00072 class TargetLoweringBase { 00073 TargetLoweringBase(const TargetLoweringBase&) LLVM_DELETED_FUNCTION; 00074 void operator=(const TargetLoweringBase&) LLVM_DELETED_FUNCTION; 00075 00076 public: 00077 /// LegalizeAction - This enum indicates whether operations are valid for a 00078 /// target, and if not, what action should be used to make them valid. 00079 enum LegalizeAction { 00080 Legal, // The target natively supports this operation. 00081 Promote, // This operation should be executed in a larger type. 00082 Expand, // Try to expand this to other ops, otherwise use a libcall. 00083 Custom // Use the LowerOperation hook to implement custom lowering. 00084 }; 00085 00086 /// LegalizeTypeAction - This enum indicates whether a types are legal for a 00087 /// target, and if not, what action should be used to make them valid. 00088 enum LegalizeTypeAction { 00089 TypeLegal, // The target natively supports this type. 00090 TypePromoteInteger, // Replace this integer with a larger one. 00091 TypeExpandInteger, // Split this integer into two of half the size. 00092 TypeSoftenFloat, // Convert this float to a same size integer type. 00093 TypeExpandFloat, // Split this float into two of half the size. 00094 TypeScalarizeVector, // Replace this one-element vector with its element. 00095 TypeSplitVector, // Split this vector into two of half the size. 00096 TypeWidenVector // This vector should be widened into a larger vector. 00097 }; 00098 00099 /// LegalizeKind holds the legalization kind that needs to happen to EVT 00100 /// in order to type-legalize it. 00101 typedef std::pair<LegalizeTypeAction, EVT> LegalizeKind; 00102 00103 enum BooleanContent { // How the target represents true/false values. 00104 UndefinedBooleanContent, // Only bit 0 counts, the rest can hold garbage. 00105 ZeroOrOneBooleanContent, // All bits zero except for bit 0. 00106 ZeroOrNegativeOneBooleanContent // All bits equal to bit 0. 00107 }; 00108 00109 enum SelectSupportKind { 00110 ScalarValSelect, // The target supports scalar selects (ex: cmov). 00111 ScalarCondVectorVal, // The target supports selects with a scalar condition 00112 // and vector values (ex: cmov). 00113 VectorMaskSelect // The target supports vector selects with a vector 00114 // mask (ex: x86 blends). 00115 }; 00116 00117 static ISD::NodeType getExtendForContent(BooleanContent Content) { 00118 switch (Content) { 00119 case UndefinedBooleanContent: 00120 // Extend by adding rubbish bits. 00121 return ISD::ANY_EXTEND; 00122 case ZeroOrOneBooleanContent: 00123 // Extend by adding zero bits. 00124 return ISD::ZERO_EXTEND; 00125 case ZeroOrNegativeOneBooleanContent: 00126 // Extend by copying the sign bit. 00127 return ISD::SIGN_EXTEND; 00128 } 00129 llvm_unreachable("Invalid content kind"); 00130 } 00131 00132 /// NOTE: The constructor takes ownership of TLOF. 00133 explicit TargetLoweringBase(const TargetMachine &TM, 00134 const TargetLoweringObjectFile *TLOF); 00135 virtual ~TargetLoweringBase(); 00136 00137 protected: 00138 /// \brief Initialize all of the actions to default values. 00139 void initActions(); 00140 00141 public: 00142 const TargetMachine &getTargetMachine() const { return TM; } 00143 const DataLayout *getDataLayout() const { return TD; } 00144 const TargetLoweringObjectFile &getObjFileLowering() const { return TLOF; } 00145 00146 bool isBigEndian() const { return !IsLittleEndian; } 00147 bool isLittleEndian() const { return IsLittleEndian; } 00148 // Return the pointer type for the given address space, defaults to 00149 // the pointer type from the data layout. 00150 // FIXME: The default needs to be removed once all the code is updated. 00151 virtual MVT getPointerTy(uint32_t /*AS*/ = 0) const { return PointerTy; } 00152 virtual MVT getScalarShiftAmountTy(EVT LHSTy) const; 00153 00154 EVT getShiftAmountTy(EVT LHSTy) const; 00155 00156 /// isSelectExpensive - Return true if the select operation is expensive for 00157 /// this target. 00158 bool isSelectExpensive() const { return SelectIsExpensive; } 00159 00160 virtual bool isSelectSupported(SelectSupportKind /*kind*/) const { 00161 return true; 00162 } 00163 00164 /// shouldSplitVectorElementType - Return true if a vector of the given type 00165 /// should be split (TypeSplitVector) instead of promoted 00166 /// (TypePromoteInteger) during type legalization. 00167 virtual bool shouldSplitVectorElementType(EVT /*VT*/) const { return false; } 00168 00169 /// isIntDivCheap() - Return true if integer divide is usually cheaper than 00170 /// a sequence of several shifts, adds, and multiplies for this target. 00171 bool isIntDivCheap() const { return IntDivIsCheap; } 00172 00173 /// isSlowDivBypassed - Returns true if target has indicated at least one 00174 /// type should be bypassed. 00175 bool isSlowDivBypassed() const { return !BypassSlowDivWidths.empty(); } 00176 00177 /// getBypassSlowDivTypes - Returns map of slow types for division or 00178 /// remainder with corresponding fast types 00179 const DenseMap<unsigned int, unsigned int> &getBypassSlowDivWidths() const { 00180 return BypassSlowDivWidths; 00181 } 00182 00183 /// isPow2DivCheap() - Return true if pow2 div is cheaper than a chain of 00184 /// srl/add/sra. 00185 bool isPow2DivCheap() const { return Pow2DivIsCheap; } 00186 00187 /// isJumpExpensive() - Return true if Flow Control is an expensive operation 00188 /// that should be avoided. 00189 bool isJumpExpensive() const { return JumpIsExpensive; } 00190 00191 /// isPredictableSelectExpensive - Return true if selects are only cheaper 00192 /// than branches if the branch is unlikely to be predicted right. 00193 bool isPredictableSelectExpensive() const { 00194 return PredictableSelectIsExpensive; 00195 } 00196 00197 /// getSetCCResultType - Return the ValueType of the result of SETCC 00198 /// operations. Also used to obtain the target's preferred type for 00199 /// the condition operand of SELECT and BRCOND nodes. In the case of 00200 /// BRCOND the argument passed is MVT::Other since there are no other 00201 /// operands to get a type hint from. 00202 virtual EVT getSetCCResultType(LLVMContext &Context, EVT VT) const; 00203 00204 /// getCmpLibcallReturnType - Return the ValueType for comparison 00205 /// libcalls. Comparions libcalls include floating point comparion calls, 00206 /// and Ordered/Unordered check calls on floating point numbers. 00207 virtual 00208 MVT::SimpleValueType getCmpLibcallReturnType() const; 00209 00210 /// getBooleanContents - For targets without i1 registers, this gives the 00211 /// nature of the high-bits of boolean values held in types wider than i1. 00212 /// "Boolean values" are special true/false values produced by nodes like 00213 /// SETCC and consumed (as the condition) by nodes like SELECT and BRCOND. 00214 /// Not to be confused with general values promoted from i1. 00215 /// Some cpus distinguish between vectors of boolean and scalars; the isVec 00216 /// parameter selects between the two kinds. For example on X86 a scalar 00217 /// boolean should be zero extended from i1, while the elements of a vector 00218 /// of booleans should be sign extended from i1. 00219 BooleanContent getBooleanContents(bool isVec) const { 00220 return isVec ? BooleanVectorContents : BooleanContents; 00221 } 00222 00223 /// getSchedulingPreference - Return target scheduling preference. 00224 Sched::Preference getSchedulingPreference() const { 00225 return SchedPreferenceInfo; 00226 } 00227 00228 /// getSchedulingPreference - Some scheduler, e.g. hybrid, can switch to 00229 /// different scheduling heuristics for different nodes. This function returns 00230 /// the preference (or none) for the given node. 00231 virtual Sched::Preference getSchedulingPreference(SDNode *) const { 00232 return Sched::None; 00233 } 00234 00235 /// getRegClassFor - Return the register class that should be used for the 00236 /// specified value type. 00237 virtual const TargetRegisterClass *getRegClassFor(MVT VT) const { 00238 const TargetRegisterClass *RC = RegClassForVT[VT.SimpleTy]; 00239 assert(RC && "This value type is not natively supported!"); 00240 return RC; 00241 } 00242 00243 /// getRepRegClassFor - Return the 'representative' register class for the 00244 /// specified value type. The 'representative' register class is the largest 00245 /// legal super-reg register class for the register class of the value type. 00246 /// For example, on i386 the rep register class for i8, i16, and i32 are GR32; 00247 /// while the rep register class is GR64 on x86_64. 00248 virtual const TargetRegisterClass *getRepRegClassFor(MVT VT) const { 00249 const TargetRegisterClass *RC = RepRegClassForVT[VT.SimpleTy]; 00250 return RC; 00251 } 00252 00253 /// getRepRegClassCostFor - Return the cost of the 'representative' register 00254 /// class for the specified value type. 00255 virtual uint8_t getRepRegClassCostFor(MVT VT) const { 00256 return RepRegClassCostForVT[VT.SimpleTy]; 00257 } 00258 00259 /// isTypeLegal - Return true if the target has native support for the 00260 /// specified value type. This means that it has a register that directly 00261 /// holds it without promotions or expansions. 00262 bool isTypeLegal(EVT VT) const { 00263 assert(!VT.isSimple() || 00264 (unsigned)VT.getSimpleVT().SimpleTy < array_lengthof(RegClassForVT)); 00265 return VT.isSimple() && RegClassForVT[VT.getSimpleVT().SimpleTy] != 0; 00266 } 00267 00268 class ValueTypeActionImpl { 00269 /// ValueTypeActions - For each value type, keep a LegalizeTypeAction enum 00270 /// that indicates how instruction selection should deal with the type. 00271 uint8_t ValueTypeActions[MVT::LAST_VALUETYPE]; 00272 00273 public: 00274 ValueTypeActionImpl() { 00275 std::fill(ValueTypeActions, array_endof(ValueTypeActions), 0); 00276 } 00277 00278 LegalizeTypeAction getTypeAction(MVT VT) const { 00279 return (LegalizeTypeAction)ValueTypeActions[VT.SimpleTy]; 00280 } 00281 00282 void setTypeAction(MVT VT, LegalizeTypeAction Action) { 00283 unsigned I = VT.SimpleTy; 00284 ValueTypeActions[I] = Action; 00285 } 00286 }; 00287 00288 const ValueTypeActionImpl &getValueTypeActions() const { 00289 return ValueTypeActions; 00290 } 00291 00292 /// getTypeAction - Return how we should legalize values of this type, either 00293 /// it is already legal (return 'Legal') or we need to promote it to a larger 00294 /// type (return 'Promote'), or we need to expand it into multiple registers 00295 /// of smaller integer type (return 'Expand'). 'Custom' is not an option. 00296 LegalizeTypeAction getTypeAction(LLVMContext &Context, EVT VT) const { 00297 return getTypeConversion(Context, VT).first; 00298 } 00299 LegalizeTypeAction getTypeAction(MVT VT) const { 00300 return ValueTypeActions.getTypeAction(VT); 00301 } 00302 00303 /// getTypeToTransformTo - For types supported by the target, this is an 00304 /// identity function. For types that must be promoted to larger types, this 00305 /// returns the larger type to promote to. For integer types that are larger 00306 /// than the largest integer register, this contains one step in the expansion 00307 /// to get to the smaller register. For illegal floating point types, this 00308 /// returns the integer type to transform to. 00309 EVT getTypeToTransformTo(LLVMContext &Context, EVT VT) const { 00310 return getTypeConversion(Context, VT).second; 00311 } 00312 00313 /// getTypeToExpandTo - For types supported by the target, this is an 00314 /// identity function. For types that must be expanded (i.e. integer types 00315 /// that are larger than the largest integer register or illegal floating 00316 /// point types), this returns the largest legal type it will be expanded to. 00317 EVT getTypeToExpandTo(LLVMContext &Context, EVT VT) const { 00318 assert(!VT.isVector()); 00319 while (true) { 00320 switch (getTypeAction(Context, VT)) { 00321 case TypeLegal: 00322 return VT; 00323 case TypeExpandInteger: 00324 VT = getTypeToTransformTo(Context, VT); 00325 break; 00326 default: 00327 llvm_unreachable("Type is not legal nor is it to be expanded!"); 00328 } 00329 } 00330 } 00331 00332 /// getVectorTypeBreakdown - Vector types are broken down into some number of 00333 /// legal first class types. For example, EVT::v8f32 maps to 2 EVT::v4f32 00334 /// with Altivec or SSE1, or 8 promoted EVT::f64 values with the X86 FP stack. 00335 /// Similarly, EVT::v2i64 turns into 4 EVT::i32 values with both PPC and X86. 00336 /// 00337 /// This method returns the number of registers needed, and the VT for each 00338 /// register. It also returns the VT and quantity of the intermediate values 00339 /// before they are promoted/expanded. 00340 /// 00341 unsigned getVectorTypeBreakdown(LLVMContext &Context, EVT VT, 00342 EVT &IntermediateVT, 00343 unsigned &NumIntermediates, 00344 MVT &RegisterVT) const; 00345 00346 /// getTgtMemIntrinsic: Given an intrinsic, checks if on the target the 00347 /// intrinsic will need to map to a MemIntrinsicNode (touches memory). If 00348 /// this is the case, it returns true and store the intrinsic 00349 /// information into the IntrinsicInfo that was passed to the function. 00350 struct IntrinsicInfo { 00351 unsigned opc; // target opcode 00352 EVT memVT; // memory VT 00353 const Value* ptrVal; // value representing memory location 00354 int offset; // offset off of ptrVal 00355 unsigned align; // alignment 00356 bool vol; // is volatile? 00357 bool readMem; // reads memory? 00358 bool writeMem; // writes memory? 00359 }; 00360 00361 virtual bool getTgtMemIntrinsic(IntrinsicInfo &, const CallInst &, 00362 unsigned /*Intrinsic*/) const { 00363 return false; 00364 } 00365 00366 /// isFPImmLegal - Returns true if the target can instruction select the 00367 /// specified FP immediate natively. If false, the legalizer will materialize 00368 /// the FP immediate as a load from a constant pool. 00369 virtual bool isFPImmLegal(const APFloat &/*Imm*/, EVT /*VT*/) const { 00370 return false; 00371 } 00372 00373 /// isShuffleMaskLegal - Targets can use this to indicate that they only 00374 /// support *some* VECTOR_SHUFFLE operations, those with specific masks. 00375 /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values 00376 /// are assumed to be legal. 00377 virtual bool isShuffleMaskLegal(const SmallVectorImpl<int> &/*Mask*/, 00378 EVT /*VT*/) const { 00379 return true; 00380 } 00381 00382 /// canOpTrap - Returns true if the operation can trap for the value type. 00383 /// VT must be a legal type. By default, we optimistically assume most 00384 /// operations don't trap except for divide and remainder. 00385 virtual bool canOpTrap(unsigned Op, EVT VT) const; 00386 00387 /// isVectorClearMaskLegal - Similar to isShuffleMaskLegal. This is 00388 /// used by Targets can use this to indicate if there is a suitable 00389 /// VECTOR_SHUFFLE that can be used to replace a VAND with a constant 00390 /// pool entry. 00391 virtual bool isVectorClearMaskLegal(const SmallVectorImpl<int> &/*Mask*/, 00392 EVT /*VT*/) const { 00393 return false; 00394 } 00395 00396 /// getOperationAction - Return how this operation should be treated: either 00397 /// it is legal, needs to be promoted to a larger size, needs to be 00398 /// expanded to some other code sequence, or the target has a custom expander 00399 /// for it. 00400 LegalizeAction getOperationAction(unsigned Op, EVT VT) const { 00401 if (VT.isExtended()) return Expand; 00402 // If a target-specific SDNode requires legalization, require the target 00403 // to provide custom legalization for it. 00404 if (Op > array_lengthof(OpActions[0])) return Custom; 00405 unsigned I = (unsigned) VT.getSimpleVT().SimpleTy; 00406 return (LegalizeAction)OpActions[I][Op]; 00407 } 00408 00409 /// isOperationLegalOrCustom - Return true if the specified operation is 00410 /// legal on this target or can be made legal with custom lowering. This 00411 /// is used to help guide high-level lowering decisions. 00412 bool isOperationLegalOrCustom(unsigned Op, EVT VT) const { 00413 return (VT == MVT::Other || isTypeLegal(VT)) && 00414 (getOperationAction(Op, VT) == Legal || 00415 getOperationAction(Op, VT) == Custom); 00416 } 00417 00418 /// isOperationLegalOrPromote - Return true if the specified operation is 00419 /// legal on this target or can be made legal using promotion. This 00420 /// is used to help guide high-level lowering decisions. 00421 bool isOperationLegalOrPromote(unsigned Op, EVT VT) const { 00422 return (VT == MVT::Other || isTypeLegal(VT)) && 00423 (getOperationAction(Op, VT) == Legal || 00424 getOperationAction(Op, VT) == Promote); 00425 } 00426 00427 /// isOperationExpand - Return true if the specified operation is illegal on 00428 /// this target or unlikely to be made legal with custom lowering. This is 00429 /// used to help guide high-level lowering decisions. 00430 bool isOperationExpand(unsigned Op, EVT VT) const { 00431 return (!isTypeLegal(VT) || getOperationAction(Op, VT) == Expand); 00432 } 00433 00434 /// isOperationLegal - Return true if the specified operation is legal on this 00435 /// target. 00436 bool isOperationLegal(unsigned Op, EVT VT) const { 00437 return (VT == MVT::Other || isTypeLegal(VT)) && 00438 getOperationAction(Op, VT) == Legal; 00439 } 00440 00441 /// getLoadExtAction - Return how this load with extension should be treated: 00442 /// either it is legal, needs to be promoted to a larger size, needs to be 00443 /// expanded to some other code sequence, or the target has a custom expander 00444 /// for it. 00445 LegalizeAction getLoadExtAction(unsigned ExtType, MVT VT) const { 00446 assert(ExtType < ISD::LAST_LOADEXT_TYPE && VT < MVT::LAST_VALUETYPE && 00447 "Table isn't big enough!"); 00448 return (LegalizeAction)LoadExtActions[VT.SimpleTy][ExtType]; 00449 } 00450 00451 /// isLoadExtLegal - Return true if the specified load with extension is legal 00452 /// on this target. 00453 bool isLoadExtLegal(unsigned ExtType, EVT VT) const { 00454 return VT.isSimple() && 00455 getLoadExtAction(ExtType, VT.getSimpleVT()) == Legal; 00456 } 00457 00458 /// getTruncStoreAction - Return how this store with truncation should be 00459 /// treated: either it is legal, needs to be promoted to a larger size, needs 00460 /// to be expanded to some other code sequence, or the target has a custom 00461 /// expander for it. 00462 LegalizeAction getTruncStoreAction(MVT ValVT, MVT MemVT) const { 00463 assert(ValVT < MVT::LAST_VALUETYPE && MemVT < MVT::LAST_VALUETYPE && 00464 "Table isn't big enough!"); 00465 return (LegalizeAction)TruncStoreActions[ValVT.SimpleTy] 00466 [MemVT.SimpleTy]; 00467 } 00468 00469 /// isTruncStoreLegal - Return true if the specified store with truncation is 00470 /// legal on this target. 00471 bool isTruncStoreLegal(EVT ValVT, EVT MemVT) const { 00472 return isTypeLegal(ValVT) && MemVT.isSimple() && 00473 getTruncStoreAction(ValVT.getSimpleVT(), MemVT.getSimpleVT()) == Legal; 00474 } 00475 00476 /// getIndexedLoadAction - Return how the indexed load should be treated: 00477 /// either it is legal, needs to be promoted to a larger size, needs to be 00478 /// expanded to some other code sequence, or the target has a custom expander 00479 /// for it. 00480 LegalizeAction 00481 getIndexedLoadAction(unsigned IdxMode, MVT VT) const { 00482 assert(IdxMode < ISD::LAST_INDEXED_MODE && VT < MVT::LAST_VALUETYPE && 00483 "Table isn't big enough!"); 00484 unsigned Ty = (unsigned)VT.SimpleTy; 00485 return (LegalizeAction)((IndexedModeActions[Ty][IdxMode] & 0xf0) >> 4); 00486 } 00487 00488 /// isIndexedLoadLegal - Return true if the specified indexed load is legal 00489 /// on this target. 00490 bool isIndexedLoadLegal(unsigned IdxMode, EVT VT) const { 00491 return VT.isSimple() && 00492 (getIndexedLoadAction(IdxMode, VT.getSimpleVT()) == Legal || 00493 getIndexedLoadAction(IdxMode, VT.getSimpleVT()) == Custom); 00494 } 00495 00496 /// getIndexedStoreAction - Return how the indexed store should be treated: 00497 /// either it is legal, needs to be promoted to a larger size, needs to be 00498 /// expanded to some other code sequence, or the target has a custom expander 00499 /// for it. 00500 LegalizeAction 00501 getIndexedStoreAction(unsigned IdxMode, MVT VT) const { 00502 assert(IdxMode < ISD::LAST_INDEXED_MODE && VT < MVT::LAST_VALUETYPE && 00503 "Table isn't big enough!"); 00504 unsigned Ty = (unsigned)VT.SimpleTy; 00505 return (LegalizeAction)(IndexedModeActions[Ty][IdxMode] & 0x0f); 00506 } 00507 00508 /// isIndexedStoreLegal - Return true if the specified indexed load is legal 00509 /// on this target. 00510 bool isIndexedStoreLegal(unsigned IdxMode, EVT VT) const { 00511 return VT.isSimple() && 00512 (getIndexedStoreAction(IdxMode, VT.getSimpleVT()) == Legal || 00513 getIndexedStoreAction(IdxMode, VT.getSimpleVT()) == Custom); 00514 } 00515 00516 /// getCondCodeAction - Return how the condition code should be treated: 00517 /// either it is legal, needs to be expanded to some other code sequence, 00518 /// or the target has a custom expander for it. 00519 LegalizeAction 00520 getCondCodeAction(ISD::CondCode CC, MVT VT) const { 00521 assert((unsigned)CC < array_lengthof(CondCodeActions) && 00522 (unsigned)VT.SimpleTy < sizeof(CondCodeActions[0])*4 && 00523 "Table isn't big enough!"); 00524 /// The lower 5 bits of the SimpleTy index into Nth 2bit set from the 64bit 00525 /// value and the upper 27 bits index into the second dimension of the 00526 /// array to select what 64bit value to use. 00527 LegalizeAction Action = (LegalizeAction) 00528 ((CondCodeActions[CC][VT.SimpleTy >> 5] >> (2*(VT.SimpleTy & 0x1F))) & 3); 00529 assert(Action != Promote && "Can't promote condition code!"); 00530 return Action; 00531 } 00532 00533 /// isCondCodeLegal - Return true if the specified condition code is legal 00534 /// on this target. 00535 bool isCondCodeLegal(ISD::CondCode CC, MVT VT) const { 00536 return 00537 getCondCodeAction(CC, VT) == Legal || 00538 getCondCodeAction(CC, VT) == Custom; 00539 } 00540 00541 00542 /// getTypeToPromoteTo - If the action for this operation is to promote, this 00543 /// method returns the ValueType to promote to. 00544 MVT getTypeToPromoteTo(unsigned Op, MVT VT) const { 00545 assert(getOperationAction(Op, VT) == Promote && 00546 "This operation isn't promoted!"); 00547 00548 // See if this has an explicit type specified. 00549 std::map<std::pair<unsigned, MVT::SimpleValueType>, 00550 MVT::SimpleValueType>::const_iterator PTTI = 00551 PromoteToType.find(std::make_pair(Op, VT.SimpleTy)); 00552 if (PTTI != PromoteToType.end()) return PTTI->second; 00553 00554 assert((VT.isInteger() || VT.isFloatingPoint()) && 00555 "Cannot autopromote this type, add it with AddPromotedToType."); 00556 00557 MVT NVT = VT; 00558 do { 00559 NVT = (MVT::SimpleValueType)(NVT.SimpleTy+1); 00560 assert(NVT.isInteger() == VT.isInteger() && NVT != MVT::isVoid && 00561 "Didn't find type to promote to!"); 00562 } while (!isTypeLegal(NVT) || 00563 getOperationAction(Op, NVT) == Promote); 00564 return NVT; 00565 } 00566 00567 /// getValueType - Return the EVT corresponding to this LLVM type. 00568 /// This is fixed by the LLVM operations except for the pointer size. If 00569 /// AllowUnknown is true, this will return MVT::Other for types with no EVT 00570 /// counterpart (e.g. structs), otherwise it will assert. 00571 EVT getValueType(Type *Ty, bool AllowUnknown = false) const { 00572 // Lower scalar pointers to native pointer types. 00573 if (Ty->isPointerTy()) return PointerTy; 00574 00575 if (Ty->isVectorTy()) { 00576 VectorType *VTy = cast<VectorType>(Ty); 00577 Type *Elm = VTy->getElementType(); 00578 // Lower vectors of pointers to native pointer types. 00579 if (Elm->isPointerTy()) 00580 Elm = EVT(PointerTy).getTypeForEVT(Ty->getContext()); 00581 return EVT::getVectorVT(Ty->getContext(), EVT::getEVT(Elm, false), 00582 VTy->getNumElements()); 00583 } 00584 return EVT::getEVT(Ty, AllowUnknown); 00585 } 00586 00587 /// Return the MVT corresponding to this LLVM type. See getValueType. 00588 MVT getSimpleValueType(Type *Ty, bool AllowUnknown = false) const { 00589 return getValueType(Ty, AllowUnknown).getSimpleVT(); 00590 } 00591 00592 /// getByValTypeAlignment - Return the desired alignment for ByVal aggregate 00593 /// function arguments in the caller parameter area. This is the actual 00594 /// alignment, not its logarithm. 00595 virtual unsigned getByValTypeAlignment(Type *Ty) const; 00596 00597 /// getRegisterType - Return the type of registers that this ValueType will 00598 /// eventually require. 00599 MVT getRegisterType(MVT VT) const { 00600 assert((unsigned)VT.SimpleTy < array_lengthof(RegisterTypeForVT)); 00601 return RegisterTypeForVT[VT.SimpleTy]; 00602 } 00603 00604 /// getRegisterType - Return the type of registers that this ValueType will 00605 /// eventually require. 00606 MVT getRegisterType(LLVMContext &Context, EVT VT) const { 00607 if (VT.isSimple()) { 00608 assert((unsigned)VT.getSimpleVT().SimpleTy < 00609 array_lengthof(RegisterTypeForVT)); 00610 return RegisterTypeForVT[VT.getSimpleVT().SimpleTy]; 00611 } 00612 if (VT.isVector()) { 00613 EVT VT1; 00614 MVT RegisterVT; 00615 unsigned NumIntermediates; 00616 (void)getVectorTypeBreakdown(Context, VT, VT1, 00617 NumIntermediates, RegisterVT); 00618 return RegisterVT; 00619 } 00620 if (VT.isInteger()) { 00621 return getRegisterType(Context, getTypeToTransformTo(Context, VT)); 00622 } 00623 llvm_unreachable("Unsupported extended type!"); 00624 } 00625 00626 /// getNumRegisters - Return the number of registers that this ValueType will 00627 /// eventually require. This is one for any types promoted to live in larger 00628 /// registers, but may be more than one for types (like i64) that are split 00629 /// into pieces. For types like i140, which are first promoted then expanded, 00630 /// it is the number of registers needed to hold all the bits of the original 00631 /// type. For an i140 on a 32 bit machine this means 5 registers. 00632 unsigned getNumRegisters(LLVMContext &Context, EVT VT) const { 00633 if (VT.isSimple()) { 00634 assert((unsigned)VT.getSimpleVT().SimpleTy < 00635 array_lengthof(NumRegistersForVT)); 00636 return NumRegistersForVT[VT.getSimpleVT().SimpleTy]; 00637 } 00638 if (VT.isVector()) { 00639 EVT VT1; 00640 MVT VT2; 00641 unsigned NumIntermediates; 00642 return getVectorTypeBreakdown(Context, VT, VT1, NumIntermediates, VT2); 00643 } 00644 if (VT.isInteger()) { 00645 unsigned BitWidth = VT.getSizeInBits(); 00646 unsigned RegWidth = getRegisterType(Context, VT).getSizeInBits(); 00647 return (BitWidth + RegWidth - 1) / RegWidth; 00648 } 00649 llvm_unreachable("Unsupported extended type!"); 00650 } 00651 00652 /// ShouldShrinkFPConstant - If true, then instruction selection should 00653 /// seek to shrink the FP constant of the specified type to a smaller type 00654 /// in order to save space and / or reduce runtime. 00655 virtual bool ShouldShrinkFPConstant(EVT) const { return true; } 00656 00657 /// hasTargetDAGCombine - If true, the target has custom DAG combine 00658 /// transformations that it can perform for the specified node. 00659 bool hasTargetDAGCombine(ISD::NodeType NT) const { 00660 assert(unsigned(NT >> 3) < array_lengthof(TargetDAGCombineArray)); 00661 return TargetDAGCombineArray[NT >> 3] & (1 << (NT&7)); 00662 } 00663 00664 /// This function returns the maximum number of store operations permitted 00665 /// to replace a call to llvm.memset. The value is set by the target at the 00666 /// performance threshold for such a replacement. If OptSize is true, 00667 /// return the limit for functions that have OptSize attribute. 00668 /// @brief Get maximum # of store operations permitted for llvm.memset 00669 unsigned getMaxStoresPerMemset(bool OptSize) const { 00670 return OptSize ? MaxStoresPerMemsetOptSize : MaxStoresPerMemset; 00671 } 00672 00673 /// This function returns the maximum number of store operations permitted 00674 /// to replace a call to llvm.memcpy. The value is set by the target at the 00675 /// performance threshold for such a replacement. If OptSize is true, 00676 /// return the limit for functions that have OptSize attribute. 00677 /// @brief Get maximum # of store operations permitted for llvm.memcpy 00678 unsigned getMaxStoresPerMemcpy(bool OptSize) const { 00679 return OptSize ? MaxStoresPerMemcpyOptSize : MaxStoresPerMemcpy; 00680 } 00681 00682 /// This function returns the maximum number of store operations permitted 00683 /// to replace a call to llvm.memmove. The value is set by the target at the 00684 /// performance threshold for such a replacement. If OptSize is true, 00685 /// return the limit for functions that have OptSize attribute. 00686 /// @brief Get maximum # of store operations permitted for llvm.memmove 00687 unsigned getMaxStoresPerMemmove(bool OptSize) const { 00688 return OptSize ? MaxStoresPerMemmoveOptSize : MaxStoresPerMemmove; 00689 } 00690 00691 /// This function returns true if the target allows unaligned memory accesses. 00692 /// of the specified type. If true, it also returns whether the unaligned 00693 /// memory access is "fast" in the second argument by reference. This is used, 00694 /// for example, in situations where an array copy/move/set is converted to a 00695 /// sequence of store operations. It's use helps to ensure that such 00696 /// replacements don't generate code that causes an alignment error (trap) on 00697 /// the target machine. 00698 /// @brief Determine if the target supports unaligned memory accesses. 00699 virtual bool allowsUnalignedMemoryAccesses(EVT, bool * /*Fast*/ = 0) const { 00700 return false; 00701 } 00702 00703 /// getOptimalMemOpType - Returns the target specific optimal type for load 00704 /// and store operations as a result of memset, memcpy, and memmove 00705 /// lowering. If DstAlign is zero that means it's safe to destination 00706 /// alignment can satisfy any constraint. Similarly if SrcAlign is zero it 00707 /// means there isn't a need to check it against alignment requirement, 00708 /// probably because the source does not need to be loaded. If 'IsMemset' is 00709 /// true, that means it's expanding a memset. If 'ZeroMemset' is true, that 00710 /// means it's a memset of zero. 'MemcpyStrSrc' indicates whether the memcpy 00711 /// source is constant so it does not need to be loaded. 00712 /// It returns EVT::Other if the type should be determined using generic 00713 /// target-independent logic. 00714 virtual EVT getOptimalMemOpType(uint64_t /*Size*/, 00715 unsigned /*DstAlign*/, unsigned /*SrcAlign*/, 00716 bool /*IsMemset*/, 00717 bool /*ZeroMemset*/, 00718 bool /*MemcpyStrSrc*/, 00719 MachineFunction &/*MF*/) const { 00720 return MVT::Other; 00721 } 00722 00723 /// isSafeMemOpType - Returns true if it's safe to use load / store of the 00724 /// specified type to expand memcpy / memset inline. This is mostly true 00725 /// for all types except for some special cases. For example, on X86 00726 /// targets without SSE2 f64 load / store are done with fldl / fstpl which 00727 /// also does type conversion. Note the specified type doesn't have to be 00728 /// legal as the hook is used before type legalization. 00729 virtual bool isSafeMemOpType(MVT /*VT*/) const { return true; } 00730 00731 /// usesUnderscoreSetJmp - Determine if we should use _setjmp or setjmp 00732 /// to implement llvm.setjmp. 00733 bool usesUnderscoreSetJmp() const { 00734 return UseUnderscoreSetJmp; 00735 } 00736 00737 /// usesUnderscoreLongJmp - Determine if we should use _longjmp or longjmp 00738 /// to implement llvm.longjmp. 00739 bool usesUnderscoreLongJmp() const { 00740 return UseUnderscoreLongJmp; 00741 } 00742 00743 /// supportJumpTables - return whether the target can generate code for 00744 /// jump tables. 00745 bool supportJumpTables() const { 00746 return SupportJumpTables; 00747 } 00748 00749 /// getMinimumJumpTableEntries - return integer threshold on number of 00750 /// blocks to use jump tables rather than if sequence. 00751 int getMinimumJumpTableEntries() const { 00752 return MinimumJumpTableEntries; 00753 } 00754 00755 /// getStackPointerRegisterToSaveRestore - If a physical register, this 00756 /// specifies the register that llvm.savestack/llvm.restorestack should save 00757 /// and restore. 00758 unsigned getStackPointerRegisterToSaveRestore() const { 00759 return StackPointerRegisterToSaveRestore; 00760 } 00761 00762 /// getExceptionPointerRegister - If a physical register, this returns 00763 /// the register that receives the exception address on entry to a landing 00764 /// pad. 00765 unsigned getExceptionPointerRegister() const { 00766 return ExceptionPointerRegister; 00767 } 00768 00769 /// getExceptionSelectorRegister - If a physical register, this returns 00770 /// the register that receives the exception typeid on entry to a landing 00771 /// pad. 00772 unsigned getExceptionSelectorRegister() const { 00773 return ExceptionSelectorRegister; 00774 } 00775 00776 /// getJumpBufSize - returns the target's jmp_buf size in bytes (if never 00777 /// set, the default is 200) 00778 unsigned getJumpBufSize() const { 00779 return JumpBufSize; 00780 } 00781 00782 /// getJumpBufAlignment - returns the target's jmp_buf alignment in bytes 00783 /// (if never set, the default is 0) 00784 unsigned getJumpBufAlignment() const { 00785 return JumpBufAlignment; 00786 } 00787 00788 /// getMinStackArgumentAlignment - return the minimum stack alignment of an 00789 /// argument. 00790 unsigned getMinStackArgumentAlignment() const { 00791 return MinStackArgumentAlignment; 00792 } 00793 00794 /// getMinFunctionAlignment - return the minimum function alignment. 00795 /// 00796 unsigned getMinFunctionAlignment() const { 00797 return MinFunctionAlignment; 00798 } 00799 00800 /// getPrefFunctionAlignment - return the preferred function alignment. 00801 /// 00802 unsigned getPrefFunctionAlignment() const { 00803 return PrefFunctionAlignment; 00804 } 00805 00806 /// getPrefLoopAlignment - return the preferred loop alignment. 00807 /// 00808 unsigned getPrefLoopAlignment() const { 00809 return PrefLoopAlignment; 00810 } 00811 00812 /// getInsertFencesFor - return whether the DAG builder should automatically 00813 /// insert fences and reduce ordering for atomics. 00814 /// 00815 bool getInsertFencesForAtomic() const { 00816 return InsertFencesForAtomic; 00817 } 00818 00819 /// getStackCookieLocation - Return true if the target stores stack 00820 /// protector cookies at a fixed offset in some non-standard address 00821 /// space, and populates the address space and offset as 00822 /// appropriate. 00823 virtual bool getStackCookieLocation(unsigned &/*AddressSpace*/, 00824 unsigned &/*Offset*/) const { 00825 return false; 00826 } 00827 00828 /// getMaximalGlobalOffset - Returns the maximal possible offset which can be 00829 /// used for loads / stores from the global. 00830 virtual unsigned getMaximalGlobalOffset() const { 00831 return 0; 00832 } 00833 00834 //===--------------------------------------------------------------------===// 00835 /// \name Helpers for TargetTransformInfo implementations 00836 /// @{ 00837 00838 /// Get the ISD node that corresponds to the Instruction class opcode. 00839 int InstructionOpcodeToISD(unsigned Opcode) const; 00840 00841 /// Estimate the cost of type-legalization and the legalized type. 00842 std::pair<unsigned, MVT> getTypeLegalizationCost(Type *Ty) const; 00843 00844 /// @} 00845 00846 //===--------------------------------------------------------------------===// 00847 // TargetLowering Configuration Methods - These methods should be invoked by 00848 // the derived class constructor to configure this object for the target. 00849 // 00850 00851 /// \brief Reset the operation actions based on target options. 00852 virtual void resetOperationActions() {} 00853 00854 protected: 00855 /// setBooleanContents - Specify how the target extends the result of a 00856 /// boolean value from i1 to a wider type. See getBooleanContents. 00857 void setBooleanContents(BooleanContent Ty) { BooleanContents = Ty; } 00858 /// setBooleanVectorContents - Specify how the target extends the result 00859 /// of a vector boolean value from a vector of i1 to a wider type. See 00860 /// getBooleanContents. 00861 void setBooleanVectorContents(BooleanContent Ty) { 00862 BooleanVectorContents = Ty; 00863 } 00864 00865 /// setSchedulingPreference - Specify the target scheduling preference. 00866 void setSchedulingPreference(Sched::Preference Pref) { 00867 SchedPreferenceInfo = Pref; 00868 } 00869 00870 /// setUseUnderscoreSetJmp - Indicate whether this target prefers to 00871 /// use _setjmp to implement llvm.setjmp or the non _ version. 00872 /// Defaults to false. 00873 void setUseUnderscoreSetJmp(bool Val) { 00874 UseUnderscoreSetJmp = Val; 00875 } 00876 00877 /// setUseUnderscoreLongJmp - Indicate whether this target prefers to 00878 /// use _longjmp to implement llvm.longjmp or the non _ version. 00879 /// Defaults to false. 00880 void setUseUnderscoreLongJmp(bool Val) { 00881 UseUnderscoreLongJmp = Val; 00882 } 00883 00884 /// setSupportJumpTables - Indicate whether the target can generate code for 00885 /// jump tables. 00886 void setSupportJumpTables(bool Val) { 00887 SupportJumpTables = Val; 00888 } 00889 00890 /// setMinimumJumpTableEntries - Indicate the number of blocks to generate 00891 /// jump tables rather than if sequence. 00892 void setMinimumJumpTableEntries(int Val) { 00893 MinimumJumpTableEntries = Val; 00894 } 00895 00896 /// setStackPointerRegisterToSaveRestore - If set to a physical register, this 00897 /// specifies the register that llvm.savestack/llvm.restorestack should save 00898 /// and restore. 00899 void setStackPointerRegisterToSaveRestore(unsigned R) { 00900 StackPointerRegisterToSaveRestore = R; 00901 } 00902 00903 /// setExceptionPointerRegister - If set to a physical register, this sets 00904 /// the register that receives the exception address on entry to a landing 00905 /// pad. 00906 void setExceptionPointerRegister(unsigned R) { 00907 ExceptionPointerRegister = R; 00908 } 00909 00910 /// setExceptionSelectorRegister - If set to a physical register, this sets 00911 /// the register that receives the exception typeid on entry to a landing 00912 /// pad. 00913 void setExceptionSelectorRegister(unsigned R) { 00914 ExceptionSelectorRegister = R; 00915 } 00916 00917 /// SelectIsExpensive - Tells the code generator not to expand operations 00918 /// into sequences that use the select operations if possible. 00919 void setSelectIsExpensive(bool isExpensive = true) { 00920 SelectIsExpensive = isExpensive; 00921 } 00922 00923 /// JumpIsExpensive - Tells the code generator not to expand sequence of 00924 /// operations into a separate sequences that increases the amount of 00925 /// flow control. 00926 void setJumpIsExpensive(bool isExpensive = true) { 00927 JumpIsExpensive = isExpensive; 00928 } 00929 00930 /// setIntDivIsCheap - Tells the code generator that integer divide is 00931 /// expensive, and if possible, should be replaced by an alternate sequence 00932 /// of instructions not containing an integer divide. 00933 void setIntDivIsCheap(bool isCheap = true) { IntDivIsCheap = isCheap; } 00934 00935 /// addBypassSlowDiv - Tells the code generator which bitwidths to bypass. 00936 void addBypassSlowDiv(unsigned int SlowBitWidth, unsigned int FastBitWidth) { 00937 BypassSlowDivWidths[SlowBitWidth] = FastBitWidth; 00938 } 00939 00940 /// setPow2DivIsCheap - Tells the code generator that it shouldn't generate 00941 /// srl/add/sra for a signed divide by power of two, and let the target handle 00942 /// it. 00943 void setPow2DivIsCheap(bool isCheap = true) { Pow2DivIsCheap = isCheap; } 00944 00945 /// addRegisterClass - Add the specified register class as an available 00946 /// regclass for the specified value type. This indicates the selector can 00947 /// handle values of that class natively. 00948 void addRegisterClass(MVT VT, const TargetRegisterClass *RC) { 00949 assert((unsigned)VT.SimpleTy < array_lengthof(RegClassForVT)); 00950 AvailableRegClasses.push_back(std::make_pair(VT, RC)); 00951 RegClassForVT[VT.SimpleTy] = RC; 00952 } 00953 00954 /// clearRegisterClasses - Remove all register classes. 00955 void clearRegisterClasses() { 00956 memset(RegClassForVT, 0,MVT::LAST_VALUETYPE * sizeof(TargetRegisterClass*)); 00957 00958 AvailableRegClasses.clear(); 00959 } 00960 00961 /// \brief Remove all operation actions. 00962 void clearOperationActions() { 00963 } 00964 00965 /// findRepresentativeClass - Return the largest legal super-reg register class 00966 /// of the register class for the specified type and its associated "cost". 00967 virtual std::pair<const TargetRegisterClass*, uint8_t> 00968 findRepresentativeClass(MVT VT) const; 00969 00970 /// computeRegisterProperties - Once all of the register classes are added, 00971 /// this allows us to compute derived properties we expose. 00972 void computeRegisterProperties(); 00973 00974 /// setOperationAction - Indicate that the specified operation does not work 00975 /// with the specified type and indicate what to do about it. 00976 void setOperationAction(unsigned Op, MVT VT, 00977 LegalizeAction Action) { 00978 assert(Op < array_lengthof(OpActions[0]) && "Table isn't big enough!"); 00979 OpActions[(unsigned)VT.SimpleTy][Op] = (uint8_t)Action; 00980 } 00981 00982 /// setLoadExtAction - Indicate that the specified load with extension does 00983 /// not work with the specified type and indicate what to do about it. 00984 void setLoadExtAction(unsigned ExtType, MVT VT, 00985 LegalizeAction Action) { 00986 assert(ExtType < ISD::LAST_LOADEXT_TYPE && VT < MVT::LAST_VALUETYPE && 00987 "Table isn't big enough!"); 00988 LoadExtActions[VT.SimpleTy][ExtType] = (uint8_t)Action; 00989 } 00990 00991 /// setTruncStoreAction - Indicate that the specified truncating store does 00992 /// not work with the specified type and indicate what to do about it. 00993 void setTruncStoreAction(MVT ValVT, MVT MemVT, 00994 LegalizeAction Action) { 00995 assert(ValVT < MVT::LAST_VALUETYPE && MemVT < MVT::LAST_VALUETYPE && 00996 "Table isn't big enough!"); 00997 TruncStoreActions[ValVT.SimpleTy][MemVT.SimpleTy] = (uint8_t)Action; 00998 } 00999 01000 /// setIndexedLoadAction - Indicate that the specified indexed load does or 01001 /// does not work with the specified type and indicate what to do abort 01002 /// it. NOTE: All indexed mode loads are initialized to Expand in 01003 /// TargetLowering.cpp 01004 void setIndexedLoadAction(unsigned IdxMode, MVT VT, 01005 LegalizeAction Action) { 01006 assert(VT < MVT::LAST_VALUETYPE && IdxMode < ISD::LAST_INDEXED_MODE && 01007 (unsigned)Action < 0xf && "Table isn't big enough!"); 01008 // Load action are kept in the upper half. 01009 IndexedModeActions[(unsigned)VT.SimpleTy][IdxMode] &= ~0xf0; 01010 IndexedModeActions[(unsigned)VT.SimpleTy][IdxMode] |= ((uint8_t)Action) <<4; 01011 } 01012 01013 /// setIndexedStoreAction - Indicate that the specified indexed store does or 01014 /// does not work with the specified type and indicate what to do about 01015 /// it. NOTE: All indexed mode stores are initialized to Expand in 01016 /// TargetLowering.cpp 01017 void setIndexedStoreAction(unsigned IdxMode, MVT VT, 01018 LegalizeAction Action) { 01019 assert(VT < MVT::LAST_VALUETYPE && IdxMode < ISD::LAST_INDEXED_MODE && 01020 (unsigned)Action < 0xf && "Table isn't big enough!"); 01021 // Store action are kept in the lower half. 01022 IndexedModeActions[(unsigned)VT.SimpleTy][IdxMode] &= ~0x0f; 01023 IndexedModeActions[(unsigned)VT.SimpleTy][IdxMode] |= ((uint8_t)Action); 01024 } 01025 01026 /// setCondCodeAction - Indicate that the specified condition code is or isn't 01027 /// supported on the target and indicate what to do about it. 01028 void setCondCodeAction(ISD::CondCode CC, MVT VT, 01029 LegalizeAction Action) { 01030 assert(VT < MVT::LAST_VALUETYPE && 01031 (unsigned)CC < array_lengthof(CondCodeActions) && 01032 "Table isn't big enough!"); 01033 /// The lower 5 bits of the SimpleTy index into Nth 2bit set from the 64bit 01034 /// value and the upper 27 bits index into the second dimension of the 01035 /// array to select what 64bit value to use. 01036 CondCodeActions[(unsigned)CC][VT.SimpleTy >> 5] 01037 &= ~(uint64_t(3UL) << (VT.SimpleTy & 0x1F)*2); 01038 CondCodeActions[(unsigned)CC][VT.SimpleTy >> 5] 01039 |= (uint64_t)Action << (VT.SimpleTy & 0x1F)*2; 01040 } 01041 01042 /// AddPromotedToType - If Opc/OrigVT is specified as being promoted, the 01043 /// promotion code defaults to trying a larger integer/fp until it can find 01044 /// one that works. If that default is insufficient, this method can be used 01045 /// by the target to override the default. 01046 void AddPromotedToType(unsigned Opc, MVT OrigVT, MVT DestVT) { 01047 PromoteToType[std::make_pair(Opc, OrigVT.SimpleTy)] = DestVT.SimpleTy; 01048 } 01049 01050 /// setTargetDAGCombine - Targets should invoke this method for each target 01051 /// independent node that they want to provide a custom DAG combiner for by 01052 /// implementing the PerformDAGCombine virtual method. 01053 void setTargetDAGCombine(ISD::NodeType NT) { 01054 assert(unsigned(NT >> 3) < array_lengthof(TargetDAGCombineArray)); 01055 TargetDAGCombineArray[NT >> 3] |= 1 << (NT&7); 01056 } 01057 01058 /// setJumpBufSize - Set the target's required jmp_buf buffer size (in 01059 /// bytes); default is 200 01060 void setJumpBufSize(unsigned Size) { 01061 JumpBufSize = Size; 01062 } 01063 01064 /// setJumpBufAlignment - Set the target's required jmp_buf buffer 01065 /// alignment (in bytes); default is 0 01066 void setJumpBufAlignment(unsigned Align) { 01067 JumpBufAlignment = Align; 01068 } 01069 01070 /// setMinFunctionAlignment - Set the target's minimum function alignment (in 01071 /// log2(bytes)) 01072 void setMinFunctionAlignment(unsigned Align) { 01073 MinFunctionAlignment = Align; 01074 } 01075 01076 /// setPrefFunctionAlignment - Set the target's preferred function alignment. 01077 /// This should be set if there is a performance benefit to 01078 /// higher-than-minimum alignment (in log2(bytes)) 01079 void setPrefFunctionAlignment(unsigned Align) { 01080 PrefFunctionAlignment = Align; 01081 } 01082 01083 /// setPrefLoopAlignment - Set the target's preferred loop alignment. Default 01084 /// alignment is zero, it means the target does not care about loop alignment. 01085 /// The alignment is specified in log2(bytes). 01086 void setPrefLoopAlignment(unsigned Align) { 01087 PrefLoopAlignment = Align; 01088 } 01089 01090 /// setMinStackArgumentAlignment - Set the minimum stack alignment of an 01091 /// argument (in log2(bytes)). 01092 void setMinStackArgumentAlignment(unsigned Align) { 01093 MinStackArgumentAlignment = Align; 01094 } 01095 01096 /// setInsertFencesForAtomic - Set if the DAG builder should 01097 /// automatically insert fences and reduce the order of atomic memory 01098 /// operations to Monotonic. 01099 void setInsertFencesForAtomic(bool fence) { 01100 InsertFencesForAtomic = fence; 01101 } 01102 01103 public: 01104 //===--------------------------------------------------------------------===// 01105 // Addressing mode description hooks (used by LSR etc). 01106 // 01107 01108 /// GetAddrModeArguments - CodeGenPrepare sinks address calculations into the 01109 /// same BB as Load/Store instructions reading the address. This allows as 01110 /// much computation as possible to be done in the address mode for that 01111 /// operand. This hook lets targets also pass back when this should be done 01112 /// on intrinsics which load/store. 01113 virtual bool GetAddrModeArguments(IntrinsicInst * /*I*/, 01114 SmallVectorImpl<Value*> &/*Ops*/, 01115 Type *&/*AccessTy*/) const { 01116 return false; 01117 } 01118 01119 /// AddrMode - This represents an addressing mode of: 01120 /// BaseGV + BaseOffs + BaseReg + Scale*ScaleReg 01121 /// If BaseGV is null, there is no BaseGV. 01122 /// If BaseOffs is zero, there is no base offset. 01123 /// If HasBaseReg is false, there is no base register. 01124 /// If Scale is zero, there is no ScaleReg. Scale of 1 indicates a reg with 01125 /// no scale. 01126 /// 01127 struct AddrMode { 01128 GlobalValue *BaseGV; 01129 int64_t BaseOffs; 01130 bool HasBaseReg; 01131 int64_t Scale; 01132 AddrMode() : BaseGV(0), BaseOffs(0), HasBaseReg(false), Scale(0) {} 01133 }; 01134 01135 /// isLegalAddressingMode - Return true if the addressing mode represented by 01136 /// AM is legal for this target, for a load/store of the specified type. 01137 /// The type may be VoidTy, in which case only return true if the addressing 01138 /// mode is legal for a load/store of any legal type. 01139 /// TODO: Handle pre/postinc as well. 01140 virtual bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const; 01141 01142 /// \brief Return the cost of the scaling factor used in the addressing 01143 /// mode represented by AM for this target, for a load/store 01144 /// of the specified type. 01145 /// If the AM is supported, the return value must be >= 0. 01146 /// If the AM is not supported, it returns a negative value. 01147 /// TODO: Handle pre/postinc as well. 01148 virtual int getScalingFactorCost(const AddrMode &AM, Type *Ty) const { 01149 // Default: assume that any scaling factor used in a legal AM is free. 01150 if (isLegalAddressingMode(AM, Ty)) return 0; 01151 return -1; 01152 } 01153 01154 /// isLegalICmpImmediate - Return true if the specified immediate is legal 01155 /// icmp immediate, that is the target has icmp instructions which can compare 01156 /// a register against the immediate without having to materialize the 01157 /// immediate into a register. 01158 virtual bool isLegalICmpImmediate(int64_t) const { 01159 return true; 01160 } 01161 01162 /// isLegalAddImmediate - Return true if the specified immediate is legal 01163 /// add immediate, that is the target has add instructions which can add 01164 /// a register with the immediate without having to materialize the 01165 /// immediate into a register. 01166 virtual bool isLegalAddImmediate(int64_t) const { 01167 return true; 01168 } 01169 01170 /// isTruncateFree - Return true if it's free to truncate a value of 01171 /// type Ty1 to type Ty2. e.g. On x86 it's free to truncate a i32 value in 01172 /// register EAX to i16 by referencing its sub-register AX. 01173 virtual bool isTruncateFree(Type * /*Ty1*/, Type * /*Ty2*/) const { 01174 return false; 01175 } 01176 01177 virtual bool isTruncateFree(EVT /*VT1*/, EVT /*VT2*/) const { 01178 return false; 01179 } 01180 01181 /// isZExtFree - Return true if any actual instruction that defines a 01182 /// value of type Ty1 implicitly zero-extends the value to Ty2 in the result 01183 /// register. This does not necessarily include registers defined in 01184 /// unknown ways, such as incoming arguments, or copies from unknown 01185 /// virtual registers. Also, if isTruncateFree(Ty2, Ty1) is true, this 01186 /// does not necessarily apply to truncate instructions. e.g. on x86-64, 01187 /// all instructions that define 32-bit values implicit zero-extend the 01188 /// result out to 64 bits. 01189 virtual bool isZExtFree(Type * /*Ty1*/, Type * /*Ty2*/) const { 01190 return false; 01191 } 01192 01193 virtual bool isZExtFree(EVT /*VT1*/, EVT /*VT2*/) const { 01194 return false; 01195 } 01196 01197 /// isZExtFree - Return true if zero-extending the specific node Val to type 01198 /// VT2 is free (either because it's implicitly zero-extended such as ARM 01199 /// ldrb / ldrh or because it's folded such as X86 zero-extending loads). 01200 virtual bool isZExtFree(SDValue Val, EVT VT2) const { 01201 return isZExtFree(Val.getValueType(), VT2); 01202 } 01203 01204 /// isFNegFree - Return true if an fneg operation is free to the point where 01205 /// it is never worthwhile to replace it with a bitwise operation. 01206 virtual bool isFNegFree(EVT) const { 01207 return false; 01208 } 01209 01210 /// isFAbsFree - Return true if an fneg operation is free to the point where 01211 /// it is never worthwhile to replace it with a bitwise operation. 01212 virtual bool isFAbsFree(EVT) const { 01213 return false; 01214 } 01215 01216 /// isFMAFasterThanMulAndAdd - Return true if an FMA operation is faster than 01217 /// a pair of mul and add instructions. fmuladd intrinsics will be expanded to 01218 /// FMAs when this method returns true (and FMAs are legal), otherwise fmuladd 01219 /// is expanded to mul + add. 01220 virtual bool isFMAFasterThanMulAndAdd(EVT) const { 01221 return false; 01222 } 01223 01224 /// isNarrowingProfitable - Return true if it's profitable to narrow 01225 /// operations of type VT1 to VT2. e.g. on x86, it's profitable to narrow 01226 /// from i32 to i8 but not from i32 to i16. 01227 virtual bool isNarrowingProfitable(EVT /*VT1*/, EVT /*VT2*/) const { 01228 return false; 01229 } 01230 01231 //===--------------------------------------------------------------------===// 01232 // Runtime Library hooks 01233 // 01234 01235 /// setLibcallName - Rename the default libcall routine name for the specified 01236 /// libcall. 01237 void setLibcallName(RTLIB::Libcall Call, const char *Name) { 01238 LibcallRoutineNames[Call] = Name; 01239 } 01240 01241 /// getLibcallName - Get the libcall routine name for the specified libcall. 01242 /// 01243 const char *getLibcallName(RTLIB::Libcall Call) const { 01244 return LibcallRoutineNames[Call]; 01245 } 01246 01247 /// setCmpLibcallCC - Override the default CondCode to be used to test the 01248 /// result of the comparison libcall against zero. 01249 void setCmpLibcallCC(RTLIB::Libcall Call, ISD::CondCode CC) { 01250 CmpLibcallCCs[Call] = CC; 01251 } 01252 01253 /// getCmpLibcallCC - Get the CondCode that's to be used to test the result of 01254 /// the comparison libcall against zero. 01255 ISD::CondCode getCmpLibcallCC(RTLIB::Libcall Call) const { 01256 return CmpLibcallCCs[Call]; 01257 } 01258 01259 /// setLibcallCallingConv - Set the CallingConv that should be used for the 01260 /// specified libcall. 01261 void setLibcallCallingConv(RTLIB::Libcall Call, CallingConv::ID CC) { 01262 LibcallCallingConvs[Call] = CC; 01263 } 01264 01265 /// getLibcallCallingConv - Get the CallingConv that should be used for the 01266 /// specified libcall. 01267 CallingConv::ID getLibcallCallingConv(RTLIB::Libcall Call) const { 01268 return LibcallCallingConvs[Call]; 01269 } 01270 01271 private: 01272 const TargetMachine &TM; 01273 const DataLayout *TD; 01274 const TargetLoweringObjectFile &TLOF; 01275 01276 /// PointerTy - The type to use for pointers for the default address space, 01277 /// usually i32 or i64. 01278 /// 01279 MVT PointerTy; 01280 01281 /// IsLittleEndian - True if this is a little endian target. 01282 /// 01283 bool IsLittleEndian; 01284 01285 /// SelectIsExpensive - Tells the code generator not to expand operations 01286 /// into sequences that use the select operations if possible. 01287 bool SelectIsExpensive; 01288 01289 /// IntDivIsCheap - Tells the code generator not to expand integer divides by 01290 /// constants into a sequence of muls, adds, and shifts. This is a hack until 01291 /// a real cost model is in place. If we ever optimize for size, this will be 01292 /// set to true unconditionally. 01293 bool IntDivIsCheap; 01294 01295 /// BypassSlowDivMap - Tells the code generator to bypass slow divide or 01296 /// remainder instructions. For example, BypassSlowDivWidths[32,8] tells the 01297 /// code generator to bypass 32-bit integer div/rem with an 8-bit unsigned 01298 /// integer div/rem when the operands are positive and less than 256. 01299 DenseMap <unsigned int, unsigned int> BypassSlowDivWidths; 01300 01301 /// Pow2DivIsCheap - Tells the code generator that it shouldn't generate 01302 /// srl/add/sra for a signed divide by power of two, and let the target handle 01303 /// it. 01304 bool Pow2DivIsCheap; 01305 01306 /// JumpIsExpensive - Tells the code generator that it shouldn't generate 01307 /// extra flow control instructions and should attempt to combine flow 01308 /// control instructions via predication. 01309 bool JumpIsExpensive; 01310 01311 /// UseUnderscoreSetJmp - This target prefers to use _setjmp to implement 01312 /// llvm.setjmp. Defaults to false. 01313 bool UseUnderscoreSetJmp; 01314 01315 /// UseUnderscoreLongJmp - This target prefers to use _longjmp to implement 01316 /// llvm.longjmp. Defaults to false. 01317 bool UseUnderscoreLongJmp; 01318 01319 /// SupportJumpTables - Whether the target can generate code for jumptables. 01320 /// If it's not true, then each jumptable must be lowered into if-then-else's. 01321 bool SupportJumpTables; 01322 01323 /// MinimumJumpTableEntries - Number of blocks threshold to use jump tables. 01324 int MinimumJumpTableEntries; 01325 01326 /// BooleanContents - Information about the contents of the high-bits in 01327 /// boolean values held in a type wider than i1. See getBooleanContents. 01328 BooleanContent BooleanContents; 01329 /// BooleanVectorContents - Information about the contents of the high-bits 01330 /// in boolean vector values when the element type is wider than i1. See 01331 /// getBooleanContents. 01332 BooleanContent BooleanVectorContents; 01333 01334 /// SchedPreferenceInfo - The target scheduling preference: shortest possible 01335 /// total cycles or lowest register usage. 01336 Sched::Preference SchedPreferenceInfo; 01337 01338 /// JumpBufSize - The size, in bytes, of the target's jmp_buf buffers 01339 unsigned JumpBufSize; 01340 01341 /// JumpBufAlignment - The alignment, in bytes, of the target's jmp_buf 01342 /// buffers 01343 unsigned JumpBufAlignment; 01344 01345 /// MinStackArgumentAlignment - The minimum alignment that any argument 01346 /// on the stack needs to have. 01347 /// 01348 unsigned MinStackArgumentAlignment; 01349 01350 /// MinFunctionAlignment - The minimum function alignment (used when 01351 /// optimizing for size, and to prevent explicitly provided alignment 01352 /// from leading to incorrect code). 01353 /// 01354 unsigned MinFunctionAlignment; 01355 01356 /// PrefFunctionAlignment - The preferred function alignment (used when 01357 /// alignment unspecified and optimizing for speed). 01358 /// 01359 unsigned PrefFunctionAlignment; 01360 01361 /// PrefLoopAlignment - The preferred loop alignment. 01362 /// 01363 unsigned PrefLoopAlignment; 01364 01365 /// InsertFencesForAtomic - Whether the DAG builder should automatically 01366 /// insert fences and reduce ordering for atomics. (This will be set for 01367 /// for most architectures with weak memory ordering.) 01368 bool InsertFencesForAtomic; 01369 01370 /// StackPointerRegisterToSaveRestore - If set to a physical register, this 01371 /// specifies the register that llvm.savestack/llvm.restorestack should save 01372 /// and restore. 01373 unsigned StackPointerRegisterToSaveRestore; 01374 01375 /// ExceptionPointerRegister - If set to a physical register, this specifies 01376 /// the register that receives the exception address on entry to a landing 01377 /// pad. 01378 unsigned ExceptionPointerRegister; 01379 01380 /// ExceptionSelectorRegister - If set to a physical register, this specifies 01381 /// the register that receives the exception typeid on entry to a landing 01382 /// pad. 01383 unsigned ExceptionSelectorRegister; 01384 01385 /// RegClassForVT - This indicates the default register class to use for 01386 /// each ValueType the target supports natively. 01387 const TargetRegisterClass *RegClassForVT[MVT::LAST_VALUETYPE]; 01388 unsigned char NumRegistersForVT[MVT::LAST_VALUETYPE]; 01389 MVT RegisterTypeForVT[MVT::LAST_VALUETYPE]; 01390 01391 /// RepRegClassForVT - This indicates the "representative" register class to 01392 /// use for each ValueType the target supports natively. This information is 01393 /// used by the scheduler to track register pressure. By default, the 01394 /// representative register class is the largest legal super-reg register 01395 /// class of the register class of the specified type. e.g. On x86, i8, i16, 01396 /// and i32's representative class would be GR32. 01397 const TargetRegisterClass *RepRegClassForVT[MVT::LAST_VALUETYPE]; 01398 01399 /// RepRegClassCostForVT - This indicates the "cost" of the "representative" 01400 /// register class for each ValueType. The cost is used by the scheduler to 01401 /// approximate register pressure. 01402 uint8_t RepRegClassCostForVT[MVT::LAST_VALUETYPE]; 01403 01404 /// TransformToType - For any value types we are promoting or expanding, this 01405 /// contains the value type that we are changing to. For Expanded types, this 01406 /// contains one step of the expand (e.g. i64 -> i32), even if there are 01407 /// multiple steps required (e.g. i64 -> i16). For types natively supported 01408 /// by the system, this holds the same type (e.g. i32 -> i32). 01409 MVT TransformToType[MVT::LAST_VALUETYPE]; 01410 01411 /// OpActions - For each operation and each value type, keep a LegalizeAction 01412 /// that indicates how instruction selection should deal with the operation. 01413 /// Most operations are Legal (aka, supported natively by the target), but 01414 /// operations that are not should be described. Note that operations on 01415 /// non-legal value types are not described here. 01416 uint8_t OpActions[MVT::LAST_VALUETYPE][ISD::BUILTIN_OP_END]; 01417 01418 /// LoadExtActions - For each load extension type and each value type, 01419 /// keep a LegalizeAction that indicates how instruction selection should deal 01420 /// with a load of a specific value type and extension type. 01421 uint8_t LoadExtActions[MVT::LAST_VALUETYPE][ISD::LAST_LOADEXT_TYPE]; 01422 01423 /// TruncStoreActions - For each value type pair keep a LegalizeAction that 01424 /// indicates whether a truncating store of a specific value type and 01425 /// truncating type is legal. 01426 uint8_t TruncStoreActions[MVT::LAST_VALUETYPE][MVT::LAST_VALUETYPE]; 01427 01428 /// IndexedModeActions - For each indexed mode and each value type, 01429 /// keep a pair of LegalizeAction that indicates how instruction 01430 /// selection should deal with the load / store. The first dimension is the 01431 /// value_type for the reference. The second dimension represents the various 01432 /// modes for load store. 01433 uint8_t IndexedModeActions[MVT::LAST_VALUETYPE][ISD::LAST_INDEXED_MODE]; 01434 01435 /// CondCodeActions - For each condition code (ISD::CondCode) keep a 01436 /// LegalizeAction that indicates how instruction selection should 01437 /// deal with the condition code. 01438 /// Because each CC action takes up 2 bits, we need to have the array size 01439 /// be large enough to fit all of the value types. This can be done by 01440 /// dividing the MVT::LAST_VALUETYPE by 32 and adding one. 01441 uint64_t CondCodeActions[ISD::SETCC_INVALID][(MVT::LAST_VALUETYPE / 32) + 1]; 01442 01443 ValueTypeActionImpl ValueTypeActions; 01444 01445 public: 01446 LegalizeKind 01447 getTypeConversion(LLVMContext &Context, EVT VT) const { 01448 // If this is a simple type, use the ComputeRegisterProp mechanism. 01449 if (VT.isSimple()) { 01450 MVT SVT = VT.getSimpleVT(); 01451 assert((unsigned)SVT.SimpleTy < array_lengthof(TransformToType)); 01452 MVT NVT = TransformToType[SVT.SimpleTy]; 01453 LegalizeTypeAction LA = ValueTypeActions.getTypeAction(SVT); 01454 01455 assert( 01456 (LA == TypeLegal || 01457 ValueTypeActions.getTypeAction(NVT) != TypePromoteInteger) 01458 && "Promote may not follow Expand or Promote"); 01459 01460 if (LA == TypeSplitVector) 01461 return LegalizeKind(LA, EVT::getVectorVT(Context, 01462 SVT.getVectorElementType(), 01463 SVT.getVectorNumElements()/2)); 01464 if (LA == TypeScalarizeVector) 01465 return LegalizeKind(LA, SVT.getVectorElementType()); 01466 return LegalizeKind(LA, NVT); 01467 } 01468 01469 // Handle Extended Scalar Types. 01470 if (!VT.isVector()) { 01471 assert(VT.isInteger() && "Float types must be simple"); 01472 unsigned BitSize = VT.getSizeInBits(); 01473 // First promote to a power-of-two size, then expand if necessary. 01474 if (BitSize < 8 || !isPowerOf2_32(BitSize)) { 01475 EVT NVT = VT.getRoundIntegerType(Context); 01476 assert(NVT != VT && "Unable to round integer VT"); 01477 LegalizeKind NextStep = getTypeConversion(Context, NVT); 01478 // Avoid multi-step promotion. 01479 if (NextStep.first == TypePromoteInteger) return NextStep; 01480 // Return rounded integer type. 01481 return LegalizeKind(TypePromoteInteger, NVT); 01482 } 01483 01484 return LegalizeKind(TypeExpandInteger, 01485 EVT::getIntegerVT(Context, VT.getSizeInBits()/2)); 01486 } 01487 01488 // Handle vector types. 01489 unsigned NumElts = VT.getVectorNumElements(); 01490 EVT EltVT = VT.getVectorElementType(); 01491 01492 // Vectors with only one element are always scalarized. 01493 if (NumElts == 1) 01494 return LegalizeKind(TypeScalarizeVector, EltVT); 01495 01496 // Try to widen vector elements until a legal type is found. 01497 if (EltVT.isInteger()) { 01498 // Vectors with a number of elements that is not a power of two are always 01499 // widened, for example <3 x float> -> <4 x float>. 01500 if (!VT.isPow2VectorType()) { 01501 NumElts = (unsigned)NextPowerOf2(NumElts); 01502 EVT NVT = EVT::getVectorVT(Context, EltVT, NumElts); 01503 return LegalizeKind(TypeWidenVector, NVT); 01504 } 01505 01506 // Examine the element type. 01507 LegalizeKind LK = getTypeConversion(Context, EltVT); 01508 01509 // If type is to be expanded, split the vector. 01510 // <4 x i140> -> <2 x i140> 01511 if (LK.first == TypeExpandInteger) 01512 return LegalizeKind(TypeSplitVector, 01513 EVT::getVectorVT(Context, EltVT, NumElts / 2)); 01514 01515 // Promote the integer element types until a legal vector type is found 01516 // or until the element integer type is too big. If a legal type was not 01517 // found, fallback to the usual mechanism of widening/splitting the 01518 // vector. 01519 EVT OldEltVT = EltVT; 01520 while (1) { 01521 // Increase the bitwidth of the element to the next pow-of-two 01522 // (which is greater than 8 bits). 01523 EltVT = EVT::getIntegerVT(Context, 1 + EltVT.getSizeInBits() 01524 ).getRoundIntegerType(Context); 01525 01526 // Stop trying when getting a non-simple element type. 01527 // Note that vector elements may be greater than legal vector element 01528 // types. Example: X86 XMM registers hold 64bit element on 32bit systems. 01529 if (!EltVT.isSimple()) break; 01530 01531 // Build a new vector type and check if it is legal. 01532 MVT NVT = MVT::getVectorVT(EltVT.getSimpleVT(), NumElts); 01533 // Found a legal promoted vector type. 01534 if (NVT != MVT() && ValueTypeActions.getTypeAction(NVT) == TypeLegal) 01535 return LegalizeKind(TypePromoteInteger, 01536 EVT::getVectorVT(Context, EltVT, NumElts)); 01537 } 01538 01539 // Reset the type to the unexpanded type if we did not find a legal vector 01540 // type with a promoted vector element type. 01541 EltVT = OldEltVT; 01542 } 01543 01544 // Try to widen the vector until a legal type is found. 01545 // If there is no wider legal type, split the vector. 01546 while (1) { 01547 // Round up to the next power of 2. 01548 NumElts = (unsigned)NextPowerOf2(NumElts); 01549 01550 // If there is no simple vector type with this many elements then there 01551 // cannot be a larger legal vector type. Note that this assumes that 01552 // there are no skipped intermediate vector types in the simple types. 01553 if (!EltVT.isSimple()) break; 01554 MVT LargerVector = MVT::getVectorVT(EltVT.getSimpleVT(), NumElts); 01555 if (LargerVector == MVT()) break; 01556 01557 // If this type is legal then widen the vector. 01558 if (ValueTypeActions.getTypeAction(LargerVector) == TypeLegal) 01559 return LegalizeKind(TypeWidenVector, LargerVector); 01560 } 01561 01562 // Widen odd vectors to next power of two. 01563 if (!VT.isPow2VectorType()) { 01564 EVT NVT = VT.getPow2VectorType(Context); 01565 return LegalizeKind(TypeWidenVector, NVT); 01566 } 01567 01568 // Vectors with illegal element types are expanded. 01569 EVT NVT = EVT::getVectorVT(Context, EltVT, VT.getVectorNumElements() / 2); 01570 return LegalizeKind(TypeSplitVector, NVT); 01571 } 01572 01573 private: 01574 std::vector<std::pair<MVT, const TargetRegisterClass*> > AvailableRegClasses; 01575 01576 /// TargetDAGCombineArray - Targets can specify ISD nodes that they would 01577 /// like PerformDAGCombine callbacks for by calling setTargetDAGCombine(), 01578 /// which sets a bit in this array. 01579 unsigned char 01580 TargetDAGCombineArray[(ISD::BUILTIN_OP_END+CHAR_BIT-1)/CHAR_BIT]; 01581 01582 /// PromoteToType - For operations that must be promoted to a specific type, 01583 /// this holds the destination type. This map should be sparse, so don't hold 01584 /// it as an array. 01585 /// 01586 /// Targets add entries to this map with AddPromotedToType(..), clients access 01587 /// this with getTypeToPromoteTo(..). 01588 std::map<std::pair<unsigned, MVT::SimpleValueType>, MVT::SimpleValueType> 01589 PromoteToType; 01590 01591 /// LibcallRoutineNames - Stores the name each libcall. 01592 /// 01593 const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL]; 01594 01595 /// CmpLibcallCCs - The ISD::CondCode that should be used to test the result 01596 /// of each of the comparison libcall against zero. 01597 ISD::CondCode CmpLibcallCCs[RTLIB::UNKNOWN_LIBCALL]; 01598 01599 /// LibcallCallingConvs - Stores the CallingConv that should be used for each 01600 /// libcall. 01601 CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL]; 01602 01603 protected: 01604 /// When lowering \@llvm.memset this field specifies the maximum number of 01605 /// store operations that may be substituted for the call to memset. Targets 01606 /// must set this value based on the cost threshold for that target. Targets 01607 /// should assume that the memset will be done using as many of the largest 01608 /// store operations first, followed by smaller ones, if necessary, per 01609 /// alignment restrictions. For example, storing 9 bytes on a 32-bit machine 01610 /// with 16-bit alignment would result in four 2-byte stores and one 1-byte 01611 /// store. This only applies to setting a constant array of a constant size. 01612 /// @brief Specify maximum number of store instructions per memset call. 01613 unsigned MaxStoresPerMemset; 01614 01615 /// Maximum number of stores operations that may be substituted for the call 01616 /// to memset, used for functions with OptSize attribute. 01617 unsigned MaxStoresPerMemsetOptSize; 01618 01619 /// When lowering \@llvm.memcpy this field specifies the maximum number of 01620 /// store operations that may be substituted for a call to memcpy. Targets 01621 /// must set this value based on the cost threshold for that target. Targets 01622 /// should assume that the memcpy will be done using as many of the largest 01623 /// store operations first, followed by smaller ones, if necessary, per 01624 /// alignment restrictions. For example, storing 7 bytes on a 32-bit machine 01625 /// with 32-bit alignment would result in one 4-byte store, a one 2-byte store 01626 /// and one 1-byte store. This only applies to copying a constant array of 01627 /// constant size. 01628 /// @brief Specify maximum bytes of store instructions per memcpy call. 01629 unsigned MaxStoresPerMemcpy; 01630 01631 /// Maximum number of store operations that may be substituted for a call 01632 /// to memcpy, used for functions with OptSize attribute. 01633 unsigned MaxStoresPerMemcpyOptSize; 01634 01635 /// When lowering \@llvm.memmove this field specifies the maximum number of 01636 /// store instructions that may be substituted for a call to memmove. Targets 01637 /// must set this value based on the cost threshold for that target. Targets 01638 /// should assume that the memmove will be done using as many of the largest 01639 /// store operations first, followed by smaller ones, if necessary, per 01640 /// alignment restrictions. For example, moving 9 bytes on a 32-bit machine 01641 /// with 8-bit alignment would result in nine 1-byte stores. This only 01642 /// applies to copying a constant array of constant size. 01643 /// @brief Specify maximum bytes of store instructions per memmove call. 01644 unsigned MaxStoresPerMemmove; 01645 01646 /// Maximum number of store instructions that may be substituted for a call 01647 /// to memmove, used for functions with OpSize attribute. 01648 unsigned MaxStoresPerMemmoveOptSize; 01649 01650 /// PredictableSelectIsExpensive - Tells the code generator that select is 01651 /// more expensive than a branch if the branch is usually predicted right. 01652 bool PredictableSelectIsExpensive; 01653 01654 protected: 01655 /// isLegalRC - Return true if the value types that can be represented by the 01656 /// specified register class are all legal. 01657 bool isLegalRC(const TargetRegisterClass *RC) const; 01658 }; 01659 01660 //===----------------------------------------------------------------------===// 01661 /// TargetLowering - This class defines information used to lower LLVM code to 01662 /// legal SelectionDAG operators that the target instruction selector can accept 01663 /// natively. 01664 /// 01665 /// This class also defines callbacks that targets must implement to lower 01666 /// target-specific constructs to SelectionDAG operators. 01667 /// 01668 class TargetLowering : public TargetLoweringBase { 01669 TargetLowering(const TargetLowering&) LLVM_DELETED_FUNCTION; 01670 void operator=(const TargetLowering&) LLVM_DELETED_FUNCTION; 01671 01672 public: 01673 /// NOTE: The constructor takes ownership of TLOF. 01674 explicit TargetLowering(const TargetMachine &TM, 01675 const TargetLoweringObjectFile *TLOF); 01676 01677 /// getPreIndexedAddressParts - returns true by value, base pointer and 01678 /// offset pointer and addressing mode by reference if the node's address 01679 /// can be legally represented as pre-indexed load / store address. 01680 virtual bool getPreIndexedAddressParts(SDNode * /*N*/, SDValue &/*Base*/, 01681 SDValue &/*Offset*/, 01682 ISD::MemIndexedMode &/*AM*/, 01683 SelectionDAG &/*DAG*/) const { 01684 return false; 01685 } 01686 01687 /// getPostIndexedAddressParts - returns true by value, base pointer and 01688 /// offset pointer and addressing mode by reference if this node can be 01689 /// combined with a load / store to form a post-indexed load / store. 01690 virtual bool getPostIndexedAddressParts(SDNode * /*N*/, SDNode * /*Op*/, 01691 SDValue &/*Base*/, SDValue &/*Offset*/, 01692 ISD::MemIndexedMode &/*AM*/, 01693 SelectionDAG &/*DAG*/) const { 01694 return false; 01695 } 01696 01697 /// getJumpTableEncoding - Return the entry encoding for a jump table in the 01698 /// current function. The returned value is a member of the 01699 /// MachineJumpTableInfo::JTEntryKind enum. 01700 virtual unsigned getJumpTableEncoding() const; 01701 01702 virtual const MCExpr * 01703 LowerCustomJumpTableEntry(const MachineJumpTableInfo * /*MJTI*/, 01704 const MachineBasicBlock * /*MBB*/, unsigned /*uid*/, 01705 MCContext &/*Ctx*/) const { 01706 llvm_unreachable("Need to implement this hook if target has custom JTIs"); 01707 } 01708 01709 /// getPICJumpTableRelocaBase - Returns relocation base for the given PIC 01710 /// jumptable. 01711 virtual SDValue getPICJumpTableRelocBase(SDValue Table, 01712 SelectionDAG &DAG) const; 01713 01714 /// getPICJumpTableRelocBaseExpr - This returns the relocation base for the 01715 /// given PIC jumptable, the same as getPICJumpTableRelocBase, but as an 01716 /// MCExpr. 01717 virtual const MCExpr * 01718 getPICJumpTableRelocBaseExpr(const MachineFunction *MF, 01719 unsigned JTI, MCContext &Ctx) const; 01720 01721 /// isOffsetFoldingLegal - Return true if folding a constant offset 01722 /// with the given GlobalAddress is legal. It is frequently not legal in 01723 /// PIC relocation models. 01724 virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const; 01725 01726 bool isInTailCallPosition(SelectionDAG &DAG, SDNode *Node, 01727 SDValue &Chain) const; 01728 01729 void softenSetCCOperands(SelectionDAG &DAG, EVT VT, 01730 SDValue &NewLHS, SDValue &NewRHS, 01731 ISD::CondCode &CCCode, SDLoc DL) const; 01732 01733 SDValue makeLibCall(SelectionDAG &DAG, RTLIB::Libcall LC, EVT RetVT, 01734 const SDValue *Ops, unsigned NumOps, 01735 bool isSigned, SDLoc dl) const; 01736 01737 //===--------------------------------------------------------------------===// 01738 // TargetLowering Optimization Methods 01739 // 01740 01741 /// TargetLoweringOpt - A convenience struct that encapsulates a DAG, and two 01742 /// SDValues for returning information from TargetLowering to its clients 01743 /// that want to combine 01744 struct TargetLoweringOpt { 01745 SelectionDAG &DAG; 01746 bool LegalTys; 01747 bool LegalOps; 01748 SDValue Old; 01749 SDValue New; 01750 01751 explicit TargetLoweringOpt(SelectionDAG &InDAG, 01752 bool LT, bool LO) : 01753 DAG(InDAG), LegalTys(LT), LegalOps(LO) {} 01754 01755 bool LegalTypes() const { return LegalTys; } 01756 bool LegalOperations() const { return LegalOps; } 01757 01758 bool CombineTo(SDValue O, SDValue N) { 01759 Old = O; 01760 New = N; 01761 return true; 01762 } 01763 01764 /// ShrinkDemandedConstant - Check to see if the specified operand of the 01765 /// specified instruction is a constant integer. If so, check to see if 01766 /// there are any bits set in the constant that are not demanded. If so, 01767 /// shrink the constant and return true. 01768 bool ShrinkDemandedConstant(SDValue Op, const APInt &Demanded); 01769 01770 /// ShrinkDemandedOp - Convert x+y to (VT)((SmallVT)x+(SmallVT)y) if the 01771 /// casts are free. This uses isZExtFree and ZERO_EXTEND for the widening 01772 /// cast, but it could be generalized for targets with other types of 01773 /// implicit widening casts. 01774 bool ShrinkDemandedOp(SDValue Op, unsigned BitWidth, const APInt &Demanded, 01775 SDLoc dl); 01776 }; 01777 01778 /// SimplifyDemandedBits - Look at Op. At this point, we know that only the 01779 /// DemandedMask bits of the result of Op are ever used downstream. If we can 01780 /// use this information to simplify Op, create a new simplified DAG node and 01781 /// return true, returning the original and new nodes in Old and New. 01782 /// Otherwise, analyze the expression and return a mask of KnownOne and 01783 /// KnownZero bits for the expression (used to simplify the caller). 01784 /// The KnownZero/One bits may only be accurate for those bits in the 01785 /// DemandedMask. 01786 bool SimplifyDemandedBits(SDValue Op, const APInt &DemandedMask, 01787 APInt &KnownZero, APInt &KnownOne, 01788 TargetLoweringOpt &TLO, unsigned Depth = 0) const; 01789 01790 /// computeMaskedBitsForTargetNode - Determine which of the bits specified in 01791 /// Mask are known to be either zero or one and return them in the 01792 /// KnownZero/KnownOne bitsets. 01793 virtual void computeMaskedBitsForTargetNode(const SDValue Op, 01794 APInt &KnownZero, 01795 APInt &KnownOne, 01796 const SelectionDAG &DAG, 01797 unsigned Depth = 0) const; 01798 01799 /// ComputeNumSignBitsForTargetNode - This method can be implemented by 01800 /// targets that want to expose additional information about sign bits to the 01801 /// DAG Combiner. 01802 virtual unsigned ComputeNumSignBitsForTargetNode(SDValue Op, 01803 unsigned Depth = 0) const; 01804 01805 struct DAGCombinerInfo { 01806 void *DC; // The DAG Combiner object. 01807 CombineLevel Level; 01808 bool CalledByLegalizer; 01809 public: 01810 SelectionDAG &DAG; 01811 01812 DAGCombinerInfo(SelectionDAG &dag, CombineLevel level, bool cl, void *dc) 01813 : DC(dc), Level(level), CalledByLegalizer(cl), DAG(dag) {} 01814 01815 bool isBeforeLegalize() const { return Level == BeforeLegalizeTypes; } 01816 bool isBeforeLegalizeOps() const { return Level < AfterLegalizeVectorOps; } 01817 bool isAfterLegalizeVectorOps() const { 01818 return Level == AfterLegalizeDAG; 01819 } 01820 CombineLevel getDAGCombineLevel() { return Level; } 01821 bool isCalledByLegalizer() const { return CalledByLegalizer; } 01822 01823 void AddToWorklist(SDNode *N); 01824 void RemoveFromWorklist(SDNode *N); 01825 SDValue CombineTo(SDNode *N, const std::vector<SDValue> &To, 01826 bool AddTo = true); 01827 SDValue CombineTo(SDNode *N, SDValue Res, bool AddTo = true); 01828 SDValue CombineTo(SDNode *N, SDValue Res0, SDValue Res1, bool AddTo = true); 01829 01830 void CommitTargetLoweringOpt(const TargetLoweringOpt &TLO); 01831 }; 01832 01833 /// SimplifySetCC - Try to simplify a setcc built with the specified operands 01834 /// and cc. If it is unable to simplify it, return a null SDValue. 01835 SDValue SimplifySetCC(EVT VT, SDValue N0, SDValue N1, 01836 ISD::CondCode Cond, bool foldBooleans, 01837 DAGCombinerInfo &DCI, SDLoc dl) const; 01838 01839 /// isGAPlusOffset - Returns true (and the GlobalValue and the offset) if the 01840 /// node is a GlobalAddress + offset. 01841 virtual bool 01842 isGAPlusOffset(SDNode *N, const GlobalValue* &GA, int64_t &Offset) const; 01843 01844 /// PerformDAGCombine - This method will be invoked for all target nodes and 01845 /// for any target-independent nodes that the target has registered with 01846 /// invoke it for. 01847 /// 01848 /// The semantics are as follows: 01849 /// Return Value: 01850 /// SDValue.Val == 0 - No change was made 01851 /// SDValue.Val == N - N was replaced, is dead, and is already handled. 01852 /// otherwise - N should be replaced by the returned Operand. 01853 /// 01854 /// In addition, methods provided by DAGCombinerInfo may be used to perform 01855 /// more complex transformations. 01856 /// 01857 virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const; 01858 01859 /// isTypeDesirableForOp - Return true if the target has native support for 01860 /// the specified value type and it is 'desirable' to use the type for the 01861 /// given node type. e.g. On x86 i16 is legal, but undesirable since i16 01862 /// instruction encodings are longer and some i16 instructions are slow. 01863 virtual bool isTypeDesirableForOp(unsigned /*Opc*/, EVT VT) const { 01864 // By default, assume all legal types are desirable. 01865 return isTypeLegal(VT); 01866 } 01867 01868 /// isDesirableToPromoteOp - Return true if it is profitable for dag combiner 01869 /// to transform a floating point op of specified opcode to a equivalent op of 01870 /// an integer type. e.g. f32 load -> i32 load can be profitable on ARM. 01871 virtual bool isDesirableToTransformToIntegerOp(unsigned /*Opc*/, 01872 EVT /*VT*/) const { 01873 return false; 01874 } 01875 01876 /// IsDesirableToPromoteOp - This method query the target whether it is 01877 /// beneficial for dag combiner to promote the specified node. If true, it 01878 /// should return the desired promotion type by reference. 01879 virtual bool IsDesirableToPromoteOp(SDValue /*Op*/, EVT &/*PVT*/) const { 01880 return false; 01881 } 01882 01883 //===--------------------------------------------------------------------===// 01884 // Lowering methods - These methods must be implemented by targets so that 01885 // the SelectionDAGBuilder code knows how to lower these. 01886 // 01887 01888 /// LowerFormalArguments - This hook must be implemented to lower the 01889 /// incoming (formal) arguments, described by the Ins array, into the 01890 /// specified DAG. The implementation should fill in the InVals array 01891 /// with legal-type argument values, and return the resulting token 01892 /// chain value. 01893 /// 01894 virtual SDValue 01895 LowerFormalArguments(SDValue /*Chain*/, CallingConv::ID /*CallConv*/, 01896 bool /*isVarArg*/, 01897 const SmallVectorImpl<ISD::InputArg> &/*Ins*/, 01898 SDLoc /*dl*/, SelectionDAG &/*DAG*/, 01899 SmallVectorImpl<SDValue> &/*InVals*/) const { 01900 llvm_unreachable("Not Implemented"); 01901 } 01902 01903 struct ArgListEntry { 01904 SDValue Node; 01905 Type* Ty; 01906 bool isSExt : 1; 01907 bool isZExt : 1; 01908 bool isInReg : 1; 01909 bool isSRet : 1; 01910 bool isNest : 1; 01911 bool isByVal : 1; 01912 bool isReturned : 1; 01913 uint16_t Alignment; 01914 01915 ArgListEntry() : isSExt(false), isZExt(false), isInReg(false), 01916 isSRet(false), isNest(false), isByVal(false), isReturned(false), 01917 Alignment(0) { } 01918 }; 01919 typedef std::vector<ArgListEntry> ArgListTy; 01920 01921 /// CallLoweringInfo - This structure contains all information that is 01922 /// necessary for lowering calls. It is passed to TLI::LowerCallTo when the 01923 /// SelectionDAG builder needs to lower a call, and targets will see this 01924 /// struct in their LowerCall implementation. 01925 struct CallLoweringInfo { 01926 SDValue Chain; 01927 Type *RetTy; 01928 bool RetSExt : 1; 01929 bool RetZExt : 1; 01930 bool IsVarArg : 1; 01931 bool IsInReg : 1; 01932 bool DoesNotReturn : 1; 01933 bool IsReturnValueUsed : 1; 01934 01935 // IsTailCall should be modified by implementations of 01936 // TargetLowering::LowerCall that perform tail call conversions. 01937 bool IsTailCall; 01938 01939 unsigned NumFixedArgs; 01940 CallingConv::ID CallConv; 01941 SDValue Callee; 01942 ArgListTy &Args; 01943 SelectionDAG &DAG; 01944 SDLoc DL; 01945 ImmutableCallSite *CS; 01946 SmallVector<ISD::OutputArg, 32> Outs; 01947 SmallVector<SDValue, 32> OutVals; 01948 SmallVector<ISD::InputArg, 32> Ins; 01949 01950 01951 /// CallLoweringInfo - Constructs a call lowering context based on the 01952 /// ImmutableCallSite \p cs. 01953 CallLoweringInfo(SDValue chain, Type *retTy, 01954 FunctionType *FTy, bool isTailCall, SDValue callee, 01955 ArgListTy &args, SelectionDAG &dag, SDLoc dl, 01956 ImmutableCallSite &cs) 01957 : Chain(chain), RetTy(retTy), RetSExt(cs.paramHasAttr(0, Attribute::SExt)), 01958 RetZExt(cs.paramHasAttr(0, Attribute::ZExt)), IsVarArg(FTy->isVarArg()), 01959 IsInReg(cs.paramHasAttr(0, Attribute::InReg)), 01960 DoesNotReturn(cs.doesNotReturn()), 01961 IsReturnValueUsed(!cs.getInstruction()->use_empty()), 01962 IsTailCall(isTailCall), NumFixedArgs(FTy->getNumParams()), 01963 CallConv(cs.getCallingConv()), Callee(callee), Args(args), DAG(dag), 01964 DL(dl), CS(&cs) {} 01965 01966 /// CallLoweringInfo - Constructs a call lowering context based on the 01967 /// provided call information. 01968 CallLoweringInfo(SDValue chain, Type *retTy, bool retSExt, bool retZExt, 01969 bool isVarArg, bool isInReg, unsigned numFixedArgs, 01970 CallingConv::ID callConv, bool isTailCall, 01971 bool doesNotReturn, bool isReturnValueUsed, SDValue callee, 01972 ArgListTy &args, SelectionDAG &dag, SDLoc dl) 01973 : Chain(chain), RetTy(retTy), RetSExt(retSExt), RetZExt(retZExt), 01974 IsVarArg(isVarArg), IsInReg(isInReg), DoesNotReturn(doesNotReturn), 01975 IsReturnValueUsed(isReturnValueUsed), IsTailCall(isTailCall), 01976 NumFixedArgs(numFixedArgs), CallConv(callConv), Callee(callee), 01977 Args(args), DAG(dag), DL(dl), CS(NULL) {} 01978 }; 01979 01980 /// LowerCallTo - This function lowers an abstract call to a function into an 01981 /// actual call. This returns a pair of operands. The first element is the 01982 /// return value for the function (if RetTy is not VoidTy). The second 01983 /// element is the outgoing token chain. It calls LowerCall to do the actual 01984 /// lowering. 01985 std::pair<SDValue, SDValue> LowerCallTo(CallLoweringInfo &CLI) const; 01986 01987 /// LowerCall - This hook must be implemented to lower calls into the 01988 /// the specified DAG. The outgoing arguments to the call are described 01989 /// by the Outs array, and the values to be returned by the call are 01990 /// described by the Ins array. The implementation should fill in the 01991 /// InVals array with legal-type return values from the call, and return 01992 /// the resulting token chain value. 01993 virtual SDValue 01994 LowerCall(CallLoweringInfo &/*CLI*/, 01995 SmallVectorImpl<SDValue> &/*InVals*/) const { 01996 llvm_unreachable("Not Implemented"); 01997 } 01998 01999 /// HandleByVal - Target-specific cleanup for formal ByVal parameters. 02000 virtual void HandleByVal(CCState *, unsigned &, unsigned) const {} 02001 02002 /// CanLowerReturn - This hook should be implemented to check whether the 02003 /// return values described by the Outs array can fit into the return 02004 /// registers. If false is returned, an sret-demotion is performed. 02005 /// 02006 virtual bool CanLowerReturn(CallingConv::ID /*CallConv*/, 02007 MachineFunction &/*MF*/, bool /*isVarArg*/, 02008 const SmallVectorImpl<ISD::OutputArg> &/*Outs*/, 02009 LLVMContext &/*Context*/) const 02010 { 02011 // Return true by default to get preexisting behavior. 02012 return true; 02013 } 02014 02015 /// LowerReturn - This hook must be implemented to lower outgoing 02016 /// return values, described by the Outs array, into the specified 02017 /// DAG. The implementation should return the resulting token chain 02018 /// value. 02019 /// 02020 virtual SDValue 02021 LowerReturn(SDValue /*Chain*/, CallingConv::ID /*CallConv*/, 02022 bool /*isVarArg*/, 02023 const SmallVectorImpl<ISD::OutputArg> &/*Outs*/, 02024 const SmallVectorImpl<SDValue> &/*OutVals*/, 02025 SDLoc /*dl*/, SelectionDAG &/*DAG*/) const { 02026 llvm_unreachable("Not Implemented"); 02027 } 02028 02029 /// isUsedByReturnOnly - Return true if result of the specified node is used 02030 /// by a return node only. It also compute and return the input chain for the 02031 /// tail call. 02032 /// This is used to determine whether it is possible 02033 /// to codegen a libcall as tail call at legalization time. 02034 virtual bool isUsedByReturnOnly(SDNode *, SDValue &/*Chain*/) const { 02035 return false; 02036 } 02037 02038 /// mayBeEmittedAsTailCall - Return true if the target may be able emit the 02039 /// call instruction as a tail call. This is used by optimization passes to 02040 /// determine if it's profitable to duplicate return instructions to enable 02041 /// tailcall optimization. 02042 virtual bool mayBeEmittedAsTailCall(CallInst *) const { 02043 return false; 02044 } 02045 02046 /// getTypeForExtArgOrReturn - Return the type that should be used to zero or 02047 /// sign extend a zeroext/signext integer argument or return value. 02048 /// FIXME: Most C calling convention requires the return type to be promoted, 02049 /// but this is not true all the time, e.g. i1 on x86-64. It is also not 02050 /// necessary for non-C calling conventions. The frontend should handle this 02051 /// and include all of the necessary information. 02052 virtual MVT getTypeForExtArgOrReturn(MVT VT, 02053 ISD::NodeType /*ExtendKind*/) const { 02054 MVT MinVT = getRegisterType(MVT::i32); 02055 return VT.bitsLT(MinVT) ? MinVT : VT; 02056 } 02057 02058 /// LowerOperationWrapper - This callback is invoked by the type legalizer 02059 /// to legalize nodes with an illegal operand type but legal result types. 02060 /// It replaces the LowerOperation callback in the type Legalizer. 02061 /// The reason we can not do away with LowerOperation entirely is that 02062 /// LegalizeDAG isn't yet ready to use this callback. 02063 /// TODO: Consider merging with ReplaceNodeResults. 02064 02065 /// The target places new result values for the node in Results (their number 02066 /// and types must exactly match those of the original return values of 02067 /// the node), or leaves Results empty, which indicates that the node is not 02068 /// to be custom lowered after all. 02069 /// The default implementation calls LowerOperation. 02070 virtual void LowerOperationWrapper(SDNode *N, 02071 SmallVectorImpl<SDValue> &Results, 02072 SelectionDAG &DAG) const; 02073 02074 /// LowerOperation - This callback is invoked for operations that are 02075 /// unsupported by the target, which are registered to use 'custom' lowering, 02076 /// and whose defined values are all legal. 02077 /// If the target has no operations that require custom lowering, it need not 02078 /// implement this. The default implementation of this aborts. 02079 virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const; 02080 02081 /// ReplaceNodeResults - This callback is invoked when a node result type is 02082 /// illegal for the target, and the operation was registered to use 'custom' 02083 /// lowering for that result type. The target places new result values for 02084 /// the node in Results (their number and types must exactly match those of 02085 /// the original return values of the node), or leaves Results empty, which 02086 /// indicates that the node is not to be custom lowered after all. 02087 /// 02088 /// If the target has no operations that require custom lowering, it need not 02089 /// implement this. The default implementation aborts. 02090 virtual void ReplaceNodeResults(SDNode * /*N*/, 02091 SmallVectorImpl<SDValue> &/*Results*/, 02092 SelectionDAG &/*DAG*/) const { 02093 llvm_unreachable("ReplaceNodeResults not implemented for this target!"); 02094 } 02095 02096 /// getTargetNodeName() - This method returns the name of a target specific 02097 /// DAG node. 02098 virtual const char *getTargetNodeName(unsigned Opcode) const; 02099 02100 /// createFastISel - This method returns a target specific FastISel object, 02101 /// or null if the target does not support "fast" ISel. 02102 virtual FastISel *createFastISel(FunctionLoweringInfo &, 02103 const TargetLibraryInfo *) const { 02104 return 0; 02105 } 02106 02107 //===--------------------------------------------------------------------===// 02108 // Inline Asm Support hooks 02109 // 02110 02111 /// ExpandInlineAsm - This hook allows the target to expand an inline asm 02112 /// call to be explicit llvm code if it wants to. This is useful for 02113 /// turning simple inline asms into LLVM intrinsics, which gives the 02114 /// compiler more information about the behavior of the code. 02115 virtual bool ExpandInlineAsm(CallInst *) const { 02116 return false; 02117 } 02118 02119 enum ConstraintType { 02120 C_Register, // Constraint represents specific register(s). 02121 C_RegisterClass, // Constraint represents any of register(s) in class. 02122 C_Memory, // Memory constraint. 02123 C_Other, // Something else. 02124 C_Unknown // Unsupported constraint. 02125 }; 02126 02127 enum ConstraintWeight { 02128 // Generic weights. 02129 CW_Invalid = -1, // No match. 02130 CW_Okay = 0, // Acceptable. 02131 CW_Good = 1, // Good weight. 02132 CW_Better = 2, // Better weight. 02133 CW_Best = 3, // Best weight. 02134 02135 // Well-known weights. 02136 CW_SpecificReg = CW_Okay, // Specific register operands. 02137 CW_Register = CW_Good, // Register operands. 02138 CW_Memory = CW_Better, // Memory operands. 02139 CW_Constant = CW_Best, // Constant operand. 02140 CW_Default = CW_Okay // Default or don't know type. 02141 }; 02142 02143 /// AsmOperandInfo - This contains information for each constraint that we are 02144 /// lowering. 02145 struct AsmOperandInfo : public InlineAsm::ConstraintInfo { 02146 /// ConstraintCode - This contains the actual string for the code, like "m". 02147 /// TargetLowering picks the 'best' code from ConstraintInfo::Codes that 02148 /// most closely matches the operand. 02149 std::string ConstraintCode; 02150 02151 /// ConstraintType - Information about the constraint code, e.g. Register, 02152 /// RegisterClass, Memory, Other, Unknown. 02153 TargetLowering::ConstraintType ConstraintType; 02154 02155 /// CallOperandval - If this is the result output operand or a 02156 /// clobber, this is null, otherwise it is the incoming operand to the 02157 /// CallInst. This gets modified as the asm is processed. 02158 Value *CallOperandVal; 02159 02160 /// ConstraintVT - The ValueType for the operand value. 02161 MVT ConstraintVT; 02162 02163 /// isMatchingInputConstraint - Return true of this is an input operand that 02164 /// is a matching constraint like "4". 02165 bool isMatchingInputConstraint() const; 02166 02167 /// getMatchedOperand - If this is an input matching constraint, this method 02168 /// returns the output operand it matches. 02169 unsigned getMatchedOperand() const; 02170 02171 /// Copy constructor for copying from an AsmOperandInfo. 02172 AsmOperandInfo(const AsmOperandInfo &info) 02173 : InlineAsm::ConstraintInfo(info), 02174 ConstraintCode(info.ConstraintCode), 02175 ConstraintType(info.ConstraintType), 02176 CallOperandVal(info.CallOperandVal), 02177 ConstraintVT(info.ConstraintVT) { 02178 } 02179 02180 /// Copy constructor for copying from a ConstraintInfo. 02181 AsmOperandInfo(const InlineAsm::ConstraintInfo &info) 02182 : InlineAsm::ConstraintInfo(info), 02183 ConstraintType(TargetLowering::C_Unknown), 02184 CallOperandVal(0), ConstraintVT(MVT::Other) { 02185 } 02186 }; 02187 02188 typedef std::vector<AsmOperandInfo> AsmOperandInfoVector; 02189 02190 /// ParseConstraints - Split up the constraint string from the inline 02191 /// assembly value into the specific constraints and their prefixes, 02192 /// and also tie in the associated operand values. 02193 /// If this returns an empty vector, and if the constraint string itself 02194 /// isn't empty, there was an error parsing. 02195 virtual AsmOperandInfoVector ParseConstraints(ImmutableCallSite CS) const; 02196 02197 /// Examine constraint type and operand type and determine a weight value. 02198 /// The operand object must already have been set up with the operand type. 02199 virtual ConstraintWeight getMultipleConstraintMatchWeight( 02200 AsmOperandInfo &info, int maIndex) const; 02201 02202 /// Examine constraint string and operand type and determine a weight value. 02203 /// The operand object must already have been set up with the operand type. 02204 virtual ConstraintWeight getSingleConstraintMatchWeight( 02205 AsmOperandInfo &info, const char *constraint) const; 02206 02207 /// ComputeConstraintToUse - Determines the constraint code and constraint 02208 /// type to use for the specific AsmOperandInfo, setting 02209 /// OpInfo.ConstraintCode and OpInfo.ConstraintType. If the actual operand 02210 /// being passed in is available, it can be passed in as Op, otherwise an 02211 /// empty SDValue can be passed. 02212 virtual void ComputeConstraintToUse(AsmOperandInfo &OpInfo, 02213 SDValue Op, 02214 SelectionDAG *DAG = 0) const; 02215 02216 /// getConstraintType - Given a constraint, return the type of constraint it 02217 /// is for this target. 02218 virtual ConstraintType getConstraintType(const std::string &Constraint) const; 02219 02220 /// getRegForInlineAsmConstraint - Given a physical register constraint (e.g. 02221 /// {edx}), return the register number and the register class for the 02222 /// register. 02223 /// 02224 /// Given a register class constraint, like 'r', if this corresponds directly 02225 /// to an LLVM register class, return a register of 0 and the register class 02226 /// pointer. 02227 /// 02228 /// This should only be used for C_Register constraints. On error, 02229 /// this returns a register number of 0 and a null register class pointer.. 02230 virtual std::pair<unsigned, const TargetRegisterClass*> 02231 getRegForInlineAsmConstraint(const std::string &Constraint, 02232 EVT VT) const; 02233 02234 /// LowerXConstraint - try to replace an X constraint, which matches anything, 02235 /// with another that has more specific requirements based on the type of the 02236 /// corresponding operand. This returns null if there is no replacement to 02237 /// make. 02238 virtual const char *LowerXConstraint(EVT ConstraintVT) const; 02239 02240 /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops 02241 /// vector. If it is invalid, don't add anything to Ops. 02242 virtual void LowerAsmOperandForConstraint(SDValue Op, std::string &Constraint, 02243 std::vector<SDValue> &Ops, 02244 SelectionDAG &DAG) const; 02245 02246 //===--------------------------------------------------------------------===// 02247 // Div utility functions 02248 // 02249 SDValue BuildExactSDIV(SDValue Op1, SDValue Op2, SDLoc dl, 02250 SelectionDAG &DAG) const; 02251 SDValue BuildSDIV(SDNode *N, SelectionDAG &DAG, bool IsAfterLegalization, 02252 std::vector<SDNode*> *Created) const; 02253 SDValue BuildUDIV(SDNode *N, SelectionDAG &DAG, bool IsAfterLegalization, 02254 std::vector<SDNode*> *Created) const; 02255 02256 //===--------------------------------------------------------------------===// 02257 // Instruction Emitting Hooks 02258 // 02259 02260 // EmitInstrWithCustomInserter - This method should be implemented by targets 02261 // that mark instructions with the 'usesCustomInserter' flag. These 02262 // instructions are special in various ways, which require special support to 02263 // insert. The specified MachineInstr is created but not inserted into any 02264 // basic blocks, and this method is called to expand it into a sequence of 02265 // instructions, potentially also creating new basic blocks and control flow. 02266 virtual MachineBasicBlock * 02267 EmitInstrWithCustomInserter(MachineInstr *MI, MachineBasicBlock *MBB) const; 02268 02269 /// AdjustInstrPostInstrSelection - This method should be implemented by 02270 /// targets that mark instructions with the 'hasPostISelHook' flag. These 02271 /// instructions must be adjusted after instruction selection by target hooks. 02272 /// e.g. To fill in optional defs for ARM 's' setting instructions. 02273 virtual void 02274 AdjustInstrPostInstrSelection(MachineInstr *MI, SDNode *Node) const; 02275 }; 02276 02277 /// GetReturnInfo - Given an LLVM IR type and return type attributes, 02278 /// compute the return value EVTs and flags, and optionally also 02279 /// the offsets, if the return value is being lowered to memory. 02280 void GetReturnInfo(Type* ReturnType, AttributeSet attr, 02281 SmallVectorImpl<ISD::OutputArg> &Outs, 02282 const TargetLowering &TLI); 02283 02284 } // end llvm namespace 02285 02286 #endif