Skip to content

Commit

Permalink
[SelectionDAG] Pass SDVTList instead of VTs to *SDNode constructors. …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
topperc committed Apr 24, 2024
1 parent 03bb10d commit fc538b0
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 71 deletions.
73 changes: 38 additions & 35 deletions llvm/include/llvm/CodeGen/SelectionDAGNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ class AddrSpaceCastSDNode : public SDNode {
unsigned DestAddrSpace;

public:
AddrSpaceCastSDNode(unsigned Order, const DebugLoc &dl, EVT VT,
AddrSpaceCastSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
unsigned SrcAS, unsigned DestAS);

unsigned getSrcAddressSpace() const { return SrcAddrSpace; }
Expand Down Expand Up @@ -1573,8 +1573,9 @@ class ShuffleVectorSDNode : public SDNode {
protected:
friend class SelectionDAG;

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

public:
ArrayRef<int> getMask() const {
Expand Down Expand Up @@ -1628,9 +1629,10 @@ class ConstantSDNode : public SDNode {

const ConstantInt *Value;

ConstantSDNode(bool isTarget, bool isOpaque, const ConstantInt *val, EVT VT)
ConstantSDNode(bool isTarget, bool isOpaque, const ConstantInt *val,
SDVTList VTs)
: SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, 0, DebugLoc(),
getSDVTList(VT)),
VTs),
Value(val) {
ConstantSDNodeBits.IsOpaque = isOpaque;
}
Expand Down Expand Up @@ -1681,9 +1683,9 @@ class ConstantFPSDNode : public SDNode {

const ConstantFP *Value;

ConstantFPSDNode(bool isTarget, const ConstantFP *val, EVT VT)
ConstantFPSDNode(bool isTarget, const ConstantFP *val, SDVTList VTs)
: SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP, 0,
DebugLoc(), getSDVTList(VT)),
DebugLoc(), VTs),
Value(val) {}

public:
Expand Down Expand Up @@ -1816,7 +1818,7 @@ class GlobalAddressSDNode : public SDNode {
unsigned TargetFlags;

GlobalAddressSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL,
const GlobalValue *GA, EVT VT, int64_t o,
const GlobalValue *GA, SDVTList VTs, int64_t o,
unsigned TF);

public:
Expand All @@ -1839,10 +1841,10 @@ class FrameIndexSDNode : public SDNode {

int FI;

FrameIndexSDNode(int fi, EVT VT, bool isTarg)
: SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
0, DebugLoc(), getSDVTList(VT)), FI(fi) {
}
FrameIndexSDNode(int fi, SDVTList VTs, bool isTarg)
: SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, 0, DebugLoc(),
VTs),
FI(fi) {}

public:
int getIndex() const { return FI; }
Expand Down Expand Up @@ -1917,10 +1919,10 @@ class JumpTableSDNode : public SDNode {
int JTI;
unsigned TargetFlags;

JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned TF)
: SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
0, DebugLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
}
JumpTableSDNode(int jti, SDVTList VTs, bool isTarg, unsigned TF)
: SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, 0, DebugLoc(),
VTs),
JTI(jti), TargetFlags(TF) {}

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

ConstantPoolSDNode(bool isTarget, const Constant *c, EVT VT, int o,
ConstantPoolSDNode(bool isTarget, const Constant *c, SDVTList VTs, int o,
Align Alignment, unsigned TF)
: SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
DebugLoc(), getSDVTList(VT)),
DebugLoc(), VTs),
Offset(o), Alignment(Alignment), TargetFlags(TF) {
assert(Offset >= 0 && "Offset is too large");
Val.ConstVal = c;
}

ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v, EVT VT, int o,
Align Alignment, unsigned TF)
ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v, SDVTList VTs,
int o, Align Alignment, unsigned TF)
: SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
DebugLoc(), getSDVTList(VT)),
DebugLoc(), VTs),
Offset(o), Alignment(Alignment), TargetFlags(TF) {
assert(Offset >= 0 && "Offset is too large");
Val.MachineCPVal = v;
Expand Down Expand Up @@ -2003,9 +2005,9 @@ class TargetIndexSDNode : public SDNode {
int64_t Offset;

public:
TargetIndexSDNode(int Idx, EVT VT, int64_t Ofs, unsigned TF)
: SDNode(ISD::TargetIndex, 0, DebugLoc(), getSDVTList(VT)),
TargetFlags(TF), Index(Idx), Offset(Ofs) {}
TargetIndexSDNode(int Idx, SDVTList VTs, int64_t Ofs, unsigned TF)
: SDNode(ISD::TargetIndex, 0, DebugLoc(), VTs), TargetFlags(TF),
Index(Idx), Offset(Ofs) {}

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

Register Reg;

RegisterSDNode(Register reg, EVT VT)
: SDNode(ISD::Register, 0, DebugLoc(), getSDVTList(VT)), Reg(reg) {}
RegisterSDNode(Register reg, SDVTList VTs)
: SDNode(ISD::Register, 0, DebugLoc(), VTs), Reg(reg) {}

public:
Register getReg() const { return Reg; }
Expand Down Expand Up @@ -2251,10 +2253,10 @@ class BlockAddressSDNode : public SDNode {
int64_t Offset;
unsigned TargetFlags;

BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
BlockAddressSDNode(unsigned NodeTy, SDVTList VTs, const BlockAddress *ba,
int64_t o, unsigned Flags)
: SDNode(NodeTy, 0, DebugLoc(), getSDVTList(VT)),
BA(ba), Offset(o), TargetFlags(Flags) {}
: SDNode(NodeTy, 0, DebugLoc(), VTs), BA(ba), Offset(o),
TargetFlags(Flags) {}

public:
const BlockAddress *getBlockAddress() const { return BA; }
Expand Down Expand Up @@ -2292,9 +2294,10 @@ class ExternalSymbolSDNode : public SDNode {
const char *Symbol;
unsigned TargetFlags;

ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned TF, EVT VT)
ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned TF,
SDVTList VTs)
: SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol, 0,
DebugLoc(), getSDVTList(VT)),
DebugLoc(), VTs),
Symbol(Sym), TargetFlags(TF) {}

public:
Expand All @@ -2312,8 +2315,8 @@ class MCSymbolSDNode : public SDNode {

MCSymbol *Symbol;

MCSymbolSDNode(MCSymbol *Symbol, EVT VT)
: SDNode(ISD::MCSymbol, 0, DebugLoc(), getSDVTList(VT)), Symbol(Symbol) {}
MCSymbolSDNode(MCSymbol *Symbol, SDVTList VTs)
: SDNode(ISD::MCSymbol, 0, DebugLoc(), VTs), Symbol(Symbol) {}

public:
MCSymbol *getMCSymbol() const { return Symbol; }
Expand Down Expand Up @@ -3026,8 +3029,8 @@ class AssertAlignSDNode : public SDNode {
Align Alignment;

public:
AssertAlignSDNode(unsigned Order, const DebugLoc &DL, EVT VT, Align A)
: SDNode(ISD::AssertAlign, Order, DL, getSDVTList(VT)), Alignment(A) {}
AssertAlignSDNode(unsigned Order, const DebugLoc &DL, SDVTList VTs, Align A)
: SDNode(ISD::AssertAlign, Order, DL, VTs), Alignment(A) {}

Align getAlign() const { return Alignment; }

Expand Down
Loading

0 comments on commit fc538b0

Please sign in to comment.