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

Joel Stanley jstanley at cs.uiuc.edu
Thu May 22 22:27:06 PDT 2003


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

Phase1.cpp updated: 1.25 -> 1.26

---
Log message:

Bug fixes; PAPI "support" added to RTL.



---
Diffs of the changes:

Index: llvm/lib/Reoptimizer/Inst/lib/Phase1/Phase1.cpp
diff -u llvm/lib/Reoptimizer/Inst/lib/Phase1/Phase1.cpp:1.25 llvm/lib/Reoptimizer/Inst/lib/Phase1/Phase1.cpp:1.26
--- llvm/lib/Reoptimizer/Inst/lib/Phase1/Phase1.cpp:1.25	Sat May 10 15:54:54 2003
+++ llvm/lib/Reoptimizer/Inst/lib/Phase1/Phase1.cpp	Thu May 22 22:26:13 2003
@@ -12,6 +12,7 @@
 #include <set>
 #include <algorithm>
 #include <map>
+#include <typeinfo>
 
 #include "llvm/Pass.h"
 #include "llvm/Module.h"
@@ -118,24 +119,37 @@
 
 }
 
+static Function* extractFunctionArg(Value* rpairParam) 
+{
+    if(ConstantExpr* ce = dyn_cast<ConstantExpr>(rpairParam)) {
+        assert(ce->getNumOperands() == 1 &&
+               "ConstantExpr encountered with unexpected #opds");
+        if(ConstantPointerRef* cpr =
+           dyn_cast<ConstantPointerRef>(ce->getOperand(0))) {
+            if(Function* func = dyn_cast<Function>(cpr->getValue())) {
+                return func;
+            }
+        }
+    }
+
+    return 0;
+}
+
 void Phase1::findRegionPairs(vector<std::pair<Function*, Function*> >& rpairs)
 {
     while(!m_regionPairDeclFunc->use_empty()) {
         CallInst* ci = dyn_cast<CallInst>(m_regionPairDeclFunc->use_back());
         assert(ci && "Expect to see region pairs sigfun only in a call");
 
-        CastInst* arg1 = dyn_cast<CastInst>(ci->getOperand(1));
-        CastInst* arg2 = dyn_cast<CastInst>(ci->getOperand(2));
-        assert(arg1 && arg2 && "Expect both call operands are results of cast insts");
-
-        Function* startFunc = dyn_cast<Function>(arg1->getOperand(0));
-        Function* endFunc =   dyn_cast<Function>(arg2->getOperand(0));
-        assert(startFunc && endFunc && "Expect operands of casts are functions");
+        Function* startFunc = extractFunctionArg(ci->getOperand(1));
+        Function* endFunc =   extractFunctionArg(ci->getOperand(2));
 
+        assert(startFunc && endFunc &&
+               "Failed to obtain Function* params of region pair sigfun");
+        
         rpairs.push_back(std::make_pair(startFunc, endFunc));
 
-        PurgeInst(arg1);
-        PurgeInst(arg2);
+        PurgeInst(ci);
     }
 }
 
@@ -160,28 +174,16 @@
 void Phase1::transformSites() 
 {
     ////////////////
-    // Build list of region pair sigfuns; finding pp_regionPair will yield user-defined
-    // instances of them.
+    // Build list of region pair sigfuns
+
     vector<std::pair<Function*, Function*> > rpairs;
     vector<const Type*> params;
 
     // Populate with builtins
 
-    // TODO: Replace this hard-coded mechanism for builtins with a
-    // different mechanism that registers functions as "significant" (i.e. pp_metricSpec
-    // directive or some such thing).
-
-    // elapsed time builtin
-    params.push_back(PointerType::get(Type::DoubleTy));
-    FunctionType* ftype = FunctionType::get(Type::VoidTy, params, false);
-    Function* elapsed1 = m_module->getOrInsertFunction("pp_elapsed_time_start", ftype);
-
-    params.clear();
-    params.push_back(PointerType::get(Type::DoubleTy));
-    params.push_back(PointerType::get(Type::DoubleTy));
-    ftype = FunctionType::get(Type::VoidTy, params, false);
-    Function* elapsed2 = m_module->getOrInsertFunction("pp_elapsed_time_end", ftype);
-    rpairs.push_back(std::make_pair(elapsed1, elapsed2));
+    // TODO: Replace the hard-coded mechanism for the point metrics with a
+    // sigfun registration mechanism like that which exists for region metrics
+    // (pp_regionPair()).
 
     // Find user-declared region-pairs and add them to the list
     findRegionPairs(rpairs);
@@ -193,7 +195,7 @@
 
     // counter builtin
     params.clear();
-    ftype = FunctionType::get(Type::UIntTy, params, false);
+    FunctionType* ftype = FunctionType::get(Type::UIntTy, params, false);
     metricSpecs.push_back(m_module->getOrInsertFunction("pp_counterPrim", ftype));
     
     // timestamp builtin
@@ -286,14 +288,17 @@
 
     for(Value::use_iterator u = startFunc->use_begin(),
             ue = startFunc->use_end(); u != ue; ++u) {
-        CallInst* startCall = dyn_cast<CallInst>(*u);
 
+        if(isa<ConstantPointerRef>(*u)) {
+            continue; // skips forward declarations of sigfun
+        }
+
+        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");





More information about the llvm-commits mailing list