projects
/
oota-llvm.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
The sign of an srem instruction is the sign of its dividend (the first
[oota-llvm.git]
/
lib
/
Transforms
/
Utils
/
LowerSwitch.cpp
diff --git
a/lib/Transforms/Utils/LowerSwitch.cpp
b/lib/Transforms/Utils/LowerSwitch.cpp
index 4cc92e982413d7436c7d1afe5562d0d037e010fd..914a439718d4438648e293d9c159d1e2ed4d8198 100644
(file)
--- a/
lib/Transforms/Utils/LowerSwitch.cpp
+++ b/
lib/Transforms/Utils/LowerSwitch.cpp
@@
-21,29
+21,29
@@
#include "llvm/LLVMContext.h"
#include "llvm/Pass.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/LLVMContext.h"
#include "llvm/Pass.h"
#include "llvm/ADT/STLExtras.h"
-#include "llvm/Support/Debug.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
using namespace llvm;
namespace {
/// LowerSwitch Pass - Replace all SwitchInst instructions with chained branch
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
using namespace llvm;
namespace {
/// LowerSwitch Pass - Replace all SwitchInst instructions with chained branch
- /// instructions. Note that this cannot be a BasicBlock pass because it
- /// modifies the CFG!
- class VISIBILITY_HIDDEN LowerSwitch : public FunctionPass {
+ /// instructions.
+ class LowerSwitch : public FunctionPass {
public:
static char ID; // Pass identification, replacement for typeid
public:
static char ID; // Pass identification, replacement for typeid
- LowerSwitch() : FunctionPass(&ID) {}
+ LowerSwitch() : FunctionPass(ID) {
+ initializeLowerSwitchPass(*PassRegistry::getPassRegistry());
+ }
virtual bool runOnFunction(Function &F);
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
// This is a cluster of orthogonal Transforms
AU.addPreserved<UnifyFunctionExitNodes>();
virtual bool runOnFunction(Function &F);
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
// This is a cluster of orthogonal Transforms
AU.addPreserved<UnifyFunctionExitNodes>();
- AU.addPreserved
ID(PromoteMemoryToRegisterID
);
+ AU.addPreserved
("mem2reg"
);
AU.addPreservedID(LowerInvokePassID);
AU.addPreservedID(LowerInvokePassID);
- AU.addPreservedID(LowerAllocationsID);
}
struct CaseRange {
}
struct CaseRange {
@@
-51,8
+51,7
@@
namespace {
Constant* High;
BasicBlock* BB;
Constant* High;
BasicBlock* BB;
- CaseRange() : Low(0), High(0), BB(0) { }
- CaseRange(Constant* low, Constant* high, BasicBlock* bb) :
+ CaseRange(Constant *low = 0, Constant *high = 0, BasicBlock *bb = 0) :
Low(low), High(high), BB(bb) { }
};
Low(low), High(high), BB(bb) { }
};
@@
-82,11
+81,11
@@
namespace {
}
char LowerSwitch::ID = 0;
}
char LowerSwitch::ID = 0;
-static RegisterPass<LowerSwitch>
-X("lowerswitch", "Lower SwitchInst's to branches");
+INITIALIZE_PASS(LowerSwitch, "lowerswitch",
+ "Lower SwitchInst's to branches", false, false)
// Publically exposed interface to pass...
// Publically exposed interface to pass...
-c
onst PassInfo *const llvm::LowerSwitchID = &X
;
+c
har &llvm::LowerSwitchID = LowerSwitch::ID
;
// createLowerSwitchPass - Interface to this file...
FunctionPass *llvm::createLowerSwitchPass() {
return new LowerSwitch();
// createLowerSwitchPass - Interface to this file...
FunctionPass *llvm::createLowerSwitchPass() {
return new LowerSwitch();
@@
-110,7
+109,8
@@
bool LowerSwitch::runOnFunction(Function &F) {
// operator<< - Used for debugging purposes.
//
static raw_ostream& operator<<(raw_ostream &O,
// operator<< - Used for debugging purposes.
//
static raw_ostream& operator<<(raw_ostream &O,
- const LowerSwitch::CaseVector &C) ATTRIBUTE_USED;
+ const LowerSwitch::CaseVector &C)
+ LLVM_ATTRIBUTE_USED;
static raw_ostream& operator<<(raw_ostream &O,
const LowerSwitch::CaseVector &C) {
O << "[";
static raw_ostream& operator<<(raw_ostream &O,
const LowerSwitch::CaseVector &C) {
O << "[";
@@
-138,12
+138,12
@@
BasicBlock* LowerSwitch::switchConvert(CaseItr Begin, CaseItr End,
unsigned Mid = Size / 2;
std::vector<CaseRange> LHS(Begin, Begin + Mid);
unsigned Mid = Size / 2;
std::vector<CaseRange> LHS(Begin, Begin + Mid);
- DEBUG(
err
s() << "LHS: " << LHS << "\n");
+ DEBUG(
dbg
s() << "LHS: " << LHS << "\n");
std::vector<CaseRange> RHS(Begin + Mid, End);
std::vector<CaseRange> RHS(Begin + Mid, End);
- DEBUG(
err
s() << "RHS: " << RHS << "\n");
+ DEBUG(
dbg
s() << "RHS: " << RHS << "\n");
CaseRange& Pivot = *(Begin + Mid);
CaseRange& Pivot = *(Begin + Mid);
- DEBUG(
err
s() << "Pivot ==> "
+ DEBUG(
dbg
s() << "Pivot ==> "
<< cast<ConstantInt>(Pivot.Low)->getValue() << " -"
<< cast<ConstantInt>(Pivot.High)->getValue() << "\n");
<< cast<ConstantInt>(Pivot.Low)->getValue() << " -"
<< cast<ConstantInt>(Pivot.High)->getValue() << "\n");
@@
-155,11
+155,11
@@
BasicBlock* LowerSwitch::switchConvert(CaseItr Begin, CaseItr End,
// Create a new node that checks if the value is < pivot. Go to the
// left branch if it is and right branch if not.
Function* F = OrigBlock->getParent();
// Create a new node that checks if the value is < pivot. Go to the
// left branch if it is and right branch if not.
Function* F = OrigBlock->getParent();
- BasicBlock* NewNode = BasicBlock::Create("NodeBlock");
+ BasicBlock* NewNode = BasicBlock::Create(
Val->getContext(),
"NodeBlock");
Function::iterator FI = OrigBlock;
F->getBasicBlockList().insert(++FI, NewNode);
Function::iterator FI = OrigBlock;
F->getBasicBlockList().insert(++FI, NewNode);
- ICmpInst* Comp = new ICmpInst(
Default->getContext(),
ICmpInst::ICMP_SLT,
+ ICmpInst* Comp = new ICmpInst(ICmpInst::ICMP_SLT,
Val, Pivot.Low, "Pivot");
NewNode->getInstList().push_back(Comp);
BranchInst::Create(LBranch, RBranch, Comp, NewNode);
Val, Pivot.Low, "Pivot");
NewNode->getInstList().push_back(Comp);
BranchInst::Create(LBranch, RBranch, Comp, NewNode);
@@
-177,7
+177,7
@@
BasicBlock* LowerSwitch::newLeafBlock(CaseRange& Leaf, Value* Val,
BasicBlock* Default)
{
Function* F = OrigBlock->getParent();
BasicBlock* Default)
{
Function* F = OrigBlock->getParent();
- BasicBlock* NewLeaf = BasicBlock::Create("LeafBlock");
+ BasicBlock* NewLeaf = BasicBlock::Create(
Val->getContext(),
"LeafBlock");
Function::iterator FI = OrigBlock;
F->getBasicBlockList().insert(++FI, NewLeaf);
Function::iterator FI = OrigBlock;
F->getBasicBlockList().insert(++FI, NewLeaf);
@@
-245,7
+245,7
@@
unsigned LowerSwitch::Clusterify(CaseVector& Cases, SwitchInst *SI) {
// Merge case into clusters
if (Cases.size()>=2)
// Merge case into clusters
if (Cases.size()>=2)
- for (CaseItr I=Cases.begin(), J=next(Cases.begin()); J!=Cases.end(); ) {
+ for (CaseItr I=Cases.begin(), J=
llvm::
next(Cases.begin()); J!=Cases.end(); ) {
int64_t nextValue = cast<ConstantInt>(J->Low)->getSExtValue();
int64_t currentValue = cast<ConstantInt>(I->High)->getSExtValue();
BasicBlock* nextBB = J->BB;
int64_t nextValue = cast<ConstantInt>(J->Low)->getSExtValue();
int64_t currentValue = cast<ConstantInt>(I->High)->getSExtValue();
BasicBlock* nextBB = J->BB;
@@
-289,7
+289,7
@@
void LowerSwitch::processSwitchInst(SwitchInst *SI) {
// Create a new, empty default block so that the new hierarchy of
// if-then statements go to this and the PHI nodes are happy.
// Create a new, empty default block so that the new hierarchy of
// if-then statements go to this and the PHI nodes are happy.
- BasicBlock* NewDefault = BasicBlock::Create("NewDefault");
+ BasicBlock* NewDefault = BasicBlock::Create(
SI->getContext(),
"NewDefault");
F->getBasicBlockList().insert(Default, NewDefault);
BranchInst::Create(Default, NewDefault);
F->getBasicBlockList().insert(Default, NewDefault);
BranchInst::Create(Default, NewDefault);
@@
-307,9
+307,9
@@
void LowerSwitch::processSwitchInst(SwitchInst *SI) {
CaseVector Cases;
unsigned numCmps = Clusterify(Cases, SI);
CaseVector Cases;
unsigned numCmps = Clusterify(Cases, SI);
- DEBUG(
err
s() << "Clusterify finished. Total clusters: " << Cases.size()
+ DEBUG(
dbg
s() << "Clusterify finished. Total clusters: " << Cases.size()
<< ". Total compares: " << numCmps << "\n");
<< ". Total compares: " << numCmps << "\n");
- DEBUG(
err
s() << "Cases: " << Cases << "\n");
+ DEBUG(
dbg
s() << "Cases: " << Cases << "\n");
(void)numCmps;
BasicBlock* SwitchBlock = switchConvert(Cases.begin(), Cases.end(), Val,
(void)numCmps;
BasicBlock* SwitchBlock = switchConvert(Cases.begin(), Cases.end(), Val,