[llvm-commits] CVS: llvm/lib/Target/SparcV9/ModuloScheduling/DependenceAnalyzer.cpp DependenceAnalyzer.h

Tanya Brethour tbrethou at cs.uiuc.edu
Tue Mar 29 12:33:53 PST 2005



Changes in directory llvm/lib/Target/SparcV9/ModuloScheduling:

DependenceAnalyzer.cpp added (r1.1)
DependenceAnalyzer.h added (r1.1)
---
Log message:

Dependence analyzer that just determines dependences within a loop for loads and stores using alias analysis.


---
Diffs of the changes:  (+182 -0)

 DependenceAnalyzer.cpp |  109 +++++++++++++++++++++++++++++++++++++++++++++++++
 DependenceAnalyzer.h   |   73 ++++++++++++++++++++++++++++++++
 2 files changed, 182 insertions(+)


Index: llvm/lib/Target/SparcV9/ModuloScheduling/DependenceAnalyzer.cpp
diff -c /dev/null llvm/lib/Target/SparcV9/ModuloScheduling/DependenceAnalyzer.cpp:1.1
*** /dev/null	Tue Mar 29 14:33:52 2005
--- llvm/lib/Target/SparcV9/ModuloScheduling/DependenceAnalyzer.cpp	Tue Mar 29 14:33:42 2005
***************
*** 0 ****
--- 1,109 ----
+ //===-- DependenceAnalyzer.cpp - DependenceAnalyzer  ----------------*- C++ -*-===//
+ //
+ //                     The LLVM Compiler Infrastructure
+ //
+ // This file was developed by the LLVM research group and is distributed under
+ // the University of Illinois Open Source License. See LICENSE.TXT for details.
+ //
+ //===----------------------------------------------------------------------===//
+ // 
+ //  
+ //  
+ // 
+ //===----------------------------------------------------------------------===//
+ #define DEBUG_TYPE "ModuloSched"
+ 
+ #include "DependenceAnalyzer.h"
+ #include "llvm/Support/Debug.h"
+ 
+ namespace llvm {
+ 
+ 
+ /// Create ModuloSchedulingPass
+ ///
+ FunctionPass *llvm::createDependenceAnalyzer() {
+   return new DependenceAnalyzer(); 
+ }
+ 
+   bool DependenceAnalyzer::runOnFunction(Function &F) {
+     AA = &getAnalysis<AliasAnalysis>();
+     TD = &getAnalysis<TargetData>();
+   
+     return  false;
+   }
+ 
+   static RegisterAnalysis<DependenceAnalyzer>X("depanalyzer", "Dependence Analyzer");
+   
+   DependenceResult DependenceAnalyzer::getDependenceInfo(Instruction *inst1, Instruction *inst2) {
+     std::vector<Dependence> deps;
+ 
+     DEBUG(std::cerr << "Inst1: " << *inst1 << "\n");
+     DEBUG(std::cerr << "Inst2: " << *inst2 << "\n");
+     
+ 
+     if(LoadInst *ldInst = dyn_cast<LoadInst>(inst1)) {
+ 
+       if(StoreInst *stInst = dyn_cast<StoreInst>(inst2)) {
+ 	//Get load mem ref
+ 	Value *ldOp = ldInst->getOperand(0);
+ 	
+ 	//Get store mem ref
+ 	Value *stOp = stInst->getOperand(1);
+ 	
+ 	if(AA->alias(ldOp, (unsigned)TD->getTypeSize(ldOp->getType()),
+ 		     stOp,(unsigned)TD->getTypeSize(stOp->getType()))
+ 	   != AliasAnalysis::NoAlias) {
+ 	  
+ 	  //Anti Dep
+ 	  deps.push_back(Dependence(0, Dependence::AntiDep));
+ 	}
+       }
+     }
+ 
+     else if(StoreInst *stInst = dyn_cast<StoreInst>(inst1)) {
+       
+       if(LoadInst *ldInst = dyn_cast<LoadInst>(inst2)) {
+ 	//Get load mem ref
+ 	Value *ldOp = ldInst->getOperand(0);
+ 	
+ 	//Get store mem ref
+ 	Value *stOp = stInst->getOperand(1);
+ 	
+ 	
+ 	if(AA->alias(ldOp, (unsigned)TD->getTypeSize(ldOp->getType()),
+ 		     stOp,(unsigned)TD->getTypeSize(stOp->getType()))
+ 	   != AliasAnalysis::NoAlias) {
+ 	  
+ 	  //Anti Dep
+ 	  deps.push_back(Dependence(0, Dependence::TrueDep));
+ 	}
+       }
+       else if(StoreInst *stInst2 = dyn_cast<StoreInst>(inst2)) {
+ 
+ 	//Get load mem ref
+ 	Value *stOp1 = stInst->getOperand(1);
+ 	
+ 	//Get store mem ref
+ 	Value *stOp2 = stInst2->getOperand(1);
+ 
+       
+ 	if(AA->alias(stOp1, (unsigned)TD->getTypeSize(stOp1->getType()),
+ 		     stOp2,(unsigned)TD->getTypeSize(stOp2->getType()))
+ 	   != AliasAnalysis::NoAlias) {
+ 	  
+ 	  //Anti Dep
+ 	  deps.push_back(Dependence(0, Dependence::OutputDep));
+ 	}
+       }
+ 
+     
+     }
+     else
+       assert("Expected a load or a store\n");
+ 
+     DependenceResult dr = DependenceResult(deps);
+     return dr;
+   }
+ }
+   
+ 


Index: llvm/lib/Target/SparcV9/ModuloScheduling/DependenceAnalyzer.h
diff -c /dev/null llvm/lib/Target/SparcV9/ModuloScheduling/DependenceAnalyzer.h:1.1
*** /dev/null	Tue Mar 29 14:33:53 2005
--- llvm/lib/Target/SparcV9/ModuloScheduling/DependenceAnalyzer.h	Tue Mar 29 14:33:42 2005
***************
*** 0 ****
--- 1,73 ----
+ //===-- DependenceAnalyzer.h - Dependence Analyzer--------------*- C++ -*-===//
+ //
+ //                     The LLVM Compiler Infrastructure
+ //
+ // This file was developed by the LLVM research group and is distributed under
+ // the University of Illinois Open Source License. See LICENSE.TXT for details.
+ //
+ //===----------------------------------------------------------------------===//
+ // 
+ // 
+ //===----------------------------------------------------------------------===//
+ 
+ #ifndef LLVM_DEPENDENCEANALYZER_H
+ #define LLVM_DEPENDENCEANALYZER_H
+ 
+ #include "llvm/Instructions.h"
+ #include "llvm/Function.h"
+ #include "llvm/Pass.h"
+ #include "llvm/Analysis/AliasAnalysis.h"
+ #include "llvm/Target/TargetData.h"
+ #include <vector>
+ 
+ namespace llvm {
+ 
+   //class to represent a dependence
+   struct Dependence {
+     
+     enum DataDepType {
+       TrueDep, AntiDep, OutputDep, NonDateDep,
+     };
+     
+     Dependence(int diff, DataDepType dep) : iteDiff(diff), depType(dep) {}
+     unsigned getIteDiff() { return iteDiff; }
+     unsigned getDepType() { return depType; }
+     
+     private:
+     
+     unsigned iteDiff;
+     unsigned depType;
+   };
+ 
+   
+   struct DependenceResult {
+     std::vector<Dependence> dependences;
+     DependenceResult(const std::vector<Dependence> &d) : dependences(d) {}
+   };
+ 
+ 
+   class DependenceAnalyzer : public FunctionPass {
+     AliasAnalysis *AA;
+     TargetData *TD;
+  
+   public:
+     DependenceAnalyzer() { AA = 0; TD = 0; }
+     virtual bool runOnFunction(Function &F);
+     virtual const char* getPassName() const { return "DependenceAnalyzer"; }
+   
+     // getAnalysisUsage
+     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+       AU.addRequired<AliasAnalysis>();
+       AU.addRequired<TargetData>();
+     }
+ 
+     //get dependence info
+     DependenceResult getDependenceInfo(Instruction *inst1, Instruction *inst2);
+ 
+   };
+ 
+ }
+ 
+ 
+ 
+ #endif






More information about the llvm-commits mailing list