Coverage Report

Created: 2018-09-23 16:00

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/CodeGen/PseudoSourceValue.h
Line
Count
Source (jump to first uncovered line)
1
//===-- llvm/CodeGen/PseudoSourceValue.h ------------------------*- 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
//
10
// This file contains the declaration of the PseudoSourceValue class.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CODEGEN_PSEUDOSOURCEVALUE_H
15
#define LLVM_CODEGEN_PSEUDOSOURCEVALUE_H
16
17
#include "llvm/ADT/StringMap.h"
18
#include "llvm/IR/GlobalValue.h"
19
#include "llvm/IR/Value.h"
20
#include "llvm/IR/ValueMap.h"
21
#include <map>
22
23
namespace llvm {
24
25
class MachineFrameInfo;
26
class MachineMemOperand;
27
class raw_ostream;
28
class TargetInstrInfo;
29
30
raw_ostream &operator<<(raw_ostream &OS, const MachineMemOperand &MMO);
31
class PseudoSourceValue;
32
raw_ostream &operator<<(raw_ostream &OS, const PseudoSourceValue* PSV);
33
34
/// Special value supplied for machine level alias analysis. It indicates that
35
/// a memory access references the functions stack frame (e.g., a spill slot),
36
/// below the stack frame (e.g., argument space), or constant pool.
37
class PseudoSourceValue {
38
public:
39
  enum PSVKind : unsigned {
40
    Stack,
41
    GOT,
42
    JumpTable,
43
    ConstantPool,
44
    FixedStack,
45
    GlobalValueCallEntry,
46
    ExternalSymbolCallEntry,
47
    TargetCustom
48
  };
49
50
private:
51
  unsigned Kind;
52
  unsigned AddressSpace;
53
  friend raw_ostream &llvm::operator<<(raw_ostream &OS,
54
                                       const PseudoSourceValue* PSV);
55
56
  friend class MachineMemOperand; // For printCustom().
57
58
  /// Implement printing for PseudoSourceValue. This is called from
59
  /// Value::print or Value's operator<<.
60
  virtual void printCustom(raw_ostream &O) const;
61
62
public:
63
  explicit PseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII);
64
65
  virtual ~PseudoSourceValue();
66
67
714k
  unsigned kind() const { return Kind; }
68
69
788k
  bool isStack() const { return Kind == Stack; }
70
808k
  bool isGOT() const { return Kind == GOT; }
71
534k
  bool isConstantPool() const { return Kind == ConstantPool; }
72
102k
  bool isJumpTable() const { return Kind == JumpTable; }
73
74
3.77M
  unsigned getAddressSpace() const { return AddressSpace; }
75
76
0
  unsigned getTargetCustom() const {
77
0
    return (Kind >= TargetCustom) ? ((Kind+1) - TargetCustom) : 0;
78
0
  }
79
80
  /// Test whether the memory pointed to by this PseudoSourceValue has a
81
  /// constant value.
82
  virtual bool isConstant(const MachineFrameInfo *) const;
83
84
  /// Test whether the memory pointed to by this PseudoSourceValue may also be
85
  /// pointed to by an LLVM IR Value.
86
  virtual bool isAliased(const MachineFrameInfo *) const;
87
88
  /// Return true if the memory pointed to by this PseudoSourceValue can ever
89
  /// alias an LLVM IR Value.
90
  virtual bool mayAlias(const MachineFrameInfo *) const;
91
};
92
93
/// A specialized PseudoSourceValue for holding FixedStack values, which must
94
/// include a frame index.
95
class FixedStackPseudoSourceValue : public PseudoSourceValue {
96
  const int FI;
97
98
public:
99
  explicit FixedStackPseudoSourceValue(int FI, const TargetInstrInfo &TII)
100
1.46M
      : PseudoSourceValue(FixedStack, TII), FI(FI) {}
101
102
710k
  static bool classof(const PseudoSourceValue *V) {
103
710k
    return V->kind() == FixedStack;
104
710k
  }
105
106
  bool isConstant(const MachineFrameInfo *MFI) const override;
107
108
  bool isAliased(const MachineFrameInfo *MFI) const override;
109
110
  bool mayAlias(const MachineFrameInfo *) const override;
111
112
  void printCustom(raw_ostream &OS) const override;
113
114
537k
  int getFrameIndex() const { return FI; }
115
};
116
117
class CallEntryPseudoSourceValue : public PseudoSourceValue {
118
protected:
119
  CallEntryPseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII);
120
121
public:
122
  bool isConstant(const MachineFrameInfo *) const override;
123
  bool isAliased(const MachineFrameInfo *) const override;
124
  bool mayAlias(const MachineFrameInfo *) const override;
125
};
126
127
/// A specialized pseudo soruce value for holding GlobalValue values.
128
class GlobalValuePseudoSourceValue : public CallEntryPseudoSourceValue {
129
  const GlobalValue *GV;
130
131
public:
132
  GlobalValuePseudoSourceValue(const GlobalValue *GV,
133
                               const TargetInstrInfo &TII);
134
135
0
  static bool classof(const PseudoSourceValue *V) {
136
0
    return V->kind() == GlobalValueCallEntry;
137
0
  }
138
139
8
  const GlobalValue *getValue() const { return GV; }
140
};
141
142
/// A specialized pseudo source value for holding external symbol values.
143
class ExternalSymbolPseudoSourceValue : public CallEntryPseudoSourceValue {
144
  const char *ES;
145
146
public:
147
  ExternalSymbolPseudoSourceValue(const char *ES, const TargetInstrInfo &TII);
148
149
0
  static bool classof(const PseudoSourceValue *V) {
150
0
    return V->kind() == ExternalSymbolCallEntry;
151
0
  }
152
153
6
  const char *getSymbol() const { return ES; }
154
};
155
156
/// Manages creation of pseudo source values.
157
class PseudoSourceValueManager {
158
  const TargetInstrInfo &TII;
159
  const PseudoSourceValue StackPSV, GOTPSV, JumpTablePSV, ConstantPoolPSV;
160
  std::map<int, std::unique_ptr<FixedStackPseudoSourceValue>> FSValues;
161
  StringMap<std::unique_ptr<const ExternalSymbolPseudoSourceValue>>
162
      ExternalCallEntries;
163
  ValueMap<const GlobalValue *,
164
           std::unique_ptr<const GlobalValuePseudoSourceValue>>
165
      GlobalCallEntries;
166
167
public:
168
  PseudoSourceValueManager(const TargetInstrInfo &TII);
169
170
  /// Return a pseudo source value referencing the area below the stack frame of
171
  /// a function, e.g., the argument space.
172
  const PseudoSourceValue *getStack();
173
174
  /// Return a pseudo source value referencing the global offset table
175
  /// (or something the like).
176
  const PseudoSourceValue *getGOT();
177
178
  /// Return a pseudo source value referencing the constant pool. Since constant
179
  /// pools are constant, this doesn't need to identify a specific constant
180
  /// pool entry.
181
  const PseudoSourceValue *getConstantPool();
182
183
  /// Return a pseudo source value referencing a jump table. Since jump tables
184
  /// are constant, this doesn't need to identify a specific jump table.
185
  const PseudoSourceValue *getJumpTable();
186
187
  /// Return a pseudo source value referencing a fixed stack frame entry,
188
  /// e.g., a spill slot.
189
  const PseudoSourceValue *getFixedStack(int FI);
190
191
  const PseudoSourceValue *getGlobalValueCallEntry(const GlobalValue *GV);
192
193
  const PseudoSourceValue *getExternalSymbolCallEntry(const char *ES);
194
};
195
196
} // end namespace llvm
197
198
#endif