1 //===- ProvenanceAnalysisEvaluator.cpp - ObjC ARC Optimization ------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "ProvenanceAnalysis.h"
10 #include "llvm/ADT/SetVector.h"
11 #include "llvm/Analysis/AliasAnalysis.h"
12 #include "llvm/Analysis/Passes.h"
13 #include "llvm/IR/Function.h"
14 #include "llvm/IR/InstIterator.h"
15 #include "llvm/IR/Module.h"
16 #include "llvm/Pass.h"
17 #include "llvm/Support/raw_ostream.h"
20 using namespace llvm::objcarc
;
23 class PAEval
: public FunctionPass
{
28 void getAnalysisUsage(AnalysisUsage
&AU
) const override
;
29 bool runOnFunction(Function
&F
) override
;
34 PAEval::PAEval() : FunctionPass(ID
) {}
36 void PAEval::getAnalysisUsage(AnalysisUsage
&AU
) const {
37 AU
.addRequired
<AAResultsWrapperPass
>();
40 static StringRef
getName(Value
*V
) {
41 StringRef Name
= V
->getName();
42 if (Name
.startswith("\1"))
43 return Name
.substr(1);
47 static void insertIfNamed(SetVector
<Value
*> &Values
, Value
*V
) {
53 bool PAEval::runOnFunction(Function
&F
) {
54 SetVector
<Value
*> Values
;
56 for (auto &Arg
: F
.args())
57 insertIfNamed(Values
, &Arg
);
59 for (auto I
= inst_begin(F
), E
= inst_end(F
); I
!= E
; ++I
) {
60 insertIfNamed(Values
, &*I
);
62 for (auto &Op
: I
->operands())
63 insertIfNamed(Values
, Op
);
66 ProvenanceAnalysis PA
;
67 PA
.setAA(&getAnalysis
<AAResultsWrapperPass
>().getAAResults());
68 const DataLayout
&DL
= F
.getParent()->getDataLayout();
70 for (Value
*V1
: Values
) {
71 StringRef NameV1
= getName(V1
);
72 for (Value
*V2
: Values
) {
73 StringRef NameV2
= getName(V2
);
76 errs() << NameV1
<< " and " << NameV2
;
77 if (PA
.related(V1
, V2
, DL
))
78 errs() << " are related.\n";
80 errs() << " are not related.\n";
87 FunctionPass
*llvm::createPAEvalPass() { return new PAEval(); }
89 INITIALIZE_PASS_BEGIN(PAEval
, "pa-eval",
90 "Evaluate ProvenanceAnalysis on all pairs", false, true)
91 INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass
)
92 INITIALIZE_PASS_END(PAEval
, "pa-eval",
93 "Evaluate ProvenanceAnalysis on all pairs", false, true)