Coverage Report

Created: 2018-09-25 00:18

/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.44M
  static MemoryLocation get(const Instruction *Inst) {
80
4.44M
    return *MemoryLocation::getOrNone(Inst);
81
4.44M
  }
82
5.09M
  static Optional<MemoryLocation> getOrNone(const Instruction *Inst) {
83
5.09M
    switch (Inst->getOpcode()) {
84
5.09M
    case Instruction::Load:
85
5.06M
      return get(cast<LoadInst>(Inst));
86
5.09M
    case Instruction::Store:
87
28.2k
      return get(cast<StoreInst>(Inst));
88
5.09M
    case Instruction::VAArg:
89
9
      return get(cast<VAArgInst>(Inst));
90
5.09M
    case Instruction::AtomicCmpXchg:
91
0
      return get(cast<AtomicCmpXchgInst>(Inst));
92
5.09M
    case Instruction::AtomicRMW:
93
4.17k
      return get(cast<AtomicRMWInst>(Inst));
94
5.09M
    default:
95
86
      return None;
96
5.09M
    }
97
5.09M
  }
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
  static MemoryLocation getForArgument(ImmutableCallSite CS, unsigned ArgIdx,
114
1.45M
                                       const TargetLibraryInfo &TLI) {
115
1.45M
    return getForArgument(CS, ArgIdx, &TLI);
116
1.45M
  }
117
118
  explicit MemoryLocation(const Value *Ptr = nullptr,
119
                          LocationSize Size = UnknownSize,
120
                          const AAMDNodes &AATags = AAMDNodes())
121
1.53G
      : Ptr(Ptr), Size(Size), AATags(AATags) {}
122
123
1.60M
  MemoryLocation getWithNewPtr(const Value *NewPtr) const {
124
1.60M
    MemoryLocation Copy(*this);
125
1.60M
    Copy.Ptr = NewPtr;
126
1.60M
    return Copy;
127
1.60M
  }
128
129
0
  MemoryLocation getWithNewSize(LocationSize NewSize) const {
130
0
    MemoryLocation Copy(*this);
131
0
    Copy.Size = NewSize;
132
0
    return Copy;
133
0
  }
134
135
11.5k
  MemoryLocation getWithoutAATags() const {
136
11.5k
    MemoryLocation Copy(*this);
137
11.5k
    Copy.AATags = AAMDNodes();
138
11.5k
    return Copy;
139
11.5k
  }
140
141
1.80G
  bool operator==(const MemoryLocation &Other) const {
142
1.80G
    return Ptr == Other.Ptr && 
Size == Other.Size1.52G
&&
AATags == Other.AATags1.52G
;
143
1.80G
  }
144
};
145
146
// Specialize DenseMapInfo for MemoryLocation.
147
template <> struct DenseMapInfo<MemoryLocation> {
148
739M
  static inline MemoryLocation getEmptyKey() {
149
739M
    return MemoryLocation(DenseMapInfo<const Value *>::getEmptyKey(), 0);
150
739M
  }
151
512M
  static inline MemoryLocation getTombstoneKey() {
152
512M
    return MemoryLocation(DenseMapInfo<const Value *>::getTombstoneKey(), 0);
153
512M
  }
154
401M
  static unsigned getHashValue(const MemoryLocation &Val) {
155
401M
    return DenseMapInfo<const Value *>::getHashValue(Val.Ptr) ^
156
401M
           DenseMapInfo<LocationSize>::getHashValue(Val.Size) ^
157
401M
           DenseMapInfo<AAMDNodes>::getHashValue(Val.AATags);
158
401M
  }
159
1.78G
  static bool isEqual(const MemoryLocation &LHS, const MemoryLocation &RHS) {
160
1.78G
    return LHS == RHS;
161
1.78G
  }
162
};
163
}
164
165
#endif