aboutsummaryrefslogtreecommitdiff
path: root/lib/Target/SparcV9/ModuloScheduling/DependenceAnalyzer.h
blob: f9aac5c01019872493e5fd6c7a99ea64325303dd (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
//===-- 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/Analysis/ScalarEvolutionExpressions.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;
    ScalarEvolution *SE;

    void advancedDepAnalysis(GetElementPtrInst *gp1, GetElementPtrInst *gp2,
                             bool valLoad, bool val2Load,
                             std::vector<Dependence> &deps, bool srcBeforeDest);

    void AnalyzeDeps(Value *val, Value *val2, bool val1Load, bool val2Load,
                     std::vector<Dependence> &deps, BasicBlock *BB,
                     bool srcBeforeDest);

    void createDep(std::vector<Dependence> &deps, bool valLoad, bool val2Load,
                   bool srcBeforeDest, int diff = 0);

  public:
    DependenceAnalyzer() { AA = 0; TD = 0; SE = 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>();
      AU.addRequired<ScalarEvolution>();
      AU.setPreservesAll();
    }

    //get dependence info
    DependenceResult getDependenceInfo(Instruction *inst1, Instruction *inst2,
                                       bool srcBeforeDest);

  };

}



#endif