LLVM  3.7.0
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/Pass.h"
12 #include "llvm/ADT/SetVector.h"
14 #include "llvm/Analysis/Passes.h"
15 #include "llvm/IR/InstIterator.h"
16 #include "llvm/IR/Function.h"
17 #include "llvm/IR/Module.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 
54 bool PAEval::runOnFunction(Function &F) {
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<AliasAnalysis>());
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:104
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
bool hasName() const
Definition: Value.h:228
StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:405
F(f)
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:188
AnalysisUsage & addRequired()
inst_iterator inst_begin(Function *F)
Definition: InstIterator.h:127
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:75
static StringRef getName(Value *V)
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:102
#define true
Definition: ConvertUTF.c:66
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:294
#define INITIALIZE_AG_DEPENDENCY(depName)
Definition: PassSupport.h:72
bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:215
This file declares a special form of Alias Analysis called ``Provenance Analysis''.
Module.h This file contains the declarations for the Module class.
static void insertIfNamed(SetVector< Value * > &Values, Value *V)
FunctionPass * createPAEvalPass()
bool related(const Value *A, const Value *B, const DataLayout &DL)
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.cpp:372
pa Evaluate ProvenanceAnalysis on all pairs
#define I(x, y, z)
Definition: MD5.cpp:54
pa Evaluate ProvenanceAnalysis on all false
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:365
LLVM Value Representation.
Definition: Value.h:69
A vector that has set insertion semantics.
Definition: SetVector.h:37
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:40
inst_iterator inst_end(Function *F)
Definition: InstIterator.h:128
INITIALIZE_PASS_BEGIN(PAEval,"pa-eval","Evaluate ProvenanceAnalysis on all pairs", false, true) INITIALIZE_PASS_END(PAEval
iterator_range< arg_iterator > args()
Definition: Function.h:489