Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/AMDGPU/AMDGPUAliasAnalysis.h
Line
Count
Source (jump to first uncovered line)
1
//===- AMDGPUAliasAnalysis --------------------------------------*- C++ -*-===//
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
/// \file
9
/// This is the AMGPU address space based alias analysis pass.
10
//===----------------------------------------------------------------------===//
11
12
#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUALIASANALYSIS_H
13
#define LLVM_LIB_TARGET_AMDGPU_AMDGPUALIASANALYSIS_H
14
15
#include "AMDGPU.h"
16
#include "llvm/ADT/Triple.h"
17
#include "llvm/Analysis/AliasAnalysis.h"
18
#include "llvm/IR/Function.h"
19
#include "llvm/IR/Module.h"
20
#include "llvm/Pass.h"
21
#include <algorithm>
22
#include <memory>
23
24
namespace llvm {
25
26
class DataLayout;
27
class MDNode;
28
class MemoryLocation;
29
30
/// A simple AA result that uses TBAA metadata to answer queries.
31
class AMDGPUAAResult : public AAResultBase<AMDGPUAAResult> {
32
  friend AAResultBase<AMDGPUAAResult>;
33
34
  const DataLayout &DL;
35
36
public:
37
  explicit AMDGPUAAResult(const DataLayout &DL, Triple T) : AAResultBase(),
38
2.82k
    DL(DL) {}
39
  AMDGPUAAResult(AMDGPUAAResult &&Arg)
40
0
      : AAResultBase(std::move(Arg)), DL(Arg.DL) {}
41
42
  /// Handle invalidation events from the new pass manager.
43
  ///
44
  /// By definition, this result is stateless and so remains valid.
45
0
  bool invalidate(Function &, const PreservedAnalyses &) { return false; }
46
47
  AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
48
                    AAQueryInfo &AAQI);
49
  bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI,
50
                              bool OrLocal);
51
52
private:
53
  bool Aliases(const MDNode *A, const MDNode *B) const;
54
  bool PathAliases(const MDNode *A, const MDNode *B) const;
55
};
56
57
/// Analysis pass providing a never-invalidated alias analysis result.
58
class AMDGPUAA : public AnalysisInfoMixin<AMDGPUAA> {
59
  friend AnalysisInfoMixin<AMDGPUAA>;
60
61
  static char PassID;
62
63
public:
64
  using Result = AMDGPUAAResult;
65
66
0
  AMDGPUAAResult run(Function &F, AnalysisManager<Function> &AM) {
67
0
    return AMDGPUAAResult(F.getParent()->getDataLayout(),
68
0
        Triple(F.getParent()->getTargetTriple()));
69
0
  }
70
};
71
72
/// Legacy wrapper pass to provide the AMDGPUAAResult object.
73
class AMDGPUAAWrapperPass : public ImmutablePass {
74
  std::unique_ptr<AMDGPUAAResult> Result;
75
76
public:
77
  static char ID;
78
79
2.85k
  AMDGPUAAWrapperPass() : ImmutablePass(ID) {
80
2.85k
    initializeAMDGPUAAWrapperPassPass(*PassRegistry::getPassRegistry());
81
2.85k
  }
82
83
198k
  AMDGPUAAResult &getResult() { return *Result; }
84
0
  const AMDGPUAAResult &getResult() const { return *Result; }
85
86
2.82k
  bool doInitialization(Module &M) override {
87
2.82k
    Result.reset(new AMDGPUAAResult(M.getDataLayout(),
88
2.82k
        Triple(M.getTargetTriple())));
89
2.82k
    return false;
90
2.82k
  }
91
92
2.81k
  bool doFinalization(Module &M) override {
93
2.81k
    Result.reset();
94
2.81k
    return false;
95
2.81k
  }
96
97
  void getAnalysisUsage(AnalysisUsage &AU) const override;
98
};
99
100
// Wrapper around ExternalAAWrapperPass so that the default constructor gets the
101
// callback.
102
class AMDGPUExternalAAWrapper : public ExternalAAWrapperPass {
103
public:
104
  static char ID;
105
106
  AMDGPUExternalAAWrapper() : ExternalAAWrapperPass(
107
15.3k
    [](Pass &P, Function &, AAResults &AAR) {
108
15.3k
      if (auto *WrapperPass = P.getAnalysisIfAvailable<AMDGPUAAWrapperPass>())
109
15.3k
        AAR.addAAResult(WrapperPass->getResult());
110
15.3k
    }) 
{}196
111
};
112
113
} // end namespace llvm
114
115
#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUALIASANALYSIS_H