LLVM  9.0.0svn
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/Module.h"
16 #include "llvm/Pass.h"
18 
19 using namespace llvm;
20 using namespace llvm::objcarc;
21 
22 namespace {
23 class PAEval : public FunctionPass {
24 
25 public:
26  static char ID;
27  PAEval();
28  void getAnalysisUsage(AnalysisUsage &AU) const override;
29  bool runOnFunction(Function &F) override;
30 };
31 }
32 
33 char PAEval::ID = 0;
34 PAEval::PAEval() : FunctionPass(ID) {}
35 
36 void PAEval::getAnalysisUsage(AnalysisUsage &AU) const {
38 }
39 
40 static StringRef getName(Value *V) {
41  StringRef Name = V->getName();
42  if (Name.startswith("\1"))
43  return Name.substr(1);
44  return Name;
45 }
46 
47 static void insertIfNamed(SetVector<Value *> &Values, Value *V) {
48  if (!V->hasName())
49  return;
50  Values.insert(V);
51 }
52 
54  SetVector<Value *> Values;
55 
56  for (auto &Arg : F.args())
57  insertIfNamed(Values, &Arg);
58 
59  for (auto I = inst_begin(F), E = inst_end(F); I != E; ++I) {
60  insertIfNamed(Values, &*I);
61 
62  for (auto &Op : I->operands())
63  insertIfNamed(Values, Op);
64  }
65 
67  PA.setAA(&getAnalysis<AAResultsWrapperPass>().getAAResults());
68  const DataLayout &DL = F.getParent()->getDataLayout();
69 
70  for (Value *V1 : Values) {
71  StringRef NameV1 = getName(V1);
72  for (Value *V2 : Values) {
73  StringRef NameV2 = getName(V2);
74  if (NameV1 >= NameV2)
75  continue;
76  errs() << NameV1 << " and " << NameV2;
77  if (PA.related(V1, V2, DL))
78  errs() << " are related.\n";
79  else
80  errs() << " are not related.\n";
81  }
82  }
83 
84  return false;
85 }
86 
87 FunctionPass *llvm::createPAEvalPass() { return new PAEval(); }
88 
89 INITIALIZE_PASS_BEGIN(PAEval, "pa-eval",
90  "Evaluate ProvenanceAnalysis on all pairs", false, true)
93  "Evaluate ProvenanceAnalysis on all pairs", false, true)
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:110
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:256
F(f)
block Block Frequency true
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:50
inst_iterator inst_begin(Function *F)
Definition: InstIterator.h:131
const DataLayout & getDataLayout() const
Get the data layout for the module&#39;s target platform.
Definition: Module.cpp:369
INITIALIZE_PASS_BEGIN(PAEval, "pa-eval", "Evaluate ProvenanceAnalysis on all pairs", false, true) INITIALIZE_PASS_END(PAEval
static StringRef getName(Value *V)
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:578
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:141
Predicate all(Predicate P0, Predicate P1)
True iff P0 and P1 are true.
static bool runOnFunction(Function &F, bool PostInlining)
bool hasName() const
Definition: Value.h:250
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:284
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
This file declares a special form of Alias Analysis called ``Provenance Analysis&#39;&#39;.
Module.h This file contains the declarations for the Module class.
FunctionPass * createPAEvalPass()
bool related(const Value *A, const Value *B, const DataLayout &DL)
pa Evaluate ProvenanceAnalysis on all pairs
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:214
#define I(x, y, z)
Definition: MD5.cpp:58
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:575
LLVM Value Representation.
Definition: Value.h:72
static void insertIfNamed(SetVector< Value *> &Values, Value *V)
This is similar to BasicAliasAnalysis, and it uses many of the same techniques, except it uses specia...
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
inst_iterator inst_end(Function *F)
Definition: InstIterator.h:132
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
iterator_range< arg_iterator > args()
Definition: Function.h:705