mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-17 15:38:40 +00:00
Simplify DCE code a lot
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1079 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
76ac1a45b4
commit
edefaa1196
@ -34,33 +34,12 @@
|
|||||||
#include "llvm/Assembly/Writer.h"
|
#include "llvm/Assembly/Writer.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
struct ConstPoolDCE {
|
static bool RemoveUnusedDefs(BasicBlock::InstListType &Vals) {
|
||||||
enum { EndOffs = 0 };
|
|
||||||
static bool isDCEable(const ConstPoolVal *CPV) {
|
|
||||||
// TODO: The bytecode writer requires that all used types are in the
|
|
||||||
// constant pool for the current method. This is messy and is really
|
|
||||||
// irritating. FIXME
|
|
||||||
return CPV->getType() != Type::TypeTy; // Don't DCE Type plane constants!
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct BasicBlockDCE {
|
|
||||||
enum { EndOffs = 1 };
|
|
||||||
static bool isDCEable(const Instruction *I) {
|
|
||||||
return !I->hasSideEffects();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template<class Container, class DCEController>
|
|
||||||
static bool RemoveUnusedDefs(Container &Vals, DCEController DCEControl) {
|
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
int Offset = DCEController::EndOffs;
|
for (BasicBlock::InstListType::iterator DI = Vals.begin();
|
||||||
|
DI != Vals.end()-1; ) {
|
||||||
for (typename Container::iterator DI = Vals.begin();
|
|
||||||
DI != Vals.end()-Offset; ) {
|
|
||||||
// Look for un"used" definitions...
|
// Look for un"used" definitions...
|
||||||
if ((*DI)->use_empty() && DCEController::isDCEable(*DI)) {
|
if ((*DI)->use_empty() && !(*DI)->hasSideEffects()) {
|
||||||
// Bye bye
|
// Bye bye
|
||||||
//cerr << "Removing: " << *DI;
|
//cerr << "Removing: " << *DI;
|
||||||
delete Vals.remove(DI);
|
delete Vals.remove(DI);
|
||||||
@ -272,7 +251,7 @@ static bool DoDCEPass(Method *M) {
|
|||||||
|
|
||||||
// Loop through now and remove instructions that have no uses...
|
// Loop through now and remove instructions that have no uses...
|
||||||
for (BBIt = M->begin(); BBIt != BBEnd; ++BBIt) {
|
for (BBIt = M->begin(); BBIt != BBEnd; ++BBIt) {
|
||||||
Changed |= RemoveUnusedDefs((*BBIt)->getInstList(), BasicBlockDCE());
|
Changed |= RemoveUnusedDefs((*BBIt)->getInstList());
|
||||||
Changed |= RemoveSingularPHIs(*BBIt);
|
Changed |= RemoveSingularPHIs(*BBIt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user