[llvm-commits] CVS: llvm/lib/Reoptimizer/Inst/lib/Phase1/Phase1.cpp PrimInfo.cpp PrimInfo.h
Joel Stanley
jstanley at cs.uiuc.edu
Fri May 30 10:26:06 PDT 2003
Changes in directory llvm/lib/Reoptimizer/Inst/lib/Phase1:
Phase1.cpp updated: 1.26.2.2 -> 1.26.2.3
PrimInfo.cpp updated: 1.15 -> 1.15.2.1
PrimInfo.h updated: 1.10 -> 1.10.2.1
---
Log message:
Implemented new dynamic-registration mechanism to split apart the notion of
instrumentation intervals/points and the metrics that are associated with them.
This allows new metrics to be associated with particular intervals at runtime
instead of at compile-time, which means that the runtime system is free to
register new metrics on the fly.
---
Diffs of the changes:
Index: llvm/lib/Reoptimizer/Inst/lib/Phase1/Phase1.cpp
diff -u llvm/lib/Reoptimizer/Inst/lib/Phase1/Phase1.cpp:1.26.2.2 llvm/lib/Reoptimizer/Inst/lib/Phase1/Phase1.cpp:1.26.2.3
--- llvm/lib/Reoptimizer/Inst/lib/Phase1/Phase1.cpp:1.26.2.2 Wed May 28 09:25:21 2003
+++ llvm/lib/Reoptimizer/Inst/lib/Phase1/Phase1.cpp Fri May 30 10:25:34 2003
@@ -12,7 +12,7 @@
#include <set>
#include <algorithm>
#include <map>
-#include <typeinfo>
+#include <string>
#include "llvm/Pass.h"
#include "llvm/Module.h"
@@ -78,6 +78,12 @@
Module* m_module; // Current module
vector<PrimInfo> m_primInfos; // Deferred documentation structures
TargetData m_targetData; // For obtaining target-specific info
+
+ static const unsigned NUM_START_OPDS = 3;
+ static const unsigned NUM_END_OPDS = 3;
+ static const unsigned NUM_STOPD_USES = 2;
+ static const unsigned ENDCALL_ID_OPIDX = 1;
+ static const unsigned POINTCALL_ID_OPIDX = 1;
};
//////////////// Phase1 implementation ////////////////
@@ -112,7 +118,7 @@
m_module);
// Invoke PrimInfo's static initializer
- PrimInfo::buildStructType(&m);
+ PrimInfo::buildStructTypes(&m);
//
////////////////
@@ -181,12 +187,17 @@
// Populate with builtins
- // TODO: Replace the hard-coded mechanism for the point metrics with a
- // sigfun registration mechanism like that which exists for region metrics
- // (pp_regionPair()).
+ // The new approach: pp_declareInterval{Start,End} are the only sigfuns used
+ // to declare an interval, instead of the interval being implicit by the
+ // given locations of the calls to (registered) region sigfuns. For now, we
+ // will still use the old code for processing the contents of 'rpairs', but
+ // the only element of rpairs will be the pair of interval-declaration
+ // sigfuns. TODO: Clean up this approach.
+
+ Function* intervalStartDeclFunc = m_module->getNamedFunction("pp_declareIntervalStart");
+ Function* intervalEndDeclFunc = m_module->getNamedFunction("pp_declareIntervalEnd");
- // Find user-declared region-pairs and add them to the list
- findRegionPairs(rpairs);
+ rpairs.push_back(std::make_pair(intervalStartDeclFunc, intervalEndDeclFunc));
////////////////
// Build list of point metric spec sigfuns, finding ppMetricSpec will yield
@@ -295,19 +306,19 @@
CallInst* startCall = dyn_cast<CallInst>(*u);
assert(startCall && "Use of a registered pp sigfun not in a call");
-
+
// Find call to endpoint: The first operand of the start function is used in only
// two places: the call to the start function, and the call to the end
// function. Find the call to the end function.
- assert(startCall->getNumOperands() == 2 &&
- "Start-region call insts should only have 2 operands");
+ assert(startCall->getNumOperands() == NUM_START_OPDS &&
+ "Start-region call inst has unexpected number of operands");
Value* stOpd = startCall->getOperand(1);
assert(isa<AllocaInst>(stOpd) && "Unexpected first operand of start call");
- assert(stOpd->use_size() == 2 &&
- "Expect only two uses of start-region operand");
+ assert(stOpd->use_size() == NUM_STOPD_USES &&
+ "Unexpected number of uses of of start-region (\"connector\") operand");
CallInst* endCall;
if((endCall = dyn_cast<CallInst>(stOpd->use_back()))) {
@@ -338,11 +349,21 @@
return cast<GlobalVariable>(ci->getOperand(1));
}
-
+
+static unsigned extractUnsignedValue(CallInst* ci, unsigned nth)
+{
+ // extract the literal value of the nth actual of ci, which must be of type
+ // unsigned.
+
+ if(ConstantUInt* ui = dyn_cast<ConstantUInt>(ci->getOperand(nth)))
+ return ui->getValue();
+
+ assert(0 && "Failed to find unsigned value as call actual");
+ return 0; // squash warning
+}
+
void Phase1::transformSite(CallInst* startCall, CallInst* endCall)
{
- GlobalVariable* metricVar = GetLHSGlobal(endCall);
-
// Insert placeholder code
PlaceholderPair startPair, endPair;
generatePlaceholder(startCall, startPair);
@@ -350,8 +371,9 @@
// Create info about this site for later documentation
- m_primInfos.push_back(PrimInfo(PrimInfo::REGION, startPair.first, endPair.first,
- metricVar, m_module,
+ unsigned siteID = extractUnsignedValue(endCall, ENDCALL_ID_OPIDX);
+ m_primInfos.push_back(PrimInfo(PrimInfo::REGION, siteID,
+ startPair.first, endPair.first, m_module,
startCall->getCalledFunction(),
endCall->getCalledFunction()));
@@ -379,8 +401,6 @@
void Phase1::transformSite(CallInst* pointCall)
{
- GlobalVariable* metricVar = GetLHSGlobal(pointCall);
-
// Insert placeholder code
PlaceholderPair php;
generatePlaceholder(pointCall, php);
@@ -391,7 +411,8 @@
PrimInfo::PrimType type = pointCall->getCalledFunction() == m_counterPrimFunc ?
PrimInfo::COUNTER : PrimInfo::POINT;
- m_primInfos.push_back(PrimInfo(type, php.first, metricVar, m_module,
+ unsigned siteID = extractUnsignedValue(pointCall, POINTCALL_ID_OPIDX);
+ m_primInfos.push_back(PrimInfo(type, siteID, php.first, m_module,
pointCall->getCalledFunction()));
// Remove the call
Index: llvm/lib/Reoptimizer/Inst/lib/Phase1/PrimInfo.cpp
diff -u llvm/lib/Reoptimizer/Inst/lib/Phase1/PrimInfo.cpp:1.15 llvm/lib/Reoptimizer/Inst/lib/Phase1/PrimInfo.cpp:1.15.2.1
--- llvm/lib/Reoptimizer/Inst/lib/Phase1/PrimInfo.cpp:1.15 Tue May 13 14:43:03 2003
+++ llvm/lib/Reoptimizer/Inst/lib/Phase1/PrimInfo.cpp Fri May 30 10:25:34 2003
@@ -29,18 +29,19 @@
//////////////// PrimInfo implementation ////////////////
StructType* PrimInfo::sm_structType = 0;
+StructType* PrimInfo::sm_infoNodeType = 0;
PrimInfo::PrimInfo(PrimType type,
+ unsigned siteID,
GlobalVariable* startGlob,
GlobalVariable* endGlob,
- GlobalVariable* metricVar,
Module* module,
Function* startFunc,
Function* endFunc):
m_type(type),
+ m_siteID(siteID),
m_globVol(startGlob),
m_globVolEnd(endGlob),
- m_metricVar(metricVar),
m_module(module),
m_startFunc(startFunc),
m_endFunc(endFunc)
@@ -48,24 +49,59 @@
}
PrimInfo::PrimInfo(PrimType type,
+ unsigned siteID,
GlobalVariable* globVol,
- GlobalVariable* metricVar,
Module* module,
Function* calledFunc):
m_type(type),
+ m_siteID(siteID),
m_globVol(globVol),
- m_metricVar(metricVar),
m_module(module),
m_startFunc(calledFunc)
{
assert(type != POINT || calledFunc && "point type --> non-null called function");
}
-void PrimInfo::buildStructType(Module* module)
+void PrimInfo::buildStructTypes(Module* module)
{
- // The structure deposited into the LLVM bytecode essentially looks like:
- // struct PrimInfo
+ static bool init = false;
+
+ assert(!init && "Expect only one invocation of this function");
+ init = true;
+
+ // The linked list of containing information about each instrumentation function
+ // registered for a particular site.
+
+ // {{{ struct InstInfoNode
+ // {
+ // // Size, in bytes, of the parameter to the instrumentation function.
+ // unsigned paramSize;
+ //
+ // // Pointer to memory for instFunc's return value This is initialized to null for
+ // // start-interval sites, and filled in at runtime by a pointer to heap-allocated
+ // // memory of the appropriate size. For all other site types, the address is
+ // // specified explicitly when a particular instrumentation is bound to a particular
+ // // interval.
+ // void* retVal;
+ //
+ // // Pointer to the instrumentation function itself.
+ // void* instFunc;
+ //
+ // // The next node in the list
+ // InstInfoNode* next;
+ // };
+ // }}}
+
+ // TODO: figger out how to make a recursive struct type
+ PointerType* vpt = PointerType::get(Type::VoidTy);
+ sm_infoNodeType = StructType::get(make_vector<const Type*>(Type::UIntTy, vpt, vpt, 0));
+ module->addTypeName("InstInfoNode", sm_infoNodeType);
+
+ // {{{ struct PrimInfo
// {
+ // // Site ID for this site (one value identifies one entire interval as well)
+ // unsigned siteID;
+ //
// // Type of GBT entry type (i.e., member of enum GBTEntryType)
// unsigned gbtType;
//
@@ -76,72 +112,37 @@
// // (NB: Only valid if gbtType == GBT_INTERVAL_END)
// unsigned gbtStartIdx;
//
- // // Size, in bytes, of the parameter to the instrumentation function that must be
- // // invoked at the instrumentation that corresponds to this structure instance.
- // unsigned paramSize;
- //
- // // Pointer to memory for instFunc's return value
- // // This is initalized to null for start-interval sites, and filled in at runtime
- // // by a pointer to heap-allocated memory of the appropriate size. For all other
- // // site types, this is initialized to the metric variable address.
- // void* retVal;
- //
- // // Pointer to instrumentation function
- // void* instFunc;
+ // // Linked list of info about what inst functions are registered for this site
+ // // Always initialized to null, and is filled in at runtime.
+ // InstInfoNode* instInfoList;
//
// Other stuff will need to go here...(TODO)
// };
-
- static bool init = false;
-
- assert(!init && "Expect only one invocation of this function");
- init = true;
+ // }}}
PointerType* uspt = PointerType::get(Type::UShortTy);
- PointerType* vpt = PointerType::get(Type::VoidTy);
+
sm_structType =
StructType::get(make_vector<const Type*>(
- Type::UIntTy, uspt, Type::UIntTy, Type::UIntTy, vpt, vpt, 0));
- module->addTypeName("PrimInfo", sm_structType);
-}
-
+ Type::UIntTy, Type::UIntTy, uspt, Type::UIntTy,
+ PointerType::get(sm_infoNodeType), 0));
-// For start sites
-static ConstantStruct* makeConstStruct(StructType* st,
- unsigned gbtType,
- GlobalVariable* loadVar,
- unsigned paramSize,
- Function* instFunc)
-{
- std::vector<Constant*> init;
- init.push_back(ConstantUInt::get(Type::UIntTy, gbtType));
- init.push_back(ConstantPointerRef::get(loadVar));
- init.push_back(ConstantUInt::get(Type::UIntTy, 0));
- init.push_back(ConstantUInt::get(Type::UIntTy, paramSize));
- init.push_back(Constant::getNullValue(PointerType::get(Type::VoidTy)));
- init.push_back(ConstantExpr::getCast(ConstantPointerRef::get(instFunc),
- PointerType::get(Type::VoidTy)));
- return ConstantStruct::get(st, init);
+ module->addTypeName("PrimInfo", sm_structType);
}
-// For non-start sites
static ConstantStruct* makeConstStruct(StructType* st,
+ unsigned siteID,
unsigned gbtType,
GlobalVariable* loadVar,
- unsigned startLinkIdx,
- unsigned paramSize,
- GlobalVariable* metricVar,
- Function* instFunc)
+ StructType* infoNodeType,
+ unsigned startLinkIdx = 0)
{
std::vector<Constant*> init;
- init.push_back(ConstantUInt::get(Type::UIntTy, gbtType));
- init.push_back(ConstantPointerRef::get(loadVar));
- init.push_back(ConstantUInt::get(Type::UIntTy, startLinkIdx));
- init.push_back(ConstantUInt::get(Type::UIntTy, paramSize));
- init.push_back(ConstantExpr::getCast(ConstantPointerRef::get(metricVar),
- PointerType::get(Type::VoidTy)));
- init.push_back(ConstantExpr::getCast(ConstantPointerRef::get(instFunc),
- PointerType::get(Type::VoidTy)));
+ init.push_back(ConstantUInt::get(Type::UIntTy, siteID)); // siteID
+ init.push_back(ConstantUInt::get(Type::UIntTy, gbtType)); // gbtType
+ init.push_back(ConstantPointerRef::get(loadVar)); // loadVar
+ init.push_back(ConstantUInt::get(Type::UIntTy, startLinkIdx)); // gbtStartIdx
+ init.push_back(Constant::getNullValue(PointerType::get(infoNodeType))); // instInfoList
return ConstantStruct::get(st, init);
}
@@ -158,16 +159,15 @@
assert(i != gbtIdxMap.end() && "No entry in map for this PrimInfo instance");
// Create the struct for the start of the region
- assert(m_startFunc->asize() == 1 && "Unexpected # args for start func");
- unsigned psize = targetData->getTypeSize(m_startFunc->afront().getType());
- gbtElems.push_back(makeConstStruct(st, GBT_INTERVAL_START, m_globVol,
- psize, m_startFunc));
+ assert(m_startFunc->asize() == 2 && "Unexpected # args for start func");
+
+ gbtElems.push_back(makeConstStruct(st, m_siteID, GBT_INTERVAL_START,
+ m_globVol, sm_infoNodeType));
// Create the struct for the end of the region
assert(m_endFunc->asize() == 2 && "Unexpected # args for end func");
- psize = targetData->getTypeSize(m_endFunc->afront().getType());
- gbtElems.push_back(makeConstStruct(st, GBT_INTERVAL_END, m_globVolEnd,
- i->second, psize, m_metricVar, m_endFunc));
+ gbtElems.push_back(makeConstStruct(st, m_siteID, GBT_INTERVAL_END,
+ m_globVolEnd, sm_infoNodeType, i->second));
break;
}
Index: llvm/lib/Reoptimizer/Inst/lib/Phase1/PrimInfo.h
diff -u llvm/lib/Reoptimizer/Inst/lib/Phase1/PrimInfo.h:1.10 llvm/lib/Reoptimizer/Inst/lib/Phase1/PrimInfo.h:1.10.2.1
--- llvm/lib/Reoptimizer/Inst/lib/Phase1/PrimInfo.h:1.10 Mon May 12 21:00:24 2003
+++ llvm/lib/Reoptimizer/Inst/lib/Phase1/PrimInfo.h Fri May 30 10:25:35 2003
@@ -26,7 +26,6 @@
PrimInfo(Module* m):
m_globVol(0),
m_globVolEnd(0),
- m_metricVar(0),
m_module(m),
m_startFunc(0),
m_endFunc(0)
@@ -35,16 +34,16 @@
// Phase 1 construction -- point/counter computation site
PrimInfo(PrimType type,
+ unsigned siteID,
GlobalVariable* globVol,
- GlobalVariable* metricVar,
Module* m,
Function* calledFunc = 0);
// Phase 1 construction -- region computation site
PrimInfo(PrimType type,
+ unsigned siteID,
GlobalVariable* startGlob,
GlobalVariable* endGlob,
- GlobalVariable* metricVar,
Module* m,
Function* startFunc,
Function* endFunc);
@@ -57,15 +56,13 @@
const Function* getStartFunc() const { return m_startFunc; }
Function* getEndFunc() { return m_endFunc; }
const Function* getEndFunc() const { return m_endFunc; }
- GlobalVariable* getMetricVar() { return m_metricVar; }
- const GlobalVariable* getMetricVar() const { return m_metricVar; }
PrimType getType() const { return m_type; }
void buildStructInstances(std::vector<Constant*>& gbtElems,
std::map<PrimInfo*, unsigned>& gbtIdxMap,
const TargetData* targetData);
- static void buildStructType(Module* module);
+ static void buildStructTypes(Module* module);
static StructType* getStructType() { return sm_structType; }
private:
@@ -74,14 +71,15 @@
// supplied configuration parameters.
PrimType m_type;
+ unsigned m_siteID;
GlobalVariable* m_globVol;
GlobalVariable* m_globVolEnd;
- GlobalVariable* m_metricVar;
Module* m_module;
Function* m_startFunc;
Function* m_endFunc;
static StructType* sm_structType;
+ static StructType* sm_infoNodeType;
};
}; // end namespace pp
More information about the llvm-commits
mailing list