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/CallingConv.h" 00026 #include "llvm/InlineAsm.h" 00027 #include "llvm/CodeGen/SelectionDAGNodes.h" 00028 #include "llvm/CodeGen/RuntimeLibcalls.h" 00029 #include "llvm/ADT/APFloat.h" 00030 #include "llvm/ADT/DenseMap.h" 00031 #include "llvm/ADT/SmallSet.h" 00032 #include "llvm/ADT/SmallVector.h" 00033 #include "llvm/ADT/STLExtras.h" 00034 #include "llvm/Support/DebugLoc.h" 00035 #include "llvm/Target/TargetMachine.h" 00036 #include <climits> 00037 #include <map> 00038 #include <vector> 00039 00040 namespace llvm { 00041 class AllocaInst; 00042 class CallInst; 00043 class Function; 00044 class FastISel; 00045 class MachineBasicBlock; 00046 class MachineFunction; 00047 class MachineFrameInfo; 00048 class MachineInstr; 00049 class MachineModuleInfo; 00050 class DwarfWriter; 00051 class SDNode; 00052 class SDValue; 00053 class SelectionDAG; 00054 class TargetData; 00055 class TargetMachine; 00056 class TargetRegisterClass; 00057 class TargetSubtarget; 00058 class TargetLoweringObjectFile; 00059 class Value; 00060 00061 // FIXME: should this be here? 00062 namespace TLSModel { 00063 enum Model { 00064 GeneralDynamic, 00065 LocalDynamic, 00066 InitialExec, 00067 LocalExec 00068 }; 00069 } 00070 TLSModel::Model getTLSModel(const GlobalValue *GV, Reloc::Model reloc); 00071 00072 00073 //===----------------------------------------------------------------------===// 00074 /// TargetLowering - This class defines information used to lower LLVM code to 00075 /// legal SelectionDAG operators that the target instruction selector can accept 00076 /// natively. 00077 /// 00078 /// This class also defines callbacks that targets must implement to lower 00079 /// target-specific constructs to SelectionDAG operators. 00080 /// 00081 class TargetLowering { 00082 TargetLowering(const TargetLowering&); // DO NOT IMPLEMENT 00083 void operator=(const TargetLowering&); // DO NOT IMPLEMENT 00084 public: 00085 /// LegalizeAction - This enum indicates whether operations are valid for a 00086 /// target, and if not, what action should be used to make them valid. 00087 enum LegalizeAction { 00088 Legal, // The target natively supports this operation. 00089 Promote, // This operation should be executed in a larger type. 00090 Expand, // Try to expand this to other ops, otherwise use a libcall. 00091 Custom // Use the LowerOperation hook to implement custom lowering. 00092 }; 00093 00094 enum BooleanContent { // How the target represents true/false values. 00095 UndefinedBooleanContent, // Only bit 0 counts, the rest can hold garbage. 00096 ZeroOrOneBooleanContent, // All bits zero except for bit 0. 00097 ZeroOrNegativeOneBooleanContent // All bits equal to bit 0. 00098 }; 00099 00100 enum SchedPreference { 00101 SchedulingForLatency, // Scheduling for shortest total latency. 00102 SchedulingForRegPressure // Scheduling for lowest register pressure. 00103 }; 00104 00105 /// NOTE: The constructor takes ownership of TLOF. 00106 explicit TargetLowering(TargetMachine &TM, TargetLoweringObjectFile *TLOF); 00107 virtual ~TargetLowering(); 00108 00109 TargetMachine &getTargetMachine() const { return TM; } 00110 const TargetData *getTargetData() const { return TD; } 00111 TargetLoweringObjectFile &getObjFileLowering() const { return TLOF; } 00112 00113 bool isBigEndian() const { return !IsLittleEndian; } 00114 bool isLittleEndian() const { return IsLittleEndian; } 00115 MVT getPointerTy() const { return PointerTy; } 00116 MVT getShiftAmountTy() const { return ShiftAmountTy; } 00117 00118 /// usesGlobalOffsetTable - Return true if this target uses a GOT for PIC 00119 /// codegen. 00120 bool usesGlobalOffsetTable() const { return UsesGlobalOffsetTable; } 00121 00122 /// isSelectExpensive - Return true if the select operation is expensive for 00123 /// this target. 00124 bool isSelectExpensive() const { return SelectIsExpensive; } 00125 00126 /// isIntDivCheap() - Return true if integer divide is usually cheaper than 00127 /// a sequence of several shifts, adds, and multiplies for this target. 00128 bool isIntDivCheap() const { return IntDivIsCheap; } 00129 00130 /// isPow2DivCheap() - Return true if pow2 div is cheaper than a chain of 00131 /// srl/add/sra. 00132 bool isPow2DivCheap() const { return Pow2DivIsCheap; } 00133 00134 /// getSetCCResultType - Return the ValueType of the result of SETCC 00135 /// operations. Also used to obtain the target's preferred type for 00136 /// the condition operand of SELECT and BRCOND nodes. In the case of 00137 /// BRCOND the argument passed is MVT::Other since there are no other 00138 /// operands to get a type hint from. 00139 virtual 00140 MVT::SimpleValueType getSetCCResultType(EVT VT) const; 00141 00142 /// getBooleanContents - For targets without i1 registers, this gives the 00143 /// nature of the high-bits of boolean values held in types wider than i1. 00144 /// "Boolean values" are special true/false values produced by nodes like 00145 /// SETCC and consumed (as the condition) by nodes like SELECT and BRCOND. 00146 /// Not to be confused with general values promoted from i1. 00147 BooleanContent getBooleanContents() const { return BooleanContents;} 00148 00149 /// getSchedulingPreference - Return target scheduling preference. 00150 SchedPreference getSchedulingPreference() const { 00151 return SchedPreferenceInfo; 00152 } 00153 00154 /// getRegClassFor - Return the register class that should be used for the 00155 /// specified value type. This may only be called on legal types. 00156 TargetRegisterClass *getRegClassFor(EVT VT) const { 00157 assert(VT.isSimple() && "getRegClassFor called on illegal type!"); 00158 TargetRegisterClass *RC = RegClassForVT[VT.getSimpleVT().SimpleTy]; 00159 assert(RC && "This value type is not natively supported!"); 00160 return RC; 00161 } 00162 00163 /// isTypeLegal - Return true if the target has native support for the 00164 /// specified value type. This means that it has a register that directly 00165 /// holds it without promotions or expansions. 00166 bool isTypeLegal(EVT VT) const { 00167 assert(!VT.isSimple() || 00168 (unsigned)VT.getSimpleVT().SimpleTy < array_lengthof(RegClassForVT)); 00169 return VT.isSimple() && RegClassForVT[VT.getSimpleVT().SimpleTy] != 0; 00170 } 00171 00172 class ValueTypeActionImpl { 00173 /// ValueTypeActions - This is a bitvector that contains two bits for each 00174 /// value type, where the two bits correspond to the LegalizeAction enum. 00175 /// This can be queried with "getTypeAction(VT)". 00176 /// dimension by (MVT::MAX_ALLOWED_VALUETYPE/32) * 2 00177 uint32_t ValueTypeActions[(MVT::MAX_ALLOWED_VALUETYPE/32)*2]; 00178 public: 00179 ValueTypeActionImpl() { 00180 ValueTypeActions[0] = ValueTypeActions[1] = 0; 00181 ValueTypeActions[2] = ValueTypeActions[3] = 0; 00182 } 00183 ValueTypeActionImpl(const ValueTypeActionImpl &RHS) { 00184 ValueTypeActions[0] = RHS.ValueTypeActions[0]; 00185 ValueTypeActions[1] = RHS.ValueTypeActions[1]; 00186 ValueTypeActions[2] = RHS.ValueTypeActions[2]; 00187 ValueTypeActions[3] = RHS.ValueTypeActions[3]; 00188 } 00189 00190 LegalizeAction getTypeAction(LLVMContext &Context, EVT VT) const { 00191 if (VT.isExtended()) { 00192 if (VT.isVector()) { 00193 return VT.isPow2VectorType() ? Expand : Promote; 00194 } 00195 if (VT.isInteger()) 00196 // First promote to a power-of-two size, then expand if necessary. 00197 return VT == VT.getRoundIntegerType(Context) ? Expand : Promote; 00198 assert(0 && "Unsupported extended type!"); 00199 return Legal; 00200 } 00201 unsigned I = VT.getSimpleVT().SimpleTy; 00202 assert(I<4*array_lengthof(ValueTypeActions)*sizeof(ValueTypeActions[0])); 00203 return (LegalizeAction)((ValueTypeActions[I>>4] >> ((2*I) & 31)) & 3); 00204 } 00205 void setTypeAction(EVT VT, LegalizeAction Action) { 00206 unsigned I = VT.getSimpleVT().SimpleTy; 00207 assert(I<4*array_lengthof(ValueTypeActions)*sizeof(ValueTypeActions[0])); 00208 ValueTypeActions[I>>4] |= Action << ((I*2) & 31); 00209 } 00210 }; 00211 00212 const ValueTypeActionImpl &getValueTypeActions() const { 00213 return ValueTypeActions; 00214 } 00215 00216 /// getTypeAction - Return how we should legalize values of this type, either 00217 /// it is already legal (return 'Legal') or we need to promote it to a larger 00218 /// type (return 'Promote'), or we need to expand it into multiple registers 00219 /// of smaller integer type (return 'Expand'). 'Custom' is not an option. 00220 LegalizeAction getTypeAction(LLVMContext &Context, EVT VT) const { 00221 return ValueTypeActions.getTypeAction(Context, VT); 00222 } 00223 00224 /// getTypeToTransformTo - For types supported by the target, this is an 00225 /// identity function. For types that must be promoted to larger types, this 00226 /// returns the larger type to promote to. For integer types that are larger 00227 /// than the largest integer register, this contains one step in the expansion 00228 /// to get to the smaller register. For illegal floating point types, this 00229 /// returns the integer type to transform to. 00230 EVT getTypeToTransformTo(LLVMContext &Context, EVT VT) const { 00231 if (VT.isSimple()) { 00232 assert((unsigned)VT.getSimpleVT().SimpleTy < 00233 array_lengthof(TransformToType)); 00234 EVT NVT = TransformToType[VT.getSimpleVT().SimpleTy]; 00235 assert(getTypeAction(Context, NVT) != Promote && 00236 "Promote may not follow Expand or Promote"); 00237 return NVT; 00238 } 00239 00240 if (VT.isVector()) { 00241 EVT NVT = VT.getPow2VectorType(Context); 00242 if (NVT == VT) { 00243 // Vector length is a power of 2 - split to half the size. 00244 unsigned NumElts = VT.getVectorNumElements(); 00245 EVT EltVT = VT.getVectorElementType(); 00246 return (NumElts == 1) ? 00247 EltVT : EVT::getVectorVT(Context, EltVT, NumElts / 2); 00248 } 00249 // Promote to a power of two size, avoiding multi-step promotion. 00250 return getTypeAction(Context, NVT) == Promote ? 00251 getTypeToTransformTo(Context, NVT) : NVT; 00252 } else if (VT.isInteger()) { 00253 EVT NVT = VT.getRoundIntegerType(Context); 00254 if (NVT == VT) 00255 // Size is a power of two - expand to half the size. 00256 return EVT::getIntegerVT(Context, VT.getSizeInBits() / 2); 00257 else 00258 // Promote to a power of two size, avoiding multi-step promotion. 00259 return getTypeAction(Context, NVT) == Promote ? 00260 getTypeToTransformTo(Context, NVT) : NVT; 00261 } 00262 assert(0 && "Unsupported extended type!"); 00263 return MVT(MVT::Other); // Not reached 00264 } 00265 00266 /// getTypeToExpandTo - For types supported by the target, this is an 00267 /// identity function. For types that must be expanded (i.e. integer types 00268 /// that are larger than the largest integer register or illegal floating 00269 /// point types), this returns the largest legal type it will be expanded to. 00270 EVT getTypeToExpandTo(LLVMContext &Context, EVT VT) const { 00271 assert(!VT.isVector()); 00272 while (true) { 00273 switch (getTypeAction(Context, VT)) { 00274 case Legal: 00275 return VT; 00276 case Expand: 00277 VT = getTypeToTransformTo(Context, VT); 00278 break; 00279 default: 00280 assert(false && "Type is not legal nor is it to be expanded!"); 00281 return VT; 00282 } 00283 } 00284 return VT; 00285 } 00286 00287 /// getVectorTypeBreakdown - Vector types are broken down into some number of 00288 /// legal first class types. For example, EVT::v8f32 maps to 2 EVT::v4f32 00289 /// with Altivec or SSE1, or 8 promoted EVT::f64 values with the X86 FP stack. 00290 /// Similarly, EVT::v2i64 turns into 4 EVT::i32 values with both PPC and X86. 00291 /// 00292 /// This method returns the number of registers needed, and the VT for each 00293 /// register. It also returns the VT and quantity of the intermediate values 00294 /// before they are promoted/expanded. 00295 /// 00296 unsigned getVectorTypeBreakdown(LLVMContext &Context, EVT VT, 00297 EVT &IntermediateVT, 00298 unsigned &NumIntermediates, 00299 EVT &RegisterVT) const; 00300 00301 /// getTgtMemIntrinsic: Given an intrinsic, checks if on the target the 00302 /// intrinsic will need to map to a MemIntrinsicNode (touches memory). If 00303 /// this is the case, it returns true and store the intrinsic 00304 /// information into the IntrinsicInfo that was passed to the function. 00305 typedef struct IntrinsicInfo { 00306 unsigned opc; // target opcode 00307 EVT memVT; // memory VT 00308 const Value* ptrVal; // value representing memory location 00309 int offset; // offset off of ptrVal 00310 unsigned align; // alignment 00311 bool vol; // is volatile? 00312 bool readMem; // reads memory? 00313 bool writeMem; // writes memory? 00314 } IntrinisicInfo; 00315 00316 virtual bool getTgtMemIntrinsic(IntrinsicInfo& Info, 00317 CallInst &I, unsigned Intrinsic) { 00318 return false; 00319 } 00320 00321 /// getWidenVectorType: given a vector type, returns the type to widen to 00322 /// (e.g., v7i8 to v8i8). If the vector type is legal, it returns itself. 00323 /// If there is no vector type that we want to widen to, returns MVT::Other 00324 /// When and were to widen is target dependent based on the cost of 00325 /// scalarizing vs using the wider vector type. 00326 virtual EVT getWidenVectorType(EVT VT) const; 00327 00328 typedef std::vector<APFloat>::const_iterator legal_fpimm_iterator; 00329 legal_fpimm_iterator legal_fpimm_begin() const { 00330 return LegalFPImmediates.begin(); 00331 } 00332 legal_fpimm_iterator legal_fpimm_end() const { 00333 return LegalFPImmediates.end(); 00334 } 00335 00336 /// isShuffleMaskLegal - Targets can use this to indicate that they only 00337 /// support *some* VECTOR_SHUFFLE operations, those with specific masks. 00338 /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values 00339 /// are assumed to be legal. 00340 virtual bool isShuffleMaskLegal(const SmallVectorImpl<int> &Mask, 00341 EVT VT) const { 00342 return true; 00343 } 00344 00345 /// isVectorClearMaskLegal - Similar to isShuffleMaskLegal. This is 00346 /// used by Targets can use this to indicate if there is a suitable 00347 /// VECTOR_SHUFFLE that can be used to replace a VAND with a constant 00348 /// pool entry. 00349 virtual bool isVectorClearMaskLegal(const SmallVectorImpl<int> &Mask, 00350 EVT VT) const { 00351 return false; 00352 } 00353 00354 /// getOperationAction - Return how this operation should be treated: either 00355 /// it is legal, needs to be promoted to a larger size, needs to be 00356 /// expanded to some other code sequence, or the target has a custom expander 00357 /// for it. 00358 LegalizeAction getOperationAction(unsigned Op, EVT VT) const { 00359 if (VT.isExtended()) return Expand; 00360 assert(Op < array_lengthof(OpActions[0]) && 00361 (unsigned)VT.getSimpleVT().SimpleTy < sizeof(OpActions[0][0])*8 && 00362 "Table isn't big enough!"); 00363 unsigned I = (unsigned) VT.getSimpleVT().SimpleTy; 00364 unsigned J = I & 31; 00365 I = I >> 5; 00366 return (LegalizeAction)((OpActions[I][Op] >> (J*2) ) & 3); 00367 } 00368 00369 /// isOperationLegalOrCustom - Return true if the specified operation is 00370 /// legal on this target or can be made legal with custom lowering. This 00371 /// is used to help guide high-level lowering decisions. 00372 bool isOperationLegalOrCustom(unsigned Op, EVT VT) const { 00373 return (VT == MVT::Other || isTypeLegal(VT)) && 00374 (getOperationAction(Op, VT) == Legal || 00375 getOperationAction(Op, VT) == Custom); 00376 } 00377 00378 /// isOperationLegal - Return true if the specified operation is legal on this 00379 /// target. 00380 bool isOperationLegal(unsigned Op, EVT VT) const { 00381 return (VT == MVT::Other || isTypeLegal(VT)) && 00382 getOperationAction(Op, VT) == Legal; 00383 } 00384 00385 /// getLoadExtAction - Return how this load with extension should be treated: 00386 /// either it is legal, needs to be promoted to a larger size, needs to be 00387 /// expanded to some other code sequence, or the target has a custom expander 00388 /// for it. 00389 LegalizeAction getLoadExtAction(unsigned LType, EVT VT) const { 00390 assert(LType < array_lengthof(LoadExtActions) && 00391 (unsigned)VT.getSimpleVT().SimpleTy < sizeof(LoadExtActions[0])*4 && 00392 "Table isn't big enough!"); 00393 return (LegalizeAction)((LoadExtActions[LType] >> 00394 (2*VT.getSimpleVT().SimpleTy)) & 3); 00395 } 00396 00397 /// isLoadExtLegal - Return true if the specified load with extension is legal 00398 /// on this target. 00399 bool isLoadExtLegal(unsigned LType, EVT VT) const { 00400 return VT.isSimple() && 00401 (getLoadExtAction(LType, VT) == Legal || 00402 getLoadExtAction(LType, VT) == Custom); 00403 } 00404 00405 /// getTruncStoreAction - Return how this store with truncation should be 00406 /// treated: either it is legal, needs to be promoted to a larger size, needs 00407 /// to be expanded to some other code sequence, or the target has a custom 00408 /// expander for it. 00409 LegalizeAction getTruncStoreAction(EVT ValVT, 00410 EVT MemVT) const { 00411 assert((unsigned)ValVT.getSimpleVT().SimpleTy < 00412 array_lengthof(TruncStoreActions) && 00413 (unsigned)MemVT.getSimpleVT().SimpleTy < 00414 sizeof(TruncStoreActions[0])*4 && 00415 "Table isn't big enough!"); 00416 return (LegalizeAction)((TruncStoreActions[ValVT.getSimpleVT().SimpleTy] >> 00417 (2*MemVT.getSimpleVT().SimpleTy)) & 3); 00418 } 00419 00420 /// isTruncStoreLegal - Return true if the specified store with truncation is 00421 /// legal on this target. 00422 bool isTruncStoreLegal(EVT ValVT, EVT MemVT) const { 00423 return isTypeLegal(ValVT) && MemVT.isSimple() && 00424 (getTruncStoreAction(ValVT, MemVT) == Legal || 00425 getTruncStoreAction(ValVT, MemVT) == Custom); 00426 } 00427 00428 /// getIndexedLoadAction - Return how the indexed load should be treated: 00429 /// either it is legal, needs to be promoted to a larger size, needs to be 00430 /// expanded to some other code sequence, or the target has a custom expander 00431 /// for it. 00432 LegalizeAction 00433 getIndexedLoadAction(unsigned IdxMode, EVT VT) const { 00434 assert( IdxMode < array_lengthof(IndexedModeActions[0][0]) && 00435 ((unsigned)VT.getSimpleVT().SimpleTy) < MVT::LAST_VALUETYPE && 00436 "Table isn't big enough!"); 00437 return (LegalizeAction)((IndexedModeActions[ 00438 (unsigned)VT.getSimpleVT().SimpleTy][0][IdxMode])); 00439 } 00440 00441 /// isIndexedLoadLegal - Return true if the specified indexed load is legal 00442 /// on this target. 00443 bool isIndexedLoadLegal(unsigned IdxMode, EVT VT) const { 00444 return VT.isSimple() && 00445 (getIndexedLoadAction(IdxMode, VT) == Legal || 00446 getIndexedLoadAction(IdxMode, VT) == Custom); 00447 } 00448 00449 /// getIndexedStoreAction - Return how the indexed store should be treated: 00450 /// either it is legal, needs to be promoted to a larger size, needs to be 00451 /// expanded to some other code sequence, or the target has a custom expander 00452 /// for it. 00453 LegalizeAction 00454 getIndexedStoreAction(unsigned IdxMode, EVT VT) const { 00455 assert(IdxMode < array_lengthof(IndexedModeActions[0][1]) && 00456 (unsigned)VT.getSimpleVT().SimpleTy < MVT::LAST_VALUETYPE && 00457 "Table isn't big enough!"); 00458 return (LegalizeAction)((IndexedModeActions[ 00459 (unsigned)VT.getSimpleVT().SimpleTy][1][IdxMode])); 00460 } 00461 00462 /// isIndexedStoreLegal - Return true if the specified indexed load is legal 00463 /// on this target. 00464 bool isIndexedStoreLegal(unsigned IdxMode, EVT VT) const { 00465 return VT.isSimple() && 00466 (getIndexedStoreAction(IdxMode, VT) == Legal || 00467 getIndexedStoreAction(IdxMode, VT) == Custom); 00468 } 00469 00470 /// getConvertAction - Return how the conversion should be treated: 00471 /// either it is legal, needs to be promoted to a larger size, needs to be 00472 /// expanded to some other code sequence, or the target has a custom expander 00473 /// for it. 00474 LegalizeAction 00475 getConvertAction(EVT FromVT, EVT ToVT) const { 00476 assert((unsigned)FromVT.getSimpleVT().SimpleTy < 00477 array_lengthof(ConvertActions) && 00478 (unsigned)ToVT.getSimpleVT().SimpleTy < 00479 sizeof(ConvertActions[0])*4 && 00480 "Table isn't big enough!"); 00481 return (LegalizeAction)((ConvertActions[FromVT.getSimpleVT().SimpleTy] >> 00482 (2*ToVT.getSimpleVT().SimpleTy)) & 3); 00483 } 00484 00485 /// isConvertLegal - Return true if the specified conversion is legal 00486 /// on this target. 00487 bool isConvertLegal(EVT FromVT, EVT ToVT) const { 00488 return isTypeLegal(FromVT) && isTypeLegal(ToVT) && 00489 (getConvertAction(FromVT, ToVT) == Legal || 00490 getConvertAction(FromVT, ToVT) == Custom); 00491 } 00492 00493 /// getCondCodeAction - Return how the condition code should be treated: 00494 /// either it is legal, needs to be expanded to some other code sequence, 00495 /// or the target has a custom expander for it. 00496 LegalizeAction 00497 getCondCodeAction(ISD::CondCode CC, EVT VT) const { 00498 assert((unsigned)CC < array_lengthof(CondCodeActions) && 00499 (unsigned)VT.getSimpleVT().SimpleTy < sizeof(CondCodeActions[0])*4 && 00500 "Table isn't big enough!"); 00501 LegalizeAction Action = (LegalizeAction) 00502 ((CondCodeActions[CC] >> (2*VT.getSimpleVT().SimpleTy)) & 3); 00503 assert(Action != Promote && "Can't promote condition code!"); 00504 return Action; 00505 } 00506 00507 /// isCondCodeLegal - Return true if the specified condition code is legal 00508 /// on this target. 00509 bool isCondCodeLegal(ISD::CondCode CC, EVT VT) const { 00510 return getCondCodeAction(CC, VT) == Legal || 00511 getCondCodeAction(CC, VT) == Custom; 00512 } 00513 00514 00515 /// getTypeToPromoteTo - If the action for this operation is to promote, this 00516 /// method returns the ValueType to promote to. 00517 EVT getTypeToPromoteTo(unsigned Op, EVT VT) const { 00518 assert(getOperationAction(Op, VT) == Promote && 00519 "This operation isn't promoted!"); 00520 00521 // See if this has an explicit type specified. 00522 std::map<std::pair<unsigned, MVT::SimpleValueType>, 00523 MVT::SimpleValueType>::const_iterator PTTI = 00524 PromoteToType.find(std::make_pair(Op, VT.getSimpleVT().SimpleTy)); 00525 if (PTTI != PromoteToType.end()) return PTTI->second; 00526 00527 assert((VT.isInteger() || VT.isFloatingPoint()) && 00528 "Cannot autopromote this type, add it with AddPromotedToType."); 00529 00530 EVT NVT = VT; 00531 do { 00532 NVT = (MVT::SimpleValueType)(NVT.getSimpleVT().SimpleTy+1); 00533 assert(NVT.isInteger() == VT.isInteger() && NVT != MVT::isVoid && 00534 "Didn't find type to promote to!"); 00535 } while (!isTypeLegal(NVT) || 00536 getOperationAction(Op, NVT) == Promote); 00537 return NVT; 00538 } 00539 00540 /// getValueType - Return the EVT corresponding to this LLVM type. 00541 /// This is fixed by the LLVM operations except for the pointer size. If 00542 /// AllowUnknown is true, this will return MVT::Other for types with no EVT 00543 /// counterpart (e.g. structs), otherwise it will assert. 00544 EVT getValueType(const Type *Ty, bool AllowUnknown = false) const { 00545 EVT VT = EVT::getEVT(Ty, AllowUnknown); 00546 return VT == MVT:: iPTR ? PointerTy : VT; 00547 } 00548 00549 /// getByValTypeAlignment - Return the desired alignment for ByVal aggregate 00550 /// function arguments in the caller parameter area. This is the actual 00551 /// alignment, not its logarithm. 00552 virtual unsigned getByValTypeAlignment(const Type *Ty) const; 00553 00554 /// getRegisterType - Return the type of registers that this ValueType will 00555 /// eventually require. 00556 EVT getRegisterType(MVT VT) const { 00557 assert((unsigned)VT.SimpleTy < array_lengthof(RegisterTypeForVT)); 00558 return RegisterTypeForVT[VT.SimpleTy]; 00559 } 00560 00561 /// getRegisterType - Return the type of registers that this ValueType will 00562 /// eventually require. 00563 EVT getRegisterType(LLVMContext &Context, EVT VT) const { 00564 if (VT.isSimple()) { 00565 assert((unsigned)VT.getSimpleVT().SimpleTy < 00566 array_lengthof(RegisterTypeForVT)); 00567 return RegisterTypeForVT[VT.getSimpleVT().SimpleTy]; 00568 } 00569 if (VT.isVector()) { 00570 EVT VT1, RegisterVT; 00571 unsigned NumIntermediates; 00572 (void)getVectorTypeBreakdown(Context, VT, VT1, 00573 NumIntermediates, RegisterVT); 00574 return RegisterVT; 00575 } 00576 if (VT.isInteger()) { 00577 return getRegisterType(Context, getTypeToTransformTo(Context, VT)); 00578 } 00579 assert(0 && "Unsupported extended type!"); 00580 return EVT(MVT::Other); // Not reached 00581 } 00582 00583 /// getNumRegisters - Return the number of registers that this ValueType will 00584 /// eventually require. This is one for any types promoted to live in larger 00585 /// registers, but may be more than one for types (like i64) that are split 00586 /// into pieces. For types like i140, which are first promoted then expanded, 00587 /// it is the number of registers needed to hold all the bits of the original 00588 /// type. For an i140 on a 32 bit machine this means 5 registers. 00589 unsigned getNumRegisters(LLVMContext &Context, EVT VT) const { 00590 if (VT.isSimple()) { 00591 assert((unsigned)VT.getSimpleVT().SimpleTy < 00592 array_lengthof(NumRegistersForVT)); 00593 return NumRegistersForVT[VT.getSimpleVT().SimpleTy]; 00594 } 00595 if (VT.isVector()) { 00596 EVT VT1, VT2; 00597 unsigned NumIntermediates; 00598 return getVectorTypeBreakdown(Context, VT, VT1, NumIntermediates, VT2); 00599 } 00600 if (VT.isInteger()) { 00601 unsigned BitWidth = VT.getSizeInBits(); 00602 unsigned RegWidth = getRegisterType(Context, VT).getSizeInBits(); 00603 return (BitWidth + RegWidth - 1) / RegWidth; 00604 } 00605 assert(0 && "Unsupported extended type!"); 00606 return 0; // Not reached 00607 } 00608 00609 /// ShouldShrinkFPConstant - If true, then instruction selection should 00610 /// seek to shrink the FP constant of the specified type to a smaller type 00611 /// in order to save space and / or reduce runtime. 00612 virtual bool ShouldShrinkFPConstant(EVT VT) const { return true; } 00613 00614 /// hasTargetDAGCombine - If true, the target has custom DAG combine 00615 /// transformations that it can perform for the specified node. 00616 bool hasTargetDAGCombine(ISD::NodeType NT) const { 00617 assert(unsigned(NT >> 3) < array_lengthof(TargetDAGCombineArray)); 00618 return TargetDAGCombineArray[NT >> 3] & (1 << (NT&7)); 00619 } 00620 00621 /// This function returns the maximum number of store operations permitted 00622 /// to replace a call to llvm.memset. The value is set by the target at the 00623 /// performance threshold for such a replacement. 00624 /// @brief Get maximum # of store operations permitted for llvm.memset 00625 unsigned getMaxStoresPerMemset() const { return maxStoresPerMemset; } 00626 00627 /// This function returns the maximum number of store operations permitted 00628 /// to replace a call to llvm.memcpy. The value is set by the target at the 00629 /// performance threshold for such a replacement. 00630 /// @brief Get maximum # of store operations permitted for llvm.memcpy 00631 unsigned getMaxStoresPerMemcpy() const { return maxStoresPerMemcpy; } 00632 00633 /// This function returns the maximum number of store operations permitted 00634 /// to replace a call to llvm.memmove. The value is set by the target at the 00635 /// performance threshold for such a replacement. 00636 /// @brief Get maximum # of store operations permitted for llvm.memmove 00637 unsigned getMaxStoresPerMemmove() const { return maxStoresPerMemmove; } 00638 00639 /// This function returns true if the target allows unaligned memory accesses. 00640 /// of the specified type. This is used, for example, in situations where an 00641 /// array copy/move/set is converted to a sequence of store operations. It's 00642 /// use helps to ensure that such replacements don't generate code that causes 00643 /// an alignment error (trap) on the target machine. 00644 /// @brief Determine if the target supports unaligned memory accesses. 00645 virtual bool allowsUnalignedMemoryAccesses(EVT VT) const { 00646 return false; 00647 } 00648 00649 /// This function returns true if the target would benefit from code placement 00650 /// optimization. 00651 /// @brief Determine if the target should perform code placement optimization. 00652 bool shouldOptimizeCodePlacement() const { 00653 return benefitFromCodePlacementOpt; 00654 } 00655 00656 /// getOptimalMemOpType - Returns the target specific optimal type for load 00657 /// and store operations as a result of memset, memcpy, and memmove lowering. 00658 /// It returns EVT::iAny if SelectionDAG should be responsible for 00659 /// determining it. 00660 virtual EVT getOptimalMemOpType(uint64_t Size, unsigned Align, 00661 bool isSrcConst, bool isSrcStr, 00662 SelectionDAG &DAG) const { 00663 return MVT::iAny; 00664 } 00665 00666 /// usesUnderscoreSetJmp - Determine if we should use _setjmp or setjmp 00667 /// to implement llvm.setjmp. 00668 bool usesUnderscoreSetJmp() const { 00669 return UseUnderscoreSetJmp; 00670 } 00671 00672 /// usesUnderscoreLongJmp - Determine if we should use _longjmp or longjmp 00673 /// to implement llvm.longjmp. 00674 bool usesUnderscoreLongJmp() const { 00675 return UseUnderscoreLongJmp; 00676 } 00677 00678 /// getStackPointerRegisterToSaveRestore - If a physical register, this 00679 /// specifies the register that llvm.savestack/llvm.restorestack should save 00680 /// and restore. 00681 unsigned getStackPointerRegisterToSaveRestore() const { 00682 return StackPointerRegisterToSaveRestore; 00683 } 00684 00685 /// getExceptionAddressRegister - If a physical register, this returns 00686 /// the register that receives the exception address on entry to a landing 00687 /// pad. 00688 unsigned getExceptionAddressRegister() const { 00689 return ExceptionPointerRegister; 00690 } 00691 00692 /// getExceptionSelectorRegister - If a physical register, this returns 00693 /// the register that receives the exception typeid on entry to a landing 00694 /// pad. 00695 unsigned getExceptionSelectorRegister() const { 00696 return ExceptionSelectorRegister; 00697 } 00698 00699 /// getJumpBufSize - returns the target's jmp_buf size in bytes (if never 00700 /// set, the default is 200) 00701 unsigned getJumpBufSize() const { 00702 return JumpBufSize; 00703 } 00704 00705 /// getJumpBufAlignment - returns the target's jmp_buf alignment in bytes 00706 /// (if never set, the default is 0) 00707 unsigned getJumpBufAlignment() const { 00708 return JumpBufAlignment; 00709 } 00710 00711 /// getIfCvtBlockLimit - returns the target specific if-conversion block size 00712 /// limit. Any block whose size is greater should not be predicated. 00713 unsigned getIfCvtBlockSizeLimit() const { 00714 return IfCvtBlockSizeLimit; 00715 } 00716 00717 /// getIfCvtDupBlockLimit - returns the target specific size limit for a 00718 /// block to be considered for duplication. Any block whose size is greater 00719 /// should not be duplicated to facilitate its predication. 00720 unsigned getIfCvtDupBlockSizeLimit() const { 00721 return IfCvtDupBlockSizeLimit; 00722 } 00723 00724 /// getPrefLoopAlignment - return the preferred loop alignment. 00725 /// 00726 unsigned getPrefLoopAlignment() const { 00727 return PrefLoopAlignment; 00728 } 00729 00730 /// getPreIndexedAddressParts - returns true by value, base pointer and 00731 /// offset pointer and addressing mode by reference if the node's address 00732 /// can be legally represented as pre-indexed load / store address. 00733 virtual bool getPreIndexedAddressParts(SDNode *N, SDValue &Base, 00734 SDValue &Offset, 00735 ISD::MemIndexedMode &AM, 00736 SelectionDAG &DAG) const { 00737 return false; 00738 } 00739 00740 /// getPostIndexedAddressParts - returns true by value, base pointer and 00741 /// offset pointer and addressing mode by reference if this node can be 00742 /// combined with a load / store to form a post-indexed load / store. 00743 virtual bool getPostIndexedAddressParts(SDNode *N, SDNode *Op, 00744 SDValue &Base, SDValue &Offset, 00745 ISD::MemIndexedMode &AM, 00746 SelectionDAG &DAG) const { 00747 return false; 00748 } 00749 00750 /// getPICJumpTableRelocaBase - Returns relocation base for the given PIC 00751 /// jumptable. 00752 virtual SDValue getPICJumpTableRelocBase(SDValue Table, 00753 SelectionDAG &DAG) const; 00754 00755 /// isOffsetFoldingLegal - Return true if folding a constant offset 00756 /// with the given GlobalAddress is legal. It is frequently not legal in 00757 /// PIC relocation models. 00758 virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const; 00759 00760 /// getFunctionAlignment - Return the Log2 alignment of this function. 00761 virtual unsigned getFunctionAlignment(const Function *) const = 0; 00762 00763 //===--------------------------------------------------------------------===// 00764 // TargetLowering Optimization Methods 00765 // 00766 00767 /// TargetLoweringOpt - A convenience struct that encapsulates a DAG, and two 00768 /// SDValues for returning information from TargetLowering to its clients 00769 /// that want to combine 00770 struct TargetLoweringOpt { 00771 SelectionDAG &DAG; 00772 SDValue Old; 00773 SDValue New; 00774 00775 explicit TargetLoweringOpt(SelectionDAG &InDAG) : DAG(InDAG) {} 00776 00777 bool CombineTo(SDValue O, SDValue N) { 00778 Old = O; 00779 New = N; 00780 return true; 00781 } 00782 00783 /// ShrinkDemandedConstant - Check to see if the specified operand of the 00784 /// specified instruction is a constant integer. If so, check to see if 00785 /// there are any bits set in the constant that are not demanded. If so, 00786 /// shrink the constant and return true. 00787 bool ShrinkDemandedConstant(SDValue Op, const APInt &Demanded); 00788 00789 /// ShrinkDemandedOp - Convert x+y to (VT)((SmallVT)x+(SmallVT)y) if the 00790 /// casts are free. This uses isZExtFree and ZERO_EXTEND for the widening 00791 /// cast, but it could be generalized for targets with other types of 00792 /// implicit widening casts. 00793 bool ShrinkDemandedOp(SDValue Op, unsigned BitWidth, const APInt &Demanded, 00794 DebugLoc dl); 00795 }; 00796 00797 /// SimplifyDemandedBits - Look at Op. At this point, we know that only the 00798 /// DemandedMask bits of the result of Op are ever used downstream. If we can 00799 /// use this information to simplify Op, create a new simplified DAG node and 00800 /// return true, returning the original and new nodes in Old and New. 00801 /// Otherwise, analyze the expression and return a mask of KnownOne and 00802 /// KnownZero bits for the expression (used to simplify the caller). 00803 /// The KnownZero/One bits may only be accurate for those bits in the 00804 /// DemandedMask. 00805 bool SimplifyDemandedBits(SDValue Op, const APInt &DemandedMask, 00806 APInt &KnownZero, APInt &KnownOne, 00807 TargetLoweringOpt &TLO, unsigned Depth = 0) const; 00808 00809 /// computeMaskedBitsForTargetNode - Determine which of the bits specified in 00810 /// Mask are known to be either zero or one and return them in the 00811 /// KnownZero/KnownOne bitsets. 00812 virtual void computeMaskedBitsForTargetNode(const SDValue Op, 00813 const APInt &Mask, 00814 APInt &KnownZero, 00815 APInt &KnownOne, 00816 const SelectionDAG &DAG, 00817 unsigned Depth = 0) const; 00818 00819 /// ComputeNumSignBitsForTargetNode - This method can be implemented by 00820 /// targets that want to expose additional information about sign bits to the 00821 /// DAG Combiner. 00822 virtual unsigned ComputeNumSignBitsForTargetNode(SDValue Op, 00823 unsigned Depth = 0) const; 00824 00825 struct DAGCombinerInfo { 00826 void *DC; // The DAG Combiner object. 00827 bool BeforeLegalize; 00828 bool BeforeLegalizeOps; 00829 bool CalledByLegalizer; 00830 public: 00831 SelectionDAG &DAG; 00832 00833 DAGCombinerInfo(SelectionDAG &dag, bool bl, bool blo, bool cl, void *dc) 00834 : DC(dc), BeforeLegalize(bl), BeforeLegalizeOps(blo), 00835 CalledByLegalizer(cl), DAG(dag) {} 00836 00837 bool isBeforeLegalize() const { return BeforeLegalize; } 00838 bool isBeforeLegalizeOps() const { return BeforeLegalizeOps; } 00839 bool isCalledByLegalizer() const { return CalledByLegalizer; } 00840 00841 void AddToWorklist(SDNode *N); 00842 SDValue CombineTo(SDNode *N, const std::vector<SDValue> &To, 00843 bool AddTo = true); 00844 SDValue CombineTo(SDNode *N, SDValue Res, bool AddTo = true); 00845 SDValue CombineTo(SDNode *N, SDValue Res0, SDValue Res1, bool AddTo = true); 00846 00847 void CommitTargetLoweringOpt(const TargetLoweringOpt &TLO); 00848 }; 00849 00850 /// SimplifySetCC - Try to simplify a setcc built with the specified operands 00851 /// and cc. If it is unable to simplify it, return a null SDValue. 00852 SDValue SimplifySetCC(EVT VT, SDValue N0, SDValue N1, 00853 ISD::CondCode Cond, bool foldBooleans, 00854 DAGCombinerInfo &DCI, DebugLoc dl) const; 00855 00856 /// isGAPlusOffset - Returns true (and the GlobalValue and the offset) if the 00857 /// node is a GlobalAddress + offset. 00858 virtual bool 00859 isGAPlusOffset(SDNode *N, GlobalValue* &GA, int64_t &Offset) const; 00860 00861 /// isConsecutiveLoad - Return true if LD is loading 'Bytes' bytes from a 00862 /// location that is 'Dist' units away from the location that the 'Base' load 00863 /// is loading from. 00864 bool isConsecutiveLoad(LoadSDNode *LD, LoadSDNode *Base, unsigned Bytes, 00865 int Dist, const MachineFrameInfo *MFI) const; 00866 00867 /// PerformDAGCombine - This method will be invoked for all target nodes and 00868 /// for any target-independent nodes that the target has registered with 00869 /// invoke it for. 00870 /// 00871 /// The semantics are as follows: 00872 /// Return Value: 00873 /// SDValue.Val == 0 - No change was made 00874 /// SDValue.Val == N - N was replaced, is dead, and is already handled. 00875 /// otherwise - N should be replaced by the returned Operand. 00876 /// 00877 /// In addition, methods provided by DAGCombinerInfo may be used to perform 00878 /// more complex transformations. 00879 /// 00880 virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const; 00881 00882 //===--------------------------------------------------------------------===// 00883 // TargetLowering Configuration Methods - These methods should be invoked by 00884 // the derived class constructor to configure this object for the target. 00885 // 00886 00887 protected: 00888 /// setUsesGlobalOffsetTable - Specify that this target does or doesn't use a 00889 /// GOT for PC-relative code. 00890 void setUsesGlobalOffsetTable(bool V) { UsesGlobalOffsetTable = V; } 00891 00892 /// setShiftAmountType - Describe the type that should be used for shift 00893 /// amounts. This type defaults to the pointer type. 00894 void setShiftAmountType(MVT VT) { ShiftAmountTy = VT; } 00895 00896 /// setBooleanContents - Specify how the target extends the result of a 00897 /// boolean value from i1 to a wider type. See getBooleanContents. 00898 void setBooleanContents(BooleanContent Ty) { BooleanContents = Ty; } 00899 00900 /// setSchedulingPreference - Specify the target scheduling preference. 00901 void setSchedulingPreference(SchedPreference Pref) { 00902 SchedPreferenceInfo = Pref; 00903 } 00904 00905 /// setUseUnderscoreSetJmp - Indicate whether this target prefers to 00906 /// use _setjmp to implement llvm.setjmp or the non _ version. 00907 /// Defaults to false. 00908 void setUseUnderscoreSetJmp(bool Val) { 00909 UseUnderscoreSetJmp = Val; 00910 } 00911 00912 /// setUseUnderscoreLongJmp - Indicate whether this target prefers to 00913 /// use _longjmp to implement llvm.longjmp or the non _ version. 00914 /// Defaults to false. 00915 void setUseUnderscoreLongJmp(bool Val) { 00916 UseUnderscoreLongJmp = Val; 00917 } 00918 00919 /// setStackPointerRegisterToSaveRestore - If set to a physical register, this 00920 /// specifies the register that llvm.savestack/llvm.restorestack should save 00921 /// and restore. 00922 void setStackPointerRegisterToSaveRestore(unsigned R) { 00923 StackPointerRegisterToSaveRestore = R; 00924 } 00925 00926 /// setExceptionPointerRegister - If set to a physical register, this sets 00927 /// the register that receives the exception address on entry to a landing 00928 /// pad. 00929 void setExceptionPointerRegister(unsigned R) { 00930 ExceptionPointerRegister = R; 00931 } 00932 00933 /// setExceptionSelectorRegister - If set to a physical register, this sets 00934 /// the register that receives the exception typeid on entry to a landing 00935 /// pad. 00936 void setExceptionSelectorRegister(unsigned R) { 00937 ExceptionSelectorRegister = R; 00938 } 00939 00940 /// SelectIsExpensive - Tells the code generator not to expand operations 00941 /// into sequences that use the select operations if possible. 00942 void setSelectIsExpensive() { SelectIsExpensive = true; } 00943 00944 /// setIntDivIsCheap - Tells the code generator that integer divide is 00945 /// expensive, and if possible, should be replaced by an alternate sequence 00946 /// of instructions not containing an integer divide. 00947 void setIntDivIsCheap(bool isCheap = true) { IntDivIsCheap = isCheap; } 00948 00949 /// setPow2DivIsCheap - Tells the code generator that it shouldn't generate 00950 /// srl/add/sra for a signed divide by power of two, and let the target handle 00951 /// it. 00952 void setPow2DivIsCheap(bool isCheap = true) { Pow2DivIsCheap = isCheap; } 00953 00954 /// addRegisterClass - Add the specified register class as an available 00955 /// regclass for the specified value type. This indicates the selector can 00956 /// handle values of that class natively. 00957 void addRegisterClass(EVT VT, TargetRegisterClass *RC) { 00958 assert((unsigned)VT.getSimpleVT().SimpleTy < array_lengthof(RegClassForVT)); 00959 AvailableRegClasses.push_back(std::make_pair(VT, RC)); 00960 RegClassForVT[VT.getSimpleVT().SimpleTy] = RC; 00961 } 00962 00963 /// computeRegisterProperties - Once all of the register classes are added, 00964 /// this allows us to compute derived properties we expose. 00965 void computeRegisterProperties(); 00966 00967 /// setOperationAction - Indicate that the specified operation does not work 00968 /// with the specified type and indicate what to do about it. 00969 void setOperationAction(unsigned Op, MVT VT, 00970 LegalizeAction Action) { 00971 unsigned I = (unsigned)VT.SimpleTy; 00972 unsigned J = I & 31; 00973 I = I >> 5; 00974 OpActions[I][Op] &= ~(uint64_t(3UL) << (J*2)); 00975 OpActions[I][Op] |= (uint64_t)Action << (J*2); 00976 } 00977 00978 /// setLoadExtAction - Indicate that the specified load with extension does 00979 /// not work with the with specified type and indicate what to do about it. 00980 void setLoadExtAction(unsigned ExtType, MVT VT, 00981 LegalizeAction Action) { 00982 assert((unsigned)VT.SimpleTy < sizeof(LoadExtActions[0])*4 && 00983 ExtType < array_lengthof(LoadExtActions) && 00984 "Table isn't big enough!"); 00985 LoadExtActions[ExtType] &= ~(uint64_t(3UL) << VT.SimpleTy*2); 00986 LoadExtActions[ExtType] |= (uint64_t)Action << VT.SimpleTy*2; 00987 } 00988 00989 /// setTruncStoreAction - Indicate that the specified truncating store does 00990 /// not work with the with specified type and indicate what to do about it. 00991 void setTruncStoreAction(MVT ValVT, MVT MemVT, 00992 LegalizeAction Action) { 00993 assert((unsigned)ValVT.SimpleTy < array_lengthof(TruncStoreActions) && 00994 (unsigned)MemVT.SimpleTy < sizeof(TruncStoreActions[0])*4 && 00995 "Table isn't big enough!"); 00996 TruncStoreActions[ValVT.SimpleTy] &= ~(uint64_t(3UL) << MemVT.SimpleTy*2); 00997 TruncStoreActions[ValVT.SimpleTy] |= (uint64_t)Action << MemVT.SimpleTy*2; 00998 } 00999 01000 /// setIndexedLoadAction - Indicate that the specified indexed load does or 01001 /// does not work with the with 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((unsigned)VT.SimpleTy < MVT::LAST_VALUETYPE && 01007 IdxMode < array_lengthof(IndexedModeActions[0][0]) && 01008 "Table isn't big enough!"); 01009 IndexedModeActions[(unsigned)VT.SimpleTy][0][IdxMode] = (uint8_t)Action; 01010 } 01011 01012 /// setIndexedStoreAction - Indicate that the specified indexed store does or 01013 /// does not work with the with specified type and indicate what to do about 01014 /// it. NOTE: All indexed mode stores are initialized to Expand in 01015 /// TargetLowering.cpp 01016 void setIndexedStoreAction(unsigned IdxMode, MVT VT, 01017 LegalizeAction Action) { 01018 assert((unsigned)VT.SimpleTy < MVT::LAST_VALUETYPE && 01019 IdxMode < array_lengthof(IndexedModeActions[0][1] ) && 01020 "Table isn't big enough!"); 01021 IndexedModeActions[(unsigned)VT.SimpleTy][1][IdxMode] = (uint8_t)Action; 01022 } 01023 01024 /// setConvertAction - Indicate that the specified conversion does or does 01025 /// not work with the with specified type and indicate what to do about it. 01026 void setConvertAction(MVT FromVT, MVT ToVT, 01027 LegalizeAction Action) { 01028 assert((unsigned)FromVT.SimpleTy < array_lengthof(ConvertActions) && 01029 (unsigned)ToVT.SimpleTy < sizeof(ConvertActions[0])*4 && 01030 "Table isn't big enough!"); 01031 ConvertActions[FromVT.SimpleTy] &= ~(uint64_t(3UL) << ToVT.SimpleTy*2); 01032 ConvertActions[FromVT.SimpleTy] |= (uint64_t)Action << ToVT.SimpleTy*2; 01033 } 01034 01035 /// setCondCodeAction - Indicate that the specified condition code is or isn't 01036 /// supported on the target and indicate what to do about it. 01037 void setCondCodeAction(ISD::CondCode CC, MVT VT, 01038 LegalizeAction Action) { 01039 assert((unsigned)VT.SimpleTy < sizeof(CondCodeActions[0])*4 && 01040 (unsigned)CC < array_lengthof(CondCodeActions) && 01041 "Table isn't big enough!"); 01042 CondCodeActions[(unsigned)CC] &= ~(uint64_t(3UL) << VT.SimpleTy*2); 01043 CondCodeActions[(unsigned)CC] |= (uint64_t)Action << VT.SimpleTy*2; 01044 } 01045 01046 /// AddPromotedToType - If Opc/OrigVT is specified as being promoted, the 01047 /// promotion code defaults to trying a larger integer/fp until it can find 01048 /// one that works. If that default is insufficient, this method can be used 01049 /// by the target to override the default. 01050 void AddPromotedToType(unsigned Opc, MVT OrigVT, MVT DestVT) { 01051 PromoteToType[std::make_pair(Opc, OrigVT.SimpleTy)] = DestVT.SimpleTy; 01052 } 01053 01054 /// addLegalFPImmediate - Indicate that this target can instruction select 01055 /// the specified FP immediate natively. 01056 void addLegalFPImmediate(const APFloat& Imm) { 01057 LegalFPImmediates.push_back(Imm); 01058 } 01059 01060 /// setTargetDAGCombine - Targets should invoke this method for each target 01061 /// independent node that they want to provide a custom DAG combiner for by 01062 /// implementing the PerformDAGCombine virtual method. 01063 void setTargetDAGCombine(ISD::NodeType NT) { 01064 assert(unsigned(NT >> 3) < array_lengthof(TargetDAGCombineArray)); 01065 TargetDAGCombineArray[NT >> 3] |= 1 << (NT&7); 01066 } 01067 01068 /// setJumpBufSize - Set the target's required jmp_buf buffer size (in 01069 /// bytes); default is 200 01070 void setJumpBufSize(unsigned Size) { 01071 JumpBufSize = Size; 01072 } 01073 01074 /// setJumpBufAlignment - Set the target's required jmp_buf buffer 01075 /// alignment (in bytes); default is 0 01076 void setJumpBufAlignment(unsigned Align) { 01077 JumpBufAlignment = Align; 01078 } 01079 01080 /// setIfCvtBlockSizeLimit - Set the target's if-conversion block size 01081 /// limit (in number of instructions); default is 2. 01082 void setIfCvtBlockSizeLimit(unsigned Limit) { 01083 IfCvtBlockSizeLimit = Limit; 01084 } 01085 01086 /// setIfCvtDupBlockSizeLimit - Set the target's block size limit (in number 01087 /// of instructions) to be considered for code duplication during 01088 /// if-conversion; default is 2. 01089 void setIfCvtDupBlockSizeLimit(unsigned Limit) { 01090 IfCvtDupBlockSizeLimit = Limit; 01091 } 01092 01093 /// setPrefLoopAlignment - Set the target's preferred loop alignment. Default 01094 /// alignment is zero, it means the target does not care about loop alignment. 01095 void setPrefLoopAlignment(unsigned Align) { 01096 PrefLoopAlignment = Align; 01097 } 01098 01099 public: 01100 01101 virtual const TargetSubtarget *getSubtarget() { 01102 assert(0 && "Not Implemented"); 01103 return NULL; // this is here to silence compiler errors 01104 } 01105 01106 //===--------------------------------------------------------------------===// 01107 // Lowering methods - These methods must be implemented by targets so that 01108 // the SelectionDAGLowering code knows how to lower these. 01109 // 01110 01111 /// LowerFormalArguments - This hook must be implemented to lower the 01112 /// incoming (formal) arguments, described by the Ins array, into the 01113 /// specified DAG. The implementation should fill in the InVals array 01114 /// with legal-type argument values, and return the resulting token 01115 /// chain value. 01116 /// 01117 virtual SDValue 01118 LowerFormalArguments(SDValue Chain, 01119 unsigned CallConv, bool isVarArg, 01120 const SmallVectorImpl<ISD::InputArg> &Ins, 01121 DebugLoc dl, SelectionDAG &DAG, 01122 SmallVectorImpl<SDValue> &InVals) { 01123 assert(0 && "Not Implemented"); 01124 return SDValue(); // this is here to silence compiler errors 01125 } 01126 01127 /// LowerCallTo - This function lowers an abstract call to a function into an 01128 /// actual call. This returns a pair of operands. The first element is the 01129 /// return value for the function (if RetTy is not VoidTy). The second 01130 /// element is the outgoing token chain. It calls LowerCall to do the actual 01131 /// lowering. 01132 struct ArgListEntry { 01133 SDValue Node; 01134 const Type* Ty; 01135 bool isSExt : 1; 01136 bool isZExt : 1; 01137 bool isInReg : 1; 01138 bool isSRet : 1; 01139 bool isNest : 1; 01140 bool isByVal : 1; 01141 uint16_t Alignment; 01142 01143 ArgListEntry() : isSExt(false), isZExt(false), isInReg(false), 01144 isSRet(false), isNest(false), isByVal(false), Alignment(0) { } 01145 }; 01146 typedef std::vector<ArgListEntry> ArgListTy; 01147 std::pair<SDValue, SDValue> 01148 LowerCallTo(SDValue Chain, const Type *RetTy, bool RetSExt, bool RetZExt, 01149 bool isVarArg, bool isInreg, unsigned NumFixedArgs, 01150 unsigned CallConv, bool isTailCall, bool isReturnValueUsed, 01151 SDValue Callee, ArgListTy &Args, SelectionDAG &DAG, DebugLoc dl); 01152 01153 /// LowerCall - This hook must be implemented to lower calls into the 01154 /// the specified DAG. The outgoing arguments to the call are described 01155 /// by the Outs array, and the values to be returned by the call are 01156 /// described by the Ins array. The implementation should fill in the 01157 /// InVals array with legal-type return values from the call, and return 01158 /// the resulting token chain value. 01159 /// 01160 /// The isTailCall flag here is normative. If it is true, the 01161 /// implementation must emit a tail call. The 01162 /// IsEligibleForTailCallOptimization hook should be used to catch 01163 /// cases that cannot be handled. 01164 /// 01165 virtual SDValue 01166 LowerCall(SDValue Chain, SDValue Callee, 01167 unsigned CallConv, bool isVarArg, bool isTailCall, 01168 const SmallVectorImpl<ISD::OutputArg> &Outs, 01169 const SmallVectorImpl<ISD::InputArg> &Ins, 01170 DebugLoc dl, SelectionDAG &DAG, 01171 SmallVectorImpl<SDValue> &InVals) { 01172 assert(0 && "Not Implemented"); 01173 return SDValue(); // this is here to silence compiler errors 01174 } 01175 01176 /// LowerReturn - This hook must be implemented to lower outgoing 01177 /// return values, described by the Outs array, into the specified 01178 /// DAG. The implementation should return the resulting token chain 01179 /// value. 01180 /// 01181 virtual SDValue 01182 LowerReturn(SDValue Chain, unsigned CallConv, bool isVarArg, 01183 const SmallVectorImpl<ISD::OutputArg> &Outs, 01184 DebugLoc dl, SelectionDAG &DAG) { 01185 assert(0 && "Not Implemented"); 01186 return SDValue(); // this is here to silence compiler errors 01187 } 01188 01189 /// EmitTargetCodeForMemcpy - Emit target-specific code that performs a 01190 /// memcpy. This can be used by targets to provide code sequences for cases 01191 /// that don't fit the target's parameters for simple loads/stores and can be 01192 /// more efficient than using a library call. This function can return a null 01193 /// SDValue if the target declines to use custom code and a different 01194 /// lowering strategy should be used. 01195 /// 01196 /// If AlwaysInline is true, the size is constant and the target should not 01197 /// emit any calls and is strongly encouraged to attempt to emit inline code 01198 /// even if it is beyond the usual threshold because this intrinsic is being 01199 /// expanded in a place where calls are not feasible (e.g. within the prologue 01200 /// for another call). If the target chooses to decline an AlwaysInline 01201 /// request here, legalize will resort to using simple loads and stores. 01202 virtual SDValue 01203 EmitTargetCodeForMemcpy(SelectionDAG &DAG, DebugLoc dl, 01204 SDValue Chain, 01205 SDValue Op1, SDValue Op2, 01206 SDValue Op3, unsigned Align, 01207 bool AlwaysInline, 01208 const Value *DstSV, uint64_t DstOff, 01209 const Value *SrcSV, uint64_t SrcOff) { 01210 return SDValue(); 01211 } 01212 01213 /// EmitTargetCodeForMemmove - Emit target-specific code that performs a 01214 /// memmove. This can be used by targets to provide code sequences for cases 01215 /// that don't fit the target's parameters for simple loads/stores and can be 01216 /// more efficient than using a library call. This function can return a null 01217 /// SDValue if the target declines to use custom code and a different 01218 /// lowering strategy should be used. 01219 virtual SDValue 01220 EmitTargetCodeForMemmove(SelectionDAG &DAG, DebugLoc dl, 01221 SDValue Chain, 01222 SDValue Op1, SDValue Op2, 01223 SDValue Op3, unsigned Align, 01224 const Value *DstSV, uint64_t DstOff, 01225 const Value *SrcSV, uint64_t SrcOff) { 01226 return SDValue(); 01227 } 01228 01229 /// EmitTargetCodeForMemset - Emit target-specific code that performs a 01230 /// memset. This can be used by targets to provide code sequences for cases 01231 /// that don't fit the target's parameters for simple stores and can be more 01232 /// efficient than using a library call. This function can return a null 01233 /// SDValue if the target declines to use custom code and a different 01234 /// lowering strategy should be used. 01235 virtual SDValue 01236 EmitTargetCodeForMemset(SelectionDAG &DAG, DebugLoc dl, 01237 SDValue Chain, 01238 SDValue Op1, SDValue Op2, 01239 SDValue Op3, unsigned Align, 01240 const Value *DstSV, uint64_t DstOff) { 01241 return SDValue(); 01242 } 01243 01244 /// LowerOperationWrapper - This callback is invoked by the type legalizer 01245 /// to legalize nodes with an illegal operand type but legal result types. 01246 /// It replaces the LowerOperation callback in the type Legalizer. 01247 /// The reason we can not do away with LowerOperation entirely is that 01248 /// LegalizeDAG isn't yet ready to use this callback. 01249 /// TODO: Consider merging with ReplaceNodeResults. 01250 01251 /// The target places new result values for the node in Results (their number 01252 /// and types must exactly match those of the original return values of 01253 /// the node), or leaves Results empty, which indicates that the node is not 01254 /// to be custom lowered after all. 01255 /// The default implementation calls LowerOperation. 01256 virtual void LowerOperationWrapper(SDNode *N, 01257 SmallVectorImpl<SDValue> &Results, 01258 SelectionDAG &DAG); 01259 01260 /// LowerOperation - This callback is invoked for operations that are 01261 /// unsupported by the target, which are registered to use 'custom' lowering, 01262 /// and whose defined values are all legal. 01263 /// If the target has no operations that require custom lowering, it need not 01264 /// implement this. The default implementation of this aborts. 01265 virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG); 01266 01267 /// ReplaceNodeResults - This callback is invoked when a node result type is 01268 /// illegal for the target, and the operation was registered to use 'custom' 01269 /// lowering for that result type. The target places new result values for 01270 /// the node in Results (their number and types must exactly match those of 01271 /// the original return values of the node), or leaves Results empty, which 01272 /// indicates that the node is not to be custom lowered after all. 01273 /// 01274 /// If the target has no operations that require custom lowering, it need not 01275 /// implement this. The default implementation aborts. 01276 virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results, 01277 SelectionDAG &DAG) { 01278 assert(0 && "ReplaceNodeResults not implemented for this target!"); 01279 } 01280 01281 /// IsEligibleForTailCallOptimization - Check whether the call is eligible for 01282 /// tail call optimization. Targets which want to do tail call optimization 01283 /// should override this function. 01284 virtual bool 01285 IsEligibleForTailCallOptimization(SDValue Callee, 01286 unsigned CalleeCC, 01287 bool isVarArg, 01288 const SmallVectorImpl<ISD::InputArg> &Ins, 01289 SelectionDAG& DAG) const { 01290 // Conservative default: no calls are eligible. 01291 return false; 01292 } 01293 01294 /// GetPossiblePreceedingTailCall - Get preceeding TailCallNodeOpCode node if 01295 /// it exists. Skip a possible ISD::TokenFactor. 01296 static SDValue GetPossiblePreceedingTailCall(SDValue Chain, 01297 unsigned TailCallNodeOpCode) { 01298 if (Chain.getOpcode() == TailCallNodeOpCode) { 01299 return Chain; 01300 } else if (Chain.getOpcode() == ISD::TokenFactor) { 01301 if (Chain.getNumOperands() && 01302 Chain.getOperand(0).getOpcode() == TailCallNodeOpCode) 01303 return Chain.getOperand(0); 01304 } 01305 return Chain; 01306 } 01307 01308 /// getTargetNodeName() - This method returns the name of a target specific 01309 /// DAG node. 01310 virtual const char *getTargetNodeName(unsigned Opcode) const; 01311 01312 /// createFastISel - This method returns a target specific FastISel object, 01313 /// or null if the target does not support "fast" ISel. 01314 virtual FastISel * 01315 createFastISel(MachineFunction &, 01316 MachineModuleInfo *, DwarfWriter *, 01317 DenseMap<const Value *, unsigned> &, 01318 DenseMap<const BasicBlock *, MachineBasicBlock *> &, 01319 DenseMap<const AllocaInst *, int> & 01320 #ifndef NDEBUG 01321 , SmallSet<Instruction*, 8> &CatchInfoLost 01322 #endif 01323 ) { 01324 return 0; 01325 } 01326 01327 //===--------------------------------------------------------------------===// 01328 // Inline Asm Support hooks 01329 // 01330 01331 /// ExpandInlineAsm - This hook allows the target to expand an inline asm 01332 /// call to be explicit llvm code if it wants to. This is useful for 01333 /// turning simple inline asms into LLVM intrinsics, which gives the 01334 /// compiler more information about the behavior of the code. 01335 virtual bool ExpandInlineAsm(CallInst *CI) const { 01336 return false; 01337 } 01338 01339 enum ConstraintType { 01340 C_Register, // Constraint represents specific register(s). 01341 C_RegisterClass, // Constraint represents any of register(s) in class. 01342 C_Memory, // Memory constraint. 01343 C_Other, // Something else. 01344 C_Unknown // Unsupported constraint. 01345 }; 01346 01347 /// AsmOperandInfo - This contains information for each constraint that we are 01348 /// lowering. 01349 struct AsmOperandInfo : public InlineAsm::ConstraintInfo { 01350 /// ConstraintCode - This contains the actual string for the code, like "m". 01351 /// TargetLowering picks the 'best' code from ConstraintInfo::Codes that 01352 /// most closely matches the operand. 01353 std::string ConstraintCode; 01354 01355 /// ConstraintType - Information about the constraint code, e.g. Register, 01356 /// RegisterClass, Memory, Other, Unknown. 01357 TargetLowering::ConstraintType ConstraintType; 01358 01359 /// CallOperandval - If this is the result output operand or a 01360 /// clobber, this is null, otherwise it is the incoming operand to the 01361 /// CallInst. This gets modified as the asm is processed. 01362 Value *CallOperandVal; 01363 01364 /// ConstraintVT - The ValueType for the operand value. 01365 EVT ConstraintVT; 01366 01367 /// isMatchingInputConstraint - Return true of this is an input operand that 01368 /// is a matching constraint like "4". 01369 bool isMatchingInputConstraint() const; 01370 01371 /// getMatchedOperand - If this is an input matching constraint, this method 01372 /// returns the output operand it matches. 01373 unsigned getMatchedOperand() const; 01374 01375 AsmOperandInfo(const InlineAsm::ConstraintInfo &info) 01376 : InlineAsm::ConstraintInfo(info), 01377 ConstraintType(TargetLowering::C_Unknown), 01378 CallOperandVal(0), ConstraintVT(MVT::Other) { 01379 } 01380 }; 01381 01382 /// ComputeConstraintToUse - Determines the constraint code and constraint 01383 /// type to use for the specific AsmOperandInfo, setting 01384 /// OpInfo.ConstraintCode and OpInfo.ConstraintType. If the actual operand 01385 /// being passed in is available, it can be passed in as Op, otherwise an 01386 /// empty SDValue can be passed. If hasMemory is true it means one of the asm 01387 /// constraint of the inline asm instruction being processed is 'm'. 01388 virtual void ComputeConstraintToUse(AsmOperandInfo &OpInfo, 01389 SDValue Op, 01390 bool hasMemory, 01391 SelectionDAG *DAG = 0) const; 01392 01393 /// getConstraintType - Given a constraint, return the type of constraint it 01394 /// is for this target. 01395 virtual ConstraintType getConstraintType(const std::string &Constraint) const; 01396 01397 /// getRegClassForInlineAsmConstraint - Given a constraint letter (e.g. "r"), 01398 /// return a list of registers that can be used to satisfy the constraint. 01399 /// This should only be used for C_RegisterClass constraints. 01400 virtual std::vector<unsigned> 01401 getRegClassForInlineAsmConstraint(const std::string &Constraint, 01402 EVT VT) const; 01403 01404 /// getRegForInlineAsmConstraint - Given a physical register constraint (e.g. 01405 /// {edx}), return the register number and the register class for the 01406 /// register. 01407 /// 01408 /// Given a register class constraint, like 'r', if this corresponds directly 01409 /// to an LLVM register class, return a register of 0 and the register class 01410 /// pointer. 01411 /// 01412 /// This should only be used for C_Register constraints. On error, 01413 /// this returns a register number of 0 and a null register class pointer.. 01414 virtual std::pair<unsigned, const TargetRegisterClass*> 01415 getRegForInlineAsmConstraint(const std::string &Constraint, 01416 EVT VT) const; 01417 01418 /// LowerXConstraint - try to replace an X constraint, which matches anything, 01419 /// with another that has more specific requirements based on the type of the 01420 /// corresponding operand. This returns null if there is no replacement to 01421 /// make. 01422 virtual const char *LowerXConstraint(EVT ConstraintVT) const; 01423 01424 /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops 01425 /// vector. If it is invalid, don't add anything to Ops. If hasMemory is true 01426 /// it means one of the asm constraint of the inline asm instruction being 01427 /// processed is 'm'. 01428 virtual void LowerAsmOperandForConstraint(SDValue Op, char ConstraintLetter, 01429 bool hasMemory, 01430 std::vector<SDValue> &Ops, 01431 SelectionDAG &DAG) const; 01432 01433 //===--------------------------------------------------------------------===// 01434 // Scheduler hooks 01435 // 01436 01437 // EmitInstrWithCustomInserter - This method should be implemented by targets 01438 // that mark instructions with the 'usesCustomDAGSchedInserter' flag. These 01439 // instructions are special in various ways, which require special support to 01440 // insert. The specified MachineInstr is created but not inserted into any 01441 // basic blocks, and the scheduler passes ownership of it to this method. 01442 virtual MachineBasicBlock *EmitInstrWithCustomInserter(MachineInstr *MI, 01443 MachineBasicBlock *MBB) const; 01444 01445 //===--------------------------------------------------------------------===// 01446 // Addressing mode description hooks (used by LSR etc). 01447 // 01448 01449 /// AddrMode - This represents an addressing mode of: 01450 /// BaseGV + BaseOffs + BaseReg + Scale*ScaleReg 01451 /// If BaseGV is null, there is no BaseGV. 01452 /// If BaseOffs is zero, there is no base offset. 01453 /// If HasBaseReg is false, there is no base register. 01454 /// If Scale is zero, there is no ScaleReg. Scale of 1 indicates a reg with 01455 /// no scale. 01456 /// 01457 struct AddrMode { 01458 GlobalValue *BaseGV; 01459 int64_t BaseOffs; 01460 bool HasBaseReg; 01461 int64_t Scale; 01462 AddrMode() : BaseGV(0), BaseOffs(0), HasBaseReg(false), Scale(0) {} 01463 }; 01464 01465 /// isLegalAddressingMode - Return true if the addressing mode represented by 01466 /// AM is legal for this target, for a load/store of the specified type. 01467 /// The type may be VoidTy, in which case only return true if the addressing 01468 /// mode is legal for a load/store of any legal type. 01469 /// TODO: Handle pre/postinc as well. 01470 virtual bool isLegalAddressingMode(const AddrMode &AM, const Type *Ty) const; 01471 01472 /// isTruncateFree - Return true if it's free to truncate a value of 01473 /// type Ty1 to type Ty2. e.g. On x86 it's free to truncate a i32 value in 01474 /// register EAX to i16 by referencing its sub-register AX. 01475 virtual bool isTruncateFree(const Type *Ty1, const Type *Ty2) const { 01476 return false; 01477 } 01478 01479 virtual bool isTruncateFree(EVT VT1, EVT VT2) const { 01480 return false; 01481 } 01482 01483 /// isZExtFree - Return true if any actual instruction that defines a 01484 /// value of type Ty1 implicit zero-extends the value to Ty2 in the result 01485 /// register. This does not necessarily include registers defined in 01486 /// unknown ways, such as incoming arguments, or copies from unknown 01487 /// virtual registers. Also, if isTruncateFree(Ty2, Ty1) is true, this 01488 /// does not necessarily apply to truncate instructions. e.g. on x86-64, 01489 /// all instructions that define 32-bit values implicit zero-extend the 01490 /// result out to 64 bits. 01491 virtual bool isZExtFree(const Type *Ty1, const Type *Ty2) const { 01492 return false; 01493 } 01494 01495 virtual bool isZExtFree(EVT VT1, EVT VT2) const { 01496 return false; 01497 } 01498 01499 /// isNarrowingProfitable - Return true if it's profitable to narrow 01500 /// operations of type VT1 to VT2. e.g. on x86, it's profitable to narrow 01501 /// from i32 to i8 but not from i32 to i16. 01502 virtual bool isNarrowingProfitable(EVT VT1, EVT VT2) const { 01503 return false; 01504 } 01505 01506 //===--------------------------------------------------------------------===// 01507 // Div utility functions 01508 // 01509 SDValue BuildSDIV(SDNode *N, SelectionDAG &DAG, 01510 std::vector<SDNode*>* Created) const; 01511 SDValue BuildUDIV(SDNode *N, SelectionDAG &DAG, 01512 std::vector<SDNode*>* Created) const; 01513 01514 01515 //===--------------------------------------------------------------------===// 01516 // Runtime Library hooks 01517 // 01518 01519 /// setLibcallName - Rename the default libcall routine name for the specified 01520 /// libcall. 01521 void setLibcallName(RTLIB::Libcall Call, const char *Name) { 01522 LibcallRoutineNames[Call] = Name; 01523 } 01524 01525 /// getLibcallName - Get the libcall routine name for the specified libcall. 01526 /// 01527 const char *getLibcallName(RTLIB::Libcall Call) const { 01528 return LibcallRoutineNames[Call]; 01529 } 01530 01531 /// setCmpLibcallCC - Override the default CondCode to be used to test the 01532 /// result of the comparison libcall against zero. 01533 void setCmpLibcallCC(RTLIB::Libcall Call, ISD::CondCode CC) { 01534 CmpLibcallCCs[Call] = CC; 01535 } 01536 01537 /// getCmpLibcallCC - Get the CondCode that's to be used to test the result of 01538 /// the comparison libcall against zero. 01539 ISD::CondCode getCmpLibcallCC(RTLIB::Libcall Call) const { 01540 return CmpLibcallCCs[Call]; 01541 } 01542 01543 /// setLibcallCallingConv - Set the CallingConv that should be used for the 01544 /// specified libcall. 01545 void setLibcallCallingConv(RTLIB::Libcall Call, CallingConv::ID CC) { 01546 LibcallCallingConvs[Call] = CC; 01547 } 01548 01549 /// getLibcallCallingConv - Get the CallingConv that should be used for the 01550 /// specified libcall. 01551 CallingConv::ID getLibcallCallingConv(RTLIB::Libcall Call) const { 01552 return LibcallCallingConvs[Call]; 01553 } 01554 01555 private: 01556 TargetMachine &TM; 01557 const TargetData *TD; 01558 TargetLoweringObjectFile &TLOF; 01559 01560 /// PointerTy - The type to use for pointers, usually i32 or i64. 01561 /// 01562 MVT PointerTy; 01563 01564 /// IsLittleEndian - True if this is a little endian target. 01565 /// 01566 bool IsLittleEndian; 01567 01568 /// UsesGlobalOffsetTable - True if this target uses a GOT for PIC codegen. 01569 /// 01570 bool UsesGlobalOffsetTable; 01571 01572 /// SelectIsExpensive - Tells the code generator not to expand operations 01573 /// into sequences that use the select operations if possible. 01574 bool SelectIsExpensive; 01575 01576 /// IntDivIsCheap - Tells the code generator not to expand integer divides by 01577 /// constants into a sequence of muls, adds, and shifts. This is a hack until 01578 /// a real cost model is in place. If we ever optimize for size, this will be 01579 /// set to true unconditionally. 01580 bool IntDivIsCheap; 01581 01582 /// Pow2DivIsCheap - Tells the code generator that it shouldn't generate 01583 /// srl/add/sra for a signed divide by power of two, and let the target handle 01584 /// it. 01585 bool Pow2DivIsCheap; 01586 01587 /// UseUnderscoreSetJmp - This target prefers to use _setjmp to implement 01588 /// llvm.setjmp. Defaults to false. 01589 bool UseUnderscoreSetJmp; 01590 01591 /// UseUnderscoreLongJmp - This target prefers to use _longjmp to implement 01592 /// llvm.longjmp. Defaults to false. 01593 bool UseUnderscoreLongJmp; 01594 01595 /// ShiftAmountTy - The type to use for shift amounts, usually i8 or whatever 01596 /// PointerTy is. 01597 MVT ShiftAmountTy; 01598 01599 /// BooleanContents - Information about the contents of the high-bits in 01600 /// boolean values held in a type wider than i1. See getBooleanContents. 01601 BooleanContent BooleanContents; 01602 01603 /// SchedPreferenceInfo - The target scheduling preference: shortest possible 01604 /// total cycles or lowest register usage. 01605 SchedPreference SchedPreferenceInfo; 01606 01607 /// JumpBufSize - The size, in bytes, of the target's jmp_buf buffers 01608 unsigned JumpBufSize; 01609 01610 /// JumpBufAlignment - The alignment, in bytes, of the target's jmp_buf 01611 /// buffers 01612 unsigned JumpBufAlignment; 01613 01614 /// IfCvtBlockSizeLimit - The maximum allowed size for a block to be 01615 /// if-converted. 01616 unsigned IfCvtBlockSizeLimit; 01617 01618 /// IfCvtDupBlockSizeLimit - The maximum allowed size for a block to be 01619 /// duplicated during if-conversion. 01620 unsigned IfCvtDupBlockSizeLimit; 01621 01622 /// PrefLoopAlignment - The perferred loop alignment. 01623 /// 01624 unsigned PrefLoopAlignment; 01625 01626 /// StackPointerRegisterToSaveRestore - If set to a physical register, this 01627 /// specifies the register that llvm.savestack/llvm.restorestack should save 01628 /// and restore. 01629 unsigned StackPointerRegisterToSaveRestore; 01630 01631 /// ExceptionPointerRegister - If set to a physical register, this specifies 01632 /// the register that receives the exception address on entry to a landing 01633 /// pad. 01634 unsigned ExceptionPointerRegister; 01635 01636 /// ExceptionSelectorRegister - If set to a physical register, this specifies 01637 /// the register that receives the exception typeid on entry to a landing 01638 /// pad. 01639 unsigned ExceptionSelectorRegister; 01640 01641 /// RegClassForVT - This indicates the default register class to use for 01642 /// each ValueType the target supports natively. 01643 TargetRegisterClass *RegClassForVT[MVT::LAST_VALUETYPE]; 01644 unsigned char NumRegistersForVT[MVT::LAST_VALUETYPE]; 01645 EVT RegisterTypeForVT[MVT::LAST_VALUETYPE]; 01646 01647 /// TransformToType - For any value types we are promoting or expanding, this 01648 /// contains the value type that we are changing to. For Expanded types, this 01649 /// contains one step of the expand (e.g. i64 -> i32), even if there are 01650 /// multiple steps required (e.g. i64 -> i16). For types natively supported 01651 /// by the system, this holds the same type (e.g. i32 -> i32). 01652 EVT TransformToType[MVT::LAST_VALUETYPE]; 01653 01654 /// OpActions - For each operation and each value type, keep a LegalizeAction 01655 /// that indicates how instruction selection should deal with the operation. 01656 /// Most operations are Legal (aka, supported natively by the target), but 01657 /// operations that are not should be described. Note that operations on 01658 /// non-legal value types are not described here. 01659 /// This array is accessed using VT.getSimpleVT(), so it is subject to 01660 /// the MVT::MAX_ALLOWED_VALUETYPE * 2 bits. 01661 uint64_t OpActions[MVT::MAX_ALLOWED_VALUETYPE/(sizeof(uint64_t)*4)][ISD::BUILTIN_OP_END]; 01662 01663 /// LoadExtActions - For each load of load extension type and each value type, 01664 /// keep a LegalizeAction that indicates how instruction selection should deal 01665 /// with the load. 01666 uint64_t LoadExtActions[ISD::LAST_LOADEXT_TYPE]; 01667 01668 /// TruncStoreActions - For each truncating store, keep a LegalizeAction that 01669 /// indicates how instruction selection should deal with the store. 01670 uint64_t TruncStoreActions[MVT::LAST_VALUETYPE]; 01671 01672 /// IndexedModeActions - For each indexed mode and each value type, 01673 /// keep a pair of LegalizeAction that indicates how instruction 01674 /// selection should deal with the load / store. The first 01675 /// dimension is now the value_type for the reference. The second 01676 /// dimension is the load [0] vs. store[1]. The third dimension 01677 /// represents the various modes for load store. 01678 uint8_t IndexedModeActions[MVT::LAST_VALUETYPE][2][ISD::LAST_INDEXED_MODE]; 01679 01680 /// ConvertActions - For each conversion from source type to destination type, 01681 /// keep a LegalizeAction that indicates how instruction selection should 01682 /// deal with the conversion. 01683 /// Currently, this is used only for floating->floating conversions 01684 /// (FP_EXTEND and FP_ROUND). 01685 uint64_t ConvertActions[MVT::LAST_VALUETYPE]; 01686 01687 /// CondCodeActions - For each condition code (ISD::CondCode) keep a 01688 /// LegalizeAction that indicates how instruction selection should 01689 /// deal with the condition code. 01690 uint64_t CondCodeActions[ISD::SETCC_INVALID]; 01691 01692 ValueTypeActionImpl ValueTypeActions; 01693 01694 std::vector<APFloat> LegalFPImmediates; 01695 01696 std::vector<std::pair<EVT, TargetRegisterClass*> > AvailableRegClasses; 01697 01698 /// TargetDAGCombineArray - Targets can specify ISD nodes that they would 01699 /// like PerformDAGCombine callbacks for by calling setTargetDAGCombine(), 01700 /// which sets a bit in this array. 01701 unsigned char 01702 TargetDAGCombineArray[(ISD::BUILTIN_OP_END+CHAR_BIT-1)/CHAR_BIT]; 01703 01704 /// PromoteToType - For operations that must be promoted to a specific type, 01705 /// this holds the destination type. This map should be sparse, so don't hold 01706 /// it as an array. 01707 /// 01708 /// Targets add entries to this map with AddPromotedToType(..), clients access 01709 /// this with getTypeToPromoteTo(..). 01710 std::map<std::pair<unsigned, MVT::SimpleValueType>, MVT::SimpleValueType> 01711 PromoteToType; 01712 01713 /// LibcallRoutineNames - Stores the name each libcall. 01714 /// 01715 const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL]; 01716 01717 /// CmpLibcallCCs - The ISD::CondCode that should be used to test the result 01718 /// of each of the comparison libcall against zero. 01719 ISD::CondCode CmpLibcallCCs[RTLIB::UNKNOWN_LIBCALL]; 01720 01721 /// LibcallCallingConvs - Stores the CallingConv that should be used for each 01722 /// libcall. 01723 CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL]; 01724 01725 protected: 01726 /// When lowering \@llvm.memset this field specifies the maximum number of 01727 /// store operations that may be substituted for the call to memset. Targets 01728 /// must set this value based on the cost threshold for that target. Targets 01729 /// should assume that the memset will be done using as many of the largest 01730 /// store operations first, followed by smaller ones, if necessary, per 01731 /// alignment restrictions. For example, storing 9 bytes on a 32-bit machine 01732 /// with 16-bit alignment would result in four 2-byte stores and one 1-byte 01733 /// store. This only applies to setting a constant array of a constant size. 01734 /// @brief Specify maximum number of store instructions per memset call. 01735 unsigned maxStoresPerMemset; 01736 01737 /// When lowering \@llvm.memcpy this field specifies the maximum number of 01738 /// store operations that may be substituted for a call to memcpy. Targets 01739 /// must set this value based on the cost threshold for that target. Targets 01740 /// should assume that the memcpy will be done using as many of the largest 01741 /// store operations first, followed by smaller ones, if necessary, per 01742 /// alignment restrictions. For example, storing 7 bytes on a 32-bit machine 01743 /// with 32-bit alignment would result in one 4-byte store, a one 2-byte store 01744 /// and one 1-byte store. This only applies to copying a constant array of 01745 /// constant size. 01746 /// @brief Specify maximum bytes of store instructions per memcpy call. 01747 unsigned maxStoresPerMemcpy; 01748 01749 /// When lowering \@llvm.memmove this field specifies the maximum number of 01750 /// store instructions that may be substituted for a call to memmove. Targets 01751 /// must set this value based on the cost threshold for that target. Targets 01752 /// should assume that the memmove will be done using as many of the largest 01753 /// store operations first, followed by smaller ones, if necessary, per 01754 /// alignment restrictions. For example, moving 9 bytes on a 32-bit machine 01755 /// with 8-bit alignment would result in nine 1-byte stores. This only 01756 /// applies to copying a constant array of constant size. 01757 /// @brief Specify maximum bytes of store instructions per memmove call. 01758 unsigned maxStoresPerMemmove; 01759 01760 /// This field specifies whether the target can benefit from code placement 01761 /// optimization. 01762 bool benefitFromCodePlacementOpt; 01763 }; 01764 } // end llvm namespace 01765 01766 #endif