[llvm-commits] CVS: llvm/lib/Reoptimizer/Inst/lib/Phase1/Phase1.cpp PrimInfo.cpp PrimInfo.h
Joel Stanley
jstanley at cs.uiuc.edu
Tue Jun 24 10:41:05 PDT 2003
Changes in directory llvm/lib/Reoptimizer/Inst/lib/Phase1:
Phase1.cpp updated: 1.26 -> 1.27
PrimInfo.cpp updated: 1.15 -> 1.16
PrimInfo.h updated: 1.10 -> 1.11
---
Log message:
Merge from branch jrsdev.
---
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 llvm/lib/Reoptimizer/Inst/lib/Phase1/Phase1.cpp:1.27
--- llvm/lib/Reoptimizer/Inst/lib/Phase1/Phase1.cpp:1.26 Thu May 22 22:26:13 2003
+++ llvm/lib/Reoptimizer/Inst/lib/Phase1/Phase1.cpp Tue Jun 24 10:39:53 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, and do
+ // the same for point-site declarations.
+
+ 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
@@ -218,26 +229,10 @@
for(unsigned i = 0, e = rpairs.size(); i < e; ++i)
transformSites(rpairs[i]);
- // Build the interval PrimInfo instance -> GBT index map. This maps the address of a
- // particular interval PrimInfo instance to the index in the GBT that corresponds to
- // the record that represents the start-interval global-volatile and related
- // information.
-
- std::map<PrimInfo*, unsigned> gbtIdxMap;
- int idx = 0;
- for(vector<PrimInfo>::iterator i = m_primInfos.begin(), e = m_primInfos.end(); i != e; ++i){
- if(i->getType() == PrimInfo::REGION) {
- gbtIdxMap[&*i] = idx;
- idx += 2;
- }
- else
- idx++;
- }
-
// Build the global bookkeeping table (GBT) contents
vector<Constant*> gbtElems;
for(vector<PrimInfo>::iterator i = m_primInfos.begin(), e = m_primInfos.end(); i != e; ++i)
- i->buildStructInstances(gbtElems, gbtIdxMap, &m_targetData);
+ i->buildStructInstances(gbtElems);
// Make the GBT itself, and the corresponding global variable.
ArrayType* gbtType = ArrayType::get(PrimInfo::getStructType(), gbtElems.size());
@@ -295,19 +290,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 +333,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 +355,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 +385,6 @@
void Phase1::transformSite(CallInst* pointCall)
{
- GlobalVariable* metricVar = GetLHSGlobal(pointCall);
-
// Insert placeholder code
PlaceholderPair php;
generatePlaceholder(pointCall, php);
@@ -391,7 +395,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.16
--- 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 Tue Jun 24 10:39:53 2003
@@ -2,10 +2,8 @@
// programmer: Joel Stanley
// date: Tue Jan 28 14:07:05 CST 2003
// fileid: PrimInfo.cpp
-// purpose: Captures information about an instance of a performance primitive. The
-// information is intended to be carried between phases by reconstructing PrimInfo
-// contents that have been placed in global static data structures by Phase1's
-// invocation of PrimInfo::Document.
+// purpose: Captures information about an instance of a performance primitive "marker"
+// in the code.
#include "llvm/Module.h"
#include "llvm/Type.h"
@@ -15,7 +13,6 @@
#include "llvm/GlobalVariable.h"
#include "llvm/Constant.h"
#include "Support/VectorExtras.h"
-#include "llvm/Target/TargetData.h"
#include "PrimInfo.h"
#include "Intraphase.h"
@@ -31,16 +28,16 @@
StructType* PrimInfo::sm_structType = 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,126 +45,75 @@
}
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;
+
+ // {{{ 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;
//
// // Address of global variable corresponding to this primitive.
// unsigned short* loadVar;
//
- // // Index in GBT of struct of corresponding GBT_INTERVAL_START entry
- // // (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;
- //
- // 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, 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)
+ GlobalVariable* loadVar)
{
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
return ConstantStruct::get(st, init);
}
-void PrimInfo::buildStructInstances(std::vector<Constant*>& gbtElems,
- std::map<PrimInfo*, unsigned>& gbtIdxMap,
- const TargetData* targetData)
+void PrimInfo::buildStructInstances(std::vector<Constant*>& gbtElems)
{
StructType* st = getStructType();
switch(m_type) {
case REGION: {
-
- std::map<PrimInfo*, unsigned>::iterator i = gbtIdxMap.find(this);
- 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));
// 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));
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.11
--- 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 Tue Jun 24 10:39:54 2003
@@ -13,8 +13,6 @@
#include <map>
-class TargetData;
-
namespace pp
{
@@ -26,7 +24,6 @@
PrimInfo(Module* m):
m_globVol(0),
m_globVolEnd(0),
- m_metricVar(0),
m_module(m),
m_startFunc(0),
m_endFunc(0)
@@ -35,16 +32,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 +54,11 @@
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);
+ void buildStructInstances(std::vector<Constant*>& gbtElems);
- static void buildStructType(Module* module);
+ static void buildStructTypes(Module* module);
static StructType* getStructType() { return sm_structType; }
private:
@@ -74,9 +67,9 @@
// 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;
More information about the llvm-commits
mailing list