mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-18 12:25:47 +00:00
enhance FindAvailableLoadedValue to make use of AliasAnalysis
if it has it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60167 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
#include "llvm/Analysis/AliasAnalysis.h"
|
#include "llvm/Analysis/AliasAnalysis.h"
|
||||||
#include "llvm/Analysis/LoopInfo.h"
|
#include "llvm/Analysis/LoopInfo.h"
|
||||||
#include "llvm/Analysis/Dominators.h"
|
#include "llvm/Analysis/Dominators.h"
|
||||||
|
#include "llvm/Target/TargetData.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
@@ -390,6 +391,13 @@ Value *llvm::FindAvailableLoadedValue(Value *Ptr, BasicBlock *ScanBB,
|
|||||||
unsigned MaxInstsToScan,
|
unsigned MaxInstsToScan,
|
||||||
AliasAnalysis *AA) {
|
AliasAnalysis *AA) {
|
||||||
if (MaxInstsToScan == 0) MaxInstsToScan = ~0U;
|
if (MaxInstsToScan == 0) MaxInstsToScan = ~0U;
|
||||||
|
|
||||||
|
// If we're using alias analysis to disambiguate get the size of *Ptr.
|
||||||
|
unsigned AccessSize = 0;
|
||||||
|
if (AA) {
|
||||||
|
const Type *AccessTy = cast<PointerType>(Ptr->getType())->getElementType();
|
||||||
|
AccessSize = AA->getTargetData().getTypeStoreSizeInBits(AccessTy);
|
||||||
|
}
|
||||||
|
|
||||||
while (ScanFrom != ScanBB->begin()) {
|
while (ScanFrom != ScanBB->begin()) {
|
||||||
// Don't scan huge blocks.
|
// Don't scan huge blocks.
|
||||||
@@ -415,14 +423,25 @@ Value *llvm::FindAvailableLoadedValue(Value *Ptr, BasicBlock *ScanBB,
|
|||||||
isa<GlobalVariable>(SI->getOperand(1))))
|
isa<GlobalVariable>(SI->getOperand(1))))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// If we have alias analysis and it says the store won't modify the loaded
|
||||||
|
// value, ignore the store.
|
||||||
|
if (AA &&
|
||||||
|
(AA->getModRefInfo(SI, Ptr, AccessSize) & AliasAnalysis::Mod) == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
// Otherwise the store that may or may not alias the pointer, bail out.
|
// Otherwise the store that may or may not alias the pointer, bail out.
|
||||||
++ScanFrom;
|
++ScanFrom;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// If this is some other instruction that may clobber Ptr, bail out.
|
// If this is some other instruction that may clobber Ptr, bail out.
|
||||||
if (Inst->mayWriteToMemory()) {
|
if (Inst->mayWriteToMemory()) {
|
||||||
|
// If alias analysis claims that it really won't modify the load,
|
||||||
|
// ignore it.
|
||||||
|
if (AA &&
|
||||||
|
(AA->getModRefInfo(Inst, Ptr, AccessSize) & AliasAnalysis::Mod) == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
// May modify the pointer, bail out.
|
// May modify the pointer, bail out.
|
||||||
++ScanFrom;
|
++ScanFrom;
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user