LLVM  13.0.0git
ProvenanceAnalysisEvaluator.cpp
Go to the documentation of this file.
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 //===----------------------------------------------------------------------===//
8 
9 #include "ProvenanceAnalysis.h"
10 #include "llvm/ADT/SetVector.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"
20 
21 using namespace llvm;
22 using namespace llvm::objcarc;
23 
24 namespace {
25 class PAEval : public FunctionPass {
26 
27 public:
28  static char ID;
29  PAEval();
30  void getAnalysisUsage(AnalysisUsage &AU) const override;
31  bool runOnFunction(Function &F) override;
32 };
33 }
34 
35 char PAEval::ID = 0;
36 PAEval::PAEval() : FunctionPass(ID) {}
37 
38 void PAEval::getAnalysisUsage(AnalysisUsage &AU) const {
40 }
41 
42 static StringRef getName(Value *V) {
43  StringRef Name = V->getName();
44  if (Name.startswith("\1"))
45  return Name.substr(1);
46  return Name;
47 }
48 
49 static void insertIfNamed(SetVector<Value *> &Values, Value *V) {
50  if (!V->hasName())
51  return;
52  Values.insert(V);
53 }
54 
56  SetVector<Value *> Values;
57 
58  for (auto &Arg : F.args())
59  insertIfNamed(Values, &Arg);
60 
61  for (auto I = inst_begin(F), E = inst_end(F); I != E; ++I) {
62  insertIfNamed(Values, &*I);
63 
64  for (auto &Op : I->operands())
65  insertIfNamed(Values, Op);
66  }
67 
69  PA.setAA(&getAnalysis<AAResultsWrapperPass>().getAAResults());
70 
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";
82  }
83  }
84 
85  return false;
86 }
87 
88 FunctionPass *llvm::createPAEvalPass() { return new PAEval(); }
89 
90 INITIALIZE_PASS_BEGIN(PAEval, "pa-eval",
91  "Evaluate ProvenanceAnalysis on all pairs", false, true)
getName
static StringRef getName(Value *V)
Definition: ProvenanceAnalysisEvaluator.cpp:42
llvm
Definition: AllocatorList.h:23
InstIterator.h
llvm::Function
Definition: Function.h:61
Pass.h
llvm::Value::hasName
bool hasName() const
Definition: Value.h:262
Module.h
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:892
llvm::objcarc::ProvenanceAnalysis
This is similar to BasicAliasAnalysis, and it uses many of the same techniques, except it uses specia...
Definition: ProvenanceAnalysis.h:51
F
#define F(x, y, z)
Definition: MD5.cpp:56
AliasAnalysis.h
llvm::createPAEvalPass
FunctionPass * createPAEvalPass()
Definition: ProvenanceAnalysisEvaluator.cpp:88
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:205
INITIALIZE_PASS_BEGIN
INITIALIZE_PASS_BEGIN(PAEval, "pa-eval", "Evaluate ProvenanceAnalysis on all pairs", false, true) INITIALIZE_PASS_END(PAEval
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
InstrTypes.h
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
false
Definition: StackSlotColoring.cpp:142
llvm::objcarc::ProvenanceAnalysis::setAA
void setAA(AAResults *aa)
Definition: ProvenanceAnalysis.h:70
INITIALIZE_PASS_END
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:58
ProvenanceAnalysis.h
insertIfNamed
static void insertIfNamed(SetVector< Value * > &Values, Value *V)
Definition: ProvenanceAnalysisEvaluator.cpp:49
INITIALIZE_PASS_DEPENDENCY
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
llvm::LegalityPredicates::all
Predicate all(Predicate P0, Predicate P1)
True iff P0 and P1 are true.
Definition: LegalizerInfo.h:196
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::objcarc
Definition: ObjCARCAliasAnalysis.h:29
pairs
pa Evaluate ProvenanceAnalysis on all pairs
Definition: ProvenanceAnalysisEvaluator.cpp:94
eval
pa eval
Definition: ProvenanceAnalysisEvaluator.cpp:93
llvm::SetVector::insert
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:141
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::Value::getName
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:299
runOnFunction
static bool runOnFunction(Function &F, bool PostInlining)
Definition: EntryExitInstrumenter.cpp:69
llvm::NVPTX::PTXLdStInstCode::V2
@ V2
Definition: NVPTX.h:123
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:314
Function.h
llvm::inst_end
inst_iterator inst_end(Function *F)
Definition: InstIterator.h:132
llvm::AAResultsWrapperPass
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.
Definition: AliasAnalysis.h:1269
llvm::FunctionPass
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
llvm::inst_begin
inst_iterator inst_begin(Function *F)
Definition: InstIterator.h:131
llvm::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition: PassAnalysisSupport.h:75
raw_ostream.h
llvm::objcarc::ProvenanceAnalysis::related
bool related(const Value *A, const Value *B)
Definition: ProvenanceAnalysis.cpp:159
llvm::SetVector< Value * >
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1789
InitializePasses.h
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
SetVector.h
Passes.h
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38