| 1 | //===- llvm/CodeGen/TargetLowering.h - Target Lowering Info -----*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// |
| 9 | /// \file |
| 10 | /// This file describes how to lower LLVM code to machine code. This has two |
| 11 | /// main components: |
| 12 | /// |
| 13 | /// 1. Which ValueTypes are natively supported by the target. |
| 14 | /// 2. Which operations are supported for supported ValueTypes. |
| 15 | /// 3. Cost thresholds for alternative implementations of certain operations. |
| 16 | /// |
| 17 | /// In addition it has a few other components, like information about FP |
| 18 | /// immediates. |
| 19 | /// |
| 20 | //===----------------------------------------------------------------------===// |
| 21 | |
| 22 | #ifndef LLVM_CODEGEN_TARGETLOWERING_H |
| 23 | #define LLVM_CODEGEN_TARGETLOWERING_H |
| 24 | |
| 25 | #include "llvm/ADT/APInt.h" |
| 26 | #include "llvm/ADT/ArrayRef.h" |
| 27 | #include "llvm/ADT/DenseMap.h" |
| 28 | #include "llvm/ADT/STLExtras.h" |
| 29 | #include "llvm/ADT/SmallVector.h" |
| 30 | #include "llvm/ADT/StringRef.h" |
| 31 | #include "llvm/CodeGen/DAGCombine.h" |
| 32 | #include "llvm/CodeGen/ISDOpcodes.h" |
| 33 | #include "llvm/CodeGen/LowLevelType.h" |
| 34 | #include "llvm/CodeGen/RuntimeLibcalls.h" |
| 35 | #include "llvm/CodeGen/SelectionDAG.h" |
| 36 | #include "llvm/CodeGen/SelectionDAGNodes.h" |
| 37 | #include "llvm/CodeGen/TargetCallingConv.h" |
| 38 | #include "llvm/CodeGen/ValueTypes.h" |
| 39 | #include "llvm/IR/Attributes.h" |
| 40 | #include "llvm/IR/CallingConv.h" |
| 41 | #include "llvm/IR/DataLayout.h" |
| 42 | #include "llvm/IR/DerivedTypes.h" |
| 43 | #include "llvm/IR/Function.h" |
| 44 | #include "llvm/IR/InlineAsm.h" |
| 45 | #include "llvm/IR/Instruction.h" |
| 46 | #include "llvm/IR/Instructions.h" |
| 47 | #include "llvm/IR/Type.h" |
| 48 | #include "llvm/Support/Alignment.h" |
| 49 | #include "llvm/Support/AtomicOrdering.h" |
| 50 | #include "llvm/Support/Casting.h" |
| 51 | #include "llvm/Support/ErrorHandling.h" |
| 52 | #include "llvm/Support/InstructionCost.h" |
| 53 | #include "llvm/Support/MachineValueType.h" |
| 54 | #include <algorithm> |
| 55 | #include <cassert> |
| 56 | #include <climits> |
| 57 | #include <cstdint> |
| 58 | #include <iterator> |
| 59 | #include <map> |
| 60 | #include <string> |
| 61 | #include <utility> |
| 62 | #include <vector> |
| 63 | |
| 64 | namespace llvm { |
| 65 | |
| 66 | class CCState; |
| 67 | class CCValAssign; |
| 68 | class Constant; |
| 69 | class FastISel; |
| 70 | class FunctionLoweringInfo; |
| 71 | class GlobalValue; |
| 72 | class GISelKnownBits; |
| 73 | class IntrinsicInst; |
| 74 | class IRBuilderBase; |
| 75 | struct KnownBits; |
| 76 | class LegacyDivergenceAnalysis; |
| 77 | class LLVMContext; |
| 78 | class MachineBasicBlock; |
| 79 | class MachineFunction; |
| 80 | class MachineInstr; |
| 81 | class MachineJumpTableInfo; |
| 82 | class MachineLoop; |
| 83 | class MachineRegisterInfo; |
| 84 | class MCContext; |
| 85 | class MCExpr; |
| 86 | class Module; |
| 87 | class ProfileSummaryInfo; |
| 88 | class TargetLibraryInfo; |
| 89 | class TargetMachine; |
| 90 | class TargetRegisterClass; |
| 91 | class TargetRegisterInfo; |
| 92 | class TargetTransformInfo; |
| 93 | class Value; |
| 94 | |
| 95 | namespace Sched { |
| 96 | |
| 97 | enum Preference { |
| 98 | None, // No preference |
| 99 | Source, // Follow source order. |
| 100 | RegPressure, // Scheduling for lowest register pressure. |
| 101 | Hybrid, // Scheduling for both latency and register pressure. |
| 102 | ILP, // Scheduling for ILP in low register pressure mode. |
| 103 | VLIW, // Scheduling for VLIW targets. |
| 104 | Fast, // Fast suboptimal list scheduling |
| 105 | Linearize // Linearize DAG, no scheduling |
| 106 | }; |
| 107 | |
| 108 | } // end namespace Sched |
| 109 | |
| 110 | // MemOp models a memory operation, either memset or memcpy/memmove. |
| 111 | struct MemOp { |
| 112 | private: |
| 113 | // Shared |
| 114 | uint64_t Size; |
| 115 | bool DstAlignCanChange; // true if destination alignment can satisfy any |
| 116 | // constraint. |
| 117 | Align DstAlign; // Specified alignment of the memory operation. |
| 118 | |
| 119 | bool AllowOverlap; |
| 120 | // memset only |
| 121 | bool IsMemset; // If setthis memory operation is a memset. |
| 122 | bool ZeroMemset; // If set clears out memory with zeros. |
| 123 | // memcpy only |
| 124 | bool MemcpyStrSrc; // Indicates whether the memcpy source is an in-register |
| 125 | // constant so it does not need to be loaded. |
| 126 | Align SrcAlign; // Inferred alignment of the source or default value if the |
| 127 | // memory operation does not need to load the value. |
| 128 | public: |
| 129 | static MemOp Copy(uint64_t Size, bool DstAlignCanChange, Align DstAlign, |
| 130 | Align SrcAlign, bool IsVolatile, |
| 131 | bool MemcpyStrSrc = false) { |
| 132 | MemOp Op; |
| 133 | Op.Size = Size; |
| 134 | Op.DstAlignCanChange = DstAlignCanChange; |
| 135 | Op.DstAlign = DstAlign; |
| 136 | Op.AllowOverlap = !IsVolatile; |
| 137 | Op.IsMemset = false; |
| 138 | Op.ZeroMemset = false; |
| 139 | Op.MemcpyStrSrc = MemcpyStrSrc; |
| 140 | Op.SrcAlign = SrcAlign; |
| 141 | return Op; |
| 142 | } |
| 143 | |
| 144 | static MemOp Set(uint64_t Size, bool DstAlignCanChange, Align DstAlign, |
| 145 | bool IsZeroMemset, bool IsVolatile) { |
| 146 | MemOp Op; |
| 147 | Op.Size = Size; |
| 148 | Op.DstAlignCanChange = DstAlignCanChange; |
| 149 | Op.DstAlign = DstAlign; |
| 150 | Op.AllowOverlap = !IsVolatile; |
| 151 | Op.IsMemset = true; |
| 152 | Op.ZeroMemset = IsZeroMemset; |
| 153 | Op.MemcpyStrSrc = false; |
| 154 | return Op; |
| 155 | } |
| 156 | |
| 157 | uint64_t size() const { return Size; } |
| 158 | Align getDstAlign() const { |
| 159 | assert(!DstAlignCanChange); |
| 160 | return DstAlign; |
| 161 | } |
| 162 | bool isFixedDstAlign() const { return !DstAlignCanChange; } |
| 163 | bool allowOverlap() const { return AllowOverlap; } |
| 164 | bool isMemset() const { return IsMemset; } |
| 165 | bool isMemcpy() const { return !IsMemset; } |
| 166 | bool isMemcpyWithFixedDstAlign() const { |
| 167 | return isMemcpy() && !DstAlignCanChange; |
| 168 | } |
| 169 | bool isZeroMemset() const { return isMemset() && ZeroMemset; } |
| 170 | bool isMemcpyStrSrc() const { |
| 171 | assert(isMemcpy() && "Must be a memcpy"); |
| 172 | return MemcpyStrSrc; |
| 173 | } |
| 174 | Align getSrcAlign() const { |
| 175 | assert(isMemcpy() && "Must be a memcpy"); |
| 176 | return SrcAlign; |
| 177 | } |
| 178 | bool isSrcAligned(Align AlignCheck) const { |
| 179 | return isMemset() || llvm::isAligned(AlignCheck, SrcAlign.value()); |
| 180 | } |
| 181 | bool isDstAligned(Align AlignCheck) const { |
| 182 | return DstAlignCanChange || llvm::isAligned(AlignCheck, DstAlign.value()); |
| 183 | } |
| 184 | bool isAligned(Align AlignCheck) const { |
| 185 | return isSrcAligned(AlignCheck) && isDstAligned(AlignCheck); |
| 186 | } |
| 187 | }; |
| 188 | |
| 189 | /// This base class for TargetLowering contains the SelectionDAG-independent |
| 190 | /// parts that can be used from the rest of CodeGen. |
| 191 | class TargetLoweringBase { |
| 192 | public: |
| 193 | /// This enum indicates whether operations are valid for a target, and if not, |
| 194 | /// what action should be used to make them valid. |
| 195 | enum LegalizeAction : uint8_t { |
| 196 | Legal, // The target natively supports this operation. |
| 197 | Promote, // This operation should be executed in a larger type. |
| 198 | Expand, // Try to expand this to other ops, otherwise use a libcall. |
| 199 | LibCall, // Don't try to expand this to other ops, always use a libcall. |
| 200 | Custom // Use the LowerOperation hook to implement custom lowering. |
| 201 | }; |
| 202 | |
| 203 | /// This enum indicates whether a types are legal for a target, and if not, |
| 204 | /// what action should be used to make them valid. |
| 205 | enum LegalizeTypeAction : uint8_t { |
| 206 | TypeLegal, // The target natively supports this type. |
| 207 | TypePromoteInteger, // Replace this integer with a larger one. |
| 208 | TypeExpandInteger, // Split this integer into two of half the size. |
| 209 | TypeSoftenFloat, // Convert this float to a same size integer type. |
| 210 | TypeExpandFloat, // Split this float into two of half the size. |
| 211 | TypeScalarizeVector, // Replace this one-element vector with its element. |
| 212 | TypeSplitVector, // Split this vector into two of half the size. |
| 213 | TypeWidenVector, // This vector should be widened into a larger vector. |
| 214 | TypePromoteFloat, // Replace this float with a larger one. |
| 215 | TypeSoftPromoteHalf, // Soften half to i16 and use float to do arithmetic. |
| 216 | TypeScalarizeScalableVector, // This action is explicitly left unimplemented. |
| 217 | // While it is theoretically possible to |
| 218 | // legalize operations on scalable types with a |
| 219 | // loop that handles the vscale * #lanes of the |
| 220 | // vector, this is non-trivial at SelectionDAG |
| 221 | // level and these types are better to be |
| 222 | // widened or promoted. |
| 223 | }; |
| 224 | |
| 225 | /// LegalizeKind holds the legalization kind that needs to happen to EVT |
| 226 | /// in order to type-legalize it. |
| 227 | using LegalizeKind = std::pair<LegalizeTypeAction, EVT>; |
| 228 | |
| 229 | /// Enum that describes how the target represents true/false values. |
| 230 | enum BooleanContent { |
| 231 | UndefinedBooleanContent, // Only bit 0 counts, the rest can hold garbage. |
| 232 | ZeroOrOneBooleanContent, // All bits zero except for bit 0. |
| 233 | ZeroOrNegativeOneBooleanContent // All bits equal to bit 0. |
| 234 | }; |
| 235 | |
| 236 | /// Enum that describes what type of support for selects the target has. |
| 237 | enum SelectSupportKind { |
| 238 | ScalarValSelect, // The target supports scalar selects (ex: cmov). |
| 239 | ScalarCondVectorVal, // The target supports selects with a scalar condition |
| 240 | // and vector values (ex: cmov). |
| 241 | VectorMaskSelect // The target supports vector selects with a vector |
| 242 | // mask (ex: x86 blends). |
| 243 | }; |
| 244 | |
| 245 | /// Enum that specifies what an atomic load/AtomicRMWInst is expanded |
| 246 | /// to, if at all. Exists because different targets have different levels of |
| 247 | /// support for these atomic instructions, and also have different options |
| 248 | /// w.r.t. what they should expand to. |
| 249 | enum class AtomicExpansionKind { |
| 250 | None, // Don't expand the instruction. |
| 251 | LLSC, // Expand the instruction into loadlinked/storeconditional; used |
| 252 | // by ARM/AArch64. |
| 253 | LLOnly, // Expand the (load) instruction into just a load-linked, which has |
| 254 | // greater atomic guarantees than a normal load. |
| 255 | CmpXChg, // Expand the instruction into cmpxchg; used by at least X86. |
| 256 | MaskedIntrinsic, // Use a target-specific intrinsic for the LL/SC loop. |
| 257 | }; |
| 258 | |
| 259 | /// Enum that specifies when a multiplication should be expanded. |
| 260 | enum class MulExpansionKind { |
| 261 | Always, // Always expand the instruction. |
| 262 | OnlyLegalOrCustom, // Only expand when the resulting instructions are legal |
| 263 | // or custom. |
| 264 | }; |
| 265 | |
| 266 | /// Enum that specifies when a float negation is beneficial. |
| 267 | enum class NegatibleCost { |
| 268 | Cheaper = 0, // Negated expression is cheaper. |
| 269 | Neutral = 1, // Negated expression has the same cost. |
| 270 | Expensive = 2 // Negated expression is more expensive. |
| 271 | }; |
| 272 | |
| 273 | class ArgListEntry { |
| 274 | public: |
| 275 | Value *Val = nullptr; |
| 276 | SDValue Node = SDValue(); |
| 277 | Type *Ty = nullptr; |
| 278 | bool IsSExt : 1; |
| 279 | bool IsZExt : 1; |
| 280 | bool IsInReg : 1; |
| 281 | bool IsSRet : 1; |
| 282 | bool IsNest : 1; |
| 283 | bool IsByVal : 1; |
| 284 | bool IsByRef : 1; |
| 285 | bool IsInAlloca : 1; |
| 286 | bool IsPreallocated : 1; |
| 287 | bool IsReturned : 1; |
| 288 | bool IsSwiftSelf : 1; |
| 289 | bool IsSwiftAsync : 1; |
| 290 | bool IsSwiftError : 1; |
| 291 | bool IsCFGuardTarget : 1; |
| 292 | MaybeAlign Alignment = None; |
| 293 | Type *IndirectType = nullptr; |
| 294 | |
| 295 | ArgListEntry() |
| 296 | : IsSExt(false), IsZExt(false), IsInReg(false), IsSRet(false), |
| 297 | IsNest(false), IsByVal(false), IsByRef(false), IsInAlloca(false), |
| 298 | IsPreallocated(false), IsReturned(false), IsSwiftSelf(false), |
| 299 | IsSwiftAsync(false), IsSwiftError(false), IsCFGuardTarget(false) {} |
| 300 | |
| 301 | void setAttributes(const CallBase *Call, unsigned ArgIdx); |
| 302 | }; |
| 303 | using ArgListTy = std::vector<ArgListEntry>; |
| 304 | |
| 305 | virtual void markLibCallAttributes(MachineFunction *MF, unsigned CC, |
| 306 | ArgListTy &Args) const {}; |
| 307 | |
| 308 | static ISD::NodeType getExtendForContent(BooleanContent Content) { |
| 309 | switch (Content) { |
| 310 | case UndefinedBooleanContent: |
| 311 | // Extend by adding rubbish bits. |
| 312 | return ISD::ANY_EXTEND; |
| 313 | case ZeroOrOneBooleanContent: |
| 314 | // Extend by adding zero bits. |
| 315 | return ISD::ZERO_EXTEND; |
| 316 | case ZeroOrNegativeOneBooleanContent: |
| 317 | // Extend by copying the sign bit. |
| 318 | return ISD::SIGN_EXTEND; |
| 319 | } |
| 320 | llvm_unreachable("Invalid content kind"); |
| 321 | } |
| 322 | |
| 323 | explicit TargetLoweringBase(const TargetMachine &TM); |
| 324 | TargetLoweringBase(const TargetLoweringBase &) = delete; |
| 325 | TargetLoweringBase &operator=(const TargetLoweringBase &) = delete; |
| 326 | virtual ~TargetLoweringBase() = default; |
| 327 | |
| 328 | /// Return true if the target support strict float operation |
| 329 | bool isStrictFPEnabled() const { |
| 330 | return IsStrictFPEnabled; |
| 331 | } |
| 332 | |
| 333 | protected: |
| 334 | /// Initialize all of the actions to default values. |
| 335 | void initActions(); |
| 336 | |
| 337 | public: |
| 338 | const TargetMachine &getTargetMachine() const { return TM; } |
| 339 | |
| 340 | virtual bool useSoftFloat() const { return false; } |
| 341 | |
| 342 | /// Return the pointer type for the given address space, defaults to |
| 343 | /// the pointer type from the data layout. |
| 344 | /// FIXME: The default needs to be removed once all the code is updated. |
| 345 | virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS = 0) const { |
| 346 | return MVT::getIntegerVT(DL.getPointerSizeInBits(AS)); |
| 347 | } |
| 348 | |
| 349 | /// Return the in-memory pointer type for the given address space, defaults to |
| 350 | /// the pointer type from the data layout. FIXME: The default needs to be |
| 351 | /// removed once all the code is updated. |
| 352 | virtual MVT getPointerMemTy(const DataLayout &DL, uint32_t AS = 0) const { |
| 353 | return MVT::getIntegerVT(DL.getPointerSizeInBits(AS)); |
| 354 | } |
| 355 | |
| 356 | /// Return the type for frame index, which is determined by |
| 357 | /// the alloca address space specified through the data layout. |
| 358 | MVT getFrameIndexTy(const DataLayout &DL) const { |
| 359 | return getPointerTy(DL, DL.getAllocaAddrSpace()); |
| 360 | } |
| 361 | |
| 362 | /// Return the type for code pointers, which is determined by the program |
| 363 | /// address space specified through the data layout. |
| 364 | MVT getProgramPointerTy(const DataLayout &DL) const { |
| 365 | return getPointerTy(DL, DL.getProgramAddressSpace()); |
| 366 | } |
| 367 | |
| 368 | /// Return the type for operands of fence. |
| 369 | /// TODO: Let fence operands be of i32 type and remove this. |
| 370 | virtual MVT getFenceOperandTy(const DataLayout &DL) const { |
| 371 | return getPointerTy(DL); |
| 372 | } |
| 373 | |
| 374 | /// Return the type to use for a scalar shift opcode, given the shifted amount |
| 375 | /// type. Targets should return a legal type if the input type is legal. |
| 376 | /// Targets can return a type that is too small if the input type is illegal. |
| 377 | virtual MVT getScalarShiftAmountTy(const DataLayout &, EVT) const; |
| 378 | |
| 379 | /// Returns the type for the shift amount of a shift opcode. For vectors, |
| 380 | /// returns the input type. For scalars, behavior depends on \p LegalTypes. If |
| 381 | /// \p LegalTypes is true, calls getScalarShiftAmountTy, otherwise uses |
| 382 | /// pointer type. If getScalarShiftAmountTy or pointer type cannot represent |
| 383 | /// all possible shift amounts, returns MVT::i32. In general, \p LegalTypes |
| 384 | /// should be set to true for calls during type legalization and after type |
| 385 | /// legalization has been completed. |
| 386 | EVT getShiftAmountTy(EVT LHSTy, const DataLayout &DL, |
| 387 | bool LegalTypes = true) const; |
| 388 | |
| 389 | /// Return the preferred type to use for a shift opcode, given the shifted |
| 390 | /// amount type is \p ShiftValueTy. |
| 391 | LLVM_READONLY |
| 392 | virtual LLT getPreferredShiftAmountTy(LLT ShiftValueTy) const { |
| 393 | return ShiftValueTy; |
| 394 | } |
| 395 | |
| 396 | /// Returns the type to be used for the index operand of: |
| 397 | /// ISD::INSERT_VECTOR_ELT, ISD::EXTRACT_VECTOR_ELT, |
| 398 | /// ISD::INSERT_SUBVECTOR, and ISD::EXTRACT_SUBVECTOR |
| 399 | virtual MVT getVectorIdxTy(const DataLayout &DL) const { |
| 400 | return getPointerTy(DL); |
| 401 | } |
| 402 | |
| 403 | /// Returns the type to be used for the EVL/AVL operand of VP nodes: |
| 404 | /// ISD::VP_ADD, ISD::VP_SUB, etc. It must be a legal scalar integer type, |
| 405 | /// and must be at least as large as i32. The EVL is implicitly zero-extended |
| 406 | /// to any larger type. |
| 407 | virtual MVT getVPExplicitVectorLengthTy() const { return MVT::i32; } |
| 408 | |
| 409 | /// This callback is used to inspect load/store instructions and add |
| 410 | /// target-specific MachineMemOperand flags to them. The default |
| 411 | /// implementation does nothing. |
| 412 | virtual MachineMemOperand::Flags getTargetMMOFlags(const Instruction &I) const { |
| 413 | return MachineMemOperand::MONone; |
| 414 | } |
| 415 | |
| 416 | MachineMemOperand::Flags getLoadMemOperandFlags(const LoadInst &LI, |
| 417 | const DataLayout &DL) const; |
| 418 | MachineMemOperand::Flags getStoreMemOperandFlags(const StoreInst &SI, |
| 419 | const DataLayout &DL) const; |
| 420 | MachineMemOperand::Flags getAtomicMemOperandFlags(const Instruction &AI, |
| 421 | const DataLayout &DL) const; |
| 422 | |
| 423 | virtual bool isSelectSupported(SelectSupportKind /*kind*/) const { |
| 424 | return true; |
| 425 | } |
| 426 | |
| 427 | /// Return true if the @llvm.get.active.lane.mask intrinsic should be expanded |
| 428 | /// using generic code in SelectionDAGBuilder. |
| 429 | virtual bool shouldExpandGetActiveLaneMask(EVT VT, EVT OpVT) const { |
| 430 | return true; |
| 431 | } |
| 432 | |
| 433 | /// Return true if it is profitable to convert a select of FP constants into |
| 434 | /// a constant pool load whose address depends on the select condition. The |
| 435 | /// parameter may be used to differentiate a select with FP compare from |
| 436 | /// integer compare. |
| 437 | virtual bool reduceSelectOfFPConstantLoads(EVT CmpOpVT) const { |
| 438 | return true; |
| 439 | } |
| 440 | |
| 441 | /// Return true if multiple condition registers are available. |
| 442 | bool hasMultipleConditionRegisters() const { |
| 443 | return HasMultipleConditionRegisters; |
| 444 | } |
| 445 | |
| 446 | /// Return true if the target has BitExtract instructions. |
| 447 | bool hasExtractBitsInsn() const { return HasExtractBitsInsn; } |
| 448 | |
| 449 | /// Return the preferred vector type legalization action. |
| 450 | virtual TargetLoweringBase::LegalizeTypeAction |
| 451 | getPreferredVectorAction(MVT VT) const { |
| 452 | // The default action for one element vectors is to scalarize |
| 453 | if (VT.getVectorElementCount().isScalar()) |
| 454 | return TypeScalarizeVector; |
| 455 | // The default action for an odd-width vector is to widen. |
| 456 | if (!VT.isPow2VectorType()) |
| 457 | return TypeWidenVector; |
| 458 | // The default action for other vectors is to promote |
| 459 | return TypePromoteInteger; |
| 460 | } |
| 461 | |
| 462 | // Return true if the half type should be passed around as i16, but promoted |
| 463 | // to float around arithmetic. The default behavior is to pass around as |
| 464 | // float and convert around loads/stores/bitcasts and other places where |
| 465 | // the size matters. |
| 466 | virtual bool softPromoteHalfType() const { return false; } |
| 467 | |
| 468 | // There are two general methods for expanding a BUILD_VECTOR node: |
| 469 | // 1. Use SCALAR_TO_VECTOR on the defined scalar values and then shuffle |
| 470 | // them together. |
| 471 | // 2. Build the vector on the stack and then load it. |
| 472 | // If this function returns true, then method (1) will be used, subject to |
| 473 | // the constraint that all of the necessary shuffles are legal (as determined |
| 474 | // by isShuffleMaskLegal). If this function returns false, then method (2) is |
| 475 | // always used. The vector type, and the number of defined values, are |
| 476 | // provided. |
| 477 | virtual bool |
| 478 | shouldExpandBuildVectorWithShuffles(EVT /* VT */, |
| 479 | unsigned DefinedValues) const { |
| 480 | return DefinedValues < 3; |
| 481 | } |
| 482 | |
| 483 | /// Return true if integer divide is usually cheaper than a sequence of |
| 484 | /// several shifts, adds, and multiplies for this target. |
| 485 | /// The definition of "cheaper" may depend on whether we're optimizing |
| 486 | /// for speed or for size. |
| 487 | virtual bool isIntDivCheap(EVT VT, AttributeList Attr) const { return false; } |
| 488 | |
| 489 | /// Return true if the target can handle a standalone remainder operation. |
| 490 | virtual bool hasStandaloneRem(EVT VT) const { |
| 491 | return true; |
| 492 | } |
| 493 | |
| 494 | /// Return true if SQRT(X) shouldn't be replaced with X*RSQRT(X). |
| 495 | virtual bool isFsqrtCheap(SDValue X, SelectionDAG &DAG) const { |
| 496 | // Default behavior is to replace SQRT(X) with X*RSQRT(X). |
| 497 | return false; |
| 498 | } |
| 499 | |
| 500 | /// Reciprocal estimate status values used by the functions below. |
| 501 | enum ReciprocalEstimate : int { |
| 502 | Unspecified = -1, |
| 503 | Disabled = 0, |
| 504 | Enabled = 1 |
| 505 | }; |
| 506 | |
| 507 | /// Return a ReciprocalEstimate enum value for a square root of the given type |
| 508 | /// based on the function's attributes. If the operation is not overridden by |
| 509 | /// the function's attributes, "Unspecified" is returned and target defaults |
| 510 | /// are expected to be used for instruction selection. |
| 511 | int getRecipEstimateSqrtEnabled(EVT VT, MachineFunction &MF) const; |
| 512 | |
| 513 | /// Return a ReciprocalEstimate enum value for a division of the given type |
| 514 | /// based on the function's attributes. If the operation is not overridden by |
| 515 | /// the function's attributes, "Unspecified" is returned and target defaults |
| 516 | /// are expected to be used for instruction selection. |
| 517 | int getRecipEstimateDivEnabled(EVT VT, MachineFunction &MF) const; |
| 518 | |
| 519 | /// Return the refinement step count for a square root of the given type based |
| 520 | /// on the function's attributes. If the operation is not overridden by |
| 521 | /// the function's attributes, "Unspecified" is returned and target defaults |
| 522 | /// are expected to be used for instruction selection. |
| 523 | int getSqrtRefinementSteps(EVT VT, MachineFunction &MF) const; |
| 524 | |
| 525 | /// Return the refinement step count for a division of the given type based |
| 526 | /// on the function's attributes. If the operation is not overridden by |
| 527 | /// the function's attributes, "Unspecified" is returned and target defaults |
| 528 | /// are expected to be used for instruction selection. |
| 529 | int getDivRefinementSteps(EVT VT, MachineFunction &MF) const; |
| 530 | |
| 531 | /// Returns true if target has indicated at least one type should be bypassed. |
| 532 | bool isSlowDivBypassed() const { return !BypassSlowDivWidths.empty(); } |
| 533 | |
| 534 | /// Returns map of slow types for division or remainder with corresponding |
| 535 | /// fast types |
| 536 | const DenseMap<unsigned int, unsigned int> &getBypassSlowDivWidths() const { |
| 537 | return BypassSlowDivWidths; |
| 538 | } |
| 539 | |
| 540 | /// Return true if Flow Control is an expensive operation that should be |
| 541 | /// avoided. |
| 542 | bool isJumpExpensive() const { return JumpIsExpensive; } |
| 543 | |
| 544 | /// Return true if selects are only cheaper than branches if the branch is |
| 545 | /// unlikely to be predicted right. |
| 546 | bool isPredictableSelectExpensive() const { |
| 547 | return PredictableSelectIsExpensive; |
| 548 | } |
| 549 | |
| 550 | virtual bool fallBackToDAGISel(const Instruction &Inst) const { |
| 551 | return false; |
| 552 | } |
| 553 | |
| 554 | /// Return true if the following transform is beneficial: |
| 555 | /// fold (conv (load x)) -> (load (conv*)x) |
| 556 | /// On architectures that don't natively support some vector loads |
| 557 | /// efficiently, casting the load to a smaller vector of larger types and |
| 558 | /// loading is more efficient, however, this can be undone by optimizations in |
| 559 | /// dag combiner. |
| 560 | virtual bool isLoadBitCastBeneficial(EVT LoadVT, EVT BitcastVT, |
| 561 | const SelectionDAG &DAG, |
| 562 | const MachineMemOperand &MMO) const { |
| 563 | // Don't do if we could do an indexed load on the original type, but not on |
| 564 | // the new one. |
| 565 | if (!LoadVT.isSimple() || !BitcastVT.isSimple()) |
| 566 | return true; |
| 567 | |
| 568 | MVT LoadMVT = LoadVT.getSimpleVT(); |
| 569 | |
| 570 | // Don't bother doing this if it's just going to be promoted again later, as |
| 571 | // doing so might interfere with other combines. |
| 572 | if (getOperationAction(ISD::LOAD, LoadMVT) == Promote && |
| 573 | getTypeToPromoteTo(ISD::LOAD, LoadMVT) == BitcastVT.getSimpleVT()) |
| 574 | return false; |
| 575 | |
| 576 | bool Fast = false; |
| 577 | return allowsMemoryAccess(*DAG.getContext(), DAG.getDataLayout(), BitcastVT, |
| 578 | MMO, &Fast) && Fast; |
| 579 | } |
| 580 | |
| 581 | /// Return true if the following transform is beneficial: |
| 582 | /// (store (y (conv x)), y*)) -> (store x, (x*)) |
| 583 | virtual bool isStoreBitCastBeneficial(EVT StoreVT, EVT BitcastVT, |
| 584 | const SelectionDAG &DAG, |
| 585 | const MachineMemOperand &MMO) const { |
| 586 | // Default to the same logic as loads. |
| 587 | return isLoadBitCastBeneficial(StoreVT, BitcastVT, DAG, MMO); |
| 588 | } |
| 589 | |
| 590 | /// Return true if it is expected to be cheaper to do a store of a non-zero |
| 591 | /// vector constant with the given size and type for the address space than to |
| 592 | /// store the individual scalar element constants. |
| 593 | virtual bool storeOfVectorConstantIsCheap(EVT MemVT, |
| 594 | unsigned NumElem, |
| 595 | unsigned AddrSpace) const { |
| 596 | return false; |
| 597 | } |
| 598 | |
| 599 | /// Allow store merging for the specified type after legalization in addition |
| 600 | /// to before legalization. This may transform stores that do not exist |
| 601 | /// earlier (for example, stores created from intrinsics). |
| 602 | virtual bool mergeStoresAfterLegalization(EVT MemVT) const { |
| 603 | return true; |
| 604 | } |
| 605 | |
| 606 | /// Returns if it's reasonable to merge stores to MemVT size. |
| 607 | virtual bool canMergeStoresTo(unsigned AS, EVT MemVT, |
| 608 | const MachineFunction &MF) const { |
| 609 | return true; |
| 610 | } |
| 611 | |
| 612 | /// Return true if it is cheap to speculate a call to intrinsic cttz. |
| 613 | virtual bool isCheapToSpeculateCttz() const { |
| 614 | return false; |
| 615 | } |
| 616 | |
| 617 | /// Return true if it is cheap to speculate a call to intrinsic ctlz. |
| 618 | virtual bool isCheapToSpeculateCtlz() const { |
| 619 | return false; |
| 620 | } |
| 621 | |
| 622 | /// Return true if ctlz instruction is fast. |
| 623 | virtual bool isCtlzFast() const { |
| 624 | return false; |
| 625 | } |
| 626 | |
| 627 | /// Return the maximum number of "x & (x - 1)" operations that can be done |
| 628 | /// instead of deferring to a custom CTPOP. |
| 629 | virtual unsigned getCustomCtpopCost(EVT VT, ISD::CondCode Cond) const { |
| 630 | return 1; |
| 631 | } |
| 632 | |
| 633 | /// Return true if instruction generated for equality comparison is folded |
| 634 | /// with instruction generated for signed comparison. |
| 635 | virtual bool isEqualityCmpFoldedWithSignedCmp() const { return true; } |
| 636 | |
| 637 | /// Return true if the heuristic to prefer icmp eq zero should be used in code |
| 638 | /// gen prepare. |
| 639 | virtual bool preferZeroCompareBranch() const { return false; } |
| 640 | |
| 641 | /// Return true if it is safe to transform an integer-domain bitwise operation |
| 642 | /// into the equivalent floating-point operation. This should be set to true |
| 643 | /// if the target has IEEE-754-compliant fabs/fneg operations for the input |
| 644 | /// type. |
| 645 | virtual bool hasBitPreservingFPLogic(EVT VT) const { |
| 646 | return false; |
| 647 | } |
| 648 | |
| 649 | /// Return true if it is cheaper to split the store of a merged int val |
| 650 | /// from a pair of smaller values into multiple stores. |
| 651 | virtual bool isMultiStoresCheaperThanBitsMerge(EVT LTy, EVT HTy) const { |
| 652 | return false; |
| 653 | } |
| 654 | |
| 655 | /// Return if the target supports combining a |
| 656 | /// chain like: |
| 657 | /// \code |
| 658 | /// %andResult = and %val1, #mask |
| 659 | /// %icmpResult = icmp %andResult, 0 |
| 660 | /// \endcode |
| 661 | /// into a single machine instruction of a form like: |
| 662 | /// \code |
| 663 | /// cc = test %register, #mask |
| 664 | /// \endcode |
| 665 | virtual bool isMaskAndCmp0FoldingBeneficial(const Instruction &AndI) const { |
| 666 | return false; |
| 667 | } |
| 668 | |
| 669 | /// Use bitwise logic to make pairs of compares more efficient. For example: |
| 670 | /// and (seteq A, B), (seteq C, D) --> seteq (or (xor A, B), (xor C, D)), 0 |
| 671 | /// This should be true when it takes more than one instruction to lower |
| 672 | /// setcc (cmp+set on x86 scalar), when bitwise ops are faster than logic on |
| 673 | /// condition bits (crand on PowerPC), and/or when reducing cmp+br is a win. |
| 674 | virtual bool convertSetCCLogicToBitwiseLogic(EVT VT) const { |
| 675 | return false; |
| 676 | } |
| 677 | |
| 678 | /// Return the preferred operand type if the target has a quick way to compare |
| 679 | /// integer values of the given size. Assume that any legal integer type can |
| 680 | /// be compared efficiently. Targets may override this to allow illegal wide |
| 681 | /// types to return a vector type if there is support to compare that type. |
| 682 | virtual MVT hasFastEqualityCompare(unsigned NumBits) const { |
| 683 | MVT VT = MVT::getIntegerVT(NumBits); |
| 684 | return isTypeLegal(VT) ? VT : MVT::INVALID_SIMPLE_VALUE_TYPE; |
| 685 | } |
| 686 | |
| 687 | /// Return true if the target should transform: |
| 688 | /// (X & Y) == Y ---> (~X & Y) == 0 |
| 689 | /// (X & Y) != Y ---> (~X & Y) != 0 |
| 690 | /// |
| 691 | /// This may be profitable if the target has a bitwise and-not operation that |
| 692 | /// sets comparison flags. A target may want to limit the transformation based |
| 693 | /// on the type of Y or if Y is a constant. |
| 694 | /// |
| 695 | /// Note that the transform will not occur if Y is known to be a power-of-2 |
| 696 | /// because a mask and compare of a single bit can be handled by inverting the |
| 697 | /// predicate, for example: |
| 698 | /// (X & 8) == 8 ---> (X & 8) != 0 |
| 699 | virtual bool hasAndNotCompare(SDValue Y) const { |
| 700 | return false; |
| 701 | } |
| 702 | |
| 703 | /// Return true if the target has a bitwise and-not operation: |
| 704 | /// X = ~A & B |
| 705 | /// This can be used to simplify select or other instructions. |
| 706 | virtual bool hasAndNot(SDValue X) const { |
| 707 | // If the target has the more complex version of this operation, assume that |
| 708 | // it has this operation too. |
| 709 | return hasAndNotCompare(X); |
| 710 | } |
| 711 | |
| 712 | /// Return true if the target has a bit-test instruction: |
| 713 | /// (X & (1 << Y)) ==/!= 0 |
| 714 | /// This knowledge can be used to prevent breaking the pattern, |
| 715 | /// or creating it if it could be recognized. |
| 716 | virtual bool hasBitTest(SDValue X, SDValue Y) const { return false; } |
| 717 | |
| 718 | /// There are two ways to clear extreme bits (either low or high): |
| 719 | /// Mask: x & (-1 << y) (the instcombine canonical form) |
| 720 | /// Shifts: x >> y << y |
| 721 | /// Return true if the variant with 2 variable shifts is preferred. |
| 722 | /// Return false if there is no preference. |
| 723 | virtual bool shouldFoldMaskToVariableShiftPair(SDValue X) const { |
| 724 | // By default, let's assume that no one prefers shifts. |
| 725 | return false; |
| 726 | } |
| 727 | |
| 728 | /// Return true if it is profitable to fold a pair of shifts into a mask. |
| 729 | /// This is usually true on most targets. But some targets, like Thumb1, |
| 730 | /// have immediate shift instructions, but no immediate "and" instruction; |
| 731 | /// this makes the fold unprofitable. |
| 732 | virtual bool shouldFoldConstantShiftPairToMask(const SDNode *N, |
| 733 | CombineLevel Level) const { |
| 734 | return true; |
| 735 | } |
| 736 | |
| 737 | /// Should we tranform the IR-optimal check for whether given truncation |
| 738 | /// down into KeptBits would be truncating or not: |
| 739 | /// (add %x, (1 << (KeptBits-1))) srccond (1 << KeptBits) |
| 740 | /// Into it's more traditional form: |
| 741 | /// ((%x << C) a>> C) dstcond %x |
| 742 | /// Return true if we should transform. |
| 743 | /// Return false if there is no preference. |
| 744 | virtual bool shouldTransformSignedTruncationCheck(EVT XVT, |
| 745 | unsigned KeptBits) const { |
| 746 | // By default, let's assume that no one prefers shifts. |
| 747 | return false; |
| 748 | } |
| 749 | |
| 750 | /// Given the pattern |
| 751 | /// (X & (C l>>/<< Y)) ==/!= 0 |
| 752 | /// return true if it should be transformed into: |
| 753 | /// ((X <</l>> Y) & C) ==/!= 0 |
| 754 | /// WARNING: if 'X' is a constant, the fold may deadlock! |
| 755 | /// FIXME: we could avoid passing XC, but we can't use isConstOrConstSplat() |
| 756 | /// here because it can end up being not linked in. |
| 757 | virtual bool shouldProduceAndByConstByHoistingConstFromShiftsLHSOfAnd( |
| 758 | SDValue X, ConstantSDNode *XC, ConstantSDNode *CC, SDValue Y, |
| 759 | unsigned OldShiftOpcode, unsigned NewShiftOpcode, |
| 760 | SelectionDAG &DAG) const { |
| 761 | if (hasBitTest(X, Y)) { |
| 762 | // One interesting pattern that we'd want to form is 'bit test': |
| 763 | // ((1 << Y) & C) ==/!= 0 |
| 764 | // But we also need to be careful not to try to reverse that fold. |
| 765 | |
| 766 | // Is this '1 << Y' ? |
| 767 | if (OldShiftOpcode == ISD::SHL && CC->isOne()) |
| 768 | return false; // Keep the 'bit test' pattern. |
| 769 | |
| 770 | // Will it be '1 << Y' after the transform ? |
| 771 | if (XC && NewShiftOpcode == ISD::SHL && XC->isOne()) |
| 772 | return true; // Do form the 'bit test' pattern. |
| 773 | } |
| 774 | |
| 775 | // If 'X' is a constant, and we transform, then we will immediately |
| 776 | // try to undo the fold, thus causing endless combine loop. |
| 777 | // So by default, let's assume everyone prefers the fold |
| 778 | // iff 'X' is not a constant. |
| 779 | return !XC; |
| 780 | } |
| 781 | |
| 782 | /// These two forms are equivalent: |
| 783 | /// sub %y, (xor %x, -1) |
| 784 | /// add (add %x, 1), %y |
| 785 | /// The variant with two add's is IR-canonical. |
| 786 | /// Some targets may prefer one to the other. |
| 787 | virtual bool preferIncOfAddToSubOfNot(EVT VT) const { |
| 788 | // By default, let's assume that everyone prefers the form with two add's. |
| 789 | return true; |
| 790 | } |
| 791 | |
| 792 | /// Return true if the target wants to use the optimization that |
| 793 | /// turns ext(promotableInst1(...(promotableInstN(load)))) into |
| 794 | /// promotedInst1(...(promotedInstN(ext(load)))). |
| 795 | bool enableExtLdPromotion() const { return EnableExtLdPromotion; } |
| 796 | |
| 797 | /// Return true if the target can combine store(extractelement VectorTy, |
| 798 | /// Idx). |
| 799 | /// \p Cost[out] gives the cost of that transformation when this is true. |
| 800 | virtual bool canCombineStoreAndExtract(Type *VectorTy, Value *Idx, |
| 801 | unsigned &Cost) const { |
| 802 | return false; |
| 803 | } |
| 804 | |
| 805 | /// Return true if inserting a scalar into a variable element of an undef |
| 806 | /// vector is more efficiently handled by splatting the scalar instead. |
| 807 | virtual bool shouldSplatInsEltVarIndex(EVT) const { |
| 808 | return false; |
| 809 | } |
| 810 | |
| 811 | /// Return true if target always benefits from combining into FMA for a |
| 812 | /// given value type. This must typically return false on targets where FMA |
| 813 | /// takes more cycles to execute than FADD. |
| 814 | virtual bool enableAggressiveFMAFusion(EVT VT) const { return false; } |
| 815 | |
| 816 | /// Return true if target always benefits from combining into FMA for a |
| 817 | /// given value type. This must typically return false on targets where FMA |
| 818 | /// takes more cycles to execute than FADD. |
| 819 | virtual bool enableAggressiveFMAFusion(LLT Ty) const { return false; } |
| 820 | |
| 821 | /// Return the ValueType of the result of SETCC operations. |
| 822 | virtual EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, |
| 823 | EVT VT) const; |
| 824 | |
| 825 | /// Return the ValueType for comparison libcalls. Comparions libcalls include |
| 826 | /// floating point comparion calls, and Ordered/Unordered check calls on |
| 827 | /// floating point numbers. |
| 828 | virtual |
| 829 | MVT::SimpleValueType getCmpLibcallReturnType() const; |
| 830 | |
| 831 | /// For targets without i1 registers, this gives the nature of the high-bits |
| 832 | /// of boolean values held in types wider than i1. |
| 833 | /// |
| 834 | /// "Boolean values" are special true/false values produced by nodes like |
| 835 | /// SETCC and consumed (as the condition) by nodes like SELECT and BRCOND. |
| 836 | /// Not to be confused with general values promoted from i1. Some cpus |
| 837 | /// distinguish between vectors of boolean and scalars; the isVec parameter |
| 838 | /// selects between the two kinds. For example on X86 a scalar boolean should |
| 839 | /// be zero extended from i1, while the elements of a vector of booleans |
| 840 | /// should be sign extended from i1. |
| 841 | /// |
| 842 | /// Some cpus also treat floating point types the same way as they treat |
| 843 | /// vectors instead of the way they treat scalars. |
| 844 | BooleanContent getBooleanContents(bool isVec, bool isFloat) const { |
| 845 | if (isVec) |
| 846 | return BooleanVectorContents; |
| 847 | return isFloat ? BooleanFloatContents : BooleanContents; |
| 848 | } |
| 849 | |
| 850 | BooleanContent getBooleanContents(EVT Type) const { |
| 851 | return getBooleanContents(Type.isVector(), Type.isFloatingPoint()); |
| 852 | } |
| 853 | |
| 854 | /// Promote the given target boolean to a target boolean of the given type. |
| 855 | /// A target boolean is an integer value, not necessarily of type i1, the bits |
| 856 | /// of which conform to getBooleanContents. |
| 857 | /// |
| 858 | /// ValVT is the type of values that produced the boolean. |
| 859 | SDValue promoteTargetBoolean(SelectionDAG &DAG, SDValue Bool, |
| 860 | EVT ValVT) const { |
| 861 | SDLoc dl(Bool); |
| 862 | EVT BoolVT = |
| 863 | getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), ValVT); |
| 864 | ISD::NodeType ExtendCode = getExtendForContent(getBooleanContents(ValVT)); |
| 865 | return DAG.getNode(ExtendCode, dl, BoolVT, Bool); |
| 866 | } |
| 867 | |
| 868 | /// Return target scheduling preference. |
| 869 | Sched::Preference getSchedulingPreference() const { |
| 870 | return SchedPreferenceInfo; |
| 871 | } |
| 872 | |
| 873 | /// Some scheduler, e.g. hybrid, can switch to different scheduling heuristics |
| 874 | /// for different nodes. This function returns the preference (or none) for |
| 875 | /// the given node. |
| 876 | virtual Sched::Preference getSchedulingPreference(SDNode *) const { |
| 877 | return Sched::None; |
| 878 | } |
| 879 | |
| 880 | /// Return the register class that should be used for the specified value |
| 881 | /// type. |
| 882 | virtual const TargetRegisterClass *getRegClassFor(MVT VT, bool isDivergent = false) const { |
| 883 | (void)isDivergent; |
| 884 | const TargetRegisterClass *RC = RegClassForVT[VT.SimpleTy]; |
| 885 | assert(RC && "This value type is not natively supported!"); |
| 886 | return RC; |
| 887 | } |
| 888 | |
| 889 | /// Allows target to decide about the register class of the |
| 890 | /// specific value that is live outside the defining block. |
| 891 | /// Returns true if the value needs uniform register class. |
| 892 | virtual bool requiresUniformRegister(MachineFunction &MF, |
| 893 | const Value *) const { |
| 894 | return false; |
| 895 | } |
| 896 | |
| 897 | /// Return the 'representative' register class for the specified value |
| 898 | /// type. |
| 899 | /// |
| 900 | /// The 'representative' register class is the largest legal super-reg |
| 901 | /// register class for the register class of the value type. For example, on |
| 902 | /// i386 the rep register class for i8, i16, and i32 are GR32; while the rep |
| 903 | /// register class is GR64 on x86_64. |
| 904 | virtual const TargetRegisterClass *getRepRegClassFor(MVT VT) const { |
| 905 | const TargetRegisterClass *RC = RepRegClassForVT[VT.SimpleTy]; |
| 906 | return RC; |
| 907 | } |
| 908 | |
| 909 | /// Return the cost of the 'representative' register class for the specified |
| 910 | /// value type. |
| 911 | virtual uint8_t getRepRegClassCostFor(MVT VT) const { |
| 912 | return RepRegClassCostForVT[VT.SimpleTy]; |
| 913 | } |
| 914 | |
| 915 | /// Return true if SHIFT instructions should be expanded to SHIFT_PARTS |
| 916 | /// instructions, and false if a library call is preferred (e.g for code-size |
| 917 | /// reasons). |
| 918 | virtual bool shouldExpandShift(SelectionDAG &DAG, SDNode *N) const { |
| 919 | return true; |
| 920 | } |
| 921 | |
| 922 | /// Return true if the target has native support for the specified value type. |
| 923 | /// This means that it has a register that directly holds it without |
| 924 | /// promotions or expansions. |
| 925 | bool isTypeLegal(EVT VT) const { |
| 926 | assert(!VT.isSimple() || |
| 927 | (unsigned)VT.getSimpleVT().SimpleTy < array_lengthof(RegClassForVT)); |
| 928 | return VT.isSimple() && RegClassForVT[VT.getSimpleVT().SimpleTy] != nullptr; |
| 929 | } |
| 930 | |
| 931 | class ValueTypeActionImpl { |
| 932 | /// ValueTypeActions - For each value type, keep a LegalizeTypeAction enum |
| 933 | /// that indicates how instruction selection should deal with the type. |
| 934 | LegalizeTypeAction ValueTypeActions[MVT::VALUETYPE_SIZE]; |
| 935 | |
| 936 | public: |
| 937 | ValueTypeActionImpl() { |
| 938 | std::fill(std::begin(ValueTypeActions), std::end(ValueTypeActions), |
| 939 | TypeLegal); |
| 940 | } |
| 941 | |
| 942 | LegalizeTypeAction getTypeAction(MVT VT) const { |
| 943 | return ValueTypeActions[VT.SimpleTy]; |
| 944 | } |
| 945 | |
| 946 | void setTypeAction(MVT VT, LegalizeTypeAction Action) { |
| 947 | ValueTypeActions[VT.SimpleTy] = Action; |
| 948 | } |
| 949 | }; |
| 950 | |
| 951 | const ValueTypeActionImpl &getValueTypeActions() const { |
| 952 | return ValueTypeActions; |
| 953 | } |
| 954 | |
| 955 | /// Return how we should legalize values of this type, either it is already |
| 956 | /// legal (return 'Legal') or we need to promote it to a larger type (return |
| 957 | /// 'Promote'), or we need to expand it into multiple registers of smaller |
| 958 | /// integer type (return 'Expand'). 'Custom' is not an option. |
| 959 | LegalizeTypeAction getTypeAction(LLVMContext &Context, EVT VT) const { |
| 960 | return getTypeConversion(Context, VT).first; |
| 961 | } |
| 962 | LegalizeTypeAction getTypeAction(MVT VT) const { |
| 963 | return ValueTypeActions.getTypeAction(VT); |
| 964 | } |
| 965 | |
| 966 | /// For types supported by the target, this is an identity function. For |
| 967 | /// types that must be promoted to larger types, this returns the larger type |
| 968 | /// to promote to. For integer types that are larger than the largest integer |
| 969 | /// register, this contains one step in the expansion to get to the smaller |
| 970 | /// register. For illegal floating point types, this returns the integer type |
| 971 | /// to transform to. |
| 972 | EVT getTypeToTransformTo(LLVMContext &Context, EVT VT) const { |
| 973 | return getTypeConversion(Context, VT).second; |
| 974 | } |
| 975 | |
| 976 | /// For types supported by the target, this is an identity function. For |
| 977 | /// types that must be expanded (i.e. integer types that are larger than the |
| 978 | /// largest integer register or illegal floating point types), this returns |
| 979 | /// the largest legal type it will be expanded to. |
| 980 | EVT getTypeToExpandTo(LLVMContext &Context, EVT VT) const { |
| 981 | assert(!VT.isVector()); |
| 982 | while (true) { |
| 983 | switch (getTypeAction(Context, VT)) { |
| 984 | case TypeLegal: |
| 985 | return VT; |
| 986 | case TypeExpandInteger: |
| 987 | VT = getTypeToTransformTo(Context, VT); |
| 988 | break; |
| 989 | default: |
| 990 | llvm_unreachable("Type is not legal nor is it to be expanded!"); |
| 991 | } |
| 992 | } |
| 993 | } |
| 994 | |
| 995 | /// Vector types are broken down into some number of legal first class types. |
| 996 | /// For example, EVT::v8f32 maps to 2 EVT::v4f32 with Altivec or SSE1, or 8 |
| 997 | /// promoted EVT::f64 values with the X86 FP stack. Similarly, EVT::v2i64 |
| 998 | /// turns into 4 EVT::i32 values with both PPC and X86. |
| 999 | /// |
| 1000 | /// This method returns the number of registers needed, and the VT for each |
| 1001 | /// register. It also returns the VT and quantity of the intermediate values |
| 1002 | /// before they are promoted/expanded. |
| 1003 | unsigned getVectorTypeBreakdown(LLVMContext &Context, EVT VT, |
| 1004 | EVT &IntermediateVT, |
| 1005 | unsigned &NumIntermediates, |
| 1006 | MVT &RegisterVT) const; |
| 1007 | |
| 1008 | /// Certain targets such as MIPS require that some types such as vectors are |
| 1009 | /// always broken down into scalars in some contexts. This occurs even if the |
| 1010 | /// vector type is legal. |
| 1011 | virtual unsigned getVectorTypeBreakdownForCallingConv( |
| 1012 | LLVMContext &Context, CallingConv::ID CC, EVT VT, EVT &IntermediateVT, |
| 1013 | unsigned &NumIntermediates, MVT &RegisterVT) const { |
| 1014 | return getVectorTypeBreakdown(Context, VT, IntermediateVT, NumIntermediates, |
| 1015 | RegisterVT); |
| 1016 | } |
| 1017 | |
| 1018 | struct IntrinsicInfo { |
| 1019 | unsigned opc = 0; // target opcode |
| 1020 | EVT memVT; // memory VT |
| 1021 | |
| 1022 | // value representing memory location |
| 1023 | PointerUnion<const Value *, const PseudoSourceValue *> ptrVal; |
| 1024 | |
| 1025 | int offset = 0; // offset off of ptrVal |
| 1026 | uint64_t size = 0; // the size of the memory location |
| 1027 | // (taken from memVT if zero) |
| 1028 | MaybeAlign align = Align(1); // alignment |
| 1029 | |
| 1030 | MachineMemOperand::Flags flags = MachineMemOperand::MONone; |
| 1031 | IntrinsicInfo() = default; |
| 1032 | }; |
| 1033 | |
| 1034 | /// Given an intrinsic, checks if on the target the intrinsic will need to map |
| 1035 | /// to a MemIntrinsicNode (touches memory). If this is the case, it returns |
| 1036 | /// true and store the intrinsic information into the IntrinsicInfo that was |
| 1037 | /// passed to the function. |
| 1038 | virtual bool getTgtMemIntrinsic(IntrinsicInfo &, const CallInst &, |
| 1039 | MachineFunction &, |
| 1040 | unsigned /*Intrinsic*/) const { |
| 1041 | return false; |
| 1042 | } |
| 1043 | |
| 1044 | /// Returns true if the target can instruction select the specified FP |
| 1045 | /// immediate natively. If false, the legalizer will materialize the FP |
| 1046 | /// immediate as a load from a constant pool. |
| 1047 | virtual bool isFPImmLegal(const APFloat & /*Imm*/, EVT /*VT*/, |
| 1048 | bool ForCodeSize = false) const { |
| 1049 | return false; |
| 1050 | } |
| 1051 | |
| 1052 | /// Targets can use this to indicate that they only support *some* |
| 1053 | /// VECTOR_SHUFFLE operations, those with specific masks. By default, if a |
| 1054 | /// target supports the VECTOR_SHUFFLE node, all mask values are assumed to be |
| 1055 | /// legal. |
| 1056 | virtual bool isShuffleMaskLegal(ArrayRef<int> /*Mask*/, EVT /*VT*/) const { |
| 1057 | return true; |
| 1058 | } |
| 1059 | |
| 1060 | /// Returns true if the operation can trap for the value type. |
| 1061 | /// |
| 1062 | /// VT must be a legal type. By default, we optimistically assume most |
| 1063 | /// operations don't trap except for integer divide and remainder. |
| 1064 | virtual bool canOpTrap(unsigned Op, EVT VT) const; |
| 1065 | |
| 1066 | /// Similar to isShuffleMaskLegal. Targets can use this to indicate if there |
| 1067 | /// is a suitable VECTOR_SHUFFLE that can be used to replace a VAND with a |
| 1068 | /// constant pool entry. |
| 1069 | virtual bool isVectorClearMaskLegal(ArrayRef<int> /*Mask*/, |
| 1070 | EVT /*VT*/) const { |
| 1071 | return false; |
| 1072 | } |
| 1073 | |
| 1074 | /// Return how this operation should be treated: either it is legal, needs to |
| 1075 | /// be promoted to a larger size, needs to be expanded to some other code |
| 1076 | /// sequence, or the target has a custom expander for it. |
| 1077 | LegalizeAction getOperationAction(unsigned Op, EVT VT) const { |
| 1078 | if (VT.isExtended()) return Expand; |
| 1079 | // If a target-specific SDNode requires legalization, require the target |
| 1080 | // to provide custom legalization for it. |
| 1081 | if (Op >= array_lengthof(OpActions[0])) return Custom; |
| 1082 | return OpActions[(unsigned)VT.getSimpleVT().SimpleTy][Op]; |
| 1083 | } |
| 1084 | |
| 1085 | /// Custom method defined by each target to indicate if an operation which |
| 1086 | /// may require a scale is supported natively by the target. |
| 1087 | /// If not, the operation is illegal. |
| 1088 | virtual bool isSupportedFixedPointOperation(unsigned Op, EVT VT, |
| 1089 | unsigned Scale) const { |
| 1090 | return false; |
| 1091 | } |
| 1092 | |
| 1093 | /// Some fixed point operations may be natively supported by the target but |
| 1094 | /// only for specific scales. This method allows for checking |
| 1095 | /// if the width is supported by the target for a given operation that may |
| 1096 | /// depend on scale. |
| 1097 | LegalizeAction getFixedPointOperationAction(unsigned Op, EVT VT, |
| 1098 | unsigned Scale) const { |
| 1099 | auto Action = getOperationAction(Op, VT); |
| 1100 | if (Action != Legal) |
| 1101 | return Action; |
| 1102 | |
| 1103 | // This operation is supported in this type but may only work on specific |
| 1104 | // scales. |
| 1105 | bool Supported; |
| 1106 | switch (Op) { |
| 1107 | default: |
| 1108 | llvm_unreachable("Unexpected fixed point operation."); |
| 1109 | case ISD::SMULFIX: |
| 1110 | case ISD::SMULFIXSAT: |
| 1111 | case ISD::UMULFIX: |
| 1112 | case ISD::UMULFIXSAT: |
| 1113 | case ISD::SDIVFIX: |
| 1114 | case ISD::SDIVFIXSAT: |
| 1115 | case ISD::UDIVFIX: |
| 1116 | case ISD::UDIVFIXSAT: |
| 1117 | Supported = isSupportedFixedPointOperation(Op, VT, Scale); |
| 1118 | break; |
| 1119 | } |
| 1120 | |
| 1121 | return Supported ? Action : Expand; |
| 1122 | } |
| 1123 | |
| 1124 | // If Op is a strict floating-point operation, return the result |
| 1125 | // of getOperationAction for the equivalent non-strict operation. |
| 1126 | LegalizeAction getStrictFPOperationAction(unsigned Op, EVT VT) const { |
| 1127 | unsigned EqOpc; |
| 1128 | switch (Op) { |
| 1129 | default: llvm_unreachable("Unexpected FP pseudo-opcode"); |
| 1130 | #define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \ |
| 1131 | case ISD::STRICT_##DAGN: EqOpc = ISD::DAGN; break; |
| 1132 | #define CMP_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \ |
| 1133 | case ISD::STRICT_##DAGN: EqOpc = ISD::SETCC; break; |
| 1134 | #include "llvm/IR/ConstrainedOps.def" |
| 1135 | } |
| 1136 | |
| 1137 | return getOperationAction(EqOpc, VT); |
| 1138 | } |
| 1139 | |
| 1140 | /// Return true if the specified operation is legal on this target or can be |
| 1141 | /// made legal with custom lowering. This is used to help guide high-level |
| 1142 | /// lowering decisions. LegalOnly is an optional convenience for code paths |
| 1143 | /// traversed pre and post legalisation. |
| 1144 | bool isOperationLegalOrCustom(unsigned Op, EVT VT, |
| 1145 | bool LegalOnly = false) const { |
| 1146 | if (LegalOnly) |
| 1147 | return isOperationLegal(Op, VT); |
| 1148 | |
| 1149 | return (VT == MVT::Other || isTypeLegal(VT)) && |
| 1150 | (getOperationAction(Op, VT) == Legal || |
| 1151 | getOperationAction(Op, VT) == Custom); |
| 1152 | } |
| 1153 | |
| 1154 | /// Return true if the specified operation is legal on this target or can be |
| 1155 | /// made legal using promotion. This is used to help guide high-level lowering |
| 1156 | /// decisions. LegalOnly is an optional convenience for code paths traversed |
| 1157 | /// pre and post legalisation. |
| 1158 | bool isOperationLegalOrPromote(unsigned Op, EVT VT, |
| 1159 | bool LegalOnly = false) const { |
| 1160 | if (LegalOnly) |
| 1161 | return isOperationLegal(Op, VT); |
| 1162 | |
| 1163 | return (VT == MVT::Other || isTypeLegal(VT)) && |
| 1164 | (getOperationAction(Op, VT) == Legal || |
| 1165 | getOperationAction(Op, VT) == Promote); |
| 1166 | } |
| 1167 | |
| 1168 | /// Return true if the specified operation is legal on this target or can be |
| 1169 | /// made legal with custom lowering or using promotion. This is used to help |
| 1170 | /// guide high-level lowering decisions. LegalOnly is an optional convenience |
| 1171 | /// for code paths traversed pre and post legalisation. |
| 1172 | bool isOperationLegalOrCustomOrPromote(unsigned Op, EVT VT, |
| 1173 | bool LegalOnly = false) const { |
| 1174 | if (LegalOnly) |
| 1175 | return isOperationLegal(Op, VT); |
| 1176 | |
| 1177 | return (VT == MVT::Other || isTypeLegal(VT)) && |
| 1178 | (getOperationAction(Op, VT) == Legal || |
| 1179 | getOperationAction(Op, VT) == Custom || |
| 1180 | getOperationAction(Op, VT) == Promote); |
| 1181 | } |
| 1182 | |
| 1183 | /// Return true if the operation uses custom lowering, regardless of whether |
| 1184 | /// the type is legal or not. |
| 1185 | bool isOperationCustom(unsigned Op, EVT VT) const { |
| 1186 | return getOperationAction(Op, VT) == Custom; |
| 1187 | } |
| 1188 | |
| 1189 | /// Return true if lowering to a jump table is allowed. |
| 1190 | virtual bool areJTsAllowed(const Function *Fn) const { |
| 1191 | if (Fn->getFnAttribute("no-jump-tables").getValueAsBool()) |
| 1192 | return false; |
| 1193 | |
| 1194 | return isOperationLegalOrCustom(ISD::BR_JT, MVT::Other) || |
| 1195 | isOperationLegalOrCustom(ISD::BRIND, MVT::Other); |
| 1196 | } |
| 1197 | |
| 1198 | /// Check whether the range [Low,High] fits in a machine word. |
| 1199 | bool rangeFitsInWord(const APInt &Low, const APInt &High, |
| 1200 | const DataLayout &DL) const { |
| 1201 | // FIXME: Using the pointer type doesn't seem ideal. |
| 1202 | uint64_t BW = DL.getIndexSizeInBits(0u); |
| 1203 | uint64_t Range = (High - Low).getLimitedValue(UINT64_MAX - 1) + 1; |
| 1204 | return Range <= BW; |
| 1205 | } |
| 1206 | |
| 1207 | /// Return true if lowering to a jump table is suitable for a set of case |
| 1208 | /// clusters which may contain \p NumCases cases, \p Range range of values. |
| 1209 | virtual bool isSuitableForJumpTable(const SwitchInst *SI, uint64_t NumCases, |
| 1210 | uint64_t Range, ProfileSummaryInfo *PSI, |
| 1211 | BlockFrequencyInfo *BFI) const; |
| 1212 | |
| 1213 | /// Return true if lowering to a bit test is suitable for a set of case |
| 1214 | /// clusters which contains \p NumDests unique destinations, \p Low and |
| 1215 | /// \p High as its lowest and highest case values, and expects \p NumCmps |
| 1216 | /// case value comparisons. Check if the number of destinations, comparison |
| 1217 | /// metric, and range are all suitable. |
| 1218 | bool isSuitableForBitTests(unsigned NumDests, unsigned NumCmps, |
| 1219 | const APInt &Low, const APInt &High, |
| 1220 | const DataLayout &DL) const { |
| 1221 | // FIXME: I don't think NumCmps is the correct metric: a single case and a |
| 1222 | // range of cases both require only one branch to lower. Just looking at the |
| 1223 | // number of clusters and destinations should be enough to decide whether to |
| 1224 | // build bit tests. |
| 1225 | |
| 1226 | // To lower a range with bit tests, the range must fit the bitwidth of a |
| 1227 | // machine word. |
| 1228 | if (!rangeFitsInWord(Low, High, DL)) |
| 1229 | return false; |
| 1230 | |
| 1231 | // Decide whether it's profitable to lower this range with bit tests. Each |
| 1232 | // destination requires a bit test and branch, and there is an overall range |
| 1233 | // check branch. For a small number of clusters, separate comparisons might |
| 1234 | // be cheaper, and for many destinations, splitting the range might be |
| 1235 | // better. |
| 1236 | return (NumDests == 1 && NumCmps >= 3) || (NumDests == 2 && NumCmps >= 5) || |
| 1237 | (NumDests == 3 && NumCmps >= 6); |
| 1238 | } |
| 1239 | |
| 1240 | /// Return true if the specified operation is illegal on this target or |
| 1241 | /// unlikely to be made legal with custom lowering. This is used to help guide |
| 1242 | /// high-level lowering decisions. |
| 1243 | bool isOperationExpand(unsigned Op, EVT VT) const { |
| 1244 | return (!isTypeLegal(VT) || getOperationAction(Op, VT) == Expand); |
| 1245 | } |
| 1246 | |
| 1247 | /// Return true if the specified operation is legal on this target. |
| 1248 | bool isOperationLegal(unsigned Op, EVT VT) const { |
| 1249 | return (VT == MVT::Other || isTypeLegal(VT)) && |
| 1250 | getOperationAction(Op, VT) == Legal; |
| 1251 | } |
| 1252 | |
| 1253 | /// Return how this load with extension should be treated: either it is legal, |
| 1254 | /// needs to be promoted to a larger size, needs to be expanded to some other |
| 1255 | /// code sequence, or the target has a custom expander for it. |
| 1256 | LegalizeAction getLoadExtAction(unsigned ExtType, EVT ValVT, |
| 1257 | EVT MemVT) const { |
| 1258 | if (ValVT.isExtended() || MemVT.isExtended()) return Expand; |
| 1259 | unsigned ValI = (unsigned) ValVT.getSimpleVT().SimpleTy; |
| 1260 | unsigned MemI = (unsigned) MemVT.getSimpleVT().SimpleTy; |
| 1261 | assert(ExtType < ISD::LAST_LOADEXT_TYPE && ValI < MVT::VALUETYPE_SIZE && |
| 1262 | MemI < MVT::VALUETYPE_SIZE && "Table isn't big enough!"); |
| 1263 | unsigned Shift = 4 * ExtType; |
| 1264 | return (LegalizeAction)((LoadExtActions[ValI][MemI] >> Shift) & 0xf); |
| 1265 | } |
| 1266 | |
| 1267 | /// Return true if the specified load with extension is legal on this target. |
| 1268 | bool isLoadExtLegal(unsigned ExtType, EVT ValVT, EVT MemVT) const { |
| 1269 | return getLoadExtAction(ExtType, ValVT, MemVT) == Legal; |
| 1270 | } |
| 1271 | |
| 1272 | /// Return true if the specified load with extension is legal or custom |
| 1273 | /// on this target. |
| 1274 | bool isLoadExtLegalOrCustom(unsigned ExtType, EVT ValVT, EVT MemVT) const { |
| 1275 | return getLoadExtAction(ExtType, ValVT, MemVT) == Legal || |
| 1276 | getLoadExtAction(ExtType, ValVT, MemVT) == Custom; |
| 1277 | } |
| 1278 | |
| 1279 | /// Return how this store with truncation should be treated: either it is |
| 1280 | /// legal, needs to be promoted to a larger size, needs to be expanded to some |
| 1281 | /// other code sequence, or the target has a custom expander for it. |
| 1282 | LegalizeAction getTruncStoreAction(EVT ValVT, EVT MemVT) const { |
| 1283 | if (ValVT.isExtended() || MemVT.isExtended()) return Expand; |
| 1284 | unsigned ValI = (unsigned) ValVT.getSimpleVT().SimpleTy; |
| 1285 | unsigned MemI = (unsigned) MemVT.getSimpleVT().SimpleTy; |
| 1286 | assert(ValI < MVT::VALUETYPE_SIZE && MemI < MVT::VALUETYPE_SIZE && |
| 1287 | "Table isn't big enough!"); |
| 1288 | return TruncStoreActions[ValI][MemI]; |
| 1289 | } |
| 1290 | |
| 1291 | /// Return true if the specified store with truncation is legal on this |
| 1292 | /// target. |
| 1293 | bool isTruncStoreLegal(EVT ValVT, EVT MemVT) const { |
| 1294 | return isTypeLegal(ValVT) && getTruncStoreAction(ValVT, MemVT) == Legal; |
| 1295 | } |
| 1296 | |
| 1297 | /// Return true if the specified store with truncation has solution on this |
| 1298 | /// target. |
| 1299 | bool isTruncStoreLegalOrCustom(EVT ValVT, EVT MemVT) const { |
| 1300 | return isTypeLegal(ValVT) && |
| 1301 | (getTruncStoreAction(ValVT, MemVT) == Legal || |
| 1302 | getTruncStoreAction(ValVT, MemVT) == Custom); |
| 1303 | } |
| 1304 | |
| 1305 | virtual bool canCombineTruncStore(EVT ValVT, EVT MemVT, |
| 1306 | bool LegalOnly) const { |
| 1307 | if (LegalOnly) |
| 1308 | return isTruncStoreLegal(ValVT, MemVT); |
| 1309 | |
| 1310 | return isTruncStoreLegalOrCustom(ValVT, MemVT); |
| 1311 | } |
| 1312 | |
| 1313 | /// Return how the indexed load should be treated: either it is legal, needs |
| 1314 | /// to be promoted to a larger size, needs to be expanded to some other code |
| 1315 | /// sequence, or the target has a custom expander for it. |
| 1316 | LegalizeAction getIndexedLoadAction(unsigned IdxMode, MVT VT) const { |
| 1317 | return getIndexedModeAction(IdxMode, VT, IMAB_Load); |
| 1318 | } |
| 1319 | |
| 1320 | /// Return true if the specified indexed load is legal on this target. |
| 1321 | bool isIndexedLoadLegal(unsigned IdxMode, EVT VT) const { |
| 1322 | return VT.isSimple() && |
| 1323 | (getIndexedLoadAction(IdxMode, VT.getSimpleVT()) == Legal || |
| 1324 | getIndexedLoadAction(IdxMode, VT.getSimpleVT()) == Custom); |
| 1325 | } |
| 1326 | |
| 1327 | /// Return how the indexed store should be treated: either it is legal, needs |
| 1328 | /// to be promoted to a larger size, needs to be expanded to some other code |
| 1329 | /// sequence, or the target has a custom expander for it. |
| 1330 | LegalizeAction getIndexedStoreAction(unsigned IdxMode, MVT VT) const { |
| 1331 | return getIndexedModeAction(IdxMode, VT, IMAB_Store); |
| 1332 | } |
| 1333 | |
| 1334 | /// Return true if the specified indexed load is legal on this target. |
| 1335 | bool isIndexedStoreLegal(unsigned IdxMode, EVT VT) const { |
| 1336 | return VT.isSimple() && |
| 1337 | (getIndexedStoreAction(IdxMode, VT.getSimpleVT()) == Legal || |
| 1338 | getIndexedStoreAction(IdxMode, VT.getSimpleVT()) == Custom); |
| 1339 | } |
| 1340 | |
| 1341 | /// Return how the indexed load should be treated: either it is legal, needs |
| 1342 | /// to be promoted to a larger size, needs to be expanded to some other code |
| 1343 | /// sequence, or the target has a custom expander for it. |
| 1344 | LegalizeAction getIndexedMaskedLoadAction(unsigned IdxMode, MVT VT) const { |
| 1345 | return getIndexedModeAction(IdxMode, VT, IMAB_MaskedLoad); |
| 1346 | } |
| 1347 | |
| 1348 | /// Return true if the specified indexed load is legal on this target. |
| 1349 | bool isIndexedMaskedLoadLegal(unsigned IdxMode, EVT VT) const { |
| 1350 | return VT.isSimple() && |
| 1351 | (getIndexedMaskedLoadAction(IdxMode, VT.getSimpleVT()) == Legal || |
| 1352 | getIndexedMaskedLoadAction(IdxMode, VT.getSimpleVT()) == Custom); |
| 1353 | } |
| 1354 | |
| 1355 | /// Return how the indexed store should be treated: either it is legal, needs |
| 1356 | /// to be promoted to a larger size, needs to be expanded to some other code |
| 1357 | /// sequence, or the target has a custom expander for it. |
| 1358 | LegalizeAction getIndexedMaskedStoreAction(unsigned IdxMode, MVT VT) const { |
| 1359 | return getIndexedModeAction(IdxMode, VT, IMAB_MaskedStore); |
| 1360 | } |
| 1361 | |
| 1362 | /// Return true if the specified indexed load is legal on this target. |
| 1363 | bool isIndexedMaskedStoreLegal(unsigned IdxMode, EVT VT) const { |
| 1364 | return VT.isSimple() && |
| 1365 | (getIndexedMaskedStoreAction(IdxMode, VT.getSimpleVT()) == Legal || |
| 1366 | getIndexedMaskedStoreAction(IdxMode, VT.getSimpleVT()) == Custom); |
| 1367 | } |
| 1368 | |
| 1369 | /// Returns true if the index type for a masked gather/scatter requires |
| 1370 | /// extending |
| 1371 | virtual bool shouldExtendGSIndex(EVT VT, EVT &EltTy) const { return false; } |
| 1372 | |
| 1373 | // Returns true if VT is a legal index type for masked gathers/scatters |
| 1374 | // on this target |
| 1375 | virtual bool shouldRemoveExtendFromGSIndex(EVT VT) const { return false; } |
| 1376 | |
| 1377 | /// Return how the condition code should be treated: either it is legal, needs |
| 1378 | /// to be expanded to some other code sequence, or the target has a custom |
| 1379 | /// expander for it. |
| 1380 | LegalizeAction |
| 1381 | getCondCodeAction(ISD::CondCode CC, MVT VT) const { |
| 1382 | assert((unsigned)CC < array_lengthof(CondCodeActions) && |
| 1383 | ((unsigned)VT.SimpleTy >> 3) < array_lengthof(CondCodeActions[0]) && |
| 1384 | "Table isn't big enough!"); |
| 1385 | // See setCondCodeAction for how this is encoded. |
| 1386 | uint32_t Shift = 4 * (VT.SimpleTy & 0x7); |
| 1387 | uint32_t Value = CondCodeActions[CC][VT.SimpleTy >> 3]; |
| 1388 | LegalizeAction Action = (LegalizeAction) ((Value >> Shift) & 0xF); |
| 1389 | assert(Action != Promote && "Can't promote condition code!"); |
| 1390 | return Action; |
| 1391 | } |
| 1392 | |
| 1393 | /// Return true if the specified condition code is legal on this target. |
| 1394 | bool isCondCodeLegal(ISD::CondCode CC, MVT VT) const { |
| 1395 | return getCondCodeAction(CC, VT) == Legal; |
| 1396 | } |
| 1397 | |
| 1398 | /// Return true if the specified condition code is legal or custom on this |
| 1399 | /// target. |
| 1400 | bool isCondCodeLegalOrCustom(ISD::CondCode CC, MVT VT) const { |
| 1401 | return getCondCodeAction(CC, VT) == Legal || |
| 1402 | getCondCodeAction(CC, VT) == Custom; |
| 1403 | } |
| 1404 | |
| 1405 | /// If the action for this operation is to promote, this method returns the |
| 1406 | /// ValueType to promote to. |
| 1407 | MVT getTypeToPromoteTo(unsigned Op, MVT VT) const { |
| 1408 | assert(getOperationAction(Op, VT) == Promote && |
| 1409 | "This operation isn't promoted!"); |
| 1410 | |
| 1411 | // See if this has an explicit type specified. |
| 1412 | std::map<std::pair<unsigned, MVT::SimpleValueType>, |
| 1413 | MVT::SimpleValueType>::const_iterator PTTI = |
| 1414 | PromoteToType.find(std::make_pair(Op, VT.SimpleTy)); |
| 1415 | if (PTTI != PromoteToType.end()) return PTTI->second; |
| 1416 | |
| 1417 | assert((VT.isInteger() || VT.isFloatingPoint()) && |
| 1418 | "Cannot autopromote this type, add it with AddPromotedToType."); |
| 1419 | |
| 1420 | MVT NVT = VT; |
| 1421 | do { |
| 1422 | NVT = (MVT::SimpleValueType)(NVT.SimpleTy+1); |
| 1423 | assert(NVT.isInteger() == VT.isInteger() && NVT != MVT::isVoid && |
| 1424 | "Didn't find type to promote to!"); |
| 1425 | } while (!isTypeLegal(NVT) || |
| 1426 | getOperationAction(Op, NVT) == Promote); |
| 1427 | return NVT; |
| 1428 | } |
| 1429 | |
| 1430 | virtual EVT getAsmOperandValueType(const DataLayout &DL, Type *Ty, |
| 1431 | bool AllowUnknown = false) const { |
| 1432 | return getValueType(DL, Ty, AllowUnknown); |
| 1433 | } |
| 1434 | |
| 1435 | /// Return the EVT corresponding to this LLVM type. This is fixed by the LLVM |
| 1436 | /// operations except for the pointer size. If AllowUnknown is true, this |
| 1437 | /// will return MVT::Other for types with no EVT counterpart (e.g. structs), |
| 1438 | /// otherwise it will assert. |
| 1439 | EVT getValueType(const DataLayout &DL, Type *Ty, |
| 1440 | bool AllowUnknown = false) const { |
| 1441 | // Lower scalar pointers to native pointer types. |
| 1442 | if (auto *PTy = dyn_cast<PointerType>(Ty)) |
| 1443 | return getPointerTy(DL, PTy->getAddressSpace()); |
| 1444 | |
| 1445 | if (auto *VTy = dyn_cast<VectorType>(Ty)) { |
| 1446 | Type *EltTy = VTy->getElementType(); |
| 1447 | // Lower vectors of pointers to native pointer types. |
| 1448 | if (auto *PTy = dyn_cast<PointerType>(EltTy)) { |
| 1449 | EVT PointerTy(getPointerTy(DL, PTy->getAddressSpace())); |
| 1450 | EltTy = PointerTy.getTypeForEVT(Ty->getContext()); |
| 1451 | } |
| 1452 | return EVT::getVectorVT(Ty->getContext(), EVT::getEVT(EltTy, false), |
| 1453 | VTy->getElementCount()); |
| 1454 | } |
| 1455 | |
| 1456 | return EVT::getEVT(Ty, AllowUnknown); |
| 1457 | } |
| 1458 | |
| 1459 | EVT getMemValueType(const DataLayout &DL, Type *Ty, |
| 1460 | bool AllowUnknown = false) const { |
| 1461 | // Lower scalar pointers to native pointer types. |
| 1462 | if (PointerType *PTy = dyn_cast<PointerType>(Ty)) |
| 1463 | return getPointerMemTy(DL, PTy->getAddressSpace()); |
| 1464 | else if (VectorType *VTy = dyn_cast<VectorType>(Ty)) { |
| 1465 | Type *Elm = VTy->getElementType(); |
| 1466 | if (PointerType *PT = dyn_cast<PointerType>(Elm)) { |
| 1467 | EVT PointerTy(getPointerMemTy(DL, PT->getAddressSpace())); |
| 1468 | Elm = PointerTy.getTypeForEVT(Ty->getContext()); |
| 1469 | } |
| 1470 | return EVT::getVectorVT(Ty->getContext(), EVT::getEVT(Elm, false), |
| 1471 | VTy->getElementCount()); |
| 1472 | } |
| 1473 | |
| 1474 | return getValueType(DL, Ty, AllowUnknown); |
| 1475 | } |
| 1476 | |
| 1477 | |
| 1478 | /// Return the MVT corresponding to this LLVM type. See getValueType. |
| 1479 | MVT getSimpleValueType(const DataLayout &DL, Type *Ty, |
| 1480 | bool AllowUnknown = false) const { |
| 1481 | return getValueType(DL, Ty, AllowUnknown).getSimpleVT(); |
| 1482 | } |
| 1483 | |
| 1484 | /// Return the desired alignment for ByVal or InAlloca aggregate function |
| 1485 | /// arguments in the caller parameter area. This is the actual alignment, not |
| 1486 | /// its logarithm. |
| 1487 | virtual uint64_t getByValTypeAlignment(Type *Ty, const DataLayout &DL) const; |
| 1488 | |
| 1489 | /// Return the type of registers that this ValueType will eventually require. |
| 1490 | MVT getRegisterType(MVT VT) const { |
| 1491 | assert((unsigned)VT.SimpleTy < array_lengthof(RegisterTypeForVT)); |
| 1492 | return RegisterTypeForVT[VT.SimpleTy]; |
| 1493 | } |
| 1494 | |
| 1495 | /// Return the type of registers that this ValueType will eventually require. |
| 1496 | MVT getRegisterType(LLVMContext &Context, EVT VT) const { |
| 1497 | if (VT.isSimple()) { |
| 1498 | assert((unsigned)VT.getSimpleVT().SimpleTy < |
| 1499 | array_lengthof(RegisterTypeForVT)); |
| 1500 | return RegisterTypeForVT[VT.getSimpleVT().SimpleTy]; |
| 1501 | } |
| 1502 | if (VT.isVector()) { |
| 1503 | EVT VT1; |
| 1504 | MVT RegisterVT; |
| 1505 | unsigned NumIntermediates; |
| 1506 | (void)getVectorTypeBreakdown(Context, VT, VT1, |
| 1507 | NumIntermediates, RegisterVT); |
| 1508 | return RegisterVT; |
| 1509 | } |
| 1510 | if (VT.isInteger()) { |
| 1511 | return getRegisterType(Context, getTypeToTransformTo(Context, VT)); |
| 1512 | } |
| 1513 | llvm_unreachable("Unsupported extended type!"); |
| 1514 | } |
| 1515 | |
| 1516 | /// Return the number of registers that this ValueType will eventually |
| 1517 | /// require. |
| 1518 | /// |
| 1519 | /// This is one for any types promoted to live in larger registers, but may be |
| 1520 | /// more than one for types (like i64) that are split into pieces. For types |
| 1521 | /// like i140, which are first promoted then expanded, it is the number of |
| 1522 | /// registers needed to hold all the bits of the original type. For an i140 |
| 1523 | /// on a 32 bit machine this means 5 registers. |
| 1524 | /// |
| 1525 | /// RegisterVT may be passed as a way to override the default settings, for |
| 1526 | /// instance with i128 inline assembly operands on SystemZ. |
| 1527 | virtual unsigned |
| 1528 | getNumRegisters(LLVMContext &Context, EVT VT, |
| 1529 | Optional<MVT> RegisterVT = None) const { |
| 1530 | if (VT.isSimple()) { |
| 1531 | assert((unsigned)VT.getSimpleVT().SimpleTy < |
| 1532 | array_lengthof(NumRegistersForVT)); |
| 1533 | return NumRegistersForVT[VT.getSimpleVT().SimpleTy]; |
| 1534 | } |
| 1535 | if (VT.isVector()) { |
| 1536 | EVT VT1; |
| 1537 | MVT VT2; |
| 1538 | unsigned NumIntermediates; |
| 1539 | return getVectorTypeBreakdown(Context, VT, VT1, NumIntermediates, VT2); |
| 1540 | } |
| 1541 | if (VT.isInteger()) { |
| 1542 | unsigned BitWidth = VT.getSizeInBits(); |
| 1543 | unsigned RegWidth = getRegisterType(Context, VT).getSizeInBits(); |
| 1544 | return (BitWidth + RegWidth - 1) / RegWidth; |
| 1545 | } |
| 1546 | llvm_unreachable("Unsupported extended type!"); |
| 1547 | } |
| 1548 | |
| 1549 | /// Certain combinations of ABIs, Targets and features require that types |
| 1550 | /// are legal for some operations and not for other operations. |
| 1551 | /// For MIPS all vector types must be passed through the integer register set. |
| 1552 | virtual MVT getRegisterTypeForCallingConv(LLVMContext &Context, |
| 1553 | CallingConv::ID CC, EVT VT) const { |
| 1554 | return getRegisterType(Context, VT); |
| 1555 | } |
| 1556 | |
| 1557 | /// Certain targets require unusual breakdowns of certain types. For MIPS, |
| 1558 | /// this occurs when a vector type is used, as vector are passed through the |
| 1559 | /// integer register set. |
| 1560 | virtual unsigned getNumRegistersForCallingConv(LLVMContext &Context, |
| 1561 | CallingConv::ID CC, |
| 1562 | EVT VT) const { |
| 1563 | return getNumRegisters(Context, VT); |
| 1564 | } |
| 1565 | |
| 1566 | /// Certain targets have context sensitive alignment requirements, where one |
| 1567 | /// type has the alignment requirement of another type. |
| 1568 | virtual Align getABIAlignmentForCallingConv(Type *ArgTy, |
| 1569 | const DataLayout &DL) const { |
| 1570 | return DL.getABITypeAlign(ArgTy); |
| 1571 | } |
| 1572 | |
| 1573 | /// If true, then instruction selection should seek to shrink the FP constant |
| 1574 | /// of the specified type to a smaller type in order to save space and / or |
| 1575 | /// reduce runtime. |
| 1576 | virtual bool ShouldShrinkFPConstant(EVT) const { return true; } |
| 1577 | |
| 1578 | /// Return true if it is profitable to reduce a load to a smaller type. |
| 1579 | /// Example: (i16 (trunc (i32 (load x))) -> i16 load x |
| 1580 | virtual bool shouldReduceLoadWidth(SDNode *Load, ISD::LoadExtType ExtTy, |
| 1581 | EVT NewVT) const { |
| 1582 | // By default, assume that it is cheaper to extract a subvector from a wide |
| 1583 | // vector load rather than creating multiple narrow vector loads. |
| 1584 | if (NewVT.isVector() && !Load->hasOneUse()) |
| 1585 | return false; |
| 1586 | |
| 1587 | return true; |
| 1588 | } |
| 1589 | |
| 1590 | /// When splitting a value of the specified type into parts, does the Lo |
| 1591 | /// or Hi part come first? This usually follows the endianness, except |
| 1592 | /// for ppcf128, where the Hi part always comes first. |
| 1593 | bool hasBigEndianPartOrdering(EVT VT, const DataLayout &DL) const { |
| 1594 | return DL.isBigEndian() || VT == MVT::ppcf128; |
| 1595 | } |
| 1596 | |
| 1597 | /// If true, the target has custom DAG combine transformations that it can |
| 1598 | /// perform for the specified node. |
| 1599 | bool hasTargetDAGCombine(ISD::NodeType NT) const { |
| 1600 | assert(unsigned(NT >> 3) < array_lengthof(TargetDAGCombineArray)); |
| 1601 | return TargetDAGCombineArray[NT >> 3] & (1 << (NT&7)); |
| 1602 | } |
| 1603 | |
| 1604 | unsigned getGatherAllAliasesMaxDepth() const { |
| 1605 | return GatherAllAliasesMaxDepth; |
| 1606 | } |
| 1607 | |
| 1608 | /// Returns the size of the platform's va_list object. |
| 1609 | virtual unsigned getVaListSizeInBits(const DataLayout &DL) const { |
| 1610 | return getPointerTy(DL).getSizeInBits(); |
| 1611 | } |
| 1612 | |
| 1613 | /// Get maximum # of store operations permitted for llvm.memset |
| 1614 | /// |
| 1615 | /// This function returns the maximum number of store operations permitted |
| 1616 | /// to replace a call to llvm.memset. The value is set by the target at the |
| 1617 | /// performance threshold for such a replacement. If OptSize is true, |
| 1618 | /// return the limit for functions that have OptSize attribute. |
| 1619 | unsigned getMaxStoresPerMemset(bool OptSize) const { |
| 1620 | return OptSize ? MaxStoresPerMemsetOptSize : MaxStoresPerMemset; |
| 1621 | } |
| 1622 | |
| 1623 | /// Get maximum # of store operations permitted for llvm.memcpy |
| 1624 | /// |
| 1625 | /// This function returns the maximum number of store operations permitted |
| 1626 | /// to replace a call to llvm.memcpy. The value is set by the target at the |
| 1627 | /// performance threshold for such a replacement. If OptSize is true, |
| 1628 | /// return the limit for functions that have OptSize attribute. |
| 1629 | unsigned getMaxStoresPerMemcpy(bool OptSize) const { |
| 1630 | return OptSize ? MaxStoresPerMemcpyOptSize : MaxStoresPerMemcpy; |
| 1631 | } |
| 1632 | |
| 1633 | /// \brief Get maximum # of store operations to be glued together |
| 1634 | /// |
| 1635 | /// This function returns the maximum number of store operations permitted |
| 1636 | /// to glue together during lowering of llvm.memcpy. The value is set by |
| 1637 | // the target at the performance threshold for such a replacement. |
| 1638 | virtual unsigned getMaxGluedStoresPerMemcpy() const { |
| 1639 | return MaxGluedStoresPerMemcpy; |
| 1640 | } |
| 1641 | |
| 1642 | /// Get maximum # of load operations permitted for memcmp |
| 1643 | /// |
| 1644 | /// This function returns the maximum number of load operations permitted |
| 1645 | /// to replace a call to memcmp. The value is set by the target at the |
| 1646 | /// performance threshold for such a replacement. If OptSize is true, |
| 1647 | /// return the limit for functions that have OptSize attribute. |
| 1648 | unsigned getMaxExpandSizeMemcmp(bool OptSize) const { |
| 1649 | return OptSize ? MaxLoadsPerMemcmpOptSize : MaxLoadsPerMemcmp; |
| 1650 | } |
| 1651 | |
| 1652 | /// Get maximum # of store operations permitted for llvm.memmove |
| 1653 | /// |
| 1654 | /// This function returns the maximum number of store operations permitted |
| 1655 | /// to replace a call to llvm.memmove. The value is set by the target at the |
| 1656 | /// performance threshold for such a replacement. If OptSize is true, |
| 1657 | /// return the limit for functions that have OptSize attribute. |
| 1658 | unsigned getMaxStoresPerMemmove(bool OptSize) const { |
| 1659 | return OptSize ? MaxStoresPerMemmoveOptSize : MaxStoresPerMemmove; |
| 1660 | } |
| 1661 | |
| 1662 | /// Determine if the target supports unaligned memory accesses. |
| 1663 | /// |
| 1664 | /// This function returns true if the target allows unaligned memory accesses |
| 1665 | /// of the specified type in the given address space. If true, it also returns |
| 1666 | /// whether the unaligned memory access is "fast" in the last argument by |
| 1667 | /// reference. This is used, for example, in situations where an array |
| 1668 | /// copy/move/set is converted to a sequence of store operations. Its use |
| 1669 | /// helps to ensure that such replacements don't generate code that causes an |
| 1670 | /// alignment error (trap) on the target machine. |
| 1671 | virtual bool allowsMisalignedMemoryAccesses( |
| 1672 | EVT, unsigned AddrSpace = 0, Align Alignment = Align(1), |
| 1673 | MachineMemOperand::Flags Flags = MachineMemOperand::MONone, |
| 1674 | bool * /*Fast*/ = nullptr) const { |
| 1675 | return false; |
| 1676 | } |
| 1677 | |
| 1678 | /// LLT handling variant. |
| 1679 | virtual bool allowsMisalignedMemoryAccesses( |
| 1680 | LLT, unsigned AddrSpace = 0, Align Alignment = Align(1), |
| 1681 | MachineMemOperand::Flags Flags = MachineMemOperand::MONone, |
| 1682 | bool * /*Fast*/ = nullptr) const { |
| 1683 | return false; |
| 1684 | } |
| 1685 | |
| 1686 | /// This function returns true if the memory access is aligned or if the |
| 1687 | /// target allows this specific unaligned memory access. If the access is |
| 1688 | /// allowed, the optional final parameter returns if the access is also fast |
| 1689 | /// (as defined by the target). |
| 1690 | bool allowsMemoryAccessForAlignment( |
| 1691 | LLVMContext &Context, const DataLayout &DL, EVT VT, |
| 1692 | unsigned AddrSpace = 0, Align Alignment = Align(1), |
| 1693 | MachineMemOperand::Flags Flags = MachineMemOperand::MONone, |
| 1694 | bool *Fast = nullptr) const; |
| 1695 | |
| 1696 | /// Return true if the memory access of this type is aligned or if the target |
| 1697 | /// allows this specific unaligned access for the given MachineMemOperand. |
| 1698 | /// If the access is allowed, the optional final parameter returns if the |
| 1699 | /// access is also fast (as defined by the target). |
| 1700 | bool allowsMemoryAccessForAlignment(LLVMContext &Context, |
| 1701 | const DataLayout &DL, EVT VT, |
| 1702 | const MachineMemOperand &MMO, |
| 1703 | bool *Fast = nullptr) const; |
| 1704 | |
| 1705 | /// Return true if the target supports a memory access of this type for the |
| 1706 | /// given address space and alignment. If the access is allowed, the optional |
| 1707 | /// final parameter returns if the access is also fast (as defined by the |
| 1708 | /// target). |
| 1709 | virtual bool |
| 1710 | allowsMemoryAccess(LLVMContext &Context, const DataLayout &DL, EVT VT, |
| 1711 | unsigned AddrSpace = 0, Align Alignment = Align(1), |
| 1712 | MachineMemOperand::Flags Flags = MachineMemOperand::MONone, |
| 1713 | bool *Fast = nullptr) const; |
| 1714 | |
| 1715 | /// Return true if the target supports a memory access of this type for the |
| 1716 | /// given MachineMemOperand. If the access is allowed, the optional |
| 1717 | /// final parameter returns if the access is also fast (as defined by the |
| 1718 | /// target). |
| 1719 | bool allowsMemoryAccess(LLVMContext &Context, const DataLayout &DL, EVT VT, |
| 1720 | const MachineMemOperand &MMO, |
| 1721 | bool *Fast = nullptr) const; |
| 1722 | |
| 1723 | /// LLT handling variant. |
| 1724 | bool allowsMemoryAccess(LLVMContext &Context, const DataLayout &DL, LLT Ty, |
| 1725 | const MachineMemOperand &MMO, |
| 1726 | bool *Fast = nullptr) const; |
| 1727 | |
| 1728 | /// Returns the target specific optimal type for load and store operations as |
| 1729 | /// a result of memset, memcpy, and memmove lowering. |
| 1730 | /// It returns EVT::Other if the type should be determined using generic |
| 1731 | /// target-independent logic. |
| 1732 | virtual EVT |
| 1733 | getOptimalMemOpType(const MemOp &Op, |
| 1734 | const AttributeList & /*FuncAttributes*/) const { |
| 1735 | return MVT::Other; |
| 1736 | } |
| 1737 | |
| 1738 | /// LLT returning variant. |
| 1739 | virtual LLT |
| 1740 | getOptimalMemOpLLT(const MemOp &Op, |
| 1741 | const AttributeList & /*FuncAttributes*/) const { |
| 1742 | return LLT(); |
| 1743 | } |
| 1744 | |
| 1745 | /// Returns true if it's safe to use load / store of the specified type to |
| 1746 | /// expand memcpy / memset inline. |
| 1747 | /// |
| 1748 | /// This is mostly true for all types except for some special cases. For |
| 1749 | /// example, on X86 targets without SSE2 f64 load / store are done with fldl / |
| 1750 | /// fstpl which also does type conversion. Note the specified type doesn't |
| 1751 | /// have to be legal as the hook is used before type legalization. |
| 1752 | virtual bool isSafeMemOpType(MVT /*VT*/) const { return true; } |
| 1753 | |
| 1754 | /// Return lower limit for number of blocks in a jump table. |
| 1755 | virtual unsigned getMinimumJumpTableEntries() const; |
| 1756 | |
| 1757 | /// Return lower limit of the density in a jump table. |
| 1758 | unsigned getMinimumJumpTableDensity(bool OptForSize) const; |
| 1759 | |
| 1760 | /// Return upper limit for number of entries in a jump table. |
| 1761 | /// Zero if no limit. |
| 1762 | unsigned getMaximumJumpTableSize() const; |
| 1763 | |
| 1764 | virtual bool isJumpTableRelative() const; |
| 1765 | |
| 1766 | /// If a physical register, this specifies the register that |
| 1767 | /// llvm.savestack/llvm.restorestack should save and restore. |
| 1768 | Register getStackPointerRegisterToSaveRestore() const { |
| 1769 | return StackPointerRegisterToSaveRestore; |
| 1770 | } |
| 1771 | |
| 1772 | /// If a physical register, this returns the register that receives the |
| 1773 | /// exception address on entry to an EH pad. |
| 1774 | virtual Register |
| 1775 | getExceptionPointerRegister(const Constant *PersonalityFn) const { |
| 1776 | return Register(); |
| 1777 | } |
| 1778 | |
| 1779 | /// If a physical register, this returns the register that receives the |
| 1780 | /// exception typeid on entry to a landing pad. |
| 1781 | virtual Register |
| 1782 | getExceptionSelectorRegister(const Constant *PersonalityFn) const { |
| 1783 | return Register(); |
| 1784 | } |
| 1785 | |
| 1786 | virtual bool needsFixedCatchObjects() const { |
| 1787 | report_fatal_error("Funclet EH is not implemented for this target"); |
| 1788 | } |
| 1789 | |
| 1790 | /// Return the minimum stack alignment of an argument. |
| 1791 | Align getMinStackArgumentAlignment() const { |
| 1792 | return MinStackArgumentAlignment; |
| 1793 | } |
| 1794 | |
| 1795 | /// Return the minimum function alignment. |
| 1796 | Align getMinFunctionAlignment() const { return MinFunctionAlignment; } |
| 1797 | |
| 1798 | /// Return the preferred function alignment. |
| 1799 | Align getPrefFunctionAlignment() const { return PrefFunctionAlignment; } |
| 1800 | |
| 1801 | /// Return the preferred loop alignment. |
| 1802 | virtual Align getPrefLoopAlignment(MachineLoop *ML = nullptr) const; |
| 1803 | |
| 1804 | /// Return the maximum amount of bytes allowed to be emitted when padding for |
| 1805 | /// alignment |
| 1806 | virtual unsigned |
| 1807 | getMaxPermittedBytesForAlignment(MachineBasicBlock *MBB) const; |
| 1808 | |
| 1809 | /// Should loops be aligned even when the function is marked OptSize (but not |
| 1810 | /// MinSize). |
| 1811 | virtual bool alignLoopsWithOptSize() const { return false; } |
| 1812 | |
| 1813 | /// If the target has a standard location for the stack protector guard, |
| 1814 | /// returns the address of that location. Otherwise, returns nullptr. |
| 1815 | /// DEPRECATED: please override useLoadStackGuardNode and customize |
| 1816 | /// LOAD_STACK_GUARD, or customize \@llvm.stackguard(). |
| 1817 | virtual Value *getIRStackGuard(IRBuilderBase &IRB) const; |
| 1818 | |
| 1819 | /// Inserts necessary declarations for SSP (stack protection) purpose. |
| 1820 | /// Should be used only when getIRStackGuard returns nullptr. |
| 1821 | virtual void insertSSPDeclarations(Module &M) const; |
| 1822 | |
| 1823 | /// Return the variable that's previously inserted by insertSSPDeclarations, |
| 1824 | /// if any, otherwise return nullptr. Should be used only when |
| 1825 | /// getIRStackGuard returns nullptr. |
| 1826 | virtual Value *getSDagStackGuard(const Module &M) const; |
| 1827 | |
| 1828 | /// If this function returns true, stack protection checks should XOR the |
| 1829 | /// frame pointer (or whichever pointer is used to address locals) into the |
| 1830 | /// stack guard value before checking it. getIRStackGuard must return nullptr |
| 1831 | /// if this returns true. |
| 1832 | virtual bool useStackGuardXorFP() const { return false; } |
| 1833 | |
| 1834 | /// If the target has a standard stack protection check function that |
| 1835 | /// performs validation and error handling, returns the function. Otherwise, |
| 1836 | /// returns nullptr. Must be previously inserted by insertSSPDeclarations. |
| 1837 | /// Should be used only when getIRStackGuard returns nullptr. |
| 1838 | virtual Function *getSSPStackGuardCheck(const Module &M) const; |
| 1839 | |
| 1840 | /// \returns true if a constant G_UBFX is legal on the target. |
| 1841 | virtual bool isConstantUnsignedBitfieldExtractLegal(unsigned Opc, LLT Ty1, |
| 1842 | LLT Ty2) const { |
| 1843 | return false; |
| 1844 | } |
| 1845 | |
| 1846 | protected: |
| 1847 | Value *getDefaultSafeStackPointerLocation(IRBuilderBase &IRB, |
| 1848 | bool UseTLS) const; |
| 1849 | |
| 1850 | public: |
| 1851 | /// Returns the target-specific address of the unsafe stack pointer. |
| 1852 | virtual Value *getSafeStackPointerLocation(IRBuilderBase &IRB) const; |
| 1853 | |
| 1854 | /// Returns the name of the symbol used to emit stack probes or the empty |
| 1855 | /// string if not applicable. |
| 1856 | virtual bool hasStackProbeSymbol(MachineFunction &MF) const { return false; } |
| 1857 | |
| 1858 | virtual bool hasInlineStackProbe(MachineFunction &MF) const { return false; } |
| 1859 | |
| 1860 | virtual StringRef getStackProbeSymbolName(MachineFunction &MF) const { |
| 1861 | return ""; |
| 1862 | } |
| 1863 | |
| 1864 | /// Returns true if a cast from SrcAS to DestAS is "cheap", such that e.g. we |
| 1865 | /// are happy to sink it into basic blocks. A cast may be free, but not |
| 1866 | /// necessarily a no-op. e.g. a free truncate from a 64-bit to 32-bit pointer. |
| 1867 | virtual bool isFreeAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const; |
| 1868 | |
| 1869 | /// Return true if the pointer arguments to CI should be aligned by aligning |
| 1870 | /// the object whose address is being passed. If so then MinSize is set to the |
| 1871 | /// minimum size the object must be to be aligned and PrefAlign is set to the |
| 1872 | /// preferred alignment. |
| 1873 | virtual bool shouldAlignPointerArgs(CallInst * /*CI*/, unsigned & /*MinSize*/, |
| 1874 | unsigned & /*PrefAlign*/) const { |
| 1875 | return false; |
| 1876 | } |
| 1877 | |
| 1878 | //===--------------------------------------------------------------------===// |
| 1879 | /// \name Helpers for TargetTransformInfo implementations |
| 1880 | /// @{ |
| 1881 | |
| 1882 | /// Get the ISD node that corresponds to the Instruction class opcode. |
| 1883 | int InstructionOpcodeToISD(unsigned Opcode) const; |
| 1884 | |
| 1885 | /// Estimate the cost of type-legalization and the legalized type. |
| 1886 | std::pair<InstructionCost, MVT> getTypeLegalizationCost(const DataLayout &DL, |
| 1887 | Type *Ty) const; |
| 1888 | |
| 1889 | /// @} |
| 1890 | |
| 1891 | //===--------------------------------------------------------------------===// |
| 1892 | /// \name Helpers for atomic expansion. |
| 1893 | /// @{ |
| 1894 | |
| 1895 | /// Returns the maximum atomic operation size (in bits) supported by |
| 1896 | /// the backend. Atomic operations greater than this size (as well |
| 1897 | /// as ones that are not naturally aligned), will be expanded by |
| 1898 | /// AtomicExpandPass into an __atomic_* library call. |
| 1899 | unsigned getMaxAtomicSizeInBitsSupported() const { |
| 1900 | return MaxAtomicSizeInBitsSupported; |
| 1901 | } |
| 1902 | |
| 1903 | /// Returns the size of the smallest cmpxchg or ll/sc instruction |
| 1904 | /// the backend supports. Any smaller operations are widened in |
| 1905 | /// AtomicExpandPass. |
| 1906 | /// |
| 1907 | /// Note that *unlike* operations above the maximum size, atomic ops |
| 1908 | /// are still natively supported below the minimum; they just |
| 1909 | /// require a more complex expansion. |
| 1910 | unsigned getMinCmpXchgSizeInBits() const { return MinCmpXchgSizeInBits; } |
| 1911 | |
| 1912 | /// Whether the target supports unaligned atomic operations. |
| 1913 | bool supportsUnalignedAtomics() const { return SupportsUnalignedAtomics; } |
| 1914 | |
| 1915 | /// Whether AtomicExpandPass should automatically insert fences and reduce |
| 1916 | /// ordering for this atomic. This should be true for most architectures with |
| 1917 | /// weak memory ordering. Defaults to false. |
| 1918 | virtual bool shouldInsertFencesForAtomic(const Instruction *I) const { |
| 1919 | return false; |
| 1920 | } |
| 1921 | |
| 1922 | /// Perform a load-linked operation on Addr, returning a "Value *" with the |
| 1923 | /// corresponding pointee type. This may entail some non-trivial operations to |
| 1924 | /// truncate or reconstruct types that will be illegal in the backend. See |
| 1925 | /// ARMISelLowering for an example implementation. |
| 1926 | virtual Value *emitLoadLinked(IRBuilderBase &Builder, Type *ValueTy, |
| 1927 | Value *Addr, AtomicOrdering Ord) const { |
| 1928 | llvm_unreachable("Load linked unimplemented on this target"); |
| 1929 | } |
| 1930 | |
| 1931 | /// Perform a store-conditional operation to Addr. Return the status of the |
| 1932 | /// store. This should be 0 if the store succeeded, non-zero otherwise. |
| 1933 | virtual Value *emitStoreConditional(IRBuilderBase &Builder, Value *Val, |
| 1934 | Value *Addr, AtomicOrdering Ord) const { |
| 1935 | llvm_unreachable("Store conditional unimplemented on this target"); |
| 1936 | } |
| 1937 | |
| 1938 | /// Perform a masked atomicrmw using a target-specific intrinsic. This |
| 1939 | /// represents the core LL/SC loop which will be lowered at a late stage by |
| 1940 | /// the backend. |
| 1941 | virtual Value *emitMaskedAtomicRMWIntrinsic(IRBuilderBase &Builder, |
| 1942 | AtomicRMWInst *AI, |
| 1943 | Value *AlignedAddr, Value *Incr, |
| 1944 | Value *Mask, Value *ShiftAmt, |
| 1945 | AtomicOrdering Ord) const { |
| 1946 | llvm_unreachable("Masked atomicrmw expansion unimplemented on this target"); |
| 1947 | } |
| 1948 | |
| 1949 | /// Perform a masked cmpxchg using a target-specific intrinsic. This |
| 1950 | /// represents the core LL/SC loop which will be lowered at a late stage by |
| 1951 | /// the backend. |
| 1952 | virtual Value *emitMaskedAtomicCmpXchgIntrinsic( |
| 1953 | IRBuilderBase &Builder, AtomicCmpXchgInst *CI, Value *AlignedAddr, |
| 1954 | Value *CmpVal, Value *NewVal, Value *Mask, AtomicOrdering Ord) const { |
| 1955 | llvm_unreachable("Masked cmpxchg expansion unimplemented on this target"); |
| 1956 | } |
| 1957 | |
| 1958 | /// Inserts in the IR a target-specific intrinsic specifying a fence. |
| 1959 | /// It is called by AtomicExpandPass before expanding an |
| 1960 | /// AtomicRMW/AtomicCmpXchg/AtomicStore/AtomicLoad |
| 1961 | /// if shouldInsertFencesForAtomic returns true. |
| 1962 | /// |
| 1963 | /// Inst is the original atomic instruction, prior to other expansions that |
| 1964 | /// may be performed. |
| 1965 | /// |
| 1966 | /// This function should either return a nullptr, or a pointer to an IR-level |
| 1967 | /// Instruction*. Even complex fence sequences can be represented by a |
| 1968 | /// single Instruction* through an intrinsic to be lowered later. |
| 1969 | /// Backends should override this method to produce target-specific intrinsic |
| 1970 | /// for their fences. |
| 1971 | /// FIXME: Please note that the default implementation here in terms of |
| 1972 | /// IR-level fences exists for historical/compatibility reasons and is |
| 1973 | /// *unsound* ! Fences cannot, in general, be used to restore sequential |
| 1974 | /// consistency. For example, consider the following example: |
| 1975 | /// atomic<int> x = y = 0; |
| 1976 | /// int r1, r2, r3, r4; |
| 1977 | /// Thread 0: |
| 1978 | /// x.store(1); |
| 1979 | /// Thread 1: |
| 1980 | /// y.store(1); |
| 1981 | /// Thread 2: |
| 1982 | /// r1 = x.load(); |
| 1983 | /// r2 = y.load(); |
| 1984 | /// Thread 3: |
| 1985 | /// r3 = y.load(); |
| 1986 | /// r4 = x.load(); |
| 1987 | /// r1 = r3 = 1 and r2 = r4 = 0 is impossible as long as the accesses are all |
| 1988 | /// seq_cst. But if they are lowered to monotonic accesses, no amount of |
| 1989 | /// IR-level fences can prevent it. |
| 1990 | /// @{ |
| 1991 | virtual Instruction *emitLeadingFence(IRBuilderBase &Builder, |
| 1992 | Instruction *Inst, |
| 1993 | AtomicOrdering Ord) const; |
| 1994 | |
| 1995 | virtual Instruction *emitTrailingFence(IRBuilderBase &Builder, |
| 1996 | Instruction *Inst, |
| 1997 | AtomicOrdering Ord) const; |
| 1998 | /// @} |
| 1999 | |
| 2000 | // Emits code that executes when the comparison result in the ll/sc |
| 2001 | // expansion of a cmpxchg instruction is such that the store-conditional will |
| 2002 | // not execute. This makes it possible to balance out the load-linked with |
| 2003 | // a dedicated instruction, if desired. |
| 2004 | // E.g., on ARM, if ldrex isn't followed by strex, the exclusive monitor would |
| 2005 | // be unnecessarily held, except if clrex, inserted by this hook, is executed. |
| 2006 | virtual void emitAtomicCmpXchgNoStoreLLBalance(IRBuilderBase &Builder) const {} |
| 2007 | |
| 2008 | /// Returns true if the given (atomic) store should be expanded by the |
| 2009 | /// IR-level AtomicExpand pass into an "atomic xchg" which ignores its input. |
| 2010 | virtual bool shouldExpandAtomicStoreInIR(StoreInst *SI) const { |
| 2011 | return false; |
| 2012 | } |
| 2013 | |
| 2014 | /// Returns true if arguments should be sign-extended in lib calls. |
| 2015 | virtual bool shouldSignExtendTypeInLibCall(EVT Type, bool IsSigned) const { |
| 2016 | return IsSigned; |
| 2017 | } |
| 2018 | |
| 2019 | /// Returns true if arguments should be extended in lib calls. |
| 2020 | virtual bool shouldExtendTypeInLibCall(EVT Type) const { |
| 2021 | return true; |
| 2022 | } |
| 2023 | |
| 2024 | /// Returns how the given (atomic) load should be expanded by the |
| 2025 | /// IR-level AtomicExpand pass. |
| 2026 | virtual AtomicExpansionKind shouldExpandAtomicLoadInIR(LoadInst *LI) const { |
| 2027 | return AtomicExpansionKind::None; |
| 2028 | } |
| 2029 | |
| 2030 | /// Returns how the given atomic cmpxchg should be expanded by the IR-level |
| 2031 | /// AtomicExpand pass. |
| 2032 | virtual AtomicExpansionKind |
| 2033 | shouldExpandAtomicCmpXchgInIR(AtomicCmpXchgInst *AI) const { |
| 2034 | return AtomicExpansionKind::None; |
| 2035 | } |
| 2036 | |
| 2037 | /// Returns how the IR-level AtomicExpand pass should expand the given |
| 2038 | /// AtomicRMW, if at all. Default is to never expand. |
| 2039 | virtual AtomicExpansionKind shouldExpandAtomicRMWInIR(AtomicRMWInst *RMW) const { |
| 2040 | return RMW->isFloatingPointOperation() ? |
| 2041 | AtomicExpansionKind::CmpXChg : AtomicExpansionKind::None; |
| 2042 | } |
| 2043 | |
| 2044 | /// On some platforms, an AtomicRMW that never actually modifies the value |
| 2045 | /// (such as fetch_add of 0) can be turned into a fence followed by an |
| 2046 | /// atomic load. This may sound useless, but it makes it possible for the |
| 2047 | /// processor to keep the cacheline shared, dramatically improving |
| 2048 | /// performance. And such idempotent RMWs are useful for implementing some |
| 2049 | /// kinds of locks, see for example (justification + benchmarks): |
| 2050 | /// http://www.hpl.hp.com/techreports/2012/HPL-2012-68.pdf |
| 2051 | /// This method tries doing that transformation, returning the atomic load if |
| 2052 | /// it succeeds, and nullptr otherwise. |
| 2053 | /// If shouldExpandAtomicLoadInIR returns true on that load, it will undergo |
| 2054 | /// another round of expansion. |
| 2055 | virtual LoadInst * |
| 2056 | lowerIdempotentRMWIntoFencedLoad(AtomicRMWInst *RMWI) const { |
| 2057 | return nullptr; |
| 2058 | } |
| 2059 | |
| 2060 | /// Returns how the platform's atomic operations are extended (ZERO_EXTEND, |
| 2061 | /// SIGN_EXTEND, or ANY_EXTEND). |
| 2062 | virtual ISD::NodeType getExtendForAtomicOps() const { |
| 2063 | return ISD::ZERO_EXTEND; |
| 2064 | } |
| 2065 | |
| 2066 | /// Returns how the platform's atomic compare and swap expects its comparison |
| 2067 | /// value to be extended (ZERO_EXTEND, SIGN_EXTEND, or ANY_EXTEND). This is |
| 2068 | /// separate from getExtendForAtomicOps, which is concerned with the |
| 2069 | /// sign-extension of the instruction's output, whereas here we are concerned |
| 2070 | /// with the sign-extension of the input. For targets with compare-and-swap |
| 2071 | /// instructions (or sub-word comparisons in their LL/SC loop expansions), |
| 2072 | /// the input can be ANY_EXTEND, but the output will still have a specific |
| 2073 | /// extension. |
| 2074 | virtual ISD::NodeType getExtendForAtomicCmpSwapArg() const { |
| 2075 | return ISD::ANY_EXTEND; |
| 2076 | } |
| 2077 | |
| 2078 | /// @} |
| 2079 | |
| 2080 | /// Returns true if we should normalize |
| 2081 | /// select(N0&N1, X, Y) => select(N0, select(N1, X, Y), Y) and |
| 2082 | /// select(N0|N1, X, Y) => select(N0, select(N1, X, Y, Y)) if it is likely |
| 2083 | /// that it saves us from materializing N0 and N1 in an integer register. |
| 2084 | /// Targets that are able to perform and/or on flags should return false here. |
| 2085 | virtual bool shouldNormalizeToSelectSequence(LLVMContext &Context, |
| 2086 | EVT VT) const { |
| 2087 | // If a target has multiple condition registers, then it likely has logical |
| 2088 | // operations on those registers. |
| 2089 | if (hasMultipleConditionRegisters()) |
| 2090 | return false; |
| 2091 | // Only do the transform if the value won't be split into multiple |
| 2092 | // registers. |
| 2093 | LegalizeTypeAction Action = getTypeAction(Context, VT); |
| 2094 | return Action != TypeExpandInteger && Action != TypeExpandFloat && |
| 2095 | Action != TypeSplitVector; |
| 2096 | } |
| 2097 | |
| 2098 | virtual bool isProfitableToCombineMinNumMaxNum(EVT VT) const { return true; } |
| 2099 | |
| 2100 | /// Return true if a select of constants (select Cond, C1, C2) should be |
| 2101 | /// transformed into simple math ops with the condition value. For example: |
| 2102 | /// select Cond, C1, C1-1 --> add (zext Cond), C1-1 |
| 2103 | virtual bool convertSelectOfConstantsToMath(EVT VT) const { |
| 2104 | return false; |
| 2105 | } |
| 2106 | |
| 2107 | /// Return true if it is profitable to transform an integer |
| 2108 | /// multiplication-by-constant into simpler operations like shifts and adds. |
| 2109 | /// This may be true if the target does not directly support the |
| 2110 | /// multiplication operation for the specified type or the sequence of simpler |
| 2111 | /// ops is faster than the multiply. |
| 2112 | virtual bool decomposeMulByConstant(LLVMContext &Context, |
| 2113 | EVT VT, SDValue C) const { |
| 2114 | return false; |
| 2115 | } |
| 2116 | |
| 2117 | /// Return true if it may be profitable to transform |
| 2118 | /// (mul (add x, c1), c2) -> (add (mul x, c2), c1*c2). |
| 2119 | /// This may not be true if c1 and c2 can be represented as immediates but |
| 2120 | /// c1*c2 cannot, for example. |
| 2121 | /// The target should check if c1, c2 and c1*c2 can be represented as |
| 2122 | /// immediates, or have to be materialized into registers. If it is not sure |
| 2123 | /// about some cases, a default true can be returned to let the DAGCombiner |
| 2124 | /// decide. |
| 2125 | /// AddNode is (add x, c1), and ConstNode is c2. |
| 2126 | virtual bool isMulAddWithConstProfitable(const SDValue &AddNode, |
| 2127 | const SDValue &ConstNode) const { |
| 2128 | return true; |
| 2129 | } |
| 2130 | |
| 2131 | /// Return true if it is more correct/profitable to use strict FP_TO_INT |
| 2132 | /// conversion operations - canonicalizing the FP source value instead of |
| 2133 | /// converting all cases and then selecting based on value. |
| 2134 | /// This may be true if the target throws exceptions for out of bounds |
| 2135 | /// conversions or has fast FP CMOV. |
| 2136 | virtual bool shouldUseStrictFP_TO_INT(EVT FpVT, EVT IntVT, |
| 2137 | bool IsSigned) const { |
| 2138 | return false; |
| 2139 | } |
| 2140 | |
| 2141 | //===--------------------------------------------------------------------===// |
| 2142 | // TargetLowering Configuration Methods - These methods should be invoked by |
| 2143 | // the derived class constructor to configure this object for the target. |
| 2144 | // |
| 2145 | protected: |
| 2146 | /// Specify how the target extends the result of integer and floating point |
| 2147 | /// boolean values from i1 to a wider type. See getBooleanContents. |
| 2148 | void setBooleanContents(BooleanContent Ty) { |
| 2149 | BooleanContents = Ty; |
| 2150 | BooleanFloatContents = Ty; |
| 2151 | } |
| 2152 | |
| 2153 | /// Specify how the target extends the result of integer and floating point |
| 2154 | /// boolean values from i1 to a wider type. See getBooleanContents. |
| 2155 | void setBooleanContents(BooleanContent IntTy, BooleanContent FloatTy) { |
| 2156 | BooleanContents = IntTy; |
| 2157 | BooleanFloatContents = FloatTy; |
| 2158 | } |
| 2159 | |
| 2160 | /// Specify how the target extends the result of a vector boolean value from a |
| 2161 | /// vector of i1 to a wider type. See getBooleanContents. |
| 2162 | void setBooleanVectorContents(BooleanContent Ty) { |
| 2163 | BooleanVectorContents = Ty; |
| 2164 | } |
| 2165 | |
| 2166 | /// Specify the target scheduling preference. |
| 2167 | void setSchedulingPreference(Sched::Preference Pref) { |
| 2168 | SchedPreferenceInfo = Pref; |
| 2169 | } |
| 2170 | |
| 2171 | /// Indicate the minimum number of blocks to generate jump tables. |
| 2172 | void setMinimumJumpTableEntries(unsigned Val); |
| 2173 | |
| 2174 | /// Indicate the maximum number of entries in jump tables. |
| 2175 | /// Set to zero to generate unlimited jump tables. |
| 2176 | void setMaximumJumpTableSize(unsigned); |
| 2177 | |
| 2178 | /// If set to a physical register, this specifies the register that |
| 2179 | /// llvm.savestack/llvm.restorestack should save and restore. |
| 2180 | void setStackPointerRegisterToSaveRestore(Register R) { |
| 2181 | StackPointerRegisterToSaveRestore = R; |
| 2182 | } |
| 2183 | |
| 2184 | /// Tells the code generator that the target has multiple (allocatable) |
| 2185 | /// condition registers that can be used to store the results of comparisons |
| 2186 | /// for use by selects and conditional branches. With multiple condition |
| 2187 | /// registers, the code generator will not aggressively sink comparisons into |
| 2188 | /// the blocks of their users. |
| 2189 | void setHasMultipleConditionRegisters(bool hasManyRegs = true) { |
| 2190 | HasMultipleConditionRegisters = hasManyRegs; |
| 2191 | } |
| 2192 | |
| 2193 | /// Tells the code generator that the target has BitExtract instructions. |
| 2194 | /// The code generator will aggressively sink "shift"s into the blocks of |
| 2195 | /// their users if the users will generate "and" instructions which can be |
| 2196 | /// combined with "shift" to BitExtract instructions. |
| 2197 | void setHasExtractBitsInsn(bool hasExtractInsn = true) { |
| 2198 | HasExtractBitsInsn = hasExtractInsn; |
| 2199 | } |
| 2200 | |
| 2201 | /// Tells the code generator not to expand logic operations on comparison |
| 2202 | /// predicates into separate sequences that increase the amount of flow |
| 2203 | /// control. |
| 2204 | void setJumpIsExpensive(bool isExpensive = true); |
| 2205 | |
| 2206 | /// Tells the code generator which bitwidths to bypass. |
| 2207 | void addBypassSlowDiv(unsigned int SlowBitWidth, unsigned int FastBitWidth) { |
| 2208 | BypassSlowDivWidths[SlowBitWidth] = FastBitWidth; |
| 2209 | } |
| 2210 | |
| 2211 | /// Add the specified register class as an available regclass for the |
| 2212 | /// specified value type. This indicates the selector can handle values of |
| 2213 | /// that class natively. |
| 2214 | void addRegisterClass(MVT VT, const TargetRegisterClass *RC) { |
| 2215 | assert((unsigned)VT.SimpleTy < array_lengthof(RegClassForVT)); |
| 2216 | RegClassForVT[VT.SimpleTy] = RC; |
| 2217 | } |
| 2218 | |
| 2219 | /// Return the largest legal super-reg register class of the register class |
| 2220 | /// for the specified type and its associated "cost". |
| 2221 | virtual std::pair<const TargetRegisterClass *, uint8_t> |
| 2222 | findRepresentativeClass(const TargetRegisterInfo *TRI, MVT VT) const; |
| 2223 | |
| 2224 | /// Once all of the register classes are added, this allows us to compute |
| 2225 | /// derived properties we expose. |
| 2226 | void computeRegisterProperties(const TargetRegisterInfo *TRI); |
| 2227 | |
| 2228 | /// Indicate that the specified operation does not work with the specified |
| 2229 | /// type and indicate what to do about it. Note that VT may refer to either |
| 2230 | /// the type of a result or that of an operand of Op. |
| 2231 | void setOperationAction(unsigned Op, MVT VT, LegalizeAction Action) { |
| 2232 | assert(Op < array_lengthof(OpActions[0]) && "Table isn't big enough!"); |
| 2233 | OpActions[(unsigned)VT.SimpleTy][Op] = Action; |
| 2234 | } |
| 2235 | |
| 2236 | /// Indicate that the specified load with extension does not work with the |
| 2237 | /// specified type and indicate what to do about it. |
| 2238 | void setLoadExtAction(unsigned ExtType, MVT ValVT, MVT MemVT, |
| 2239 | LegalizeAction Action) { |
| 2240 | assert(ExtType < ISD::LAST_LOADEXT_TYPE && ValVT.isValid() && |
| 2241 | MemVT.isValid() && "Table isn't big enough!"); |
| 2242 | assert((unsigned)Action < 0x10 && "too many bits for bitfield array"); |
| 2243 | unsigned Shift = 4 * ExtType; |
| 2244 | LoadExtActions[ValVT.SimpleTy][MemVT.SimpleTy] &= ~((uint16_t)0xF << Shift); |
| 2245 | LoadExtActions[ValVT.SimpleTy][MemVT.SimpleTy] |= (uint16_t)Action << Shift; |
| 2246 | } |
| 2247 | |
| 2248 | /// Indicate that the specified truncating store does not work with the |
| 2249 | /// specified type and indicate what to do about it. |
| 2250 | void setTruncStoreAction(MVT ValVT, MVT MemVT, LegalizeAction Action) { |
| 2251 | assert(ValVT.isValid() && MemVT.isValid() && "Table isn't big enough!"); |
| 2252 | TruncStoreActions[(unsigned)ValVT.SimpleTy][MemVT.SimpleTy] = Action; |
| 2253 | } |
| 2254 | |
| 2255 | /// Indicate that the specified indexed load does or does not work with the |
| 2256 | /// specified type and indicate what to do abort it. |
| 2257 | /// |
| 2258 | /// NOTE: All indexed mode loads are initialized to Expand in |
| 2259 | /// TargetLowering.cpp |
| 2260 | void setIndexedLoadAction(unsigned IdxMode, MVT VT, LegalizeAction Action) { |
| 2261 | setIndexedModeAction(IdxMode, VT, IMAB_Load, Action); |
| 2262 | } |
| 2263 | |
| 2264 | /// Indicate that the specified indexed store does or does not work with the |
| 2265 | /// specified type and indicate what to do about it. |
| 2266 | /// |
| 2267 | /// NOTE: All indexed mode stores are initialized to Expand in |
| 2268 | /// TargetLowering.cpp |
| 2269 | void setIndexedStoreAction(unsigned IdxMode, MVT VT, LegalizeAction Action) { |
| 2270 | setIndexedModeAction(IdxMode, VT, IMAB_Store, Action); |
| 2271 | } |
| 2272 | |
| 2273 | /// Indicate that the specified indexed masked load does or does not work with |
| 2274 | /// the specified type and indicate what to do about it. |
| 2275 | /// |
| 2276 | /// NOTE: All indexed mode masked loads are initialized to Expand in |
| 2277 | /// TargetLowering.cpp |
| 2278 | void setIndexedMaskedLoadAction(unsigned IdxMode, MVT VT, |
| 2279 | LegalizeAction Action) { |
| 2280 | setIndexedModeAction(IdxMode, VT, IMAB_MaskedLoad, Action); |
| 2281 | } |
| 2282 | |
| 2283 | /// Indicate that the specified indexed masked store does or does not work |
| 2284 | /// with the specified type and indicate what to do about it. |
| 2285 | /// |
| 2286 | /// NOTE: All indexed mode masked stores are initialized to Expand in |
| 2287 | /// TargetLowering.cpp |
| 2288 | void setIndexedMaskedStoreAction(unsigned IdxMode, MVT VT, |
| 2289 | LegalizeAction Action) { |
| 2290 | setIndexedModeAction(IdxMode, VT, IMAB_MaskedStore, Action); |
| 2291 | } |
| 2292 | |
| 2293 | /// Indicate that the specified condition code is or isn't supported on the |
| 2294 | /// target and indicate what to do about it. |
| 2295 | void setCondCodeAction(ISD::CondCode CC, MVT VT, |
| 2296 | LegalizeAction Action) { |
| 2297 | assert(VT.isValid() && (unsigned)CC < array_lengthof(CondCodeActions) && |
| 2298 | "Table isn't big enough!"); |
| 2299 | assert((unsigned)Action < 0x10 && "too many bits for bitfield array"); |
| 2300 | /// The lower 3 bits of the SimpleTy index into Nth 4bit set from the 32-bit |
| 2301 | /// value and the upper 29 bits index into the second dimension of the array |
| 2302 | /// to select what 32-bit value to use. |
| 2303 | uint32_t Shift = 4 * (VT.SimpleTy & 0x7); |
| 2304 | CondCodeActions[CC][VT.SimpleTy >> 3] &= ~((uint32_t)0xF << Shift); |
| 2305 | CondCodeActions[CC][VT.SimpleTy >> 3] |= (uint32_t)Action << Shift; |
| 2306 | } |
| 2307 | |
| 2308 | /// If Opc/OrigVT is specified as being promoted, the promotion code defaults |
| 2309 | /// to trying a larger integer/fp until it can find one that works. If that |
| 2310 | /// default is insufficient, this method can be used by the target to override |
| 2311 | /// the default. |
| 2312 | void AddPromotedToType(unsigned Opc, MVT OrigVT, MVT DestVT) { |
| 2313 | PromoteToType[std::make_pair(Opc, OrigVT.SimpleTy)] = DestVT.SimpleTy; |
| 2314 | } |
| 2315 | |
| 2316 | /// Convenience method to set an operation to Promote and specify the type |
| 2317 | /// in a single call. |
| 2318 | void setOperationPromotedToType(unsigned Opc, MVT OrigVT, MVT DestVT) { |
| 2319 | setOperationAction(Opc, OrigVT, Promote); |
| 2320 | AddPromotedToType(Opc, OrigVT, DestVT); |
| 2321 | } |
| 2322 | |
| 2323 | /// Targets should invoke this method for each target independent node that |
| 2324 | /// they want to provide a custom DAG combiner for by implementing the |
| 2325 | /// PerformDAGCombine virtual method. |
| 2326 | void setTargetDAGCombine(ISD::NodeType NT) { |
| 2327 | assert(unsigned(NT >> 3) < array_lengthof(TargetDAGCombineArray)); |
| 2328 | TargetDAGCombineArray[NT >> 3] |= 1 << (NT&7); |
| 2329 | } |
| 2330 | |
| 2331 | /// Set the target's minimum function alignment. |
| 2332 | void setMinFunctionAlignment(Align Alignment) { |
| 2333 | MinFunctionAlignment = Alignment; |
| 2334 | } |
| 2335 | |
| 2336 | /// Set the target's preferred function alignment. This should be set if |
| 2337 | /// there is a performance benefit to higher-than-minimum alignment |
| 2338 | void setPrefFunctionAlignment(Align Alignment) { |
| 2339 | PrefFunctionAlignment = Alignment; |
| 2340 | } |
| 2341 | |
| 2342 | /// Set the target's preferred loop alignment. Default alignment is one, it |
| 2343 | /// means the target does not care about loop alignment. The target may also |
| 2344 | /// override getPrefLoopAlignment to provide per-loop values. |
| 2345 | void setPrefLoopAlignment(Align Alignment) { PrefLoopAlignment = Alignment; } |
| 2346 | void setMaxBytesForAlignment(unsigned MaxBytes) { |
| 2347 | MaxBytesForAlignment = MaxBytes; |
| 2348 | } |
| 2349 | |
| 2350 | /// Set the minimum stack alignment of an argument. |
| 2351 | void setMinStackArgumentAlignment(Align Alignment) { |
| 2352 | MinStackArgumentAlignment = Alignment; |
| 2353 | } |
| 2354 | |
| 2355 | /// Set the maximum atomic operation size supported by the |
| 2356 | /// backend. Atomic operations greater than this size (as well as |
| 2357 | /// ones that are not naturally aligned), will be expanded by |
| 2358 | /// AtomicExpandPass into an __atomic_* library call. |
| 2359 | void setMaxAtomicSizeInBitsSupported(unsigned SizeInBits) { |
| 2360 | MaxAtomicSizeInBitsSupported = SizeInBits; |
| 2361 | } |
| 2362 | |
| 2363 | /// Sets the minimum cmpxchg or ll/sc size supported by the backend. |
| 2364 | void setMinCmpXchgSizeInBits(unsigned SizeInBits) { |
| 2365 | MinCmpXchgSizeInBits = SizeInBits; |
| 2366 | } |
| 2367 | |
| 2368 | /// Sets whether unaligned atomic operations are supported. |
| 2369 | void setSupportsUnalignedAtomics(bool UnalignedSupported) { |
| 2370 | SupportsUnalignedAtomics = UnalignedSupported; |
| 2371 | } |
| 2372 | |
| 2373 | public: |
| 2374 | //===--------------------------------------------------------------------===// |
| 2375 | // Addressing mode description hooks (used by LSR etc). |
| 2376 | // |
| 2377 | |
| 2378 | /// CodeGenPrepare sinks address calculations into the same BB as Load/Store |
| 2379 | /// instructions reading the address. This allows as much computation as |
| 2380 | /// possible to be done in the address mode for that operand. This hook lets |
| 2381 | /// targets also pass back when this should be done on intrinsics which |
| 2382 | /// load/store. |
| 2383 | virtual bool getAddrModeArguments(IntrinsicInst * /*I*/, |
| 2384 | SmallVectorImpl<Value*> &/*Ops*/, |
| 2385 | Type *&/*AccessTy*/) const { |
| 2386 | return false; |
| 2387 | } |
| 2388 | |
| 2389 | /// This represents an addressing mode of: |
| 2390 | /// BaseGV + BaseOffs + BaseReg + Scale*ScaleReg |
| 2391 | /// If BaseGV is null, there is no BaseGV. |
| 2392 | /// If BaseOffs is zero, there is no base offset. |
| 2393 | /// If HasBaseReg is false, there is no base register. |
| 2394 | /// If Scale is zero, there is no ScaleReg. Scale of 1 indicates a reg with |
| 2395 | /// no scale. |
| 2396 | struct AddrMode { |
| 2397 | GlobalValue *BaseGV = nullptr; |
| 2398 | int64_t BaseOffs = 0; |
| 2399 | bool HasBaseReg = false; |
| 2400 | int64_t Scale = 0; |
| 2401 | AddrMode() = default; |
| 2402 | }; |
| 2403 | |
| 2404 | /// Return true if the addressing mode represented by AM is legal for this |
| 2405 | /// target, for a load/store of the specified type. |
| 2406 | /// |
| 2407 | /// The type may be VoidTy, in which case only return true if the addressing |
| 2408 | /// mode is legal for a load/store of any legal type. TODO: Handle |
| 2409 | /// pre/postinc as well. |
| 2410 | /// |
| 2411 | /// If the address space cannot be determined, it will be -1. |
| 2412 | /// |
| 2413 | /// TODO: Remove default argument |
| 2414 | virtual bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, |
| 2415 | Type *Ty, unsigned AddrSpace, |
| 2416 | Instruction *I = nullptr) const; |
| 2417 | |
| 2418 | /// Return the cost of the scaling factor used in the addressing mode |
| 2419 | /// represented by AM for this target, for a load/store of the specified type. |
| 2420 | /// |
| 2421 | /// If the AM is supported, the return value must be >= 0. |
| 2422 | /// If the AM is not supported, it returns a negative value. |
| 2423 | /// TODO: Handle pre/postinc as well. |
| 2424 | /// TODO: Remove default argument |
| 2425 | virtual InstructionCost getScalingFactorCost(const DataLayout &DL, |
| 2426 | const AddrMode &AM, Type *Ty, |
| 2427 | unsigned AS = 0) const { |
| 2428 | // Default: assume that any scaling factor used in a legal AM is free. |
| 2429 | if (isLegalAddressingMode(DL, AM, Ty, AS)) |
| 2430 | return 0; |
| 2431 | return -1; |
| 2432 | } |
| 2433 | |
| 2434 | /// Return true if the specified immediate is legal icmp immediate, that is |
| 2435 | /// the target has icmp instructions which can compare a register against the |
| 2436 | /// immediate without having to materialize the immediate into a register. |
| 2437 | virtual bool isLegalICmpImmediate(int64_t) const { |
| 2438 | return true; |
| 2439 | } |
| 2440 | |
| 2441 | /// Return true if the specified immediate is legal add immediate, that is the |
| 2442 | /// target has add instructions which can add a register with the immediate |
| 2443 | /// without having to materialize the immediate into a register. |
| 2444 | virtual bool isLegalAddImmediate(int64_t) const { |
| 2445 | return true; |
| 2446 | } |
| 2447 | |
| 2448 | /// Return true if the specified immediate is legal for the value input of a |
| 2449 | /// store instruction. |
| 2450 | virtual bool isLegalStoreImmediate(int64_t Value) const { |
| 2451 | // Default implementation assumes that at least 0 works since it is likely |
| 2452 | // that a zero register exists or a zero immediate is allowed. |
| 2453 | return Value == 0; |
| 2454 | } |
| 2455 | |
| 2456 | /// Return true if it's significantly cheaper to shift a vector by a uniform |
| 2457 | /// scalar than by an amount which will vary across each lane. On x86 before |
| 2458 | /// AVX2 for example, there is a "psllw" instruction for the former case, but |
| 2459 | /// no simple instruction for a general "a << b" operation on vectors. |
| 2460 | /// This should also apply to lowering for vector funnel shifts (rotates). |
| 2461 | virtual bool isVectorShiftByScalarCheap(Type *Ty) const { |
| 2462 | return false; |
| 2463 | } |
| 2464 | |
| 2465 | /// Given a shuffle vector SVI representing a vector splat, return a new |
| 2466 | /// scalar type of size equal to SVI's scalar type if the new type is more |
| 2467 | /// profitable. Returns nullptr otherwise. For example under MVE float splats |
| 2468 | /// are converted to integer to prevent the need to move from SPR to GPR |
| 2469 | /// registers. |
| 2470 | virtual Type* shouldConvertSplatType(ShuffleVectorInst* SVI) const { |
| 2471 | return nullptr; |
| 2472 | } |
| 2473 | |
| 2474 | /// Given a set in interconnected phis of type 'From' that are loaded/stored |
| 2475 | /// or bitcast to type 'To', return true if the set should be converted to |
| 2476 | /// 'To'. |
| 2477 | virtual bool shouldConvertPhiType(Type *From, Type *To) const { |
| 2478 | return (From->isIntegerTy() || From->isFloatingPointTy()) && |
| 2479 | (To->isIntegerTy() || To->isFloatingPointTy()); |
| 2480 | } |
| 2481 | |
| 2482 | /// Returns true if the opcode is a commutative binary operation. |
| 2483 | virtual bool isCommutativeBinOp(unsigned Opcode) const { |
| 2484 | // FIXME: This should get its info from the td file. |
| 2485 | switch (Opcode) { |
| 2486 | case ISD::ADD: |
| 2487 | case ISD::SMIN: |
| 2488 | case ISD::SMAX: |
| 2489 | case ISD::UMIN: |
| 2490 | case ISD::UMAX: |
| 2491 | case ISD::MUL: |
| 2492 | case ISD::MULHU: |
| 2493 | case ISD::MULHS: |
| 2494 | case ISD::SMUL_LOHI: |
| 2495 | case ISD::UMUL_LOHI: |
| 2496 | case ISD::FADD: |
| 2497 | case ISD::FMUL: |
| 2498 | case ISD::AND: |
| 2499 | case ISD::OR: |
| 2500 | case ISD::XOR: |
| 2501 | case ISD::SADDO: |
| 2502 | case ISD::UADDO: |
| 2503 | case ISD::ADDC: |
| 2504 | case ISD::ADDE: |
| 2505 | case ISD::SADDSAT: |
| 2506 | case ISD::UADDSAT: |
| 2507 | case ISD::FMINNUM: |
| 2508 | case ISD::FMAXNUM: |
| 2509 | case ISD::FMINNUM_IEEE: |
| 2510 | case ISD::FMAXNUM_IEEE: |
| 2511 | case ISD::FMINIMUM: |
| 2512 | case ISD::FMAXIMUM: |
| 2513 | return true; |
| 2514 | default: return false; |
| 2515 | } |
| 2516 | } |
| 2517 | |
| 2518 | /// Return true if the node is a math/logic binary operator. |
| 2519 | virtual bool isBinOp(unsigned Opcode) const { |
| 2520 | // A commutative binop must be a binop. |
| 2521 | if (isCommutativeBinOp(Opcode)) |
| 2522 | return true; |
| 2523 | // These are non-commutative binops. |
| 2524 | switch (Opcode) { |
| 2525 | case ISD::SUB: |
| 2526 | case ISD::SHL: |
| 2527 | case ISD::SRL: |
| 2528 | case ISD::SRA: |
| 2529 | case ISD::ROTL: |
| 2530 | case ISD::ROTR: |
| 2531 | case ISD::SDIV: |
| 2532 | case ISD::UDIV: |
| 2533 | case ISD::SREM: |
| 2534 | case ISD::UREM: |
| 2535 | case ISD::SSUBSAT: |
| 2536 | case ISD::USUBSAT: |
| 2537 | case ISD::FSUB: |
| 2538 | case ISD::FDIV: |
| 2539 | case ISD::FREM: |
| 2540 | return true; |
| 2541 | default: |
| 2542 | return false; |
| 2543 | } |
| 2544 | } |
| 2545 | |
| 2546 | /// Return true if it's free to truncate a value of type FromTy to type |
| 2547 | /// ToTy. e.g. On x86 it's free to truncate a i32 value in register EAX to i16 |
| 2548 | /// by referencing its sub-register AX. |
| 2549 | /// Targets must return false when FromTy <= ToTy. |
| 2550 | virtual bool isTruncateFree(Type *FromTy, Type *ToTy) const { |
| 2551 | return false; |
| 2552 | } |
| 2553 | |
| 2554 | /// Return true if a truncation from FromTy to ToTy is permitted when deciding |
| 2555 | /// whether a call is in tail position. Typically this means that both results |
| 2556 | /// would be assigned to the same register or stack slot, but it could mean |
| 2557 | /// the target performs adequate checks of its own before proceeding with the |
| 2558 | /// tail call. Targets must return false when FromTy <= ToTy. |
| 2559 | virtual bool allowTruncateForTailCall(Type *FromTy, Type *ToTy) const { |
| 2560 | return false; |
| 2561 | } |
| 2562 | |
| 2563 | virtual bool isTruncateFree(EVT FromVT, EVT ToVT) const { return false; } |
| 2564 | virtual bool isTruncateFree(LLT FromTy, LLT ToTy, const DataLayout &DL, |
| 2565 | LLVMContext &Ctx) const { |
| 2566 | return isTruncateFree(getApproximateEVTForLLT(FromTy, DL, Ctx), |
| 2567 | getApproximateEVTForLLT(ToTy, DL, Ctx)); |
| 2568 | } |
| 2569 | |
| 2570 | virtual bool isProfitableToHoist(Instruction *I) const { return true; } |
| 2571 | |
| 2572 | /// Return true if the extension represented by \p I is free. |
| 2573 | /// Unlikely the is[Z|FP]ExtFree family which is based on types, |
| 2574 | /// this method can use the context provided by \p I to decide |
| 2575 | /// whether or not \p I is free. |
| 2576 | /// This method extends the behavior of the is[Z|FP]ExtFree family. |
| 2577 | /// In other words, if is[Z|FP]Free returns true, then this method |
| 2578 | /// returns true as well. The converse is not true. |
| 2579 | /// The target can perform the adequate checks by overriding isExtFreeImpl. |
| 2580 | /// \pre \p I must be a sign, zero, or fp extension. |
| 2581 | bool isExtFree(const Instruction *I) const { |
| 2582 | switch (I->getOpcode()) { |
| 2583 | case Instruction::FPExt: |
| 2584 | if (isFPExtFree(EVT::getEVT(I->getType()), |
| 2585 | EVT::getEVT(I->getOperand(0)->getType()))) |
| 2586 | return true; |
| 2587 | break; |
| 2588 | case Instruction::ZExt: |
| 2589 | if (isZExtFree(I->getOperand(0)->getType(), I->getType())) |
| 2590 | return true; |
| 2591 | break; |
| 2592 | case Instruction::SExt: |
| 2593 | break; |
| 2594 | default: |
| 2595 | llvm_unreachable("Instruction is not an extension"); |
| 2596 | } |
| 2597 | return isExtFreeImpl(I); |
| 2598 | } |
| 2599 | |
| 2600 | /// Return true if \p Load and \p Ext can form an ExtLoad. |
| 2601 | /// For example, in AArch64 |
| 2602 | /// %L = load i8, i8* %ptr |
| 2603 | /// %E = zext i8 %L to i32 |
| 2604 | /// can be lowered into one load instruction |
| 2605 | /// ldrb w0, [x0] |
| 2606 | bool isExtLoad(const LoadInst *Load, const Instruction *Ext, |
| 2607 | const DataLayout &DL) const { |
| 2608 | EVT VT = getValueType(DL, Ext->getType()); |
| 2609 | EVT LoadVT = getValueType(DL, Load->getType()); |
| 2610 | |
| 2611 | // If the load has other users and the truncate is not free, the ext |
| 2612 | // probably isn't free. |
| 2613 | if (!Load->hasOneUse() && (isTypeLegal(LoadVT) || !isTypeLegal(VT)) && |
| 2614 | !isTruncateFree(Ext->getType(), Load->getType())) |
| 2615 | return false; |
| 2616 | |
| 2617 | // Check whether the target supports casts folded into loads. |
| 2618 | unsigned LType; |
| 2619 | if (isa<ZExtInst>(Ext)) |
| 2620 | LType = ISD::ZEXTLOAD; |
| 2621 | else { |
| 2622 | assert(isa<SExtInst>(Ext) && "Unexpected ext type!"); |
| 2623 | LType = ISD::SEXTLOAD; |
| 2624 | } |
| 2625 | |
| 2626 | return isLoadExtLegal(LType, VT, LoadVT); |
| 2627 | } |
| 2628 | |
| 2629 | /// Return true if any actual instruction that defines a value of type FromTy |
| 2630 | /// implicitly zero-extends the value to ToTy in the result register. |
| 2631 | /// |
| 2632 | /// The function should return true when it is likely that the truncate can |
| 2633 | /// be freely folded with an instruction defining a value of FromTy. If |
| 2634 | /// the defining instruction is unknown (because you're looking at a |
| 2635 | /// function argument, PHI, etc.) then the target may require an |
| 2636 | /// explicit truncate, which is not necessarily free, but this function |
| 2637 | /// does not deal with those cases. |
| 2638 | /// Targets must return false when FromTy >= ToTy. |
| 2639 | virtual bool isZExtFree(Type *FromTy, Type *ToTy) const { |
| 2640 | return false; |
| 2641 | } |
| 2642 | |
| 2643 | virtual bool isZExtFree(EVT FromTy, EVT ToTy) const { return false; } |
| 2644 | virtual bool isZExtFree(LLT FromTy, LLT ToTy, const DataLayout &DL, |
| 2645 | LLVMContext &Ctx) const { |
| 2646 | return isZExtFree(getApproximateEVTForLLT(FromTy, DL, Ctx), |
| 2647 | getApproximateEVTForLLT(ToTy, DL, Ctx)); |
| 2648 | } |
| 2649 | |
| 2650 | /// Return true if sign-extension from FromTy to ToTy is cheaper than |
| 2651 | /// zero-extension. |
| 2652 | virtual bool isSExtCheaperThanZExt(EVT FromTy, EVT ToTy) const { |
| 2653 | return false; |
| 2654 | } |
| 2655 | |
| 2656 | /// Return true if sinking I's operands to the same basic block as I is |
| 2657 | /// profitable, e.g. because the operands can be folded into a target |
| 2658 | /// instruction during instruction selection. After calling the function |
| 2659 | /// \p Ops contains the Uses to sink ordered by dominance (dominating users |
| 2660 | /// come first). |
| 2661 | virtual bool shouldSinkOperands(Instruction *I, |
| 2662 | SmallVectorImpl<Use *> &Ops) const { |
| 2663 | return false; |
| 2664 | } |
| 2665 | |
| 2666 | /// Return true if the target supplies and combines to a paired load |
| 2667 | /// two loaded values of type LoadedType next to each other in memory. |
| 2668 | /// RequiredAlignment gives the minimal alignment constraints that must be met |
| 2669 | /// to be able to select this paired load. |
| 2670 | /// |
| 2671 | /// This information is *not* used to generate actual paired loads, but it is |
| 2672 | /// used to generate a sequence of loads that is easier to combine into a |
| 2673 | /// paired load. |
| 2674 | /// For instance, something like this: |
| 2675 | /// a = load i64* addr |
| 2676 | /// b = trunc i64 a to i32 |
| 2677 | /// c = lshr i64 a, 32 |
| 2678 | /// d = trunc i64 c to i32 |
| 2679 | /// will be optimized into: |
| 2680 | /// b = load i32* addr1 |
| 2681 | /// d = load i32* addr2 |
| 2682 | /// Where addr1 = addr2 +/- sizeof(i32). |
| 2683 | /// |
| 2684 | /// In other words, unless the target performs a post-isel load combining, |
| 2685 | /// this information should not be provided because it will generate more |
| 2686 | /// loads. |
| 2687 | virtual bool hasPairedLoad(EVT /*LoadedType*/, |
| 2688 | Align & /*RequiredAlignment*/) const { |
| 2689 | return false; |
| 2690 | } |
| 2691 | |
| 2692 | /// Return true if the target has a vector blend instruction. |
| 2693 | virtual bool hasVectorBlend() const { return false; } |
| 2694 | |
| 2695 | /// Get the maximum supported factor for interleaved memory accesses. |
| 2696 | /// Default to be the minimum interleave factor: 2. |
| 2697 | virtual unsigned getMaxSupportedInterleaveFactor() const { return 2; } |
| 2698 | |
| 2699 | /// Lower an interleaved load to target specific intrinsics. Return |
| 2700 | /// true on success. |
| 2701 | /// |
| 2702 | /// \p LI is the vector load instruction. |
| 2703 | /// \p Shuffles is the shufflevector list to DE-interleave the loaded vector. |
| 2704 | /// \p Indices is the corresponding indices for each shufflevector. |
| 2705 | /// \p Factor is the interleave factor. |
| 2706 | virtual bool lowerInterleavedLoad(LoadInst *LI, |
| 2707 | ArrayRef<ShuffleVectorInst *> Shuffles, |
| 2708 | ArrayRef<unsigned> Indices, |
| 2709 | unsigned Factor) const { |
| 2710 | return false; |
| 2711 | } |
| 2712 | |
| 2713 | /// Lower an interleaved store to target specific intrinsics. Return |
| 2714 | /// true on success. |
| 2715 | /// |
| 2716 | /// \p SI is the vector store instruction. |
| 2717 | /// \p SVI is the shufflevector to RE-interleave the stored vector. |
| 2718 | /// \p Factor is the interleave factor. |
| 2719 | virtual bool lowerInterleavedStore(StoreInst *SI, ShuffleVectorInst *SVI, |
| 2720 | unsigned Factor) const { |
| 2721 | return false; |
| 2722 | } |
| 2723 | |
| 2724 | /// Return true if zero-extending the specific node Val to type VT2 is free |
| 2725 | /// (either because it's implicitly zero-extended such as ARM ldrb / ldrh or |
| 2726 | /// because it's folded such as X86 zero-extending loads). |
| 2727 | virtual bool isZExtFree(SDValue Val, EVT VT2) const { |
| 2728 | return isZExtFree(Val.getValueType(), VT2); |
| 2729 | } |
| 2730 | |
| 2731 | /// Return true if an fpext operation is free (for instance, because |
| 2732 | /// single-precision floating-point numbers are implicitly extended to |
| 2733 | /// double-precision). |
| 2734 | virtual bool isFPExtFree(EVT DestVT, EVT SrcVT) const { |
| 2735 | assert(SrcVT.isFloatingPoint() && DestVT.isFloatingPoint() && |
| 2736 | "invalid fpext types"); |
| 2737 | return false; |
| 2738 | } |
| 2739 | |
| 2740 | /// Return true if an fpext operation input to an \p Opcode operation is free |
| 2741 | /// (for instance, because half-precision floating-point numbers are |
| 2742 | /// implicitly extended to float-precision) for an FMA instruction. |
| 2743 | virtual bool isFPExtFoldable(const MachineInstr &MI, unsigned Opcode, |
| 2744 | LLT DestTy, LLT SrcTy) const { |
| 2745 | return false; |
| 2746 | } |
| 2747 | |
| 2748 | /// Return true if an fpext operation input to an \p Opcode operation is free |
| 2749 | /// (for instance, because half-precision floating-point numbers are |
| 2750 | /// implicitly extended to float-precision) for an FMA instruction. |
| 2751 | virtual bool isFPExtFoldable(const SelectionDAG &DAG, unsigned Opcode, |
| 2752 | EVT DestVT, EVT SrcVT) const { |
| 2753 | assert(DestVT.isFloatingPoint() && SrcVT.isFloatingPoint() && |
| 2754 | "invalid fpext types"); |
| 2755 | return isFPExtFree(DestVT, SrcVT); |
| 2756 | } |
| 2757 | |
| 2758 | /// Return true if folding a vector load into ExtVal (a sign, zero, or any |
| 2759 | /// extend node) is profitable. |
| 2760 | virtual bool isVectorLoadExtDesirable(SDValue ExtVal) const { return false; } |
| 2761 | |
| 2762 | /// Return true if an fneg operation is free to the point where it is never |
| 2763 | /// worthwhile to replace it with a bitwise operation. |
| 2764 | virtual bool isFNegFree(EVT VT) const { |
| 2765 | assert(VT.isFloatingPoint()); |
| 2766 | return false; |
| 2767 | } |
| 2768 | |
| 2769 | /// Return true if an fabs operation is free to the point where it is never |
| 2770 | /// worthwhile to replace it with a bitwise operation. |
| 2771 | virtual bool isFAbsFree(EVT VT) const { |
| 2772 | assert(VT.isFloatingPoint()); |
| 2773 | return false; |
| 2774 | } |
| 2775 | |
| 2776 | /// Return true if an FMA operation is faster than a pair of fmul and fadd |
| 2777 | /// instructions. fmuladd intrinsics will be expanded to FMAs when this method |
| 2778 | /// returns true, otherwise fmuladd is expanded to fmul + fadd. |
| 2779 | /// |
| 2780 | /// NOTE: This may be called before legalization on types for which FMAs are |
| 2781 | /// not legal, but should return true if those types will eventually legalize |
| 2782 | /// to types that support FMAs. After legalization, it will only be called on |
| 2783 | /// types that support FMAs (via Legal or Custom actions) |
| 2784 | virtual bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF, |
| 2785 | EVT) const { |
| 2786 | return false; |
| 2787 | } |
| 2788 | |
| 2789 | /// Return true if an FMA operation is faster than a pair of fmul and fadd |
| 2790 | /// instructions. fmuladd intrinsics will be expanded to FMAs when this method |
| 2791 | /// returns true, otherwise fmuladd is expanded to fmul + fadd. |
| 2792 | /// |
| 2793 | /// NOTE: This may be called before legalization on types for which FMAs are |
| 2794 | /// not legal, but should return true if those types will eventually legalize |
| 2795 | /// to types that support FMAs. After legalization, it will only be called on |
| 2796 | /// types that support FMAs (via Legal or Custom actions) |
| 2797 | virtual bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF, |
| 2798 | LLT) const { |
| 2799 | return false; |
| 2800 | } |
| 2801 | |
| 2802 | /// IR version |
| 2803 | virtual bool isFMAFasterThanFMulAndFAdd(const Function &F, Type *) const { |
| 2804 | return false; |
| 2805 | } |
| 2806 | |
| 2807 | /// Returns true if \p MI can be combined with another instruction to |
| 2808 | /// form TargetOpcode::G_FMAD. \p N may be an TargetOpcode::G_FADD, |
| 2809 | /// TargetOpcode::G_FSUB, or an TargetOpcode::G_FMUL which will be |
| 2810 | /// distributed into an fadd/fsub. |
| 2811 | virtual bool isFMADLegal(const MachineInstr &MI, LLT Ty) const { |
| 2812 | assert((MI.getOpcode() == TargetOpcode::G_FADD || |
| 2813 | MI.getOpcode() == TargetOpcode::G_FSUB || |
| 2814 | MI.getOpcode() == TargetOpcode::G_FMUL) && |
| 2815 | "unexpected node in FMAD forming combine"); |
| 2816 | switch (Ty.getScalarSizeInBits()) { |
| 2817 | case 16: |
| 2818 | return isOperationLegal(TargetOpcode::G_FMAD, MVT::f16); |
| 2819 | case 32: |
| 2820 | return isOperationLegal(TargetOpcode::G_FMAD, MVT::f32); |
| 2821 | case 64: |
| 2822 | return isOperationLegal(TargetOpcode::G_FMAD, MVT::f64); |
| 2823 | default: |
| 2824 | break; |
| 2825 | } |
| 2826 | |
| 2827 | return false; |
| 2828 | } |
| 2829 | |
| 2830 | /// Returns true if be combined with to form an ISD::FMAD. \p N may be an |
| 2831 | /// ISD::FADD, ISD::FSUB, or an ISD::FMUL which will be distributed into an |
| 2832 | /// fadd/fsub. |
| 2833 | virtual bool isFMADLegal(const SelectionDAG &DAG, const SDNode *N) const { |
| 2834 | assert((N->getOpcode() == ISD::FADD || N->getOpcode() == ISD::FSUB || |
| 2835 | N->getOpcode() == ISD::FMUL) && |
| 2836 | "unexpected node in FMAD forming combine"); |
| 2837 | return isOperationLegal(ISD::FMAD, N->getValueType(0)); |
| 2838 | } |
| 2839 | |
| 2840 | // Return true when the decision to generate FMA's (or FMS, FMLA etc) rather |
| 2841 | // than FMUL and ADD is delegated to the machine combiner. |
| 2842 | virtual bool generateFMAsInMachineCombiner(EVT VT, |
| 2843 | CodeGenOpt::Level OptLevel) const { |
| 2844 | return false; |
| 2845 | } |
| 2846 | |
| 2847 | /// Return true if it's profitable to narrow operations of type VT1 to |
| 2848 | /// VT2. e.g. on x86, it's profitable to narrow from i32 to i8 but not from |
| 2849 | /// i32 to i16. |
| 2850 | virtual bool isNarrowingProfitable(EVT /*VT1*/, EVT /*VT2*/) const { |
| 2851 | return false; |
| 2852 | } |
| 2853 | |
| 2854 | /// Return true if pulling a binary operation into a select with an identity |
| 2855 | /// constant is profitable. This is the inverse of an IR transform. |
| 2856 | /// Example: X + (Cond ? Y : 0) --> Cond ? (X + Y) : X |
| 2857 | virtual bool shouldFoldSelectWithIdentityConstant(unsigned BinOpcode, |
| 2858 | EVT VT) const { |
| 2859 | return false; |
| 2860 | } |
| 2861 | |
| 2862 | /// Return true if it is beneficial to convert a load of a constant to |
| 2863 | /// just the constant itself. |
| 2864 | /// On some targets it might be more efficient to use a combination of |
| 2865 | /// arithmetic instructions to materialize the constant instead of loading it |
| 2866 | /// from a constant pool. |
| 2867 | virtual bool shouldConvertConstantLoadToIntImm(const APInt &Imm, |
| 2868 | Type *Ty) const { |
| 2869 | return false; |
| 2870 | } |
| 2871 | |
| 2872 | /// Return true if EXTRACT_SUBVECTOR is cheap for extracting this result type |
| 2873 | /// from this source type with this index. This is needed because |
| 2874 | /// EXTRACT_SUBVECTOR usually has custom lowering that depends on the index of |
| 2875 | /// the first element, and only the target knows which lowering is cheap. |
| 2876 | virtual bool isExtractSubvectorCheap(EVT ResVT, EVT SrcVT, |
| 2877 | unsigned Index) const { |
| 2878 | return false; |
| 2879 | } |
| 2880 | |
| 2881 | /// Try to convert an extract element of a vector binary operation into an |
| 2882 | /// extract element followed by a scalar operation. |
| 2883 | virtual bool shouldScalarizeBinop(SDValue VecOp) const { |
| 2884 | return false; |
| 2885 | } |
| 2886 | |
| 2887 | /// Return true if extraction of a scalar element from the given vector type |
| 2888 | /// at the given index is cheap. For example, if scalar operations occur on |
| 2889 | /// the same register file as vector operations, then an extract element may |
| 2890 | /// be a sub-register rename rather than an actual instruction. |
| 2891 | virtual bool isExtractVecEltCheap(EVT VT, unsigned Index) const { |
| 2892 | return false; |
| 2893 | } |
| 2894 | |
| 2895 | /// Try to convert math with an overflow comparison into the corresponding DAG |
| 2896 | /// node operation. Targets may want to override this independently of whether |
| 2897 | /// the operation is legal/custom for the given type because it may obscure |
| 2898 | /// matching of other patterns. |
| 2899 | virtual bool shouldFormOverflowOp(unsigned Opcode, EVT VT, |
| 2900 | bool MathUsed) const { |
| 2901 | // TODO: The default logic is inherited from code in CodeGenPrepare. |
| 2902 | // The opcode should not make a difference by default? |
| 2903 | if (Opcode != ISD::UADDO) |
| 2904 | return false; |
| 2905 | |
| 2906 | // Allow the transform as long as we have an integer type that is not |
| 2907 | // obviously illegal and unsupported and if the math result is used |
| 2908 | // besides the overflow check. On some targets (e.g. SPARC), it is |
| 2909 | // not profitable to form on overflow op if the math result has no |
| 2910 | // concrete users. |
| 2911 | if (VT.isVector()) |
| 2912 | return false; |
| 2913 | return MathUsed && (VT.isSimple() || !isOperationExpand(Opcode, VT)); |
| 2914 | } |
| 2915 | |
| 2916 | // Return true if it is profitable to use a scalar input to a BUILD_VECTOR |
| 2917 | // even if the vector itself has multiple uses. |
| 2918 | virtual bool aggressivelyPreferBuildVectorSources(EVT VecVT) const { |
| 2919 | return false; |
| 2920 | } |
| 2921 | |
| 2922 | // Return true if CodeGenPrepare should consider splitting large offset of a |
| 2923 | // GEP to make the GEP fit into the addressing mode and can be sunk into the |
| 2924 | // same blocks of its users. |
| 2925 | virtual bool shouldConsiderGEPOffsetSplit() const { return false; } |
| 2926 | |
| 2927 | /// Return true if creating a shift of the type by the given |
| 2928 | /// amount is not profitable. |
| 2929 | virtual bool shouldAvoidTransformToShift(EVT VT, unsigned Amount) const { |
| 2930 | return false; |
| 2931 | } |
| 2932 | |
| 2933 | /// Does this target require the clearing of high-order bits in a register |
| 2934 | /// passed to the fp16 to fp conversion library function. |
| 2935 | virtual bool shouldKeepZExtForFP16Conv() const { return false; } |
| 2936 | |
| 2937 | /// Should we generate fp_to_si_sat and fp_to_ui_sat from type FPVT to type VT |
| 2938 | /// from min(max(fptoi)) saturation patterns. |
| 2939 | virtual bool shouldConvertFpToSat(unsigned Op, EVT FPVT, EVT VT) const { |
| 2940 | return isOperationLegalOrCustom(Op, VT); |
| 2941 | } |
| 2942 | |
| 2943 | //===--------------------------------------------------------------------===// |
| 2944 | // Runtime Library hooks |
| 2945 | // |
| 2946 | |
| 2947 | /// Rename the default libcall routine name for the specified libcall. |
| 2948 | void setLibcallName(RTLIB::Libcall Call, const char *Name) { |
| 2949 | LibcallRoutineNames[Call] = Name; |
| 2950 | } |
| 2951 | |
| 2952 | /// Get the libcall routine name for the specified libcall. |
| 2953 | const char *getLibcallName(RTLIB::Libcall Call) const { |
| 2954 | return LibcallRoutineNames[Call]; |
| 2955 | } |
| 2956 | |
| 2957 | /// Override the default CondCode to be used to test the result of the |
| 2958 | /// comparison libcall against zero. |
| 2959 | void setCmpLibcallCC(RTLIB::Libcall Call, ISD::CondCode CC) { |
| 2960 | CmpLibcallCCs[Call] = CC; |
| 2961 | } |
| 2962 | |
| 2963 | /// Get the CondCode that's to be used to test the result of the comparison |
| 2964 | /// libcall against zero. |
| 2965 | ISD::CondCode getCmpLibcallCC(RTLIB::Libcall Call) const { |
| 2966 | return CmpLibcallCCs[Call]; |
| 2967 | } |
| 2968 | |
| 2969 | /// Set the CallingConv that should be used for the specified libcall. |
| 2970 | void setLibcallCallingConv(RTLIB::Libcall Call, CallingConv::ID CC) { |
| 2971 | LibcallCallingConvs[Call] = CC; |
| 2972 | } |
| 2973 | |
| 2974 | /// Get the CallingConv that should be used for the specified libcall. |
| 2975 | CallingConv::ID getLibcallCallingConv(RTLIB::Libcall Call) const { |
| 2976 | return LibcallCallingConvs[Call]; |
| 2977 | } |
| 2978 | |
| 2979 | /// Execute target specific actions to finalize target lowering. |
| 2980 | /// This is used to set extra flags in MachineFrameInformation and freezing |
| 2981 | /// the set of reserved registers. |
| 2982 | /// The default implementation just freezes the set of reserved registers. |
| 2983 | virtual void finalizeLowering(MachineFunction &MF) const; |
| 2984 | |
| 2985 | //===----------------------------------------------------------------------===// |
| 2986 | // GlobalISel Hooks |
| 2987 | //===----------------------------------------------------------------------===// |
| 2988 | /// Check whether or not \p MI needs to be moved close to its uses. |
| 2989 | virtual bool shouldLocalize(const MachineInstr &MI, const TargetTransformInfo *TTI) const; |
| 2990 | |
| 2991 | |
| 2992 | private: |
| 2993 | const TargetMachine &TM; |
| 2994 | |
| 2995 | /// Tells the code generator that the target has multiple (allocatable) |
| 2996 | /// condition registers that can be used to store the results of comparisons |
| 2997 | /// for use by selects and conditional branches. With multiple condition |
| 2998 | /// registers, the code generator will not aggressively sink comparisons into |
| 2999 | /// the blocks of their users. |
| 3000 | bool HasMultipleConditionRegisters; |
| 3001 | |
| 3002 | /// Tells the code generator that the target has BitExtract instructions. |
| 3003 | /// The code generator will aggressively sink "shift"s into the blocks of |
| 3004 | /// their users if the users will generate "and" instructions which can be |
| 3005 | /// combined with "shift" to BitExtract instructions. |
| 3006 | bool HasExtractBitsInsn; |
| 3007 | |
| 3008 | /// Tells the code generator to bypass slow divide or remainder |
| 3009 | /// instructions. For example, BypassSlowDivWidths[32,8] tells the code |
| 3010 | /// generator to bypass 32-bit integer div/rem with an 8-bit unsigned integer |
| 3011 | /// div/rem when the operands are positive and less than 256. |
| 3012 | DenseMap <unsigned int, unsigned int> BypassSlowDivWidths; |
| 3013 | |
| 3014 | /// Tells the code generator that it shouldn't generate extra flow control |
| 3015 | /// instructions and should attempt to combine flow control instructions via |
| 3016 | /// predication. |
| 3017 | bool JumpIsExpensive; |
| 3018 | |
| 3019 | /// Information about the contents of the high-bits in boolean values held in |
| 3020 | /// a type wider than i1. See getBooleanContents. |
| 3021 | BooleanContent BooleanContents; |
| 3022 | |
| 3023 | /// Information about the contents of the high-bits in boolean values held in |
| 3024 | /// a type wider than i1. See getBooleanContents. |
| 3025 | BooleanContent BooleanFloatContents; |
| 3026 | |
| 3027 | /// Information about the contents of the high-bits in boolean vector values |
| 3028 | /// when the element type is wider than i1. See getBooleanContents. |
| 3029 | BooleanContent BooleanVectorContents; |
| 3030 | |
| 3031 | /// The target scheduling preference: shortest possible total cycles or lowest |
| 3032 | /// register usage. |
| 3033 | Sched::Preference SchedPreferenceInfo; |
| 3034 | |
| 3035 | /// The minimum alignment that any argument on the stack needs to have. |
| 3036 | Align MinStackArgumentAlignment; |
| 3037 | |
| 3038 | /// The minimum function alignment (used when optimizing for size, and to |
| 3039 | /// prevent explicitly provided alignment from leading to incorrect code). |
| 3040 | Align MinFunctionAlignment; |
| 3041 | |
| 3042 | /// The preferred function alignment (used when alignment unspecified and |
| 3043 | /// optimizing for speed). |
| 3044 | Align PrefFunctionAlignment; |
| 3045 | |
| 3046 | /// The preferred loop alignment (in log2 bot in bytes). |
| 3047 | Align PrefLoopAlignment; |
| 3048 | /// The maximum amount of bytes permitted to be emitted for alignment. |
| 3049 | unsigned MaxBytesForAlignment; |
| 3050 | |
| 3051 | /// Size in bits of the maximum atomics size the backend supports. |
| 3052 | /// Accesses larger than this will be expanded by AtomicExpandPass. |
| 3053 | unsigned MaxAtomicSizeInBitsSupported; |
| 3054 | |
| 3055 | /// Size in bits of the minimum cmpxchg or ll/sc operation the |
| 3056 | /// backend supports. |
| 3057 | unsigned MinCmpXchgSizeInBits; |
| 3058 | |
| 3059 | /// This indicates if the target supports unaligned atomic operations. |
| 3060 | bool SupportsUnalignedAtomics; |
| 3061 | |
| 3062 | /// If set to a physical register, this specifies the register that |
| 3063 | /// llvm.savestack/llvm.restorestack should save and restore. |
| 3064 | Register StackPointerRegisterToSaveRestore; |
| 3065 | |
| 3066 | /// This indicates the default register class to use for each ValueType the |
| 3067 | /// target supports natively. |
| 3068 | const TargetRegisterClass *RegClassForVT[MVT::VALUETYPE_SIZE]; |
| 3069 | uint16_t NumRegistersForVT[MVT::VALUETYPE_SIZE]; |
| 3070 | MVT RegisterTypeForVT[MVT::VALUETYPE_SIZE]; |
| 3071 | |
| 3072 | /// This indicates the "representative" register class to use for each |
| 3073 | /// ValueType the target supports natively. This information is used by the |
| 3074 | /// scheduler to track register pressure. By default, the representative |
| 3075 | /// register class is the largest legal super-reg register class of the |
| 3076 | /// register class of the specified type. e.g. On x86, i8, i16, and i32's |
| 3077 | /// representative class would be GR32. |
| 3078 | const TargetRegisterClass *RepRegClassForVT[MVT::VALUETYPE_SIZE]; |
| 3079 | |
| 3080 | /// This indicates the "cost" of the "representative" register class for each |
| 3081 | /// ValueType. The cost is used by the scheduler to approximate register |
| 3082 | /// pressure. |
| 3083 | uint8_t RepRegClassCostForVT[MVT::VALUETYPE_SIZE]; |
| 3084 | |
| 3085 | /// For any value types we are promoting or expanding, this contains the value |
| 3086 | /// type that we are changing to. For Expanded types, this contains one step |
| 3087 | /// of the expand (e.g. i64 -> i32), even if there are multiple steps required |
| 3088 | /// (e.g. i64 -> i16). For types natively supported by the system, this holds |
| 3089 | /// the same type (e.g. i32 -> i32). |
| 3090 | MVT TransformToType[MVT::VALUETYPE_SIZE]; |
| 3091 | |
| 3092 | /// For each operation and each value type, keep a LegalizeAction that |
| 3093 | /// indicates how instruction selection should deal with the operation. Most |
| 3094 | /// operations are Legal (aka, supported natively by the target), but |
| 3095 | /// operations that are not should be described. Note that operations on |
| 3096 | /// non-legal value types are not described here. |
| 3097 | LegalizeAction OpActions[MVT::VALUETYPE_SIZE][ISD::BUILTIN_OP_END]; |
| 3098 | |
| 3099 | /// For each load extension type and each value type, keep a LegalizeAction |
| 3100 | /// that indicates how instruction selection should deal with a load of a |
| 3101 | /// specific value type and extension type. Uses 4-bits to store the action |
| 3102 | /// for each of the 4 load ext types. |
| 3103 | uint16_t LoadExtActions[MVT::VALUETYPE_SIZE][MVT::VALUETYPE_SIZE]; |
| 3104 | |
| 3105 | /// For each value type pair keep a LegalizeAction that indicates whether a |
| 3106 | /// truncating store of a specific value type and truncating type is legal. |
| 3107 | LegalizeAction TruncStoreActions[MVT::VALUETYPE_SIZE][MVT::VALUETYPE_SIZE]; |
| 3108 | |
| 3109 | /// For each indexed mode and each value type, keep a quad of LegalizeAction |
| 3110 | /// that indicates how instruction selection should deal with the load / |
| 3111 | /// store / maskedload / maskedstore. |
| 3112 | /// |
| 3113 | /// The first dimension is the value_type for the reference. The second |
| 3114 | /// dimension represents the various modes for load store. |
| 3115 | uint16_t IndexedModeActions[MVT::VALUETYPE_SIZE][ISD::LAST_INDEXED_MODE]; |
| 3116 | |
| 3117 | /// For each condition code (ISD::CondCode) keep a LegalizeAction that |
| 3118 | /// indicates how instruction selection should deal with the condition code. |
| 3119 | /// |
| 3120 | /// Because each CC action takes up 4 bits, we need to have the array size be |
| 3121 | /// large enough to fit all of the value types. This can be done by rounding |
| 3122 | /// up the MVT::VALUETYPE_SIZE value to the next multiple of 8. |
| 3123 | uint32_t CondCodeActions[ISD::SETCC_INVALID][(MVT::VALUETYPE_SIZE + 7) / 8]; |
| 3124 | |
| 3125 | ValueTypeActionImpl ValueTypeActions; |
| 3126 | |
| 3127 | private: |
| 3128 | LegalizeKind getTypeConversion(LLVMContext &Context, EVT VT) const; |
| 3129 | |
| 3130 | /// Targets can specify ISD nodes that they would like PerformDAGCombine |
| 3131 | /// callbacks for by calling setTargetDAGCombine(), which sets a bit in this |
| 3132 | /// array. |
| 3133 | unsigned char |
| 3134 | TargetDAGCombineArray[(ISD::BUILTIN_OP_END+CHAR_BIT-1)/CHAR_BIT]; |
| 3135 | |
| 3136 | /// For operations that must be promoted to a specific type, this holds the |
| 3137 | /// destination type. This map should be sparse, so don't hold it as an |
| 3138 | /// array. |
| 3139 | /// |
| 3140 | /// Targets add entries to this map with AddPromotedToType(..), clients access |
| 3141 | /// this with getTypeToPromoteTo(..). |
| 3142 | std::map<std::pair<unsigned, MVT::SimpleValueType>, MVT::SimpleValueType> |
| 3143 | PromoteToType; |
| 3144 | |
| 3145 | /// Stores the name each libcall. |
| 3146 | const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1]; |
| 3147 | |
| 3148 | /// The ISD::CondCode that should be used to test the result of each of the |
| 3149 | /// comparison libcall against zero. |
| 3150 | ISD::CondCode CmpLibcallCCs[RTLIB::UNKNOWN_LIBCALL]; |
| 3151 | |
| 3152 | /// Stores the CallingConv that should be used for each libcall. |
| 3153 | CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL]; |
| 3154 | |
| 3155 | /// Set default libcall names and calling conventions. |
| 3156 | void InitLibcalls(const Triple &TT); |
| 3157 | |
| 3158 | /// The bits of IndexedModeActions used to store the legalisation actions |
| 3159 | /// We store the data as | ML | MS | L | S | each taking 4 bits. |
| 3160 | enum IndexedModeActionsBits { |
| 3161 | IMAB_Store = 0, |
| 3162 | IMAB_Load = 4, |
| 3163 | IMAB_MaskedStore = 8, |
| 3164 | IMAB_MaskedLoad = 12 |
| 3165 | }; |
| 3166 | |
| 3167 | void setIndexedModeAction(unsigned IdxMode, MVT VT, unsigned Shift, |
| 3168 | LegalizeAction Action) { |
| 3169 | assert(VT.isValid() && IdxMode < ISD::LAST_INDEXED_MODE && |
| 3170 | (unsigned)Action < 0xf && "Table isn't big enough!"); |
| 3171 | unsigned Ty = (unsigned)VT.SimpleTy; |
| 3172 | IndexedModeActions[Ty][IdxMode] &= ~(0xf << Shift); |
| 3173 | IndexedModeActions[Ty][IdxMode] |= ((uint16_t)Action) << Shift; |
| 3174 | } |
| 3175 | |
| 3176 | LegalizeAction getIndexedModeAction(unsigned IdxMode, MVT VT, |
| 3177 | unsigned Shift) const { |
| 3178 | assert(IdxMode < ISD::LAST_INDEXED_MODE && VT.isValid() && |
| 3179 | "Table isn't big enough!"); |
| 3180 | unsigned Ty = (unsigned)VT.SimpleTy; |
| 3181 | return (LegalizeAction)((IndexedModeActions[Ty][IdxMode] >> Shift) & 0xf); |
| 3182 | } |
| 3183 | |
| 3184 | protected: |
| 3185 | /// Return true if the extension represented by \p I is free. |
| 3186 | /// \pre \p I is a sign, zero, or fp extension and |
| 3187 | /// is[Z|FP]ExtFree of the related types is not true. |
| 3188 | virtual bool isExtFreeImpl(const Instruction *I) const { return false; } |
| 3189 | |
| 3190 | /// Depth that GatherAllAliases should should continue looking for chain |
| 3191 | /// dependencies when trying to find a more preferable chain. As an |
| 3192 | /// approximation, this should be more than the number of consecutive stores |
| 3193 | /// expected to be merged. |
| 3194 | unsigned GatherAllAliasesMaxDepth; |
| 3195 | |
| 3196 | /// \brief Specify maximum number of store instructions per memset call. |
| 3197 | /// |
| 3198 | /// When lowering \@llvm.memset this field specifies the maximum number of |
| 3199 | /// store operations that may be substituted for the call to memset. Targets |
| 3200 | /// must set this value based on the cost threshold for that target. Targets |
| 3201 | /// should assume that the memset will be done using as many of the largest |
| 3202 | /// store operations first, followed by smaller ones, if necessary, per |
| 3203 | /// alignment restrictions. For example, storing 9 bytes on a 32-bit machine |
| 3204 | /// with 16-bit alignment would result in four 2-byte stores and one 1-byte |
| 3205 | /// store. This only applies to setting a constant array of a constant size. |
| 3206 | unsigned MaxStoresPerMemset; |
| 3207 | /// Likewise for functions with the OptSize attribute. |
| 3208 | unsigned MaxStoresPerMemsetOptSize; |
| 3209 | |
| 3210 | /// \brief Specify maximum number of store instructions per memcpy call. |
| 3211 | /// |
| 3212 | /// When lowering \@llvm.memcpy this field specifies the maximum number of |
| 3213 | /// store operations that may be substituted for a call to memcpy. Targets |
| 3214 | /// must set this value based on the cost threshold for that target. Targets |
| 3215 | /// should assume that the memcpy will be done using as many of the largest |
| 3216 | /// store operations first, followed by smaller ones, if necessary, per |
| 3217 | /// alignment restrictions. For example, storing 7 bytes on a 32-bit machine |
| 3218 | /// with 32-bit alignment would result in one 4-byte store, a one 2-byte store |
| 3219 | /// and one 1-byte store. This only applies to copying a constant array of |
| 3220 | /// constant size. |
| 3221 | unsigned MaxStoresPerMemcpy; |
| 3222 | /// Likewise for functions with the OptSize attribute. |
| 3223 | unsigned MaxStoresPerMemcpyOptSize; |
| 3224 | /// \brief Specify max number of store instructions to glue in inlined memcpy. |
| 3225 | /// |
| 3226 | /// When memcpy is inlined based on MaxStoresPerMemcpy, specify maximum number |
| 3227 | /// of store instructions to keep together. This helps in pairing and |
| 3228 | // vectorization later on. |
| 3229 | unsigned MaxGluedStoresPerMemcpy = 0; |
| 3230 | |
| 3231 | /// \brief Specify maximum number of load instructions per memcmp call. |
| 3232 | /// |
| 3233 | /// When lowering \@llvm.memcmp this field specifies the maximum number of |
| 3234 | /// pairs of load operations that may be substituted for a call to memcmp. |
| 3235 | /// Targets must set this value based on the cost threshold for that target. |
| 3236 | /// Targets should assume that the memcmp will be done using as many of the |
| 3237 | /// largest load operations first, followed by smaller ones, if necessary, per |
| 3238 | /// alignment restrictions. For example, loading 7 bytes on a 32-bit machine |
| 3239 | /// with 32-bit alignment would result in one 4-byte load, a one 2-byte load |
| 3240 | /// and one 1-byte load. This only applies to copying a constant array of |
| 3241 | /// constant size. |
| 3242 | unsigned MaxLoadsPerMemcmp; |
| 3243 | /// Likewise for functions with the OptSize attribute. |
| 3244 | unsigned MaxLoadsPerMemcmpOptSize; |
| 3245 | |
| 3246 | /// \brief Specify maximum number of store instructions per memmove call. |
| 3247 | /// |
| 3248 | /// When lowering \@llvm.memmove this field specifies the maximum number of |
| 3249 | /// store instructions that may be substituted for a call to memmove. Targets |
| 3250 | /// must set this value based on the cost threshold for that target. Targets |
| 3251 | /// should assume that the memmove will be done using as many of the largest |
| 3252 | /// store operations first, followed by smaller ones, if necessary, per |
| 3253 | /// alignment restrictions. For example, moving 9 bytes on a 32-bit machine |
| 3254 | /// with 8-bit alignment would result in nine 1-byte stores. This only |
| 3255 | /// applies to copying a constant array of constant size. |
| 3256 | unsigned MaxStoresPerMemmove; |
| 3257 | /// Likewise for functions with the OptSize attribute. |
| 3258 | unsigned MaxStoresPerMemmoveOptSize; |
| 3259 | |
| 3260 | /// Tells the code generator that select is more expensive than a branch if |
| 3261 | /// the branch is usually predicted right. |
| 3262 | bool PredictableSelectIsExpensive; |
| 3263 | |
| 3264 | /// \see enableExtLdPromotion. |
| 3265 | bool EnableExtLdPromotion; |
| 3266 | |
| 3267 | /// Return true if the value types that can be represented by the specified |
| 3268 | /// register class are all legal. |
| 3269 | bool isLegalRC(const TargetRegisterInfo &TRI, |
| 3270 | const TargetRegisterClass &RC) const; |
| 3271 | |
| 3272 | /// Replace/modify any TargetFrameIndex operands with a targte-dependent |
| 3273 | /// sequence of memory operands that is recognized by PrologEpilogInserter. |
| 3274 | MachineBasicBlock *emitPatchPoint(MachineInstr &MI, |
| 3275 | MachineBasicBlock *MBB) const; |
| 3276 | |
| 3277 | bool IsStrictFPEnabled; |
| 3278 | }; |
| 3279 | |
| 3280 | /// This class defines information used to lower LLVM code to legal SelectionDAG |
| 3281 | /// operators that the target instruction selector can accept natively. |
| 3282 | /// |
| 3283 | /// This class also defines callbacks that targets must implement to lower |
| 3284 | /// target-specific constructs to SelectionDAG operators. |
| 3285 | class TargetLowering : public TargetLoweringBase { |
| 3286 | public: |
| 3287 | struct DAGCombinerInfo; |
| 3288 | struct MakeLibCallOptions; |
| 3289 | |
| 3290 | TargetLowering(const TargetLowering &) = delete; |
| 3291 | TargetLowering &operator=(const TargetLowering &) = delete; |
| 3292 | |
| 3293 | explicit TargetLowering(const TargetMachine &TM); |
| 3294 | |
| 3295 | bool isPositionIndependent() const; |
| 3296 | |
| 3297 | virtual bool isSDNodeSourceOfDivergence(const SDNode *N, |
| 3298 | FunctionLoweringInfo *FLI, |
| 3299 | LegacyDivergenceAnalysis *DA) const { |
| 3300 | return false; |
| 3301 | } |
| 3302 | |
| 3303 | // Lets target to control the following reassociation of operands: (op (op x, |
| 3304 | // c1), y) -> (op (op x, y), c1) where N0 is (op x, c1) and N1 is y. By |
| 3305 | // default consider profitable any case where N0 has single use. This |
| 3306 | // behavior reflects the condition replaced by this target hook call in the |
| 3307 | // DAGCombiner. Any particular target can implement its own heuristic to |
| 3308 | // restrict common combiner. |
| 3309 | virtual bool isReassocProfitable(SelectionDAG &DAG, SDValue N0, |
| 3310 | SDValue N1) const { |
| 3311 | return N0.hasOneUse(); |
| 3312 | } |
| 3313 | |
| 3314 | virtual bool isSDNodeAlwaysUniform(const SDNode * N) const { |
| 3315 | return false; |
| 3316 | } |
| 3317 | |
| 3318 | /// Returns true by value, base pointer and offset pointer and addressing mode |
| 3319 | /// by reference if the node's address can be legally represented as |
| 3320 | /// pre-indexed load / store address. |
| 3321 | virtual bool getPreIndexedAddressParts(SDNode * /*N*/, SDValue &/*Base*/, |
| 3322 | SDValue &/*Offset*/, |
| 3323 | ISD::MemIndexedMode &/*AM*/, |
| 3324 | SelectionDAG &/*DAG*/) const { |
| 3325 | return false; |
| 3326 | } |
| 3327 | |
| 3328 | /// Returns true by value, base pointer and offset pointer and addressing mode |
| 3329 | /// by reference if this node can be combined with a load / store to form a |
| 3330 | /// post-indexed load / store. |
| 3331 | virtual bool getPostIndexedAddressParts(SDNode * /*N*/, SDNode * /*Op*/, |
| 3332 | SDValue &/*Base*/, |
| 3333 | SDValue &/*Offset*/, |
| 3334 | ISD::MemIndexedMode &/*AM*/, |
| 3335 | SelectionDAG &/*DAG*/) const { |
| 3336 | return false; |
| 3337 | } |
| 3338 | |
| 3339 | /// Returns true if the specified base+offset is a legal indexed addressing |
| 3340 | /// mode for this target. \p MI is the load or store instruction that is being |
| 3341 | /// considered for transformation. |
| 3342 | virtual bool isIndexingLegal(MachineInstr &MI, Register Base, Register Offset, |
| 3343 | bool IsPre, MachineRegisterInfo &MRI) const { |
| 3344 | return false; |
| 3345 | } |
| 3346 | |
| 3347 | /// Return the entry encoding for a jump table in the current function. The |
| 3348 | /// returned value is a member of the MachineJumpTableInfo::JTEntryKind enum. |
| 3349 | virtual unsigned getJumpTableEncoding() const; |
| 3350 | |
| 3351 | virtual const MCExpr * |
| 3352 | LowerCustomJumpTableEntry(const MachineJumpTableInfo * /*MJTI*/, |
| 3353 | const MachineBasicBlock * /*MBB*/, unsigned /*uid*/, |
| 3354 | MCContext &/*Ctx*/) const { |
| 3355 | llvm_unreachable("Need to implement this hook if target has custom JTIs"); |
| 3356 | } |
| 3357 | |
| 3358 | /// Returns relocation base for the given PIC jumptable. |
| 3359 | virtual SDValue getPICJumpTableRelocBase(SDValue Table, |
| 3360 | SelectionDAG &DAG) const; |
| 3361 | |
| 3362 | /// This returns the relocation base for the given PIC jumptable, the same as |
| 3363 | /// getPICJumpTableRelocBase, but as an MCExpr. |
| 3364 | virtual const MCExpr * |
| 3365 | getPICJumpTableRelocBaseExpr(const MachineFunction *MF, |
| 3366 | unsigned JTI, MCContext &Ctx) const; |
| 3367 | |
| 3368 | /// Return true if folding a constant offset with the given GlobalAddress is |
| 3369 | /// legal. It is frequently not legal in PIC relocation models. |
| 3370 | virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const; |
| 3371 | |
| 3372 | bool isInTailCallPosition(SelectionDAG &DAG, SDNode *Node, |
| 3373 | SDValue &Chain) const; |
| 3374 | |
| 3375 | void softenSetCCOperands(SelectionDAG &DAG, EVT VT, SDValue &NewLHS, |
| 3376 | SDValue &NewRHS, ISD::CondCode &CCCode, |
| 3377 | const SDLoc &DL, const SDValue OldLHS, |
| 3378 | const SDValue OldRHS) const; |
| 3379 | |
| 3380 | void softenSetCCOperands(SelectionDAG &DAG, EVT VT, SDValue &NewLHS, |
| 3381 | SDValue &NewRHS, ISD::CondCode &CCCode, |
| 3382 | const SDLoc &DL, const SDValue OldLHS, |
| 3383 | const SDValue OldRHS, SDValue &Chain, |
| 3384 | bool IsSignaling = false) const; |
| 3385 | |
| 3386 | /// Returns a pair of (return value, chain). |
| 3387 | /// It is an error to pass RTLIB::UNKNOWN_LIBCALL as \p LC. |
| 3388 | std::pair<SDValue, SDValue> makeLibCall(SelectionDAG &DAG, RTLIB::Libcall LC, |
| 3389 | EVT RetVT, ArrayRef<SDValue> Ops, |
| 3390 | MakeLibCallOptions CallOptions, |
| 3391 | const SDLoc &dl, |
| 3392 | SDValue Chain = SDValue()) const; |
| 3393 | |
| 3394 | /// Check whether parameters to a call that are passed in callee saved |
| 3395 | /// registers are the same as from the calling function. This needs to be |
| 3396 | /// checked for tail call eligibility. |
| 3397 | bool parametersInCSRMatch(const MachineRegisterInfo &MRI, |
| 3398 | const uint32_t *CallerPreservedMask, |
| 3399 | const SmallVectorImpl<CCValAssign> &ArgLocs, |
| 3400 | const SmallVectorImpl<SDValue> &OutVals) const; |
| 3401 | |
| 3402 | //===--------------------------------------------------------------------===// |
| 3403 | // TargetLowering Optimization Methods |
| 3404 | // |
| 3405 | |
| 3406 | /// A convenience struct that encapsulates a DAG, and two SDValues for |
| 3407 | /// returning information from TargetLowering to its clients that want to |
| 3408 | /// combine. |
| 3409 | struct TargetLoweringOpt { |
| 3410 | SelectionDAG &DAG; |
| 3411 | bool LegalTys; |
| 3412 | bool LegalOps; |
| 3413 | SDValue Old; |
| 3414 | SDValue New; |
| 3415 | |
| 3416 | explicit TargetLoweringOpt(SelectionDAG &InDAG, |
| 3417 | bool LT, bool LO) : |
| 3418 | DAG(InDAG), LegalTys(LT), LegalOps(LO) {} |
| 3419 | |
| 3420 | bool LegalTypes() const { return LegalTys; } |
| 3421 | bool LegalOperations() const { return LegalOps; } |
| 3422 | |
| 3423 | bool CombineTo(SDValue O, SDValue N) { |
| 3424 | Old = O; |
| 3425 | New = N; |
| 3426 | return true; |
| 3427 | } |
| 3428 | }; |
| 3429 | |
| 3430 | /// Determines the optimal series of memory ops to replace the memset / memcpy. |
| 3431 | /// Return true if the number of memory ops is below the threshold (Limit). |
| 3432 | /// It returns the types of the sequence of memory ops to perform |
| 3433 | /// memset / memcpy by reference. |
| 3434 | bool findOptimalMemOpLowering(std::vector<EVT> &MemOps, unsigned Limit, |
| 3435 | const MemOp &Op, unsigned DstAS, unsigned SrcAS, |
| 3436 | const AttributeList &FuncAttributes) const; |
| 3437 | |
| 3438 | /// Check to see if the specified operand of the specified instruction is a |
| 3439 | /// constant integer. If so, check to see if there are any bits set in the |
| 3440 | /// constant that are not demanded. If so, shrink the constant and return |
| 3441 | /// true. |
| 3442 | bool ShrinkDemandedConstant(SDValue Op, const APInt &DemandedBits, |
| 3443 | const APInt &DemandedElts, |
| 3444 | TargetLoweringOpt &TLO) const; |
| 3445 | |
| 3446 | /// Helper wrapper around ShrinkDemandedConstant, demanding all elements. |
| 3447 | bool ShrinkDemandedConstant(SDValue Op, const APInt &DemandedBits, |
| 3448 | TargetLoweringOpt &TLO) const; |
| 3449 | |
| 3450 | // Target hook to do target-specific const optimization, which is called by |
| 3451 | // ShrinkDemandedConstant. This function should return true if the target |
| 3452 | // doesn't want ShrinkDemandedConstant to further optimize the constant. |
| 3453 | virtual bool targetShrinkDemandedConstant(SDValue Op, |
| 3454 | const APInt &DemandedBits, |
| 3455 | const APInt &DemandedElts, |
| 3456 | TargetLoweringOpt &TLO) const { |
| 3457 | return false; |
| 3458 | } |
| 3459 | |
| 3460 | /// Convert x+y to (VT)((SmallVT)x+(SmallVT)y) if the casts are free. This |
| 3461 | /// uses isZExtFree and ZERO_EXTEND for the widening cast, but it could be |
| 3462 | /// generalized for targets with other types of implicit widening casts. |
| 3463 | bool ShrinkDemandedOp(SDValue Op, unsigned BitWidth, const APInt &Demanded, |
| 3464 | TargetLoweringOpt &TLO) const; |
| 3465 | |
| 3466 | /// Look at Op. At this point, we know that only the DemandedBits bits of the |
| 3467 | /// result of Op are ever used downstream. If we can use this information to |
| 3468 | /// simplify Op, create a new simplified DAG node and return true, returning |
| 3469 | /// the original and new nodes in Old and New. Otherwise, analyze the |
| 3470 | /// expression and return a mask of KnownOne and KnownZero bits for the |
| 3471 | /// expression (used to simplify the caller). The KnownZero/One bits may only |
| 3472 | /// be accurate for those bits in the Demanded masks. |
| 3473 | /// \p AssumeSingleUse When this parameter is true, this function will |
| 3474 | /// attempt to simplify \p Op even if there are multiple uses. |
| 3475 | /// Callers are responsible for correctly updating the DAG based on the |
| 3476 | /// results of this function, because simply replacing replacing TLO.Old |
| 3477 | /// with TLO.New will be incorrect when this parameter is true and TLO.Old |
| 3478 | /// has multiple uses. |
| 3479 | bool SimplifyDemandedBits(SDValue Op, const APInt &DemandedBits, |
| 3480 | const APInt &DemandedElts, KnownBits &Known, |
| 3481 | TargetLoweringOpt &TLO, unsigned Depth = 0, |
| 3482 | bool AssumeSingleUse = false) const; |
| 3483 | |
| 3484 | /// Helper wrapper around SimplifyDemandedBits, demanding all elements. |
| 3485 | /// Adds Op back to the worklist upon success. |
| 3486 | bool SimplifyDemandedBits(SDValue Op, const APInt &DemandedBits, |
| 3487 | KnownBits &Known, TargetLoweringOpt &TLO, |
| 3488 | unsigned Depth = 0, |
| 3489 | bool AssumeSingleUse = false) const; |
| 3490 | |
| 3491 | /// Helper wrapper around SimplifyDemandedBits. |
| 3492 | /// Adds Op back to the worklist upon success. |
| 3493 | bool SimplifyDemandedBits(SDValue Op, const APInt &DemandedBits, |
| 3494 | DAGCombinerInfo &DCI) const; |
| 3495 | |
| 3496 | /// Helper wrapper around SimplifyDemandedBits. |
| 3497 | /// Adds Op back to the worklist upon success. |
| 3498 | bool SimplifyDemandedBits(SDValue Op, const APInt &DemandedBits, |
| 3499 | const APInt &DemandedElts, |
| 3500 | DAGCombinerInfo &DCI) const; |
| 3501 | |
| 3502 | /// More limited version of SimplifyDemandedBits that can be used to "look |
| 3503 | /// through" ops that don't contribute to the DemandedBits/DemandedElts - |
| 3504 | /// bitwise ops etc. |
| 3505 | SDValue SimplifyMultipleUseDemandedBits(SDValue Op, const APInt &DemandedBits, |
| 3506 | const APInt &DemandedElts, |
| 3507 | SelectionDAG &DAG, |
| 3508 | unsigned Depth = 0) const; |
| 3509 | |
| 3510 | /// Helper wrapper around SimplifyMultipleUseDemandedBits, demanding all |
| 3511 | /// elements. |
| 3512 | SDValue SimplifyMultipleUseDemandedBits(SDValue Op, const APInt &DemandedBits, |
| 3513 | SelectionDAG &DAG, |
| 3514 | unsigned Depth = 0) const; |
| 3515 | |
| 3516 | /// Helper wrapper around SimplifyMultipleUseDemandedBits, demanding all |
| 3517 | /// bits from only some vector elements. |
| 3518 | SDValue SimplifyMultipleUseDemandedVectorElts(SDValue Op, |
| 3519 | const APInt &DemandedElts, |
| 3520 | SelectionDAG &DAG, |
| 3521 | unsigned Depth = 0) const; |
| 3522 | |
| 3523 | /// Look at Vector Op. At this point, we know that only the DemandedElts |
| 3524 | /// elements of the result of Op are ever used downstream. If we can use |
| 3525 | /// this information to simplify Op, create a new simplified DAG node and |
| 3526 | /// return true, storing the original and new nodes in TLO. |
| 3527 | /// Otherwise, analyze the expression and return a mask of KnownUndef and |
| 3528 | /// KnownZero elements for the expression (used to simplify the caller). |
| 3529 | /// The KnownUndef/Zero elements may only be accurate for those bits |
| 3530 | /// in the DemandedMask. |
| 3531 | /// \p AssumeSingleUse When this parameter is true, this function will |
| 3532 | /// attempt to simplify \p Op even if there are multiple uses. |
| 3533 | /// Callers are responsible for correctly updating the DAG based on the |
| 3534 | /// results of this function, because simply replacing replacing TLO.Old |
| 3535 | /// with TLO.New will be incorrect when this parameter is true and TLO.Old |
| 3536 | /// has multiple uses. |
| 3537 | bool SimplifyDemandedVectorElts(SDValue Op, const APInt &DemandedEltMask, |
| 3538 | APInt &KnownUndef, APInt &KnownZero, |
| 3539 | TargetLoweringOpt &TLO, unsigned Depth = 0, |
| 3540 | bool AssumeSingleUse = false) const; |
| 3541 | |
| 3542 | /// Helper wrapper around SimplifyDemandedVectorElts. |
| 3543 | /// Adds Op back to the worklist upon success. |
| 3544 | bool SimplifyDemandedVectorElts(SDValue Op, const APInt &DemandedElts, |
| 3545 | APInt &KnownUndef, APInt &KnownZero, |
| 3546 | DAGCombinerInfo &DCI) const; |
| 3547 | |
| 3548 | /// Determine which of the bits specified in Mask are known to be either zero |
| 3549 | /// or one and return them in the KnownZero/KnownOne bitsets. The DemandedElts |
| 3550 | /// argument allows us to only collect the known bits that are shared by the |
| 3551 | /// requested vector elements. |
| 3552 | virtual void computeKnownBitsForTargetNode(const SDValue Op, |
| 3553 | KnownBits &Known, |
| 3554 | const APInt &DemandedElts, |
| 3555 | const SelectionDAG &DAG, |
| 3556 | unsigned Depth = 0) const; |
| 3557 | |
| 3558 | /// Determine which of the bits specified in Mask are known to be either zero |
| 3559 | /// or one and return them in the KnownZero/KnownOne bitsets. The DemandedElts |
| 3560 | /// argument allows us to only collect the known bits that are shared by the |
| 3561 | /// requested vector elements. This is for GISel. |
| 3562 | virtual void computeKnownBitsForTargetInstr(GISelKnownBits &Analysis, |
| 3563 | Register R, KnownBits &Known, |
| 3564 | const APInt &DemandedElts, |
| 3565 | const MachineRegisterInfo &MRI, |
| 3566 | unsigned Depth = 0) const; |
| 3567 | |
| 3568 | /// Determine the known alignment for the pointer value \p R. This is can |
| 3569 | /// typically be inferred from the number of low known 0 bits. However, for a |
| 3570 | /// pointer with a non-integral address space, the alignment value may be |
| 3571 | /// independent from the known low bits. |
| 3572 | virtual Align computeKnownAlignForTargetInstr(GISelKnownBits &Analysis, |
| 3573 | Register R, |
| 3574 | const MachineRegisterInfo &MRI, |
| 3575 | unsigned Depth = 0) const; |
| 3576 | |
| 3577 | /// Determine which of the bits of FrameIndex \p FIOp are known to be 0. |
| 3578 | /// Default implementation computes low bits based on alignment |
| 3579 | /// information. This should preserve known bits passed into it. |
| 3580 | virtual void computeKnownBitsForFrameIndex(int FIOp, |
| 3581 | KnownBits &Known, |
| 3582 | const MachineFunction &MF) const; |
| 3583 | |
| 3584 | /// This method can be implemented by targets that want to expose additional |
| 3585 | /// information about sign bits to the DAG Combiner. The DemandedElts |
| 3586 | /// argument allows us to only collect the minimum sign bits that are shared |
| 3587 | /// by the requested vector elements. |
| 3588 | virtual unsigned ComputeNumSignBitsForTargetNode(SDValue Op, |
| 3589 | const APInt &DemandedElts, |
| 3590 | const SelectionDAG &DAG, |
| 3591 | unsigned Depth = 0) const; |
| 3592 | |
| 3593 | /// This method can be implemented by targets that want to expose additional |
| 3594 | /// information about sign bits to GlobalISel combiners. The DemandedElts |
| 3595 | /// argument allows us to only collect the minimum sign bits that are shared |
| 3596 | /// by the requested vector elements. |
| 3597 | virtual unsigned computeNumSignBitsForTargetInstr(GISelKnownBits &Analysis, |
| 3598 | Register R, |
| 3599 | const APInt &DemandedElts, |
| 3600 | const MachineRegisterInfo &MRI, |
| 3601 | unsigned Depth = 0) const; |
| 3602 | |
| 3603 | /// Attempt to simplify any target nodes based on the demanded vector |
| 3604 | /// elements, returning true on success. Otherwise, analyze the expression and |
| 3605 | /// return a mask of KnownUndef and KnownZero elements for the expression |
| 3606 | /// (used to simplify the caller). The KnownUndef/Zero elements may only be |
| 3607 | /// accurate for those bits in the DemandedMask. |
| 3608 | virtual bool SimplifyDemandedVectorEltsForTargetNode( |
| 3609 | SDValue Op, const APInt &DemandedElts, APInt &KnownUndef, |
| 3610 | APInt &KnownZero, TargetLoweringOpt &TLO, unsigned Depth = 0) const; |
| 3611 | |
| 3612 | /// Attempt to simplify any target nodes based on the demanded bits/elts, |
| 3613 | /// returning true on success. Otherwise, analyze the |
| 3614 | /// expression and return a mask of KnownOne and KnownZero bits for the |
| 3615 | /// expression (used to simplify the caller). The KnownZero/One bits may only |
| 3616 | /// be accurate for those bits in the Demanded masks. |
| 3617 | virtual bool SimplifyDemandedBitsForTargetNode(SDValue Op, |
| 3618 | const APInt &DemandedBits, |
| 3619 | const APInt &DemandedElts, |
| 3620 | KnownBits &Known, |
| 3621 | TargetLoweringOpt &TLO, |
| 3622 | unsigned Depth = 0) const; |
| 3623 | |
| 3624 | /// More limited version of SimplifyDemandedBits that can be used to "look |
| 3625 | /// through" ops that don't contribute to the DemandedBits/DemandedElts - |
| 3626 | /// bitwise ops etc. |
| 3627 | virtual SDValue SimplifyMultipleUseDemandedBitsForTargetNode( |
| 3628 | SDValue Op, const APInt &DemandedBits, const APInt &DemandedElts, |
| 3629 | SelectionDAG &DAG, unsigned Depth) const; |
| 3630 | |
| 3631 | /// Return true if this function can prove that \p Op is never poison |
| 3632 | /// and, if \p PoisonOnly is false, does not have undef bits. The DemandedElts |
| 3633 | /// argument limits the check to the requested vector elements. |
| 3634 | virtual bool isGuaranteedNotToBeUndefOrPoisonForTargetNode( |
| 3635 | SDValue Op, const APInt &DemandedElts, const SelectionDAG &DAG, |
| 3636 | bool PoisonOnly, unsigned Depth) const; |
| 3637 | |
| 3638 | /// Tries to build a legal vector shuffle using the provided parameters |
| 3639 | /// or equivalent variations. The Mask argument maybe be modified as the |
| 3640 | /// function tries different variations. |
| 3641 | /// Returns an empty SDValue if the operation fails. |
| 3642 | SDValue buildLegalVectorShuffle(EVT VT, const SDLoc &DL, SDValue N0, |
| 3643 | SDValue N1, MutableArrayRef<int> Mask, |
| 3644 | SelectionDAG &DAG) const; |
| 3645 | |
| 3646 | /// This method returns the constant pool value that will be loaded by LD. |
| 3647 | /// NOTE: You must check for implicit extensions of the constant by LD. |
| 3648 | virtual const Constant *getTargetConstantFromLoad(LoadSDNode *LD) const; |
| 3649 | |
| 3650 | /// If \p SNaN is false, \returns true if \p Op is known to never be any |
| 3651 | /// NaN. If \p sNaN is true, returns if \p Op is known to never be a signaling |
| 3652 | /// NaN. |
| 3653 | virtual bool isKnownNeverNaNForTargetNode(SDValue Op, |
| 3654 | const SelectionDAG &DAG, |
| 3655 | bool SNaN = false, |
| 3656 | unsigned Depth = 0) const; |
| 3657 | |
| 3658 | /// Return true if vector \p Op has the same value across all \p DemandedElts, |
| 3659 | /// indicating any elements which may be undef in the output \p UndefElts. |
| 3660 | virtual bool isSplatValueForTargetNode(SDValue Op, const APInt &DemandedElts, |
| 3661 | APInt &UndefElts, |
| 3662 | unsigned Depth = 0) const; |
| 3663 | |
| 3664 | struct DAGCombinerInfo { |
| 3665 | void *DC; // The DAG Combiner object. |
| 3666 | CombineLevel Level; |
| 3667 | bool CalledByLegalizer; |
| 3668 | |
| 3669 | public: |
| 3670 | SelectionDAG &DAG; |
| 3671 | |
| 3672 | DAGCombinerInfo(SelectionDAG &dag, CombineLevel level, bool cl, void *dc) |
| 3673 | : DC(dc), Level(level), CalledByLegalizer(cl), DAG(dag) {} |
| 3674 | |
| 3675 | bool isBeforeLegalize() const { return Level == BeforeLegalizeTypes; } |
| 3676 | bool isBeforeLegalizeOps() const { return Level < AfterLegalizeVectorOps; } |
| 3677 | bool isAfterLegalizeDAG() const { return Level >= AfterLegalizeDAG; } |
| 3678 | CombineLevel getDAGCombineLevel() { return Level; } |
| 3679 | bool isCalledByLegalizer() const { return CalledByLegalizer; } |
| 3680 | |
| 3681 | void AddToWorklist(SDNode *N); |
| 3682 | SDValue CombineTo(SDNode *N, ArrayRef<SDValue> To, bool AddTo = true); |
| 3683 | SDValue CombineTo(SDNode *N, SDValue Res, bool AddTo = true); |
| 3684 | SDValue CombineTo(SDNode *N, SDValue Res0, SDValue Res1, bool AddTo = true); |
| 3685 | |
| 3686 | bool recursivelyDeleteUnusedNodes(SDNode *N); |
| 3687 | |
| 3688 | void CommitTargetLoweringOpt(const TargetLoweringOpt &TLO); |
| 3689 | }; |
| 3690 | |
| 3691 | /// Return if the N is a constant or constant vector equal to the true value |
| 3692 | /// from getBooleanContents(). |
| 3693 | bool isConstTrueVal(SDValue N) const; |
| 3694 | |
| 3695 | /// Return if the N is a constant or constant vector equal to the false value |
| 3696 | /// from getBooleanContents(). |
| 3697 | bool isConstFalseVal(SDValue N) const; |
| 3698 | |
| 3699 | /// Return if \p N is a True value when extended to \p VT. |
| 3700 | bool isExtendedTrueVal(const ConstantSDNode *N, EVT VT, bool SExt) const; |
| 3701 | |
| 3702 | /// Try to simplify a setcc built with the specified operands and cc. If it is |
| 3703 | /// unable to simplify it, return a null SDValue. |
| 3704 | SDValue SimplifySetCC(EVT VT, SDValue N0, SDValue N1, ISD::CondCode Cond, |
| 3705 | bool foldBooleans, DAGCombinerInfo &DCI, |
| 3706 | const SDLoc &dl) const; |
| 3707 | |
| 3708 | // For targets which wrap address, unwrap for analysis. |
| 3709 | virtual SDValue unwrapAddress(SDValue N) const { return N; } |
| 3710 | |
| 3711 | /// Returns true (and the GlobalValue and the offset) if the node is a |
| 3712 | /// GlobalAddress + offset. |
| 3713 | virtual bool |
| 3714 | isGAPlusOffset(SDNode *N, const GlobalValue* &GA, int64_t &Offset) const; |
| 3715 | |
| 3716 | /// This method will be invoked for all target nodes and for any |
| 3717 | /// target-independent nodes that the target has registered with invoke it |
| 3718 | /// for. |
| 3719 | /// |
| 3720 | /// The semantics are as follows: |
| 3721 | /// Return Value: |
| 3722 | /// SDValue.Val == 0 - No change was made |
| 3723 | /// SDValue.Val == N - N was replaced, is dead, and is already handled. |
| 3724 | /// otherwise - N should be replaced by the returned Operand. |
| 3725 | /// |
| 3726 | /// In addition, methods provided by DAGCombinerInfo may be used to perform |
| 3727 | /// more complex transformations. |
| 3728 | /// |
| 3729 | virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const; |
| 3730 | |
| 3731 | /// Return true if it is profitable to move this shift by a constant amount |
| 3732 | /// though its operand, adjusting any immediate operands as necessary to |
| 3733 | /// preserve semantics. This transformation may not be desirable if it |
| 3734 | /// disrupts a particularly auspicious target-specific tree (e.g. bitfield |
| 3735 | /// extraction in AArch64). By default, it returns true. |
| 3736 | /// |
| 3737 | /// @param N the shift node |
| 3738 | /// @param Level the current DAGCombine legalization level. |
| 3739 | virtual bool isDesirableToCommuteWithShift(const SDNode *N, |
| 3740 | CombineLevel Level) const { |
| 3741 | return true; |
| 3742 | } |
| 3743 | |
| 3744 | /// Return true if the target has native support for the specified value type |
| 3745 | /// and it is 'desirable' to use the type for the given node type. e.g. On x86 |
| 3746 | /// i16 is legal, but undesirable since i16 instruction encodings are longer |
| 3747 | /// and some i16 instructions are slow. |
| 3748 | virtual bool isTypeDesirableForOp(unsigned /*Opc*/, EVT VT) const { |
| 3749 | // By default, assume all legal types are desirable. |
| 3750 | return isTypeLegal(VT); |
| 3751 | } |
| 3752 | |
| 3753 | /// Return true if it is profitable for dag combiner to transform a floating |
| 3754 | /// point op of specified opcode to a equivalent op of an integer |
| 3755 | /// type. e.g. f32 load -> i32 load can be profitable on ARM. |
| 3756 | virtual bool isDesirableToTransformToIntegerOp(unsigned /*Opc*/, |
| 3757 | EVT /*VT*/) const { |
| 3758 | return false; |
| 3759 | } |
| 3760 | |
| 3761 | /// This method query the target whether it is beneficial for dag combiner to |
| 3762 | /// promote the specified node. If true, it should return the desired |
| 3763 | /// promotion type by reference. |
| 3764 | virtual bool IsDesirableToPromoteOp(SDValue /*Op*/, EVT &/*PVT*/) const { |
| 3765 | return false; |
| 3766 | } |
| 3767 | |
| 3768 | /// Return true if the target supports swifterror attribute. It optimizes |
| 3769 | /// loads and stores to reading and writing a specific register. |
| 3770 | virtual bool supportSwiftError() const { |
| 3771 | return false; |
| 3772 | } |
| 3773 | |
| 3774 | /// Return true if the target supports that a subset of CSRs for the given |
| 3775 | /// machine function is handled explicitly via copies. |
| 3776 | virtual bool supportSplitCSR(MachineFunction *MF) const { |
| 3777 | return false; |
| 3778 | } |
| 3779 | |
| 3780 | /// Perform necessary initialization to handle a subset of CSRs explicitly |
| 3781 | /// via copies. This function is called at the beginning of instruction |
| 3782 | /// selection. |
| 3783 | virtual void initializeSplitCSR(MachineBasicBlock *Entry) const { |
| 3784 | llvm_unreachable("Not Implemented"); |
| 3785 | } |
| 3786 | |
| 3787 | /// Insert explicit copies in entry and exit blocks. We copy a subset of |
| 3788 | /// CSRs to virtual registers in the entry block, and copy them back to |
| 3789 | /// physical registers in the exit blocks. This function is called at the end |
| 3790 | /// of instruction selection. |
| 3791 | virtual void insertCopiesSplitCSR( |
| 3792 | MachineBasicBlock *Entry, |
| 3793 | const SmallVectorImpl<MachineBasicBlock *> &Exits) const { |
| 3794 | llvm_unreachable("Not Implemented"); |
| 3795 | } |
| 3796 | |
| 3797 | /// Return the newly negated expression if the cost is not expensive and |
| 3798 | /// set the cost in \p Cost to indicate that if it is cheaper or neutral to |
| 3799 | /// do the negation. |
| 3800 | virtual SDValue getNegatedExpression(SDValue Op, SelectionDAG &DAG, |
| 3801 | bool LegalOps, bool OptForSize, |
| 3802 | NegatibleCost &Cost, |
| 3803 | unsigned Depth = 0) const; |
| 3804 | |
| 3805 | /// This is the helper function to return the newly negated expression only |
| 3806 | /// when the cost is cheaper. |
| 3807 | SDValue getCheaperNegatedExpression(SDValue Op, SelectionDAG &DAG, |
| 3808 | bool LegalOps, bool OptForSize, |
| 3809 | unsigned Depth = 0) const { |
| 3810 | NegatibleCost Cost = NegatibleCost::Expensive; |
| 3811 | SDValue Neg = |
| 3812 | getNegatedExpression(Op, DAG, LegalOps, OptForSize, Cost, Depth); |
| 3813 | if (Neg && Cost == NegatibleCost::Cheaper) |
| 3814 | return Neg; |
| 3815 | // Remove the new created node to avoid the side effect to the DAG. |
| 3816 | if (Neg && Neg.getNode()->use_empty()) |
| 3817 | DAG.RemoveDeadNode(Neg.getNode()); |
| 3818 | return SDValue(); |
| 3819 | } |
| 3820 | |
| 3821 | /// This is the helper function to return the newly negated expression if |
| 3822 | /// the cost is not expensive. |
| 3823 | SDValue getNegatedExpression(SDValue Op, SelectionDAG &DAG, bool LegalOps, |
| 3824 | bool OptForSize, unsigned Depth = 0) const { |
| 3825 | NegatibleCost Cost = NegatibleCost::Expensive; |
| 3826 | return getNegatedExpression(Op, DAG, LegalOps, OptForSize, Cost, Depth); |
| 3827 | } |
| 3828 | |
| 3829 | //===--------------------------------------------------------------------===// |
| 3830 | // Lowering methods - These methods must be implemented by targets so that |
| 3831 | // the SelectionDAGBuilder code knows how to lower these. |
| 3832 | // |
| 3833 | |
| 3834 | /// Target-specific splitting of values into parts that fit a register |
| 3835 | /// storing a legal type |
| 3836 | virtual bool splitValueIntoRegisterParts(SelectionDAG &DAG, const SDLoc &DL, |
| 3837 | SDValue Val, SDValue *Parts, |
| 3838 | unsigned NumParts, MVT PartVT, |
| 3839 | Optional<CallingConv::ID> CC) const { |
| 3840 | return false; |
| 3841 | } |
| 3842 | |
| 3843 | /// Target-specific combining of register parts into its original value |
| 3844 | virtual SDValue |
| 3845 | joinRegisterPartsIntoValue(SelectionDAG &DAG, const SDLoc &DL, |
| 3846 | const SDValue *Parts, unsigned NumParts, |
| 3847 | MVT PartVT, EVT ValueVT, |
| 3848 | Optional<CallingConv::ID> CC) const { |
| 3849 | return SDValue(); |
| 3850 | } |
| 3851 | |
| 3852 | /// This hook must be implemented to lower the incoming (formal) arguments, |
| 3853 | /// described by the Ins array, into the specified DAG. The implementation |
| 3854 | /// should fill in the InVals array with legal-type argument values, and |
| 3855 | /// return the resulting token chain value. |
| 3856 | virtual SDValue LowerFormalArguments( |
| 3857 | SDValue /*Chain*/, CallingConv::ID /*CallConv*/, bool /*isVarArg*/, |
| 3858 | const SmallVectorImpl<ISD::InputArg> & /*Ins*/, const SDLoc & /*dl*/, |
| 3859 | SelectionDAG & /*DAG*/, SmallVectorImpl<SDValue> & /*InVals*/) const { |
| 3860 | llvm_unreachable("Not Implemented"); |
| 3861 | } |
| 3862 | |
| 3863 | /// This structure contains all information that is necessary for lowering |
| 3864 | /// calls. It is passed to TLI::LowerCallTo when the SelectionDAG builder |
| 3865 | /// needs to lower a call, and targets will see this struct in their LowerCall |
| 3866 | /// implementation. |
| 3867 | struct CallLoweringInfo { |
| 3868 | SDValue Chain; |
| 3869 | Type *RetTy = nullptr; |
| 3870 | bool RetSExt : 1; |
| 3871 | bool RetZExt : 1; |
| 3872 | bool IsVarArg : 1; |
| 3873 | bool IsInReg : 1; |
| 3874 | bool DoesNotReturn : 1; |
| 3875 | bool IsReturnValueUsed : 1; |
| 3876 | bool IsConvergent : 1; |
| 3877 | bool IsPatchPoint : 1; |
| 3878 | bool IsPreallocated : 1; |
| 3879 | bool NoMerge : 1; |
| 3880 | |
| 3881 | // IsTailCall should be modified by implementations of |
| 3882 | // TargetLowering::LowerCall that perform tail call conversions. |
| 3883 | bool IsTailCall = false; |
| 3884 | |
| 3885 | // Is Call lowering done post SelectionDAG type legalization. |
| 3886 | bool IsPostTypeLegalization = false; |
| 3887 | |
| 3888 | unsigned NumFixedArgs = -1; |
| 3889 | CallingConv::ID CallConv = CallingConv::C; |
| 3890 | SDValue Callee; |
| 3891 | ArgListTy Args; |
| 3892 | SelectionDAG &DAG; |
| 3893 | SDLoc DL; |
| 3894 | const CallBase *CB = nullptr; |
| 3895 | SmallVector<ISD::OutputArg, 32> Outs; |
| 3896 | SmallVector<SDValue, 32> OutVals; |
| 3897 | SmallVector<ISD::InputArg, 32> Ins; |
| 3898 | SmallVector<SDValue, 4> InVals; |
| 3899 | |
| 3900 | CallLoweringInfo(SelectionDAG &DAG) |
| 3901 | : RetSExt(false), RetZExt(false), IsVarArg(false), IsInReg(false), |
| 3902 | DoesNotReturn(false), IsReturnValueUsed(true), IsConvergent(false), |
| 3903 | IsPatchPoint(false), IsPreallocated(false), NoMerge(false), |
| 3904 | DAG(DAG) {} |
| 3905 | |
| 3906 | CallLoweringInfo &setDebugLoc(const SDLoc &dl) { |
| 3907 | DL = dl; |
| 3908 | return *this; |
| 3909 | } |
| 3910 | |
| 3911 | CallLoweringInfo &setChain(SDValue InChain) { |
| 3912 | Chain = InChain; |
| 3913 | return *this; |
| 3914 | } |
| 3915 | |
| 3916 | // setCallee with target/module-specific attributes |
| 3917 | CallLoweringInfo &setLibCallee(CallingConv::ID CC, Type *ResultType, |
| 3918 | SDValue Target, ArgListTy &&ArgsList) { |
| 3919 | RetTy = ResultType; |
| 3920 | Callee = Target; |
| 3921 | CallConv = CC; |
| 3922 | NumFixedArgs = ArgsList.size(); |
| 3923 | Args = std::move(ArgsList); |
| 3924 | |
| 3925 | DAG.getTargetLoweringInfo().markLibCallAttributes( |
| 3926 | &(DAG.getMachineFunction()), CC, Args); |
| 3927 | return *this; |
| 3928 | } |
| 3929 | |
| 3930 | CallLoweringInfo &setCallee(CallingConv::ID CC, Type *ResultType, |
| 3931 | SDValue Target, ArgListTy &&ArgsList) { |
| 3932 | RetTy = ResultType; |
| 3933 | Callee = Target; |
| 3934 | CallConv = CC; |
| 3935 | NumFixedArgs = ArgsList.size(); |
| 3936 | Args = std::move(ArgsList); |
| 3937 | return *this; |
| 3938 | } |
| 3939 | |
| 3940 | CallLoweringInfo &setCallee(Type *ResultType, FunctionType *FTy, |
| 3941 | SDValue Target, ArgListTy &&ArgsList, |
| 3942 | const CallBase &Call) { |
| 3943 | RetTy = ResultType; |
| 3944 | |
| 3945 | IsInReg = Call.hasRetAttr(Attribute::InReg); |
| 3946 | DoesNotReturn = |
| 3947 | Call.doesNotReturn() || |
| 3948 | (!isa<InvokeInst>(Call) && isa<UnreachableInst>(Call.getNextNode())); |
| 3949 | IsVarArg = FTy->isVarArg(); |
| 3950 | IsReturnValueUsed = !Call.use_empty(); |
| 3951 | RetSExt = Call.hasRetAttr(Attribute::SExt); |
| 3952 | RetZExt = Call.hasRetAttr(Attribute::ZExt); |
| 3953 | NoMerge = Call.hasFnAttr(Attribute::NoMerge); |
| 3954 | |
| 3955 | Callee = Target; |
| 3956 | |
| 3957 | CallConv = Call.getCallingConv(); |
| 3958 | NumFixedArgs = FTy->getNumParams(); |
| 3959 | Args = std::move(ArgsList); |
| 3960 | |
| 3961 | CB = &Call; |
| 3962 | |
| 3963 | return *this; |
| 3964 | } |
| 3965 | |
| 3966 | CallLoweringInfo &setInRegister(bool Value = true) { |
| 3967 | IsInReg = Value; |
| 3968 | return *this; |
| 3969 | } |
| 3970 | |
| 3971 | CallLoweringInfo &setNoReturn(bool Value = true) { |
| 3972 | DoesNotReturn = Value; |
| 3973 | return *this; |
| 3974 | } |
| 3975 | |
| 3976 | CallLoweringInfo &setVarArg(bool Value = true) { |
| 3977 | IsVarArg = Value; |
| 3978 | return *this; |
| 3979 | } |
| 3980 | |
| 3981 | CallLoweringInfo &setTailCall(bool Value = true) { |
| 3982 | IsTailCall = Value; |
| 3983 | return *this; |
| 3984 | } |
| 3985 | |
| 3986 | CallLoweringInfo &setDiscardResult(bool Value = true) { |
| 3987 | IsReturnValueUsed = !Value; |
| 3988 | return *this; |
| 3989 | } |
| 3990 | |
| 3991 | CallLoweringInfo &setConvergent(bool Value = true) { |
| 3992 | IsConvergent = Value; |
| 3993 | return *this; |
| 3994 | } |
| 3995 | |
| 3996 | CallLoweringInfo &setSExtResult(bool Value = true) { |
| 3997 | RetSExt = Value; |
| 3998 | return *this; |
| 3999 | } |
| 4000 | |
| 4001 | CallLoweringInfo &setZExtResult(bool Value = true) { |
| 4002 | RetZExt = Value; |
| 4003 | return *this; |
| 4004 | } |
| 4005 | |
| 4006 | CallLoweringInfo &setIsPatchPoint(bool Value = true) { |
| 4007 | IsPatchPoint = Value; |
| 4008 | return *this; |
| 4009 | } |
| 4010 | |
| 4011 | CallLoweringInfo &setIsPreallocated(bool Value = true) { |
| 4012 | IsPreallocated = Value; |
| 4013 | return *this; |
| 4014 | } |
| 4015 | |
| 4016 | CallLoweringInfo &setIsPostTypeLegalization(bool Value=true) { |
| 4017 | IsPostTypeLegalization = Value; |
| 4018 | return *this; |
| 4019 | } |
| 4020 | |
| 4021 | ArgListTy &getArgs() { |
| 4022 | return Args; |
| 4023 | } |
| 4024 | }; |
| 4025 | |
| 4026 | /// This structure is used to pass arguments to makeLibCall function. |
| 4027 | struct MakeLibCallOptions { |
| 4028 | // By passing type list before soften to makeLibCall, the target hook |
| 4029 | // shouldExtendTypeInLibCall can get the original type before soften. |
| 4030 | ArrayRef<EVT> OpsVTBeforeSoften; |
| 4031 | EVT RetVTBeforeSoften; |
| 4032 | bool IsSExt : 1; |
| 4033 | bool DoesNotReturn : 1; |
| 4034 | bool IsReturnValueUsed : 1; |
| 4035 | bool IsPostTypeLegalization : 1; |
| 4036 | bool IsSoften : 1; |
| 4037 | |
| 4038 | MakeLibCallOptions() |
| 4039 | : IsSExt(false), DoesNotReturn(false), IsReturnValueUsed(true), |
| 4040 | IsPostTypeLegalization(false), IsSoften(false) {} |
| 4041 | |
| 4042 | MakeLibCallOptions &setSExt(bool Value = true) { |
| 4043 | IsSExt = Value; |
| 4044 | return *this; |
| 4045 | } |
| 4046 | |
| 4047 | MakeLibCallOptions &setNoReturn(bool Value = true) { |
| 4048 | DoesNotReturn = Value; |
| 4049 | return *this; |
| 4050 | } |
| 4051 | |
| 4052 | MakeLibCallOptions &setDiscardResult(bool Value = true) { |
| 4053 | IsReturnValueUsed = !Value; |
| 4054 | return *this; |
| 4055 | } |
| 4056 | |
| 4057 | MakeLibCallOptions &setIsPostTypeLegalization(bool Value = true) { |
| 4058 | IsPostTypeLegalization = Value; |
| 4059 | return *this; |
| 4060 | } |
| 4061 | |
| 4062 | MakeLibCallOptions &setTypeListBeforeSoften(ArrayRef<EVT> OpsVT, EVT RetVT, |
| 4063 | bool Value = true) { |
| 4064 | OpsVTBeforeSoften = OpsVT; |
| 4065 | RetVTBeforeSoften = RetVT; |
| 4066 | IsSoften = Value; |
| 4067 | return *this; |
| 4068 | } |
| 4069 | }; |
| 4070 | |
| 4071 | /// This function lowers an abstract call to a function into an actual call. |
| 4072 | /// This returns a pair of operands. The first element is the return value |
| 4073 | /// for the function (if RetTy is not VoidTy). The second element is the |
| 4074 | /// outgoing token chain. It calls LowerCall to do the actual lowering. |
| 4075 | std::pair<SDValue, SDValue> LowerCallTo(CallLoweringInfo &CLI) const; |
| 4076 | |
| 4077 | /// This hook must be implemented to lower calls into the specified |
| 4078 | /// DAG. The outgoing arguments to the call are described by the Outs array, |
| 4079 | /// and the values to be returned by the call are described by the Ins |
| 4080 | /// array. The implementation should fill in the InVals array with legal-type |
| 4081 | /// return values from the call, and return the resulting token chain value. |
| 4082 | virtual SDValue |
| 4083 | LowerCall(CallLoweringInfo &/*CLI*/, |
| 4084 | SmallVectorImpl<SDValue> &/*InVals*/) const { |
| 4085 | llvm_unreachable("Not Implemented"); |
| 4086 | } |
| 4087 | |
| 4088 | /// Target-specific cleanup for formal ByVal parameters. |
| 4089 | virtual void HandleByVal(CCState *, unsigned &, Align) const {} |
| 4090 | |
| 4091 | /// This hook should be implemented to check whether the return values |
| 4092 | /// described by the Outs array can fit into the return registers. If false |
| 4093 | /// is returned, an sret-demotion is performed. |
| 4094 | virtual bool CanLowerReturn(CallingConv::ID /*CallConv*/, |
| 4095 | MachineFunction &/*MF*/, bool /*isVarArg*/, |
| 4096 | const SmallVectorImpl<ISD::OutputArg> &/*Outs*/, |
| 4097 | LLVMContext &/*Context*/) const |
| 4098 | { |
| 4099 | // Return true by default to get preexisting behavior. |
| 4100 | return true; |
| 4101 | } |
| 4102 | |
| 4103 | /// This hook must be implemented to lower outgoing return values, described |
| 4104 | /// by the Outs array, into the specified DAG. The implementation should |
| 4105 | /// return the resulting token chain value. |
| 4106 | virtual SDValue LowerReturn(SDValue /*Chain*/, CallingConv::ID /*CallConv*/, |
| 4107 | bool /*isVarArg*/, |
| 4108 | const SmallVectorImpl<ISD::OutputArg> & /*Outs*/, |
| 4109 | const SmallVectorImpl<SDValue> & /*OutVals*/, |
| 4110 | const SDLoc & /*dl*/, |
| 4111 | SelectionDAG & /*DAG*/) const { |
| 4112 | llvm_unreachable("Not Implemented"); |
| 4113 | } |
| 4114 | |
| 4115 | /// Return true if result of the specified node is used by a return node |
| 4116 | /// only. It also compute and return the input chain for the tail call. |
| 4117 | /// |
| 4118 | /// This is used to determine whether it is possible to codegen a libcall as |
| 4119 | /// tail call at legalization time. |
| 4120 | virtual bool isUsedByReturnOnly(SDNode *, SDValue &/*Chain*/) const { |
| 4121 | return false; |
| 4122 | } |
| 4123 | |
| 4124 | /// Return true if the target may be able emit the call instruction as a tail |
| 4125 | /// call. This is used by optimization passes to determine if it's profitable |
| 4126 | /// to duplicate return instructions to enable tailcall optimization. |
| 4127 | virtual bool mayBeEmittedAsTailCall(const CallInst *) const { |
| 4128 | return false; |
| 4129 | } |
| 4130 | |
| 4131 | /// Return the builtin name for the __builtin___clear_cache intrinsic |
| 4132 | /// Default is to invoke the clear cache library call |
| 4133 | virtual const char * getClearCacheBuiltinName() const { |
| 4134 | return "__clear_cache"; |
| 4135 | } |
| 4136 | |
| 4137 | /// Return the register ID of the name passed in. Used by named register |
| 4138 | /// global variables extension. There is no target-independent behaviour |
| 4139 | /// so the default action is to bail. |
| 4140 | virtual Register getRegisterByName(const char* RegName, LLT Ty, |
| 4141 | const MachineFunction &MF) const { |
| 4142 | report_fatal_error("Named registers not implemented for this target"); |
| 4143 | } |
| 4144 | |
| 4145 | /// Return the type that should be used to zero or sign extend a |
| 4146 | /// zeroext/signext integer return value. FIXME: Some C calling conventions |
| 4147 | /// require the return type to be promoted, but this is not true all the time, |
| 4148 | /// e.g. i1/i8/i16 on x86/x86_64. It is also not necessary for non-C calling |
| 4149 | /// conventions. The frontend should handle this and include all of the |
| 4150 | /// necessary information. |
| 4151 | virtual EVT getTypeForExtReturn(LLVMContext &Context, EVT VT, |
| 4152 | ISD::NodeType /*ExtendKind*/) const { |
| 4153 | EVT MinVT = getRegisterType(Context, MVT::i32); |
| 4154 | return VT.bitsLT(MinVT) ? MinVT : VT; |
| 4155 | } |
| 4156 | |
| 4157 | /// For some targets, an LLVM struct type must be broken down into multiple |
| 4158 | /// simple types, but the calling convention specifies that the entire struct |
| 4159 | /// must be passed in a block of consecutive registers. |
| 4160 | virtual bool |
| 4161 | functionArgumentNeedsConsecutiveRegisters(Type *Ty, CallingConv::ID CallConv, |
| 4162 | bool isVarArg, |
| 4163 | const DataLayout &DL) const { |
| 4164 | return false; |
| 4165 | } |
| 4166 | |
| 4167 | /// For most targets, an LLVM type must be broken down into multiple |
| 4168 | /// smaller types. Usually the halves are ordered according to the endianness |
| 4169 | /// but for some platform that would break. So this method will default to |
| 4170 | /// matching the endianness but can be overridden. |
| 4171 | virtual bool |
| 4172 | shouldSplitFunctionArgumentsAsLittleEndian(const DataLayout &DL) const { |
| 4173 | return DL.isLittleEndian(); |
| 4174 | } |
| 4175 | |
| 4176 | /// Returns a 0 terminated array of registers that can be safely used as |
| 4177 | /// scratch registers. |
| 4178 | virtual const MCPhysReg *getScratchRegisters(CallingConv::ID CC) const { |
| 4179 | return nullptr; |
| 4180 | } |
| 4181 | |
| 4182 | /// This callback is used to prepare for a volatile or atomic load. |
| 4183 | /// It takes a chain node as input and returns the chain for the load itself. |
| 4184 | /// |
| 4185 | /// Having a callback like this is necessary for targets like SystemZ, |
| 4186 | /// which allows a CPU to reuse the result of a previous load indefinitely, |
| 4187 | /// even if a cache-coherent store is performed by another CPU. The default |
| 4188 | /// implementation does nothing. |
| 4189 | virtual SDValue prepareVolatileOrAtomicLoad(SDValue Chain, const SDLoc &DL, |
| 4190 | SelectionDAG &DAG) const { |
| 4191 | return Chain; |
| 4192 | } |
| 4193 | |
| 4194 | /// Should SelectionDAG lower an atomic store of the given kind as a normal |
| 4195 | /// StoreSDNode (as opposed to an AtomicSDNode)? NOTE: The intention is to |
| 4196 | /// eventually migrate all targets to the using StoreSDNodes, but porting is |
| 4197 | /// being done target at a time. |
| 4198 | virtual bool lowerAtomicStoreAsStoreSDNode(const StoreInst &SI) const { |
| 4199 | assert(SI.isAtomic() && "violated precondition"); |
| 4200 | return false; |
| 4201 | } |
| 4202 | |
| 4203 | /// Should SelectionDAG lower an atomic load of the given kind as a normal |
| 4204 | /// LoadSDNode (as opposed to an AtomicSDNode)? NOTE: The intention is to |
| 4205 | /// eventually migrate all targets to the using LoadSDNodes, but porting is |
| 4206 | /// being done target at a time. |
| 4207 | virtual bool lowerAtomicLoadAsLoadSDNode(const LoadInst &LI) const { |
| 4208 | assert(LI.isAtomic() && "violated precondition"); |
| 4209 | return false; |
| 4210 | } |
| 4211 | |
| 4212 | |
| 4213 | /// This callback is invoked by the type legalizer to legalize nodes with an |
| 4214 | /// illegal operand type but legal result types. It replaces the |
| 4215 | /// LowerOperation callback in the type Legalizer. The reason we can not do |
| 4216 | /// away with LowerOperation entirely is that LegalizeDAG isn't yet ready to |
| 4217 | /// use this callback. |
| 4218 | /// |
| 4219 | /// TODO: Consider merging with ReplaceNodeResults. |
| 4220 | /// |
| 4221 | /// The target places new result values for the node in Results (their number |
| 4222 | /// and types must exactly match those of the original return values of |
| 4223 | /// the node), or leaves Results empty, which indicates that the node is not |
| 4224 | /// to be custom lowered after all. |
| 4225 | /// The default implementation calls LowerOperation. |
| 4226 | virtual void LowerOperationWrapper(SDNode *N, |
| 4227 | SmallVectorImpl<SDValue> &Results, |
| 4228 | SelectionDAG &DAG) const; |
| 4229 | |
| 4230 | /// This callback is invoked for operations that are unsupported by the |
| 4231 | /// target, which are registered to use 'custom' lowering, and whose defined |
| 4232 | /// values are all legal. If the target has no operations that require custom |
| 4233 | /// lowering, it need not implement this. The default implementation of this |
| 4234 | /// aborts. |
| 4235 | virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const; |
| 4236 | |
| 4237 | /// This callback is invoked when a node result type is illegal for the |
| 4238 | /// target, and the operation was registered to use 'custom' lowering for that |
| 4239 | /// result type. The target places new result values for the node in Results |
| 4240 | /// (their number and types must exactly match those of the original return |
| 4241 | /// values of the node), or leaves Results empty, which indicates that the |
| 4242 | /// node is not to be custom lowered after all. |
| 4243 | /// |
| 4244 | /// If the target has no operations that require custom lowering, it need not |
| 4245 | /// implement this. The default implementation aborts. |
| 4246 | virtual void ReplaceNodeResults(SDNode * /*N*/, |
| 4247 | SmallVectorImpl<SDValue> &/*Results*/, |
| 4248 | SelectionDAG &/*DAG*/) const { |
| 4249 | llvm_unreachable("ReplaceNodeResults not implemented for this target!"); |
| 4250 | } |
| 4251 | |
| 4252 | /// This method returns the name of a target specific DAG node. |
| 4253 | virtual const char *getTargetNodeName(unsigned Opcode) const; |
| 4254 | |
| 4255 | /// This method returns a target specific FastISel object, or null if the |
| 4256 | /// target does not support "fast" ISel. |
| 4257 | virtual FastISel *createFastISel(FunctionLoweringInfo &, |
| 4258 | const TargetLibraryInfo *) const { |
| 4259 | return nullptr; |
| 4260 | } |
| 4261 | |
| 4262 | bool verifyReturnAddressArgumentIsConstant(SDValue Op, |
| 4263 | SelectionDAG &DAG) const; |
| 4264 | |
| 4265 | //===--------------------------------------------------------------------===// |
| 4266 | // Inline Asm Support hooks |
| 4267 | // |
| 4268 | |
| 4269 | /// This hook allows the target to expand an inline asm call to be explicit |
| 4270 | /// llvm code if it wants to. This is useful for turning simple inline asms |
| 4271 | /// into LLVM intrinsics, which gives the compiler more information about the |
| 4272 | /// behavior of the code. |
| 4273 | virtual bool ExpandInlineAsm(CallInst *) const { |
| 4274 | return false; |
| 4275 | } |
| 4276 | |
| 4277 | enum ConstraintType { |
| 4278 | C_Register, // Constraint represents specific register(s). |
| 4279 | C_RegisterClass, // Constraint represents any of register(s) in class. |
| 4280 | C_Memory, // Memory constraint. |
| 4281 | C_Immediate, // Requires an immediate. |
| 4282 | C_Other, // Something else. |
| 4283 | C_Unknown // Unsupported constraint. |
| 4284 | }; |
| 4285 | |
| 4286 | enum ConstraintWeight { |
| 4287 | // Generic weights. |
| 4288 | CW_Invalid = -1, // No match. |
| 4289 | CW_Okay = 0, // Acceptable. |
| 4290 | CW_Good = 1, // Good weight. |
| 4291 | CW_Better = 2, // Better weight. |
| 4292 | CW_Best = 3, // Best weight. |
| 4293 | |
| 4294 | // Well-known weights. |
| 4295 | CW_SpecificReg = CW_Okay, // Specific register operands. |
| 4296 | CW_Register = CW_Good, // Register operands. |
| 4297 | CW_Memory = CW_Better, // Memory operands. |
| 4298 | CW_Constant = CW_Best, // Constant operand. |
| 4299 | CW_Default = CW_Okay // Default or don't know type. |
| 4300 | }; |
| 4301 | |
| 4302 | /// This contains information for each constraint that we are lowering. |
| 4303 | struct AsmOperandInfo : public InlineAsm::ConstraintInfo { |
| 4304 | /// This contains the actual string for the code, like "m". TargetLowering |
| 4305 | /// picks the 'best' code from ConstraintInfo::Codes that most closely |
| 4306 | /// matches the operand. |
| 4307 | std::string ConstraintCode; |
| 4308 | |
| 4309 | /// Information about the constraint code, e.g. Register, RegisterClass, |
| 4310 | /// Memory, Other, Unknown. |
| 4311 | TargetLowering::ConstraintType ConstraintType = TargetLowering::C_Unknown; |
| 4312 | |
| 4313 | /// If this is the result output operand or a clobber, this is null, |
| 4314 | /// otherwise it is the incoming operand to the CallInst. This gets |
| 4315 | /// modified as the asm is processed. |
| 4316 | Value *CallOperandVal = nullptr; |
| 4317 | |
| 4318 | /// The ValueType for the operand value. |
| 4319 | MVT ConstraintVT = MVT::Other; |
| 4320 | |
| 4321 | /// Copy constructor for copying from a ConstraintInfo. |
| 4322 | AsmOperandInfo(InlineAsm::ConstraintInfo Info) |
| 4323 | : InlineAsm::ConstraintInfo(std::move(Info)) {} |
| 4324 | |
| 4325 | /// Return true of this is an input operand that is a matching constraint |
| 4326 | /// like "4". |
| 4327 | bool isMatchingInputConstraint() const; |
| 4328 | |
| 4329 | /// If this is an input matching constraint, this method returns the output |
| 4330 | /// operand it matches. |
| 4331 | unsigned getMatchedOperand() const; |
| 4332 | }; |
| 4333 | |
| 4334 | using AsmOperandInfoVector = std::vector<AsmOperandInfo>; |
| 4335 | |
| 4336 | /// Split up the constraint string from the inline assembly value into the |
| 4337 | /// specific constraints and their prefixes, and also tie in the associated |
| 4338 | /// operand values. If this returns an empty vector, and if the constraint |
| 4339 | /// string itself isn't empty, there was an error parsing. |
| 4340 | virtual AsmOperandInfoVector ParseConstraints(const DataLayout &DL, |
| 4341 | const TargetRegisterInfo *TRI, |
| 4342 | const CallBase &Call) const; |
| 4343 | |
| 4344 | /// Examine constraint type and operand type and determine a weight value. |
| 4345 | /// The operand object must already have been set up with the operand type. |
| 4346 | virtual ConstraintWeight getMultipleConstraintMatchWeight( |
| 4347 | AsmOperandInfo &info, int maIndex) const; |
| 4348 | |
| 4349 | /// Examine constraint string and operand type and determine a weight value. |
| 4350 | /// The operand object must already have been set up with the operand type. |
| 4351 | virtual ConstraintWeight getSingleConstraintMatchWeight( |
| 4352 | AsmOperandInfo &info, const char *constraint) const; |
| 4353 | |
| 4354 | /// Determines the constraint code and constraint type to use for the specific |
| 4355 | /// AsmOperandInfo, setting OpInfo.ConstraintCode and OpInfo.ConstraintType. |
| 4356 | /// If the actual operand being passed in is available, it can be passed in as |
| 4357 | /// Op, otherwise an empty SDValue can be passed. |
| 4358 | virtual void ComputeConstraintToUse(AsmOperandInfo &OpInfo, |
| 4359 | SDValue Op, |
| 4360 | SelectionDAG *DAG = nullptr) const; |
| 4361 | |
| 4362 | /// Given a constraint, return the type of constraint it is for this target. |
| 4363 | virtual ConstraintType getConstraintType(StringRef Constraint) const; |
| 4364 | |
| 4365 | /// Given a physical register constraint (e.g. {edx}), return the register |
| 4366 | /// number and the register class for the register. |
| 4367 | /// |
| 4368 | /// Given a register class constraint, like 'r', if this corresponds directly |
| 4369 | /// to an LLVM register class, return a register of 0 and the register class |
| 4370 | /// pointer. |
| 4371 | /// |
| 4372 | /// This should only be used for C_Register constraints. On error, this |
| 4373 | /// returns a register number of 0 and a null register class pointer. |
| 4374 | virtual std::pair<unsigned, const TargetRegisterClass *> |
| 4375 | getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, |
| 4376 | StringRef Constraint, MVT VT) const; |
| 4377 | |
| 4378 | virtual unsigned getInlineAsmMemConstraint(StringRef ConstraintCode) const { |
| 4379 | if (ConstraintCode == "m") |
| 4380 | return InlineAsm::Constraint_m; |
| 4381 | if (ConstraintCode == "o") |
| 4382 | return InlineAsm::Constraint_o; |
| 4383 | if (ConstraintCode == "X") |
| 4384 | return InlineAsm::Constraint_X; |
| 4385 | return InlineAsm::Constraint_Unknown; |
| 4386 | } |
| 4387 | |
| 4388 | /// Try to replace an X constraint, which matches anything, with another that |
| 4389 | /// has more specific requirements based on the type of the corresponding |
| 4390 | /// operand. This returns null if there is no replacement to make. |
| 4391 | virtual const char *LowerXConstraint(EVT ConstraintVT) const; |
| 4392 | |
| 4393 | /// Lower the specified operand into the Ops vector. If it is invalid, don't |
| 4394 | /// add anything to Ops. |
| 4395 | virtual void LowerAsmOperandForConstraint(SDValue Op, std::string &Constraint, |
| 4396 | std::vector<SDValue> &Ops, |
| 4397 | SelectionDAG &DAG) const; |
| 4398 | |
| 4399 | // Lower custom output constraints. If invalid, return SDValue(). |
| 4400 | virtual SDValue LowerAsmOutputForConstraint(SDValue &Chain, SDValue &Flag, |
| 4401 | const SDLoc &DL, |
| 4402 | const AsmOperandInfo &OpInfo, |
| 4403 | SelectionDAG &DAG) const; |
| 4404 | |
| 4405 | //===--------------------------------------------------------------------===// |
| 4406 | // Div utility functions |
| 4407 | // |
| 4408 | SDValue BuildSDIV(SDNode *N, SelectionDAG &DAG, bool IsAfterLegalization, |
| 4409 | SmallVectorImpl<SDNode *> &Created) const; |
| 4410 | SDValue BuildUDIV(SDNode *N, SelectionDAG &DAG, bool IsAfterLegalization, |
| 4411 | SmallVectorImpl<SDNode *> &Created) const; |
| 4412 | |
| 4413 | /// Targets may override this function to provide custom SDIV lowering for |
| 4414 | /// power-of-2 denominators. If the target returns an empty SDValue, LLVM |
| 4415 | /// assumes SDIV is expensive and replaces it with a series of other integer |
| 4416 | /// operations. |
| 4417 | virtual SDValue BuildSDIVPow2(SDNode *N, const APInt &Divisor, |
| 4418 | SelectionDAG &DAG, |
| 4419 | SmallVectorImpl<SDNode *> &Created) const; |
| 4420 | |
| 4421 | /// Indicate whether this target prefers to combine FDIVs with the same |
| 4422 | /// divisor. If the transform should never be done, return zero. If the |
| 4423 | /// transform should be done, return the minimum number of divisor uses |
| 4424 | /// that must exist. |
| 4425 | virtual unsigned combineRepeatedFPDivisors() const { |
| 4426 | return 0; |
| 4427 | } |
| 4428 | |
| 4429 | /// Hooks for building estimates in place of slower divisions and square |
| 4430 | /// roots. |
| 4431 | |
| 4432 | /// Return either a square root or its reciprocal estimate value for the input |
| 4433 | /// operand. |
| 4434 | /// \p Enabled is a ReciprocalEstimate enum with value either 'Unspecified' or |
| 4435 | /// 'Enabled' as set by a potential default override attribute. |
| 4436 | /// If \p RefinementSteps is 'Unspecified', the number of Newton-Raphson |
| 4437 | /// refinement iterations required to generate a sufficient (though not |
| 4438 | /// necessarily IEEE-754 compliant) estimate is returned in that parameter. |
| 4439 | /// The boolean UseOneConstNR output is used to select a Newton-Raphson |
| 4440 | /// algorithm implementation that uses either one or two constants. |
| 4441 | /// The boolean Reciprocal is used to select whether the estimate is for the |
| 4442 | /// square root of the input operand or the reciprocal of its square root. |
| 4443 | /// A target may choose to implement its own refinement within this function. |
| 4444 | /// If that's true, then return '0' as the number of RefinementSteps to avoid |
| 4445 | /// any further refinement of the estimate. |
| 4446 | /// An empty SDValue return means no estimate sequence can be created. |
| 4447 | virtual SDValue getSqrtEstimate(SDValue Operand, SelectionDAG &DAG, |
| 4448 | int Enabled, int &RefinementSteps, |
| 4449 | bool &UseOneConstNR, bool Reciprocal) const { |
| 4450 | return SDValue(); |
| 4451 | } |
| 4452 | |
| 4453 | /// Return a reciprocal estimate value for the input operand. |
| 4454 | /// \p Enabled is a ReciprocalEstimate enum with value either 'Unspecified' or |
| 4455 | /// 'Enabled' as set by a potential default override attribute. |
| 4456 | /// If \p RefinementSteps is 'Unspecified', the number of Newton-Raphson |
| 4457 | /// refinement iterations required to generate a sufficient (though not |
| 4458 | /// necessarily IEEE-754 compliant) estimate is returned in that parameter. |
| 4459 | /// A target may choose to implement its own refinement within this function. |
| 4460 | /// If that's true, then return '0' as the number of RefinementSteps to avoid |
| 4461 | /// any further refinement of the estimate. |
| 4462 | /// An empty SDValue return means no estimate sequence can be created. |
| 4463 | virtual SDValue getRecipEstimate(SDValue Operand, SelectionDAG &DAG, |
| 4464 | int Enabled, int &RefinementSteps) const { |
| 4465 | return SDValue(); |
| 4466 | } |
| 4467 | |
| 4468 | /// Return a target-dependent comparison result if the input operand is |
| 4469 | /// suitable for use with a square root estimate calculation. For example, the |
| 4470 | /// comparison may check if the operand is NAN, INF, zero, normal, etc. The |
| 4471 | /// result should be used as the condition operand for a select or branch. |
| 4472 | virtual SDValue getSqrtInputTest(SDValue Operand, SelectionDAG &DAG, |
| 4473 | const DenormalMode &Mode) const; |
| 4474 | |
| 4475 | /// Return a target-dependent result if the input operand is not suitable for |
| 4476 | /// use with a square root estimate calculation. |
| 4477 | virtual SDValue getSqrtResultForDenormInput(SDValue Operand, |
| 4478 | SelectionDAG &DAG) const { |
| 4479 | return DAG.getConstantFP(0.0, SDLoc(Operand), Operand.getValueType()); |
| 4480 | } |
| 4481 | |
| 4482 | //===--------------------------------------------------------------------===// |
| 4483 | // Legalization utility functions |
| 4484 | // |
| 4485 | |
| 4486 | /// Expand a MUL or [US]MUL_LOHI of n-bit values into two or four nodes, |
| 4487 | /// respectively, each computing an n/2-bit part of the result. |
| 4488 | /// \param Result A vector that will be filled with the parts of the result |
| 4489 | /// in little-endian order. |
| 4490 | /// \param LL Low bits of the LHS of the MUL. You can use this parameter |
| 4491 | /// if you want to control how low bits are extracted from the LHS. |
| 4492 | /// \param LH High bits of the LHS of the MUL. See LL for meaning. |
| 4493 | /// \param RL Low bits of the RHS of the MUL. See LL for meaning |
| 4494 | /// \param RH High bits of the RHS of the MUL. See LL for meaning. |
| 4495 | /// \returns true if the node has been expanded, false if it has not |
| 4496 | bool expandMUL_LOHI(unsigned Opcode, EVT VT, const SDLoc &dl, SDValue LHS, |
| 4497 | SDValue RHS, SmallVectorImpl<SDValue> &Result, EVT HiLoVT, |
| 4498 | SelectionDAG &DAG, MulExpansionKind Kind, |
| 4499 | SDValue LL = SDValue(), SDValue LH = SDValue(), |
| 4500 | SDValue RL = SDValue(), SDValue RH = SDValue()) const; |
| 4501 | |
| 4502 | /// Expand a MUL into two nodes. One that computes the high bits of |
| 4503 | /// the result and one that computes the low bits. |
| 4504 | /// \param HiLoVT The value type to use for the Lo and Hi nodes. |
| 4505 | /// \param LL Low bits of the LHS of the MUL. You can use this parameter |
| 4506 | /// if you want to control how low bits are extracted from the LHS. |
| 4507 | /// \param LH High bits of the LHS of the MUL. See LL for meaning. |
| 4508 | /// \param RL Low bits of the RHS of the MUL. See LL for meaning |
| 4509 | /// \param RH High bits of the RHS of the MUL. See LL for meaning. |
| 4510 | /// \returns true if the node has been expanded. false if it has not |
| 4511 | bool expandMUL(SDNode *N, SDValue &Lo, SDValue &Hi, EVT HiLoVT, |
| 4512 | SelectionDAG &DAG, MulExpansionKind Kind, |
| 4513 | SDValue LL = SDValue(), SDValue LH = SDValue(), |
| 4514 | SDValue RL = SDValue(), SDValue RH = SDValue()) const; |
| 4515 | |
| 4516 | /// Expand funnel shift. |
| 4517 | /// \param N Node to expand |
| 4518 | /// \returns The expansion if successful, SDValue() otherwise |
| 4519 | SDValue expandFunnelShift(SDNode *N, SelectionDAG &DAG) const; |
| 4520 | |
| 4521 | /// Expand rotations. |
| 4522 | /// \param N Node to expand |
| 4523 | /// \param AllowVectorOps expand vector rotate, this should only be performed |
| 4524 | /// if the legalization is happening outside of LegalizeVectorOps |
| 4525 | /// \returns The expansion if successful, SDValue() otherwise |
| 4526 | SDValue expandROT(SDNode *N, bool AllowVectorOps, SelectionDAG &DAG) const; |
| 4527 | |
| 4528 | /// Expand shift-by-parts. |
| 4529 | /// \param N Node to expand |
| 4530 | /// \param Lo lower-output-part after conversion |
| 4531 | /// \param Hi upper-output-part after conversion |
| 4532 | void expandShiftParts(SDNode *N, SDValue &Lo, SDValue &Hi, |
| 4533 | SelectionDAG &DAG) const; |
| 4534 | |
| 4535 | /// Expand float(f32) to SINT(i64) conversion |
| 4536 | /// \param N Node to expand |
| 4537 | /// \param Result output after conversion |
| 4538 | /// \returns True, if the expansion was successful, false otherwise |
| 4539 | bool expandFP_TO_SINT(SDNode *N, SDValue &Result, SelectionDAG &DAG) const; |
| 4540 | |
| 4541 | /// Expand float to UINT conversion |
| 4542 | /// \param N Node to expand |
| 4543 | /// \param Result output after conversion |
| 4544 | /// \param Chain output chain after conversion |
| 4545 | /// \returns True, if the expansion was successful, false otherwise |
| 4546 | bool expandFP_TO_UINT(SDNode *N, SDValue &Result, SDValue &Chain, |
| 4547 | SelectionDAG &DAG) const; |
| 4548 | |
| 4549 | /// Expand UINT(i64) to double(f64) conversion |
| 4550 | /// \param N Node to expand |
| 4551 | /// \param Result output after conversion |
| 4552 | /// \param Chain output chain after conversion |
| 4553 | /// \returns True, if the expansion was successful, false otherwise |
| 4554 | bool expandUINT_TO_FP(SDNode *N, SDValue &Result, SDValue &Chain, |
| 4555 | SelectionDAG &DAG) const; |
| 4556 | |
| 4557 | /// Expand fminnum/fmaxnum into fminnum_ieee/fmaxnum_ieee with quieted inputs. |
| 4558 | SDValue expandFMINNUM_FMAXNUM(SDNode *N, SelectionDAG &DAG) const; |
| 4559 | |
| 4560 | /// Expand FP_TO_[US]INT_SAT into FP_TO_[US]INT and selects or min/max. |
| 4561 | /// \param N Node to expand |
| 4562 | /// \returns The expansion result |
| 4563 | SDValue expandFP_TO_INT_SAT(SDNode *N, SelectionDAG &DAG) const; |
| 4564 | |
| 4565 | /// Expand CTPOP nodes. Expands vector/scalar CTPOP nodes, |
| 4566 | /// vector nodes can only succeed if all operations are legal/custom. |
| 4567 | /// \param N Node to expand |
| 4568 | /// \returns The expansion result or SDValue() if it fails. |
| 4569 | SDValue expandCTPOP(SDNode *N, SelectionDAG &DAG) const; |
| 4570 | |
| 4571 | /// Expand CTLZ/CTLZ_ZERO_UNDEF nodes. Expands vector/scalar CTLZ nodes, |
| 4572 | /// vector nodes can only succeed if all operations are legal/custom. |
| 4573 | /// \param N Node to expand |
| 4574 | /// \returns The expansion result or SDValue() if it fails. |
| 4575 | SDValue expandCTLZ(SDNode *N, SelectionDAG &DAG) const; |
| 4576 | |
| 4577 | /// Expand CTTZ/CTTZ_ZERO_UNDEF nodes. Expands vector/scalar CTTZ nodes, |
| 4578 | /// vector nodes can only succeed if all operations are legal/custom. |
| 4579 | /// \param N Node to expand |
| 4580 | /// \returns The expansion result or SDValue() if it fails. |
| 4581 | SDValue expandCTTZ(SDNode *N, SelectionDAG &DAG) const; |
| 4582 | |
| 4583 | /// Expand ABS nodes. Expands vector/scalar ABS nodes, |
| 4584 | /// vector nodes can only succeed if all operations are legal/custom. |
| 4585 | /// (ABS x) -> (XOR (ADD x, (SRA x, type_size)), (SRA x, type_size)) |
| 4586 | /// \param N Node to expand |
| 4587 | /// \param IsNegative indicate negated abs |
| 4588 | /// \returns The expansion result or SDValue() if it fails. |
| 4589 | SDValue expandABS(SDNode *N, SelectionDAG &DAG, |
| 4590 | bool IsNegative = false) const; |
| 4591 | |
| 4592 | /// Expand BSWAP nodes. Expands scalar/vector BSWAP nodes with i16/i32/i64 |
| 4593 | /// scalar types. Returns SDValue() if expand fails. |
| 4594 | /// \param N Node to expand |
| 4595 | /// \returns The expansion result or SDValue() if it fails. |
| 4596 | SDValue expandBSWAP(SDNode *N, SelectionDAG &DAG) const; |
| 4597 | |
| 4598 | /// Expand BITREVERSE nodes. Expands scalar/vector BITREVERSE nodes. |
| 4599 | /// Returns SDValue() if expand fails. |
| 4600 | /// \param N Node to expand |
| 4601 | /// \returns The expansion result or SDValue() if it fails. |
| 4602 | SDValue expandBITREVERSE(SDNode *N, SelectionDAG &DAG) const; |
| 4603 | |
| 4604 | /// Turn load of vector type into a load of the individual elements. |
| 4605 | /// \param LD load to expand |
| 4606 | /// \returns BUILD_VECTOR and TokenFactor nodes. |
| 4607 | std::pair<SDValue, SDValue> scalarizeVectorLoad(LoadSDNode *LD, |
| 4608 | SelectionDAG &DAG) const; |
| 4609 | |
| 4610 | // Turn a store of a vector type into stores of the individual elements. |
| 4611 | /// \param ST Store with a vector value type |
| 4612 | /// \returns TokenFactor of the individual store chains. |
| 4613 | SDValue scalarizeVectorStore(StoreSDNode *ST, SelectionDAG &DAG) const; |
| 4614 | |
| 4615 | /// Expands an unaligned load to 2 half-size loads for an integer, and |
| 4616 | /// possibly more for vectors. |
| 4617 | std::pair<SDValue, SDValue> expandUnalignedLoad(LoadSDNode *LD, |
| 4618 | SelectionDAG &DAG) const; |
| 4619 | |
| 4620 | /// Expands an unaligned store to 2 half-size stores for integer values, and |
| 4621 | /// possibly more for vectors. |
| 4622 | SDValue expandUnalignedStore(StoreSDNode *ST, SelectionDAG &DAG) const; |
| 4623 | |
| 4624 | /// Increments memory address \p Addr according to the type of the value |
| 4625 | /// \p DataVT that should be stored. If the data is stored in compressed |
| 4626 | /// form, the memory address should be incremented according to the number of |
| 4627 | /// the stored elements. This number is equal to the number of '1's bits |
| 4628 | /// in the \p Mask. |
| 4629 | /// \p DataVT is a vector type. \p Mask is a vector value. |
| 4630 | /// \p DataVT and \p Mask have the same number of vector elements. |
| 4631 | SDValue IncrementMemoryAddress(SDValue Addr, SDValue Mask, const SDLoc &DL, |
| 4632 | EVT DataVT, SelectionDAG &DAG, |
| 4633 | bool IsCompressedMemory) const; |
| 4634 | |
| 4635 | /// Get a pointer to vector element \p Idx located in memory for a vector of |
| 4636 | /// type \p VecVT starting at a base address of \p VecPtr. If \p Idx is out of |
| 4637 | /// bounds the returned pointer is unspecified, but will be within the vector |
| 4638 | /// bounds. |
| 4639 | SDValue getVectorElementPointer(SelectionDAG &DAG, SDValue VecPtr, EVT VecVT, |
| 4640 | SDValue Index) const; |
| 4641 | |
| 4642 | /// Get a pointer to a sub-vector of type \p SubVecVT at index \p Idx located |
| 4643 | /// in memory for a vector of type \p VecVT starting at a base address of |
| 4644 | /// \p VecPtr. If \p Idx plus the size of \p SubVecVT is out of bounds the |
| 4645 | /// returned pointer is unspecified, but the value returned will be such that |
| 4646 | /// the entire subvector would be within the vector bounds. |
| 4647 | SDValue getVectorSubVecPointer(SelectionDAG &DAG, SDValue VecPtr, EVT VecVT, |
| 4648 | EVT SubVecVT, SDValue Index) const; |
| 4649 | |
| 4650 | /// Method for building the DAG expansion of ISD::[US][MIN|MAX]. This |
| 4651 | /// method accepts integers as its arguments. |
| 4652 | SDValue expandIntMINMAX(SDNode *Node, SelectionDAG &DAG) const; |
| 4653 | |
| 4654 | /// Method for building the DAG expansion of ISD::[US][ADD|SUB]SAT. This |
| 4655 | /// method accepts integers as its arguments. |
| 4656 | SDValue expandAddSubSat(SDNode *Node, SelectionDAG &DAG) const; |
| 4657 | |
| 4658 | /// Method for building the DAG expansion of ISD::[US]SHLSAT. This |
| 4659 | /// method accepts integers as its arguments. |
| 4660 | SDValue expandShlSat(SDNode *Node, SelectionDAG &DAG) const; |
| 4661 | |
| 4662 | /// Method for building the DAG expansion of ISD::[U|S]MULFIX[SAT]. This |
| 4663 | /// method accepts integers as its arguments. |
| 4664 | SDValue expandFixedPointMul(SDNode *Node, SelectionDAG &DAG) const; |
| 4665 | |
| 4666 | /// Method for building the DAG expansion of ISD::[US]DIVFIX[SAT]. This |
| 4667 | /// method accepts integers as its arguments. |
| 4668 | /// Note: This method may fail if the division could not be performed |
| 4669 | /// within the type. Clients must retry with a wider type if this happens. |
| 4670 | SDValue expandFixedPointDiv(unsigned Opcode, const SDLoc &dl, |
| 4671 | SDValue LHS, SDValue RHS, |
| 4672 | unsigned Scale, SelectionDAG &DAG) const; |
| 4673 | |
| 4674 | /// Method for building the DAG expansion of ISD::U(ADD|SUB)O. Expansion |
| 4675 | /// always suceeds and populates the Result and Overflow arguments. |
| 4676 | void expandUADDSUBO(SDNode *Node, SDValue &Result, SDValue &Overflow, |
| 4677 | SelectionDAG &DAG) const; |
| 4678 | |
| 4679 | /// Method for building the DAG expansion of ISD::S(ADD|SUB)O. Expansion |
| 4680 | /// always suceeds and populates the Result and Overflow arguments. |
| 4681 | void expandSADDSUBO(SDNode *Node, SDValue &Result, SDValue &Overflow, |
| 4682 | SelectionDAG &DAG) const; |
| 4683 | |
| 4684 | /// Method for building the DAG expansion of ISD::[US]MULO. Returns whether |
| 4685 | /// expansion was successful and populates the Result and Overflow arguments. |
| 4686 | bool expandMULO(SDNode *Node, SDValue &Result, SDValue &Overflow, |
| 4687 | SelectionDAG &DAG) const; |
| 4688 | |
| 4689 | /// Expand a VECREDUCE_* into an explicit calculation. If Count is specified, |
| 4690 | /// only the first Count elements of the vector are used. |
| 4691 | SDValue expandVecReduce(SDNode *Node, SelectionDAG &DAG) const; |
| 4692 | |
| 4693 | /// Expand a VECREDUCE_SEQ_* into an explicit ordered calculation. |
| 4694 | SDValue expandVecReduceSeq(SDNode *Node, SelectionDAG &DAG) const; |
| 4695 | |
| 4696 | /// Expand an SREM or UREM using SDIV/UDIV or SDIVREM/UDIVREM, if legal. |
| 4697 | /// Returns true if the expansion was successful. |
| 4698 | bool expandREM(SDNode *Node, SDValue &Result, SelectionDAG &DAG) const; |
| 4699 | |
| 4700 | /// Method for building the DAG expansion of ISD::VECTOR_SPLICE. This |
| 4701 | /// method accepts vectors as its arguments. |
| 4702 | SDValue expandVectorSplice(SDNode *Node, SelectionDAG &DAG) const; |
| 4703 | |
| 4704 | /// Legalize a SETCC with given LHS and RHS and condition code CC on the |
| 4705 | /// current target. |
| 4706 | /// |
| 4707 | /// If the SETCC has been legalized using AND / OR, then the legalized node |
| 4708 | /// will be stored in LHS. RHS and CC will be set to SDValue(). NeedInvert |
| 4709 | /// will be set to false. |
| 4710 | /// |
| 4711 | /// If the SETCC has been legalized by using getSetCCSwappedOperands(), |
| 4712 | /// then the values of LHS and RHS will be swapped, CC will be set to the |
| 4713 | /// new condition, and NeedInvert will be set to false. |
| 4714 | /// |
| 4715 | /// If the SETCC has been legalized using the inverse condcode, then LHS and |
| 4716 | /// RHS will be unchanged, CC will set to the inverted condcode, and |
| 4717 | /// NeedInvert will be set to true. The caller must invert the result of the |
| 4718 | /// SETCC with SelectionDAG::getLogicalNOT() or take equivalent action to swap |
| 4719 | /// the effect of a true/false result. |
| 4720 | /// |
| 4721 | /// \returns true if the SetCC has been legalized, false if it hasn't. |
| 4722 | bool LegalizeSetCCCondCode(SelectionDAG &DAG, EVT VT, SDValue &LHS, |
| 4723 | SDValue &RHS, SDValue &CC, bool &NeedInvert, |
| 4724 | const SDLoc &dl, SDValue &Chain, |
| 4725 | bool IsSignaling = false) const; |
| 4726 | |
| 4727 | //===--------------------------------------------------------------------===// |
| 4728 | // Instruction Emitting Hooks |
| 4729 | // |
| 4730 | |
| 4731 | /// This method should be implemented by targets that mark instructions with |
| 4732 | /// the 'usesCustomInserter' flag. These instructions are special in various |
| 4733 | /// ways, which require special support to insert. The specified MachineInstr |
| 4734 | /// is created but not inserted into any basic blocks, and this method is |
| 4735 | /// called to expand it into a sequence of instructions, potentially also |
| 4736 | /// creating new basic blocks and control flow. |
| 4737 | /// As long as the returned basic block is different (i.e., we created a new |
| 4738 | /// one), the custom inserter is free to modify the rest of \p MBB. |
| 4739 | virtual MachineBasicBlock * |
| 4740 | EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *MBB) const; |
| 4741 | |
| 4742 | /// This method should be implemented by targets that mark instructions with |
| 4743 | /// the 'hasPostISelHook' flag. These instructions must be adjusted after |
| 4744 | /// instruction selection by target hooks. e.g. To fill in optional defs for |
| 4745 | /// ARM 's' setting instructions. |
| 4746 | virtual void AdjustInstrPostInstrSelection(MachineInstr &MI, |
| 4747 | SDNode *Node) const; |
| 4748 | |
| 4749 | /// If this function returns true, SelectionDAGBuilder emits a |
| 4750 | /// LOAD_STACK_GUARD node when it is lowering Intrinsic::stackprotector. |
| 4751 | virtual bool useLoadStackGuardNode() const { |
| 4752 | return false; |
| 4753 | } |
| 4754 | |
| 4755 | virtual SDValue emitStackGuardXorFP(SelectionDAG &DAG, SDValue Val, |
| 4756 | const SDLoc &DL) const { |
| 4757 | llvm_unreachable("not implemented for this target"); |
| 4758 | } |
| 4759 | |
| 4760 | /// Lower TLS global address SDNode for target independent emulated TLS model. |
| 4761 | virtual SDValue LowerToTLSEmulatedModel(const GlobalAddressSDNode *GA, |
| 4762 | SelectionDAG &DAG) const; |
| 4763 | |
| 4764 | /// Expands target specific indirect branch for the case of JumpTable |
| 4765 | /// expanasion. |
| 4766 | virtual SDValue expandIndirectJTBranch(const SDLoc& dl, SDValue Value, SDValue Addr, |
| 4767 | SelectionDAG &DAG) const { |
| 4768 | return DAG.getNode(ISD::BRIND, dl, MVT::Other, Value, Addr); |
| 4769 | } |
| 4770 | |
| 4771 | // seteq(x, 0) -> truncate(srl(ctlz(zext(x)), log2(#bits))) |
| 4772 | // If we're comparing for equality to zero and isCtlzFast is true, expose the |
| 4773 | // fact that this can be implemented as a ctlz/srl pair, so that the dag |
| 4774 | // combiner can fold the new nodes. |
| 4775 | SDValue lowerCmpEqZeroToCtlzSrl(SDValue Op, SelectionDAG &DAG) const; |
| 4776 | |
| 4777 | /// Give targets the chance to reduce the number of distinct addresing modes. |
| 4778 | ISD::MemIndexType getCanonicalIndexType(ISD::MemIndexType IndexType, |
| 4779 | EVT MemVT, SDValue Offsets) const; |
| 4780 | |
| 4781 | private: |
| 4782 | SDValue foldSetCCWithAnd(EVT VT, SDValue N0, SDValue N1, ISD::CondCode Cond, |
| 4783 | const SDLoc &DL, DAGCombinerInfo &DCI) const; |
| 4784 | SDValue foldSetCCWithBinOp(EVT VT, SDValue N0, SDValue N1, ISD::CondCode Cond, |
| 4785 | const SDLoc &DL, DAGCombinerInfo &DCI) const; |
| 4786 | |
| 4787 | SDValue optimizeSetCCOfSignedTruncationCheck(EVT SCCVT, SDValue N0, |
| 4788 | SDValue N1, ISD::CondCode Cond, |
| 4789 | DAGCombinerInfo &DCI, |
| 4790 | const SDLoc &DL) const; |
| 4791 | |
| 4792 | // (X & (C l>>/<< Y)) ==/!= 0 --> ((X <</l>> Y) & C) ==/!= 0 |
| 4793 | SDValue optimizeSetCCByHoistingAndByConstFromLogicalShift( |
| 4794 | EVT SCCVT, SDValue N0, SDValue N1C, ISD::CondCode Cond, |
| 4795 | DAGCombinerInfo &DCI, const SDLoc &DL) const; |
| 4796 | |
| 4797 | SDValue prepareUREMEqFold(EVT SETCCVT, SDValue REMNode, |
| 4798 | SDValue CompTargetNode, ISD::CondCode Cond, |
| 4799 | DAGCombinerInfo &DCI, const SDLoc &DL, |
| 4800 | SmallVectorImpl<SDNode *> &Created) const; |
| 4801 | SDValue buildUREMEqFold(EVT SETCCVT, SDValue REMNode, SDValue CompTargetNode, |
| 4802 | ISD::CondCode Cond, DAGCombinerInfo &DCI, |
| 4803 | const SDLoc &DL) const; |
| 4804 | |
| 4805 | SDValue prepareSREMEqFold(EVT SETCCVT, SDValue REMNode, |
| 4806 | SDValue CompTargetNode, ISD::CondCode Cond, |
| 4807 | DAGCombinerInfo &DCI, const SDLoc &DL, |
| 4808 | SmallVectorImpl<SDNode *> &Created) const; |
| 4809 | SDValue buildSREMEqFold(EVT SETCCVT, SDValue REMNode, SDValue CompTargetNode, |
| 4810 | ISD::CondCode Cond, DAGCombinerInfo &DCI, |
| 4811 | const SDLoc &DL) const; |
| 4812 | }; |
| 4813 | |
| 4814 | /// Given an LLVM IR type and return type attributes, compute the return value |
| 4815 | /// EVTs and flags, and optionally also the offsets, if the return value is |
| 4816 | /// being lowered to memory. |
| 4817 | void GetReturnInfo(CallingConv::ID CC, Type *ReturnType, AttributeList attr, |
| 4818 | SmallVectorImpl<ISD::OutputArg> &Outs, |
| 4819 | const TargetLowering &TLI, const DataLayout &DL); |
| 4820 | |
| 4821 | } // end namespace llvm |
| 4822 | |
| 4823 | #endif // LLVM_CODEGEN_TARGETLOWERING_H |