aboutsummaryrefslogtreecommitdiff
path: root/lib/Target/SparcV9/ModuloScheduling/DependenceAnalyzer.cpp
blob: f27bca01458909fe0a69f53a5e0af2c3f27255bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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;
  }
}