20#define DEBUG_TYPE "coro-suspend-crossing"
23#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
37 dbgs() << Label <<
":";
39 auto BBNo = Mapping.blockToIndex(BB);
60 auto BBNo = Mapping.blockToIndex(BB);
63 dump(
" Consumes", Block[BBNo].Consumes, RPOT, MST);
64 dump(
" Kills", Block[BBNo].Kills, RPOT, MST);
72 size_t const FromIndex = Mapping.blockToIndex(From);
73 size_t const ToIndex = Mapping.blockToIndex(To);
74 bool const Result = Block[ToIndex].Kills[FromIndex];
76 <<
" crosses suspend point\n");
82 size_t const FromIndex = Mapping.blockToIndex(From);
83 size_t const ToIndex = Mapping.blockToIndex(To);
84 bool Result = Block[ToIndex].Kills[FromIndex] ||
85 (From == To && Block[ToIndex].KillLoop);
87 <<
" crosses suspend point (path or loop)\n");
91template <
bool Initialize>
92bool SuspendCrossingInfo::computeBlockData(
101 if constexpr (!Initialize)
113 auto SavedConsumes =
B.Consumes;
114 auto SavedKills =
B.Kills;
116 for (BasicBlock *PI : predecessors(
B)) {
117 auto PrevNo = Mapping.blockToIndex(PI);
118 auto &
P = Block[PrevNo];
121 B.Consumes |=
P.Consumes;
124 if (
P.isAlwaysKill())
125 B.Kills |=
P.Consumes;
128 if (
B.isAlwaysKill()) {
129 B.Kills |=
B.Consumes;
130 }
else if (
B.isNeverKill()) {
135 B.KillLoop |=
B.Kills[BBNo];
139 if constexpr (!Initialize) {
140 B.Changed = (
B.Kills != SavedKills) || (
B.Consumes != SavedConsumes);
150 const size_t N = Mapping.size();
154 for (
size_t I = 0;
I <
N; ++
I) {
156 B.Consumes.resize(
N);
167 assert(CE->getParent()->getFirstInsertionPt() == CE->getIterator() &&
168 CE->getParent()->size() <= 2 &&
"CoroEnd must be in its own BB");
170 getBlockData(CE->getParent()).setNeverKill();
174 for (
auto *U : InRamp->users())
176 auto *TrueBB = Br->getSuccessor(0);
177 if (TrueBB->getSinglePredecessor())
178 getBlockData(TrueBB).setNeverKill();
187 auto &
B = getBlockData(SuspendBlock);
189 B.Kills |=
B.Consumes;
193 assert(CSI->getParent()->getFirstInsertionPt() == CSI->getIterator() &&
194 CSI->getParent()->size() <= 2 &&
195 "CoroSuspend must be in its own BB");
197 markSuspendBlock(CSI);
198 if (auto *Save = CSI->getCoroSave())
199 markSuspendBlock(Save);
205 computeBlockData<
true>(RPOT);
206 while (computeBlockData</*Initialize*/ false>(RPOT))
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
LLVM Basic Block Representation.
const Function * getParent() const
Return the enclosing method, or null if none.
size_t blockToIndex(BasicBlock const *BB) const
A wrapper class for inspecting calls to intrinsic functions.
Manage lifetime of a slot tracker for printing IR.
int getLocalSlot(const Value *V)
Return the slot number of the specified local value.
void incorporateFunction(const Function &F)
Incorporate the given function.
Represent a constant reference to a string, i.e.
LLVM_ABI bool hasPathCrossingSuspendPoint(BasicBlock *From, BasicBlock *To) const
Returns true if there is a path from From to To crossing a suspend point without crossing From a 2nd ...
LLVM_ABI bool hasPathOrLoopCrossingSuspendPoint(BasicBlock *From, BasicBlock *To) const
Returns true if there is a path from From to To crossing a suspend point without crossing From a 2nd ...
LLVM_ABI SuspendCrossingInfo(Function &F, const coro::Shape &Shape)
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
static void dumpBasicBlockLabel(const BasicBlock *BB, ModuleSlotTracker &MST)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
auto predecessors(const MachineBasicBlock *BB)
SmallVector< AnyCoroSuspendInst *, 4 > CoroSuspends
SmallVector< CoroIsInRampInst *, 2 > CoroIsInRampInsts
SmallVector< AnyCoroEndInst *, 4 > CoroEnds