#include "llvm/Type.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Assembly/Writer.h"
-#include "llvm/Support/Compiler.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/InstIterator.h"
-#include "llvm/Support/Streams.h"
+#include "llvm/Support/Format.h"
+#include "llvm/Support/raw_ostream.h"
using namespace llvm;
/// mergeSetIn - Merge the specified alias set into this alias set.
// Check the call sites list and invoke list...
if (!CallSites.empty()) {
- if (AA.hasNoModRefInfoForCalls())
- return true;
-
for (unsigned i = 0, e = CallSites.size(); i != e; ++i)
- if (AA.getModRefInfo(CallSites[i], const_cast<Value*>(Ptr), Size)
+ if (AA.getModRefInfo(CallSites[i], Ptr, Size)
!= AliasAnalysis::NoModRef)
return true;
}
if (AA.doesNotAccessMemory(CS))
return false;
- if (AA.hasNoModRefInfoForCalls())
- return true;
-
for (unsigned i = 0, e = CallSites.size(); i != e; ++i)
if (AA.getModRefInfo(CallSites[i], CS) != AliasAnalysis::NoModRef ||
AA.getModRefInfo(CS, CallSites[i]) != AliasAnalysis::NoModRef)
void AliasSetTracker::clear() {
// Delete all the PointerRec entries.
- for (DenseMap<Value*, AliasSet::PointerRec*>::iterator I = PointerMap.begin(),
- E = PointerMap.end(); I != E; ++I)
+ for (PointerMapType::iterator I = PointerMap.begin(), E = PointerMap.end();
+ I != E; ++I)
I->second->eraseFromList();
PointerMap.clear();
bool AliasSetTracker::add(LoadInst *LI) {
bool NewPtr;
AliasSet &AS = addPointer(LI->getOperand(0),
- AA.getTargetData().getTypeStoreSize(LI->getType()),
+ AA.getTypeStoreSize(LI->getType()),
AliasSet::Refs, NewPtr);
if (LI->isVolatile()) AS.setVolatile();
return NewPtr;
bool NewPtr;
Value *Val = SI->getOperand(0);
AliasSet &AS = addPointer(SI->getOperand(1),
- AA.getTargetData().getTypeStoreSize(Val->getType()),
+ AA.getTypeStoreSize(Val->getType()),
AliasSet::Mods, NewPtr);
if (SI->isVolatile()) AS.setVolatile();
return NewPtr;
}
-bool AliasSetTracker::add(FreeInst *FI) {
- bool NewPtr;
- addPointer(FI->getOperand(0), ~0, AliasSet::Mods, NewPtr);
- return NewPtr;
-}
-
bool AliasSetTracker::add(VAArgInst *VAAI) {
bool NewPtr;
addPointer(VAAI->getOperand(0), ~0, AliasSet::ModRef, NewPtr);
return add(CI);
else if (InvokeInst *II = dyn_cast<InvokeInst>(I))
return add(II);
- else if (FreeInst *FI = dyn_cast<FreeInst>(I))
- return add(FI);
else if (VAArgInst *VAAI = dyn_cast<VAArgInst>(I))
return add(VAAI);
return true;
}
bool AliasSetTracker::remove(LoadInst *LI) {
- unsigned Size = AA.getTargetData().getTypeStoreSize(LI->getType());
+ unsigned Size = AA.getTypeStoreSize(LI->getType());
AliasSet *AS = findAliasSetForPointer(LI->getOperand(0), Size);
if (!AS) return false;
remove(*AS);
}
bool AliasSetTracker::remove(StoreInst *SI) {
- unsigned Size =
- AA.getTargetData().getTypeStoreSize(SI->getOperand(0)->getType());
+ unsigned Size = AA.getTypeStoreSize(SI->getOperand(0)->getType());
AliasSet *AS = findAliasSetForPointer(SI->getOperand(1), Size);
if (!AS) return false;
remove(*AS);
return true;
}
-bool AliasSetTracker::remove(FreeInst *FI) {
- AliasSet *AS = findAliasSetForPointer(FI->getOperand(0), ~0);
- if (!AS) return false;
- remove(*AS);
- return true;
-}
-
bool AliasSetTracker::remove(VAArgInst *VAAI) {
AliasSet *AS = findAliasSetForPointer(VAAI->getOperand(0), ~0);
if (!AS) return false;
return remove(SI);
else if (CallInst *CI = dyn_cast<CallInst>(I))
return remove(CI);
- else if (FreeInst *FI = dyn_cast<FreeInst>(I))
- return remove(FI);
else if (VAArgInst *VAAI = dyn_cast<VAArgInst>(I))
return remove(VAAI);
return true;
// If this is a call instruction, remove the callsite from the appropriate
// AliasSet.
- CallSite CS = CallSite::get(PtrVal);
- if (CS.getInstruction())
+ if (CallSite CS = PtrVal)
if (!AA.doesNotAccessMemory(CS))
if (AliasSet *AS = findAliasSetForCallSite(CS))
AS->removeCallSite(CS);
// First, look up the PointerRec for this pointer.
- DenseMap<Value*, AliasSet::PointerRec*>::iterator I = PointerMap.find(PtrVal);
+ PointerMapType::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.
AA.copyValue(From, To);
// First, look up the PointerRec for this pointer.
- DenseMap<Value*, AliasSet::PointerRec*>::iterator I = PointerMap.find(From);
+ PointerMapType::iterator I = PointerMap.find(From);
if (I == PointerMap.end())
return; // Noop
assert(I->second->hasAliasSet() && "Dead entry?");
if (Entry.hasAliasSet()) return; // Already in the tracker!
// Add it to the alias set it aliases...
+ I = PointerMap.find(From);
AliasSet *AS = I->second->getAliasSet(*this);
AS->addPointer(*this, Entry, I->second->getSize(), true);
}
// AliasSet/AliasSetTracker Printing Support
//===----------------------------------------------------------------------===//
-void AliasSet::print(std::ostream &OS) const {
- OS << " AliasSet[" << (void*)this << "," << RefCount << "] ";
+void AliasSet::print(raw_ostream &OS) const {
+ OS << " AliasSet[" << format("0x%p", (void*)this) << "," << RefCount << "] ";
OS << (AliasTy == MustAlias ? "must" : "may") << " alias, ";
switch (AccessTy) {
case NoModRef: OS << "No access "; break;
case Refs : OS << "Ref "; break;
case Mods : OS << "Mod "; break;
case ModRef : OS << "Mod/Ref "; break;
- default: assert(0 && "Bad value for AccessTy!");
+ default: llvm_unreachable("Bad value for AccessTy!");
}
if (isVolatile()) OS << "[volatile] ";
if (Forward)
OS << "\n";
}
-void AliasSetTracker::print(std::ostream &OS) const {
+void AliasSetTracker::print(raw_ostream &OS) const {
OS << "Alias Set Tracker: " << AliasSets.size() << " alias sets for "
<< PointerMap.size() << " pointer values.\n";
for (const_iterator I = begin(), E = end(); I != E; ++I)
OS << "\n";
}
-void AliasSet::dump() const { print (cerr); }
-void AliasSetTracker::dump() const { print(cerr); }
+void AliasSet::dump() const { print(dbgs()); }
+void AliasSetTracker::dump() const { print(dbgs()); }
+
+//===----------------------------------------------------------------------===//
+// ASTCallbackVH Class Implementation
+//===----------------------------------------------------------------------===//
+
+void AliasSetTracker::ASTCallbackVH::deleted() {
+ assert(AST && "ASTCallbackVH called with a null AliasSetTracker!");
+ AST->deleteValue(getValPtr());
+ // this now dangles!
+}
+
+AliasSetTracker::ASTCallbackVH::ASTCallbackVH(Value *V, AliasSetTracker *ast)
+ : CallbackVH(V), AST(ast) {}
+
+AliasSetTracker::ASTCallbackVH &
+AliasSetTracker::ASTCallbackVH::operator=(Value *V) {
+ return *this = ASTCallbackVH(V, AST);
+}
//===----------------------------------------------------------------------===//
// AliasSetPrinter Pass
//===----------------------------------------------------------------------===//
namespace {
- class VISIBILITY_HIDDEN AliasSetPrinter : public FunctionPass {
+ class AliasSetPrinter : public FunctionPass {
AliasSetTracker *Tracker;
public:
static char ID; // Pass identification, replacement for typeid
- AliasSetPrinter() : FunctionPass(&ID) {}
+ AliasSetPrinter() : FunctionPass(ID) {}
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
Tracker->add(&*I);
- Tracker->print(cerr);
+ Tracker->print(errs());
delete Tracker;
return false;
}
}
char AliasSetPrinter::ID = 0;
-static RegisterPass<AliasSetPrinter>
-X("print-alias-sets", "Alias Set Printer", false, true);
+INITIALIZE_PASS(AliasSetPrinter, "print-alias-sets",
+ "Alias Set Printer", false, true);