aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnand Shukla <ashukla@cs.uiuc.edu>2003-06-05 06:02:46 +0000
committerAnand Shukla <ashukla@cs.uiuc.edu>2003-06-05 06:02:46 +0000
commitcd0cc613293b2e2d0964dca95a4c0f63708e0f64 (patch)
treeb997899caa6fb07c66eec1fe9f6f9e5c42839c58
parent7990199625f097c04e2dc4d85a8fb3f74cb01d42 (diff)
downloadexternal_llvm-cd0cc613293b2e2d0964dca95a4c0f63708e0f64.zip
external_llvm-cd0cc613293b2e2d0964dca95a4c0f63708e0f64.tar.gz
external_llvm-cd0cc613293b2e2d0964dca95a4c0f63708e0f64.tar.bz2
Fixed a bug so initialization code is always inserted in main
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6622 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp3
-rw-r--r--lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp59
2 files changed, 44 insertions, 18 deletions
diff --git a/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp b/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp
index 61c60ec..16b07f7 100644
--- a/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp
+++ b/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp
@@ -293,7 +293,7 @@ void insertInTopBB(BasicBlock *front,
//iniArgs.push_back(ConstantSInt::get(Type::IntTy, k));
//new CallInst(inCountMth, iniArgs, "", here);
-
+/*
if(front->getParent()->getName() == "main"){
//intialize threshold
vector<const Type*> initialize_args;
@@ -309,6 +309,7 @@ void insertInTopBB(BasicBlock *front,
new CallInst(initialMeth, trargs, "", here);
}
+*/
}
diff --git a/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp b/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp
index 79b94e8..138f582 100644
--- a/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp
+++ b/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp
@@ -29,10 +29,12 @@
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/iMemory.h"
+#include "llvm/iOperators.h"
+#include "llvm/iOther.h"
#include "llvm/Module.h"
#include "Graph.h"
#include <fstream>
-
+#include <stdio.h>
using std::vector;
struct ProfilePaths : public FunctionPass {
@@ -61,7 +63,7 @@ static Node *findBB(std::vector<Node *> &st, BasicBlock *BB){
bool ProfilePaths::runOnFunction(Function &F){
static int mn = -1;
-
+ static int CountCounter = 1;
if(F.isExternal()) {
return false;
}
@@ -157,6 +159,38 @@ bool ProfilePaths::runOnFunction(Function &F){
//if(numPaths<=1) return false;
+ static GlobalVariable *threshold = NULL;
+ static bool insertedThreshold = false;
+
+ if(!insertedThreshold){
+ threshold = new GlobalVariable(Type::IntTy, false,
+ GlobalValue::ExternalLinkage, 0,
+ "reopt_threshold");
+
+ F.getParent()->getGlobalList().push_back(threshold);
+ insertedThreshold = true;
+ }
+
+ assert(threshold && "GlobalVariable threshold not defined!");
+
+
+ if(fr->getParent()->getName() == "main"){
+ //intialize threshold
+ vector<const Type*> initialize_args;
+ initialize_args.push_back(PointerType::get(Type::IntTy));
+
+ const FunctionType *Fty = FunctionType::get(Type::VoidTy, initialize_args,
+ false);
+ Function *initialMeth = fr->getParent()->getParent()->getOrInsertFunction("reoptimizerInitialize", Fty);
+ assert(initialMeth && "Initialize method could not be inserted!");
+
+ vector<Value *> trargs;
+ trargs.push_back(threshold);
+
+ new CallInst(initialMeth, trargs, "", fr->begin());
+ }
+
+
if(numPaths<=1 || numPaths >5000) return false;
#ifdef DEBUG_PATH_PROFILES
@@ -185,24 +219,15 @@ bool ProfilePaths::runOnFunction(Function &F){
const ArrayType *ATy = ArrayType::get(Type::IntTy, numPaths);
Constant *initializer = ConstantArray::get(ATy, arrayInitialize);
+ char tempChar[20];
+ sprintf(tempChar, "Count%d", CountCounter);
+ CountCounter++;
+ std::string countStr = tempChar;
GlobalVariable *countVar = new GlobalVariable(ATy, false,
GlobalValue::InternalLinkage,
- initializer, "Count",
+ initializer, countStr,
F.getParent());
- static GlobalVariable *threshold = NULL;
- static bool insertedThreshold = false;
-
- if(!insertedThreshold){
- threshold = new GlobalVariable(Type::IntTy, false,
- GlobalValue::ExternalLinkage, 0,
- "reopt_threshold");
-
- F.getParent()->getGlobalList().push_back(threshold);
- insertedThreshold = true;
- }
-
- assert(threshold && "GlobalVariable threshold not defined!");
-
+
// insert initialization code in first (entry) BB
// this includes initializing r and count
insertInTopBB(&F.getEntryNode(),numPaths, rVar, threshold);