mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2026-04-21 23:17:16 +00:00
Factor code out to the TransformUtils library
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2516 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -10,31 +10,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Transforms/Scalar/DCE.h"
|
||||
#include "llvm/Transforms/Utils/Local.h"
|
||||
#include "llvm/Instruction.h"
|
||||
#include "llvm/Pass.h"
|
||||
#include "llvm/InstrTypes.h"
|
||||
#include "llvm/Function.h"
|
||||
#include "llvm/Support/InstIterator.h"
|
||||
#include <set>
|
||||
|
||||
static inline bool isInstDead(Instruction *I) {
|
||||
return I->use_empty() && !I->hasSideEffects() && !isa<TerminatorInst>(I);
|
||||
}
|
||||
|
||||
// dceInstruction - Inspect the instruction at *BBI and figure out if it's
|
||||
// [trivially] dead. If so, remove the instruction and update the iterator
|
||||
// to point to the instruction that immediately succeeded the original
|
||||
// instruction.
|
||||
//
|
||||
bool dceInstruction(BasicBlock::InstListType &BBIL,
|
||||
BasicBlock::iterator &BBI) {
|
||||
// Look for un"used" definitions...
|
||||
if (isInstDead(*BBI)) {
|
||||
delete BBIL.remove(BBI); // Bye bye
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// DeadInstElimination pass implementation
|
||||
//
|
||||
@@ -95,7 +76,7 @@ bool DCE::runOnFunction(Function *F) {
|
||||
Instruction *I = WorkList.back();
|
||||
WorkList.pop_back();
|
||||
|
||||
if (isInstDead(I)) { // If the instruction is dead...
|
||||
if (isInstructionTriviallyDead(I)) { // If the instruction is dead...
|
||||
// Loop over all of the values that the instruction uses, if there are
|
||||
// instructions being used, add them to the worklist, because they might
|
||||
// go dead after this one is removed.
|
||||
|
||||
Reference in New Issue
Block a user