Changeset View
Changeset View
Standalone View
Standalone View
mlir/lib/Transforms/Utils/RegionUtils.cpp
Show First 20 Lines • Show All 203 Lines • ▼ Show 20 Lines | |||||
static void propagateLiveness(Region ®ion, LiveMap &liveMap); | static void propagateLiveness(Region ®ion, LiveMap &liveMap); | ||||
static void propagateTerminatorLiveness(Operation *op, LiveMap &liveMap) { | static void propagateTerminatorLiveness(Operation *op, LiveMap &liveMap) { | ||||
// Terminators are always live. | // Terminators are always live. | ||||
liveMap.setProvedLive(op); | liveMap.setProvedLive(op); | ||||
// Check to see if we can reason about the successor operands and mutate them. | // Check to see if we can reason about the successor operands and mutate them. | ||||
BranchOpInterface branchInterface = dyn_cast<BranchOpInterface>(op); | BranchOpInterface branchInterface = dyn_cast<BranchOpInterface>(op); | ||||
if (!branchInterface || !branchInterface.canEraseSuccessorOperand()) { | if (!branchInterface) { | ||||
for (Block *successor : op->getSuccessors()) | for (Block *successor : op->getSuccessors()) | ||||
for (BlockArgument arg : successor->getArguments()) | for (BlockArgument arg : successor->getArguments()) | ||||
liveMap.setProvedLive(arg); | liveMap.setProvedLive(arg); | ||||
return; | return; | ||||
} | } | ||||
// If we can't reason about the operands to a successor, conservatively mark | // If we can't reason about the operands to a successor, conservatively mark | ||||
// all arguments as live. | // all arguments as live. | ||||
for (unsigned i = 0, e = op->getNumSuccessors(); i != e; ++i) { | for (unsigned i = 0, e = op->getNumSuccessors(); i != e; ++i) { | ||||
if (!branchInterface.getSuccessorOperands(i)) | if (!branchInterface.getMutableSuccessorOperands(i)) | ||||
for (BlockArgument arg : op->getSuccessor(i)->getArguments()) | for (BlockArgument arg : op->getSuccessor(i)->getArguments()) | ||||
liveMap.setProvedLive(arg); | liveMap.setProvedLive(arg); | ||||
} | } | ||||
} | } | ||||
static void propagateLiveness(Operation *op, LiveMap &liveMap) { | static void propagateLiveness(Operation *op, LiveMap &liveMap) { | ||||
// All Value's are either a block argument or an op result. | // All Value's are either a block argument or an op result. | ||||
// We call processValue on those cases. | // We call processValue on those cases. | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | static void eraseTerminatorSuccessorOperands(Operation *terminator, | ||||
for (unsigned succI = 0, succE = terminator->getNumSuccessors(); | for (unsigned succI = 0, succE = terminator->getNumSuccessors(); | ||||
succI < succE; succI++) { | succI < succE; succI++) { | ||||
// Iterating successors in reverse is not strictly needed, since we | // Iterating successors in reverse is not strictly needed, since we | ||||
// aren't erasing any successors. But it is slightly more efficient | // aren't erasing any successors. But it is slightly more efficient | ||||
// since it will promote later operands of the terminator being erased | // since it will promote later operands of the terminator being erased | ||||
// first, reducing the quadratic-ness. | // first, reducing the quadratic-ness. | ||||
unsigned succ = succE - succI - 1; | unsigned succ = succE - succI - 1; | ||||
Optional<OperandRange> succOperands = branchOp.getSuccessorOperands(succ); | Optional<MutableOperandRange> succOperands = | ||||
branchOp.getMutableSuccessorOperands(succ); | |||||
if (!succOperands) | if (!succOperands) | ||||
continue; | continue; | ||||
Block *successor = terminator->getSuccessor(succ); | Block *successor = terminator->getSuccessor(succ); | ||||
for (unsigned argI = 0, argE = succOperands->size(); argI < argE; ++argI) { | for (unsigned argI = 0, argE = succOperands->size(); argI < argE; ++argI) { | ||||
// Iterating args in reverse is needed for correctness, to avoid | // Iterating args in reverse is needed for correctness, to avoid | ||||
// shifting later args when earlier args are erased. | // shifting later args when earlier args are erased. | ||||
unsigned arg = argE - argI - 1; | unsigned arg = argE - argI - 1; | ||||
if (!liveMap.wasProvenLive(successor->getArgument(arg))) | if (!liveMap.wasProvenLive(successor->getArgument(arg))) | ||||
branchOp.eraseSuccessorOperand(succ, arg); | succOperands->erase(arg); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
static LogicalResult deleteDeadness(MutableArrayRef<Region> regions, | static LogicalResult deleteDeadness(MutableArrayRef<Region> regions, | ||||
LiveMap &liveMap) { | LiveMap &liveMap) { | ||||
bool erasedAnything = false; | bool erasedAnything = false; | ||||
for (Region ®ion : regions) { | for (Region ®ion : regions) { | ||||
▲ Show 20 Lines • Show All 82 Lines • Show Last 20 Lines |