[SelectionDAG] Reduce code duplication between getStore, getTruncStore, and getIndexedStore. (#137435)
Create an extra overload of getStore that can handle of the 3 types of stores. This is similar to how getLoad/getExtLoad/getIndexLoad is structure.
This commit is contained in:
parent
f3a61f61ee
commit
e17f07c4de
@ -1466,6 +1466,9 @@ public:
|
||||
SDValue Ptr, EVT SVT, MachineMemOperand *MMO);
|
||||
SDValue getIndexedStore(SDValue OrigStore, const SDLoc &dl, SDValue Base,
|
||||
SDValue Offset, ISD::MemIndexedMode AM);
|
||||
SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr,
|
||||
SDValue Offset, EVT SVT, MachineMemOperand *MMO,
|
||||
ISD::MemIndexedMode AM, bool IsTruncating = false);
|
||||
|
||||
SDValue getLoadVP(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, EVT VT,
|
||||
const SDLoc &dl, SDValue Chain, SDValue Ptr, SDValue Offset,
|
||||
|
@ -9439,17 +9439,42 @@ SDValue SelectionDAG::getStore(SDValue Chain, const SDLoc &dl, SDValue Val,
|
||||
|
||||
SDValue SelectionDAG::getStore(SDValue Chain, const SDLoc &dl, SDValue Val,
|
||||
SDValue Ptr, MachineMemOperand *MMO) {
|
||||
assert(Chain.getValueType() == MVT::Other &&
|
||||
"Invalid chain type");
|
||||
EVT VT = Val.getValueType();
|
||||
SDVTList VTs = getVTList(MVT::Other);
|
||||
SDValue Undef = getUNDEF(Ptr.getValueType());
|
||||
SDValue Ops[] = { Chain, Val, Ptr, Undef };
|
||||
return getStore(Chain, dl, Val, Ptr, Undef, Val.getValueType(), MMO,
|
||||
ISD::UNINDEXED);
|
||||
}
|
||||
|
||||
SDValue SelectionDAG::getStore(SDValue Chain, const SDLoc &dl, SDValue Val,
|
||||
SDValue Ptr, SDValue Offset, EVT SVT,
|
||||
MachineMemOperand *MMO, ISD::MemIndexedMode AM,
|
||||
bool IsTruncating) {
|
||||
assert(Chain.getValueType() == MVT::Other && "Invalid chain type");
|
||||
EVT VT = Val.getValueType();
|
||||
if (VT == SVT) {
|
||||
IsTruncating = false;
|
||||
} else if (!IsTruncating) {
|
||||
assert(VT == SVT && "No-truncating store from different memory type!");
|
||||
} else {
|
||||
assert(SVT.getScalarType().bitsLT(VT.getScalarType()) &&
|
||||
"Should only be a truncating store, not extending!");
|
||||
assert(VT.isInteger() == SVT.isInteger() && "Can't do FP-INT conversion!");
|
||||
assert(VT.isVector() == SVT.isVector() &&
|
||||
"Cannot use trunc store to convert to or from a vector!");
|
||||
assert((!VT.isVector() ||
|
||||
VT.getVectorElementCount() == SVT.getVectorElementCount()) &&
|
||||
"Cannot use trunc store to change the number of vector elements!");
|
||||
}
|
||||
|
||||
bool Indexed = AM != ISD::UNINDEXED;
|
||||
assert((Indexed || Offset.isUndef()) && "Unindexed store with an offset!");
|
||||
SDVTList VTs = Indexed ? getVTList(Ptr.getValueType(), MVT::Other)
|
||||
: getVTList(MVT::Other);
|
||||
SDValue Ops[] = {Chain, Val, Ptr, Offset};
|
||||
FoldingSetNodeID ID;
|
||||
AddNodeIDNode(ID, ISD::STORE, VTs, Ops);
|
||||
ID.AddInteger(VT.getRawBits());
|
||||
ID.AddInteger(SVT.getRawBits());
|
||||
ID.AddInteger(getSyntheticNodeSubclassData<StoreSDNode>(
|
||||
dl.getIROrder(), VTs, ISD::UNINDEXED, false, VT, MMO));
|
||||
dl.getIROrder(), VTs, AM, IsTruncating, SVT, MMO));
|
||||
ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
|
||||
ID.AddInteger(MMO->getFlags());
|
||||
void *IP = nullptr;
|
||||
@ -9457,8 +9482,8 @@ SDValue SelectionDAG::getStore(SDValue Chain, const SDLoc &dl, SDValue Val,
|
||||
cast<StoreSDNode>(E)->refineAlignment(MMO);
|
||||
return SDValue(E, 0);
|
||||
}
|
||||
auto *N = newSDNode<StoreSDNode>(dl.getIROrder(), dl.getDebugLoc(), VTs,
|
||||
ISD::UNINDEXED, false, VT, MMO);
|
||||
auto *N = newSDNode<StoreSDNode>(dl.getIROrder(), dl.getDebugLoc(), VTs, AM,
|
||||
IsTruncating, SVT, MMO);
|
||||
createOperands(N, Ops);
|
||||
|
||||
CSEMap.InsertNode(N, IP);
|
||||
@ -9491,47 +9516,8 @@ SDValue SelectionDAG::getTruncStore(SDValue Chain, const SDLoc &dl, SDValue Val,
|
||||
SDValue SelectionDAG::getTruncStore(SDValue Chain, const SDLoc &dl, SDValue Val,
|
||||
SDValue Ptr, EVT SVT,
|
||||
MachineMemOperand *MMO) {
|
||||
EVT VT = Val.getValueType();
|
||||
|
||||
assert(Chain.getValueType() == MVT::Other &&
|
||||
"Invalid chain type");
|
||||
if (VT == SVT)
|
||||
return getStore(Chain, dl, Val, Ptr, MMO);
|
||||
|
||||
assert(SVT.getScalarType().bitsLT(VT.getScalarType()) &&
|
||||
"Should only be a truncating store, not extending!");
|
||||
assert(VT.isInteger() == SVT.isInteger() &&
|
||||
"Can't do FP-INT conversion!");
|
||||
assert(VT.isVector() == SVT.isVector() &&
|
||||
"Cannot use trunc store to convert to or from a vector!");
|
||||
assert((!VT.isVector() ||
|
||||
VT.getVectorElementCount() == SVT.getVectorElementCount()) &&
|
||||
"Cannot use trunc store to change the number of vector elements!");
|
||||
|
||||
SDVTList VTs = getVTList(MVT::Other);
|
||||
SDValue Undef = getUNDEF(Ptr.getValueType());
|
||||
SDValue Ops[] = { Chain, Val, Ptr, Undef };
|
||||
FoldingSetNodeID ID;
|
||||
AddNodeIDNode(ID, ISD::STORE, VTs, Ops);
|
||||
ID.AddInteger(SVT.getRawBits());
|
||||
ID.AddInteger(getSyntheticNodeSubclassData<StoreSDNode>(
|
||||
dl.getIROrder(), VTs, ISD::UNINDEXED, true, SVT, MMO));
|
||||
ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
|
||||
ID.AddInteger(MMO->getFlags());
|
||||
void *IP = nullptr;
|
||||
if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP)) {
|
||||
cast<StoreSDNode>(E)->refineAlignment(MMO);
|
||||
return SDValue(E, 0);
|
||||
}
|
||||
auto *N = newSDNode<StoreSDNode>(dl.getIROrder(), dl.getDebugLoc(), VTs,
|
||||
ISD::UNINDEXED, true, SVT, MMO);
|
||||
createOperands(N, Ops);
|
||||
|
||||
CSEMap.InsertNode(N, IP);
|
||||
InsertNode(N);
|
||||
SDValue V(N, 0);
|
||||
NewSDValueDbgMsg(V, "Creating new node: ", this);
|
||||
return V;
|
||||
return getStore(Chain, dl, Val, Ptr, Undef, SVT, MMO, ISD::UNINDEXED, true);
|
||||
}
|
||||
|
||||
SDValue SelectionDAG::getIndexedStore(SDValue OrigStore, const SDLoc &dl,
|
||||
@ -9539,28 +9525,9 @@ SDValue SelectionDAG::getIndexedStore(SDValue OrigStore, const SDLoc &dl,
|
||||
ISD::MemIndexedMode AM) {
|
||||
StoreSDNode *ST = cast<StoreSDNode>(OrigStore);
|
||||
assert(ST->getOffset().isUndef() && "Store is already a indexed store!");
|
||||
SDVTList VTs = getVTList(Base.getValueType(), MVT::Other);
|
||||
SDValue Ops[] = { ST->getChain(), ST->getValue(), Base, Offset };
|
||||
FoldingSetNodeID ID;
|
||||
AddNodeIDNode(ID, ISD::STORE, VTs, Ops);
|
||||
ID.AddInteger(ST->getMemoryVT().getRawBits());
|
||||
ID.AddInteger(ST->getRawSubclassData());
|
||||
ID.AddInteger(ST->getPointerInfo().getAddrSpace());
|
||||
ID.AddInteger(ST->getMemOperand()->getFlags());
|
||||
void *IP = nullptr;
|
||||
if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP))
|
||||
return SDValue(E, 0);
|
||||
|
||||
auto *N = newSDNode<StoreSDNode>(dl.getIROrder(), dl.getDebugLoc(), VTs, AM,
|
||||
ST->isTruncatingStore(), ST->getMemoryVT(),
|
||||
ST->getMemOperand());
|
||||
createOperands(N, Ops);
|
||||
|
||||
CSEMap.InsertNode(N, IP);
|
||||
InsertNode(N);
|
||||
SDValue V(N, 0);
|
||||
NewSDValueDbgMsg(V, "Creating new node: ", this);
|
||||
return V;
|
||||
return getStore(ST->getChain(), dl, ST->getValue(), Base, Offset,
|
||||
ST->getMemoryVT(), ST->getMemOperand(), AM,
|
||||
ST->isTruncatingStore());
|
||||
}
|
||||
|
||||
SDValue SelectionDAG::getLoadVP(
|
||||
|
Loading…
x
Reference in New Issue
Block a user