[llvm-commits] CVS: llvm/lib/Reoptimizer/Inst/lib/Phase1/Phase1.cpp PrimInfo.cpp PrimInfo.h

Joel Stanley jstanley at cs.uiuc.edu
Sat May 10 15:45:01 PDT 2003


Changes in directory llvm/lib/Reoptimizer/Inst/lib/Phase1:

Phase1.cpp updated: 1.24 -> 1.25
PrimInfo.cpp updated: 1.10 -> 1.11
PrimInfo.h updated: 1.8 -> 1.9

---
Log message:

- Removed old code segments that wrote directly into the documentation function,
and got rid of "documentation function" notion completly, as it is not needed.

- Removed dead Phase2 actions from PrimInfo class (the Phase 2 LLVM pass no
longer exists, as it has been completely subsumed by the binary editing phases
which are invoked at runtime).

- Removed code that relied on the older performance-instrumentation function
signatures (the signatures that required return-by-value instrumentation
functions rather than functions that return void)

- Removed ifdef'd-out block of code in Phase1::buildGuardedGVRead, which was
wrapping global volatile reads in conditionals. This may be needed later, but it
is assumed that the code is not needed.  Refer back to this version for the
deleted code to save time if it is needed later.

- PrimInfo::buildStructInstances is now writing the address of the
instrumentation functions into the appropriate field in the GBT.







---
Diffs of the changes:

Index: llvm/lib/Reoptimizer/Inst/lib/Phase1/Phase1.cpp
diff -u llvm/lib/Reoptimizer/Inst/lib/Phase1/Phase1.cpp:1.24 llvm/lib/Reoptimizer/Inst/lib/Phase1/Phase1.cpp:1.25
--- llvm/lib/Reoptimizer/Inst/lib/Phase1/Phase1.cpp:1.24	Sat May 10 13:44:33 2003
+++ llvm/lib/Reoptimizer/Inst/lib/Phase1/Phase1.cpp	Sat May 10 15:54:54 2003
@@ -73,7 +73,6 @@
     Function*        m_counterPrimFunc;    // Counter sigfun
     Function*        m_regionPairDeclFunc; // Region-pair metric spec sigfun
     Function*        m_metricSpecDeclFunc; // Point metric spec sigfun
-    Function*        m_docFunc;            // Documentation function
     GlobalVariable*  m_allocAddr;          // Global to store alloca result
     Module*          m_module;             // Current module
     vector<PrimInfo> m_primInfos;          // Deferred documentation structures
@@ -110,22 +109,6 @@
                                      Constant::getNullValue(Type::UByteTy),
                                      "allocAddr",
                                      m_module);
-    
-    ////////////////
-    // Build documentation function to keep data persistent between phases
-
-    params.clear();
-    m_docFunc  = m.getOrInsertFunction("docFunc", FunctionType::get(Type::VoidTy, params, false));
-    BasicBlock* docBlock = new BasicBlock("entry", m_docFunc);
-    docBlock->getInstList().push_back(new ReturnInst());
-    
-    // Place call to docFunc at entry to main so that it doesn't get optimized away.
-#if 0
-    Function* main = m.getMainFunction();
-    assert(main && "Require existence of main to place call to doc func");
-    BasicBlock::iterator entry = main->getEntryNode().begin();
-    new CallInst(m_docFunc, "", &*entry);
-#endif
 
     // Invoke PrimInfo's static initializer
     PrimInfo::buildStructType(&m);
@@ -233,16 +216,6 @@
     for(unsigned i = 0, e = rpairs.size(); i < e; ++i)
         transformSites(rpairs[i]);
 
-#if 0
-    // Dump all documentation from constructed PrimInfo instances into the documentation
-    // function; we do this here (as opposed to doing it as the objects are constructed)
-    // to avoid introducing uses of the region function ptrs (which complicates other code
-    // and isn't as efficient).
-
-    for(vector<PrimInfo>::iterator i = m_primInfos.begin(), e = m_primInfos.end(); i != e; ++i)
-        i->Document(m_docFunc);
-#endif
-
     // 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
@@ -341,18 +314,6 @@
         else
             assert(0 && "Use of start call's first opd in non-call inst");
 
-        // {{{ Old implementation
-#if 0
-        assert(startCall->use_size() == 1 && isa<StoreInst>(startCall->use_back()) && "Must see only one use, in a store");
-        AllocaInst* ai = dyn_cast<AllocaInst>(cast<StoreInst>(startCall->use_back())->getPointerOperand());
-        assert(ai && ai->use_size() == 2 && "Address of stack-local expected as store pointer opd, and has two uses");
-
-        // CallInst use of stack local one of ai's two uses; it's used once in the store as well
-        CallInst* endCall = isa<CallInst>(ai->use_back()) ?
-            cast<CallInst>(ai->use_back()) : dyn_cast<CallInst>(*ai->use_begin());
-#endif
-        // }}}
-        
         assert(startCall->getCalledFunction() == startFunc &&
                endCall->getCalledFunction() == endFunc &&
                "Failed to match start/end call insts with proper functions");
@@ -371,14 +332,6 @@
            "Call inst does not have expected format");
 
     return cast<GlobalVariable>(ci->getOperand(1));
-
-#if 0
-    
-    assert(ci->use_size() == 1 && isa<StoreInst>(ci->use_back()) && "Only use of call return val should be in store");
-    StoreInst* si = cast<StoreInst>(ci->use_back());
-    assert(isa<GlobalVariable>(si->getPointerOperand()) && "Pointer operand of store must be of type global variable");
-    return cast<GlobalVariable>(si->getPointerOperand());
-#endif
 }
     
 void Phase1::transformSite(CallInst* startCall, CallInst* endCall) 
@@ -462,38 +415,6 @@
     LoadInst* deref = new LoadInst(newGV, "deref", ci);
     CastInst* toTmpType = new CastInst(deref, newTmp->getType()->getElementType(), "castToTmpType", ci);
     new StoreInst(toTmpType, newTmp, ci);
-
-#if 0
-    // Build instructions to store new global volatile into the new temporary; place in
-    // new BasicBlock containing nothing else.  We call this the 'assign' block.
-
-    BasicBlock* gvAssignBlk = new BasicBlock("gvAssignBlk", ci->getParent()->getParent());
-    LoadInst* deref = new LoadInst(newGV, "deref");
-    gvAssignBlk->getInstList().push_back(deref);
-    gvAssignBlk->getInstList().push_back(new StoreInst(deref, newTmp));
-    
-    // Build condition wrapper for the load of the global volatile; this is done by
-    // splitting ci's BasicBlock in two ('before', 'after'), making sure that the before
-    // block conditionally branches to the assign block or the after block, and that the
-    // assign block unconditionally branches to the after block.
-
-    BasicBlock* beforeBB = ci->getParent();
-    BasicBlock* afterBB = beforeBB->splitBasicBlock(ci->getNext());
-    afterBB->setName("ppSplit");
-
-    // The 'assign' block unconditionally branches to the after block.
-    gvAssignBlk->getInstList().push_back(new BranchInst(afterBB));
-
-    // The 'before' block conditionally branches to the assign block and the after block;
-    // make conditional here as well [if (newTmp > 0) { ... }].
-
-    BasicBlock::iterator ti(beforeBB->getTerminator());
-    LoadInst* li     = new LoadInst(newTmp, "tmpDeref", ti);
-    SetCondInst* sci = new SetCondInst(BinaryOperator::SetGT, li,
-                                       Constant::getNullValue(li->getType()), "cond", li->getNext());
-
-    ReplaceInstWithInst(beforeBB->getInstList(), ti, new BranchInst(gvAssignBlk, afterBB, sci));
-#endif
 }
 
 bool Phase1::run(Module& m) 


Index: llvm/lib/Reoptimizer/Inst/lib/Phase1/PrimInfo.cpp
diff -u llvm/lib/Reoptimizer/Inst/lib/Phase1/PrimInfo.cpp:1.10 llvm/lib/Reoptimizer/Inst/lib/Phase1/PrimInfo.cpp:1.11
--- llvm/lib/Reoptimizer/Inst/lib/Phase1/PrimInfo.cpp:1.10	Fri May  9 23:02:35 2003
+++ llvm/lib/Reoptimizer/Inst/lib/Phase1/PrimInfo.cpp	Sat May 10 15:54:54 2003
@@ -27,13 +27,6 @@
 //////////////// PrimInfo implementation ////////////////
 
 StructType* PrimInfo::sm_structType = 0;
-CastInst*   PrimInfo::sm_dummyCast = 0;
-
-PrimInfo::PrimInfo(Module& m, CallInst* ci):
-    m_module(&m)
-{
-    buildFromCall(ci);
-}
 
 PrimInfo::PrimInfo(PrimType type,
                    GlobalVariable* startGlob,
@@ -95,7 +88,6 @@
 
     assert(!init && "Expect only one invocation of this function");
     init = true;
-    
         
     std::vector<const Type*> fields;
 
@@ -103,7 +95,7 @@
     fields.push_back(PointerType::get(Type::UShortTy)); // unsigned short* loadVar;
     fields.push_back(Type::UIntTy);                     // unsigned gbtStartIdx;
     fields.push_back(Type::UIntTy);                     // unsigned paramSize;
-    //fields.push_back(PointerType::get(Type::VoidTy));   // void* instFunc;
+    fields.push_back(PointerType::get(Type::VoidTy));   // void* instFunc;
 
     sm_structType = StructType::get(fields);
     module->addTypeName("PrimInfo", sm_structType);
@@ -121,7 +113,8 @@
     initFlds.push_back(ConstantPointerRef::get(loadVar));
     initFlds.push_back(ConstantUInt::get(Type::UIntTy, startLinkIdx));
     initFlds.push_back(ConstantUInt::get(Type::UIntTy, paramSize));
-    //initFlds.push_back(ConstantPointerRef::get(instFunc));
+    initFlds.push_back(ConstantExpr::getCast(ConstantPointerRef::get(instFunc),
+                                             PointerType::get(Type::VoidTy)));
     return ConstantStruct::get(st, initFlds);
 }
 
@@ -157,125 +150,6 @@
         default:
             assert(0 && "(BuildStructInstances) Unsupported PrimInfo type");
     }
-}
-
-void PrimInfo::document(Function* docFunc) 
-{
-    GlobalVariable* gstruct;
-
-    // Build data structure to track configuration about this particular primitive
-    std::vector<Constant*> initializerFields;
-
-    switch(m_type) {
-        case COUNTER:
-            // counter primitives don't use anything but the type field
-            initializerFields.push_back(ConstantUInt::get(Type::UIntTy, COUNTER));
-            initializerFields.push_back(Constant::getNullValue(Type::UIntTy));
-            break;
-        case POINT:
-            initializerFields.push_back(ConstantUInt::get(Type::UIntTy, POINT));
-            initializerFields.push_back(Constant::getNullValue(Type::UIntTy));
-            break;
-        case REGION:
-            initializerFields.push_back(ConstantUInt::get(Type::UIntTy, REGION));
-            initializerFields.push_back(Constant::getNullValue(Type::UIntTy));
-            break;
-        default:
-            assert(0 && "Unknown metric type");
-            break;
-    }
-    
-    ConstantStruct* init = ConstantStruct::get(sm_structType, initializerFields);
-    gstruct = new GlobalVariable(sm_structType, true,
-                                 GlobalVariable::ExternalLinkage, init,
-                                 "ctrPrimCfgData", m_module);
-
-    // Construct the call to printf (using dummy string), ensuring that the
-    // (non-string) parameters are layed out as follows:
-    //
-    // When we're dealing with a point computation site:
-    //
-    // 1st parameter: global static data structure holding configuration information
-    // 2nd parameter: metric variable itself
-    // 3rd parameter: global volatile used as placeholder
-    // 4th parameter: called function for point (not present for COUNTER type)
-    //
-    // When we're dealing with a region computation site
-    // 1st parameter: global static data structure holding configuration information
-    // 2nd parameter: metric variable itself
-    // 3rd parameter: global volatile used as placeholder for start of region
-    // 4th parameter: global volatile used as placeholder for end of region
-    // 5th parameter: called function for start of region
-    // 6th parameter: called function for end of region
-
-    // Build the dummy string and cast to sbyte*; insert cast inst in doc func
-
-    if(!sm_dummyCast) {
-        ConstantArray* dummyStr = ConstantArray::get("floogle!");
-
-        GlobalVariable* ds = new GlobalVariable(dummyStr->getType(), true,
-                                                GlobalVariable::ExternalLinkage,
-                                                dummyStr, "dummyStr", m_module);
-
-        sm_dummyCast = new CastInst(ds, PointerType::get(Type::SByteTy),
-                                   "sbyte_cast", docFunc->getEntryNode().getTerminator());
-    }
-
-    // Build the printf call & insert it at the end of the doc function
-    std::vector<Value*> callParams;
-    callParams.push_back(sm_dummyCast);
-    callParams.push_back(gstruct);
-    callParams.push_back(m_metricVar);
-    callParams.push_back(m_globVol);
-
-    if(m_type == REGION) {
-        assert(m_startFunc && m_endFunc && "Must have function ptrs for region");
-        callParams.push_back(m_globVolEnd);
-        callParams.push_back(m_startFunc);
-        callParams.push_back(m_endFunc);
-    }
-    else if(m_type == POINT) {
-        callParams.push_back(m_startFunc);
-    }
-
-    Function* printfFunc = m_module->getNamedFunction("printf");
-    assert(printfFunc && "Couldn't find printf function in module");
-    
-    new CallInst(printfFunc, callParams,
-                 "printfRet", docFunc->getEntryNode().getTerminator());
-}
-
-void PrimInfo::buildFromCall(CallInst* ci)
-{
-    // fp, dummy string are first two args
-    assert(ci->getNumOperands() > 2 && "Require global struct argument");
-    GlobalVariable* gstruct = dyn_cast<GlobalVariable>(ci->getOperand(2));
-    assert(gstruct && "Expect to obtain global struct for processing");
-
-    // extract info from global, then fill in appropriate class fields
-    const std::vector<Use>& values = dyn_cast<ConstantStruct>(gstruct->getInitializer())->getValues();
-    m_type = (PrimType) cast<ConstantUInt>(values[0].get())->getValue();
-
-    assert(m_type == COUNTER && ci->getNumOperands() == 5 ||
-           m_type == POINT   && ci->getNumOperands() == 6 ||
-           m_type == REGION && ci->getNumOperands() == 8 &&
-           "Expect proper number of significant arguments in printf call");
-
-    m_metricVar = dyn_cast<GlobalVariable>(ci->getOperand(3));
-    m_globVol   = dyn_cast<GlobalVariable>(ci->getOperand(4));
-    assert(m_metricVar && m_globVol && "Require proper parameter types in printf");
-
-    if(m_type == REGION) {
-        m_globVolEnd = dyn_cast<GlobalVariable>(ci->getOperand(5));
-        m_startFunc  = dyn_cast<Function>(ci->getOperand(6));
-        m_endFunc    = dyn_cast<Function>(ci->getOperand(7));
-        assert(m_globVolEnd && m_startFunc && m_endFunc && "Require proper parameter types in printf");
-    }
-    else if(m_type == POINT) {
-        m_startFunc = dyn_cast<Function>(ci->getOperand(5));
-    }
-
-    // TODO: Write stuff for specFld here when it becomes relevant
 }
 
 }; // end namespace pp


Index: llvm/lib/Reoptimizer/Inst/lib/Phase1/PrimInfo.h
diff -u llvm/lib/Reoptimizer/Inst/lib/Phase1/PrimInfo.h:1.8 llvm/lib/Reoptimizer/Inst/lib/Phase1/PrimInfo.h:1.9
--- llvm/lib/Reoptimizer/Inst/lib/Phase1/PrimInfo.h:1.8	Fri May  9 23:02:35 2003
+++ llvm/lib/Reoptimizer/Inst/lib/Phase1/PrimInfo.h	Sat May 10 15:54:54 2003
@@ -56,8 +56,6 @@
              Function* startFunc,
              Function* endFunc);
     
-    PrimInfo(Module& m, CallInst* ci); // Phase 2 (re)construction
-
     GlobalVariable*       getGlobVol()          { return m_globVol;    }
     const GlobalVariable* getGlobVol() const    { return m_globVol;    }
     GlobalVariable*       getGlobVolEnd()       { return m_globVolEnd; }
@@ -74,11 +72,8 @@
                               std::map<PrimInfo*, unsigned>& gbtIdxMap,
                               const TargetData* targetData);
 
-    void document(Function* docFunc);
-    void buildFromCall(CallInst* ci);
-    
-    static void        buildStructType(Module* module);
-    static StructType* getStructType() { return sm_structType; }
+    static void           buildStructType(Module* module);
+    static StructType*    getStructType() { return sm_structType; }
     
   private:
     
@@ -94,7 +89,6 @@
     Function*          m_endFunc;
     
     static StructType* sm_structType;
-    static CastInst*   sm_dummyCast;
 };
  
 }; // end namespace pp





More information about the llvm-commits mailing list