Tanya Lattner | 5ec3a63 | 2005-03-29 20:33:42 +0000 | [diff] [blame^] | 1 | //===-- DependenceAnalyzer.cpp - DependenceAnalyzer ----------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // |
| 11 | // |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | #define DEBUG_TYPE "ModuloSched" |
| 15 | |
| 16 | #include "DependenceAnalyzer.h" |
| 17 | #include "llvm/Support/Debug.h" |
| 18 | |
| 19 | namespace llvm { |
| 20 | |
| 21 | |
| 22 | /// Create ModuloSchedulingPass |
| 23 | /// |
| 24 | FunctionPass *llvm::createDependenceAnalyzer() { |
| 25 | return new DependenceAnalyzer(); |
| 26 | } |
| 27 | |
| 28 | bool DependenceAnalyzer::runOnFunction(Function &F) { |
| 29 | AA = &getAnalysis<AliasAnalysis>(); |
| 30 | TD = &getAnalysis<TargetData>(); |
| 31 | |
| 32 | return false; |
| 33 | } |
| 34 | |
| 35 | static RegisterAnalysis<DependenceAnalyzer>X("depanalyzer", "Dependence Analyzer"); |
| 36 | |
| 37 | DependenceResult DependenceAnalyzer::getDependenceInfo(Instruction *inst1, Instruction *inst2) { |
| 38 | std::vector<Dependence> deps; |
| 39 | |
| 40 | DEBUG(std::cerr << "Inst1: " << *inst1 << "\n"); |
| 41 | DEBUG(std::cerr << "Inst2: " << *inst2 << "\n"); |
| 42 | |
| 43 | |
| 44 | if(LoadInst *ldInst = dyn_cast<LoadInst>(inst1)) { |
| 45 | |
| 46 | if(StoreInst *stInst = dyn_cast<StoreInst>(inst2)) { |
| 47 | //Get load mem ref |
| 48 | Value *ldOp = ldInst->getOperand(0); |
| 49 | |
| 50 | //Get store mem ref |
| 51 | Value *stOp = stInst->getOperand(1); |
| 52 | |
| 53 | if(AA->alias(ldOp, (unsigned)TD->getTypeSize(ldOp->getType()), |
| 54 | stOp,(unsigned)TD->getTypeSize(stOp->getType())) |
| 55 | != AliasAnalysis::NoAlias) { |
| 56 | |
| 57 | //Anti Dep |
| 58 | deps.push_back(Dependence(0, Dependence::AntiDep)); |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | else if(StoreInst *stInst = dyn_cast<StoreInst>(inst1)) { |
| 64 | |
| 65 | if(LoadInst *ldInst = dyn_cast<LoadInst>(inst2)) { |
| 66 | //Get load mem ref |
| 67 | Value *ldOp = ldInst->getOperand(0); |
| 68 | |
| 69 | //Get store mem ref |
| 70 | Value *stOp = stInst->getOperand(1); |
| 71 | |
| 72 | |
| 73 | if(AA->alias(ldOp, (unsigned)TD->getTypeSize(ldOp->getType()), |
| 74 | stOp,(unsigned)TD->getTypeSize(stOp->getType())) |
| 75 | != AliasAnalysis::NoAlias) { |
| 76 | |
| 77 | //Anti Dep |
| 78 | deps.push_back(Dependence(0, Dependence::TrueDep)); |
| 79 | } |
| 80 | } |
| 81 | else if(StoreInst *stInst2 = dyn_cast<StoreInst>(inst2)) { |
| 82 | |
| 83 | //Get load mem ref |
| 84 | Value *stOp1 = stInst->getOperand(1); |
| 85 | |
| 86 | //Get store mem ref |
| 87 | Value *stOp2 = stInst2->getOperand(1); |
| 88 | |
| 89 | |
| 90 | if(AA->alias(stOp1, (unsigned)TD->getTypeSize(stOp1->getType()), |
| 91 | stOp2,(unsigned)TD->getTypeSize(stOp2->getType())) |
| 92 | != AliasAnalysis::NoAlias) { |
| 93 | |
| 94 | //Anti Dep |
| 95 | deps.push_back(Dependence(0, Dependence::OutputDep)); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | |
| 100 | } |
| 101 | else |
| 102 | assert("Expected a load or a store\n"); |
| 103 | |
| 104 | DependenceResult dr = DependenceResult(deps); |
| 105 | return dr; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | |