mirror of
https://github.com/RPCS3/llvm.git
synced 2025-03-01 07:09:02 +00:00
Dependence analyzer that just determines dependences within a loop for loads and stores using alias analysis.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20930 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
77b505670c
commit
5ec3a63f6d
109
lib/Target/SparcV9/ModuloScheduling/DependenceAnalyzer.cpp
Normal file
109
lib/Target/SparcV9/ModuloScheduling/DependenceAnalyzer.cpp
Normal file
@ -0,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;
|
||||
}
|
||||
}
|
||||
|
||||
|
73
lib/Target/SparcV9/ModuloScheduling/DependenceAnalyzer.h
Normal file
73
lib/Target/SparcV9/ModuloScheduling/DependenceAnalyzer.h
Normal file
@ -0,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
|
Loading…
x
Reference in New Issue
Block a user