Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysisEvaluator.cpp
Line
Count
Source (jump to first uncovered line)
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"
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/Module.h"
16
#include "llvm/Pass.h"
17
#include "llvm/Support/raw_ostream.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
1
PAEval::PAEval() : FunctionPass(ID) {}
35
36
1
void PAEval::getAnalysisUsage(AnalysisUsage &AU) const {
37
1
  AU.addRequired<AAResultsWrapperPass>();
38
1
}
39
40
380
static StringRef getName(Value *V) {
41
380
  StringRef Name = V->getName();
42
380
  if (Name.startswith("\1"))
43
20
    return Name.substr(1);
44
360
  return Name;
45
360
}
46
47
43
static void insertIfNamed(SetVector<Value *> &Values, Value *V) {
48
43
  if (!V->hasName())
49
8
    return;
50
35
  Values.insert(V);
51
35
}
52
53
1
bool PAEval::runOnFunction(Function &F) {
54
1
  SetVector<Value *> Values;
55
1
56
1
  for (auto &Arg : F.args())
57
3
    insertIfNamed(Values, &Arg);
58
1
59
18
  for (auto I = inst_begin(F), E = inst_end(F); I != E; 
++I17
) {
60
17
    insertIfNamed(Values, &*I);
61
17
62
17
    for (auto &Op : I->operands())
63
23
    insertIfNamed(Values, Op);
64
17
  }
65
1
66
1
  ProvenanceAnalysis PA;
67
1
  PA.setAA(&getAnalysis<AAResultsWrapperPass>().getAAResults());
68
1
  const DataLayout &DL = F.getParent()->getDataLayout();
69
1
70
19
  for (Value *V1 : Values) {
71
19
    StringRef NameV1 = getName(V1);
72
361
    for (Value *V2 : Values) {
73
361
      StringRef NameV2 = getName(V2);
74
361
      if (NameV1 >= NameV2)
75
190
        continue;
76
171
      errs() << NameV1 << " and " << NameV2;
77
171
      if (PA.related(V1, V2, DL))
78
3
        errs() << " are related.\n";
79
168
      else
80
168
        errs() << " are not related.\n";
81
171
    }
82
19
  }
83
1
84
1
  return false;
85
1
}
86
87
0
FunctionPass *llvm::createPAEvalPass() { return new PAEval(); }
88
89
11.0k
INITIALIZE_PASS_BEGIN(PAEval, "pa-eval",
90
11.0k
                      "Evaluate ProvenanceAnalysis on all pairs", false, true)
91
11.0k
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
92
11.0k
INITIALIZE_PASS_END(PAEval, "pa-eval",
93
                    "Evaluate ProvenanceAnalysis on all pairs", false, true)