2003-02-06 22:29:49 +01:00
|
|
|
//===- AliasAnalysisEvaluator.cpp - Alias Analysis Accuracy Evaluator -----===//
|
2005-04-21 23:13:18 +02:00
|
|
|
//
|
2003-10-20 21:43:21 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 21:36:04 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 23:13:18 +02:00
|
|
|
//
|
2003-10-20 21:43:21 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2003-02-06 22:29:49 +01:00
|
|
|
|
2016-02-20 04:46:03 +01:00
|
|
|
#include "llvm/Analysis/AliasAnalysisEvaluator.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/ADT/SetVector.h"
|
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/Constants.h"
|
2015-08-06 04:05:46 +02:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
2015-08-06 04:05:46 +02:00
|
|
|
#include "llvm/IR/Module.h"
|
2014-03-04 11:30:26 +01:00
|
|
|
#include "llvm/IR/InstIterator.h"
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/Instructions.h"
|
2004-03-12 07:15:08 +01:00
|
|
|
#include "llvm/Pass.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2009-12-23 20:21:19 +01:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-25 02:23:56 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2003-12-10 16:33:59 +01:00
|
|
|
using namespace llvm;
|
2003-11-11 23:41:34 +01:00
|
|
|
|
2008-05-13 02:00:25 +02:00
|
|
|
static cl::opt<bool> PrintAll("print-all-alias-modref-info", cl::ReallyHidden);
|
2004-07-17 08:28:49 +02:00
|
|
|
|
2008-05-13 02:00:25 +02:00
|
|
|
static cl::opt<bool> PrintNoAlias("print-no-aliases", cl::ReallyHidden);
|
|
|
|
static cl::opt<bool> PrintMayAlias("print-may-aliases", cl::ReallyHidden);
|
2010-12-10 20:52:40 +01:00
|
|
|
static cl::opt<bool> PrintPartialAlias("print-partial-aliases", cl::ReallyHidden);
|
2008-05-13 02:00:25 +02:00
|
|
|
static cl::opt<bool> PrintMustAlias("print-must-aliases", cl::ReallyHidden);
|
2004-03-12 07:15:08 +01:00
|
|
|
|
2008-05-13 02:00:25 +02:00
|
|
|
static cl::opt<bool> PrintNoModRef("print-no-modref", cl::ReallyHidden);
|
|
|
|
static cl::opt<bool> PrintMod("print-mod", cl::ReallyHidden);
|
|
|
|
static cl::opt<bool> PrintRef("print-ref", cl::ReallyHidden);
|
|
|
|
static cl::opt<bool> PrintModRef("print-modref", cl::ReallyHidden);
|
2003-02-09 21:40:13 +01:00
|
|
|
|
2014-07-24 14:16:19 +02:00
|
|
|
static cl::opt<bool> EvalAAMD("evaluate-aa-metadata", cl::ReallyHidden);
|
2013-03-22 23:34:41 +01:00
|
|
|
|
2009-08-23 07:17:37 +02:00
|
|
|
static void PrintResults(const char *Msg, bool P, const Value *V1,
|
|
|
|
const Value *V2, const Module *M) {
|
2016-02-20 04:46:03 +01:00
|
|
|
if (PrintAll || P) {
|
2009-08-23 07:17:37 +02:00
|
|
|
std::string o1, o2;
|
|
|
|
{
|
|
|
|
raw_string_ostream os1(o1), os2(o2);
|
2014-01-09 03:29:41 +01:00
|
|
|
V1->printAsOperand(os1, true, M);
|
|
|
|
V2->printAsOperand(os2, true, M);
|
2009-08-23 07:17:37 +02:00
|
|
|
}
|
|
|
|
|
2008-02-28 09:38:45 +01:00
|
|
|
if (o2 < o1)
|
2009-07-25 02:23:56 +02:00
|
|
|
std::swap(o1, o2);
|
2009-12-23 23:49:57 +01:00
|
|
|
errs() << " " << Msg << ":\t"
|
2009-07-25 02:23:56 +02:00
|
|
|
<< o1 << ", "
|
|
|
|
<< o2 << "\n";
|
2003-02-09 21:40:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-21 23:13:18 +02:00
|
|
|
static inline void
|
2004-07-17 08:43:20 +02:00
|
|
|
PrintModRefResults(const char *Msg, bool P, Instruction *I, Value *Ptr,
|
|
|
|
Module *M) {
|
2016-02-20 04:46:03 +01:00
|
|
|
if (PrintAll || P) {
|
2009-12-23 23:49:57 +01:00
|
|
|
errs() << " " << Msg << ": Ptr: ";
|
2014-01-09 03:29:41 +01:00
|
|
|
Ptr->printAsOperand(errs(), true, M);
|
2009-12-23 23:49:57 +01:00
|
|
|
errs() << "\t<->" << *I << '\n';
|
2004-07-17 08:43:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-05 00:56:29 +02:00
|
|
|
static inline void
|
|
|
|
PrintModRefResults(const char *Msg, bool P, CallSite CSA, CallSite CSB,
|
|
|
|
Module *M) {
|
2016-02-20 04:46:03 +01:00
|
|
|
if (PrintAll || P) {
|
2010-08-05 00:56:29 +02:00
|
|
|
errs() << " " << Msg << ": " << *CSA.getInstruction()
|
|
|
|
<< " <-> " << *CSB.getInstruction() << '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-22 23:34:41 +01:00
|
|
|
static inline void
|
|
|
|
PrintLoadStoreResults(const char *Msg, bool P, const Value *V1,
|
|
|
|
const Value *V2, const Module *M) {
|
2016-02-20 04:46:03 +01:00
|
|
|
if (PrintAll || P) {
|
2013-03-22 23:34:41 +01:00
|
|
|
errs() << " " << Msg << ": " << *V1
|
|
|
|
<< " <-> " << *V2 << '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-08 18:46:24 +02:00
|
|
|
static inline bool isInterestingPointer(Value *V) {
|
|
|
|
return V->getType()->isPointerTy()
|
|
|
|
&& !isa<ConstantPointerNull>(V);
|
|
|
|
}
|
|
|
|
|
2016-03-11 12:05:24 +01:00
|
|
|
PreservedAnalyses AAEvaluator::run(Function &F, AnalysisManager<Function> &AM) {
|
|
|
|
runInternal(F, AM.getResult<AAManager>(F));
|
2016-02-20 04:46:03 +01:00
|
|
|
return PreservedAnalyses::all();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AAEvaluator::runInternal(Function &F, AAResults &AA) {
|
2015-08-06 04:05:46 +02:00
|
|
|
const DataLayout &DL = F.getParent()->getDataLayout();
|
2016-02-20 04:46:03 +01:00
|
|
|
|
|
|
|
++FunctionCount;
|
2010-07-07 16:27:09 +02:00
|
|
|
|
|
|
|
SetVector<Value *> Pointers;
|
2015-11-18 07:52:18 +01:00
|
|
|
SmallSetVector<CallSite, 16> CallSites;
|
2013-03-22 23:34:41 +01:00
|
|
|
SetVector<Value *> Loads;
|
|
|
|
SetVector<Value *> Stores;
|
2010-07-07 16:27:09 +02:00
|
|
|
|
Analysis: Remove implicit ilist iterator conversions
Remove implicit ilist iterator conversions from LLVMAnalysis.
I came across something really scary in `llvm::isKnownNotFullPoison()`
which relied on `Instruction::getNextNode()` being completely broken
(not surprising, but scary nevertheless). This function is documented
(and coded to) return `nullptr` when it gets to the sentinel, but with
an `ilist_half_node` as a sentinel, the sentinel check looks into some
other memory and we don't recognize we've hit the end.
Rooting out these scary cases is the reason I'm removing the implicit
conversions before doing anything else with `ilist`; I'm not at all
surprised that clients rely on badness.
I found another scary case -- this time, not relying on badness, just
bad (but I guess getting lucky so far) -- in
`ObjectSizeOffsetEvaluator::compute_()`. Here, we save out the
insertion point, do some things, and then restore it. Previously, we
let the iterator auto-convert to `Instruction*`, and then set it back
using the `Instruction*` version:
Instruction *PrevInsertPoint = Builder.GetInsertPoint();
/* Logic that may change insert point */
if (PrevInsertPoint)
Builder.SetInsertPoint(PrevInsertPoint);
The check for `PrevInsertPoint` doesn't protect correctly against bad
accesses. If the insertion point has been set to the end of a basic
block (i.e., `SetInsertPoint(SomeBB)`), then `GetInsertPoint()` returns
an iterator pointing at the list sentinel. The version of
`SetInsertPoint()` that's getting called will then call
`PrevInsertPoint->getParent()`, which explodes horribly. The only
reason this hasn't blown up is that it's fairly unlikely the builder is
adding to the end of the block; usually, we're adding instructions
somewhere before the terminator.
llvm-svn: 249925
2015-10-10 02:53:03 +02:00
|
|
|
for (auto &I : F.args())
|
|
|
|
if (I.getType()->isPointerTy()) // Add all pointer arguments.
|
|
|
|
Pointers.insert(&I);
|
2003-02-06 22:29:49 +01:00
|
|
|
|
2003-06-29 02:07:11 +02:00
|
|
|
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
|
2010-04-08 18:46:24 +02:00
|
|
|
if (I->getType()->isPointerTy()) // Add all pointer instructions.
|
2004-04-27 17:13:33 +02:00
|
|
|
Pointers.insert(&*I);
|
2014-07-24 14:16:19 +02:00
|
|
|
if (EvalAAMD && isa<LoadInst>(&*I))
|
2013-03-22 23:34:41 +01:00
|
|
|
Loads.insert(&*I);
|
2014-07-24 14:16:19 +02:00
|
|
|
if (EvalAAMD && isa<StoreInst>(&*I))
|
2013-03-22 23:34:41 +01:00
|
|
|
Stores.insert(&*I);
|
2005-03-17 21:25:04 +01:00
|
|
|
Instruction &Inst = *I;
|
2015-04-10 16:50:08 +02:00
|
|
|
if (auto CS = CallSite(&Inst)) {
|
2010-04-08 18:46:24 +02:00
|
|
|
Value *Callee = CS.getCalledValue();
|
|
|
|
// Skip actual functions for direct function calls.
|
|
|
|
if (!isa<Function>(Callee) && isInterestingPointer(Callee))
|
|
|
|
Pointers.insert(Callee);
|
|
|
|
// Consider formals.
|
2015-12-23 10:58:46 +01:00
|
|
|
for (Use &DataOp : CS.data_ops())
|
|
|
|
if (isInterestingPointer(DataOp))
|
|
|
|
Pointers.insert(DataOp);
|
2010-07-28 17:31:37 +02:00
|
|
|
CallSites.insert(CS);
|
2010-04-08 18:46:24 +02:00
|
|
|
} else {
|
|
|
|
// Consider all operands.
|
|
|
|
for (Instruction::op_iterator OI = Inst.op_begin(), OE = Inst.op_end();
|
|
|
|
OI != OE; ++OI)
|
|
|
|
if (isInterestingPointer(*OI))
|
|
|
|
Pointers.insert(*OI);
|
|
|
|
}
|
2004-03-12 07:15:08 +01:00
|
|
|
}
|
|
|
|
|
2016-02-20 04:46:03 +01:00
|
|
|
if (PrintAll || PrintNoAlias || PrintMayAlias || PrintPartialAlias ||
|
|
|
|
PrintMustAlias || PrintNoModRef || PrintMod || PrintRef || PrintModRef)
|
2010-07-07 16:27:09 +02:00
|
|
|
errs() << "Function: " << F.getName() << ": " << Pointers.size()
|
|
|
|
<< " pointers, " << CallSites.size() << " call sites\n";
|
2003-02-09 21:40:13 +01:00
|
|
|
|
2003-02-06 22:29:49 +01:00
|
|
|
// iterate over the worklist, and run the full (n^2)/2 disambiguations
|
2009-08-26 16:32:17 +02:00
|
|
|
for (SetVector<Value *>::iterator I1 = Pointers.begin(), E = Pointers.end();
|
2004-11-26 22:05:39 +01:00
|
|
|
I1 != E; ++I1) {
|
2015-06-17 09:21:38 +02:00
|
|
|
uint64_t I1Size = MemoryLocation::UnknownSize;
|
2011-07-18 06:54:35 +02:00
|
|
|
Type *I1ElTy = cast<PointerType>((*I1)->getType())->getElementType();
|
2015-08-06 04:05:46 +02:00
|
|
|
if (I1ElTy->isSized()) I1Size = DL.getTypeStoreSize(I1ElTy);
|
2004-11-26 22:05:39 +01:00
|
|
|
|
2009-08-26 16:32:17 +02:00
|
|
|
for (SetVector<Value *>::iterator I2 = Pointers.begin(); I2 != I1; ++I2) {
|
2015-06-17 09:21:38 +02:00
|
|
|
uint64_t I2Size = MemoryLocation::UnknownSize;
|
2011-07-18 06:54:35 +02:00
|
|
|
Type *I2ElTy =cast<PointerType>((*I2)->getType())->getElementType();
|
2015-08-06 04:05:46 +02:00
|
|
|
if (I2ElTy->isSized()) I2Size = DL.getTypeStoreSize(I2ElTy);
|
2004-11-26 22:05:39 +01:00
|
|
|
|
2010-07-07 16:27:09 +02:00
|
|
|
switch (AA.alias(*I1, I1Size, *I2, I2Size)) {
|
2015-06-22 04:16:51 +02:00
|
|
|
case NoAlias:
|
2010-07-07 16:27:09 +02:00
|
|
|
PrintResults("NoAlias", PrintNoAlias, *I1, *I2, F.getParent());
|
2015-06-17 09:21:41 +02:00
|
|
|
++NoAliasCount;
|
|
|
|
break;
|
2015-06-22 04:16:51 +02:00
|
|
|
case MayAlias:
|
2010-07-07 16:27:09 +02:00
|
|
|
PrintResults("MayAlias", PrintMayAlias, *I1, *I2, F.getParent());
|
2015-06-17 09:21:41 +02:00
|
|
|
++MayAliasCount;
|
|
|
|
break;
|
2015-06-22 04:16:51 +02:00
|
|
|
case PartialAlias:
|
2010-12-10 20:52:40 +01:00
|
|
|
PrintResults("PartialAlias", PrintPartialAlias, *I1, *I2,
|
|
|
|
F.getParent());
|
2015-06-17 09:21:41 +02:00
|
|
|
++PartialAliasCount;
|
|
|
|
break;
|
2015-06-22 04:16:51 +02:00
|
|
|
case MustAlias:
|
2010-07-07 16:27:09 +02:00
|
|
|
PrintResults("MustAlias", PrintMustAlias, *I1, *I2, F.getParent());
|
2015-06-17 09:21:41 +02:00
|
|
|
++MustAliasCount;
|
|
|
|
break;
|
2003-02-06 22:29:49 +01:00
|
|
|
}
|
2004-11-26 22:05:39 +01:00
|
|
|
}
|
|
|
|
}
|
2003-02-06 22:29:49 +01:00
|
|
|
|
2014-07-24 14:16:19 +02:00
|
|
|
if (EvalAAMD) {
|
2013-03-22 23:34:41 +01:00
|
|
|
// iterate over all pairs of load, store
|
|
|
|
for (SetVector<Value *>::iterator I1 = Loads.begin(), E = Loads.end();
|
|
|
|
I1 != E; ++I1) {
|
|
|
|
for (SetVector<Value *>::iterator I2 = Stores.begin(), E2 = Stores.end();
|
|
|
|
I2 != E2; ++I2) {
|
2015-06-04 04:03:15 +02:00
|
|
|
switch (AA.alias(MemoryLocation::get(cast<LoadInst>(*I1)),
|
|
|
|
MemoryLocation::get(cast<StoreInst>(*I2)))) {
|
2015-06-22 04:16:51 +02:00
|
|
|
case NoAlias:
|
2013-03-22 23:34:41 +01:00
|
|
|
PrintLoadStoreResults("NoAlias", PrintNoAlias, *I1, *I2,
|
|
|
|
F.getParent());
|
2015-06-17 09:21:41 +02:00
|
|
|
++NoAliasCount;
|
|
|
|
break;
|
2015-06-22 04:16:51 +02:00
|
|
|
case MayAlias:
|
2013-03-22 23:34:41 +01:00
|
|
|
PrintLoadStoreResults("MayAlias", PrintMayAlias, *I1, *I2,
|
|
|
|
F.getParent());
|
2015-06-17 09:21:41 +02:00
|
|
|
++MayAliasCount;
|
|
|
|
break;
|
2015-06-22 04:16:51 +02:00
|
|
|
case PartialAlias:
|
2013-03-22 23:34:41 +01:00
|
|
|
PrintLoadStoreResults("PartialAlias", PrintPartialAlias, *I1, *I2,
|
|
|
|
F.getParent());
|
2015-06-17 09:21:41 +02:00
|
|
|
++PartialAliasCount;
|
|
|
|
break;
|
2015-06-22 04:16:51 +02:00
|
|
|
case MustAlias:
|
2013-03-22 23:34:41 +01:00
|
|
|
PrintLoadStoreResults("MustAlias", PrintMustAlias, *I1, *I2,
|
|
|
|
F.getParent());
|
2015-06-17 09:21:41 +02:00
|
|
|
++MustAliasCount;
|
|
|
|
break;
|
2013-03-22 23:34:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// iterate over all pairs of store, store
|
|
|
|
for (SetVector<Value *>::iterator I1 = Stores.begin(), E = Stores.end();
|
|
|
|
I1 != E; ++I1) {
|
|
|
|
for (SetVector<Value *>::iterator I2 = Stores.begin(); I2 != I1; ++I2) {
|
2015-06-04 04:03:15 +02:00
|
|
|
switch (AA.alias(MemoryLocation::get(cast<StoreInst>(*I1)),
|
|
|
|
MemoryLocation::get(cast<StoreInst>(*I2)))) {
|
2015-06-22 04:16:51 +02:00
|
|
|
case NoAlias:
|
2013-03-22 23:34:41 +01:00
|
|
|
PrintLoadStoreResults("NoAlias", PrintNoAlias, *I1, *I2,
|
|
|
|
F.getParent());
|
2015-06-17 09:21:41 +02:00
|
|
|
++NoAliasCount;
|
|
|
|
break;
|
2015-06-22 04:16:51 +02:00
|
|
|
case MayAlias:
|
2013-03-22 23:34:41 +01:00
|
|
|
PrintLoadStoreResults("MayAlias", PrintMayAlias, *I1, *I2,
|
|
|
|
F.getParent());
|
2015-06-17 09:21:41 +02:00
|
|
|
++MayAliasCount;
|
|
|
|
break;
|
2015-06-22 04:16:51 +02:00
|
|
|
case PartialAlias:
|
2013-03-22 23:34:41 +01:00
|
|
|
PrintLoadStoreResults("PartialAlias", PrintPartialAlias, *I1, *I2,
|
|
|
|
F.getParent());
|
2015-06-17 09:21:41 +02:00
|
|
|
++PartialAliasCount;
|
|
|
|
break;
|
2015-06-22 04:16:51 +02:00
|
|
|
case MustAlias:
|
2013-03-22 23:34:41 +01:00
|
|
|
PrintLoadStoreResults("MustAlias", PrintMustAlias, *I1, *I2,
|
|
|
|
F.getParent());
|
2015-06-17 09:21:41 +02:00
|
|
|
++MustAliasCount;
|
|
|
|
break;
|
2013-03-22 23:34:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-12 07:15:08 +01:00
|
|
|
// Mod/ref alias analysis: compare all pairs of calls and values
|
2015-11-18 07:52:18 +01:00
|
|
|
for (auto C = CallSites.begin(), Ce = CallSites.end(); C != Ce; ++C) {
|
2005-03-26 23:16:44 +01:00
|
|
|
Instruction *I = C->getInstruction();
|
2005-04-21 23:13:18 +02:00
|
|
|
|
2009-08-26 16:32:17 +02:00
|
|
|
for (SetVector<Value *>::iterator V = Pointers.begin(), Ve = Pointers.end();
|
2005-03-26 23:16:44 +01:00
|
|
|
V != Ve; ++V) {
|
2015-06-17 09:21:38 +02:00
|
|
|
uint64_t Size = MemoryLocation::UnknownSize;
|
2011-07-18 06:54:35 +02:00
|
|
|
Type *ElTy = cast<PointerType>((*V)->getType())->getElementType();
|
2015-08-06 04:05:46 +02:00
|
|
|
if (ElTy->isSized()) Size = DL.getTypeStoreSize(ElTy);
|
2005-04-21 23:13:18 +02:00
|
|
|
|
2010-07-07 16:27:09 +02:00
|
|
|
switch (AA.getModRefInfo(*C, *V, Size)) {
|
2015-07-23 01:15:57 +02:00
|
|
|
case MRI_NoModRef:
|
2010-07-07 16:27:09 +02:00
|
|
|
PrintModRefResults("NoModRef", PrintNoModRef, I, *V, F.getParent());
|
2015-06-17 09:21:41 +02:00
|
|
|
++NoModRefCount;
|
|
|
|
break;
|
2015-07-23 01:15:57 +02:00
|
|
|
case MRI_Mod:
|
2010-08-05 01:37:55 +02:00
|
|
|
PrintModRefResults("Just Mod", PrintMod, I, *V, F.getParent());
|
2015-06-17 09:21:41 +02:00
|
|
|
++ModCount;
|
|
|
|
break;
|
2015-07-23 01:15:57 +02:00
|
|
|
case MRI_Ref:
|
2010-08-05 01:37:55 +02:00
|
|
|
PrintModRefResults("Just Ref", PrintRef, I, *V, F.getParent());
|
2015-06-17 09:21:41 +02:00
|
|
|
++RefCount;
|
|
|
|
break;
|
2015-07-23 01:15:57 +02:00
|
|
|
case MRI_ModRef:
|
2010-08-05 01:37:55 +02:00
|
|
|
PrintModRefResults("Both ModRef", PrintModRef, I, *V, F.getParent());
|
2015-06-17 09:21:41 +02:00
|
|
|
++ModRefCount;
|
|
|
|
break;
|
2004-03-12 07:15:08 +01:00
|
|
|
}
|
2004-11-26 22:05:39 +01:00
|
|
|
}
|
2004-07-17 09:40:34 +02:00
|
|
|
}
|
2005-04-21 23:13:18 +02:00
|
|
|
|
2010-08-05 00:56:29 +02:00
|
|
|
// Mod/ref alias analysis: compare all pairs of calls
|
2015-11-18 07:52:18 +01:00
|
|
|
for (auto C = CallSites.begin(), Ce = CallSites.end(); C != Ce; ++C) {
|
|
|
|
for (auto D = CallSites.begin(); D != Ce; ++D) {
|
2010-08-05 00:56:29 +02:00
|
|
|
if (D == C)
|
|
|
|
continue;
|
|
|
|
switch (AA.getModRefInfo(*C, *D)) {
|
2015-07-23 01:15:57 +02:00
|
|
|
case MRI_NoModRef:
|
2010-08-05 00:56:29 +02:00
|
|
|
PrintModRefResults("NoModRef", PrintNoModRef, *C, *D, F.getParent());
|
2015-06-17 09:21:41 +02:00
|
|
|
++NoModRefCount;
|
|
|
|
break;
|
2015-07-23 01:15:57 +02:00
|
|
|
case MRI_Mod:
|
2010-08-05 01:37:55 +02:00
|
|
|
PrintModRefResults("Just Mod", PrintMod, *C, *D, F.getParent());
|
2015-06-17 09:21:41 +02:00
|
|
|
++ModCount;
|
|
|
|
break;
|
2015-07-23 01:15:57 +02:00
|
|
|
case MRI_Ref:
|
2010-08-05 01:37:55 +02:00
|
|
|
PrintModRefResults("Just Ref", PrintRef, *C, *D, F.getParent());
|
2015-06-17 09:21:41 +02:00
|
|
|
++RefCount;
|
|
|
|
break;
|
2015-07-23 01:15:57 +02:00
|
|
|
case MRI_ModRef:
|
2010-08-05 01:37:55 +02:00
|
|
|
PrintModRefResults("Both ModRef", PrintModRef, *C, *D, F.getParent());
|
2015-06-17 09:21:41 +02:00
|
|
|
++ModRefCount;
|
|
|
|
break;
|
2010-08-05 00:56:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-02-06 22:29:49 +01:00
|
|
|
}
|
|
|
|
|
2016-02-20 04:46:03 +01:00
|
|
|
static void PrintPercent(int64_t Num, int64_t Sum) {
|
|
|
|
errs() << "(" << Num * 100LL / Sum << "." << ((Num * 1000LL / Sum) % 10)
|
|
|
|
<< "%)\n";
|
2005-03-27 00:56:33 +01:00
|
|
|
}
|
|
|
|
|
2016-02-20 04:46:03 +01:00
|
|
|
AAEvaluator::~AAEvaluator() {
|
|
|
|
if (FunctionCount == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int64_t AliasSum =
|
2015-06-17 09:21:41 +02:00
|
|
|
NoAliasCount + MayAliasCount + PartialAliasCount + MustAliasCount;
|
2009-12-23 23:49:57 +01:00
|
|
|
errs() << "===== Alias Analysis Evaluator Report =====\n";
|
2004-03-12 07:15:08 +01:00
|
|
|
if (AliasSum == 0) {
|
2009-12-23 23:49:57 +01:00
|
|
|
errs() << " Alias Analysis Evaluator Summary: No pointers!\n";
|
2005-04-21 23:13:18 +02:00
|
|
|
} else {
|
2009-12-23 23:49:57 +01:00
|
|
|
errs() << " " << AliasSum << " Total Alias Queries Performed\n";
|
2015-06-17 09:21:41 +02:00
|
|
|
errs() << " " << NoAliasCount << " no alias responses ";
|
|
|
|
PrintPercent(NoAliasCount, AliasSum);
|
|
|
|
errs() << " " << MayAliasCount << " may alias responses ";
|
|
|
|
PrintPercent(MayAliasCount, AliasSum);
|
|
|
|
errs() << " " << PartialAliasCount << " partial alias responses ";
|
|
|
|
PrintPercent(PartialAliasCount, AliasSum);
|
|
|
|
errs() << " " << MustAliasCount << " must alias responses ";
|
|
|
|
PrintPercent(MustAliasCount, AliasSum);
|
2009-12-23 23:49:57 +01:00
|
|
|
errs() << " Alias Analysis Evaluator Pointer Alias Summary: "
|
2015-06-17 09:21:41 +02:00
|
|
|
<< NoAliasCount * 100 / AliasSum << "%/"
|
|
|
|
<< MayAliasCount * 100 / AliasSum << "%/"
|
|
|
|
<< PartialAliasCount * 100 / AliasSum << "%/"
|
|
|
|
<< MustAliasCount * 100 / AliasSum << "%\n";
|
2004-03-12 07:15:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Display the summary for mod/ref analysis
|
2016-02-20 04:46:03 +01:00
|
|
|
int64_t ModRefSum = NoModRefCount + ModCount + RefCount + ModRefCount;
|
2004-03-12 07:15:08 +01:00
|
|
|
if (ModRefSum == 0) {
|
2015-06-17 09:21:41 +02:00
|
|
|
errs() << " Alias Analysis Mod/Ref Evaluator Summary: no "
|
|
|
|
"mod/ref!\n";
|
2004-03-12 07:15:08 +01:00
|
|
|
} else {
|
2009-12-23 23:49:57 +01:00
|
|
|
errs() << " " << ModRefSum << " Total ModRef Queries Performed\n";
|
2015-06-17 09:21:41 +02:00
|
|
|
errs() << " " << NoModRefCount << " no mod/ref responses ";
|
|
|
|
PrintPercent(NoModRefCount, ModRefSum);
|
|
|
|
errs() << " " << ModCount << " mod responses ";
|
|
|
|
PrintPercent(ModCount, ModRefSum);
|
|
|
|
errs() << " " << RefCount << " ref responses ";
|
|
|
|
PrintPercent(RefCount, ModRefSum);
|
|
|
|
errs() << " " << ModRefCount << " mod & ref responses ";
|
|
|
|
PrintPercent(ModRefCount, ModRefSum);
|
2009-12-23 23:49:57 +01:00
|
|
|
errs() << " Alias Analysis Evaluator Mod/Ref Summary: "
|
2015-06-17 09:21:41 +02:00
|
|
|
<< NoModRefCount * 100 / ModRefSum << "%/"
|
|
|
|
<< ModCount * 100 / ModRefSum << "%/" << RefCount * 100 / ModRefSum
|
|
|
|
<< "%/" << ModRefCount * 100 / ModRefSum << "%\n";
|
2003-02-09 00:04:50 +01:00
|
|
|
}
|
2016-02-20 04:46:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class AAEvalLegacyPass : public FunctionPass {
|
|
|
|
std::unique_ptr<AAEvaluator> P;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static char ID; // Pass identification, replacement for typeid
|
|
|
|
AAEvalLegacyPass() : FunctionPass(ID) {
|
|
|
|
initializeAAEvalLegacyPassPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
2010-07-07 16:27:09 +02:00
|
|
|
|
2016-02-20 04:46:03 +01:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
|
|
AU.addRequired<AAResultsWrapperPass>();
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool doInitialization(Module &M) override {
|
|
|
|
P.reset(new AAEvaluator());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool runOnFunction(Function &F) override {
|
|
|
|
P->runInternal(F, getAnalysis<AAResultsWrapperPass>().getAAResults());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool doFinalization(Module &M) override {
|
|
|
|
P.reset();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2003-02-06 22:29:49 +01:00
|
|
|
}
|
2016-02-20 04:46:03 +01:00
|
|
|
|
|
|
|
char AAEvalLegacyPass::ID = 0;
|
|
|
|
INITIALIZE_PASS_BEGIN(AAEvalLegacyPass, "aa-eval",
|
|
|
|
"Exhaustive Alias Analysis Precision Evaluator", false,
|
|
|
|
true)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
|
|
|
|
INITIALIZE_PASS_END(AAEvalLegacyPass, "aa-eval",
|
|
|
|
"Exhaustive Alias Analysis Precision Evaluator", false,
|
|
|
|
true)
|
|
|
|
|
|
|
|
FunctionPass *llvm::createAAEvalPass() { return new AAEvalLegacyPass(); }
|