[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / llvm / lib / Transforms / ObjCARC / ProvenanceAnalysisEvaluator.cpp
blob6fdfe787d438689c5978ad41aba0d7f4332bb79e
1 //===- ProvenanceAnalysisEvaluator.cpp - ObjC ARC Optimization ------------===//
2 //
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
6 //
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/InstrTypes.h"
16 #include "llvm/IR/Module.h"
17 #include "llvm/InitializePasses.h"
18 #include "llvm/Pass.h"
19 #include "llvm/Support/raw_ostream.h"
21 using namespace llvm;
22 using namespace llvm::objcarc;
24 namespace {
25 class PAEval : public FunctionPass {
27 public:
28 static char ID;
29 PAEval();
30 void getAnalysisUsage(AnalysisUsage &AU) const override;
31 bool runOnFunction(Function &F) override;
35 char PAEval::ID = 0;
36 PAEval::PAEval() : FunctionPass(ID) {}
38 void PAEval::getAnalysisUsage(AnalysisUsage &AU) const {
39 AU.addRequired<AAResultsWrapperPass>();
42 static StringRef getName(Value *V) {
43 StringRef Name = V->getName();
44 if (Name.startswith("\1"))
45 return Name.substr(1);
46 return Name;
49 static void insertIfNamed(SetVector<Value *> &Values, Value *V) {
50 if (!V->hasName())
51 return;
52 Values.insert(V);
55 bool PAEval::runOnFunction(Function &F) {
56 SetVector<Value *> Values;
58 for (auto &Arg : F.args())
59 insertIfNamed(Values, &Arg);
61 for (auto I = inst_begin(F), E = inst_end(F); I != E; ++I) {
62 insertIfNamed(Values, &*I);
64 for (auto &Op : I->operands())
65 insertIfNamed(Values, Op);
68 ProvenanceAnalysis PA;
69 PA.setAA(&getAnalysis<AAResultsWrapperPass>().getAAResults());
71 for (Value *V1 : Values) {
72 StringRef NameV1 = getName(V1);
73 for (Value *V2 : Values) {
74 StringRef NameV2 = getName(V2);
75 if (NameV1 >= NameV2)
76 continue;
77 errs() << NameV1 << " and " << NameV2;
78 if (PA.related(V1, V2))
79 errs() << " are related.\n";
80 else
81 errs() << " are not related.\n";
85 return false;
88 FunctionPass *llvm::createPAEvalPass() { return new PAEval(); }
90 INITIALIZE_PASS_BEGIN(PAEval, "pa-eval",
91 "Evaluate ProvenanceAnalysis on all pairs", false, true)
92 INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
93 INITIALIZE_PASS_END(PAEval, "pa-eval",
94 "Evaluate ProvenanceAnalysis on all pairs", false, true)