26 #define DEBUG_TYPE "legalize-types"
35 void DAGTypeLegalizer::ExpandRes_MERGE_VALUES(
SDNode *
N,
unsigned ResNo,
37 SDValue Op = DisintegrateMERGE_VALUES(N, ResNo);
38 GetExpandedOp(Op, Lo, Hi);
49 switch (getTypeAction(InVT)) {
59 auto SoftenedOp = GetSoftenedFloat(InOp);
60 if (isLegalInHWReg(SoftenedOp.getValueType()))
62 SplitInteger(SoftenedOp, Lo, Hi);
71 GetExpandedOp(InOp, Lo, Hi);
80 GetSplitVector(InOp, Lo, Hi);
88 SplitInteger(BitConvertToInteger(GetScalarizedVector(InOp)), Lo, Hi);
94 InOp = GetWidenedVector(InOp);
97 std::tie(Lo, Hi) = DAG.
SplitVector(InOp, dl, LoVT, HiVT);
109 unsigned NumElems = 2;
114 while (!isTypeLegal(NVT)) {
117 if (NewSizeInBits < 8)
124 if (isTypeLegal(NVT)) {
128 for (
unsigned i = 0; i < NumElems; ++i)
135 for (
unsigned e = Vals.
size(); e - Slot > 2; Slot += 2, e += 1) {
167 int SPFI = cast<FrameIndexSDNode>(StackPtr.
getNode())->getIndex();
175 Lo = DAG.
getLoad(NOutVT, dl, Store, StackPtr, PtrInfo);
179 StackPtr = DAG.
getNode(
ISD::ADD, dl, StackPtr.getValueType(), StackPtr,
181 StackPtr.getValueType()));
184 Hi = DAG.
getLoad(NOutVT, dl, Store, StackPtr,
186 MinAlign(Alignment, IncrementSize));
193 void DAGTypeLegalizer::ExpandRes_BUILD_PAIR(
SDNode *N,
SDValue &Lo,
200 void DAGTypeLegalizer::ExpandRes_EXTRACT_ELEMENT(
SDNode *N,
SDValue &Lo,
207 "Type twice as big as expanded type not itself expanded!");
209 GetPairElements(Part, Lo, Hi);
212 void DAGTypeLegalizer::ExpandRes_EXTRACT_VECTOR_ELT(
SDNode *N,
SDValue &Lo,
224 if (OldVT != OldEltVT) {
228 assert(OldEltVT.
bitsLT(OldVT) &&
"Result type smaller then element type!");
252 void DAGTypeLegalizer::ExpandRes_NormalLoad(
SDNode *N,
SDValue &Lo,
274 Hi = DAG.
getLoad(NVT, dl, Chain, Ptr,
290 ReplaceValueWith(
SDValue(N, 1), Chain);
318 void DAGTypeLegalizer::IntegerToVector(
SDValue Op,
unsigned NumElements,
325 if (NumElements > 1) {
327 SplitInteger(Op, Parts[0], Parts[1]);
330 IntegerToVector(Parts[0], NumElements, Ops, EltVT);
331 IntegerToVector(Parts[1], NumElements, Ops, EltVT);
350 unsigned NumElts = 2;
355 if (!isTypeLegal(NVT)) {
383 "BUILD_VECTOR operand type doesn't match vector element type!");
387 std::vector<SDValue> NewElts;
388 NewElts.reserve(NumElts*2);
390 for (
unsigned i = 0; i < NumElts; ++i) {
395 NewElts.push_back(Lo);
396 NewElts.push_back(Hi);
406 SDValue DAGTypeLegalizer::ExpandOp_EXTRACT_ELEMENT(
SDNode *N) {
409 return cast<ConstantSDNode>(N->
getOperand(1))->getZExtValue() ? Hi :
Lo;
412 SDValue DAGTypeLegalizer::ExpandOp_INSERT_VECTOR_ELT(
SDNode *N) {
423 "Inserted element type doesn't match vector element type!");
432 GetExpandedOp(Val, Lo, Hi);
448 SDValue DAGTypeLegalizer::ExpandOp_SCALAR_TO_VECTOR(
SDNode *N) {
452 "SCALAR_TO_VECTOR operand type doesn't match vector element type!");
457 for (
unsigned i = 1; i < NumElts; ++i)
462 SDValue DAGTypeLegalizer::ExpandOp_NormalStore(
SDNode *N,
unsigned OpNo) {
464 assert(OpNo == 1 &&
"Can only expand the stored value so far");
489 Hi = DAG.
getStore(Chain, dl, Hi, Ptr,
507 void DAGTypeLegalizer::SplitRes_MERGE_VALUES(
SDNode *N,
unsigned ResNo,
509 SDValue Op = DisintegrateMERGE_VALUES(N, ResNo);
510 GetSplitOp(Op, Lo, Hi);
527 return std::make_pair(Lo, Hi);
538 if (Cond.getValueType().isVector()) {
539 if (
SDValue Res = WidenVSELECTAndMask(N))
540 std::tie(CL, CH) = DAG.
SplitVector(Res->getOperand(0), dl);
544 std::tie(CL, CH) =
SplitVSETCC(Cond.getNode(), DAG);
547 else if (getTypeAction(Cond.getValueType()) ==
549 GetSplitVector(Cond, CL, CH);
558 void DAGTypeLegalizer::SplitRes_SELECT_CC(
SDNode *N,
SDValue &Lo,
SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, unsigned Alignment=0, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
Helper function to build ISD::STORE nodes.
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
void push_back(const T &Elt)
SDValue getValue(unsigned R) const
Flags getFlags() const
Return the raw flags of the source value,.
LLVMContext * getContext() const
unsigned getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
std::pair< EVT, EVT > GetSplitDestVTs(const EVT &VT) const
Compute the VTs needed for the low/hi parts of a type which is split (or expanded) into two not neces...
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
unsigned getValueSizeInBits() const
Returns the size of the value in bits.
const SDValue & getOperand(unsigned Num) const
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
const SDValue & getBasePtr() const
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
bool bitsLT(EVT VT) const
Return true if this has less bits than VT.
bool isVector() const
Return true if this is a vector value type.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
bool isNormalStore(const SDNode *N)
Returns true if the specified node is a non-truncating and unindexed store.
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
MachineFunction & getMachineFunction() const
BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
MachinePointerInfo getWithOffset(int64_t O) const
bool isInteger() const
Return true if this is an integer or a vector integer type.
virtual MVT getVectorIdxTy(const DataLayout &DL) const
Returns the type to be used for the index operand of: ISD::INSERT_VECTOR_ELT, ISD::EXTRACT_VECTOR_ELT...
EVT getVectorElementType() const
Given a vector type, return the type of each element.
bool hasBigEndianPartOrdering(EVT VT, const DataLayout &DL) const
When splitting a value of the specified type into parts, does the Lo or Hi part come first...
Simple integer binary arithmetic operators.
const SDValue & getBasePtr() const
SDValue getUNDEF(EVT VT)
Return an UNDEF node. UNDEF does not have a useful SDLoc.
const DataLayout & getDataLayout() const
This class is used to represent ISD::STORE nodes.
SDNode * getNode() const
get the SDNode which holds the desired result
constexpr uint64_t MinAlign(uint64_t A, uint64_t B)
A and B are either alignments or offsets.
bool isNormalLoad(const SDNode *N)
Returns true if the specified node is a non-extending and unindexed load.
INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element at IDX replaced with VAL...
std::pair< SDValue, SDValue > SplitVectorOperand(const SDNode *N, unsigned OpNo)
Split the node's operand with EXTRACT_SUBVECTOR and return the low/high part.
uint64_t getConstantOperandVal(unsigned Num) const
Helper method returns the integer value of a ConstantSDNode operand.
const SDValue & getValue() const
This class contains a discriminated union of information about pointers in memory operands...
SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, unsigned Alignment=0, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr)
Loads are not normal binary operators: their result type is not determined by their operands...
SDValue CreateStackTemporary(EVT VT, unsigned minAlign=1)
Create a stack temporary, suitable for holding the specified value type.
const MachinePointerInfo & getPointerInfo() const
TokenFactor - This node takes multiple tokens as input and produces a single token result...
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
std::pair< SDValue, SDValue > SplitVector(const SDValue &N, const SDLoc &DL, const EVT &LoVT, const EVT &HiVT)
Split the vector with EXTRACT_SUBVECTOR using the provides VTs and return the low/high part...
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
SDValue getBuildVector(EVT VT, const SDLoc &DL, ArrayRef< SDValue > Ops)
Return an ISD::BUILD_VECTOR node.
const SDValue & getChain() const
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
AAMDNodes getAAInfo() const
Returns the AA info that describes the dereference.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements, bool IsScalable=false)
Returns the EVT that represents a vector NumElements in length, where each element is of type VT...
ANY_EXTEND - Used for integer types. The high bits are undefined.
llvm_unreachable("Unknown RegBank!")
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
unsigned getSizeInBits() const
Return the size of the specified value type in bits.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
static std::pair< SDValue, SDValue > SplitVSETCC(const SDNode *N, SelectionDAG &DAG)
EVT getValueType() const
Return the ValueType of the referenced return value.
SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
SDValue getVAArg(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, SDValue SV, unsigned Align)
VAArg produces a result and token chain, and takes a pointer and a source value as input...
bool isByteSized() const
Return true if the bit size is a multiple of 8.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
EVT getTypeToTransformTo(LLVMContext &Context, EVT VT) const
For types supported by the target, this is an identity function.
SetCC operator - This evaluates to a true value iff the condition is true.
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
unsigned getAlignment() const
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth)
Returns the EVT that represents an integer with the given number of bits.
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
This class is used to represent ISD::LOAD nodes.