35 class VectorLegalizer {
47 LegalizedNodes.
insert(std::make_pair(From, To));
50 LegalizedNodes.insert(std::make_pair(To, To));
84 DAG(dag), TLI(dag.getTargetLoweringInfo()), Changed(
false) {}
87 bool VectorLegalizer::Run() {
89 bool HasVectors =
false;
96 HasVectors |= J->isVector();
113 DAG.AssignTopologicalOrder();
119 SDValue OldRoot = DAG.getRoot();
120 assert(LegalizedNodes.count(OldRoot) &&
"Root didn't get legalized?");
121 DAG.setRoot(LegalizedNodes[OldRoot]);
123 LegalizedNodes.clear();
126 DAG.RemoveDeadNodes();
142 if (I != LegalizedNodes.
end())
return I->second;
148 for (
unsigned i = 0, e = Node->getNumOperands(); i != e; ++i)
149 Ops.
push_back(LegalizeOp(Node->getOperand(i)));
159 return TranslateLegalizeResults(Op, Result);
161 return LegalizeOp(ExpandLoad(Op));
168 switch (TLI.getTruncStoreAction(ValVT, StVT.getSimpleVT())) {
171 return TranslateLegalizeResults(Op, Result);
174 return TranslateLegalizeResults(Op, TLI.LowerOperation(Result, DAG));
177 return LegalizeOp(ExpandStore(Op));
181 bool HasVectorValue =
false;
185 HasVectorValue |= J->isVector();
187 return TranslateLegalizeResults(Op, Result);
192 return TranslateLegalizeResults(Op, Result);
251 QueryType = Node->getValueType(0);
254 QueryType = cast<VTSDNode>(Node->getOperand(1))->getVT();
258 QueryType = Node->getOperand(0).getValueType();
262 switch (TLI.getOperationAction(Node->getOpcode(), QueryType)) {
267 Result = PromoteVectorOp(Op);
273 Result = PromoteVectorOpINT_TO_FP(Op);
280 SDValue Tmp1 = TLI.LowerOperation(Op, DAG);
289 Result = ExpandSEXTINREG(Op);
291 Result = ExpandVSELECT(Op);
293 Result = ExpandSELECT(Op);
295 Result = ExpandUINT_TO_FLOAT(Op);
297 Result = ExpandFNEG(Op);
299 Result = UnrollVSETCC(Op);
301 Result = DAG.UnrollVectorOp(Op.
getNode());
307 Result = LegalizeOp(Result);
313 AddLegalizedOperand(Op, Result);
323 "Can't promote a vector with multiple results!");
345 "Can't promote a vector with multiple results!");
357 assert(EltVT.
isSimple() &&
"Promoting to a non-simple vector type!");
369 Operands[j] = DAG.getNode(Opc, dl, NVT, Op.
getOperand(j));
400 EVT WideVT = TLI.getPointerTy();
403 "Could not handle the sophisticated case when the widest integer is"
405 assert(WideVT.
bitsGE(SrcEltVT) &&
406 "Type is not legalized?");
413 while (RemainingBytes > 0) {
415 unsigned LoadBytes = WideBytes;
417 if (RemainingBytes >= LoadBytes) {
418 ScalarLoad = DAG.getLoad(WideVT, dl, Chain, BasePTR,
425 while (RemainingBytes < LoadBytes) {
429 ScalarLoad = DAG.getExtLoad(
ISD::EXTLOAD, dl, WideVT, Chain, BasePTR,
436 RemainingBytes -= LoadBytes;
447 SDValue SrcEltBitMask = DAG.getConstant((1U << SrcEltBits) - 1, WideVT);
449 unsigned BitOffset = 0;
450 unsigned WideIdx = 0;
453 for (
unsigned Idx = 0; Idx != NumElem; ++Idx) {
456 if (BitOffset < WideBits) {
457 ShAmt = DAG.getConstant(BitOffset, TLI.getShiftAmountTy(WideVT));
462 BitOffset += SrcEltBits;
463 if (BitOffset >= WideBits) {
467 ShAmt = DAG.getConstant(SrcEltBits - Offset,
468 TLI.getShiftAmountTy(WideVT));
480 Lo = DAG.getAnyExtOrTrunc(Lo, dl, DstEltVT);
483 Lo = DAG.getZExtOrTrunc(Lo, dl, DstEltVT);
486 ShAmt = DAG.getConstant(WideBits - SrcEltBits,
487 TLI.getShiftAmountTy(WideVT));
490 Lo = DAG.getSExtOrTrunc(Lo, dl, DstEltVT);
498 for (
unsigned Idx=0; Idx<NumElem; Idx++) {
499 SDValue ScalarLoad = DAG.getExtLoad(ExtType, dl,
507 DAG.getConstant(Stride, BasePTR.getValueType()));
515 &LoadChains[0], LoadChains.
size());
519 AddLegalizedOperand(Op.
getValue(0), Value);
520 AddLegalizedOperand(Op.
getValue(1), NewChain);
522 return (Op.
getResNo() ? NewChain : Value);
553 unsigned Stride = ScalarSize/8;
557 for (
unsigned Idx = 0; Idx < NumElem; Idx++) {
559 RegSclVT, Value, DAG.getConstant(Idx, TLI.getVectorIdxTy()));
562 SDValue Store = DAG.getTruncStore(Chain, dl, Ex, BasePTR,
564 isVolatile, isNonTemporal, Alignment, TBAAInfo);
572 &Stores[0], Stores.
size());
573 AddLegalizedOperand(Op, TF);
602 return DAG.UnrollVectorOp(Op.
getNode());
610 Mask = DAG.getSelect(DL, BitTy, Mask,
612 DAG.getConstant(0, BitTy));
624 SDValue AllOnes = DAG.getConstant(
640 return DAG.UnrollVectorOp(Op.
getNode());
647 SDValue ShiftSz = DAG.getConstant(BW - OrigBW, VT);
651 return DAG.getNode(
ISD::SRA, DL, VT, Op, ShiftSz);
675 TLI.getBooleanContents(
true) !=
677 return DAG.UnrollVectorOp(Op.
getNode());
683 return DAG.UnrollVectorOp(Op.
getNode());
691 SDValue AllOnes = DAG.getConstant(
708 return DAG.UnrollVectorOp(Op.
getNode());
712 "Elements in vector-UINT_TO_FP must be 32 or 64 bits wide");
715 SDValue HalfWord = DAG.getConstant(BW/2, VT);
720 uint64_t HWMask = (SVT.
getSizeInBits()==64)?0x00000000FFFFFFFF:0x0000FFFF;
721 SDValue HalfWordMask = DAG.getConstant(HWMask, VT);
747 return DAG.UnrollVectorOp(Op.
getNode());
758 for (
unsigned i = 0; i < NumElems; ++i) {
760 DAG.getConstant(i, TLI.getVectorIdxTy()));
762 DAG.getConstant(i, TLI.getVectorIdxTy()));
764 TLI.getSetCCResultType(*DAG.getContext(), TmpEltVT),
765 LHSElem, RHSElem, CC);
766 Ops[i] = DAG.getSelect(dl, EltVT, Ops[i],
769 DAG.getConstant(0, EltVT));
777 return VectorLegalizer(*this).Run();
MVT getSimpleValueType() const
Return the simple ValueType of the referenced return value.
void push_back(const T &Elt)
SDValue getValue(unsigned R) const
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
static MVT getVectorVT(MVT VT, unsigned NumElements)
unsigned getNumOperands() const
MDNode - a tuple of other values.
const SDValue & getOperand(unsigned Num) const
const SDValue & getBasePtr() const
unsigned getResNo() const
get the index which selects a specific result in the SDNode
bool isVector() const
isVector - Return true if this is a vector value type.
bool isRound() const
isRound - Return true if the size is a power-of-two number of bytes.
#define llvm_unreachable(msg)
EVT getValueType(unsigned ResNo) const
MachinePointerInfo getWithOffset(int64_t O) const
EVT getScalarType() const
bool bitsGE(EVT VT) const
bitsGE - Return true if this has no less bits than VT.
EVT getVectorElementType() const
unsigned getNumValues() const
Simple integer binary arithmetic operators.
const SDValue & getBasePtr() const
EVT getMemoryVT() const
getMemoryVT - Return the type of the in-memory value.
SDNode * getNode() const
get the SDNode which holds the desired result
unsigned getStoreSize() const
const SDValue & getOperand(unsigned i) const
Simple binary floating point operators.
bool isNonTemporal() const
ItTy next(ItTy it, Dist n)
unsigned getOpcode() const
const SDValue & getValue() const
Bit counting operators with an undefined result for zero inputs.
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
uint64_t NextPowerOf2(uint64_t A)
const MachinePointerInfo & getPointerInfo() const
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
const SDValue & getChain() const
const MDNode * getTBAAInfo() const
Returns the TBAAInfo that describes the dereference.
ISD::LoadExtType getExtensionType() const
ZERO_EXTEND - Used for integer types, zeroing the new bits.
ANY_EXTEND - Used for integer types. The high bits are undefined.
Bitwise operators - logical and, logical or, logical xor.
pointer data()
data - Return a pointer to the vector's buffer, even if empty().
unsigned getSizeInBits() const
getSizeInBits - Return the size of the specified value type in bits.
bool isByteSized() const
isByteSized - Return true if the bit size is a multiple of 8.
LLVM Value Representation.
bool isTruncatingStore() const
ItTy prior(ItTy it, Dist n)
bool isPowerOf2_32(uint32_t Value)
TRUNCATE - Completely drop the high bits.
unsigned getAlignment() const
static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth)
EVT changeVectorElementTypeToInteger() const
unsigned getVectorNumElements() const