LLVM API Documentation

DependenceAnalyzer.h

Go to the documentation of this file.
00001 //===-- DependenceAnalyzer.h - Dependence Analyzer--------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //
00011 //===----------------------------------------------------------------------===//
00012 
00013 #ifndef LLVM_DEPENDENCEANALYZER_H
00014 #define LLVM_DEPENDENCEANALYZER_H
00015 
00016 #include "llvm/Instructions.h"
00017 #include "llvm/Function.h"
00018 #include "llvm/Pass.h"
00019 #include "llvm/Analysis/AliasAnalysis.h"
00020 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
00021 #include "llvm/Target/TargetData.h"
00022 #include <vector>
00023 
00024 namespace llvm {
00025 
00026 
00027   //class to represent a dependence
00028   struct Dependence {
00029 
00030     enum DataDepType {
00031       TrueDep, AntiDep, OutputDep, NonDateDep,
00032     };
00033 
00034     Dependence(int diff, DataDepType dep) : iteDiff(diff), depType(dep) {}
00035     unsigned getIteDiff() { return iteDiff; }
00036     unsigned getDepType() { return depType; }
00037 
00038     private:
00039 
00040     unsigned iteDiff;
00041     unsigned depType;
00042   };
00043 
00044 
00045   struct DependenceResult {
00046     std::vector<Dependence> dependences;
00047     DependenceResult(const std::vector<Dependence> &d) : dependences(d) {}
00048   };
00049 
00050 
00051   class DependenceAnalyzer : public FunctionPass {
00052 
00053 
00054     AliasAnalysis *AA;
00055     TargetData *TD;
00056     ScalarEvolution *SE;
00057 
00058     void advancedDepAnalysis(GetElementPtrInst *gp1, GetElementPtrInst *gp2,
00059                              bool valLoad, bool val2Load,
00060                              std::vector<Dependence> &deps, bool srcBeforeDest);
00061 
00062     void AnalyzeDeps(Value *val, Value *val2, bool val1Load, bool val2Load,
00063                      std::vector<Dependence> &deps, BasicBlock *BB,
00064                      bool srcBeforeDest);
00065 
00066     void createDep(std::vector<Dependence> &deps, bool valLoad, bool val2Load,
00067                    bool srcBeforeDest, int diff = 0);
00068 
00069   public:
00070     DependenceAnalyzer() { AA = 0; TD = 0; SE = 0; }
00071     virtual bool runOnFunction(Function &F);
00072     virtual const char* getPassName() const { return "DependenceAnalyzer"; }
00073 
00074     // getAnalysisUsage
00075     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
00076       AU.addRequired<AliasAnalysis>();
00077       AU.addRequired<TargetData>();
00078       AU.addRequired<ScalarEvolution>();
00079       AU.setPreservesAll();
00080     }
00081 
00082     //get dependence info
00083     DependenceResult getDependenceInfo(Instruction *inst1, Instruction *inst2,
00084                                        bool srcBeforeDest);
00085 
00086   };
00087 
00088 }
00089 
00090 
00091 
00092 #endif