25#define DEBUG_TYPE "legalize-types"
34void DAGTypeLegalizer::ExpandRes_MERGE_VALUES(
SDNode *
N,
unsigned ResNo,
36 SDValue Op = DisintegrateMERGE_VALUES(
N, ResNo);
41 EVT OutVT =
N->getValueType(0);
42 EVT NOutVT = TLI.getTypeToTransformTo(*DAG.getContext(), OutVT);
48 switch (getTypeAction(InVT)) {
57 SplitInteger(GetSoftenedFloat(InOp),
Lo,
Hi);
58 Lo = DAG.getNode(ISD::BITCAST, dl, NOutVT,
Lo);
59 Hi = DAG.getNode(ISD::BITCAST, dl, NOutVT,
Hi);
63 auto &
DL = DAG.getDataLayout();
65 GetExpandedOp(InOp,
Lo,
Hi);
66 if (TLI.hasBigEndianPartOrdering(InVT,
DL) !=
67 TLI.hasBigEndianPartOrdering(OutVT,
DL))
69 Lo = DAG.getNode(ISD::BITCAST, dl, NOutVT,
Lo);
70 Hi = DAG.getNode(ISD::BITCAST, dl, NOutVT,
Hi);
74 GetSplitVector(InOp,
Lo,
Hi);
75 if (TLI.hasBigEndianPartOrdering(OutVT, DAG.getDataLayout()))
77 Lo = DAG.getNode(ISD::BITCAST, dl, NOutVT,
Lo);
78 Hi = DAG.getNode(ISD::BITCAST, dl, NOutVT,
Hi);
82 SplitInteger(BitConvertToInteger(GetScalarizedVector(InOp)),
Lo,
Hi);
83 Lo = DAG.getNode(ISD::BITCAST, dl, NOutVT,
Lo);
84 Hi = DAG.getNode(ISD::BITCAST, dl, NOutVT,
Hi);
90 InOp = GetWidenedVector(InOp);
92 std::tie(LoVT, HiVT) = DAG.GetSplitDestVTs(InVT);
93 std::tie(
Lo,
Hi) = DAG.SplitVector(InOp, dl, LoVT, HiVT);
94 if (TLI.hasBigEndianPartOrdering(OutVT, DAG.getDataLayout()))
96 Lo = DAG.getNode(ISD::BITCAST, dl, NOutVT,
Lo);
97 Hi = DAG.getNode(ISD::BITCAST, dl, NOutVT,
Hi);
105 unsigned NumElems = 2;
110 while (!isTypeLegal(NVT)) {
113 if (NewSizeInBits < 8)
120 if (isTypeLegal(NVT)) {
121 SDValue CastInOp = DAG.getNode(ISD::BITCAST, dl, NVT, InOp);
124 for (
unsigned i = 0; i < NumElems; ++i)
126 CastInOp, DAG.getVectorIdxConstant(i, dl)));
130 for (
unsigned e = Vals.
size(); e - Slot > 2; Slot += 2, e += 1) {
136 if (DAG.getDataLayout().isBigEndian())
147 if (DAG.getDataLayout().isBigEndian())
162 Align InAlign = DAG.getReducedAlign(InVT,
false);
163 Align NOutAlign = DAG.getReducedAlign(NOutVT,
false);
167 MachinePointerInfo PtrInfo =
171 SDValue Store = DAG.getStore(DAG.getEntryNode(), dl, InOp, StackPtr, PtrInfo);
174 Lo = DAG.getLoad(NOutVT, dl, Store, StackPtr, PtrInfo, NOutAlign);
182 Hi = DAG.getLoad(NOutVT, dl, Store, StackPtr,
186 if (TLI.hasBigEndianPartOrdering(OutVT, DAG.getDataLayout()))
193 Lo =
N->getOperand(0);
194 Hi =
N->getOperand(1);
199 GetExpandedOp(
N->getOperand(0),
Lo,
Hi);
203 "Type twice as big as expanded type not itself expanded!");
205 GetPairElements(Part,
Lo,
Hi);
217 EVT OldVT =
N->getValueType(0);
218 EVT NewVT = TLI.getTypeToTransformTo(*DAG.getContext(), OldVT);
220 if (OldVT != OldEltVT) {
224 assert(OldEltVT.
bitsLT(OldVT) &&
"Result type smaller then element type!");
243 if (DAG.getDataLayout().isBigEndian())
253 assert(!
LD->isAtomic() &&
"Atomics can not be split");
254 EVT ValueVT =
LD->getValueType(0);
255 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), ValueVT);
258 AAMDNodes AAInfo =
LD->getAAInfo();
262 Lo = DAG.getLoad(NVT, dl, Chain,
Ptr,
LD->getPointerInfo(),
263 LD->getBaseAlign(),
LD->getMemOperand()->getFlags(), AAInfo);
268 Hi = DAG.getLoad(NVT, dl, Chain,
Ptr,
269 LD->getPointerInfo().getWithOffset(IncrementSize),
270 LD->getBaseAlign(),
LD->getMemOperand()->getFlags(), AAInfo);
278 if (TLI.hasBigEndianPartOrdering(ValueVT, DAG.getDataLayout()))
283 ReplaceValueWith(
SDValue(
N, 1), Chain);
287 EVT OVT =
N->getValueType(0);
288 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), OVT);
292 const unsigned Align =
N->getConstantOperandVal(3);
294 Lo = DAG.getVAArg(NVT, dl, Chain,
Ptr,
N->getOperand(2), Align);
295 Hi = DAG.getVAArg(NVT, dl,
Lo.getValue(1),
Ptr,
N->getOperand(2), 0);
299 if (TLI.hasBigEndianPartOrdering(OVT, DAG.getDataLayout()))
304 ReplaceValueWith(
SDValue(
N, 1), Chain);
312void DAGTypeLegalizer::IntegerToVector(
SDValue Op,
unsigned NumElements,
315 assert(
Op.getValueType().isInteger());
319 if (NumElements > 1) {
321 SplitInteger(
Op, Parts[0], Parts[1]);
322 if (DAG.getDataLayout().isBigEndian())
324 IntegerToVector(Parts[0], NumElements,
Ops, EltVT);
325 IntegerToVector(Parts[1], NumElements,
Ops, EltVT);
327 Ops.push_back(DAG.getNode(ISD::BITCAST,
DL, EltVT,
Op));
333 if (
N->getValueType(0).isVector() &&
334 N->getOperand(0).getValueType().isInteger()) {
344 unsigned NumElts = 2;
345 EVT OVT =
N->getOperand(0).getValueType();
347 TLI.getTypeToTransformTo(*DAG.getContext(), OVT),
349 if (!isTypeLegal(NVT)) {
352 NumElts =
N->getValueType(0).getVectorNumElements();
353 NVT =
N->getValueType(0);
360 return DAG.getNode(ISD::BITCAST, dl,
N->getValueType(0), Vec);
364 return CreateStackStoreLoad(
N->getOperand(0),
N->getValueType(0));
371 EVT OldVT =
N->getOperand(0).getValueType();
372 EVT NewVT = TLI.getTypeToTransformTo(*DAG.getContext(), OldVT);
376 "BUILD_VECTOR operand type doesn't match vector element type!");
382 GetExpandedOp(V,
Lo,
Hi);
392 for (
unsigned i = 0; i < NumElts; ++i) {
394 GetExpandedOp(
N->getOperand(i),
Lo,
Hi);
395 if (DAG.getDataLayout().isBigEndian())
402 SDValue NewVec = DAG.getBuildVector(NewVecVT, dl, NewElts);
405 return DAG.
getNode(ISD::BITCAST, dl, VecVT, NewVec);
410 GetExpandedOp(
N->getOperand(0),
Lo,
Hi);
411 return N->getConstantOperandVal(1) ?
Hi :
Lo;
419 GetExpandedOp(
N->getOperand(1),
Lo,
Hi);
420 SDValue LoUse = DAG.getNode(ISD::FAKE_USE, SDLoc(), MVT::Other, Chain,
Lo);
421 DAG.UpdateNodeOperands(
N, LoUse,
Hi);
427 EVT VecVT =
N->getValueType(0);
433 EVT NewEVT = TLI.getTypeToTransformTo(*DAG.getContext(), OldEVT);
436 "Inserted element type doesn't match vector element type!");
442 NewVecVT,
N->getOperand(0));
445 GetExpandedOp(Val,
Lo,
Hi);
446 if (DAG.getDataLayout().isBigEndian())
458 return DAG.getNode(ISD::BITCAST, dl, VecVT, NewVec);
463 EVT VT =
N->getValueType(0);
465 "SCALAR_TO_VECTOR operand type doesn't match vector element type!");
468 Ops[0] =
N->getOperand(0);
470 for (
unsigned i = 1; i < NumElts; ++i)
472 return DAG.getBuildVector(VT, dl,
Ops);
475SDValue DAGTypeLegalizer::ExpandOp_NormalStore(
SDNode *
N,
unsigned OpNo) {
477 assert(OpNo == 1 &&
"Can only expand the stored value so far");
483 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), ValueVT);
494 if (TLI.hasBigEndianPartOrdering(ValueVT, DAG.getDataLayout()))
519void DAGTypeLegalizer::SplitRes_MERGE_VALUES(
SDNode *
N,
unsigned ResNo,
521 SDValue Op = DisintegrateMERGE_VALUES(
N, ResNo);
528 unsigned Opcode =
N->getOpcode();
529 GetSplitOp(
N->getOperand(1), LL, LH);
530 GetSplitOp(
N->getOperand(2), RL, RH);
534 if (
Cond.getValueType().isVector()) {
535 if (
SDValue Res = WidenVSELECTMask(
N))
536 std::tie(CL,
CH) = DAG.SplitVector(Res, dl);
539 else if (getTypeAction(
Cond.getValueType()) ==
541 GetSplitVector(
Cond, CL,
CH);
548 EVT CondLHSVT =
Cond.getOperand(0).getValueType();
549 if (
Cond.getValueType().getVectorElementType() == MVT::i1 &&
550 isTypeLegal(CondLHSVT) &&
551 getSetCCResultType(CondLHSVT) ==
Cond.getValueType())
552 std::tie(CL,
CH) = DAG.SplitVector(
Cond, dl);
554 SplitVecRes_SETCC(
Cond.getNode(), CL,
CH);
556 std::tie(CL,
CH) = DAG.SplitVector(
Cond, dl);
559 if (Opcode != ISD::VP_SELECT && Opcode != ISD::VP_MERGE) {
566 std::tie(EVLLo, EVLHi) =
567 DAG.SplitEVL(
N->getOperand(3),
N->getValueType(0), dl);
577 GetSplitOp(
N->getOperand(2), LL, LH);
578 GetSplitOp(
N->getOperand(3), RL, RH);
581 N->getOperand(1), LL, RL,
N->getOperand(4));
583 N->getOperand(1), LH, RH,
N->getOperand(4));
588 std::tie(LoVT, HiVT) = DAG.GetSplitDestVTs(
N->getValueType(0));
589 Lo = DAG.getUNDEF(LoVT);
590 Hi = DAG.getUNDEF(HiVT);
597 GetSplitOp(
N->getOperand(0), L,
H);
606 GetSplitOp(
N->getOperand(0), L,
H);
616 GetSplitOp(
N->getOperand(0), L,
H);
618 Lo = DAG.getNode(ISD::ARITH_FENCE,
DL,
L.getValueType(), L);
619 Hi = DAG.getNode(ISD::ARITH_FENCE,
DL,
H.getValueType(),
H);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
const SmallVectorImpl< MachineOperand > & Cond
static Type * getValueType(Value *V)
Returns the type of the given value/instruction V.
Flags getFlags() const
Return the raw flags of the source value,.
Align getBaseAlign() const
Returns alignment and volatility of the memory access.
AAMDNodes getAAInfo() const
Returns the AA info that describes the dereference.
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
const MachinePointerInfo & getPointerInfo() const
const SDValue & getChain() const
bool isAtomic() const
Return true if the memory operation ordering is Unordered or higher.
Represents one node in the SelectionDAG.
const SDValue & getOperand(unsigned Num) const
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
SDNode * getNode() const
get the SDNode which holds the desired result
SDValue getValue(unsigned R) const
EVT getValueType() const
Return the ValueType of the referenced return value.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void reserve(size_type N)
void push_back(const T &Elt)
const SDValue & getBasePtr() const
const SDValue & getValue() const
@ TypeScalarizeScalableVector
static constexpr TypeSize getFixed(ScalarTy ExactSize)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
@ SETCC
SetCC operator - This evaluates to a true value iff the condition is true.
@ ADD
Simple integer binary arithmetic operators.
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
@ BUILD_PAIR
BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.
@ SPLAT_VECTOR
SPLAT_VECTOR(VAL) - Returns a vector with the scalar value VAL duplicated in all lanes.
@ EXTRACT_VECTOR_ELT
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
@ SELECT_CC
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
@ SPLAT_VECTOR_PARTS
SPLAT_VECTOR_PARTS(SCALAR1, SCALAR2, ...) - Returns a vector with the scalar values joined together a...
@ FREEZE
FREEZE - FREEZE(VAL) returns an arbitrary value if VAL is UNDEF (or is evaluated to UNDEF),...
@ INSERT_VECTOR_ELT
INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element at IDX replaced with VAL.
@ TokenFactor
TokenFactor - This node takes multiple tokens as input and produces a single token result.
bool isNormalStore(const SDNode *N)
Returns true if the specified node is a non-truncating and unindexed store.
bool isNormalLoad(const SDNode *N)
Returns true if the specified node is a non-extending and unindexed load.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI Value * getSplatValue(const Value *V)
Get splat value if the input is a splat vector or return nullptr.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
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.
bool bitsLT(EVT VT) const
Return true if this has less bits than VT.
ElementCount getVectorElementCount() const
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
bool isByteSized() const
Return true if the bit size is a multiple of 8.
static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth)
Returns the EVT that represents an integer with the given number of bits.
bool isVector() const
Return true if this is a vector value type.
EVT getVectorElementType() const
Given a vector type, return the type of each element.
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
bool isInteger() const
Return true if this is an integer or a vector integer type.
MachinePointerInfo getWithOffset(int64_t O) const
static LLVM_ABI MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.