Skip to content

Commit fc538b0

Browse files
authored
[SelectionDAG] Pass SDVTList instead of VTs to *SDNode constructors. NFC (#89880)
All of these constructors were creating a SDVTList using an EVT* created by SDNode::getValueTypeList. This EVT needs to live at least as long as the SDNode that uses it. To do this, SDNode::getValueTypeList contains several function scoped static variables that hold the memory for the EVT. So the EVT lives until global destructors run. This is problematic since an EVT contains a Type* that points to memory allocated by an LLVMContext. If multiple LLVMContexts are used that don't have overlapping lifetimes, we can end up with stale or or incorrect pointers cached in the EVTs owned by SDNode::getValueTypeList. I want to try to make the EVTs be owned by SelectionDAG instead. This is already done for SDVTLists with more than 1 VT. The single value case is a very old optimizaton that should be re-evaluated. In order to do this, I need the SDVTLists to be created by SelectionDAG rather than by the SDNode itself. This patch doesn't change how the allocation is done yet. It just moves the code around. This patch does reduce the number of calls to getVTList since we now share with the call needed for the SDNode FoldingSet. Part of fixing #88233.
1 parent 03bb10d commit fc538b0

File tree

2 files changed

+86
-71
lines changed

2 files changed

+86
-71
lines changed

llvm/include/llvm/CodeGen/SelectionDAGNodes.h

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ class AddrSpaceCastSDNode : public SDNode {
12831283
unsigned DestAddrSpace;
12841284

12851285
public:
1286-
AddrSpaceCastSDNode(unsigned Order, const DebugLoc &dl, EVT VT,
1286+
AddrSpaceCastSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
12871287
unsigned SrcAS, unsigned DestAS);
12881288

12891289
unsigned getSrcAddressSpace() const { return SrcAddrSpace; }
@@ -1573,8 +1573,9 @@ class ShuffleVectorSDNode : public SDNode {
15731573
protected:
15741574
friend class SelectionDAG;
15751575

1576-
ShuffleVectorSDNode(EVT VT, unsigned Order, const DebugLoc &dl, const int *M)
1577-
: SDNode(ISD::VECTOR_SHUFFLE, Order, dl, getSDVTList(VT)), Mask(M) {}
1576+
ShuffleVectorSDNode(SDVTList VTs, unsigned Order, const DebugLoc &dl,
1577+
const int *M)
1578+
: SDNode(ISD::VECTOR_SHUFFLE, Order, dl, VTs), Mask(M) {}
15781579

15791580
public:
15801581
ArrayRef<int> getMask() const {
@@ -1628,9 +1629,10 @@ class ConstantSDNode : public SDNode {
16281629

16291630
const ConstantInt *Value;
16301631

1631-
ConstantSDNode(bool isTarget, bool isOpaque, const ConstantInt *val, EVT VT)
1632+
ConstantSDNode(bool isTarget, bool isOpaque, const ConstantInt *val,
1633+
SDVTList VTs)
16321634
: SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, 0, DebugLoc(),
1633-
getSDVTList(VT)),
1635+
VTs),
16341636
Value(val) {
16351637
ConstantSDNodeBits.IsOpaque = isOpaque;
16361638
}
@@ -1681,9 +1683,9 @@ class ConstantFPSDNode : public SDNode {
16811683

16821684
const ConstantFP *Value;
16831685

1684-
ConstantFPSDNode(bool isTarget, const ConstantFP *val, EVT VT)
1686+
ConstantFPSDNode(bool isTarget, const ConstantFP *val, SDVTList VTs)
16851687
: SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP, 0,
1686-
DebugLoc(), getSDVTList(VT)),
1688+
DebugLoc(), VTs),
16871689
Value(val) {}
16881690

16891691
public:
@@ -1816,7 +1818,7 @@ class GlobalAddressSDNode : public SDNode {
18161818
unsigned TargetFlags;
18171819

18181820
GlobalAddressSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL,
1819-
const GlobalValue *GA, EVT VT, int64_t o,
1821+
const GlobalValue *GA, SDVTList VTs, int64_t o,
18201822
unsigned TF);
18211823

18221824
public:
@@ -1839,10 +1841,10 @@ class FrameIndexSDNode : public SDNode {
18391841

18401842
int FI;
18411843

1842-
FrameIndexSDNode(int fi, EVT VT, bool isTarg)
1843-
: SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
1844-
0, DebugLoc(), getSDVTList(VT)), FI(fi) {
1845-
}
1844+
FrameIndexSDNode(int fi, SDVTList VTs, bool isTarg)
1845+
: SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, 0, DebugLoc(),
1846+
VTs),
1847+
FI(fi) {}
18461848

18471849
public:
18481850
int getIndex() const { return FI; }
@@ -1917,10 +1919,10 @@ class JumpTableSDNode : public SDNode {
19171919
int JTI;
19181920
unsigned TargetFlags;
19191921

1920-
JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned TF)
1921-
: SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
1922-
0, DebugLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
1923-
}
1922+
JumpTableSDNode(int jti, SDVTList VTs, bool isTarg, unsigned TF)
1923+
: SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, 0, DebugLoc(),
1924+
VTs),
1925+
JTI(jti), TargetFlags(TF) {}
19241926

19251927
public:
19261928
int getIndex() const { return JTI; }
@@ -1943,19 +1945,19 @@ class ConstantPoolSDNode : public SDNode {
19431945
Align Alignment; // Minimum alignment requirement of CP.
19441946
unsigned TargetFlags;
19451947

1946-
ConstantPoolSDNode(bool isTarget, const Constant *c, EVT VT, int o,
1948+
ConstantPoolSDNode(bool isTarget, const Constant *c, SDVTList VTs, int o,
19471949
Align Alignment, unsigned TF)
19481950
: SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1949-
DebugLoc(), getSDVTList(VT)),
1951+
DebugLoc(), VTs),
19501952
Offset(o), Alignment(Alignment), TargetFlags(TF) {
19511953
assert(Offset >= 0 && "Offset is too large");
19521954
Val.ConstVal = c;
19531955
}
19541956

1955-
ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v, EVT VT, int o,
1956-
Align Alignment, unsigned TF)
1957+
ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v, SDVTList VTs,
1958+
int o, Align Alignment, unsigned TF)
19571959
: SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1958-
DebugLoc(), getSDVTList(VT)),
1960+
DebugLoc(), VTs),
19591961
Offset(o), Alignment(Alignment), TargetFlags(TF) {
19601962
assert(Offset >= 0 && "Offset is too large");
19611963
Val.MachineCPVal = v;
@@ -2003,9 +2005,9 @@ class TargetIndexSDNode : public SDNode {
20032005
int64_t Offset;
20042006

20052007
public:
2006-
TargetIndexSDNode(int Idx, EVT VT, int64_t Ofs, unsigned TF)
2007-
: SDNode(ISD::TargetIndex, 0, DebugLoc(), getSDVTList(VT)),
2008-
TargetFlags(TF), Index(Idx), Offset(Ofs) {}
2008+
TargetIndexSDNode(int Idx, SDVTList VTs, int64_t Ofs, unsigned TF)
2009+
: SDNode(ISD::TargetIndex, 0, DebugLoc(), VTs), TargetFlags(TF),
2010+
Index(Idx), Offset(Ofs) {}
20092011

20102012
unsigned getTargetFlags() const { return TargetFlags; }
20112013
int getIndex() const { return Index; }
@@ -2215,8 +2217,8 @@ class RegisterSDNode : public SDNode {
22152217

22162218
Register Reg;
22172219

2218-
RegisterSDNode(Register reg, EVT VT)
2219-
: SDNode(ISD::Register, 0, DebugLoc(), getSDVTList(VT)), Reg(reg) {}
2220+
RegisterSDNode(Register reg, SDVTList VTs)
2221+
: SDNode(ISD::Register, 0, DebugLoc(), VTs), Reg(reg) {}
22202222

22212223
public:
22222224
Register getReg() const { return Reg; }
@@ -2251,10 +2253,10 @@ class BlockAddressSDNode : public SDNode {
22512253
int64_t Offset;
22522254
unsigned TargetFlags;
22532255

2254-
BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
2256+
BlockAddressSDNode(unsigned NodeTy, SDVTList VTs, const BlockAddress *ba,
22552257
int64_t o, unsigned Flags)
2256-
: SDNode(NodeTy, 0, DebugLoc(), getSDVTList(VT)),
2257-
BA(ba), Offset(o), TargetFlags(Flags) {}
2258+
: SDNode(NodeTy, 0, DebugLoc(), VTs), BA(ba), Offset(o),
2259+
TargetFlags(Flags) {}
22582260

22592261
public:
22602262
const BlockAddress *getBlockAddress() const { return BA; }
@@ -2292,9 +2294,10 @@ class ExternalSymbolSDNode : public SDNode {
22922294
const char *Symbol;
22932295
unsigned TargetFlags;
22942296

2295-
ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned TF, EVT VT)
2297+
ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned TF,
2298+
SDVTList VTs)
22962299
: SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol, 0,
2297-
DebugLoc(), getSDVTList(VT)),
2300+
DebugLoc(), VTs),
22982301
Symbol(Sym), TargetFlags(TF) {}
22992302

23002303
public:
@@ -2312,8 +2315,8 @@ class MCSymbolSDNode : public SDNode {
23122315

23132316
MCSymbol *Symbol;
23142317

2315-
MCSymbolSDNode(MCSymbol *Symbol, EVT VT)
2316-
: SDNode(ISD::MCSymbol, 0, DebugLoc(), getSDVTList(VT)), Symbol(Symbol) {}
2318+
MCSymbolSDNode(MCSymbol *Symbol, SDVTList VTs)
2319+
: SDNode(ISD::MCSymbol, 0, DebugLoc(), VTs), Symbol(Symbol) {}
23172320

23182321
public:
23192322
MCSymbol *getMCSymbol() const { return Symbol; }
@@ -3026,8 +3029,8 @@ class AssertAlignSDNode : public SDNode {
30263029
Align Alignment;
30273030

30283031
public:
3029-
AssertAlignSDNode(unsigned Order, const DebugLoc &DL, EVT VT, Align A)
3030-
: SDNode(ISD::AssertAlign, Order, DL, getSDVTList(VT)), Alignment(A) {}
3032+
AssertAlignSDNode(unsigned Order, const DebugLoc &DL, SDVTList VTs, Align A)
3033+
: SDNode(ISD::AssertAlign, Order, DL, VTs), Alignment(A) {}
30313034

30323035
Align getAlign() const { return Alignment; }
30333036

0 commit comments

Comments
 (0)