Skip to content

Commit 97e3eb7

Browse files
committed
Don't record chain or glue operands in stackmap DAG nodes.
In the last LLVM sync, I tickled a bug in the "large stackmap locations" support that we added to ykllvm a while back. It manifested when building yklua. An "I shouldn't have already visited this node" assertion fails: ``` ld.lld: llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp:393: void llvm::ScheduleDAGSDNodes::BuildSchedUnits(): Assertion `N->getNodeId() == -1 && "Node already inserted!"' failed. ``` Upon inspecting the DAGs, the stackmap nodes contain glue and chain operands as constituents of live variables. That makes zero sense! We are effectively asking the compiler to record the location of something which isn't a piece of data! It causes two incoming glue and chains edges for some stackmap nodes, hence the assertion failure (two visits instead of one). This change omits chain and glue nodes when pushing stackmap operands and adds an assertion to catch this problem should it arise again.
1 parent 3a6ecd0 commit 97e3eb7

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9531,6 +9531,11 @@ void SelectionDAGBuilder::populateCallLoweringInfo(
95319531
Call->countOperandBundlesOfType(LLVMContext::OB_preallocated) != 0);
95329532
}
95339533

9534+
// Is the node `N` a glue or chain node?
9535+
bool isGlueOrChain(const SDValue &N) {
9536+
return (N.getValueType() == MVT::Other) || (N.getValueType() == MVT::Glue);
9537+
}
9538+
95349539
/// Given the stackmap live variable `N`, search its sub-DAG and return all of
95359540
/// the constituent values that need to be reported in the stackmap table.
95369541
static std::vector<SDValue> findLiveConstituents(SelectionDAG &DAG,
@@ -9542,8 +9547,11 @@ static std::vector<SDValue> findLiveConstituents(SelectionDAG &DAG,
95429547
case ISD::CONCAT_VECTORS:
95439548
case ISD::MERGE_VALUES:
95449549
case ISD::BUILD_VECTOR:
9545-
for (SDValue Op : N->op_values())
9546-
V.push_back(Op);
9550+
for (SDValue Op : N->op_values()) {
9551+
if (!isGlueOrChain(Op)) {
9552+
V.push_back(Op);
9553+
}
9554+
}
95479555
break;
95489556
case ISD::INSERT_VECTOR_ELT: {
95499557
V = findLiveConstituents(DAG, N.getOperand(0));
@@ -9556,6 +9564,14 @@ static std::vector<SDValue> findLiveConstituents(SelectionDAG &DAG,
95569564
V.push_back(N);
95579565
}
95589566

9567+
// We have to be careful not to ask the stackmap to record the locations
9568+
// of glue or chain operands. That would make no sense, as glue and chain
9569+
// operands are not real data, rather control dependencies that are an
9570+
// artefact of using a DAG.
9571+
for (SDValue &VV: V) {
9572+
assert(!isGlueOrChain(VV));
9573+
}
9574+
95599575
return V;
95609576
}
95619577

0 commit comments

Comments
 (0)