Coverage Report

Created: 2018-07-18 22:01

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Analysis/MemoryLocation.h
Line
Count
Source (jump to first uncovered line)
1
//===- MemoryLocation.h - Memory location descriptions ----------*- C++ -*-===//
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
/// \file
10
/// This file provides utility analysis objects describing memory locations.
11
/// These are used both by the Alias Analysis infrastructure and more
12
/// specialized memory analysis layers.
13
///
14
//===----------------------------------------------------------------------===//
15
16
#ifndef LLVM_ANALYSIS_MEMORYLOCATION_H
17
#define LLVM_ANALYSIS_MEMORYLOCATION_H
18
19
#include "llvm/ADT/Optional.h"
20
#include "llvm/ADT/DenseMapInfo.h"
21
#include "llvm/IR/CallSite.h"
22
#include "llvm/IR/Metadata.h"
23
24
namespace llvm {
25
26
class LoadInst;
27
class StoreInst;
28
class MemTransferInst;
29
class MemIntrinsic;
30
class AtomicMemTransferInst;
31
class AtomicMemIntrinsic;
32
class AnyMemTransferInst;
33
class AnyMemIntrinsic;
34
class TargetLibraryInfo;
35
36
// Represents the size of a MemoryLocation. Logically, it's an
37
// Optional<uint64_t>, with a special UnknownSize value from `MemoryLocation`.
38
using LocationSize = uint64_t;
39
40
/// Representation for a specific memory location.
41
///
42
/// This abstraction can be used to represent a specific location in memory.
43
/// The goal of the location is to represent enough information to describe
44
/// abstract aliasing, modification, and reference behaviors of whatever
45
/// value(s) are stored in memory at the particular location.
46
///
47
/// The primary user of this interface is LLVM's Alias Analysis, but other
48
/// memory analyses such as MemoryDependence can use it as well.
49
0
class MemoryLocation {
Unexecuted instantiation: llvm::MemoryLocation::operator=(llvm::MemoryLocation const&)
Unexecuted instantiation: llvm::MemoryLocation::operator=(llvm::MemoryLocation&&)
50
public:
51
  /// UnknownSize - This is a special value which can be used with the
52
  /// size arguments in alias queries to indicate that the caller does not
53
  /// know the sizes of the potential memory references.
54
  enum : uint64_t { UnknownSize = ~UINT64_C(0) };
55
56
  /// The address of the start of the location.
57
  const Value *Ptr;
58
59
  /// The maximum size of the location, in address-units, or
60
  /// UnknownSize if the size is not known.
61
  ///
62
  /// Note that an unknown size does not mean the pointer aliases the entire
63
  /// virtual address space, because there are restrictions on stepping out of
64
  /// one object and into another. See
65
  /// http://llvm.org/docs/LangRef.html#pointeraliasing
66
  LocationSize Size;
67
68
  /// The metadata nodes which describes the aliasing of the location (each
69
  /// member is null if that kind of information is unavailable).
70
  AAMDNodes AATags;
71
72
  /// Return a location with information about the memory reference by the given
73
  /// instruction.
74
  static MemoryLocation get(const LoadInst *LI);
75
  static MemoryLocation get(const StoreInst *SI);
76
  static MemoryLocation get(const VAArgInst *VI);
77
  static MemoryLocation get(const AtomicCmpXchgInst *CXI);
78
  static MemoryLocation get(const AtomicRMWInst *RMWI);
79
4.23M
  static MemoryLocation get(const Instruction *Inst) {
80
4.23M
    return *MemoryLocation::getOrNone(Inst);
81
4.23M
  }
82
4.85M
  static Optional<MemoryLocation> getOrNone(const Instruction *Inst) {
83
4.85M
    switch (Inst->getOpcode()) {
84
4.85M
    case Instruction::Load:
85
4.82M
      return get(cast<LoadInst>(Inst));
86
4.85M
    case Instruction::Store:
87
27.9k
      return get(cast<StoreInst>(Inst));
88
4.85M
    case Instruction::VAArg:
89
9
      return get(cast<VAArgInst>(Inst));
90
4.85M
    case Instruction::AtomicCmpXchg:
91
0
      return get(cast<AtomicCmpXchgInst>(Inst));
92
4.85M
    case Instruction::AtomicRMW:
93
4.17k
      return get(cast<AtomicRMWInst>(Inst));
94
4.85M
    default:
95
86
      return None;
96
4.85M
    }
97
4.85M
  }
98
99
  /// Return a location representing the source of a memory transfer.
100
  static MemoryLocation getForSource(const MemTransferInst *MTI);
101
  static MemoryLocation getForSource(const AtomicMemTransferInst *MTI);
102
  static MemoryLocation getForSource(const AnyMemTransferInst *MTI);
103
104
  /// Return a location representing the destination of a memory set or
105
  /// transfer.
106
  static MemoryLocation getForDest(const MemIntrinsic *MI);
107
  static MemoryLocation getForDest(const AtomicMemIntrinsic *MI);
108
  static MemoryLocation getForDest(const AnyMemIntrinsic *MI);
109
110
  /// Return a location representing a particular argument of a call.
111
  static MemoryLocation getForArgument(ImmutableCallSite CS, unsigned ArgIdx,
112
                                       const TargetLibraryInfo &TLI);
113
114
  explicit MemoryLocation(const Value *Ptr = nullptr,
115
                          LocationSize Size = UnknownSize,
116
                          const AAMDNodes &AATags = AAMDNodes())
117
1.41G
      : Ptr(Ptr), Size(Size), AATags(AATags) {}
118
119
1.55M
  MemoryLocation getWithNewPtr(const Value *NewPtr) const {
120
1.55M
    MemoryLocation Copy(*this);
121
1.55M
    Copy.Ptr = NewPtr;
122
1.55M
    return Copy;
123
1.55M
  }
124
125
0
  MemoryLocation getWithNewSize(LocationSize NewSize) const {
126
0
    MemoryLocation Copy(*this);
127
0
    Copy.Size = NewSize;
128
0
    return Copy;
129
0
  }
130
131
9.36k
  MemoryLocation getWithoutAATags() const {
132
9.36k
    MemoryLocation Copy(*this);
133
9.36k
    Copy.AATags = AAMDNodes();
134
9.36k
    return Copy;
135
9.36k
  }
136
137
1.64G
  bool operator==(const MemoryLocation &Other) const {
138
1.64G
    return Ptr == Other.Ptr && 
Size == Other.Size1.39G
&&
AATags == Other.AATags1.38G
;
139
1.64G
  }
140
};
141
142
// Specialize DenseMapInfo for MemoryLocation.
143
template <> struct DenseMapInfo<MemoryLocation> {
144
683M
  static inline MemoryLocation getEmptyKey() {
145
683M
    return MemoryLocation(DenseMapInfo<const Value *>::getEmptyKey(), 0);
146
683M
  }
147
474M
  static inline MemoryLocation getTombstoneKey() {
148
474M
    return MemoryLocation(DenseMapInfo<const Value *>::getTombstoneKey(), 0);
149
474M
  }
150
374M
  static unsigned getHashValue(const MemoryLocation &Val) {
151
374M
    return DenseMapInfo<const Value *>::getHashValue(Val.Ptr) ^
152
374M
           DenseMapInfo<LocationSize>::getHashValue(Val.Size) ^
153
374M
           DenseMapInfo<AAMDNodes>::getHashValue(Val.AATags);
154
374M
  }
155
1.62G
  static bool isEqual(const MemoryLocation &LHS, const MemoryLocation &RHS) {
156
1.62G
    return LHS == RHS;
157
1.62G
  }
158
};
159
}
160
161
#endif