Make the AST interface a bit richer by returning whether an insertion caused

an insertion or not (because the pointer set already existed).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15064 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2004-07-21 05:18:04 +00:00
parent e8a7e593e6
commit 12c1155403
2 changed files with 49 additions and 29 deletions

View File

@ -255,12 +255,15 @@ public:
/// 3. If the instruction aliases multiple sets, merge the sets, and add /// 3. If the instruction aliases multiple sets, merge the sets, and add
/// the instruction to the result. /// the instruction to the result.
/// ///
void add(LoadInst *LI); /// These methods return true if inserting the instruction resulted in the
void add(StoreInst *SI); /// addition of a new alias set (i.e., the pointer did not alias anything).
void add(CallSite CS); // Call/Invoke instructions ///
void add(CallInst *CI) { add(CallSite(CI)); } bool add(LoadInst *LI);
void add(InvokeInst *II) { add(CallSite(II)); } bool add(StoreInst *SI);
void add(Instruction *I); // Dispatch to one of the other add methods... bool add(CallSite CS); // Call/Invoke instructions
bool add(CallInst *CI) { return add(CallSite(CI)); }
bool add(InvokeInst *II) { return add(CallSite(II)); }
bool add(Instruction *I); // Dispatch to one of the other add methods...
void add(BasicBlock &BB); // Add all instructions in basic block void add(BasicBlock &BB); // Add all instructions in basic block
void add(const AliasSetTracker &AST); // Add alias relations from another AST void add(const AliasSetTracker &AST); // Add alias relations from another AST
@ -275,8 +278,10 @@ public:
const ilist<AliasSet> &getAliasSets() const { return AliasSets; } const ilist<AliasSet> &getAliasSets() const { return AliasSets; }
/// getAliasSetForPointer - Return the alias set that the specified pointer /// getAliasSetForPointer - Return the alias set that the specified pointer
/// lives in... /// lives in. If the New argument is non-null, this method sets the value to
AliasSet &getAliasSetForPointer(Value *P, unsigned Size); /// true if a new alias set is created to contain the pointer (because the
/// pointer didn't alias anything).
AliasSet &getAliasSetForPointer(Value *P, unsigned Size, bool *New = 0);
/// getAliasAnalysis - Return the underlying alias analysis object used by /// getAliasAnalysis - Return the underlying alias analysis object used by
/// this tracker. /// this tracker.
@ -305,8 +310,10 @@ private:
AliasSet::PointerRec())).first; AliasSet::PointerRec())).first;
} }
AliasSet &addPointer(Value *P, unsigned Size, AliasSet::AccessType E) { AliasSet &addPointer(Value *P, unsigned Size, AliasSet::AccessType E,
AliasSet &AS = getAliasSetForPointer(P, Size); bool &NewSet) {
NewSet = false;
AliasSet &AS = getAliasSetForPointer(P, Size, &NewSet);
AS.AccessTy |= E; AS.AccessTy |= E;
return AS; return AS;
} }

View File

@ -189,7 +189,8 @@ AliasSet *AliasSetTracker::findAliasSetForCallSite(CallSite CS) {
/// getAliasSetForPointer - Return the alias set that the specified pointer /// getAliasSetForPointer - Return the alias set that the specified pointer
/// lives in... /// lives in...
AliasSet &AliasSetTracker::getAliasSetForPointer(Value *Pointer, unsigned Size){ AliasSet &AliasSetTracker::getAliasSetForPointer(Value *Pointer, unsigned Size,
bool *New) {
AliasSet::HashNodePair &Entry = getEntryFor(Pointer); AliasSet::HashNodePair &Entry = getEntryFor(Pointer);
// Check to see if the pointer is already known... // Check to see if the pointer is already known...
@ -201,6 +202,7 @@ AliasSet &AliasSetTracker::getAliasSetForPointer(Value *Pointer, unsigned Size){
AS->addPointer(*this, Entry, Size); AS->addPointer(*this, Entry, Size);
return *AS; return *AS;
} else { } else {
if (New) *New = true;
// Otherwise create a new alias set to hold the loaded pointer... // Otherwise create a new alias set to hold the loaded pointer...
AliasSets.push_back(AliasSet()); AliasSets.push_back(AliasSet());
AliasSets.back().addPointer(*this, Entry, Size); AliasSets.back().addPointer(*this, Entry, Size);
@ -208,45 +210,55 @@ AliasSet &AliasSetTracker::getAliasSetForPointer(Value *Pointer, unsigned Size){
} }
} }
void AliasSetTracker::add(LoadInst *LI) { bool AliasSetTracker::add(LoadInst *LI) {
AliasSet &AS = bool NewPtr;
addPointer(LI->getOperand(0), AliasSet &AS = addPointer(LI->getOperand(0),
AA.getTargetData().getTypeSize(LI->getType()), AliasSet::Refs); AA.getTargetData().getTypeSize(LI->getType()),
AliasSet::Refs, NewPtr);
if (LI->isVolatile()) AS.setVolatile(); if (LI->isVolatile()) AS.setVolatile();
return NewPtr;
} }
void AliasSetTracker::add(StoreInst *SI) { bool AliasSetTracker::add(StoreInst *SI) {
AliasSet &AS = bool NewPtr;
addPointer(SI->getOperand(1), Value *Val = SI->getOperand(0);
AA.getTargetData().getTypeSize(SI->getOperand(0)->getType()), AliasSet &AS = addPointer(SI->getOperand(1),
AliasSet::Mods); AA.getTargetData().getTypeSize(Val->getType()),
AliasSet::Mods, NewPtr);
if (SI->isVolatile()) AS.setVolatile(); if (SI->isVolatile()) AS.setVolatile();
return NewPtr;
} }
void AliasSetTracker::add(CallSite CS) { bool AliasSetTracker::add(CallSite CS) {
bool NewPtr;
if (Function *F = CS.getCalledFunction()) if (Function *F = CS.getCalledFunction())
if (AA.doesNotAccessMemory(F)) if (AA.doesNotAccessMemory(F))
return; return true; // doesn't alias anything
AliasSet *AS = findAliasSetForCallSite(CS); AliasSet *AS = findAliasSetForCallSite(CS);
if (!AS) { if (!AS) {
AliasSets.push_back(AliasSet()); AliasSets.push_back(AliasSet());
AS = &AliasSets.back(); AS = &AliasSets.back();
AS->addCallSite(CS, AA);
return true;
} else {
AS->addCallSite(CS, AA);
return false;
} }
AS->addCallSite(CS, AA);
} }
void AliasSetTracker::add(Instruction *I) { bool AliasSetTracker::add(Instruction *I) {
// Dispatch to one of the other add methods... // Dispatch to one of the other add methods...
if (LoadInst *LI = dyn_cast<LoadInst>(I)) if (LoadInst *LI = dyn_cast<LoadInst>(I))
add(LI); return add(LI);
else if (StoreInst *SI = dyn_cast<StoreInst>(I)) else if (StoreInst *SI = dyn_cast<StoreInst>(I))
add(SI); return add(SI);
else if (CallInst *CI = dyn_cast<CallInst>(I)) else if (CallInst *CI = dyn_cast<CallInst>(I))
add(CI); return add(CI);
else if (InvokeInst *II = dyn_cast<InvokeInst>(I)) else if (InvokeInst *II = dyn_cast<InvokeInst>(I))
add(II); return add(II);
return true;
} }
void AliasSetTracker::add(BasicBlock &BB) { void AliasSetTracker::add(BasicBlock &BB) {
@ -271,9 +283,10 @@ void AliasSetTracker::add(const AliasSetTracker &AST) {
// Loop over all of the pointers in this alias set... // Loop over all of the pointers in this alias set...
AliasSet::iterator I = AS.begin(), E = AS.end(); AliasSet::iterator I = AS.begin(), E = AS.end();
bool X;
for (; I != E; ++I) for (; I != E; ++I)
addPointer(I->first, I->second.getSize(), addPointer(I->first, I->second.getSize(),
(AliasSet::AccessType)AS.AccessTy); (AliasSet::AccessType)AS.AccessTy, X);
} }
} }