LLVM  8.0.1
ProvenanceAnalysisEvaluator.cpp
Go to the documentation of this file.
1 //===- ProvenanceAnalysisEvaluator.cpp - ObjC ARC Optimization ------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "ProvenanceAnalysis.h"
11 #include "llvm/ADT/SetVector.h"
13 #include "llvm/Analysis/Passes.h"
14 #include "llvm/IR/Function.h"
15 #include "llvm/IR/InstIterator.h"
16 #include "llvm/IR/Module.h"
17 #include "llvm/Pass.h"
19 
20 using namespace llvm;
21 using namespace llvm::objcarc;
22 
23 namespace {
24 class PAEval : public FunctionPass {
25 
26 public:
27  static char ID;
28  PAEval();
29  void getAnalysisUsage(AnalysisUsage &AU) const override;
30  bool runOnFunction(Function &F) override;
31 };
32 }
33 
34 char PAEval::ID = 0;
35 PAEval::PAEval() : FunctionPass(ID) {}
36 
37 void PAEval::getAnalysisUsage(AnalysisUsage &AU) const {
39 }
40 
41 static StringRef getName(Value *V) {
42  StringRef Name = V->getName();
43  if (Name.startswith("\1"))
44  return Name.substr(1);
45  return Name;
46 }
47 
48 static void insertIfNamed(SetVector<Value *> &Values, Value *V) {
49  if (!V->hasName())
50  return;
51  Values.insert(V);
52 }
53 
55  SetVector<Value *> Values;
56 
57  for (auto &Arg : F.args())
58  insertIfNamed(Values, &Arg);
59 
60  for (auto I = inst_begin(F), E = inst_end(F); I != E; ++I) {
61  insertIfNamed(Values, &*I);
62 
63  for (auto &Op : I->operands())
64  insertIfNamed(Values, Op);
65  }
66 
68  PA.setAA(&getAnalysis<AAResultsWrapperPass>().getAAResults());
69  const DataLayout &DL = F.getParent()->getDataLayout();
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, DL))
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)
94  "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:111
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
This class represents lattice values for constants.
Definition: AllocatorList.h:24
F(f)
block Block Frequency true
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:51
amdgpu Simplify well known AMD library false Value Value const Twine & Name
inst_iterator inst_begin(Function *F)
Definition: InstIterator.h:132
const DataLayout & getDataLayout() const
Get the data layout for the module&#39;s target platform.
Definition: Module.cpp:371
INITIALIZE_PASS_BEGIN(PAEval, "pa-eval", "Evaluate ProvenanceAnalysis on all pairs", false, true) INITIALIZE_PASS_END(PAEval
static StringRef getName(Value *V)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:267
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:142
Predicate all(Predicate P0, Predicate P1)
True iff P0 and P1 are true.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:598
static bool runOnFunction(Function &F, bool PostInlining)
bool hasName() const
Definition: Value.h:251
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:285
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)
amdgpu Simplify well known AMD library false Value Value * Arg
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:566
LLVM Value Representation.
Definition: Value.h:73
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:49
inst_iterator inst_end(Function *F)
Definition: InstIterator.h:133
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
iterator_range< arg_iterator > args()
Definition: Function.h:689