Skip to content

Commit 1d3f9f8

Browse files
authored
[SelectionDAG] Stop storing EVTs in a function scoped static std::set. (#118715)
EVTs potentially contain a Type * that points into memory owned by an LLVMContext. Storing them in a function scoped static means they may outlive the LLVMContext they point to. This std::set is used to unique single element VT lists containing a single extended EVT. Single element VT list with a simple EVT are uniqued by a separate cache indexed by the MVT::SimpleValueType enum. VT lists with more than one element are uniqued by a FoldingSet owned by the SelectionDAG object. This patch moves the single element cache into SelectionDAG so that it will be destroyed when SelectionDAG is destroyed. Fixes #88233
1 parent 2393ab6 commit 1d3f9f8

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <cstdint>
4545
#include <functional>
4646
#include <map>
47+
#include <set>
4748
#include <string>
4849
#include <tuple>
4950
#include <utility>
@@ -247,6 +248,9 @@ class SelectionDAG {
247248
BlockFrequencyInfo *BFI = nullptr;
248249
MachineModuleInfo *MMI = nullptr;
249250

251+
/// Extended EVTs used for single value VTLists.
252+
std::set<EVT, EVT::compareRawBits> EVTs;
253+
250254
/// List of non-single value types.
251255
FoldingSet<SDVTListNode> VTListMap;
252256

llvm/include/llvm/CodeGen/SelectionDAGNodes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ END_TWO_BYTE_PACK()
664664
DebugLoc debugLoc;
665665

666666
/// Return a pointer to the specified value type.
667-
static const EVT *getValueTypeList(EVT VT);
667+
static const EVT *getValueTypeList(MVT VT);
668668

669669
/// Index in worklist of DAGCombiner, or negative if the node is not in the
670670
/// worklist. -1 = not in worklist; -2 = not in worklist, but has already been
@@ -1124,7 +1124,7 @@ END_TWO_BYTE_PACK()
11241124
void addUse(SDUse &U) { U.addToList(&UseList); }
11251125

11261126
protected:
1127-
static SDVTList getSDVTList(EVT VT) {
1127+
static SDVTList getSDVTList(MVT VT) {
11281128
SDVTList Ret = { getValueTypeList(VT), 1 };
11291129
return Ret;
11301130
}

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10623,7 +10623,10 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
1062310623
}
1062410624

1062510625
SDVTList SelectionDAG::getVTList(EVT VT) {
10626-
return makeVTList(SDNode::getValueTypeList(VT), 1);
10626+
if (!VT.isExtended())
10627+
return makeVTList(SDNode::getValueTypeList(VT.getSimpleVT()), 1);
10628+
10629+
return makeVTList(&(*EVTs.insert(VT).first), 1);
1062710630
}
1062810631

1062910632
SDVTList SelectionDAG::getVTList(EVT VT1, EVT VT2) {
@@ -12383,17 +12386,11 @@ namespace {
1238312386

1238412387
/// getValueTypeList - Return a pointer to the specified value type.
1238512388
///
12386-
const EVT *SDNode::getValueTypeList(EVT VT) {
12387-
static std::set<EVT, EVT::compareRawBits> EVTs;
12389+
const EVT *SDNode::getValueTypeList(MVT VT) {
1238812390
static EVTArray SimpleVTArray;
12389-
static sys::SmartMutex<true> VTMutex;
1239012391

12391-
if (VT.isExtended()) {
12392-
sys::SmartScopedLock<true> Lock(VTMutex);
12393-
return &(*EVTs.insert(VT).first);
12394-
}
12395-
assert(VT.getSimpleVT() < MVT::VALUETYPE_SIZE && "Value type out of range!");
12396-
return &SimpleVTArray.VTs[VT.getSimpleVT().SimpleTy];
12392+
assert(VT < MVT::VALUETYPE_SIZE && "Value type out of range!");
12393+
return &SimpleVTArray.VTs[VT.SimpleTy];
1239712394
}
1239812395

1239912396
/// hasNUsesOfValue - Return true if there are exactly NUSES uses of the

0 commit comments

Comments
 (0)