mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-19 04:32:19 +00:00
Initial checkin of indvar stuff
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1404 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c50df7e3aa
commit
6148c02591
69
lib/Transforms/Scalar/IndVarSimplify.cpp
Normal file
69
lib/Transforms/Scalar/IndVarSimplify.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
//===- IndVarSimplify.cpp - Induction Variable Elimination ----------------===//
|
||||
//
|
||||
// InductionVariableSimplify - Transform induction variables in a program
|
||||
// to all use a single cannonical induction variable per loop.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Transforms/Scalar/IndVarSimplify.h"
|
||||
#include "llvm/Analysis/InductionVariable.h"
|
||||
#include "llvm/Analysis/LoopInfo.h"
|
||||
#include "llvm/Analysis/Dominators.h"
|
||||
#include "llvm/iPHINode.h"
|
||||
#include "Support/STLExtras.h"
|
||||
|
||||
static bool TransformLoop(cfg::LoopInfo *Loops, cfg::Loop *Loop) {
|
||||
// Transform all subloops before this loop...
|
||||
bool Changed = reduce_apply_bool(Loop->getSubLoops().begin(),
|
||||
Loop->getSubLoops().end(),
|
||||
std::bind1st(ptr_fun(TransformLoop), Loops));
|
||||
// Get the header node for this loop. All of the phi nodes that could be
|
||||
// induction variables must live in this basic block.
|
||||
BasicBlock *Header = (BasicBlock*)Loop->getBlocks().front();
|
||||
|
||||
// Loop over all of the PHI nodes in the basic block, calculating the
|
||||
// induction variables that they represent... stuffing the induction variable
|
||||
// info into a vector...
|
||||
//
|
||||
vector<InductionVariable> IndVars; // Induction variables for block
|
||||
for (BasicBlock::iterator I = Header->begin();
|
||||
PHINode *PN = dyn_cast<PHINode>(*I); ++I)
|
||||
IndVars.push_back(InductionVariable(PN, Loops));
|
||||
|
||||
// If there are phi nodes in this basic block, there can't be indvars...
|
||||
if (IndVars.empty()) return Changed;
|
||||
|
||||
// Loop over the induction variables, looking for a cannonical induction
|
||||
// variable, and checking to make sure they are not all unknown induction
|
||||
// variables.
|
||||
//
|
||||
bool FoundIndVars = false;
|
||||
InductionVariable *Cannonical = 0;
|
||||
for (unsigned i = 0; i < IndVars.size(); ++i) {
|
||||
if (IndVars[i].InductionType == InductionVariable::Cannonical)
|
||||
Cannonical = &IndVars[i];
|
||||
if (IndVars[i].InductionType != InductionVariable::Unknown)
|
||||
FoundIndVars = true;
|
||||
}
|
||||
|
||||
// No induction variables, bail early... don't add a cannonnical indvar
|
||||
if (!FoundIndVars) return Changed;
|
||||
|
||||
// Okay, we want to convert other induction variables to use a cannonical
|
||||
// indvar. If we don't have one, add one now...
|
||||
if (!Cannonical) {
|
||||
|
||||
}
|
||||
|
||||
return Changed;
|
||||
}
|
||||
|
||||
bool InductionVariableSimplify::doit(Method *M) {
|
||||
// Figure out the loop structure of the method...
|
||||
cfg::LoopInfo Loops(M);
|
||||
|
||||
// Induction Variables live in the header nodes of the loops of the method...
|
||||
return reduce_apply_bool(Loops.getTopLevelLoops().begin(),
|
||||
Loops.getTopLevelLoops().end(),
|
||||
std::bind1st(std::ptr_fun(TransformLoop), &Loops));
|
||||
}
|
6
lib/Transforms/Scalar/Makefile
Normal file
6
lib/Transforms/Scalar/Makefile
Normal file
@ -0,0 +1,6 @@
|
||||
LEVEL = ../../..
|
||||
|
||||
LIBRARYNAME = scalaropts
|
||||
|
||||
include $(LEVEL)/Makefile.common
|
||||
|
Loading…
x
Reference in New Issue
Block a user