aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/ExprTypeConvert.cpp56
-rw-r--r--lib/Transforms/IPO/FunctionResolution.cpp23
-rw-r--r--lib/Transforms/IPO/InlineSimple.cpp93
-rw-r--r--lib/Transforms/IPO/RaiseAllocations.cpp26
-rw-r--r--lib/Transforms/Instrumentation/TraceValues.cpp106
-rw-r--r--lib/Transforms/LevelRaise.cpp60
-rw-r--r--lib/Transforms/Scalar/ADCE.cpp51
-rw-r--r--lib/Transforms/Scalar/ConstantProp.cpp4
-rw-r--r--lib/Transforms/Scalar/DCE.cpp19
-rw-r--r--lib/Transforms/Scalar/DecomposeMultiDimRefs.cpp41
-rw-r--r--lib/Transforms/Scalar/GCSE.cpp133
-rw-r--r--lib/Transforms/Scalar/IndVarSimplify.cpp29
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp322
-rw-r--r--lib/Transforms/Scalar/LICM.cpp62
-rw-r--r--lib/Transforms/Scalar/PiNodeInsertion.cpp12
-rw-r--r--lib/Transforms/Scalar/Reassociate.cpp42
-rw-r--r--lib/Transforms/Scalar/SCCP.cpp132
-rw-r--r--lib/Transforms/Scalar/SimplifyCFG.cpp29
-rw-r--r--lib/Transforms/Scalar/SymbolStripping.cpp25
-rw-r--r--lib/Transforms/TransformInternals.cpp8
-rw-r--r--lib/Transforms/Utils/LowerAllocations.cpp44
-rw-r--r--lib/Transforms/Utils/PromoteMemoryToRegister.cpp21
22 files changed, 627 insertions, 711 deletions
diff --git a/lib/Transforms/ExprTypeConvert.cpp b/lib/Transforms/ExprTypeConvert.cpp
index a1f6425302..a6106b0822 100644
--- a/lib/Transforms/ExprTypeConvert.cpp
+++ b/lib/Transforms/ExprTypeConvert.cpp
@@ -31,7 +31,7 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
static bool AllIndicesZero(const MemAccessInst *MAI) {
for (User::const_op_iterator S = MAI->idx_begin(), E = MAI->idx_end();
S != E; ++S)
- if (!isa<Constant>(*S) || !cast<Constant>(*S)->isNullValue())
+ if (!isa<Constant>(S->get()) || !cast<Constant>(S->get())->isNullValue())
return false;
return true;
}
@@ -110,7 +110,7 @@ static Instruction *ConvertMallocToType(MallocInst *MI, const Type *Ty,
unsigned Scale = (unsigned)ScaleVal * OldTypeSize / DataSize;
// Locate the malloc instruction, because we may be inserting instructions
- It = find(BB->getInstList().begin(), BB->getInstList().end(), MI);
+ It = MI;
// If we have a scale, apply it first...
if (Expr.Var) {
@@ -118,7 +118,7 @@ static Instruction *ConvertMallocToType(MallocInst *MI, const Type *Ty,
if (Expr.Var->getType() != Type::UIntTy) {
Instruction *CI = new CastInst(Expr.Var, Type::UIntTy);
if (Expr.Var->hasName()) CI->setName(Expr.Var->getName()+"-uint");
- It = BB->getInstList().insert(It, CI)+1;
+ It = ++BB->getInstList().insert(It, CI);
Expr.Var = CI;
}
@@ -127,7 +127,7 @@ static Instruction *ConvertMallocToType(MallocInst *MI, const Type *Ty,
BinaryOperator::create(Instruction::Mul, Expr.Var,
ConstantUInt::get(Type::UIntTy, Scale));
if (Expr.Var->hasName()) ScI->setName(Expr.Var->getName()+"-scl");
- It = BB->getInstList().insert(It, ScI)+1;
+ It = ++BB->getInstList().insert(It, ScI);
Expr.Var = ScI;
}
@@ -145,7 +145,7 @@ static Instruction *ConvertMallocToType(MallocInst *MI, const Type *Ty,
BinaryOperator::create(Instruction::Add, Expr.Var,
ConstantUInt::get(Type::UIntTy, Offset));
if (Expr.Var->hasName()) AddI->setName(Expr.Var->getName()+"-off");
- It = BB->getInstList().insert(It, AddI)+1;
+ It = ++BB->getInstList().insert(It, AddI);
Expr.Var = AddI;
}
@@ -193,9 +193,10 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty,
// We also do not allow conversion of a cast that casts from a ptr to array
// of X to a *X. For example: cast [4 x %List *] * %val to %List * *
//
- if (PointerType *SPT = dyn_cast<PointerType>(I->getOperand(0)->getType()))
- if (PointerType *DPT = dyn_cast<PointerType>(I->getType()))
- if (ArrayType *AT = dyn_cast<ArrayType>(SPT->getElementType()))
+ if (const PointerType *SPT =
+ dyn_cast<PointerType>(I->getOperand(0)->getType()))
+ if (const PointerType *DPT = dyn_cast<PointerType>(I->getType()))
+ if (const ArrayType *AT = dyn_cast<ArrayType>(SPT->getElementType()))
if (AT->getElementType() == DPT->getElementType())
return false;
break;
@@ -475,7 +476,7 @@ Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC) {
// and we could convert this to an appropriate GEP for the new type.
//
const PointerType *NewSrcTy = PointerType::get(PVTy);
- BasicBlock::iterator It = find(BIL.begin(), BIL.end(), I);
+ BasicBlock::iterator It = I;
// Check to see if 'N' is an expression that can be converted to
// the appropriate size... if so, allow it.
@@ -519,9 +520,7 @@ Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC) {
assert(Res->getType() == Ty && "Didn't convert expr to correct type!");
- BasicBlock::iterator It = find(BIL.begin(), BIL.end(), I);
- assert(It != BIL.end() && "Instruction not in own basic block??");
- BIL.insert(It, Res);
+ BIL.insert(I, Res);
// Add the instruction to the expression map
VMC.ExprMap[I] = Res;
@@ -618,9 +617,10 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
// We also do not allow conversion of a cast that casts from a ptr to array
// of X to a *X. For example: cast [4 x %List *] * %val to %List * *
//
- if (PointerType *SPT = dyn_cast<PointerType>(I->getOperand(0)->getType()))
- if (PointerType *DPT = dyn_cast<PointerType>(I->getType()))
- if (ArrayType *AT = dyn_cast<ArrayType>(SPT->getElementType()))
+ if (const PointerType *SPT =
+ dyn_cast<PointerType>(I->getOperand(0)->getType()))
+ if (const PointerType *DPT = dyn_cast<PointerType>(I->getType()))
+ if (const ArrayType *AT = dyn_cast<ArrayType>(SPT->getElementType()))
if (AT->getElementType() == DPT->getElementType())
return false;
return true;
@@ -719,7 +719,7 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
// a whole structure at a time), so the level raiser must be trying to
// store into the first field. Check for this and allow it now:
//
- if (StructType *SElTy = dyn_cast<StructType>(ElTy)) {
+ if (const StructType *SElTy = dyn_cast<StructType>(ElTy)) {
unsigned Offset = 0;
std::vector<Value*> Indices;
ElTy = getStructOffsetType(ElTy, Offset, Indices, false);
@@ -817,9 +817,9 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
// Are we trying to change the function pointer value to a new type?
if (OpNum == 0) {
- PointerType *PTy = dyn_cast<PointerType>(Ty);
+ const PointerType *PTy = dyn_cast<PointerType>(Ty);
if (PTy == 0) return false; // Can't convert to a non-pointer type...
- FunctionType *MTy = dyn_cast<FunctionType>(PTy->getElementType());
+ const FunctionType *MTy = dyn_cast<FunctionType>(PTy->getElementType());
if (MTy == 0) return false; // Can't convert to a non ptr to function...
// Perform sanity checks to make sure that new function type has the
@@ -926,7 +926,7 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
if (isa<PointerType>(NewTy)) {
Value *IndexVal = I->getOperand(OldVal == I->getOperand(0) ? 1 : 0);
std::vector<Value*> Indices;
- BasicBlock::iterator It = find(BIL.begin(), BIL.end(), I);
+ BasicBlock::iterator It = I;
if (const Type *ETy = ConvertableToGEP(NewTy, IndexVal, Indices, &It)) {
// If successful, convert the add to a GEP
@@ -1016,7 +1016,7 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
// Convert a one index getelementptr into just about anything that is
// desired.
//
- BasicBlock::iterator It = find(BIL.begin(), BIL.end(), I);
+ BasicBlock::iterator It = I;
const Type *OldElTy = cast<PointerType>(I->getType())->getElementType();
unsigned DataSize = TD.getTypeSize(OldElTy);
Value *Index = I->getOperand(1);
@@ -1025,7 +1025,7 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
// Insert a multiply of the old element type is not a unit size...
Index = BinaryOperator::create(Instruction::Mul, Index,
ConstantUInt::get(Type::UIntTy, DataSize));
- It = BIL.insert(It, cast<Instruction>(Index))+1;
+ It = ++BIL.insert(It, cast<Instruction>(Index));
}
// Perform the conversion now...
@@ -1042,7 +1042,7 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
// Convert a getelementptr sbyte * %reg111, uint 16 freely back to
// anything that is a pointer type...
//
- BasicBlock::iterator It = find(BIL.begin(), BIL.end(), I);
+ BasicBlock::iterator It = I;
// Check to see if the second argument is an expression that can
// be converted to the appropriate size... if so, allow it.
@@ -1086,8 +1086,8 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
std::vector<Value*> Params(I->op_begin()+1, I->op_end());
if (Meth == OldVal) { // Changing the function pointer?
- PointerType *NewPTy = cast<PointerType>(NewVal->getType());
- FunctionType *NewTy = cast<FunctionType>(NewPTy->getElementType());
+ const PointerType *NewPTy = cast<PointerType>(NewVal->getType());
+ const FunctionType *NewTy = cast<FunctionType>(NewPTy->getElementType());
const FunctionType::ParamTypes &PTs = NewTy->getParamTypes();
// Get an iterator to the call instruction so that we can insert casts for
@@ -1096,7 +1096,7 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
// compatible. The reason for this is that we prefer to have resolved
// functions but casted arguments if possible.
//
- BasicBlock::iterator It = find(BIL.begin(), BIL.end(), I);
+ BasicBlock::iterator It = I;
// Convert over all of the call operands to their new types... but only
// convert over the part that is not in the vararg section of the call.
@@ -1107,7 +1107,7 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
// is a lossless cast...
//
Params[i] = new CastInst(Params[i], PTs[i], "call.resolve.cast");
- It = BIL.insert(It, cast<Instruction>(Params[i]))+1;
+ It = ++BIL.insert(It, cast<Instruction>(Params[i]));
}
Meth = NewVal; // Update call destination to new value
@@ -1130,7 +1130,7 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
// If the instruction was newly created, insert it into the instruction
// stream.
//
- BasicBlock::iterator It = find(BIL.begin(), BIL.end(), I);
+ BasicBlock::iterator It = I;
assert(It != BIL.end() && "Instruction not in own basic block??");
BIL.insert(It, Res); // Keep It pointing to old instruction
@@ -1186,7 +1186,7 @@ static void RecursiveDelete(ValueMapCache &Cache, Instruction *I) {
for (User::op_iterator OI = I->op_begin(), OE = I->op_end();
OI != OE; ++OI)
- if (Instruction *U = dyn_cast<Instruction>(*OI)) {
+ if (Instruction *U = dyn_cast<Instruction>(OI->get())) {
*OI = 0;
RecursiveDelete(Cache, U);
}
diff --git a/lib/Transforms/IPO/FunctionResolution.cpp b/lib/Transforms/IPO/FunctionResolution.cpp
index 9eb6e54eec..6cb901b79f 100644
--- a/lib/Transforms/IPO/FunctionResolution.cpp
+++ b/lib/Transforms/IPO/FunctionResolution.cpp
@@ -13,8 +13,6 @@
#include "llvm/Transforms/CleanupGCCOutput.h"
#include "llvm/Module.h"
-#include "llvm/Function.h"
-#include "llvm/BasicBlock.h"
#include "llvm/SymbolTable.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Pass.h"
@@ -34,7 +32,7 @@ namespace {
struct FunctionResolvingPass : public Pass {
const char *getPassName() const { return "Resolve Functions"; }
- bool run(Module *M);
+ bool run(Module &M);
};
}
@@ -50,12 +48,10 @@ static void ConvertCallTo(CallInst *CI, Function *Dest) {
Dest->getFunctionType()->getParamTypes();
BasicBlock *BB = CI->getParent();
- // Get an iterator to where we want to insert cast instructions if the
+ // Keep an iterator to where we want to insert cast instructions if the
// argument types don't agree.
//
- BasicBlock::iterator BBI = find(BB->begin(), BB->end(), CI);
- assert(BBI != BB->end() && "CallInst not in parent block?");
-
+ BasicBlock::iterator BBI = CI;
assert(CI->getNumOperands()-1 == ParamTys.size() &&
"Function calls resolved funny somehow, incompatible number of args");
@@ -68,7 +64,7 @@ static void ConvertCallTo(CallInst *CI, Function *Dest) {
if (V->getType() != ParamTys[i-1]) { // Must insert a cast...
Instruction *Cast = new CastInst(V, ParamTys[i-1]);
- BBI = BB->getInstList().insert(BBI, Cast)+1;
+ BBI = ++BB->getInstList().insert(BBI, Cast);
V = Cast;
}
@@ -80,7 +76,7 @@ static void ConvertCallTo(CallInst *CI, Function *Dest) {
// Replace the old call instruction with a new call instruction that calls
// the real function.
//
- BBI = BB->getInstList().insert(BBI, NewCall)+1;
+ BBI = ++BB->getInstList().insert(BBI, NewCall);
// Remove the old call instruction from the program...
BB->getInstList().remove(BBI);
@@ -110,8 +106,8 @@ static void ConvertCallTo(CallInst *CI, Function *Dest) {
}
-bool FunctionResolvingPass::run(Module *M) {
- SymbolTable *ST = M->getSymbolTable();
+bool FunctionResolvingPass::run(Module &M) {
+ SymbolTable *ST = M.getSymbolTable();
if (!ST) return false;
std::map<string, vector<Function*> > Functions;
@@ -151,9 +147,8 @@ bool FunctionResolvingPass::run(Module *M) {
// warnings... here we will actually DCE the function so that it isn't
// used later.
//
- if (Functions[i]->use_size() == 0) {
- M->getFunctionList().remove(Functions[i]);
- delete Functions[i];
+ if (Functions[i]->use_empty()) {
+ M.getFunctionList().erase(Functions[i]);
Functions.erase(Functions.begin()+i);
Changed = true;
++NumResolved;
diff --git a/lib/Transforms/IPO/InlineSimple.cpp b/lib/Transforms/IPO/InlineSimple.cpp
index 12430e1270..7d36e379bc 100644
--- a/lib/Transforms/IPO/InlineSimple.cpp
+++ b/lib/Transforms/IPO/InlineSimple.cpp
@@ -20,18 +20,16 @@
#include "llvm/Transforms/FunctionInlining.h"
#include "llvm/Module.h"
-#include "llvm/Function.h"
#include "llvm/Pass.h"
#include "llvm/iTerminators.h"
#include "llvm/iPHINode.h"
#include "llvm/iOther.h"
#include "llvm/Type.h"
-#include "llvm/Argument.h"
#include "Support/StatisticReporter.h"
-
-static Statistic<> NumInlined("inline\t\t- Number of functions inlined");
#include <algorithm>
#include <iostream>
+
+static Statistic<> NumInlined("inline\t\t- Number of functions inlined");
using std::cerr;
// RemapInstruction - Convert the instruction operands from referencing the
@@ -65,17 +63,16 @@ static inline void RemapInstruction(Instruction *I,
// exists in the instruction stream. Similiarly this will inline a recursive
// function by one level.
//
-bool InlineFunction(BasicBlock::iterator CIIt) {
- assert(isa<CallInst>(*CIIt) && "InlineFunction only works on CallInst nodes");
- assert((*CIIt)->getParent() && "Instruction not embedded in basic block!");
- assert((*CIIt)->getParent()->getParent() && "Instruction not in function!");
+bool InlineFunction(CallInst *CI) {
+ assert(isa<CallInst>(CI) && "InlineFunction only works on CallInst nodes");
+ assert(CI->getParent() && "Instruction not embedded in basic block!");
+ assert(CI->getParent()->getParent() && "Instruction not in function!");
- CallInst *CI = cast<CallInst>(*CIIt);
- const Function *CalledMeth = CI->getCalledFunction();
- if (CalledMeth == 0 || // Can't inline external function or indirect call!
- CalledMeth->isExternal()) return false;
+ const Function *CalledFunc = CI->getCalledFunction();
+ if (CalledFunc == 0 || // Can't inline external function or indirect call!
+ CalledFunc->isExternal()) return false;
- //cerr << "Inlining " << CalledMeth->getName() << " into "
+ //cerr << "Inlining " << CalledFunc->getName() << " into "
// << CurrentMeth->getName() << "\n";
BasicBlock *OrigBB = CI->getParent();
@@ -84,7 +81,7 @@ bool InlineFunction(BasicBlock::iterator CIIt) {
// immediately before the call. The original basic block now ends with an
// unconditional branch to NewBB, and NewBB starts with the call instruction.
//
- BasicBlock *NewBB = OrigBB->splitBasicBlock(CIIt);
+ BasicBlock *NewBB = OrigBB->splitBasicBlock(CI);
NewBB->setName("InlinedFunctionReturnNode");
// Remove (unlink) the CallInst from the start of the new basic block.
@@ -95,8 +92,8 @@ bool InlineFunction(BasicBlock::iterator CIIt) {
// function.
//
PHINode *PHI = 0;
- if (CalledMeth->getReturnType() != Type::VoidTy) {
- PHI = new PHINode(CalledMeth->getReturnType(), CI->getName());
+ if (CalledFunc->getReturnType() != Type::VoidTy) {
+ PHI = new PHINode(CalledFunc->getReturnType(), CI->getName());
// The PHI node should go at the front of the new basic block to merge all
// possible incoming values.
@@ -118,19 +115,17 @@ bool InlineFunction(BasicBlock::iterator CIIt) {
// Add the function arguments to the mapping: (start counting at 1 to skip the
// function reference itself)
//
- Function::ArgumentListType::const_iterator PTI =
- CalledMeth->getArgumentList().begin();
+ Function::const_aiterator PTI = CalledFunc->abegin();
for (unsigned a = 1, E = CI->getNumOperands(); a != E; ++a, ++PTI)
- ValueMap[*PTI] = CI->getOperand(a);
+ ValueMap[PTI] = CI->getOperand(a);
ValueMap[NewBB] = NewBB; // Returns get converted to reference NewBB
// Loop over all of the basic blocks in the function, inlining them as
// appropriate. Keep track of the first basic block of the function...
//
- for (Function::const_iterator BI = CalledMeth->begin();
- BI != CalledMeth->end(); ++BI) {
- const BasicBlock *BB = *BI;
+ for (Function::const_iterator BB = CalledFunc->begin();
+ BB != CalledFunc->end(); ++BB) {
assert(BB->getTerminator() && "BasicBlock doesn't have terminator!?!?");
// Create a new basic block to copy instructions into!
@@ -148,23 +143,24 @@ bool InlineFunction(BasicBlock::iterator CIIt) {
// Loop over all instructions copying them over...
Instruction *NewInst;
for (BasicBlock::const_iterator II = BB->begin();
- II != (BB->end()-1); ++II) {
- IBB->getInstList().push_back((NewInst = (*II)->clone()));
- ValueMap[*II] = NewInst; // Add instruction map to value.
- if ((*II)->hasName())
- NewInst->setName((*II)->getName()+".i"); // .i = inlined once
+ II != --BB->end(); ++II) {
+ IBB->getInstList().push_back((NewInst = II->clone()));
+ ValueMap[II] = NewInst; // Add instruction map to value.
+ if (II->hasName())
+ NewInst->setName(II->getName()+".i"); // .i = inlined once
}
// Copy over the terminator now...
switch (TI->getOpcode()) {
case Instruction::Ret: {
- const ReturnInst *RI = cast<const ReturnInst>(TI);
+ const ReturnInst *RI = cast<ReturnInst>(TI);
if (PHI) { // The PHI node should include this value!
assert(RI->getReturnValue() && "Ret should have value!");
assert(RI->getReturnValue()->getType() == PHI->getType() &&
"Ret value not consistent in function!");
- PHI->addIncoming((Value*)RI->getReturnValue(), cast<BasicBlock>(BB));
+ PHI->addIncoming((Value*)RI->getReturnValue(),
+ (BasicBlock*)cast<BasicBlock>(&*BB));
}
// Add a branch to the code that was after the original Call.
@@ -185,15 +181,14 @@ bool InlineFunction(BasicBlock::iterator CIIt) {
// Loop over all of the instructions in the function, fixing up operand
// references as we go. This uses ValueMap to do all the hard work.
//
- for (Function::const_iterator BI = CalledMeth->begin();
- BI != CalledMeth->end(); ++BI) {
- const BasicBlock *BB = *BI;
+ for (Function::const_iterator BB = CalledFunc->begin();
+ BB != CalledFunc->end(); ++BB) {
BasicBlock *NBB = (BasicBlock*)ValueMap[BB];
// Loop over all instructions, fixing each one as we find it...
//
- for (BasicBlock::iterator II = NBB->begin(); II != NBB->end(); II++)
- RemapInstruction(*II, ValueMap);
+ for (BasicBlock::iterator II = NBB->begin(); II != NBB->end(); ++II)
+ RemapInstruction(II, ValueMap);
}
if (PHI) RemapInstruction(PHI, ValueMap); // Fix the PHI node also...
@@ -204,24 +199,13 @@ bool InlineFunction(BasicBlock::iterator CIIt) {
TerminatorInst *Br = OrigBB->getTerminator();
assert(Br && Br->getOpcode() == Instruction::Br &&
"splitBasicBlock broken!");
- Br->setOperand(0, ValueMap[CalledMeth->front()]);
+ Br->setOperand(0, ValueMap[&CalledFunc->front()]);
// Since we are now done with the CallInst, we can finally delete it.
delete CI;
return true;
}
-bool InlineFunction(CallInst *CI) {
- assert(CI->getParent() && "CallInst not embeded in BasicBlock!");
- BasicBlock *PBB = CI->getParent();
-
- BasicBlock::iterator CallIt = find(PBB->begin(), PBB->end(), CI);
-
- assert(CallIt != PBB->end() &&
- "CallInst has parent that doesn't contain CallInst?!?");
- return InlineFunction(CallIt);
-}
-
static inline bool ShouldInlineFunction(const CallInst *CI, const Function *F) {
assert(CI->getParent() && CI->getParent()->getParent() &&
"Call not embedded into a function!");
@@ -242,11 +226,12 @@ static inline bool ShouldInlineFunction(const CallInst *CI, const Function *F) {
static inline bool DoFunctionInlining(BasicBlock *BB) {
for (BasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) {
- if (CallInst *CI = dyn_cast<CallInst>(*I)) {
+ if (CallInst *CI = dyn_cast<CallInst>(&*I)) {
// Check to see if we should inline this function
Function *F = CI->getCalledFunction();
- if (F && ShouldInlineFunction(CI, F))
- return InlineFunction(I);
+ if (F && ShouldInlineFunction(CI, F)) {
+ return InlineFunction(CI);
+ }
}
}
return false;
@@ -255,16 +240,14 @@ static inline bool DoFunctionInlining(BasicBlock *BB) {
// doFunctionInlining - Use a heuristic based approach to inline functions that
// seem to look good.
//
-static bool doFunctionInlining(Function *F) {
+static bool doFunctionInlining(Function &F) {
bool Changed = false;
// Loop through now and inline instructions a basic block at a time...
- for (Function::iterator I = F->begin(); I != F->end(); )
- if (DoFunctionInlining(*I)) {
+ for (Function::iterator I = F.begin(); I != F.end(); )
+ if (DoFunctionInlining(I)) {
++NumInlined;
Changed = true;
- // Iterator is now invalidated by new basic blocks inserted
- I = F->begin();
} else {
++I;
}
@@ -275,7 +258,7 @@ static bool doFunctionInlining(Function *F) {
namespace {
struct FunctionInlining : public FunctionPass {
const char *getPassName() const { return "Function Inlining"; }
- virtual bool runOnFunction(Function *F) {
+ virtual bool runOnFunction(Function &F) {
return doFunctionInlining(F);
}
};
diff --git a/lib/Transforms/IPO/RaiseAllocations.cpp b/lib/Transforms/IPO/RaiseAllocations.cpp
index 5dc1254db9..42e1a28af7 100644
--- a/lib/Transforms/IPO/RaiseAllocations.cpp
+++ b/lib/Transforms/IPO/RaiseAllocations.cpp
@@ -33,12 +33,12 @@ public:
// doPassInitialization - For the raise allocations pass, this finds a
// declaration for malloc and free if they exist.
//
- bool doInitialization(Module *M);
+ bool doInitialization(Module &M);
// runOnBasicBlock - This method does the actual work of converting
// instructions over, assuming that the pass has already been initialized.
//
- bool runOnBasicBlock(BasicBlock *BB);
+ bool runOnBasicBlock(BasicBlock &BB);
};
} // end anonymous namespace
@@ -50,7 +50,7 @@ Pass *createRaiseAllocationsPass() {
}
-bool RaiseAllocations::doInitialization(Module *M) {
+bool RaiseAllocations::doInitialization(Module &M) {
// If the module has a symbol table, they might be referring to the malloc
// and free functions. If this is the case, grab the method pointers that
// the module is using.
@@ -68,22 +68,22 @@ bool RaiseAllocations::doInitialization(Module *M) {
std::vector<const Type*>(1, PointerType::get(Type::SByteTy)),
false);
- MallocFunc = M->getFunction("malloc", MallocType);
- FreeFunc = M->getFunction("free" , FreeType);
+ MallocFunc = M.getFunction("malloc", MallocType);
+ FreeFunc = M.getFunction("free" , FreeType);
// Check to see if the prototype is missing, giving us sbyte*(...) * malloc
// This handles the common declaration of: 'char *malloc();'
if (MallocFunc == 0) {
MallocType = FunctionType::get(PointerType::get(Type::SByteTy),
std::vector<const Type*>(), true);
- MallocFunc = M->getFunction("malloc", MallocType);
+ MallocFunc = M.getFunction("malloc", MallocType);
}
// Check to see if the prototype was forgotten, giving us void (...) * free
// This handles the common forward declaration of: 'void free();'
if (FreeFunc == 0) {
FreeType = FunctionType::get(Type::VoidTy, std::vector<const Type*>(),true);
- FreeFunc = M->getFunction("free", FreeType);
+ FreeFunc = M.getFunction("free", FreeType);
}
@@ -95,12 +95,12 @@ bool RaiseAllocations::doInitialization(Module *M) {
// runOnBasicBlock - Process a basic block, fixing it up...
//
-bool RaiseAllocations::runOnBasicBlock(BasicBlock *BB) {
+bool RaiseAllocations::runOnBasicBlock(BasicBlock &BB) {
bool Changed = false;
- BasicBlock::InstListType &BIL = BB->getInstList();
+ BasicBlock::InstListType &BIL = BB.getInstList();
- for (BasicBlock::iterator BI = BB->begin(); BI != BB->end();) {
- Instruction *I = *BI;
+ for (BasicBlock::iterator BI = BB.begin(); BI != BB.end();) {
+ Instruction *I = BI;
if (CallInst *CI = dyn_cast<CallInst>(I)) {
if (CI->getCalledValue() == MallocFunc) { // Replace call to malloc?
@@ -111,7 +111,7 @@ bool RaiseAllocations::runOnBasicBlock(BasicBlock *BB) {
// source size.
if (Source->getType() != Type::UIntTy) {
CastInst *New = new CastInst(Source, Type::UIntTy, "MallocAmtCast");
- BI = BIL.insert(BI, New)+1;
+ BI = ++BIL.insert(BI, New);
Source = New;
}
@@ -132,7 +132,7 @@ bool RaiseAllocations::runOnBasicBlock(BasicBlock *BB) {
if (!isa<PointerType>(Source->getType())) {
CastInst *New = new CastInst(Source, PointerType::get(Type::SByteTy),
"FreePtrCast");
- BI = BIL.insert(BI, New)+1;
+ BI = ++BIL.insert(BI, New);
Source = New;
}
diff --git a/lib/Transforms/Instrumentation/TraceValues.cpp b/lib/Transforms/Instrumentation/TraceValues.cpp
index 079edced64..92aff1217d 100644
--- a/lib/Transforms/Instrumentation/TraceValues.cpp
+++ b/lib/Transforms/Instrumentation/TraceValues.cpp
@@ -49,7 +49,7 @@ namespace {
struct ExternalFuncs {
Function *PrintfFunc, *HashPtrFunc, *ReleasePtrFunc;
Function *RecordPtrFunc, *PushOnEntryFunc, *ReleaseOnReturnFunc;
- void doInitialization(Module *M); // Add prototypes for external functions
+ void doInitialization(Module &M); // Add prototypes for external functions
};
class InsertTraceCode : public FunctionPass {
@@ -64,7 +64,7 @@ namespace {
// Add a prototype for runtime functions not already in the program.
//
- bool doInitialization(Module *M);
+ bool doInitialization(Module &M);
//--------------------------------------------------------------------------
// Function InsertCodeToTraceValues
@@ -77,8 +77,8 @@ namespace {
// runOnFunction - This method does the work.
//
- bool runOnFunction(Function *F) {
- return doit(F, TraceBasicBlockExits, TraceFunctionExits, externalFuncs);
+ bool runOnFunction(Function &F) {
+ return doit(&F, TraceBasicBlockExits, TraceFunctionExits, externalFuncs);
}
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
@@ -98,36 +98,36 @@ Pass *createTraceValuesPassForBasicBlocks() { // Trace BB's and functions
// Add a prototype for external functions used by the tracing code.
//
-void ExternalFuncs::doInitialization(Module *M) {
+void ExternalFuncs::doInitialization(Module &M) {
const Type *SBP = PointerType::get(Type::SByteTy);
const FunctionType *MTy =
FunctionType::get(Type::IntTy, vector<const Type*>(1, SBP), true);
- PrintfFunc = M->getOrInsertFunction("printf", MTy);
+ PrintfFunc = M.getOrInsertFunction("printf", MTy);
// uint (sbyte*)
const FunctionType *hashFuncTy =
FunctionType::get(Type::UIntTy, vector<const Type*>(1, SBP), false);
- HashPtrFunc = M->getOrInsertFunction("HashPointerToSeqNum", hashFuncTy);
+ HashPtrFunc = M.getOrInsertFunction("HashPointerToSeqNum", hashFuncTy);
// void (sbyte*)
const FunctionType *voidSBPFuncTy =
FunctionType::get(Type::VoidTy, vector<const Type*>(1, SBP), false);
- ReleasePtrFunc =M->getOrInsertFunction("ReleasePointerSeqNum", voidSBPFuncTy);
- RecordPtrFunc = M->getOrInsertFunction("RecordPointer", voidSBPFuncTy);
+ ReleasePtrFunc = M.getOrInsertFunction("ReleasePointerSeqNum", voidSBPFuncTy);
+ RecordPtrFunc = M.getOrInsertFunction("RecordPointer", voidSBPFuncTy);
const FunctionType *voidvoidFuncTy =
FunctionType::get(Type::VoidTy, vector<const Type*>(), false);
- PushOnEntryFunc = M->getOrInsertFunction("PushPointerSet", voidvoidFuncTy);
- ReleaseOnReturnFunc = M->getOrInsertFunction("ReleasePointersPopSet",
+ PushOnEntryFunc = M.getOrInsertFunction("PushPointerSet", voidvoidFuncTy);
+ ReleaseOnReturnFunc = M.getOrInsertFunction("ReleasePointersPopSet",
voidvoidFuncTy);
}
// Add a prototype for external functions used by the tracing code.
//
-bool InsertTraceCode::doInitialization(Module *M) {
+bool InsertTraceCode::doInitialization(Module &M) {
externalFuncs.doInitialization(M);
return false;
}
@@ -214,20 +214,20 @@ static void InsertPrintInst(Value *V,BasicBlock *BB, BasicBlock::iterator &BBI,
new GetElementPtrInst(fmtVal,
vector<Value*>(2,ConstantUInt::get(Type::UIntTy, 0)),
"trstr");
- BBI = BB->getInstList().insert(BBI, GEP)+1;
+ BBI = ++BB->getInstList().insert(BBI, GEP);
// Insert a call to the hash function if this is a pointer value
if (V && isa<PointerType>(V->getType()) && !DisablePtrHashing) {
const Type *SBP = PointerType::get(Type::SByteTy);
if (V->getType() != SBP) { // Cast pointer to be sbyte*
Instruction *I = new CastInst(V, SBP, "Hash_cast");
- BBI = BB->getInstList().insert(BBI, I)+1;
+ BBI = ++BB->getInstList().insert(BBI, I);
V = I;
}
vector<Value*> HashArgs(1, V);
V = new CallInst(HashPtrToSeqNum, HashArgs, "ptrSeqNum");
- BBI = BB->getInstList().insert(BBI, cast<Instruction>(V))+1;
+ BBI = ++BB->getInstList().insert(BBI, cast<Instruction>(V));
}
// Insert the first print instruction to print the string flag:
@@ -235,7 +235,7 @@ static void InsertPrintInst(Value *V,BasicBlock *BB, BasicBlock::iterator &BBI,
PrintArgs.push_back(GEP);
if (V) PrintArgs.push_back(V);
Instruction *I = new CallInst(Printf, PrintArgs, "trace");
- BBI = BB->getInstList().insert(BBI, I)+1;
+ BBI = ++BB->getInstList().insert(BBI, I);
}
@@ -257,12 +257,12 @@ InsertReleaseInst(Value *V, BasicBlock *BB,
const Type *SBP = PointerType::get(Type::SByteTy);
if (V->getType()