Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/IR/Operator.h
Line
Count
Source (jump to first uncovered line)
1
//===-- llvm/Operator.h - Operator utility subclass -------------*- 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
//
9
// This file defines various classes for working with Instructions and
10
// ConstantExprs.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_IR_OPERATOR_H
15
#define LLVM_IR_OPERATOR_H
16
17
#include "llvm/ADT/None.h"
18
#include "llvm/ADT/Optional.h"
19
#include "llvm/IR/Constants.h"
20
#include "llvm/IR/Instruction.h"
21
#include "llvm/IR/Type.h"
22
#include "llvm/IR/Value.h"
23
#include "llvm/Support/Casting.h"
24
#include <cstddef>
25
26
namespace llvm {
27
28
/// This is a utility class that provides an abstraction for the common
29
/// functionality between Instructions and ConstantExprs.
30
class Operator : public User {
31
public:
32
  // The Operator class is intended to be used as a utility, and is never itself
33
  // instantiated.
34
  Operator() = delete;
35
  ~Operator() = delete;
36
37
  void *operator new(size_t s) = delete;
38
39
  /// Return the opcode for this Instruction or ConstantExpr.
40
1.01G
  unsigned getOpcode() const {
41
1.01G
    if (const Instruction *I = dyn_cast<Instruction>(this))
42
979M
      return I->getOpcode();
43
33.4M
    return cast<ConstantExpr>(this)->getOpcode();
44
33.4M
  }
45
46
  /// If V is an Instruction or ConstantExpr, return its opcode.
47
  /// Otherwise return UserOp1.
48
1.31G
  static unsigned getOpcode(const Value *V) {
49
1.31G
    if (const Instruction *I = dyn_cast<Instruction>(V))
50
757M
      return I->getOpcode();
51
556M
    if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
52
26.1M
      return CE->getOpcode();
53
529M
    return Instruction::UserOp1;
54
529M
  }
55
56
144k
  static bool classof(const Instruction *) { return true; }
57
0
  static bool classof(const ConstantExpr *) { return true; }
58
1.00G
  static bool classof(const Value *V) {
59
1.00G
    return isa<Instruction>(V) || 
isa<ConstantExpr>(V)147M
;
60
1.00G
  }
61
};
62
63
/// Utility class for integer operators which may exhibit overflow - Add, Sub,
64
/// Mul, and Shl. It does not include SDiv, despite that operator having the
65
/// potential for overflow.
66
class OverflowingBinaryOperator : public Operator {
67
public:
68
  enum {
69
    NoUnsignedWrap = (1 << 0),
70
    NoSignedWrap   = (1 << 1)
71
  };
72
73
private:
74
  friend class Instruction;
75
  friend class ConstantExpr;
76
77
1.23M
  void setHasNoUnsignedWrap(bool B) {
78
1.23M
    SubclassOptionalData =
79
1.23M
      (SubclassOptionalData & ~NoUnsignedWrap) | (B * NoUnsignedWrap);
80
1.23M
  }
81
1.21M
  void setHasNoSignedWrap(bool B) {
82
1.21M
    SubclassOptionalData =
83
1.21M
      (SubclassOptionalData & ~NoSignedWrap) | (B * NoSignedWrap);
84
1.21M
  }
85
86
public:
87
  /// Test whether this operation is known to never
88
  /// undergo unsigned overflow, aka the nuw property.
89
35.3M
  bool hasNoUnsignedWrap() const {
90
35.3M
    return SubclassOptionalData & NoUnsignedWrap;
91
35.3M
  }
92
93
  /// Test whether this operation is known to never
94
  /// undergo signed overflow, aka the nsw property.
95
153M
  bool hasNoSignedWrap() const {
96
153M
    return (SubclassOptionalData & NoSignedWrap) != 0;
97
153M
  }
98
99
56.2M
  static bool classof(const Instruction *I) {
100
56.2M
    return I->getOpcode() == Instruction::Add ||
101
56.2M
           
I->getOpcode() == Instruction::Sub20.3M
||
102
56.2M
           
I->getOpcode() == Instruction::Mul18.0M
||
103
56.2M
           
I->getOpcode() == Instruction::Shl16.9M
;
104
56.2M
  }
105
140k
  static bool classof(const ConstantExpr *CE) {
106
140k
    return CE->getOpcode() == Instruction::Add ||
107
140k
           
CE->getOpcode() == Instruction::Sub136k
||
108
140k
           
CE->getOpcode() == Instruction::Mul135k
||
109
140k
           
CE->getOpcode() == Instruction::Shl135k
;
110
140k
  }
111
41.1M
  static bool classof(const Value *V) {
112
41.1M
    return (isa<Instruction>(V) && 
classof(cast<Instruction>(V))40.1M
) ||
113
41.1M
           
(8.24M
isa<ConstantExpr>(V)8.24M
&&
classof(cast<ConstantExpr>(V))140k
);
114
41.1M
  }
115
};
116
117
/// A udiv or sdiv instruction, which can be marked as "exact",
118
/// indicating that no bits are destroyed.
119
class PossiblyExactOperator : public Operator {
120
public:
121
  enum {
122
    IsExact = (1 << 0)
123
  };
124
125
private:
126
  friend class Instruction;
127
  friend class ConstantExpr;
128
129
32.0k
  void setIsExact(bool B) {
130
32.0k
    SubclassOptionalData = (SubclassOptionalData & ~IsExact) | (B * IsExact);
131
32.0k
  }
132
133
public:
134
  /// Test whether this division is known to be exact, with zero remainder.
135
5.85M
  bool isExact() const {
136
5.85M
    return SubclassOptionalData & IsExact;
137
5.85M
  }
138
139
55.4M
  static bool isPossiblyExactOpcode(unsigned OpC) {
140
55.4M
    return OpC == Instruction::SDiv ||
141
55.4M
           
OpC == Instruction::UDiv55.2M
||
142
55.4M
           
OpC == Instruction::AShr55.0M
||
143
55.4M
           
OpC == Instruction::LShr54.7M
;
144
55.4M
  }
145
146
135k
  static bool classof(const ConstantExpr *CE) {
147
135k
    return isPossiblyExactOpcode(CE->getOpcode());
148
135k
  }
149
55.2M
  static bool classof(const Instruction *I) {
150
55.2M
    return isPossiblyExactOpcode(I->getOpcode());
151
55.2M
  }
152
60.8M
  static bool classof(const Value *V) {
153
60.8M
    return (isa<Instruction>(V) && 
classof(cast<Instruction>(V))47.8M
) ||
154
60.8M
           
(60.2M
isa<ConstantExpr>(V)60.2M
&&
classof(cast<ConstantExpr>(V))135k
);
155
60.8M
  }
156
};
157
158
/// Convenience struct for specifying and reasoning about fast-math flags.
159
class FastMathFlags {
160
private:
161
  friend class FPMathOperator;
162
163
  unsigned Flags = 0;
164
165
4.06M
  FastMathFlags(unsigned F) {
166
4.06M
    // If all 7 bits are set, turn this into -1. If the number of bits grows,
167
4.06M
    // this must be updated. This is intended to provide some forward binary
168
4.06M
    // compatibility insurance for the meaning of 'fast' in case bits are added.
169
4.06M
    if (F == 0x7F) 
Flags = ~0U23.7k
;
170
4.03M
    else Flags = F;
171
4.06M
  }
172
173
public:
174
  // This is how the bits are used in Value::SubclassOptionalData so they
175
  // should fit there too.
176
  // WARNING: We're out of space. SubclassOptionalData only has 7 bits. New
177
  // functionality will require a change in how this information is stored.
178
  enum {
179
    AllowReassoc    = (1 << 0),
180
    NoNaNs          = (1 << 1),
181
    NoInfs          = (1 << 2),
182
    NoSignedZeros   = (1 << 3),
183
    AllowReciprocal = (1 << 4),
184
    AllowContract   = (1 << 5),
185
    ApproxFunc      = (1 << 6)
186
  };
187
188
154M
  FastMathFlags() = default;
189
190
593k
  static FastMathFlags getFast() {
191
593k
    FastMathFlags FMF;
192
593k
    FMF.setFast();
193
593k
    return FMF;
194
593k
  }
195
196
2.49M
  bool any() const { return Flags != 0; }
197
0
  bool none() const { return Flags == 0; }
198
23.7k
  bool all() const { return Flags == ~0U; }
199
200
10
  void clear() { Flags = 0; }
201
610k
  void set()   { Flags = ~0U; }
202
203
  /// Flag queries
204
181k
  bool allowReassoc() const    { return 0 != (Flags & AllowReassoc); }
205
4.18M
  bool noNaNs() const          { return 0 != (Flags & NoNaNs); }
206
174k
  bool noInfs() const          { return 0 != (Flags & NoInfs); }
207
1.94M
  bool noSignedZeros() const   { return 0 != (Flags & NoSignedZeros); }
208
174k
  bool allowReciprocal() const { return 0 != (Flags & AllowReciprocal); }
209
174k
  bool allowContract() const   { return 0 != (Flags & AllowContract); }
210
174k
  bool approxFunc() const      { return 0 != (Flags & ApproxFunc); }
211
  /// 'Fast' means all bits are set.
212
23.7k
  bool isFast() const          { return all(); }
213
214
  /// Flag setters
215
959
  void setAllowReassoc(bool B = true) {
216
959
    Flags = (Flags & ~AllowReassoc) | B * AllowReassoc;
217
959
  }
218
2.40k
  void setNoNaNs(bool B = true) {
219
2.40k
    Flags = (Flags & ~NoNaNs) | B * NoNaNs;
220
2.40k
  }
221
848
  void setNoInfs(bool B = true) {
222
848
    Flags = (Flags & ~NoInfs) | B * NoInfs;
223
848
  }
224
1.41k
  void setNoSignedZeros(bool B = true) {
225
1.41k
    Flags = (Flags & ~NoSignedZeros) | B * NoSignedZeros;
226
1.41k
  }
227
699
  void setAllowReciprocal(bool B = true) {
228
699
    Flags = (Flags & ~AllowReciprocal) | B * AllowReciprocal;
229
699
  }
230
46.8k
  void setAllowContract(bool B = true) {
231
46.8k
    Flags = (Flags & ~AllowContract) | B * AllowContract;
232
46.8k
  }
233
210
  void setApproxFunc(bool B = true) {
234
210
    Flags = (Flags & ~ApproxFunc) | B * ApproxFunc;
235
210
  }
236
610k
  void setFast(bool B = true) { B ? set() : 
clear()0
; }
237
238
41.0k
  void operator&=(const FastMathFlags &OtherFlags) {
239
41.0k
    Flags &= OtherFlags.Flags;
240
41.0k
  }
241
};
242
243
/// Utility class for floating point operations which can have
244
/// information about relaxed accuracy requirements attached to them.
245
class FPMathOperator : public Operator {
246
private:
247
  friend class Instruction;
248
249
  /// 'Fast' means all bits are set.
250
1
  void setFast(bool B) {
251
1
    setHasAllowReassoc(B);
252
1
    setHasNoNaNs(B);
253
1
    setHasNoInfs(B);
254
1
    setHasNoSignedZeros(B);
255
1
    setHasAllowReciprocal(B);
256
1
    setHasAllowContract(B);
257
1
    setHasApproxFunc(B);
258
1
  }
259
260
1
  void setHasAllowReassoc(bool B) {
261
1
    SubclassOptionalData =
262
1
    (SubclassOptionalData & ~FastMathFlags::AllowReassoc) |
263
1
    (B * FastMathFlags::AllowReassoc);
264
1
  }
265
266
5
  void setHasNoNaNs(bool B) {
267
5
    SubclassOptionalData =
268
5
      (SubclassOptionalData & ~FastMathFlags::NoNaNs) |
269
5
      (B * FastMathFlags::NoNaNs);
270
5
  }
271
272
2
  void setHasNoInfs(bool B) {
273
2
    SubclassOptionalData =
274
2
      (SubclassOptionalData & ~FastMathFlags::NoInfs) |
275
2
      (B * FastMathFlags::NoInfs);
276
2
  }
277
278
3
  void setHasNoSignedZeros(bool B) {
279
3
    SubclassOptionalData =
280
3
      (SubclassOptionalData & ~FastMathFlags::NoSignedZeros) |
281
3
      (B * FastMathFlags::NoSignedZeros);
282
3
  }
283
284
3
  void setHasAllowReciprocal(bool B) {
285
3
    SubclassOptionalData =
286
3
      (SubclassOptionalData & ~FastMathFlags::AllowReciprocal) |
287
3
      (B * FastMathFlags::AllowReciprocal);
288
3
  }
289
290
1
  void setHasAllowContract(bool B) {
291
1
    SubclassOptionalData =
292
1
        (SubclassOptionalData & ~FastMathFlags::AllowContract) |
293
1
        (B * FastMathFlags::AllowContract);
294
1
  }
295
296
1
  void setHasApproxFunc(bool B) {
297
1
    SubclassOptionalData =
298
1
        (SubclassOptionalData & ~FastMathFlags::ApproxFunc) |
299
1
        (B * FastMathFlags::ApproxFunc);
300
1
  }
301
302
  /// Convenience function for setting multiple fast-math flags.
303
  /// FMF is a mask of the bits to set.
304
222k
  void setFastMathFlags(FastMathFlags FMF) {
305
222k
    SubclassOptionalData |= FMF.Flags;
306
222k
  }
307
308
  /// Convenience function for copying all fast-math flags.
309
  /// All values in FMF are transferred to this operator.
310
81.2k
  void copyFastMathFlags(FastMathFlags FMF) {
311
81.2k
    SubclassOptionalData = FMF.Flags;
312
81.2k
  }
313
314
public:
315
  /// Test if this operation allows all non-strict floating-point transforms.
316
1.10M
  bool isFast() const {
317
1.10M
    return ((SubclassOptionalData & FastMathFlags::AllowReassoc) != 0 &&
318
1.10M
            
(SubclassOptionalData & FastMathFlags::NoNaNs) != 030.4k
&&
319
1.10M
            
(SubclassOptionalData & FastMathFlags::NoInfs) != 029.7k
&&
320
1.10M
            
(SubclassOptionalData & FastMathFlags::NoSignedZeros) != 029.6k
&&
321
1.10M
            
(SubclassOptionalData & FastMathFlags::AllowReciprocal) != 029.6k
&&
322
1.10M
            
(SubclassOptionalData & FastMathFlags::AllowContract) != 029.6k
&&
323
1.10M
            
(SubclassOptionalData & FastMathFlags::ApproxFunc) != 029.6k
);
324
1.10M
  }
325
326
  /// Test if this operation may be simplified with reassociative transforms.
327
5.68M
  bool hasAllowReassoc() const {
328
5.68M
    return (SubclassOptionalData & FastMathFlags::AllowReassoc) != 0;
329
5.68M
  }
330
331
  /// Test if this operation's arguments and results are assumed not-NaN.
332
914k
  bool hasNoNaNs() const {
333
914k
    return (SubclassOptionalData & FastMathFlags::NoNaNs) != 0;
334
914k
  }
335
336
  /// Test if this operation's arguments and results are assumed not-infinite.
337
342k
  bool hasNoInfs() const {
338
342k
    return (SubclassOptionalData & FastMathFlags::NoInfs) != 0;
339
342k
  }
340
341
  /// Test if this operation can ignore the sign of zero.
342
1.89M
  bool hasNoSignedZeros() const {
343
1.89M
    return (SubclassOptionalData & FastMathFlags::NoSignedZeros) != 0;
344
1.89M
  }
345
346
  /// Test if this operation can use reciprocal multiply instead of division.
347
416k
  bool hasAllowReciprocal() const {
348
416k
    return (SubclassOptionalData & FastMathFlags::AllowReciprocal) != 0;
349
416k
  }
350
351
  /// Test if this operation can be floating-point contracted (FMA).
352
342k
  bool hasAllowContract() const {
353
342k
    return (SubclassOptionalData & FastMathFlags::AllowContract) != 0;
354
342k
  }
355
356
  /// Test if this operation allows approximations of math library functions or
357
  /// intrinsics.
358
343k
  bool hasApproxFunc() const {
359
343k
    return (SubclassOptionalData & FastMathFlags::ApproxFunc) != 0;
360
343k
  }
361
362
  /// Convenience function for getting all the fast-math flags
363
4.06M
  FastMathFlags getFastMathFlags() const {
364
4.06M
    return FastMathFlags(SubclassOptionalData);
365
4.06M
  }
366
367
  /// Get the maximum error permitted by this operation in ULPs. An accuracy of
368
  /// 0.0 means that the operation should be performed with the default
369
  /// precision.
370
  float getFPAccuracy() const;
371
372
83.0M
  static bool classof(const Value *V) {
373
83.0M
    unsigned Opcode;
374
83.0M
    if (auto *I = dyn_cast<Instruction>(V))
375
81.8M
      Opcode = I->getOpcode();
376
1.16M
    else if (auto *CE = dyn_cast<ConstantExpr>(V))
377
139k
      Opcode = CE->getOpcode();
378
1.02M
    else
379
1.02M
      return false;
380
81.9M
381
81.9M
    switch (Opcode) {
382
81.9M
    case Instruction::FCmp:
383
290k
      return true;
384
81.9M
    // non math FP Operators (no FMF)
385
81.9M
    case Instruction::ExtractElement:
386
5.85M
    case Instruction::ShuffleVector:
387
5.85M
    case Instruction::InsertElement:
388
5.85M
    case Instruction::PHI:
389
5.85M
      return false;
390
75.8M
    default:
391
75.8M
      return V->getType()->isFPOrFPVectorTy();
392
81.9M
    }
393
81.9M
  }
394
};
395
396
/// A helper template for defining operators for individual opcodes.
397
template<typename SuperClass, unsigned Opc>
398
class ConcreteOperator : public SuperClass {
399
public:
400
1.11G
  static bool classof(const Instruction *I) {
401
1.11G
    return I->getOpcode() == Opc;
402
1.11G
  }
llvm::ConcreteOperator<llvm::OverflowingBinaryOperator, 17u>::classof(llvm::Instruction const*)
Line
Count
Source
400
331
  static bool classof(const Instruction *I) {
401
331
    return I->getOpcode() == Opc;
402
331
  }
llvm::ConcreteOperator<llvm::OverflowingBinaryOperator, 25u>::classof(llvm::Instruction const*)
Line
Count
Source
400
246k
  static bool classof(const Instruction *I) {
401
246k
    return I->getOpcode() == Opc;
402
246k
  }
llvm::ConcreteOperator<llvm::Operator, 34u>::classof(llvm::Instruction const*)
Line
Count
Source
400
1.06G
  static bool classof(const Instruction *I) {
401
1.06G
    return I->getOpcode() == Opc;
402
1.06G
  }
llvm::ConcreteOperator<llvm::Operator, 49u>::classof(llvm::Instruction const*)
Line
Count
Source
400
27.5M
  static bool classof(const Instruction *I) {
401
27.5M
    return I->getOpcode() == Opc;
402
27.5M
  }
llvm::ConcreteOperator<llvm::Operator, 47u>::classof(llvm::Instruction const*)
Line
Count
Source
400
23.1M
  static bool classof(const Instruction *I) {
401
23.1M
    return I->getOpcode() == Opc;
402
23.1M
  }
llvm::ConcreteOperator<llvm::PossiblyExactOperator, 27u>::classof(llvm::Instruction const*)
Line
Count
Source
400
72
  static bool classof(const Instruction *I) {
401
72
    return I->getOpcode() == Opc;
402
72
  }
llvm::ConcreteOperator<llvm::OverflowingBinaryOperator, 13u>::classof(llvm::Instruction const*)
Line
Count
Source
400
6.51k
  static bool classof(const Instruction *I) {
401
6.51k
    return I->getOpcode() == Opc;
402
6.51k
  }
403
105M
  static bool classof(const ConstantExpr *CE) {
404
105M
    return CE->getOpcode() == Opc;
405
105M
  }
Unexecuted instantiation: llvm::ConcreteOperator<llvm::OverflowingBinaryOperator, 17u>::classof(llvm::ConstantExpr const*)
Unexecuted instantiation: llvm::ConcreteOperator<llvm::OverflowingBinaryOperator, 25u>::classof(llvm::ConstantExpr const*)
llvm::ConcreteOperator<llvm::Operator, 34u>::classof(llvm::ConstantExpr const*)
Line
Count
Source
403
105M
  static bool classof(const ConstantExpr *CE) {
404
105M
    return CE->getOpcode() == Opc;
405
105M
  }
llvm::ConcreteOperator<llvm::Operator, 49u>::classof(llvm::ConstantExpr const*)
Line
Count
Source
403
197k
  static bool classof(const ConstantExpr *CE) {
404
197k
    return CE->getOpcode() == Opc;
405
197k
  }
llvm::ConcreteOperator<llvm::Operator, 47u>::classof(llvm::ConstantExpr const*)
Line
Count
Source
403
107
  static bool classof(const ConstantExpr *CE) {
404
107
    return CE->getOpcode() == Opc;
405
107
  }
Unexecuted instantiation: llvm::ConcreteOperator<llvm::PossiblyExactOperator, 27u>::classof(llvm::ConstantExpr const*)
Unexecuted instantiation: llvm::ConcreteOperator<llvm::OverflowingBinaryOperator, 13u>::classof(llvm::ConstantExpr const*)
406
1.56G
  static bool classof(const Value *V) {
407
1.56G
    return (isa<Instruction>(V) && 
classof(cast<Instruction>(V))1.11G
) ||
408
1.56G
           
(1.09G
isa<ConstantExpr>(V)1.09G
&&
classof(cast<ConstantExpr>(V))103M
);
409
1.56G
  }
llvm::ConcreteOperator<llvm::OverflowingBinaryOperator, 17u>::classof(llvm::Value const*)
Line
Count
Source
406
583
  static bool classof(const Value *V) {
407
583
    return (isa<Instruction>(V) && 
classof(cast<Instruction>(V))331
) ||
408
583
           
(560
isa<ConstantExpr>(V)560
&&
classof(cast<ConstantExpr>(V))0
);
409
583
  }
llvm::ConcreteOperator<llvm::OverflowingBinaryOperator, 25u>::classof(llvm::Value const*)
Line
Count
Source
406
155
  static bool classof(const Value *V) {
407
155
    return (isa<Instruction>(V) && 
classof(cast<Instruction>(V))51
) ||
408
155
           
(130
isa<ConstantExpr>(V)130
&&
classof(cast<ConstantExpr>(V))0
);
409
155
  }
llvm::ConcreteOperator<llvm::Operator, 34u>::classof(llvm::Value const*)
Line
Count
Source
406
1.50G
  static bool classof(const Value *V) {
407
1.50G
    return (isa<Instruction>(V) && 
classof(cast<Instruction>(V))1.06G
) ||
408
1.50G
           
(1.03G
isa<ConstantExpr>(V)1.03G
&&
classof(cast<ConstantExpr>(V))103M
);
409
1.50G
  }
llvm::ConcreteOperator<llvm::Operator, 49u>::classof(llvm::Value const*)
Line
Count
Source
406
40.3M
  static bool classof(const Value *V) {
407
40.3M
    return (isa<Instruction>(V) && 
classof(cast<Instruction>(V))27.5M
) ||
408
40.3M
           
(38.0M
isa<ConstantExpr>(V)38.0M
&&
classof(cast<ConstantExpr>(V))197k
);
409
40.3M
  }
llvm::ConcreteOperator<llvm::Operator, 47u>::classof(llvm::Value const*)
Line
Count
Source
406
25.5M
  static bool classof(const Value *V) {
407
25.5M
    return (isa<Instruction>(V) && 
classof(cast<Instruction>(V))23.1M
) ||
408
25.5M
           
(25.4M
isa<ConstantExpr>(V)25.4M
&&
classof(cast<ConstantExpr>(V))107
);
409
25.5M
  }
llvm::ConcreteOperator<llvm::PossiblyExactOperator, 27u>::classof(llvm::Value const*)
Line
Count
Source
406
72
  static bool classof(const Value *V) {
407
72
    return (isa<Instruction>(V) && classof(cast<Instruction>(V))) ||
408
72
           
(51
isa<ConstantExpr>(V)51
&&
classof(cast<ConstantExpr>(V))0
);
409
72
  }
llvm::ConcreteOperator<llvm::OverflowingBinaryOperator, 13u>::classof(llvm::Value const*)
Line
Count
Source
406
10.4k
  static bool classof(const Value *V) {
407
10.4k
    return (isa<Instruction>(V) && 
classof(cast<Instruction>(V))6.51k
) ||
408
10.4k
           
(10.2k
isa<ConstantExpr>(V)10.2k
&&
classof(cast<ConstantExpr>(V))0
);
409
10.4k
  }
410
};
411
412
class AddOperator
413
  : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Add> {
414
};
415
class SubOperator
416
  : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Sub> {
417
};
418
class MulOperator
419
  : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Mul> {
420
};
421
class ShlOperator
422
  : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Shl> {
423
};
424
425
class SDivOperator
426
  : public ConcreteOperator<PossiblyExactOperator, Instruction::SDiv> {
427
};
428
class UDivOperator
429
  : public ConcreteOperator<PossiblyExactOperator, Instruction::UDiv> {
430
};
431
class AShrOperator
432
  : public ConcreteOperator<PossiblyExactOperator, Instruction::AShr> {
433
};
434
class LShrOperator
435
  : public ConcreteOperator<PossiblyExactOperator, Instruction::LShr> {
436
};
437
438
class ZExtOperator : public ConcreteOperator<Operator, Instruction::ZExt> {};
439
440
class GEPOperator
441
  : public ConcreteOperator<Operator, Instruction::GetElementPtr> {
442
  friend class GetElementPtrInst;
443
  friend class ConstantExpr;
444
445
  enum {
446
    IsInBounds = (1 << 0),
447
    // InRangeIndex: bits 1-6
448
  };
449
450
4.32M
  void setIsInBounds(bool B) {
451
4.32M
    SubclassOptionalData =
452
4.32M
      (SubclassOptionalData & ~IsInBounds) | (B * IsInBounds);
453
4.32M
  }
454
455
public:
456
  /// Test whether this is an inbounds GEP, as defined by LangRef.html.
457
124M
  bool isInBounds() const {
458
124M
    return SubclassOptionalData & IsInBounds;
459
124M
  }
460
461
  /// Returns the offset of the index with an inrange attachment, or None if
462
  /// none.
463
26.8M
  Optional<unsigned> getInRangeIndex() const {
464
26.8M
    if (SubclassOptionalData >> 1 == 0) 
return None26.4M
;
465
425k
    return (SubclassOptionalData >> 1) - 1;
466
425k
  }
467
468
2.04M
  inline op_iterator       idx_begin()       { return op_begin()+1; }
469
151M
  inline const_op_iterator idx_begin() const { return op_begin()+1; }
470
5.76M
  inline op_iterator       idx_end()         { return op_end(); }
471
151M
  inline const_op_iterator idx_end()   const { return op_end(); }
472
473
180M
  Value *getPointerOperand() {
474
180M
    return getOperand(0);
475
180M
  }
476
169M
  const Value *getPointerOperand() const {
477
169M
    return getOperand(0);
478
169M
  }
479
0
  static unsigned getPointerOperandIndex() {
480
0
    return 0U;                      // get index for modifying correct operand
481
0
  }
482
483
  /// Method to return the pointer operand as a PointerType.
484
109M
  Type *getPointerOperandType() const {
485
109M
    return getPointerOperand()->getType();
486
109M
  }
487
488
  Type *getSourceElementType() const;
489
  Type *getResultElementType() const;
490
491
  /// Method to return the address space of the pointer operand.
492
82.1M
  unsigned getPointerAddressSpace() const {
493
82.1M
    return getPointerOperandType()->getPointerAddressSpace();
494
82.1M
  }
495
496
48.2M
  unsigned getNumIndices() const {  // Note: always non-negative
497
48.2M
    return getNumOperands() - 1;
498
48.2M
  }
499
500
0
  bool hasIndices() const {
501
0
    return getNumOperands() > 1;
502
0
  }
503
504
  /// Return true if all of the indices of this GEP are zeros.
505
  /// If so, the result pointer and the first operand have the same
506
  /// value, just potentially different types.
507
151M
  bool hasAllZeroIndices() const {
508
292M
    for (const_op_iterator I = idx_begin(), E = idx_end(); I != E; 
++I141M
) {
509
280M
      if (ConstantInt *C = dyn_cast<ConstantInt>(I))
510
249M
        if (C->isZero())
511
141M
          continue;
512
138M
      return false;
513
138M
    }
514
151M
    
return true12.7M
;
515
151M
  }
516
517
  /// Return true if all of the indices of this GEP are constant integers.
518
  /// If so, the result pointer and the first operand have
519
  /// a constant offset between them.
520
709k
  bool hasAllConstantIndices() const {
521
1.43M
    for (const_op_iterator I = idx_begin(), E = idx_end(); I != E; 
++I730k
) {
522
967k
      if (!isa<ConstantInt>(I))
523
237k
        return false;
524
967k
    }
525
709k
    
return true471k
;
526
709k
  }
527
528
1.85k
  unsigned countNonConstantIndices() const {
529
1.87k
    return count_if(make_range(idx_begin(), idx_end()), [](const Use& use) {
530
1.87k
        return !isa<ConstantInt>(*use);
531
1.87k
      });
532
1.85k
  }
533
534
  /// Accumulate the constant address offset of this GEP if possible.
535
  ///
536
  /// This routine accepts an APInt into which it will accumulate the constant
537
  /// offset of this GEP if the GEP is in fact constant. If the GEP is not
538
  /// all-constant, it returns false and the value of the offset APInt is
539
  /// undefined (it is *not* preserved!). The APInt passed into this routine
540
  /// must be at exactly as wide as the IntPtr type for the address space of the
541
  /// base GEP pointer.
542
  bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const;
543
};
544
545
class PtrToIntOperator
546
    : public ConcreteOperator<Operator, Instruction::PtrToInt> {
547
  friend class PtrToInt;
548
  friend class ConstantExpr;
549
550
public:
551
2.09k
  Value *getPointerOperand() {
552
2.09k
    return getOperand(0);
553
2.09k
  }
554
2.15k
  const Value *getPointerOperand() const {
555
2.15k
    return getOperand(0);
556
2.15k
  }
557
558
0
  static unsigned getPointerOperandIndex() {
559
0
    return 0U;                      // get index for modifying correct operand
560
0
  }
561
562
  /// Method to return the pointer operand as a PointerType.
563
2.15k
  Type *getPointerOperandType() const {
564
2.15k
    return getPointerOperand()->getType();
565
2.15k
  }
566
567
  /// Method to return the address space of the pointer operand.
568
0
  unsigned getPointerAddressSpace() const {
569
0
    return cast<PointerType>(getPointerOperandType())->getAddressSpace();
570
0
  }
571
};
572
573
class BitCastOperator
574
    : public ConcreteOperator<Operator, Instruction::BitCast> {
575
  friend class BitCastInst;
576
  friend class ConstantExpr;
577
578
public:
579
0
  Type *getSrcTy() const {
580
0
    return getOperand(0)->getType();
581
0
  }
582
583
7
  Type *getDestTy() const {
584
7
    return getType();
585
7
  }
586
};
587
588
} // end namespace llvm
589
590
#endif // LLVM_IR_OPERATOR_H