~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/include/llvm/InstrTypes.h

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-03-12 11:30:04 UTC
  • mfrom: (0.41.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100312113004-b0fop4bkycszdd0z
Tags: 0.96~rc1+dfsg-0ubuntu1
* New upstream RC - FFE (LP: #537636):
  - Add OfficialDatabaseOnly option to clamav-base.postinst.in
  - Add LocalSocketGroup option to clamav-base.postinst.in
  - Add LocalSocketMode option to clamav-base.postinst.in
  - Add CrossFilesystems option to clamav-base.postinst.in
  - Add ClamukoScannerCount option to clamav-base.postinst.in
  - Add BytecodeSecurity opiton to clamav-base.postinst.in
  - Add DetectionStatsHostID option to clamav-freshclam.postinst.in
  - Add Bytecode option to clamav-freshclam.postinst.in
  - Add MilterSocketGroup option to clamav-milter.postinst.in
  - Add MilterSocketMode option to clamav-milter.postinst.in
  - Add ReportHostname option to clamav-milter.postinst.in
  - Bump libclamav SO version to 6.1.0 in libclamav6.install
  - Drop clamdmon from clamav.examples (no longer shipped by upstream)
  - Drop libclamav.a from libclamav-dev.install (not built by upstream)
  - Update SO version for lintian override for libclamav6
  - Add new Bytecode Testing Tool, usr/bin/clambc, to clamav.install
  - Add build-depends on python and python-setuptools for new test suite
  - Update debian/copyright for the embedded copy of llvm (using the system
    llvm is not currently feasible)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//===-- llvm/InstrTypes.h - Important Instruction subclasses ----*- 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 defines various meta classes of instructions that exist in the VM
 
11
// representation.  Specific concrete subclasses of these may be found in the
 
12
// i*.h files...
 
13
//
 
14
//===----------------------------------------------------------------------===//
 
15
 
 
16
#ifndef LLVM_INSTRUCTION_TYPES_H
 
17
#define LLVM_INSTRUCTION_TYPES_H
 
18
 
 
19
#include "llvm/Instruction.h"
 
20
#include "llvm/OperandTraits.h"
 
21
#include "llvm/Operator.h"
 
22
#include "llvm/DerivedTypes.h"
 
23
#include "llvm/ADT/Twine.h"
 
24
 
 
25
namespace llvm {
 
26
 
 
27
class LLVMContext;
 
28
 
 
29
//===----------------------------------------------------------------------===//
 
30
//                            TerminatorInst Class
 
31
//===----------------------------------------------------------------------===//
 
32
 
 
33
/// TerminatorInst - Subclasses of this class are all able to terminate a basic
 
34
/// block.  Thus, these are all the flow control type of operations.
 
35
///
 
36
class TerminatorInst : public Instruction {
 
37
protected:
 
38
  TerminatorInst(const Type *Ty, Instruction::TermOps iType,
 
39
                 Use *Ops, unsigned NumOps,
 
40
                 Instruction *InsertBefore = 0)
 
41
    : Instruction(Ty, iType, Ops, NumOps, InsertBefore) {}
 
42
 
 
43
  TerminatorInst(const Type *Ty, Instruction::TermOps iType,
 
44
                 Use *Ops, unsigned NumOps, BasicBlock *InsertAtEnd)
 
45
    : Instruction(Ty, iType, Ops, NumOps, InsertAtEnd) {}
 
46
 
 
47
  // Out of line virtual method, so the vtable, etc has a home.
 
48
  ~TerminatorInst();
 
49
 
 
50
  /// Virtual methods - Terminators should overload these and provide inline
 
51
  /// overrides of non-V methods.
 
52
  virtual BasicBlock *getSuccessorV(unsigned idx) const = 0;
 
53
  virtual unsigned getNumSuccessorsV() const = 0;
 
54
  virtual void setSuccessorV(unsigned idx, BasicBlock *B) = 0;
 
55
  virtual TerminatorInst *clone_impl() const = 0;
 
56
public:
 
57
 
 
58
  /// getNumSuccessors - Return the number of successors that this terminator
 
59
  /// has.
 
60
  unsigned getNumSuccessors() const {
 
61
    return getNumSuccessorsV();
 
62
  }
 
63
 
 
64
  /// getSuccessor - Return the specified successor.
 
65
  ///
 
66
  BasicBlock *getSuccessor(unsigned idx) const {
 
67
    return getSuccessorV(idx);
 
68
  }
 
69
 
 
70
  /// setSuccessor - Update the specified successor to point at the provided
 
71
  /// block.
 
72
  void setSuccessor(unsigned idx, BasicBlock *B) {
 
73
    setSuccessorV(idx, B);
 
74
  }
 
75
 
 
76
  // Methods for support type inquiry through isa, cast, and dyn_cast:
 
77
  static inline bool classof(const TerminatorInst *) { return true; }
 
78
  static inline bool classof(const Instruction *I) {
 
79
    return I->isTerminator();
 
80
  }
 
81
  static inline bool classof(const Value *V) {
 
82
    return isa<Instruction>(V) && classof(cast<Instruction>(V));
 
83
  }
 
84
};
 
85
 
 
86
 
 
87
//===----------------------------------------------------------------------===//
 
88
//                          UnaryInstruction Class
 
89
//===----------------------------------------------------------------------===//
 
90
 
 
91
class UnaryInstruction : public Instruction {
 
92
  void *operator new(size_t, unsigned);      // Do not implement
 
93
 
 
94
protected:
 
95
  UnaryInstruction(const Type *Ty, unsigned iType, Value *V,
 
96
                   Instruction *IB = 0)
 
97
    : Instruction(Ty, iType, &Op<0>(), 1, IB) {
 
98
    Op<0>() = V;
 
99
  }
 
100
  UnaryInstruction(const Type *Ty, unsigned iType, Value *V, BasicBlock *IAE)
 
101
    : Instruction(Ty, iType, &Op<0>(), 1, IAE) {
 
102
    Op<0>() = V;
 
103
  }
 
104
public:
 
105
  // allocate space for exactly one operand
 
106
  void *operator new(size_t s) {
 
107
    return User::operator new(s, 1);
 
108
  }
 
109
 
 
110
  // Out of line virtual method, so the vtable, etc has a home.
 
111
  ~UnaryInstruction();
 
112
 
 
113
  /// Transparently provide more efficient getOperand methods.
 
114
  DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
 
115
 
 
116
  // Methods for support type inquiry through isa, cast, and dyn_cast:
 
117
  static inline bool classof(const UnaryInstruction *) { return true; }
 
118
  static inline bool classof(const Instruction *I) {
 
119
    return I->getOpcode() == Instruction::Alloca ||
 
120
           I->getOpcode() == Instruction::Load ||
 
121
           I->getOpcode() == Instruction::VAArg ||
 
122
           I->getOpcode() == Instruction::ExtractValue ||
 
123
           (I->getOpcode() >= CastOpsBegin && I->getOpcode() < CastOpsEnd);
 
124
  }
 
125
  static inline bool classof(const Value *V) {
 
126
    return isa<Instruction>(V) && classof(cast<Instruction>(V));
 
127
  }
 
128
};
 
129
 
 
130
template <>
 
131
struct OperandTraits<UnaryInstruction> : public FixedNumOperandTraits<1> {
 
132
};
 
133
 
 
134
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(UnaryInstruction, Value)
 
135
 
 
136
//===----------------------------------------------------------------------===//
 
137
//                           BinaryOperator Class
 
138
//===----------------------------------------------------------------------===//
 
139
 
 
140
class BinaryOperator : public Instruction {
 
141
  void *operator new(size_t, unsigned); // Do not implement
 
142
protected:
 
143
  void init(BinaryOps iType);
 
144
  BinaryOperator(BinaryOps iType, Value *S1, Value *S2, const Type *Ty,
 
145
                 const Twine &Name, Instruction *InsertBefore);
 
146
  BinaryOperator(BinaryOps iType, Value *S1, Value *S2, const Type *Ty,
 
147
                 const Twine &Name, BasicBlock *InsertAtEnd);
 
148
  virtual BinaryOperator *clone_impl() const;
 
149
public:
 
150
  // allocate space for exactly two operands
 
151
  void *operator new(size_t s) {
 
152
    return User::operator new(s, 2);
 
153
  }
 
154
 
 
155
  /// Transparently provide more efficient getOperand methods.
 
156
  DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
 
157
 
 
158
  /// Create() - Construct a binary instruction, given the opcode and the two
 
159
  /// operands.  Optionally (if InstBefore is specified) insert the instruction
 
160
  /// into a BasicBlock right before the specified instruction.  The specified
 
161
  /// Instruction is allowed to be a dereferenced end iterator.
 
162
  ///
 
163
  static BinaryOperator *Create(BinaryOps Op, Value *S1, Value *S2,
 
164
                                const Twine &Name = Twine(),
 
165
                                Instruction *InsertBefore = 0);
 
166
 
 
167
  /// Create() - Construct a binary instruction, given the opcode and the two
 
168
  /// operands.  Also automatically insert this instruction to the end of the
 
169
  /// BasicBlock specified.
 
170
  ///
 
171
  static BinaryOperator *Create(BinaryOps Op, Value *S1, Value *S2,
 
172
                                const Twine &Name, BasicBlock *InsertAtEnd);
 
173
 
 
174
  /// Create* - These methods just forward to Create, and are useful when you
 
175
  /// statically know what type of instruction you're going to create.  These
 
176
  /// helpers just save some typing.
 
177
#define HANDLE_BINARY_INST(N, OPC, CLASS) \
 
178
  static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
 
179
                                     const Twine &Name = "") {\
 
180
    return Create(Instruction::OPC, V1, V2, Name);\
 
181
  }
 
182
#include "llvm/Instruction.def"
 
183
#define HANDLE_BINARY_INST(N, OPC, CLASS) \
 
184
  static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
 
185
                                     const Twine &Name, BasicBlock *BB) {\
 
186
    return Create(Instruction::OPC, V1, V2, Name, BB);\
 
187
  }
 
188
#include "llvm/Instruction.def"
 
189
#define HANDLE_BINARY_INST(N, OPC, CLASS) \
 
190
  static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
 
191
                                     const Twine &Name, Instruction *I) {\
 
192
    return Create(Instruction::OPC, V1, V2, Name, I);\
 
193
  }
 
194
#include "llvm/Instruction.def"
 
195
 
 
196
 
 
197
  /// CreateNSWAdd - Create an Add operator with the NSW flag set.
 
198
  ///
 
199
  static BinaryOperator *CreateNSWAdd(Value *V1, Value *V2,
 
200
                                      const Twine &Name = "") {
 
201
    BinaryOperator *BO = CreateAdd(V1, V2, Name);
 
202
    BO->setHasNoSignedWrap(true);
 
203
    return BO;
 
204
  }
 
205
  static BinaryOperator *CreateNSWAdd(Value *V1, Value *V2,
 
206
                                      const Twine &Name, BasicBlock *BB) {
 
207
    BinaryOperator *BO = CreateAdd(V1, V2, Name, BB);
 
208
    BO->setHasNoSignedWrap(true);
 
209
    return BO;
 
210
  }
 
211
  static BinaryOperator *CreateNSWAdd(Value *V1, Value *V2,
 
212
                                      const Twine &Name, Instruction *I) {
 
213
    BinaryOperator *BO = CreateAdd(V1, V2, Name, I);
 
214
    BO->setHasNoSignedWrap(true);
 
215
    return BO;
 
216
  }
 
217
 
 
218
  /// CreateNUWAdd - Create an Add operator with the NUW flag set.
 
219
  ///
 
220
  static BinaryOperator *CreateNUWAdd(Value *V1, Value *V2,
 
221
                                      const Twine &Name = "") {
 
222
    BinaryOperator *BO = CreateAdd(V1, V2, Name);
 
223
    BO->setHasNoUnsignedWrap(true);
 
224
    return BO;
 
225
  }
 
226
  static BinaryOperator *CreateNUWAdd(Value *V1, Value *V2,
 
227
                                      const Twine &Name, BasicBlock *BB) {
 
228
    BinaryOperator *BO = CreateAdd(V1, V2, Name, BB);
 
229
    BO->setHasNoUnsignedWrap(true);
 
230
    return BO;
 
231
  }
 
232
  static BinaryOperator *CreateNUWAdd(Value *V1, Value *V2,
 
233
                                      const Twine &Name, Instruction *I) {
 
234
    BinaryOperator *BO = CreateAdd(V1, V2, Name, I);
 
235
    BO->setHasNoUnsignedWrap(true);
 
236
    return BO;
 
237
  }
 
238
 
 
239
  /// CreateNSWSub - Create an Sub operator with the NSW flag set.
 
240
  ///
 
241
  static BinaryOperator *CreateNSWSub(Value *V1, Value *V2,
 
242
                                      const Twine &Name = "") {
 
243
    BinaryOperator *BO = CreateSub(V1, V2, Name);
 
244
    BO->setHasNoSignedWrap(true);
 
245
    return BO;
 
246
  }
 
247
  static BinaryOperator *CreateNSWSub(Value *V1, Value *V2,
 
248
                                      const Twine &Name, BasicBlock *BB) {
 
249
    BinaryOperator *BO = CreateSub(V1, V2, Name, BB);
 
250
    BO->setHasNoSignedWrap(true);
 
251
    return BO;
 
252
  }
 
253
  static BinaryOperator *CreateNSWSub(Value *V1, Value *V2,
 
254
                                      const Twine &Name, Instruction *I) {
 
255
    BinaryOperator *BO = CreateSub(V1, V2, Name, I);
 
256
    BO->setHasNoSignedWrap(true);
 
257
    return BO;
 
258
  }
 
259
 
 
260
  /// CreateNUWSub - Create an Sub operator with the NUW flag set.
 
261
  ///
 
262
  static BinaryOperator *CreateNUWSub(Value *V1, Value *V2,
 
263
                                      const Twine &Name = "") {
 
264
    BinaryOperator *BO = CreateSub(V1, V2, Name);
 
265
    BO->setHasNoUnsignedWrap(true);
 
266
    return BO;
 
267
  }
 
268
  static BinaryOperator *CreateNUWSub(Value *V1, Value *V2,
 
269
                                      const Twine &Name, BasicBlock *BB) {
 
270
    BinaryOperator *BO = CreateSub(V1, V2, Name, BB);
 
271
    BO->setHasNoUnsignedWrap(true);
 
272
    return BO;
 
273
  }
 
274
  static BinaryOperator *CreateNUWSub(Value *V1, Value *V2,
 
275
                                      const Twine &Name, Instruction *I) {
 
276
    BinaryOperator *BO = CreateSub(V1, V2, Name, I);
 
277
    BO->setHasNoUnsignedWrap(true);
 
278
    return BO;
 
279
  }
 
280
 
 
281
  /// CreateNSWMul - Create a Mul operator with the NSW flag set.
 
282
  ///
 
283
  static BinaryOperator *CreateNSWMul(Value *V1, Value *V2,
 
284
                                      const Twine &Name = "") {
 
285
    BinaryOperator *BO = CreateMul(V1, V2, Name);
 
286
    BO->setHasNoSignedWrap(true);
 
287
    return BO;
 
288
  }
 
289
  static BinaryOperator *CreateNSWMul(Value *V1, Value *V2,
 
290
                                      const Twine &Name, BasicBlock *BB) {
 
291
    BinaryOperator *BO = CreateMul(V1, V2, Name, BB);
 
292
    BO->setHasNoSignedWrap(true);
 
293
    return BO;
 
294
  }
 
295
  static BinaryOperator *CreateNSWMul(Value *V1, Value *V2,
 
296
                                      const Twine &Name, Instruction *I) {
 
297
    BinaryOperator *BO = CreateMul(V1, V2, Name, I);
 
298
    BO->setHasNoSignedWrap(true);
 
299
    return BO;
 
300
  }
 
301
 
 
302
  /// CreateNUWMul - Create a Mul operator with the NUW flag set.
 
303
  ///
 
304
  static BinaryOperator *CreateNUWMul(Value *V1, Value *V2,
 
305
                                      const Twine &Name = "") {
 
306
    BinaryOperator *BO = CreateMul(V1, V2, Name);
 
307
    BO->setHasNoUnsignedWrap(true);
 
308
    return BO;
 
309
  }
 
310
  static BinaryOperator *CreateNUWMul(Value *V1, Value *V2,
 
311
                                      const Twine &Name, BasicBlock *BB) {
 
312
    BinaryOperator *BO = CreateMul(V1, V2, Name, BB);
 
313
    BO->setHasNoUnsignedWrap(true);
 
314
    return BO;
 
315
  }
 
316
  static BinaryOperator *CreateNUWMul(Value *V1, Value *V2,
 
317
                                      const Twine &Name, Instruction *I) {
 
318
    BinaryOperator *BO = CreateMul(V1, V2, Name, I);
 
319
    BO->setHasNoUnsignedWrap(true);
 
320
    return BO;
 
321
  }
 
322
 
 
323
  /// CreateExactSDiv - Create an SDiv operator with the exact flag set.
 
324
  ///
 
325
  static BinaryOperator *CreateExactSDiv(Value *V1, Value *V2,
 
326
                                         const Twine &Name = "") {
 
327
    BinaryOperator *BO = CreateSDiv(V1, V2, Name);
 
328
    BO->setIsExact(true);
 
329
    return BO;
 
330
  }
 
331
  static BinaryOperator *CreateExactSDiv(Value *V1, Value *V2,
 
332
                                         const Twine &Name, BasicBlock *BB) {
 
333
    BinaryOperator *BO = CreateSDiv(V1, V2, Name, BB);
 
334
    BO->setIsExact(true);
 
335
    return BO;
 
336
  }
 
337
  static BinaryOperator *CreateExactSDiv(Value *V1, Value *V2,
 
338
                                         const Twine &Name, Instruction *I) {
 
339
    BinaryOperator *BO = CreateSDiv(V1, V2, Name, I);
 
340
    BO->setIsExact(true);
 
341
    return BO;
 
342
  }
 
343
 
 
344
  /// Helper functions to construct and inspect unary operations (NEG and NOT)
 
345
  /// via binary operators SUB and XOR:
 
346
  ///
 
347
  /// CreateNeg, CreateNot - Create the NEG and NOT
 
348
  ///     instructions out of SUB and XOR instructions.
 
349
  ///
 
350
  static BinaryOperator *CreateNeg(Value *Op, const Twine &Name = "",
 
351
                                   Instruction *InsertBefore = 0);
 
352
  static BinaryOperator *CreateNeg(Value *Op, const Twine &Name,
 
353
                                   BasicBlock *InsertAtEnd);
 
354
  static BinaryOperator *CreateNSWNeg(Value *Op, const Twine &Name = "",
 
355
                                      Instruction *InsertBefore = 0);
 
356
  static BinaryOperator *CreateNSWNeg(Value *Op, const Twine &Name,
 
357
                                      BasicBlock *InsertAtEnd);
 
358
  static BinaryOperator *CreateNUWNeg(Value *Op, const Twine &Name = "",
 
359
                                      Instruction *InsertBefore = 0);
 
360
  static BinaryOperator *CreateNUWNeg(Value *Op, const Twine &Name,
 
361
                                      BasicBlock *InsertAtEnd);
 
362
  static BinaryOperator *CreateFNeg(Value *Op, const Twine &Name = "",
 
363
                                    Instruction *InsertBefore = 0);
 
364
  static BinaryOperator *CreateFNeg(Value *Op, const Twine &Name,
 
365
                                    BasicBlock *InsertAtEnd);
 
366
  static BinaryOperator *CreateNot(Value *Op, const Twine &Name = "",
 
367
                                   Instruction *InsertBefore = 0);
 
368
  static BinaryOperator *CreateNot(Value *Op, const Twine &Name,
 
369
                                   BasicBlock *InsertAtEnd);
 
370
 
 
371
  /// isNeg, isFNeg, isNot - Check if the given Value is a
 
372
  /// NEG, FNeg, or NOT instruction.
 
373
  ///
 
374
  static bool isNeg(const Value *V);
 
375
  static bool isFNeg(const Value *V);
 
376
  static bool isNot(const Value *V);
 
377
 
 
378
  /// getNegArgument, getNotArgument - Helper functions to extract the
 
379
  ///     unary argument of a NEG, FNEG or NOT operation implemented via
 
380
  ///     Sub, FSub, or Xor.
 
381
  ///
 
382
  static const Value *getNegArgument(const Value *BinOp);
 
383
  static       Value *getNegArgument(      Value *BinOp);
 
384
  static const Value *getFNegArgument(const Value *BinOp);
 
385
  static       Value *getFNegArgument(      Value *BinOp);
 
386
  static const Value *getNotArgument(const Value *BinOp);
 
387
  static       Value *getNotArgument(      Value *BinOp);
 
388
 
 
389
  BinaryOps getOpcode() const {
 
390
    return static_cast<BinaryOps>(Instruction::getOpcode());
 
391
  }
 
392
 
 
393
  /// swapOperands - Exchange the two operands to this instruction.
 
394
  /// This instruction is safe to use on any binary instruction and
 
395
  /// does not modify the semantics of the instruction.  If the instruction
 
396
  /// cannot be reversed (ie, it's a Div), then return true.
 
397
  ///
 
398
  bool swapOperands();
 
399
 
 
400
  /// setHasNoUnsignedWrap - Set or clear the nsw flag on this instruction,
 
401
  /// which must be an operator which supports this flag. See LangRef.html
 
402
  /// for the meaning of this flag.
 
403
  void setHasNoUnsignedWrap(bool b = true);
 
404
 
 
405
  /// setHasNoSignedWrap - Set or clear the nsw flag on this instruction,
 
406
  /// which must be an operator which supports this flag. See LangRef.html
 
407
  /// for the meaning of this flag.
 
408
  void setHasNoSignedWrap(bool b = true);
 
409
 
 
410
  /// setIsExact - Set or clear the exact flag on this instruction,
 
411
  /// which must be an operator which supports this flag. See LangRef.html
 
412
  /// for the meaning of this flag.
 
413
  void setIsExact(bool b = true);
 
414
 
 
415
  /// hasNoUnsignedWrap - Determine whether the no unsigned wrap flag is set.
 
416
  bool hasNoUnsignedWrap() const;
 
417
 
 
418
  /// hasNoSignedWrap - Determine whether the no signed wrap flag is set.
 
419
  bool hasNoSignedWrap() const;
 
420
 
 
421
  /// isExact - Determine whether the exact flag is set.
 
422
  bool isExact() const;
 
423
 
 
424
  // Methods for support type inquiry through isa, cast, and dyn_cast:
 
425
  static inline bool classof(const BinaryOperator *) { return true; }
 
426
  static inline bool classof(const Instruction *I) {
 
427
    return I->isBinaryOp();
 
428
  }
 
429
  static inline bool classof(const Value *V) {
 
430
    return isa<Instruction>(V) && classof(cast<Instruction>(V));
 
431
  }
 
432
};
 
433
 
 
434
template <>
 
435
struct OperandTraits<BinaryOperator> : public FixedNumOperandTraits<2> {
 
436
};
 
437
 
 
438
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BinaryOperator, Value)
 
439
 
 
440
//===----------------------------------------------------------------------===//
 
441
//                               CastInst Class
 
442
//===----------------------------------------------------------------------===//
 
443
 
 
444
/// CastInst - This is the base class for all instructions that perform data
 
445
/// casts. It is simply provided so that instruction category testing
 
446
/// can be performed with code like:
 
447
///
 
448
/// if (isa<CastInst>(Instr)) { ... }
 
449
/// @brief Base class of casting instructions.
 
450
class CastInst : public UnaryInstruction {
 
451
protected:
 
452
  /// @brief Constructor with insert-before-instruction semantics for subclasses
 
453
  CastInst(const Type *Ty, unsigned iType, Value *S,
 
454
           const Twine &NameStr = "", Instruction *InsertBefore = 0)
 
455
    : UnaryInstruction(Ty, iType, S, InsertBefore) {
 
456
    setName(NameStr);
 
457
  }
 
458
  /// @brief Constructor with insert-at-end-of-block semantics for subclasses
 
459
  CastInst(const Type *Ty, unsigned iType, Value *S,
 
460
           const Twine &NameStr, BasicBlock *InsertAtEnd)
 
461
    : UnaryInstruction(Ty, iType, S, InsertAtEnd) {
 
462
    setName(NameStr);
 
463
  }
 
464
public:
 
465
  /// Provides a way to construct any of the CastInst subclasses using an
 
466
  /// opcode instead of the subclass's constructor. The opcode must be in the
 
467
  /// CastOps category (Instruction::isCast(opcode) returns true). This
 
468
  /// constructor has insert-before-instruction semantics to automatically
 
469
  /// insert the new CastInst before InsertBefore (if it is non-null).
 
470
  /// @brief Construct any of the CastInst subclasses
 
471
  static CastInst *Create(
 
472
    Instruction::CastOps,    ///< The opcode of the cast instruction
 
473
    Value *S,                ///< The value to be casted (operand 0)
 
474
    const Type *Ty,          ///< The type to which cast should be made
 
475
    const Twine &Name = "", ///< Name for the instruction
 
476
    Instruction *InsertBefore = 0 ///< Place to insert the instruction
 
477
  );
 
478
  /// Provides a way to construct any of the CastInst subclasses using an
 
479
  /// opcode instead of the subclass's constructor. The opcode must be in the
 
480
  /// CastOps category. This constructor has insert-at-end-of-block semantics
 
481
  /// to automatically insert the new CastInst at the end of InsertAtEnd (if
 
482
  /// its non-null).
 
483
  /// @brief Construct any of the CastInst subclasses
 
484
  static CastInst *Create(
 
485
    Instruction::CastOps,    ///< The opcode for the cast instruction
 
486
    Value *S,                ///< The value to be casted (operand 0)
 
487
    const Type *Ty,          ///< The type to which operand is casted
 
488
    const Twine &Name, ///< The name for the instruction
 
489
    BasicBlock *InsertAtEnd  ///< The block to insert the instruction into
 
490
  );
 
491
 
 
492
  /// @brief Create a ZExt or BitCast cast instruction
 
493
  static CastInst *CreateZExtOrBitCast(
 
494
    Value *S,                ///< The value to be casted (operand 0)
 
495
    const Type *Ty,          ///< The type to which cast should be made
 
496
    const Twine &Name = "", ///< Name for the instruction
 
497
    Instruction *InsertBefore = 0 ///< Place to insert the instruction
 
498
  );
 
499
 
 
500
  /// @brief Create a ZExt or BitCast cast instruction
 
501
  static CastInst *CreateZExtOrBitCast(
 
502
    Value *S,                ///< The value to be casted (operand 0)
 
503
    const Type *Ty,          ///< The type to which operand is casted
 
504
    const Twine &Name, ///< The name for the instruction
 
505
    BasicBlock *InsertAtEnd  ///< The block to insert the instruction into
 
506
  );
 
507
 
 
508
  /// @brief Create a SExt or BitCast cast instruction
 
509
  static CastInst *CreateSExtOrBitCast(
 
510
    Value *S,                ///< The value to be casted (operand 0)
 
511
    const Type *Ty,          ///< The type to which cast should be made
 
512
    const Twine &Name = "", ///< Name for the instruction
 
513
    Instruction *InsertBefore = 0 ///< Place to insert the instruction
 
514
  );
 
515
 
 
516
  /// @brief Create a SExt or BitCast cast instruction
 
517
  static CastInst *CreateSExtOrBitCast(
 
518
    Value *S,                ///< The value to be casted (operand 0)
 
519
    const Type *Ty,          ///< The type to which operand is casted
 
520
    const Twine &Name, ///< The name for the instruction
 
521
    BasicBlock *InsertAtEnd  ///< The block to insert the instruction into
 
522
  );
 
523
 
 
524
  /// @brief Create a BitCast or a PtrToInt cast instruction
 
525
  static CastInst *CreatePointerCast(
 
526
    Value *S,                ///< The pointer value to be casted (operand 0)
 
527
    const Type *Ty,          ///< The type to which operand is casted
 
528
    const Twine &Name, ///< The name for the instruction
 
529
    BasicBlock *InsertAtEnd  ///< The block to insert the instruction into
 
530
  );
 
531
 
 
532
  /// @brief Create a BitCast or a PtrToInt cast instruction
 
533
  static CastInst *CreatePointerCast(
 
534
    Value *S,                ///< The pointer value to be casted (operand 0)
 
535
    const Type *Ty,          ///< The type to which cast should be made
 
536
    const Twine &Name = "", ///< Name for the instruction
 
537
    Instruction *InsertBefore = 0 ///< Place to insert the instruction
 
538
  );
 
539
 
 
540
  /// @brief Create a ZExt, BitCast, or Trunc for int -> int casts.
 
541
  static CastInst *CreateIntegerCast(
 
542
    Value *S,                ///< The pointer value to be casted (operand 0)
 
543
    const Type *Ty,          ///< The type to which cast should be made
 
544
    bool isSigned,           ///< Whether to regard S as signed or not
 
545
    const Twine &Name = "", ///< Name for the instruction
 
546
    Instruction *InsertBefore = 0 ///< Place to insert the instruction
 
547
  );
 
548
 
 
549
  /// @brief Create a ZExt, BitCast, or Trunc for int -> int casts.
 
550
  static CastInst *CreateIntegerCast(
 
551
    Value *S,                ///< The integer value to be casted (operand 0)
 
552
    const Type *Ty,          ///< The integer type to which operand is casted
 
553
    bool isSigned,           ///< Whether to regard S as signed or not
 
554
    const Twine &Name, ///< The name for the instruction
 
555
    BasicBlock *InsertAtEnd  ///< The block to insert the instruction into
 
556
  );
 
557
 
 
558
  /// @brief Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
 
559
  static CastInst *CreateFPCast(
 
560
    Value *S,                ///< The floating point value to be casted
 
561
    const Type *Ty,          ///< The floating point type to cast to
 
562
    const Twine &Name = "", ///< Name for the instruction
 
563
    Instruction *InsertBefore = 0 ///< Place to insert the instruction
 
564
  );
 
565
 
 
566
  /// @brief Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
 
567
  static CastInst *CreateFPCast(
 
568
    Value *S,                ///< The floating point value to be casted
 
569
    const Type *Ty,          ///< The floating point type to cast to
 
570
    const Twine &Name, ///< The name for the instruction
 
571
    BasicBlock *InsertAtEnd  ///< The block to insert the instruction into
 
572
  );
 
573
 
 
574
  /// @brief Create a Trunc or BitCast cast instruction
 
575
  static CastInst *CreateTruncOrBitCast(
 
576
    Value *S,                ///< The value to be casted (operand 0)
 
577
    const Type *Ty,          ///< The type to which cast should be made
 
578
    const Twine &Name = "", ///< Name for the instruction
 
579
    Instruction *InsertBefore = 0 ///< Place to insert the instruction
 
580
  );
 
581
 
 
582
  /// @brief Create a Trunc or BitCast cast instruction
 
583
  static CastInst *CreateTruncOrBitCast(
 
584
    Value *S,                ///< The value to be casted (operand 0)
 
585
    const Type *Ty,          ///< The type to which operand is casted
 
586
    const Twine &Name, ///< The name for the instruction
 
587
    BasicBlock *InsertAtEnd  ///< The block to insert the instruction into
 
588
  );
 
589
 
 
590
  /// @brief Check whether it is valid to call getCastOpcode for these types.
 
591
  static bool isCastable(
 
592
    const Type *SrcTy, ///< The Type from which the value should be cast.
 
593
    const Type *DestTy ///< The Type to which the value should be cast.
 
594
  );
 
595
 
 
596
  /// Returns the opcode necessary to cast Val into Ty using usual casting
 
597
  /// rules.
 
598
  /// @brief Infer the opcode for cast operand and type
 
599
  static Instruction::CastOps getCastOpcode(
 
600
    const Value *Val, ///< The value to cast
 
601
    bool SrcIsSigned, ///< Whether to treat the source as signed
 
602
    const Type *Ty,   ///< The Type to which the value should be casted
 
603
    bool DstIsSigned  ///< Whether to treate the dest. as signed
 
604
  );
 
605
 
 
606
  /// There are several places where we need to know if a cast instruction
 
607
  /// only deals with integer source and destination types. To simplify that
 
608
  /// logic, this method is provided.
 
609
  /// @returns true iff the cast has only integral typed operand and dest type.
 
610
  /// @brief Determine if this is an integer-only cast.
 
611
  bool isIntegerCast() const;
 
612
 
 
613
  /// A lossless cast is one that does not alter the basic value. It implies
 
614
  /// a no-op cast but is more stringent, preventing things like int->float,
 
615
  /// long->double, int->ptr, or vector->anything.
 
616
  /// @returns true iff the cast is lossless.
 
617
  /// @brief Determine if this is a lossless cast.
 
618
  bool isLosslessCast() const;
 
619
 
 
620
  /// A no-op cast is one that can be effected without changing any bits.
 
621
  /// It implies that the source and destination types are the same size. The
 
622
  /// IntPtrTy argument is used to make accurate determinations for casts
 
623
  /// involving Integer and Pointer types. They are no-op casts if the integer
 
624
  /// is the same size as the pointer. However, pointer size varies with
 
625
  /// platform. Generally, the result of TargetData::getIntPtrType() should be
 
626
  /// passed in. If that's not available, use Type::Int64Ty, which will make
 
627
  /// the isNoopCast call conservative.
 
628
  /// @brief Determine if this cast is a no-op cast.
 
629
  bool isNoopCast(
 
630
    const Type *IntPtrTy ///< Integer type corresponding to pointer
 
631
  ) const;
 
632
 
 
633
  /// Determine how a pair of casts can be eliminated, if they can be at all.
 
634
  /// This is a helper function for both CastInst and ConstantExpr.
 
635
  /// @returns 0 if the CastInst pair can't be eliminated
 
636
  /// @returns Instruction::CastOps value for a cast that can replace
 
637
  /// the pair, casting SrcTy to DstTy.
 
638
  /// @brief Determine if a cast pair is eliminable
 
639
  static unsigned isEliminableCastPair(
 
640
    Instruction::CastOps firstOpcode,  ///< Opcode of first cast
 
641
    Instruction::CastOps secondOpcode, ///< Opcode of second cast
 
642
    const Type *SrcTy, ///< SrcTy of 1st cast
 
643
    const Type *MidTy, ///< DstTy of 1st cast & SrcTy of 2nd cast
 
644
    const Type *DstTy, ///< DstTy of 2nd cast
 
645
    const Type *IntPtrTy ///< Integer type corresponding to Ptr types, or null
 
646
  );
 
647
 
 
648
  /// @brief Return the opcode of this CastInst
 
649
  Instruction::CastOps getOpcode() const {
 
650
    return Instruction::CastOps(Instruction::getOpcode());
 
651
  }
 
652
 
 
653
  /// @brief Return the source type, as a convenience
 
654
  const Type* getSrcTy() const { return getOperand(0)->getType(); }
 
655
  /// @brief Return the destination type, as a convenience
 
656
  const Type* getDestTy() const { return getType(); }
 
657
 
 
658
  /// This method can be used to determine if a cast from S to DstTy using
 
659
  /// Opcode op is valid or not.
 
660
  /// @returns true iff the proposed cast is valid.
 
661
  /// @brief Determine if a cast is valid without creating one.
 
662
  static bool castIsValid(Instruction::CastOps op, Value *S, const Type *DstTy);
 
663
 
 
664
  /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
 
665
  static inline bool classof(const CastInst *) { return true; }
 
666
  static inline bool classof(const Instruction *I) {
 
667
    return I->isCast();
 
668
  }
 
669
  static inline bool classof(const Value *V) {
 
670
    return isa<Instruction>(V) && classof(cast<Instruction>(V));
 
671
  }
 
672
};
 
673
 
 
674
//===----------------------------------------------------------------------===//
 
675
//                               CmpInst Class
 
676
//===----------------------------------------------------------------------===//
 
677
 
 
678
/// This class is the base class for the comparison instructions.
 
679
/// @brief Abstract base class of comparison instructions.
 
680
class CmpInst : public Instruction {
 
681
  void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
 
682
  CmpInst(); // do not implement
 
683
protected:
 
684
  CmpInst(const Type *ty, Instruction::OtherOps op, unsigned short pred,
 
685
          Value *LHS, Value *RHS, const Twine &Name = "",
 
686
          Instruction *InsertBefore = 0);
 
687
 
 
688
  CmpInst(const Type *ty, Instruction::OtherOps op, unsigned short pred,
 
689
          Value *LHS, Value *RHS, const Twine &Name,
 
690
          BasicBlock *InsertAtEnd);
 
691
 
 
692
  virtual void Anchor() const; // Out of line virtual method.
 
693
public:
 
694
  /// This enumeration lists the possible predicates for CmpInst subclasses.
 
695
  /// Values in the range 0-31 are reserved for FCmpInst, while values in the
 
696
  /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
 
697
  /// predicate values are not overlapping between the classes.
 
698
  enum Predicate {
 
699
    // Opcode              U L G E    Intuitive operation
 
700
    FCMP_FALSE =  0,  ///< 0 0 0 0    Always false (always folded)
 
701
    FCMP_OEQ   =  1,  ///< 0 0 0 1    True if ordered and equal
 
702
    FCMP_OGT   =  2,  ///< 0 0 1 0    True if ordered and greater than
 
703
    FCMP_OGE   =  3,  ///< 0 0 1 1    True if ordered and greater than or equal
 
704
    FCMP_OLT   =  4,  ///< 0 1 0 0    True if ordered and less than
 
705
    FCMP_OLE   =  5,  ///< 0 1 0 1    True if ordered and less than or equal
 
706
    FCMP_ONE   =  6,  ///< 0 1 1 0    True if ordered and operands are unequal
 
707
    FCMP_ORD   =  7,  ///< 0 1 1 1    True if ordered (no nans)
 
708
    FCMP_UNO   =  8,  ///< 1 0 0 0    True if unordered: isnan(X) | isnan(Y)
 
709
    FCMP_UEQ   =  9,  ///< 1 0 0 1    True if unordered or equal
 
710
    FCMP_UGT   = 10,  ///< 1 0 1 0    True if unordered or greater than
 
711
    FCMP_UGE   = 11,  ///< 1 0 1 1    True if unordered, greater than, or equal
 
712
    FCMP_ULT   = 12,  ///< 1 1 0 0    True if unordered or less than
 
713
    FCMP_ULE   = 13,  ///< 1 1 0 1    True if unordered, less than, or equal
 
714
    FCMP_UNE   = 14,  ///< 1 1 1 0    True if unordered or not equal
 
715
    FCMP_TRUE  = 15,  ///< 1 1 1 1    Always true (always folded)
 
716
    FIRST_FCMP_PREDICATE = FCMP_FALSE,
 
717
    LAST_FCMP_PREDICATE = FCMP_TRUE,
 
718
    BAD_FCMP_PREDICATE = FCMP_TRUE + 1,
 
719
    ICMP_EQ    = 32,  ///< equal
 
720
    ICMP_NE    = 33,  ///< not equal
 
721
    ICMP_UGT   = 34,  ///< unsigned greater than
 
722
    ICMP_UGE   = 35,  ///< unsigned greater or equal
 
723
    ICMP_ULT   = 36,  ///< unsigned less than
 
724
    ICMP_ULE   = 37,  ///< unsigned less or equal
 
725
    ICMP_SGT   = 38,  ///< signed greater than
 
726
    ICMP_SGE   = 39,  ///< signed greater or equal
 
727
    ICMP_SLT   = 40,  ///< signed less than
 
728
    ICMP_SLE   = 41,  ///< signed less or equal
 
729
    FIRST_ICMP_PREDICATE = ICMP_EQ,
 
730
    LAST_ICMP_PREDICATE = ICMP_SLE,
 
731
    BAD_ICMP_PREDICATE = ICMP_SLE + 1
 
732
  };
 
733
 
 
734
  // allocate space for exactly two operands
 
735
  void *operator new(size_t s) {
 
736
    return User::operator new(s, 2);
 
737
  }
 
738
  /// Construct a compare instruction, given the opcode, the predicate and
 
739
  /// the two operands.  Optionally (if InstBefore is specified) insert the
 
740
  /// instruction into a BasicBlock right before the specified instruction.
 
741
  /// The specified Instruction is allowed to be a dereferenced end iterator.
 
742
  /// @brief Create a CmpInst
 
743
  static CmpInst *Create(OtherOps Op,
 
744
                         unsigned short predicate, Value *S1,
 
745
                         Value *S2, const Twine &Name = "",
 
746
                         Instruction *InsertBefore = 0);
 
747
 
 
748
  /// Construct a compare instruction, given the opcode, the predicate and the
 
749
  /// two operands.  Also automatically insert this instruction to the end of
 
750
  /// the BasicBlock specified.
 
751
  /// @brief Create a CmpInst
 
752
  static CmpInst *Create(OtherOps Op, unsigned short predicate, Value *S1,
 
753
                         Value *S2, const Twine &Name, BasicBlock *InsertAtEnd);
 
754
  
 
755
  /// @brief Get the opcode casted to the right type
 
756
  OtherOps getOpcode() const {
 
757
    return static_cast<OtherOps>(Instruction::getOpcode());
 
758
  }
 
759
 
 
760
  /// @brief Return the predicate for this instruction.
 
761
  Predicate getPredicate() const {
 
762
    return Predicate(getSubclassDataFromInstruction());
 
763
  }
 
764
 
 
765
  /// @brief Set the predicate for this instruction to the specified value.
 
766
  void setPredicate(Predicate P) { setInstructionSubclassData(P); }
 
767
 
 
768
  static bool isFPPredicate(Predicate P) {
 
769
    return P >= FIRST_FCMP_PREDICATE && P <= LAST_FCMP_PREDICATE;
 
770
  }
 
771
  
 
772
  static bool isIntPredicate(Predicate P) {
 
773
    return P >= FIRST_ICMP_PREDICATE && P <= LAST_ICMP_PREDICATE;
 
774
  }
 
775
  
 
776
  bool isFPPredicate() const { return isFPPredicate(getPredicate()); }
 
777
  bool isIntPredicate() const { return isIntPredicate(getPredicate()); }
 
778
  
 
779
  
 
780
  /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE,
 
781
  ///              OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
 
782
  /// @returns the inverse predicate for the instruction's current predicate.
 
783
  /// @brief Return the inverse of the instruction's predicate.
 
784
  Predicate getInversePredicate() const {
 
785
    return getInversePredicate(getPredicate());
 
786
  }
 
787
 
 
788
  /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE,
 
789
  ///              OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
 
790
  /// @returns the inverse predicate for predicate provided in \p pred.
 
791
  /// @brief Return the inverse of a given predicate
 
792
  static Predicate getInversePredicate(Predicate pred);
 
793
 
 
794
  /// For example, EQ->EQ, SLE->SGE, ULT->UGT,
 
795
  ///              OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
 
796
  /// @returns the predicate that would be the result of exchanging the two
 
797
  /// operands of the CmpInst instruction without changing the result
 
798
  /// produced.
 
799
  /// @brief Return the predicate as if the operands were swapped
 
800
  Predicate getSwappedPredicate() const {
 
801
    return getSwappedPredicate(getPredicate());
 
802
  }
 
803
 
 
804
  /// This is a static version that you can use without an instruction
 
805
  /// available.
 
806
  /// @brief Return the predicate as if the operands were swapped.
 
807
  static Predicate getSwappedPredicate(Predicate pred);
 
808
 
 
809
  /// @brief Provide more efficient getOperand methods.
 
810
  DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
 
811
 
 
812
  /// This is just a convenience that dispatches to the subclasses.
 
813
  /// @brief Swap the operands and adjust predicate accordingly to retain
 
814
  /// the same comparison.
 
815
  void swapOperands();
 
816
 
 
817
  /// This is just a convenience that dispatches to the subclasses.
 
818
  /// @brief Determine if this CmpInst is commutative.
 
819
  bool isCommutative();
 
820
 
 
821
  /// This is just a convenience that dispatches to the subclasses.
 
822
  /// @brief Determine if this is an equals/not equals predicate.
 
823
  bool isEquality();
 
824
 
 
825
  /// @returns true if the comparison is signed, false otherwise.
 
826
  /// @brief Determine if this instruction is using a signed comparison.
 
827
  bool isSigned() const {
 
828
    return isSigned(getPredicate());
 
829
  }
 
830
 
 
831
  /// @returns true if the comparison is unsigned, false otherwise.
 
832
  /// @brief Determine if this instruction is using an unsigned comparison.
 
833
  bool isUnsigned() const {
 
834
    return isUnsigned(getPredicate());
 
835
  }
 
836
 
 
837
  /// This is just a convenience.
 
838
  /// @brief Determine if this is true when both operands are the same.
 
839
  bool isTrueWhenEqual() const {
 
840
    return isTrueWhenEqual(getPredicate());
 
841
  }
 
842
 
 
843
  /// This is just a convenience.
 
844
  /// @brief Determine if this is false when both operands are the same.
 
845
  bool isFalseWhenEqual() const {
 
846
    return isFalseWhenEqual(getPredicate());
 
847
  }
 
848
 
 
849
  /// @returns true if the predicate is unsigned, false otherwise.
 
850
  /// @brief Determine if the predicate is an unsigned operation.
 
851
  static bool isUnsigned(unsigned short predicate);
 
852
 
 
853
  /// @returns true if the predicate is signed, false otherwise.
 
854
  /// @brief Determine if the predicate is an signed operation.
 
855
  static bool isSigned(unsigned short predicate);
 
856
 
 
857
  /// @brief Determine if the predicate is an ordered operation.
 
858
  static bool isOrdered(unsigned short predicate);
 
859
 
 
860
  /// @brief Determine if the predicate is an unordered operation.
 
861
  static bool isUnordered(unsigned short predicate);
 
862
 
 
863
  /// Determine if the predicate is true when comparing a value with itself.
 
864
  static bool isTrueWhenEqual(unsigned short predicate);
 
865
 
 
866
  /// Determine if the predicate is false when comparing a value with itself.
 
867
  static bool isFalseWhenEqual(unsigned short predicate);
 
868
 
 
869
  /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
 
870
  static inline bool classof(const CmpInst *) { return true; }
 
871
  static inline bool classof(const Instruction *I) {
 
872
    return I->getOpcode() == Instruction::ICmp ||
 
873
           I->getOpcode() == Instruction::FCmp;
 
874
  }
 
875
  static inline bool classof(const Value *V) {
 
876
    return isa<Instruction>(V) && classof(cast<Instruction>(V));
 
877
  }
 
878
  
 
879
  /// @brief Create a result type for fcmp/icmp
 
880
  static const Type* makeCmpResultType(const Type* opnd_type) {
 
881
    if (const VectorType* vt = dyn_cast<const VectorType>(opnd_type)) {
 
882
      return VectorType::get(Type::getInt1Ty(opnd_type->getContext()),
 
883
                             vt->getNumElements());
 
884
    }
 
885
    return Type::getInt1Ty(opnd_type->getContext());
 
886
  }
 
887
private:
 
888
  // Shadow Value::setValueSubclassData with a private forwarding method so that
 
889
  // subclasses cannot accidentally use it.
 
890
  void setValueSubclassData(unsigned short D) {
 
891
    Value::setValueSubclassData(D);
 
892
  }
 
893
};
 
894
 
 
895
 
 
896
// FIXME: these are redundant if CmpInst < BinaryOperator
 
897
template <>
 
898
struct OperandTraits<CmpInst> : public FixedNumOperandTraits<2> {
 
899
};
 
900
 
 
901
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CmpInst, Value)
 
902
 
 
903
} // End llvm namespace
 
904
 
 
905
#endif