Skip to content

Commit

Permalink
Merge rust-lang#41
Browse files Browse the repository at this point in the history
41: Include PHINode operands in liveness analysis. r=ltratt a=ptersilie



Co-authored-by: Lukas Diekmann <lukas.diekmann@gmail.com>
  • Loading branch information
bors[bot] and ptersilie committed Aug 31, 2022
2 parents 22e35b8 + 4c1baeb commit a0fb4e0
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions llvm/lib/Transforms/Yk/LivenessAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,36 @@ LivenessAnalysis::LivenessAnalysis(Function *Func) {

// Record what this instruction uses.
//
// Note that Phi nodes are special and must be skipped. If we consider
// their operands as uses, then Phi nodes in loops may use variables
// before they are defined, and this messes with the algorithm.
// In order to track the operands of PHI nodes we need to be a bit crafty
// as otherwise we end up with live values in blocks where they actually
// don't exist. To avoid this, we need to mark as live any PHI operand
// from one block at the end of all other blocks. This leads to those
// values being killed immediately after entering the block in the
// backwards pass and thus the value never being live there.
//
// The book doesn't cover this quirk, as it explains liveness for
// non-SSA form, and thus doesn't need to worry about Phi nodes.
if (isa<PHINode>(I))
if (isa<PHINode>(I)) {
PHINode *P = cast<PHINode>(&I);
for (unsigned IVC = 0; IVC < P->getNumIncomingValues(); IVC++) {
BasicBlock *IBB = P->getIncomingBlock(IVC);
Value *IV = P->getIncomingValue(IVC);
if (isa<Constant>(IV)) {
continue;
}
// For each block that isn't the incoming block create a Def for this
// value. This means when we do the backwards liveness pass this
// value is immediately killed in the block.
for (auto *BBB = P->block_begin(); BBB != P->block_end(); BBB++) {
if (*BBB != IBB) {
Instruction *Last = &((*BBB)->back());
Defs[Last].insert(IV);
}
}
Uses[&I].insert(IV);
}
continue;
}

for (auto *U = I.op_begin(); U < I.op_end(); U++)
if ((!isa<Constant>(U)) && (!isa<BasicBlock>(U)) &&
Expand Down

0 comments on commit a0fb4e0

Please sign in to comment.