summaryrefslogtreecommitdiff
path: root/lib/Transforms/Instrumentation
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-07-06 18:42:36 +0000
committerOwen Anderson <resistor@mac.com>2009-07-06 18:42:36 +0000
commit508955156a25a9abc470a29e1760aa176d341cf9 (patch)
tree8b7b55caabc0fbb16b6025f38e84ebc4fbd79c31 /lib/Transforms/Instrumentation
parente034393b15bc9257314b0c7adfb778e0c504bed7 (diff)
downloadllvm-508955156a25a9abc470a29e1760aa176d341cf9.tar.gz
llvm-508955156a25a9abc470a29e1760aa176d341cf9.tar.bz2
llvm-508955156a25a9abc470a29e1760aa176d341cf9.tar.xz
Thread LLVMContext through the constant folding APIs, which touches a lot of files.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74844 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Instrumentation')
-rw-r--r--lib/Transforms/Instrumentation/BlockProfiling.cpp9
-rw-r--r--lib/Transforms/Instrumentation/EdgeProfiling.cpp5
-rw-r--r--lib/Transforms/Instrumentation/ProfilingUtils.cpp29
-rw-r--r--lib/Transforms/Instrumentation/RSProfiling.cpp34
4 files changed, 45 insertions, 32 deletions
diff --git a/lib/Transforms/Instrumentation/BlockProfiling.cpp b/lib/Transforms/Instrumentation/BlockProfiling.cpp
index 2bd9809a39..913680cdd0 100644
--- a/lib/Transforms/Instrumentation/BlockProfiling.cpp
+++ b/lib/Transforms/Instrumentation/BlockProfiling.cpp
@@ -21,6 +21,7 @@
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Pass.h"
#include "llvm/Support/Compiler.h"
@@ -62,10 +63,10 @@ bool FunctionProfiler::runOnModule(Module &M) {
if (!I->isDeclaration())
++NumFunctions;
- const Type *ATy = ArrayType::get(Type::Int32Ty, NumFunctions);
+ const Type *ATy = Context->getArrayType(Type::Int32Ty, NumFunctions);
GlobalVariable *Counters =
new GlobalVariable(ATy, false, GlobalValue::InternalLinkage,
- Constant::getNullValue(ATy), "FuncProfCounters", &M);
+ Context->getNullValue(ATy), "FuncProfCounters", &M);
// Instrument all of the functions...
unsigned i = 0;
@@ -107,10 +108,10 @@ bool BlockProfiler::runOnModule(Module &M) {
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
NumBlocks += I->size();
- const Type *ATy = ArrayType::get(Type::Int32Ty, NumBlocks);
+ const Type *ATy = Context->getArrayType(Type::Int32Ty, NumBlocks);
GlobalVariable *Counters =
new GlobalVariable(ATy, false, GlobalValue::InternalLinkage,
- Constant::getNullValue(ATy), "BlockProfCounters", &M);
+ Context->getNullValue(ATy), "BlockProfCounters", &M);
// Instrument all of the blocks...
unsigned i = 0;
diff --git a/lib/Transforms/Instrumentation/EdgeProfiling.cpp b/lib/Transforms/Instrumentation/EdgeProfiling.cpp
index 0831f3b7a4..88825b164c 100644
--- a/lib/Transforms/Instrumentation/EdgeProfiling.cpp
+++ b/lib/Transforms/Instrumentation/EdgeProfiling.cpp
@@ -20,6 +20,7 @@
#include "ProfilingUtils.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Pass.h"
#include "llvm/Support/Compiler.h"
@@ -63,10 +64,10 @@ bool EdgeProfiler::runOnModule(Module &M) {
NumEdges += BB->getTerminator()->getNumSuccessors();
}
- const Type *ATy = ArrayType::get(Type::Int32Ty, NumEdges);
+ const Type *ATy = Context->getArrayType(Type::Int32Ty, NumEdges);
GlobalVariable *Counters =
new GlobalVariable(ATy, false, GlobalValue::InternalLinkage,
- Constant::getNullValue(ATy), "EdgeProfCounters", &M);
+ Context->getNullValue(ATy), "EdgeProfCounters", &M);
// Instrument all of the edges...
unsigned i = 0;
diff --git a/lib/Transforms/Instrumentation/ProfilingUtils.cpp b/lib/Transforms/Instrumentation/ProfilingUtils.cpp
index 48071f1156..8ae4c4f078 100644
--- a/lib/Transforms/Instrumentation/ProfilingUtils.cpp
+++ b/lib/Transforms/Instrumentation/ProfilingUtils.cpp
@@ -18,13 +18,15 @@
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Instructions.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
GlobalValue *Array) {
+ LLVMContext* Context = MainFn->getContext();
const Type *ArgVTy =
- PointerType::getUnqual(PointerType::getUnqual(Type::Int8Ty));
- const PointerType *UIntPtr = PointerType::getUnqual(Type::Int32Ty);
+ Context->getPointerTypeUnqual(Context->getPointerTypeUnqual(Type::Int8Ty));
+ const PointerType *UIntPtr = Context->getPointerTypeUnqual(Type::Int32Ty);
Module &M = *MainFn->getParent();
Constant *InitFn = M.getOrInsertFunction(FnName, Type::Int32Ty, Type::Int32Ty,
ArgVTy, UIntPtr, Type::Int32Ty,
@@ -33,27 +35,27 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
// This could force argc and argv into programs that wouldn't otherwise have
// them, but instead we just pass null values in.
std::vector<Value*> Args(4);
- Args[0] = Constant::getNullValue(Type::Int32Ty);
- Args[1] = Constant::getNullValue(ArgVTy);
+ Args[0] = Context->getNullValue(Type::Int32Ty);
+ Args[1] = Context->getNullValue(ArgVTy);
// Skip over any allocas in the entry block.
BasicBlock *Entry = MainFn->begin();
BasicBlock::iterator InsertPos = Entry->begin();
while (isa<AllocaInst>(InsertPos)) ++InsertPos;
- std::vector<Constant*> GEPIndices(2, Constant::getNullValue(Type::Int32Ty));
+ std::vector<Constant*> GEPIndices(2, Context->getNullValue(Type::Int32Ty));
unsigned NumElements = 0;
if (Array) {
- Args[2] = ConstantExpr::getGetElementPtr(Array, &GEPIndices[0],
+ Args[2] = Context->getConstantExprGetElementPtr(Array, &GEPIndices[0],
GEPIndices.size());
NumElements =
cast<ArrayType>(Array->getType()->getElementType())->getNumElements();
} else {
// If this profiling instrumentation doesn't have a constant array, just
// pass null.
- Args[2] = ConstantPointerNull::get(UIntPtr);
+ Args[2] = Context->getConstantPointerNull(UIntPtr);
}
- Args[3] = ConstantInt::get(Type::Int32Ty, NumElements);
+ Args[3] = Context->getConstantInt(Type::Int32Ty, NumElements);
Instruction *InitCall = CallInst::Create(InitFn, Args.begin(), Args.end(),
"newargc", InsertPos);
@@ -99,6 +101,8 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
void llvm::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum,
GlobalValue *CounterArray) {
+ LLVMContext* Context = BB->getContext();
+
// Insert the increment after any alloca or PHI instructions...
BasicBlock::iterator InsertPos = BB->getFirstNonPHI();
while (isa<AllocaInst>(InsertPos))
@@ -106,15 +110,16 @@ void llvm::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum,
// Create the getelementptr constant expression
std::vector<Constant*> Indices(2);
- Indices[0] = Constant::getNullValue(Type::Int32Ty);
- Indices[1] = ConstantInt::get(Type::Int32Ty, CounterNum);
+ Indices[0] = Context->getNullValue(Type::Int32Ty);
+ Indices[1] = Context->getConstantInt(Type::Int32Ty, CounterNum);
Constant *ElementPtr =
- ConstantExpr::getGetElementPtr(CounterArray, &Indices[0], Indices.size());
+ Context->getConstantExprGetElementPtr(CounterArray, &Indices[0],
+ Indices.size());
// Load, increment and store the value back.
Value *OldVal = new LoadInst(ElementPtr, "OldFuncCounter", InsertPos);
Value *NewVal = BinaryOperator::Create(Instruction::Add, OldVal,
- ConstantInt::get(Type::Int32Ty, 1),
+ Context->getConstantInt(Type::Int32Ty, 1),
"NewFuncCounter", InsertPos);
new StoreInst(NewVal, ElementPtr, InsertPos);
}
diff --git a/lib/Transforms/Instrumentation/RSProfiling.cpp b/lib/Transforms/Instrumentation/RSProfiling.cpp
index b110f4eb36..5f95f29ea1 100644
--- a/lib/Transforms/Instrumentation/RSProfiling.cpp
+++ b/lib/Transforms/Instrumentation/RSProfiling.cpp
@@ -33,6 +33,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Pass.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Instructions.h"
#include "llvm/Constants.h"
@@ -195,7 +196,7 @@ static void getBackEdges(Function& F, T& BackEdges);
GlobalRandomCounter::GlobalRandomCounter(Module& M, const IntegerType* t,
uint64_t resetval) : T(t) {
- ConstantInt* Init = ConstantInt::get(T, resetval);
+ ConstantInt* Init = M.getContext().getConstantInt(T, resetval);
ResetValue = Init;
Counter = new GlobalVariable(T, false, GlobalValue::InternalLinkage,
Init, "RandomSteeringCounter", &M);
@@ -207,14 +208,16 @@ void GlobalRandomCounter::PrepFunction(Function* F) {}
void GlobalRandomCounter::ProcessChoicePoint(BasicBlock* bb) {
BranchInst* t = cast<BranchInst>(bb->getTerminator());
+ LLVMContext* Context = bb->getContext();
//decrement counter
LoadInst* l = new LoadInst(Counter, "counter", t);
- ICmpInst* s = new ICmpInst(ICmpInst::ICMP_EQ, l, ConstantInt::get(T, 0),
+ ICmpInst* s = new ICmpInst(ICmpInst::ICMP_EQ, l,
+ Context->getConstantInt(T, 0),
"countercc", t);
- Value* nv = BinaryOperator::CreateSub(l, ConstantInt::get(T, 1),
+ Value* nv = BinaryOperator::CreateSub(l, Context->getConstantInt(T, 1),
"counternew", t);
new StoreInst(nv, Counter, t);
t->setCondition(s);
@@ -232,7 +235,7 @@ void GlobalRandomCounter::ProcessChoicePoint(BasicBlock* bb) {
GlobalRandomCounterOpt::GlobalRandomCounterOpt(Module& M, const IntegerType* t,
uint64_t resetval)
: AI(0), T(t) {
- ConstantInt* Init = ConstantInt::get(T, resetval);
+ ConstantInt* Init = M.getContext().getConstantInt(T, resetval);
ResetValue = Init;
Counter = new GlobalVariable(T, false, GlobalValue::InternalLinkage,
Init, "RandomSteeringCounter", &M);
@@ -279,14 +282,16 @@ void GlobalRandomCounterOpt::PrepFunction(Function* F) {
void GlobalRandomCounterOpt::ProcessChoicePoint(BasicBlock* bb) {
BranchInst* t = cast<BranchInst>(bb->getTerminator());
+ LLVMContext* Context = bb->getContext();
//decrement counter
LoadInst* l = new LoadInst(AI, "counter", t);
- ICmpInst* s = new ICmpInst(ICmpInst::ICMP_EQ, l, ConstantInt::get(T, 0),
+ ICmpInst* s = new ICmpInst(ICmpInst::ICMP_EQ, l,
+ Context->getConstantInt(T, 0),
"countercc", t);
- Value* nv = BinaryOperator::CreateSub(l, ConstantInt::get(T, 1),
+ Value* nv = BinaryOperator::CreateSub(l, Context->getConstantInt(T, 1),
"counternew", t);
new StoreInst(nv, AI, t);
t->setCondition(s);
@@ -312,14 +317,15 @@ void CycleCounter::PrepFunction(Function* F) {}
void CycleCounter::ProcessChoicePoint(BasicBlock* bb) {
BranchInst* t = cast<BranchInst>(bb->getTerminator());
+ LLVMContext* Context = bb->getContext();
CallInst* c = CallInst::Create(F, "rdcc", t);
BinaryOperator* b =
- BinaryOperator::CreateAnd(c, ConstantInt::get(Type::Int64Ty, rm),
+ BinaryOperator::CreateAnd(c, Context->getConstantInt(Type::Int64Ty, rm),
"mrdcc", t);
ICmpInst *s = new ICmpInst(ICmpInst::ICMP_EQ, b,
- ConstantInt::get(Type::Int64Ty, 0),
+ Context->getConstantInt(Type::Int64Ty, 0),
"mrdccc", t);
t->setCondition(s);
@@ -345,16 +351,16 @@ void RSProfilers_std::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNu
// Create the getelementptr constant expression
std::vector<Constant*> Indices(2);
- Indices[0] = Constant::getNullValue(Type::Int32Ty);
- Indices[1] = ConstantInt::get(Type::Int32Ty, CounterNum);
- Constant *ElementPtr = ConstantExpr::getGetElementPtr(CounterArray,
+ Indices[0] = Context->getNullValue(Type::Int32Ty);
+ Indices[1] = Context->getConstantInt(Type::Int32Ty, CounterNum);
+ Constant *ElementPtr = Context->getConstantExprGetElementPtr(CounterArray,
&Indices[0], 2);
// Load, increment and store the value back.
Value *OldVal = new LoadInst(ElementPtr, "OldCounter", InsertPos);
profcode.insert(OldVal);
Value *NewVal = BinaryOperator::CreateAdd(OldVal,
- ConstantInt::get(Type::Int32Ty, 1),
+ Context->getConstantInt(Type::Int32Ty, 1),
"NewCounter", InsertPos);
profcode.insert(NewVal);
profcode.insert(new StoreInst(NewVal, ElementPtr, InsertPos));
@@ -475,7 +481,7 @@ void ProfilerRS::ProcessBackEdge(BasicBlock* src, BasicBlock* dst, Function& F)
//b:
BranchInst::Create(cast<BasicBlock>(Translate(dst)), bbC);
BranchInst::Create(dst, cast<BasicBlock>(Translate(dst)),
- ConstantInt::get(Type::Int1Ty, true), bbCp);
+ Context->getConstantInt(Type::Int1Ty, true), bbCp);
//c:
{
TerminatorInst* iB = src->getTerminator();
@@ -532,7 +538,7 @@ bool ProfilerRS::runOnFunction(Function& F) {
ReplaceInstWithInst(T, BranchInst::Create(T->getSuccessor(0),
cast<BasicBlock>(
Translate(T->getSuccessor(0))),
- ConstantInt::get(Type::Int1Ty,
+ Context->getConstantInt(Type::Int1Ty,
true)));
//do whatever is needed now that the function is duplicated