Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/Transforms/Scalar/Reassociate.cpp
Show First 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | |||||
// Insts so they will be removed as well. | // Insts so they will be removed as well. | ||||
void ReassociatePass::RecursivelyEraseDeadInsts(Instruction *I, | void ReassociatePass::RecursivelyEraseDeadInsts(Instruction *I, | ||||
OrderedSet &Insts) { | OrderedSet &Insts) { | ||||
assert(isInstructionTriviallyDead(I) && "Trivially dead instructions only!"); | assert(isInstructionTriviallyDead(I) && "Trivially dead instructions only!"); | ||||
SmallVector<Value *, 4> Ops(I->op_begin(), I->op_end()); | SmallVector<Value *, 4> Ops(I->op_begin(), I->op_end()); | ||||
ValueRankMap.erase(I); | ValueRankMap.erase(I); | ||||
Insts.remove(I); | Insts.remove(I); | ||||
RedoInsts.remove(I); | RedoInsts.remove(I); | ||||
llvm::salvageDebugInfoOrMarkUndef(*I); | llvm::salvageDebugInfo(*I); | ||||
I->eraseFromParent(); | I->eraseFromParent(); | ||||
for (auto Op : Ops) | for (auto Op : Ops) | ||||
if (Instruction *OpInst = dyn_cast<Instruction>(Op)) | if (Instruction *OpInst = dyn_cast<Instruction>(Op)) | ||||
if (OpInst->use_empty()) | if (OpInst->use_empty()) | ||||
Insts.insert(OpInst); | Insts.insert(OpInst); | ||||
} | } | ||||
/// Zap the given instruction, adding interesting operands to the work list. | /// Zap the given instruction, adding interesting operands to the work list. | ||||
void ReassociatePass::EraseInst(Instruction *I) { | void ReassociatePass::EraseInst(Instruction *I) { | ||||
assert(isInstructionTriviallyDead(I) && "Trivially dead instructions only!"); | assert(isInstructionTriviallyDead(I) && "Trivially dead instructions only!"); | ||||
LLVM_DEBUG(dbgs() << "Erasing dead inst: "; I->dump()); | LLVM_DEBUG(dbgs() << "Erasing dead inst: "; I->dump()); | ||||
SmallVector<Value*, 8> Ops(I->op_begin(), I->op_end()); | SmallVector<Value*, 8> Ops(I->op_begin(), I->op_end()); | ||||
// Erase the dead instruction. | // Erase the dead instruction. | ||||
ValueRankMap.erase(I); | ValueRankMap.erase(I); | ||||
RedoInsts.remove(I); | RedoInsts.remove(I); | ||||
llvm::salvageDebugInfoOrMarkUndef(*I); | llvm::salvageDebugInfo(*I); | ||||
I->eraseFromParent(); | I->eraseFromParent(); | ||||
// Optimize its operands. | // Optimize its operands. | ||||
SmallPtrSet<Instruction *, 8> Visited; // Detect self-referential nodes. | SmallPtrSet<Instruction *, 8> Visited; // Detect self-referential nodes. | ||||
for (unsigned i = 0, e = Ops.size(); i != e; ++i) | for (unsigned i = 0, e = Ops.size(); i != e; ++i) | ||||
if (Instruction *Op = dyn_cast<Instruction>(Ops[i])) { | if (Instruction *Op = dyn_cast<Instruction>(Ops[i])) { | ||||
// If this is a node in an expression tree, climb to the expression root | // If this is a node in an expression tree, climb to the expression root | ||||
// and add that since that's where optimization actually happens. | // and add that since that's where optimization actually happens. | ||||
unsigned Opcode = Op->getOpcode(); | unsigned Opcode = Op->getOpcode(); | ||||
▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines |