mirror of
https://github.com/RPCSX/llvm.git
synced 2025-01-26 22:45:05 +00:00
When evaluating an AA, pass in size info
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18264 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
15ee8adb00
commit
1ed80b66b1
@ -23,6 +23,7 @@
|
|||||||
#include "llvm/DerivedTypes.h"
|
#include "llvm/DerivedTypes.h"
|
||||||
#include "llvm/Analysis/AliasAnalysis.h"
|
#include "llvm/Analysis/AliasAnalysis.h"
|
||||||
#include "llvm/Assembly/Writer.h"
|
#include "llvm/Assembly/Writer.h"
|
||||||
|
#include "llvm/Target/TargetData.h"
|
||||||
#include "llvm/Support/InstIterator.h"
|
#include "llvm/Support/InstIterator.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -92,6 +93,8 @@ PrintModRefResults(const char *Msg, bool P, Instruction *I, Value *Ptr,
|
|||||||
|
|
||||||
bool AAEval::runOnFunction(Function &F) {
|
bool AAEval::runOnFunction(Function &F) {
|
||||||
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
|
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
|
||||||
|
|
||||||
|
const TargetData &TD = AA.getTargetData();
|
||||||
|
|
||||||
std::set<Value *> Pointers;
|
std::set<Value *> Pointers;
|
||||||
std::set<CallSite> CallSites;
|
std::set<CallSite> CallSites;
|
||||||
@ -118,9 +121,17 @@ bool AAEval::runOnFunction(Function &F) {
|
|||||||
|
|
||||||
// iterate over the worklist, and run the full (n^2)/2 disambiguations
|
// iterate over the worklist, and run the full (n^2)/2 disambiguations
|
||||||
for (std::set<Value *>::iterator I1 = Pointers.begin(), E = Pointers.end();
|
for (std::set<Value *>::iterator I1 = Pointers.begin(), E = Pointers.end();
|
||||||
I1 != E; ++I1)
|
I1 != E; ++I1) {
|
||||||
for (std::set<Value *>::iterator I2 = Pointers.begin(); I2 != I1; ++I2)
|
unsigned I1Size = 0;
|
||||||
switch (AA.alias(*I1, 0, *I2, 0)) {
|
const Type *I1ElTy = cast<PointerType>((*I1)->getType())->getElementType();
|
||||||
|
if (I1ElTy->isSized()) I1Size = TD.getTypeSize(I1ElTy);
|
||||||
|
|
||||||
|
for (std::set<Value *>::iterator I2 = Pointers.begin(); I2 != I1; ++I2) {
|
||||||
|
unsigned I2Size = 0;
|
||||||
|
const Type *I2ElTy =cast<PointerType>((*I2)->getType())->getElementType();
|
||||||
|
if (I2ElTy->isSized()) I2Size = TD.getTypeSize(I2ElTy);
|
||||||
|
|
||||||
|
switch (AA.alias(*I1, I1Size, *I2, I2Size)) {
|
||||||
case AliasAnalysis::NoAlias:
|
case AliasAnalysis::NoAlias:
|
||||||
PrintResults("NoAlias", PrintNoAlias, *I1, *I2, F.getParent());
|
PrintResults("NoAlias", PrintNoAlias, *I1, *I2, F.getParent());
|
||||||
++NoAlias; break;
|
++NoAlias; break;
|
||||||
@ -133,37 +144,36 @@ bool AAEval::runOnFunction(Function &F) {
|
|||||||
default:
|
default:
|
||||||
std::cerr << "Unknown alias query result!\n";
|
std::cerr << "Unknown alias query result!\n";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Mod/ref alias analysis: compare all pairs of calls and values
|
// Mod/ref alias analysis: compare all pairs of calls and values
|
||||||
for (std::set<Value *>::iterator V = Pointers.begin(), Ve = Pointers.end();
|
for (std::set<Value *>::iterator V = Pointers.begin(), Ve = Pointers.end();
|
||||||
V != Ve; ++V) {
|
V != Ve; ++V) {
|
||||||
unsigned Size = 0;
|
unsigned Size = 0;
|
||||||
if (const PointerType *PTy = dyn_cast<PointerType>((*V)->getType()))
|
const Type *ElTy = cast<PointerType>((*V)->getType())->getElementType();
|
||||||
if (!(Size = PTy->getElementType()->getPrimitiveSize()))
|
if (ElTy->isSized()) Size = TD.getTypeSize(ElTy);
|
||||||
if (isa<PointerType>(PTy->getElementType()))
|
|
||||||
Size = 4; // This is a hack, but it's good enough for eval.
|
|
||||||
|
|
||||||
if (Size)
|
for (std::set<CallSite>::iterator C = CallSites.begin(),
|
||||||
for (std::set<CallSite>::iterator C = CallSites.begin(),
|
Ce = CallSites.end(); C != Ce; ++C) {
|
||||||
Ce = CallSites.end(); C != Ce; ++C) {
|
Instruction *I = C->getInstruction();
|
||||||
Instruction *I = C->getInstruction();
|
switch (AA.getModRefInfo(*C, *V, Size)) {
|
||||||
switch (AA.getModRefInfo(*C, *V, Size)) {
|
case AliasAnalysis::NoModRef:
|
||||||
case AliasAnalysis::NoModRef:
|
PrintModRefResults("NoModRef", PrintNoModRef, I, *V, F.getParent());
|
||||||
PrintModRefResults("NoModRef", PrintNoModRef, I, *V, F.getParent());
|
++NoModRef; break;
|
||||||
++NoModRef; break;
|
case AliasAnalysis::Mod:
|
||||||
case AliasAnalysis::Mod:
|
PrintModRefResults(" Mod", PrintMod, I, *V, F.getParent());
|
||||||
PrintModRefResults(" Mod", PrintMod, I, *V, F.getParent());
|
++Mod; break;
|
||||||
++Mod; break;
|
case AliasAnalysis::Ref:
|
||||||
case AliasAnalysis::Ref:
|
PrintModRefResults(" Ref", PrintRef, I, *V, F.getParent());
|
||||||
PrintModRefResults(" Ref", PrintRef, I, *V, F.getParent());
|
++Ref; break;
|
||||||
++Ref; break;
|
case AliasAnalysis::ModRef:
|
||||||
case AliasAnalysis::ModRef:
|
PrintModRefResults(" ModRef", PrintModRef, I, *V, F.getParent());
|
||||||
PrintModRefResults(" ModRef", PrintModRef, I, *V, F.getParent());
|
++ModRef; break;
|
||||||
++ModRef; break;
|
default:
|
||||||
default:
|
std::cerr << "Unknown alias query result!\n";
|
||||||
std::cerr << "Unknown alias query result!\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user