1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
//===- ProvenanceAnalysisEvaluator.cpp - ObjC ARC Optimization ------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "ProvenanceAnalysis.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/Passes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Module.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
using namespace llvm::objcarc;
namespace {
class PAEval : public FunctionPass {
public:
static char ID;
PAEval();
void getAnalysisUsage(AnalysisUsage &AU) const override;
bool runOnFunction(Function &F) override;
};
}
char PAEval::ID = 0;
PAEval::PAEval() : FunctionPass(ID) {}
void PAEval::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<AAResultsWrapperPass>();
}
static StringRef getName(Value *V) {
StringRef Name = V->getName();
if (Name.startswith("\1"))
return Name.substr(1);
return Name;
}
static void insertIfNamed(SetVector<Value *> &Values, Value *V) {
if (!V->hasName())
return;
Values.insert(V);
}
bool PAEval::runOnFunction(Function &F) {
SetVector<Value *> Values;
for (auto &Arg : F.args())
insertIfNamed(Values, &Arg);
for (Instruction &I : instructions(F)) {
insertIfNamed(Values, &I);
for (auto &Op : I.operands())
insertIfNamed(Values, Op);
}
ProvenanceAnalysis PA;
PA.setAA(&getAnalysis<AAResultsWrapperPass>().getAAResults());
for (Value *V1 : Values) {
StringRef NameV1 = getName(V1);
for (Value *V2 : Values) {
StringRef NameV2 = getName(V2);
if (NameV1 >= NameV2)
continue;
errs() << NameV1 << " and " << NameV2;
if (PA.related(V1, V2))
errs() << " are related.\n";
else
errs() << " are not related.\n";
}
}
return false;
}
FunctionPass *llvm::createPAEvalPass() { return new PAEval(); }
INITIALIZE_PASS_BEGIN(PAEval, "pa-eval",
"Evaluate ProvenanceAnalysis on all pairs", false, true)
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
INITIALIZE_PASS_END(PAEval, "pa-eval",
"Evaluate ProvenanceAnalysis on all pairs", false, true)
|