mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2026-04-21 23:17:16 +00:00
Enhance GVN to do more precise alias queries for non-local memory
references. For example, this allows gvn to eliminate the load in
this example:
void foo(int n, int* p, int *q) {
p[0] = 0;
p[1] = 1;
if (n) {
*q = p[0];
}
}
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118714 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Analysis/MemoryDependenceAnalysis.h"
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Analysis/Passes.h"
|
||||
#include "llvm/Assembly/Writer.h"
|
||||
#include "llvm/Support/CallSite.h"
|
||||
@@ -40,7 +41,8 @@ namespace {
|
||||
void print(raw_ostream &OS, const Module * = 0) const;
|
||||
|
||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
||||
AU.addRequired<MemoryDependenceAnalysis>();
|
||||
AU.addRequiredTransitive<AliasAnalysis>();
|
||||
AU.addRequiredTransitive<MemoryDependenceAnalysis>();
|
||||
AU.setPreservesAll();
|
||||
}
|
||||
|
||||
@@ -64,6 +66,7 @@ FunctionPass *llvm::createMemDepPrinter() {
|
||||
|
||||
bool MemDepPrinter::runOnFunction(Function &F) {
|
||||
this->F = &F;
|
||||
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
|
||||
MemoryDependenceAnalysis &MDA = getAnalysis<MemoryDependenceAnalysis>();
|
||||
|
||||
// All this code uses non-const interfaces because MemDep is not
|
||||
@@ -99,15 +102,23 @@ bool MemDepPrinter::runOnFunction(Function &F) {
|
||||
SmallVector<NonLocalDepResult, 4> NLDI;
|
||||
if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
|
||||
// FIXME: Volatile is not handled properly here.
|
||||
MDA.getNonLocalPointerDependency(LI->getPointerOperand(), !LI->isVolatile(),
|
||||
AliasAnalysis::Location Loc(LI->getPointerOperand(),
|
||||
AA.getTypeStoreSize(LI->getType()),
|
||||
LI->getMetadata(LLVMContext::MD_tbaa));
|
||||
MDA.getNonLocalPointerDependency(Loc, !LI->isVolatile(),
|
||||
LI->getParent(), NLDI);
|
||||
} else if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
|
||||
// FIXME: Volatile is not handled properly here.
|
||||
MDA.getNonLocalPointerDependency(SI->getPointerOperand(), false,
|
||||
SI->getParent(), NLDI);
|
||||
AliasAnalysis::Location Loc(SI->getPointerOperand(),
|
||||
AA.getTypeStoreSize(SI->getValueOperand()
|
||||
->getType()),
|
||||
SI->getMetadata(LLVMContext::MD_tbaa));
|
||||
MDA.getNonLocalPointerDependency(Loc, false, SI->getParent(), NLDI);
|
||||
} else if (VAArgInst *VI = dyn_cast<VAArgInst>(Inst)) {
|
||||
MDA.getNonLocalPointerDependency(VI->getPointerOperand(), false,
|
||||
VI->getParent(), NLDI);
|
||||
AliasAnalysis::Location Loc(SI->getPointerOperand(),
|
||||
AliasAnalysis::UnknownSize,
|
||||
SI->getMetadata(LLVMContext::MD_tbaa));
|
||||
MDA.getNonLocalPointerDependency(Loc, false, VI->getParent(), NLDI);
|
||||
} else {
|
||||
llvm_unreachable("Unknown memory instruction!");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user