#include "llvm/Target/TargetData.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/Support/InstIterator.h"
-
-namespace llvm {
+using namespace llvm;
/// mergeSetIn - Merge the specified alias set into this alias set...
///
RefCount++; // AS is now pointing to us...
// Merge the list of constituent pointers...
- PtrListTail->second.setTail(AS.PtrListHead);
- PtrListTail = AS.PtrListTail;
- AS.PtrListHead = AS.PtrListTail = 0;
+ if (AS.PtrList) {
+ *PtrListEnd = AS.PtrList;
+ AS.PtrList->second.setPrevInList(PtrListEnd);
+ PtrListEnd = AS.PtrListEnd;
+
+ AS.PtrList = 0;
+ AS.PtrListEnd = &AS.PtrList;
+ }
}
void AliasSetTracker::removeAliasSet(AliasSet *AS) {
Entry.second.updateSize(Size);
// Add it to the end of the list...
- if (PtrListTail)
- PtrListTail->second.setTail(&Entry);
- else
- PtrListHead = &Entry;
- PtrListTail = &Entry;
+ assert(*PtrListEnd == 0 && "End of list is not null?");
+ *PtrListEnd = &Entry;
+ PtrListEnd = Entry.second.setPrevInList(PtrListEnd);
RefCount++; // Entry points to alias set...
}
-void AliasSet::addCallSite(CallSite CS) {
+void AliasSet::addCallSite(CallSite CS, AliasAnalysis &AA) {
CallSites.push_back(CS);
- AliasTy = MayAlias; // FIXME: Too conservative?
+
+ if (Function *F = CS.getCalledFunction()) {
+ if (AA.doesNotAccessMemory(F))
+ return;
+ else if (AA.onlyReadsMemory(F)) {
+ AliasTy = MayAlias;
+ AccessTy |= Refs;
+ return;
+ }
+ }
+
+ // FIXME: This should use mod/ref information to make this not suck so bad
+ AliasTy = MayAlias;
AccessTy = ModRef;
}
}
bool AliasSet::aliasesCallSite(CallSite CS, AliasAnalysis &AA) const {
- // FIXME: Too conservative!
+ // FIXME: Use mod/ref information to prune this better!
+ if (Function *F = CS.getCalledFunction())
+ if (AA.doesNotAccessMemory(F))
+ return false;
+
return true;
}
}
void AliasSetTracker::add(LoadInst *LI) {
- addPointer(LI->getOperand(0),
- AA.getTargetData().getTypeSize(LI->getType()), AliasSet::Refs);
+ AliasSet &AS =
+ addPointer(LI->getOperand(0),
+ AA.getTargetData().getTypeSize(LI->getType()), AliasSet::Refs);
+ if (LI->isVolatile()) AS.setVolatile();
}
void AliasSetTracker::add(StoreInst *SI) {
- addPointer(SI->getOperand(1),
- AA.getTargetData().getTypeSize(SI->getOperand(0)->getType()),
- AliasSet::Mods);
+ AliasSet &AS =
+ addPointer(SI->getOperand(1),
+ AA.getTargetData().getTypeSize(SI->getOperand(0)->getType()),
+ AliasSet::Mods);
+ if (SI->isVolatile()) AS.setVolatile();
}
+
void AliasSetTracker::add(CallSite CS) {
+ if (Function *F = CS.getCalledFunction())
+ if (AA.doesNotAccessMemory(F))
+ return;
+
AliasSet *AS = findAliasSetForCallSite(CS);
if (!AS) {
AliasSets.push_back(AliasSet());
AS = &AliasSets.back();
}
- AS->addCallSite(CS);
+ AS->addCallSite(CS, AA);
}
void AliasSetTracker::add(Instruction *I) {
}
}
+
+// remove method - This method is used to remove a pointer value from the
+// AliasSetTracker entirely. It should be used when an instruction is deleted
+// from the program to update the AST. If you don't use this, you would have
+// dangling pointers to deleted instructions.
+//
+void AliasSetTracker::remove(Value *PtrVal) {
+ // First, look up the PointerRec for this pointer...
+ hash_map<Value*, AliasSet::PointerRec>::iterator I = PointerMap.find(PtrVal);
+ if (I == PointerMap.end()) return; // Noop
+
+ // If we found one, remove the pointer from the alias set it is in.
+ AliasSet::HashNodePair &PtrValEnt = *I;
+ AliasSet *AS = PtrValEnt.second.getAliasSet(*this);
+
+ // Unlink from the list of values...
+ PtrValEnt.second.removeFromList();
+ // Stop using the alias set
+ if (--AS->RefCount == 0)
+ AS->removeFromTracker(*this);
+
+ PointerMap.erase(I);
+}
+
+
//===----------------------------------------------------------------------===//
// AliasSet/AliasSetTracker Printing Support
//===----------------------------------------------------------------------===//
case ModRef : OS << "Mod/Ref "; break;
default: assert(0 && "Bad value for AccessTy!");
}
+ if (isVolatile()) OS << "[volatile] ";
if (Forward)
OS << " forwarding to " << (void*)Forward;
RegisterPass<AliasSetPrinter> X("print-alias-sets", "Alias Set Printer",
PassInfo::Analysis | PassInfo::Optimization);
}
-
-} // End llvm namespace