LLVM 19.0.0git
InstrTypes.h
Go to the documentation of this file.
1//===- llvm/InstrTypes.h - Important Instruction subclasses -----*- 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 meta classes of instructions that exist in the VM
10// representation. Specific concrete subclasses of these may be found in the
11// i*.h files...
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_IR_INSTRTYPES_H
16#define LLVM_IR_INSTRTYPES_H
17
18#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/STLExtras.h"
20#include "llvm/ADT/Sequence.h"
21#include "llvm/ADT/StringMap.h"
22#include "llvm/ADT/Twine.h"
24#include "llvm/IR/Attributes.h"
25#include "llvm/IR/CallingConv.h"
27#include "llvm/IR/Function.h"
28#include "llvm/IR/Instruction.h"
29#include "llvm/IR/LLVMContext.h"
31#include "llvm/IR/User.h"
32#include <algorithm>
33#include <cassert>
34#include <cstddef>
35#include <cstdint>
36#include <iterator>
37#include <optional>
38#include <string>
39#include <vector>
40
41namespace llvm {
42
43class StringRef;
44class Type;
45class Value;
46
47namespace Intrinsic {
48typedef unsigned ID;
49}
50
51//===----------------------------------------------------------------------===//
52// UnaryInstruction Class
53//===----------------------------------------------------------------------===//
54
56protected:
57 UnaryInstruction(Type *Ty, unsigned iType, Value *V, BasicBlock::iterator IB)
58 : Instruction(Ty, iType, &Op<0>(), 1, IB) {
59 Op<0>() = V;
60 }
61 UnaryInstruction(Type *Ty, unsigned iType, Value *V,
62 Instruction *IB = nullptr)
63 : Instruction(Ty, iType, &Op<0>(), 1, IB) {
64 Op<0>() = V;
65 }
66 UnaryInstruction(Type *Ty, unsigned iType, Value *V, BasicBlock *IAE)
67 : Instruction(Ty, iType, &Op<0>(), 1, IAE) {
68 Op<0>() = V;
69 }
70
71public:
72 // allocate space for exactly one operand
73 void *operator new(size_t S) { return User::operator new(S, 1); }
74 void operator delete(void *Ptr) { User::operator delete(Ptr); }
75
76 /// Transparently provide more efficient getOperand methods.
78
79 // Methods for support type inquiry through isa, cast, and dyn_cast:
80 static bool classof(const Instruction *I) {
81 return I->isUnaryOp() ||
82 I->getOpcode() == Instruction::Alloca ||
83 I->getOpcode() == Instruction::Load ||
84 I->getOpcode() == Instruction::VAArg ||
85 I->getOpcode() == Instruction::ExtractValue ||
86 (I->getOpcode() >= CastOpsBegin && I->getOpcode() < CastOpsEnd);
87 }
88 static bool classof(const Value *V) {
89 return isa<Instruction>(V) && classof(cast<Instruction>(V));
90 }
91};
92
93template <>
95 public FixedNumOperandTraits<UnaryInstruction, 1> {
96};
97
99
100//===----------------------------------------------------------------------===//
101// UnaryOperator Class
102//===----------------------------------------------------------------------===//
103
105 void AssertOK();
106
107protected:
108 UnaryOperator(UnaryOps iType, Value *S, Type *Ty,
109 const Twine &Name, BasicBlock::iterator InsertBefore);
110 UnaryOperator(UnaryOps iType, Value *S, Type *Ty,
111 const Twine &Name, Instruction *InsertBefore);
112 UnaryOperator(UnaryOps iType, Value *S, Type *Ty,
113 const Twine &Name, BasicBlock *InsertAtEnd);
114
115 // Note: Instruction needs to be a friend here to call cloneImpl.
116 friend class Instruction;
117
118 UnaryOperator *cloneImpl() const;
119
120public:
121 /// Construct a unary instruction, given the opcode and an operand.
122 /// Insert the instruction into a BasicBlock right before the specified
123 /// instruction (InsertBefore must be a valid iterator).
124 ///
125 static UnaryOperator *Create(UnaryOps Op, Value *S, const Twine &Name,
126 BasicBlock::iterator InsertBefore);
127
128 /// Construct a unary instruction, given the opcode and an operand.
129 /// Optionally (if InstBefore is specified) insert the instruction
130 /// into a BasicBlock right before the specified instruction. The specified
131 /// Instruction is allowed to be a dereferenced end iterator.
132 ///
133 static UnaryOperator *Create(UnaryOps Op, Value *S,
134 const Twine &Name = Twine(),
135 Instruction *InsertBefore = nullptr);
136
137 /// Construct a unary instruction, given the opcode and an operand.
138 /// Also automatically insert this instruction to the end of the
139 /// BasicBlock specified.
140 ///
141 static UnaryOperator *Create(UnaryOps Op, Value *S,
142 const Twine &Name,
143 BasicBlock *InsertAtEnd);
144
145 /// These methods just forward to Create, and are useful when you
146 /// statically know what type of instruction you're going to create. These
147 /// helpers just save some typing.
148#define HANDLE_UNARY_INST(N, OPC, CLASS) \
149 static UnaryOperator *Create##OPC(Value *V, const Twine &Name = "") {\
150 return Create(Instruction::OPC, V, Name);\
151 }
152#include "llvm/IR/Instruction.def"
153#define HANDLE_UNARY_INST(N, OPC, CLASS) \
154 static UnaryOperator *Create##OPC(Value *V, const Twine &Name, \
155 BasicBlock *BB) {\
156 return Create(Instruction::OPC, V, Name, BB);\
157 }
158#include "llvm/IR/Instruction.def"
159#define HANDLE_UNARY_INST(N, OPC, CLASS) \
160 static UnaryOperator *Create##OPC(Value *V, const Twine &Name, \
161 Instruction *I) {\
162 return Create(Instruction::OPC, V, Name, I);\
163 }
164#include "llvm/IR/Instruction.def"
165#define HANDLE_UNARY_INST(N, OPC, CLASS) \
166 static UnaryOperator *Create##OPC(Value *V, const Twine &Name, \
167 BasicBlock::iterator It) {\
168 return Create(Instruction::OPC, V, Name, It);\
169 }
170#include "llvm/IR/Instruction.def"
171
172 static UnaryOperator *
174 const Twine &Name, BasicBlock::iterator InsertBefore) {
175 UnaryOperator *UO = Create(Opc, V, Name, InsertBefore);
176 UO->copyIRFlags(CopyO);
177 return UO;
178 }
179
180 static UnaryOperator *
182 const Twine &Name = "",
183 Instruction *InsertBefore = nullptr) {
184 UnaryOperator *UO = Create(Opc, V, Name, InsertBefore);
185 UO->copyIRFlags(CopyO);
186 return UO;
187 }
188
190 const Twine &Name,
191 BasicBlock::iterator InsertBefore) {
192 return CreateWithCopiedFlags(Instruction::FNeg, Op, FMFSource, Name,
193 InsertBefore);
194 }
195
197 const Twine &Name = "",
198 Instruction *InsertBefore = nullptr) {
199 return CreateWithCopiedFlags(Instruction::FNeg, Op, FMFSource, Name,
200 InsertBefore);
201 }
202
204 return static_cast<UnaryOps>(Instruction::getOpcode());
205 }
206
207 // Methods for support type inquiry through isa, cast, and dyn_cast:
208 static bool classof(const Instruction *I) {
209 return I->isUnaryOp();
210 }
211 static bool classof(const Value *V) {
212 return isa<Instruction>(V) && classof(cast<Instruction>(V));
213 }
214};
215
216//===----------------------------------------------------------------------===//
217// BinaryOperator Class
218//===----------------------------------------------------------------------===//
219
221 void AssertOK();
222
223protected:
224 BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty,
225 const Twine &Name, BasicBlock::iterator InsertBefore);
226 BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty,
227 const Twine &Name, Instruction *InsertBefore);
228 BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty,
229 const Twine &Name, BasicBlock *InsertAtEnd);
230
231 // Note: Instruction needs to be a friend here to call cloneImpl.
232 friend class Instruction;
233
234 BinaryOperator *cloneImpl() const;
235
236public:
237 // allocate space for exactly two operands
238 void *operator new(size_t S) { return User::operator new(S, 2); }
239 void operator delete(void *Ptr) { User::operator delete(Ptr); }
240
241 /// Transparently provide more efficient getOperand methods.
243
244 /// Construct a binary instruction, given the opcode and the two
245 /// operands. Insert the instruction into a BasicBlock right before the
246 /// specified instruction.
247 ///
249 const Twine &Name,
250 BasicBlock::iterator InsertBefore);
251
252 /// Construct a binary instruction, given the opcode and the two
253 /// operands. Optionally (if InstBefore is specified) insert the instruction
254 /// into a BasicBlock right before the specified instruction. The specified
255 /// Instruction is allowed to be a dereferenced end iterator.
256 ///
258 const Twine &Name = Twine(),
259 Instruction *InsertBefore = nullptr);
260
261 /// Construct a binary instruction, given the opcode and the two
262 /// operands. Also automatically insert this instruction to the end of the
263 /// BasicBlock specified.
264 ///
266 const Twine &Name, BasicBlock *InsertAtEnd);
267
268 /// These methods just forward to Create, and are useful when you
269 /// statically know what type of instruction you're going to create. These
270 /// helpers just save some typing.
271#define HANDLE_BINARY_INST(N, OPC, CLASS) \
272 static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
273 const Twine &Name = "") {\
274 return Create(Instruction::OPC, V1, V2, Name);\
275 }
276#include "llvm/IR/Instruction.def"
277#define HANDLE_BINARY_INST(N, OPC, CLASS) \
278 static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
279 const Twine &Name, BasicBlock *BB) {\
280 return Create(Instruction::OPC, V1, V2, Name, BB);\
281 }
282#include "llvm/IR/Instruction.def"
283#define HANDLE_BINARY_INST(N, OPC, CLASS) \
284 static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
285 const Twine &Name, Instruction *I) {\
286 return Create(Instruction::OPC, V1, V2, Name, I);\
287 }
288#include "llvm/IR/Instruction.def"
289#define HANDLE_BINARY_INST(N, OPC, CLASS) \
290 static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
291 const Twine &Name, BasicBlock::iterator It) {\
292 return Create(Instruction::OPC, V1, V2, Name, It);\
293 }
294#include "llvm/IR/Instruction.def"
295
296 static BinaryOperator *
298 const Twine &Name, BasicBlock::iterator InsertBefore) {
299 BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
300 BO->copyIRFlags(CopyO);
301 return BO;
302 }
303
304 static BinaryOperator *
306 const Twine &Name = "",
307 Instruction *InsertBefore = nullptr) {
308 BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
309 BO->copyIRFlags(CopyO);
310 return BO;
311 }
312
314 Instruction *FMFSource,
315 const Twine &Name = "") {
316 return CreateWithCopiedFlags(Instruction::FAdd, V1, V2, FMFSource, Name);
317 }
319 Instruction *FMFSource,
320 const Twine &Name = "") {
321 return CreateWithCopiedFlags(Instruction::FSub, V1, V2, FMFSource, Name);
322 }
324 Instruction *FMFSource,
325 const Twine &Name = "") {
326 return CreateWithCopiedFlags(Instruction::FMul, V1, V2, FMFSource, Name);
327 }
329 Instruction *FMFSource,
330 const Twine &Name = "") {
331 return CreateWithCopiedFlags(Instruction::FDiv, V1, V2, FMFSource, Name);
332 }
334 Instruction *FMFSource,
335 const Twine &Name = "") {
336 return CreateWithCopiedFlags(Instruction::FRem, V1, V2, FMFSource, Name);
337 }
338
340 const Twine &Name = "") {
341 BinaryOperator *BO = Create(Opc, V1, V2, Name);
342 BO->setHasNoSignedWrap(true);
343 return BO;
344 }
346 const Twine &Name, BasicBlock *BB) {
347 BinaryOperator *BO = Create(Opc, V1, V2, Name, BB);
348 BO->setHasNoSignedWrap(true);
349 return BO;
350 }
352 const Twine &Name, Instruction *I) {
353 BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
354 BO->setHasNoSignedWrap(true);
355 return BO;
356 }
358 const Twine &Name, BasicBlock::iterator It) {
359 BinaryOperator *BO = Create(Opc, V1, V2, Name, It);
360 BO->setHasNoSignedWrap(true);
361 return BO;
362 }
363
365 const Twine &Name = "") {
366 BinaryOperator *BO = Create(Opc, V1, V2, Name);
367 BO->setHasNoUnsignedWrap(true);
368 return BO;
369 }
371 const Twine &Name, BasicBlock *BB) {
372 BinaryOperator *BO = Create(Opc, V1, V2, Name, BB);
373 BO->setHasNoUnsignedWrap(true);
374 return BO;
375 }
377 const Twine &Name, Instruction *I) {
378 BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
379 BO->setHasNoUnsignedWrap(true);
380 return BO;
381 }
383 const Twine &Name, BasicBlock::iterator It) {
384 BinaryOperator *BO = Create(Opc, V1, V2, Name, It);
385 BO->setHasNoUnsignedWrap(true);
386 return BO;
387 }
388
390 const Twine &Name = "") {
391 BinaryOperator *BO = Create(Opc, V1, V2, Name);
392 BO->setIsExact(true);
393 return BO;
394 }
396 const Twine &Name, BasicBlock *BB) {
397 BinaryOperator *BO = Create(Opc, V1, V2, Name, BB);
398 BO->setIsExact(true);
399 return BO;
400 }
402 const Twine &Name, Instruction *I) {
403 BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
404 BO->setIsExact(true);
405 return BO;
406 }
408 const Twine &Name,
410 BinaryOperator *BO = Create(Opc, V1, V2, Name, It);
411 BO->setIsExact(true);
412 return BO;
413 }
414
415 static inline BinaryOperator *
416 CreateDisjoint(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name = "");
417 static inline BinaryOperator *CreateDisjoint(BinaryOps Opc, Value *V1,
418 Value *V2, const Twine &Name,
419 BasicBlock *BB);
420 static inline BinaryOperator *CreateDisjoint(BinaryOps Opc, Value *V1,
421 Value *V2, const Twine &Name,
422 Instruction *I);
423 static inline BinaryOperator *CreateDisjoint(BinaryOps Opc, Value *V1,
424 Value *V2, const Twine &Name,
426
427#define DEFINE_HELPERS(OPC, NUWNSWEXACT) \
428 static BinaryOperator *Create##NUWNSWEXACT##OPC(Value *V1, Value *V2, \
429 const Twine &Name = "") { \
430 return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name); \
431 } \
432 static BinaryOperator *Create##NUWNSWEXACT##OPC( \
433 Value *V1, Value *V2, const Twine &Name, BasicBlock *BB) { \
434 return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name, BB); \
435 } \
436 static BinaryOperator *Create##NUWNSWEXACT##OPC( \
437 Value *V1, Value *V2, const Twine &Name, Instruction *I) { \
438 return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name, I); \
439 } \
440 static BinaryOperator *Create##NUWNSWEXACT##OPC( \
441 Value *V1, Value *V2, const Twine &Name, BasicBlock::iterator It) { \
442 return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name, It); \
443 }
444
445 DEFINE_HELPERS(Add, NSW) // CreateNSWAdd
446 DEFINE_HELPERS(Add, NUW) // CreateNUWAdd
447 DEFINE_HELPERS(Sub, NSW) // CreateNSWSub
448 DEFINE_HELPERS(Sub, NUW) // CreateNUWSub
449 DEFINE_HELPERS(Mul, NSW) // CreateNSWMul
450 DEFINE_HELPERS(Mul, NUW) // CreateNUWMul
451 DEFINE_HELPERS(Shl, NSW) // CreateNSWShl
452 DEFINE_HELPERS(Shl, NUW) // CreateNUWShl
453
454 DEFINE_HELPERS(SDiv, Exact) // CreateExactSDiv
455 DEFINE_HELPERS(UDiv, Exact) // CreateExactUDiv
456 DEFINE_HELPERS(AShr, Exact) // CreateExactAShr
457 DEFINE_HELPERS(LShr, Exact) // CreateExactLShr
458
459 DEFINE_HELPERS(Or, Disjoint) // CreateDisjointOr
460
461#undef DEFINE_HELPERS
462
463 /// Helper functions to construct and inspect unary operations (NEG and NOT)
464 /// via binary operators SUB and XOR:
465 ///
466 /// Create the NEG and NOT instructions out of SUB and XOR instructions.
467 ///
468 static BinaryOperator *CreateNeg(Value *Op, const Twine &Name,
469 BasicBlock::iterator InsertBefore);
470 static BinaryOperator *CreateNeg(Value *Op, const Twine &Name = "",
471 BasicBlock *InsertAtEnd = nullptr);
473 BasicBlock::iterator InsertBefore);
474 static BinaryOperator *CreateNSWNeg(Value *Op, const Twine &Name = "",
475 Instruction *InsertBefore = nullptr);
476 static BinaryOperator *CreateNSWNeg(Value *Op, const Twine &Name,
477 BasicBlock *InsertAtEnd);
479 BasicBlock::iterator InsertBefore);
480 static BinaryOperator *CreateNUWNeg(Value *Op, const Twine &Name = "",
481 Instruction *InsertBefore = nullptr);
482 static BinaryOperator *CreateNUWNeg(Value *Op, const Twine &Name,
483 BasicBlock *InsertAtEnd);
484 static BinaryOperator *CreateNot(Value *Op, const Twine &Name,
485 BasicBlock::iterator InsertBefore);
486 static BinaryOperator *CreateNot(Value *Op, const Twine &Name = "",
487 Instruction *InsertBefore = nullptr);
488 static BinaryOperator *CreateNot(Value *Op, const Twine &Name,
489 BasicBlock *InsertAtEnd);
490
492 return static_cast<BinaryOps>(Instruction::getOpcode());
493 }
494
495 /// Exchange the two operands to this instruction.
496 /// This instruction is safe to use on any binary instruction and
497 /// does not modify the semantics of the instruction. If the instruction
498 /// cannot be reversed (ie, it's a Div), then return true.
499 ///
500 bool swapOperands();
501
502 // Methods for support type inquiry through isa, cast, and dyn_cast:
503 static bool classof(const Instruction *I) {
504 return I->isBinaryOp();
505 }
506 static bool classof(const Value *V) {
507 return isa<Instruction>(V) && classof(cast<Instruction>(V));
508 }
509};
510
511template <>
513 public FixedNumOperandTraits<BinaryOperator, 2> {
514};
515
517
518/// An or instruction, which can be marked as "disjoint", indicating that the
519/// inputs don't have a 1 in the same bit position. Meaning this instruction
520/// can also be treated as an add.
522public:
523 enum { IsDisjoint = (1 << 0) };
524
525 void setIsDisjoint(bool B) {
526 SubclassOptionalData =
527 (SubclassOptionalData & ~IsDisjoint) | (B * IsDisjoint);
528 }
529
530 bool isDisjoint() const { return SubclassOptionalData & IsDisjoint; }
531
532 static bool classof(const Instruction *I) {
533 return I->getOpcode() == Instruction::Or;
534 }
535
536 static bool classof(const Value *V) {
537 return isa<Instruction>(V) && classof(cast<Instruction>(V));
538 }
539};
540
542 Value *V2, const Twine &Name) {
543 BinaryOperator *BO = Create(Opc, V1, V2, Name);
544 cast<PossiblyDisjointInst>(BO)->setIsDisjoint(true);
545 return BO;
546}
548 Value *V2, const Twine &Name,
549 BasicBlock *BB) {
550 BinaryOperator *BO = Create(Opc, V1, V2, Name, BB);
551 cast<PossiblyDisjointInst>(BO)->setIsDisjoint(true);
552 return BO;
553}
555 Value *V2, const Twine &Name,
556 Instruction *I) {
557 BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
558 cast<PossiblyDisjointInst>(BO)->setIsDisjoint(true);
559 return BO;
560}
562 Value *V2, const Twine &Name,
564 BinaryOperator *BO = Create(Opc, V1, V2, Name, It);
565 cast<PossiblyDisjointInst>(BO)->setIsDisjoint(true);
566 return BO;
567}
568
569//===----------------------------------------------------------------------===//
570// CastInst Class
571//===----------------------------------------------------------------------===//
572
573/// This is the base class for all instructions that perform data
574/// casts. It is simply provided so that instruction category testing
575/// can be performed with code like:
576///
577/// if (isa<CastInst>(Instr)) { ... }
578/// Base class of casting instructions.
580protected:
581 /// Constructor with insert-before-instruction semantics for subclasses
582 CastInst(Type *Ty, unsigned iType, Value *S, const Twine &NameStr,
583 BasicBlock::iterator InsertBefore)
584 : UnaryInstruction(Ty, iType, S, InsertBefore) {
585 setName(NameStr);
586 }
587 /// Constructor with insert-before-instruction semantics for subclasses
588 CastInst(Type *Ty, unsigned iType, Value *S,
589 const Twine &NameStr = "", Instruction *InsertBefore = nullptr)
590 : UnaryInstruction(Ty, iType, S, InsertBefore) {
591 setName(NameStr);
592 }
593 /// Constructor with insert-at-end-of-block semantics for subclasses
594 CastInst(Type *Ty, unsigned iType, Value *S,
595 const Twine &NameStr, BasicBlock *InsertAtEnd)
596 : UnaryInstruction(Ty, iType, S, InsertAtEnd) {
597 setName(NameStr);
598 }
599
600public:
601 /// Provides a way to construct any of the CastInst subclasses using an
602 /// opcode instead of the subclass's constructor. The opcode must be in the
603 /// CastOps category (Instruction::isCast(opcode) returns true). This
604 /// constructor has insert-before-instruction semantics to automatically
605 /// insert the new CastInst before InsertBefore, which must be a valid
606 /// iterator. Construct any of the CastInst subclasses.
607 static CastInst *
608 Create(Instruction::CastOps, ///< The opcode of the cast instruction
609 Value *S, ///< The value to be casted (operand 0)
610 Type *Ty, ///< The type to which cast should be made
611 const Twine &Name, ///< Name for the instruction
612 BasicBlock::iterator InsertBefore ///< Place to insert the instruction
613 );
614 /// Provides a way to construct any of the CastInst subclasses using an
615 /// opcode instead of the subclass's constructor. The opcode must be in the
616 /// CastOps category (Instruction::isCast(opcode) returns true). This
617 /// constructor has insert-before-instruction semantics to automatically
618 /// insert the new CastInst before InsertBefore (if it is non-null).
619 /// Construct any of the CastInst subclasses
620 static CastInst *Create(
621 Instruction::CastOps, ///< The opcode of the cast instruction
622 Value *S, ///< The value to be casted (operand 0)
623 Type *Ty, ///< The type to which cast should be made
624 const Twine &Name = "", ///< Name for the instruction
625 Instruction *InsertBefore = nullptr ///< Place to insert the instruction
626 );
627 /// Provides a way to construct any of the CastInst subclasses using an
628 /// opcode instead of the subclass's constructor. The opcode must be in the
629 /// CastOps category. This constructor has insert-at-end-of-block semantics
630 /// to automatically insert the new CastInst at the end of InsertAtEnd (if
631 /// its non-null).
632 /// Construct any of the CastInst subclasses
633 static CastInst *Create(
634 Instruction::CastOps, ///< The opcode for the cast instruction
635 Value *S, ///< The value to be casted (operand 0)
636 Type *Ty, ///< The type to which operand is casted
637 const Twine &Name, ///< The name for the instruction
638 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
639 );
640
641 /// Create a ZExt or BitCast cast instruction
643 Value *S, ///< The value to be casted (operand 0)
644 Type *Ty, ///< The type to which cast should be made
645 const Twine &Name, ///< Name for the instruction
646 BasicBlock::iterator InsertBefore ///< Place to insert the instruction
647 );
648
649 /// Create a ZExt or BitCast cast instruction
651 Value *S, ///< The value to be casted (operand 0)
652 Type *Ty, ///< The type to which cast should be made
653 const Twine &Name = "", ///< Name for the instruction
654 Instruction *InsertBefore = nullptr ///< Place to insert the instruction
655 );
656
657 /// Create a ZExt or BitCast cast instruction
659 Value *S, ///< The value to be casted (operand 0)
660 Type *Ty, ///< The type to which operand is casted
661 const Twine &Name, ///< The name for the instruction
662 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
663 );
664
665 /// Create a SExt or BitCast cast instruction
667 Value *S, ///< The value to be casted (operand 0)
668 Type *Ty, ///< The type to which cast should be made
669 const Twine &Name, ///< Name for the instruction
670 BasicBlock::iterator InsertBefore ///< Place to insert the instruction
671 );
672
673 /// Create a SExt or BitCast cast instruction
675 Value *S, ///< The value to be casted (operand 0)
676 Type *Ty, ///< The type to which cast should be made
677 const Twine &Name = "", ///< Name for the instruction
678 Instruction *InsertBefore = nullptr ///< Place to insert the instruction
679 );
680
681 /// Create a SExt or BitCast cast instruction
683 Value *S, ///< The value to be casted (operand 0)
684 Type *Ty, ///< The type to which operand is casted
685 const Twine &Name, ///< The name for the instruction
686 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
687 );
688
689 /// Create a BitCast AddrSpaceCast, or a PtrToInt cast instruction.
691 Value *S, ///< The pointer value to be casted (operand 0)
692 Type *Ty, ///< The type to which operand is casted
693 const Twine &Name, ///< The name for the instruction
694 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
695 );
696
697 /// Create a BitCast, AddrSpaceCast or a PtrToInt cast instruction.
699 Value *S, ///< The pointer value to be casted (operand 0)
700 Type *Ty, ///< The type to which cast should be made
701 const Twine &Name, ///< Name for the instruction
702 BasicBlock::iterator InsertBefore ///< Place to insert the instruction
703 );
704
705 /// Create a BitCast, AddrSpaceCast or a PtrToInt cast instruction.
707 Value *S, ///< The pointer value to be casted (operand 0)
708 Type *Ty, ///< The type to which cast should be made
709 const Twine &Name = "", ///< Name for the instruction
710 Instruction *InsertBefore = nullptr ///< Place to insert the instruction
711 );
712
713 /// Create a BitCast or an AddrSpaceCast cast instruction.
715 Value *S, ///< The pointer value to be casted (operand 0)
716 Type *Ty, ///< The type to which operand is casted
717 const Twine &Name, ///< The name for the instruction
718 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
719 );
720
721 /// Create a BitCast or an AddrSpaceCast cast instruction.
723 Value *S, ///< The pointer value to be casted (operand 0)
724 Type *Ty, ///< The type to which cast should be made
725 const Twine &Name, ///< Name for the instruction
726 BasicBlock::iterator InsertBefore ///< Place to insert the instruction
727 );
728
729 /// Create a BitCast or an AddrSpaceCast cast instruction.
731 Value *S, ///< The pointer value to be casted (operand 0)
732 Type *Ty, ///< The type to which cast should be made
733 const Twine &Name = "", ///< Name for the instruction
734 Instruction *InsertBefore = nullptr ///< Place to insert the instruction
735 );
736
737 /// Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
738 ///
739 /// If the value is a pointer type and the destination an integer type,
740 /// creates a PtrToInt cast. If the value is an integer type and the
741 /// destination a pointer type, creates an IntToPtr cast. Otherwise, creates
742 /// a bitcast.
744 Value *S, ///< The pointer value to be casted (operand 0)
745 Type *Ty, ///< The type to which cast should be made
746 const Twine &Name, ///< Name for the instruction
747 BasicBlock::iterator InsertBefore ///< Place to insert the instruction
748 );
749
750 /// Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
751 ///
752 /// If the value is a pointer type and the destination an integer type,
753 /// creates a PtrToInt cast. If the value is an integer type and the
754 /// destination a pointer type, creates an IntToPtr cast. Otherwise, creates
755 /// a bitcast.
757 Value *S, ///< The pointer value to be casted (operand 0)
758 Type *Ty, ///< The type to which cast should be made
759 const Twine &Name = "", ///< Name for the instruction
760 Instruction *InsertBefore = nullptr ///< Place to insert the instruction
761 );
762
763 /// Create a ZExt, BitCast, or Trunc for int -> int casts.
765 Value *S, ///< The pointer value to be casted (operand 0)
766 Type *Ty, ///< The type to which cast should be made
767 bool isSigned, ///< Whether to regard S as signed or not
768 const Twine &Name, ///< Name for the instruction
769 BasicBlock::iterator InsertBefore ///< Place to insert the instruction
770 );
771
772 /// Create a ZExt, BitCast, or Trunc for int -> int casts.
774 Value *S, ///< The pointer value to be casted (operand 0)
775 Type *Ty, ///< The type to which cast should be made
776 bool isSigned, ///< Whether to regard S as signed or not
777 const Twine &Name = "", ///< Name for the instruction
778 Instruction *InsertBefore = nullptr ///< Place to insert the instruction
779 );
780
781 /// Create a ZExt, BitCast, or Trunc for int -> int casts.
783 Value *S, ///< The integer value to be casted (operand 0)
784 Type *Ty, ///< The integer type to which operand is casted
785 bool isSigned, ///< Whether to regard S as signed or not
786 const Twine &Name, ///< The name for the instruction
787 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
788 );
789
790 /// Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
791 static CastInst *CreateFPCast(
792 Value *S, ///< The floating point value to be casted
793 Type *Ty, ///< The floating point type to cast to
794 const Twine &Name, ///< Name for the instruction
795 BasicBlock::iterator InsertBefore ///< Place to insert the instruction
796 );
797
798 /// Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
799 static CastInst *CreateFPCast(
800 Value *S, ///< The floating point value to be casted
801 Type *Ty, ///< The floating point type to cast to
802 const Twine &Name = "", ///< Name for the instruction
803 Instruction *InsertBefore = nullptr ///< Place to insert the instruction
804 );
805
806 /// Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
807 static CastInst *CreateFPCast(
808 Value *S, ///< The floating point value to be casted
809 Type *Ty, ///< The floating point type to cast to
810 const Twine &Name, ///< The name for the instruction
811 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
812 );
813
814 /// Create a Trunc or BitCast cast instruction
816 Value *S, ///< The value to be casted (operand 0)
817 Type *Ty, ///< The type to which cast should be made
818 const Twine &Name, ///< Name for the instruction
819 BasicBlock::iterator InsertBefore ///< Place to insert the instruction
820 );
821
822 /// Create a Trunc or BitCast cast instruction
824 Value *S, ///< The value to be casted (operand 0)
825 Type *Ty, ///< The type to which cast should be made
826 const Twine &Name = "", ///< Name for the instruction
827 Instruction *InsertBefore = nullptr ///< Place to insert the instruction
828 );
829
830 /// Create a Trunc or BitCast cast instruction
832 Value *S, ///< The value to be casted (operand 0)
833 Type *Ty, ///< The type to which operand is casted
834 const Twine &Name, ///< The name for the instruction
835 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
836 );
837
838 /// Check whether a bitcast between these types is valid
839 static bool isBitCastable(
840 Type *SrcTy, ///< The Type from which the value should be cast.
841 Type *DestTy ///< The Type to which the value should be cast.
842 );
843
844 /// Check whether a bitcast, inttoptr, or ptrtoint cast between these
845 /// types is valid and a no-op.
846 ///
847 /// This ensures that any pointer<->integer cast has enough bits in the
848 /// integer and any other cast is a bitcast.
849 static bool isBitOrNoopPointerCastable(
850 Type *SrcTy, ///< The Type from which the value should be cast.
851 Type *DestTy, ///< The Type to which the value should be cast.
852 const DataLayout &DL);
853
854 /// Returns the opcode necessary to cast Val into Ty using usual casting
855 /// rules.
856 /// Infer the opcode for cast operand and type
858 const Value *Val, ///< The value to cast
859 bool SrcIsSigned, ///< Whether to treat the source as signed
860 Type *Ty, ///< The Type to which the value should be casted
861 bool DstIsSigned ///< Whether to treate the dest. as signed
862 );
863
864 /// There are several places where we need to know if a cast instruction
865 /// only deals with integer source and destination types. To simplify that
866 /// logic, this method is provided.
867 /// @returns true iff the cast has only integral typed operand and dest type.
868 /// Determine if this is an integer-only cast.
869 bool isIntegerCast() const;
870
871 /// A no-op cast is one that can be effected without changing any bits.
872 /// It implies that the source and destination types are the same size. The
873 /// DataLayout argument is to determine the pointer size when examining casts
874 /// involving Integer and Pointer types. They are no-op casts if the integer
875 /// is the same size as the pointer. However, pointer size varies with
876 /// platform. Note that a precondition of this method is that the cast is
877 /// legal - i.e. the instruction formed with these operands would verify.
878 static bool isNoopCast(
879 Instruction::CastOps Opcode, ///< Opcode of cast
880 Type *SrcTy, ///< SrcTy of cast
881 Type *DstTy, ///< DstTy of cast
882 const DataLayout &DL ///< DataLayout to get the Int Ptr type from.
883 );
884
885 /// Determine if this cast is a no-op cast.
886 ///
887 /// \param DL is the DataLayout to determine pointer size.
888 bool isNoopCast(const DataLayout &DL) const;
889
890 /// Determine how a pair of casts can be eliminated, if they can be at all.
891 /// This is a helper function for both CastInst and ConstantExpr.
892 /// @returns 0 if the CastInst pair can't be eliminated, otherwise
893 /// returns Instruction::CastOps value for a cast that can replace
894 /// the pair, casting SrcTy to DstTy.
895 /// Determine if a cast pair is eliminable
896 static unsigned isEliminableCastPair(
897 Instruction::CastOps firstOpcode, ///< Opcode of first cast
898 Instruction::CastOps secondOpcode, ///< Opcode of second cast
899 Type *SrcTy, ///< SrcTy of 1st cast
900 Type *MidTy, ///< DstTy of 1st cast & SrcTy of 2nd cast
901 Type *DstTy, ///< DstTy of 2nd cast
902 Type *SrcIntPtrTy, ///< Integer type corresponding to Ptr SrcTy, or null
903 Type *MidIntPtrTy, ///< Integer type corresponding to Ptr MidTy, or null
904 Type *DstIntPtrTy ///< Integer type corresponding to Ptr DstTy, or null
905 );
906
907 /// Return the opcode of this CastInst
910 }
911
912 /// Return the source type, as a convenience
913 Type* getSrcTy() const { return getOperand(0)->getType(); }
914 /// Return the destination type, as a convenience
915 Type* getDestTy() const { return getType(); }
916
917 /// This method can be used to determine if a cast from SrcTy to DstTy using
918 /// Opcode op is valid or not.
919 /// @returns true iff the proposed cast is valid.
920 /// Determine if a cast is valid without creating one.
921 static bool castIsValid(Instruction::CastOps op, Type *SrcTy, Type *DstTy);
922 static bool castIsValid(Instruction::CastOps op, Value *S, Type *DstTy) {
923 return castIsValid(op, S->getType(), DstTy);
924 }
925
926 /// Methods for support type inquiry through isa, cast, and dyn_cast:
927 static bool classof(const Instruction *I) {
928 return I->isCast();
929 }
930 static bool classof(const Value *V) {
931 return isa<Instruction>(V) && classof(cast<Instruction>(V));
932 }
933};
934
935/// Instruction that can have a nneg flag (only zext).
937public:
938 enum { NonNeg = (1 << 0) };
939
940 static bool classof(const Instruction *I) {
941 return I->getOpcode() == Instruction::ZExt;
942 }
943
944 static bool classof(const Value *V) {
945 return isa<Instruction>(V) && classof(cast<Instruction>(V));
946 }
947};
948
949//===----------------------------------------------------------------------===//
950// CmpInst Class
951//===----------------------------------------------------------------------===//
952
953/// This class is the base class for the comparison instructions.
954/// Abstract base class of comparison instructions.
955class CmpInst : public Instruction {
956public:
957 /// This enumeration lists the possible predicates for CmpInst subclasses.
958 /// Values in the range 0-31 are reserved for FCmpInst, while values in the
959 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
960 /// predicate values are not overlapping between the classes.
961 ///
962 /// Some passes (e.g. InstCombine) depend on the bit-wise characteristics of
963 /// FCMP_* values. Changing the bit patterns requires a potential change to
964 /// those passes.
965 enum Predicate : unsigned {
966 // Opcode U L G E Intuitive operation
967 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
968 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
969 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
970 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
971 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
972 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
973 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
974 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
975 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
976 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
977 FCMP_UGT = 10, ///< 1 0 1 0 True if unordered or greater than
978 FCMP_UGE = 11, ///< 1 0 1 1 True if unordered, greater than, or equal
979 FCMP_ULT = 12, ///< 1 1 0 0 True if unordered or less than
980 FCMP_ULE = 13, ///< 1 1 0 1 True if unordered, less than, or equal
981 FCMP_UNE = 14, ///< 1 1 1 0 True if unordered or not equal
982 FCMP_TRUE = 15, ///< 1 1 1 1 Always true (always folded)
986 ICMP_EQ = 32, ///< equal
987 ICMP_NE = 33, ///< not equal
988 ICMP_UGT = 34, ///< unsigned greater than
989 ICMP_UGE = 35, ///< unsigned greater or equal
990 ICMP_ULT = 36, ///< unsigned less than
991 ICMP_ULE = 37, ///< unsigned less or equal
992 ICMP_SGT = 38, ///< signed greater than
993 ICMP_SGE = 39, ///< signed greater or equal
994 ICMP_SLT = 40, ///< signed less than
995 ICMP_SLE = 41, ///< signed less or equal
999 };
1002
1003 /// Returns the sequence of all FCmp predicates.
1004 static auto FCmpPredicates() {
1008 }
1009
1010 /// Returns the sequence of all ICmp predicates.
1011 static auto ICmpPredicates() {
1015 }
1016
1017protected:
1019 Value *RHS, const Twine &Name, BasicBlock::iterator InsertBefore,
1020 Instruction *FlagsSource = nullptr);
1021
1023 Value *LHS, Value *RHS, const Twine &Name = "",
1024 Instruction *InsertBefore = nullptr,
1025 Instruction *FlagsSource = nullptr);
1026
1028 Value *LHS, Value *RHS, const Twine &Name,
1029 BasicBlock *InsertAtEnd);
1030
1031public:
1032 // allocate space for exactly two operands
1033 void *operator new(size_t S) { return User::operator new(S, 2); }
1034 void operator delete(void *Ptr) { User::operator delete(Ptr); }
1035
1036 /// Construct a compare instruction, given the opcode, the predicate and
1037 /// the two operands. Insert the instruction into a BasicBlock right before
1038 /// the specified instruction.
1039 /// Create a CmpInst
1040 static CmpInst *Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2,
1041 const Twine &Name, BasicBlock::iterator InsertBefore);
1042
1043 /// Construct a compare instruction, given the opcode, the predicate and
1044 /// the two operands. Optionally (if InstBefore is specified) insert the
1045 /// instruction into a BasicBlock right before the specified instruction.
1046 /// The specified Instruction is allowed to be a dereferenced end iterator.
1047 /// Create a CmpInst
1048 static CmpInst *Create(OtherOps Op,
1049 Predicate predicate, Value *S1,
1050 Value *S2, const Twine &Name = "",
1051 Instruction *InsertBefore = nullptr);
1052
1053 /// Construct a compare instruction, given the opcode, the predicate and the
1054 /// two operands. Also automatically insert this instruction to the end of
1055 /// the BasicBlock specified.
1056 /// Create a CmpInst
1057 static CmpInst *Create(OtherOps Op, Predicate predicate, Value *S1,
1058 Value *S2, const Twine &Name, BasicBlock *InsertAtEnd);
1059
1060 /// Get the opcode casted to the right type
1062 return static_cast<OtherOps>(Instruction::getOpcode());
1063 }
1064
1065 /// Return the predicate for this instruction.
1066 Predicate getPredicate() const { return getSubclassData<PredicateField>(); }
1067
1068 /// Set the predicate for this instruction to the specified value.
1069 void setPredicate(Predicate P) { setSubclassData<PredicateField>(P); }
1070
1072 static_assert(FIRST_FCMP_PREDICATE == 0,
1073 "FIRST_FCMP_PREDICATE is required to be 0");
1074 return P <= LAST_FCMP_PREDICATE;
1075 }
1076
1079 }
1080
1082
1083 bool isFPPredicate() const { return isFPPredicate(getPredicate()); }
1084 bool isIntPredicate() const { return isIntPredicate(getPredicate()); }
1085
1086 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE,
1087 /// OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
1088 /// @returns the inverse predicate for the instruction's current predicate.
1089 /// Return the inverse of the instruction's predicate.
1092 }
1093
1094 /// Returns the ordered variant of a floating point compare.
1095 ///
1096 /// For example, UEQ -> OEQ, ULT -> OLT, OEQ -> OEQ
1098 return static_cast<Predicate>(Pred & FCMP_ORD);
1099 }
1100
1103 }
1104
1105 /// Returns the unordered variant of a floating point compare.
1106 ///
1107 /// For example, OEQ -> UEQ, OLT -> ULT, OEQ -> UEQ
1109 return static_cast<Predicate>(Pred | FCMP_UNO);
1110 }
1111
1114 }
1115
1116 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE,
1117 /// OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
1118 /// @returns the inverse predicate for predicate provided in \p pred.
1119 /// Return the inverse of a given predicate
1121
1122 /// For example, EQ->EQ, SLE->SGE, ULT->UGT,
1123 /// OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
1124 /// @returns the predicate that would be the result of exchanging the two
1125 /// operands of the CmpInst instruction without changing the result
1126 /// produced.
1127 /// Return the predicate as if the operands were swapped
1130 }
1131
1132 /// This is a static version that you can use without an instruction
1133 /// available.
1134 /// Return the predicate as if the operands were swapped.
1136
1137 /// This is a static version that you can use without an instruction
1138 /// available.
1139 /// @returns true if the comparison predicate is strict, false otherwise.
1140 static bool isStrictPredicate(Predicate predicate);
1141
1142 /// @returns true if the comparison predicate is strict, false otherwise.
1143 /// Determine if this instruction is using an strict comparison predicate.
1145
1146 /// This is a static version that you can use without an instruction
1147 /// available.
1148 /// @returns true if the comparison predicate is non-strict, false otherwise.
1149 static bool isNonStrictPredicate(Predicate predicate);
1150
1151 /// @returns true if the comparison predicate is non-strict, false otherwise.
1152 /// Determine if this instruction is using an non-strict comparison predicate.
1155 }
1156
1157 /// For example, SGE -> SGT, SLE -> SLT, ULE -> ULT, UGE -> UGT.
1158 /// Returns the strict version of non-strict comparisons.
1161 }
1162
1163 /// This is a static version that you can use without an instruction
1164 /// available.
1165 /// @returns the strict version of comparison provided in \p pred.
1166 /// If \p pred is not a strict comparison predicate, returns \p pred.
1167 /// Returns the strict version of non-strict comparisons.
1169
1170 /// For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
1171 /// Returns the non-strict version of strict comparisons.
1174 }
1175
1176 /// This is a static version that you can use without an instruction
1177 /// available.
1178 /// @returns the non-strict version of comparison provided in \p pred.
1179 /// If \p pred is not a strict comparison predicate, returns \p pred.
1180 /// Returns the non-strict version of strict comparisons.
1182
1183 /// This is a static version that you can use without an instruction
1184 /// available.
1185 /// Return the flipped strictness of predicate
1187
1188 /// For predicate of kind "is X or equal to 0" returns the predicate "is X".
1189 /// For predicate of kind "is X" returns the predicate "is X or equal to 0".
1190 /// does not support other kind of predicates.
1191 /// @returns the predicate that does not contains is equal to zero if
1192 /// it had and vice versa.
1193 /// Return the flipped strictness of predicate
1196 }
1197
1198 /// Provide more efficient getOperand methods.
1200
1201 /// This is just a convenience that dispatches to the subclasses.
1202 /// Swap the operands and adjust predicate accordingly to retain
1203 /// the same comparison.
1204 void swapOperands();
1205
1206 /// This is just a convenience that dispatches to the subclasses.
1207 /// Determine if this CmpInst is commutative.
1208 bool isCommutative() const;
1209
1210 /// Determine if this is an equals/not equals predicate.
1211 /// This is a static version that you can use without an instruction
1212 /// available.
1213 static bool isEquality(Predicate pred);
1214
1215 /// Determine if this is an equals/not equals predicate.
1216 bool isEquality() const { return isEquality(getPredicate()); }
1217
1218 /// Return true if the predicate is relational (not EQ or NE).
1219 static bool isRelational(Predicate P) { return !isEquality(P); }
1220
1221 /// Return true if the predicate is relational (not EQ or NE).
1222 bool isRelational() const { return !isEquality(); }
1223
1224 /// @returns true if the comparison is signed, false otherwise.
1225 /// Determine if this instruction is using a signed comparison.
1226 bool isSigned() const {
1227 return isSigned(getPredicate());
1228 }
1229
1230 /// @returns true if the comparison is unsigned, false otherwise.
1231 /// Determine if this instruction is using an unsigned comparison.
1232 bool isUnsigned() const {
1233 return isUnsigned(getPredicate());
1234 }
1235
1236 /// For example, ULT->SLT, ULE->SLE, UGT->SGT, UGE->SGE, SLT->Failed assert
1237 /// @returns the signed version of the unsigned predicate pred.
1238 /// return the signed version of a predicate
1240
1241 /// For example, ULT->SLT, ULE->SLE, UGT->SGT, UGE->SGE, SLT->Failed assert
1242 /// @returns the signed version of the predicate for this instruction (which
1243 /// has to be an unsigned predicate).
1244 /// return the signed version of a predicate
1247 }
1248
1249 /// For example, SLT->ULT, SLE->ULE, SGT->UGT, SGE->UGE, ULT->Failed assert
1250 /// @returns the unsigned version of the signed predicate pred.
1252
1253 /// For example, SLT->ULT, SLE->ULE, SGT->UGT, SGE->UGE, ULT->Failed assert
1254 /// @returns the unsigned version of the predicate for this instruction (which
1255 /// has to be an signed predicate).
1256 /// return the unsigned version of a predicate
1259 }
1260
1261 /// For example, SLT->ULT, ULT->SLT, SLE->ULE, ULE->SLE, EQ->Failed assert
1262 /// @returns the unsigned version of the signed predicate pred or
1263 /// the signed version of the signed predicate pred.
1265
1266 /// For example, SLT->ULT, ULT->SLT, SLE->ULE, ULE->SLE, EQ->Failed assert
1267 /// @returns the unsigned version of the signed predicate pred or
1268 /// the signed version of the signed predicate pred.
1271 }
1272
1273 /// This is just a convenience.
1274 /// Determine if this is true when both operands are the same.
1275 bool isTrueWhenEqual() const {
1276 return isTrueWhenEqual(getPredicate());
1277 }
1278
1279 /// This is just a convenience.
1280 /// Determine if this is false when both operands are the same.
1281 bool isFalseWhenEqual() const {
1283 }
1284
1285 /// @returns true if the predicate is unsigned, false otherwise.
1286 /// Determine if the predicate is an unsigned operation.
1287 static bool isUnsigned(Predicate predicate);
1288
1289 /// @returns true if the predicate is signed, false otherwise.
1290 /// Determine if the predicate is an signed operation.
1291 static bool isSigned(Predicate predicate);
1292
1293 /// Determine if the predicate is an ordered operation.
1294 static bool isOrdered(Predicate predicate);
1295
1296 /// Determine if the predicate is an unordered operation.
1297 static bool isUnordered(Predicate predicate);
1298
1299 /// Determine if the predicate is true when comparing a value with itself.
1300 static bool isTrueWhenEqual(Predicate predicate);
1301
1302 /// Determine if the predicate is false when comparing a value with itself.
1303 static bool isFalseWhenEqual(Predicate predicate);
1304
1305 /// Determine if Pred1 implies Pred2 is true when two compares have matching
1306 /// operands.
1307 static bool isImpliedTrueByMatchingCmp(Predicate Pred1, Predicate Pred2);
1308
1309 /// Determine if Pred1 implies Pred2 is false when two compares have matching
1310 /// operands.
1311 static bool isImpliedFalseByMatchingCmp(Predicate Pred1, Predicate Pred2);
1312
1313 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1314 static bool classof(const Instruction *I) {
1315 return I->getOpcode() == Instruction::ICmp ||
1316 I->getOpcode() == Instruction::FCmp;
1317 }
1318 static bool classof(const Value *V) {
1319 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1320 }
1321
1322 /// Create a result type for fcmp/icmp
1323 static Type* makeCmpResultType(Type* opnd_type) {
1324 if (VectorType* vt = dyn_cast<VectorType>(opnd_type)) {
1325 return VectorType::get(Type::getInt1Ty(opnd_type->getContext()),
1326 vt->getElementCount());
1327 }
1328 return Type::getInt1Ty(opnd_type->getContext());
1329 }
1330
1331private:
1332 // Shadow Value::setValueSubclassData with a private forwarding method so that
1333 // subclasses cannot accidentally use it.
1334 void setValueSubclassData(unsigned short D) {
1336 }
1337};
1338
1339// FIXME: these are redundant if CmpInst < BinaryOperator
1340template <>
1341struct OperandTraits<CmpInst> : public FixedNumOperandTraits<CmpInst, 2> {
1342};
1343
1345
1347
1348/// A lightweight accessor for an operand bundle meant to be passed
1349/// around by value.
1352
1353 OperandBundleUse() = default;
1355 : Inputs(Inputs), Tag(Tag) {}
1356
1357 /// Return true if the operand at index \p Idx in this operand bundle
1358 /// has the attribute A.
1359 bool operandHasAttr(unsigned Idx, Attribute::AttrKind A) const {
1361 if (A == Attribute::ReadOnly || A == Attribute::NoCapture)
1362 return Inputs[Idx]->getType()->isPointerTy();
1363
1364 // Conservative answer: no operands have any attributes.
1365 return false;
1366 }
1367
1368 /// Return the tag of this operand bundle as a string.
1370 return Tag->getKey();
1371 }
1372
1373 /// Return the tag of this operand bundle as an integer.
1374 ///
1375 /// Operand bundle tags are interned by LLVMContextImpl::getOrInsertBundleTag,
1376 /// and this function returns the unique integer getOrInsertBundleTag
1377 /// associated the tag of this operand bundle to.
1379 return Tag->getValue();
1380 }
1381
1382 /// Return true if this is a "deopt" operand bundle.
1384 return getTagID() == LLVMContext::OB_deopt;
1385 }
1386
1387 /// Return true if this is a "funclet" operand bundle.
1390 }
1391
1392 /// Return true if this is a "cfguardtarget" operand bundle.
1395 }
1396
1397private:
1398 /// Pointer to an entry in LLVMContextImpl::getOrInsertBundleTag.
1400};
1401
1402/// A container for an operand bundle being viewed as a set of values
1403/// rather than a set of uses.
1404///
1405/// Unlike OperandBundleUse, OperandBundleDefT owns the memory it carries, and
1406/// so it is possible to create and pass around "self-contained" instances of
1407/// OperandBundleDef and ConstOperandBundleDef.
1408template <typename InputTy> class OperandBundleDefT {
1409 std::string Tag;
1410 std::vector<InputTy> Inputs;
1411
1412public:
1413 explicit OperandBundleDefT(std::string Tag, std::vector<InputTy> Inputs)
1414 : Tag(std::move(Tag)), Inputs(std::move(Inputs)) {}
1415 explicit OperandBundleDefT(std::string Tag, ArrayRef<InputTy> Inputs)
1416 : Tag(std::move(Tag)), Inputs(Inputs) {}
1417
1419 Tag = std::string(OBU.getTagName());
1420 llvm::append_range(Inputs, OBU.Inputs);
1421 }
1422
1423 ArrayRef<InputTy> inputs() const { return Inputs; }
1424
1425 using input_iterator = typename std::vector<InputTy>::const_iterator;
1426
1427 size_t input_size() const { return Inputs.size(); }
1428 input_iterator input_begin() const { return Inputs.begin(); }
1429 input_iterator input_end() const { return Inputs.end(); }
1430
1431 StringRef getTag() const { return Tag; }
1432};
1433
1434using OperandBundleDef = OperandBundleDefT<Value *>;
1436
1437//===----------------------------------------------------------------------===//
1438// CallBase Class
1439//===----------------------------------------------------------------------===//
1440
1441/// Base class for all callable instructions (InvokeInst and CallInst)
1442/// Holds everything related to calling a function.
1443///
1444/// All call-like instructions are required to use a common operand layout:
1445/// - Zero or more arguments to the call,
1446/// - Zero or more operand bundles with zero or more operand inputs each
1447/// bundle,
1448/// - Zero or more subclass controlled operands
1449/// - The called function.
1450///
1451/// This allows this base class to easily access the called function and the
1452/// start of the arguments without knowing how many other operands a particular
1453/// subclass requires. Note that accessing the end of the argument list isn't
1454/// as cheap as most other operations on the base class.
1455class CallBase : public Instruction {
1456protected:
1457 // The first two bits are reserved by CallInst for fast retrieval,
1462 static_assert(
1463 Bitfield::areContiguous<CallInstReservedField, CallingConvField>(),
1464 "Bitfields must be contiguous");
1465
1466 /// The last operand is the called operand.
1467 static constexpr int CalledOperandOpEndIdx = -1;
1468
1469 AttributeList Attrs; ///< parameter attributes for callable
1471
1472 template <class... ArgsTy>
1473 CallBase(AttributeList const &A, FunctionType *FT, ArgsTy &&... Args)
1474 : Instruction(std::forward<ArgsTy>(Args)...), Attrs(A), FTy(FT) {}
1475
1477
1478 bool hasDescriptor() const { return Value::HasDescriptor; }
1479
1481 switch (getOpcode()) {
1482 case Instruction::Call:
1483 return 0;
1484 case Instruction::Invoke:
1485 return 2;
1486 case Instruction::CallBr:
1488 }
1489 llvm_unreachable("Invalid opcode!");
1490 }
1491
1492 /// Get the number of extra operands for instructions that don't have a fixed
1493 /// number of extra operands.
1494 unsigned getNumSubclassExtraOperandsDynamic() const;
1495
1496public:
1498
1499 /// Create a clone of \p CB with a different set of operand bundles and
1500 /// insert it before \p InsertPt.
1501 ///
1502 /// The returned call instruction is identical \p CB in every way except that
1503 /// the operand bundles for the new instruction are set to the operand bundles
1504 /// in \p Bundles.
1506 BasicBlock::iterator InsertPt);
1507
1508 /// Create a clone of \p CB with a different set of operand bundles and
1509 /// insert it before \p InsertPt.
1510 ///
1511 /// The returned call instruction is identical \p CB in every way except that
1512 /// the operand bundles for the new instruction are set to the operand bundles
1513 /// in \p Bundles.
1515 Instruction *InsertPt = nullptr);
1516
1517 /// Create a clone of \p CB with the operand bundle with the tag matching
1518 /// \p Bundle's tag replaced with Bundle, and insert it before \p InsertPt.
1519 ///
1520 /// The returned call instruction is identical \p CI in every way except that
1521 /// the specified operand bundle has been replaced.
1523 BasicBlock::iterator InsertPt);
1524
1525 /// Create a clone of \p CB with the operand bundle with the tag matching
1526 /// \p Bundle's tag replaced with Bundle, and insert it before \p InsertPt.
1527 ///
1528 /// The returned call instruction is identical \p CI in every way except that
1529 /// the specified operand bundle has been replaced.
1530 static CallBase *Create(CallBase *CB,
1531 OperandBundleDef Bundle,
1532 Instruction *InsertPt = nullptr);
1533
1534 /// Create a clone of \p CB with operand bundle \p OB added.
1537 Instruction *InsertPt = nullptr);
1538
1539 /// Create a clone of \p CB with operand bundle \p OB added.
1542 BasicBlock::iterator InsertPt);
1543
1544 /// Create a clone of \p CB with operand bundle \p ID removed.
1546 Instruction *InsertPt = nullptr);
1547
1548 /// Create a clone of \p CB with operand bundle \p ID removed.
1550 BasicBlock::iterator InsertPt);
1551
1552 static bool classof(const Instruction *I) {
1553 return I->getOpcode() == Instruction::Call ||
1554 I->getOpcode() == Instruction::Invoke ||
1555 I->getOpcode() == Instruction::CallBr;
1556 }
1557 static bool classof(const Value *V) {
1558 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1559 }
1560
1561 FunctionType *getFunctionType() const { return FTy; }
1562
1565 this->FTy = FTy;
1566 }
1567
1569
1570 /// data_operands_begin/data_operands_end - Return iterators iterating over
1571 /// the call / invoke argument list and bundle operands. For invokes, this is
1572 /// the set of instruction operands except the invoke target and the two
1573 /// successor blocks; and for calls this is the set of instruction operands
1574 /// except the call target.
1577 return const_cast<CallBase *>(this)->data_operands_begin();
1578 }
1580 // Walk from the end of the operands over the called operand and any
1581 // subclass operands.
1582 return op_end() - getNumSubclassExtraOperands() - 1;
1583 }
1585 return const_cast<CallBase *>(this)->data_operands_end();
1586 }
1589 }
1592 }
1593 bool data_operands_empty() const {
1595 }
1596 unsigned data_operands_size() const {
1597 return std::distance(data_operands_begin(), data_operands_end());
1598 }
1599
1600 bool isDataOperand(const Use *U) const {
1601 assert(this == U->getUser() &&
1602 "Only valid to query with a use of this instruction!");
1603 return data_operands_begin() <= U && U < data_operands_end();
1604 }
1606 return isDataOperand(&UI.getUse());
1607 }
1608
1609 /// Given a value use iterator, return the data operand corresponding to it.
1610 /// Iterator must actually correspond to a data operand.
1612 return getDataOperandNo(&UI.getUse());
1613 }
1614
1615 /// Given a use for a data operand, get the data operand number that
1616 /// corresponds to it.
1617 unsigned getDataOperandNo(const Use *U) const {
1618 assert(isDataOperand(U) && "Data operand # out of range!");
1619 return U - data_operands_begin();
1620 }
1621
1622 /// Return the iterator pointing to the beginning of the argument list.
1625 return const_cast<CallBase *>(this)->arg_begin();
1626 }
1627
1628 /// Return the iterator pointing to the end of the argument list.
1630 // From the end of the data operands, walk backwards past the bundle
1631 // operands.
1633 }
1635 return const_cast<CallBase *>(this)->arg_end();
1636 }
1637
1638 /// Iteration adapter for range-for loops.
1640 return make_range(arg_begin(), arg_end());
1641 }
1643 return make_range(arg_begin(), arg_end());
1644 }
1645 bool arg_empty() const { return arg_end() == arg_begin(); }
1646 unsigned arg_size() const { return arg_end() - arg_begin(); }
1647
1648 Value *getArgOperand(unsigned i) const {
1649 assert(i < arg_size() && "Out of bounds!");
1650 return getOperand(i);
1651 }
1652
1653 void setArgOperand(unsigned i, Value *v) {
1654 assert(i < arg_size() && "Out of bounds!");
1655 setOperand(i, v);
1656 }
1657
1658 /// Wrappers for getting the \c Use of a call argument.
1659 const Use &getArgOperandUse(unsigned i) const {
1660 assert(i < arg_size() && "Out of bounds!");
1661 return User::getOperandUse(i);
1662 }
1663 Use &getArgOperandUse(unsigned i) {
1664 assert(i < arg_size() && "Out of bounds!");
1665 return User::getOperandUse(i);
1666 }
1667
1668 bool isArgOperand(const Use *U) const {
1669 assert(this == U->getUser() &&
1670 "Only valid to query with a use of this instruction!");
1671 return arg_begin() <= U && U < arg_end();
1672 }
1674 return isArgOperand(&UI.getUse());
1675 }
1676
1677 /// Given a use for a arg operand, get the arg operand number that
1678 /// corresponds to it.
1679 unsigned getArgOperandNo(const Use *U) const {
1680 assert(isArgOperand(U) && "Arg operand # out of range!");
1681 return U - arg_begin();
1682 }
1683
1684 /// Given a value use iterator, return the arg operand number corresponding to
1685 /// it. Iterator must actually correspond to a data operand.
1687 return getArgOperandNo(&UI.getUse());
1688 }
1689
1690 /// Returns true if this CallSite passes the given Value* as an argument to
1691 /// the called function.
1692 bool hasArgument(const Value *V) const {
1693 return llvm::is_contained(args(), V);
1694 }
1695
1697
1700
1701 /// Returns the function called, or null if this is an indirect function
1702 /// invocation or the function signature does not match the call signature.
1704 if (auto *F = dyn_cast_or_null<Function>(getCalledOperand()))
1705 if (F->getValueType() == getFunctionType())
1706 return F;
1707 return nullptr;
1708 }
1709
1710 /// Return true if the callsite is an indirect call.
1711 bool isIndirectCall() const;
1712
1713 /// Determine whether the passed iterator points to the callee operand's Use.
1715 return isCallee(&UI.getUse());
1716 }
1717
1718 /// Determine whether this Use is the callee operand's Use.
1719 bool isCallee(const Use *U) const { return &getCalledOperandUse() == U; }
1720
1721 /// Helper to get the caller (the parent function).
1723 const Function *getCaller() const {
1724 return const_cast<CallBase *>(this)->getCaller();
1725 }
1726
1727 /// Tests if this call site must be tail call optimized. Only a CallInst can
1728 /// be tail call optimized.
1729 bool isMustTailCall() const;
1730
1731 /// Tests if this call site is marked as a tail call.
1732 bool isTailCall() const;
1733
1734 /// Returns the intrinsic ID of the intrinsic called or
1735 /// Intrinsic::not_intrinsic if the called function is not an intrinsic, or if
1736 /// this is an indirect call.
1738
1740
1741 /// Sets the function called, including updating the function type.
1744 }
1745
1746 /// Sets the function called, including updating the function type.
1749 }
1750
1751 /// Sets the function called, including updating to the specified function
1752 /// type.
1754 this->FTy = FTy;
1755 // This function doesn't mutate the return type, only the function
1756 // type. Seems broken, but I'm just gonna stick an assert in for now.
1758 setCalledOperand(Fn);
1759 }
1760
1762 return getSubclassData<CallingConvField>();
1763 }
1764
1766 setSubclassData<CallingConvField>(CC);
1767 }
1768
1769 /// Check if this call is an inline asm statement.
1770 bool isInlineAsm() const { return isa<InlineAsm>(getCalledOperand()); }
1771
1772 /// \name Attribute API
1773 ///
1774 /// These methods access and modify attributes on this call (including
1775 /// looking through to the attributes on the called function when necessary).
1776 ///@{
1777
1778 /// Return the parameter attributes for this call.
1779 ///
1781
1782 /// Set the parameter attributes for this call.
1783 ///
1785
1786 /// Determine whether this call has the given attribute. If it does not
1787 /// then determine if the called function has the attribute, but only if
1788 /// the attribute is allowed for the call.
1790 assert(Kind != Attribute::NoBuiltin &&
1791 "Use CallBase::isNoBuiltin() to check for Attribute::NoBuiltin");
1792 return hasFnAttrImpl(Kind);
1793 }
1794
1795 /// Determine whether this call has the given attribute. If it does not
1796 /// then determine if the called function has the attribute, but only if
1797 /// the attribute is allowed for the call.
1798 bool hasFnAttr(StringRef Kind) const { return hasFnAttrImpl(Kind); }
1799
1800 // TODO: remove non-AtIndex versions of these methods.
1801 /// adds the attribute to the list of attributes.
1804 }
1805
1806 /// adds the attribute to the list of attributes.
1807 void addAttributeAtIndex(unsigned i, Attribute Attr) {
1809 }
1810
1811 /// Adds the attribute to the function.
1814 }
1815
1816 /// Adds the attribute to the function.
1819 }
1820
1821 /// Adds the attribute to the return value.
1824 }
1825
1826 /// Adds the attribute to the return value.
1829 }
1830
1831 /// Adds the attribute to the indicated argument
1832 void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
1833 assert(ArgNo < arg_size() && "Out of bounds");
1834 Attrs = Attrs.addParamAttribute(getContext(), ArgNo, Kind);
1835 }
1836
1837 /// Adds the attribute to the indicated argument
1838 void addParamAttr(unsigned ArgNo, Attribute Attr) {
1839 assert(ArgNo < arg_size() && "Out of bounds");
1840 Attrs = Attrs.addParamAttribute(getContext(), ArgNo, Attr);
1841 }
1842
1843 /// removes the attribute from the list of attributes.
1846 }
1847
1848 /// removes the attribute from the list of attributes.
1849 void removeAttributeAtIndex(unsigned i, StringRef Kind) {
1851 }
1852
1853 /// Removes the attributes from the function
1854 void removeFnAttrs(const AttributeMask &AttrsToRemove) {
1855 Attrs = Attrs.removeFnAttributes(getContext(), AttrsToRemove);
1856 }
1857
1858 /// Removes the attribute from the function
1861 }
1862
1863 /// Removes the attribute from the function
1866 }
1867
1868 /// Removes the attribute from the return value
1871 }
1872
1873 /// Removes the attributes from the return value
1874 void removeRetAttrs(const AttributeMask &AttrsToRemove) {
1875 Attrs = Attrs.removeRetAttributes(getContext(), AttrsToRemove);
1876 }
1877
1878 /// Removes the attribute from the given argument
1879 void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
1880 assert(ArgNo < arg_size() && "Out of bounds");
1881 Attrs = Attrs.removeParamAttribute(getContext(), ArgNo, Kind);
1882 }
1883
1884 /// Removes the attribute from the given argument
1885 void removeParamAttr(unsigned ArgNo, StringRef Kind) {
1886 assert(ArgNo < arg_size() && "Out of bounds");
1887 Attrs = Attrs.removeParamAttribute(getContext(), ArgNo, Kind);
1888 }
1889
1890 /// Removes the attributes from the given argument
1891 void removeParamAttrs(unsigned ArgNo, const AttributeMask &AttrsToRemove) {
1892 Attrs = Attrs.removeParamAttributes(getContext(), ArgNo, AttrsToRemove);
1893 }
1894
1895 /// adds the dereferenceable attribute to the list of attributes.
1896 void addDereferenceableParamAttr(unsigned i, uint64_t Bytes) {
1898 }
1899
1900 /// adds the dereferenceable attribute to the list of attributes.
1903 }
1904
1905 /// Determine whether the return value has the given attribute.
1907 return hasRetAttrImpl(Kind);
1908 }
1909 /// Determine whether the return value has the given attribute.
1910 bool hasRetAttr(StringRef Kind) const { return hasRetAttrImpl(Kind); }
1911
1912 /// Return the attribute for the given attribute kind for the return value.
1915 if (RetAttr.isValid())
1916 return RetAttr;
1917
1918 // Look at the callee, if available.
1919 if (const Function *F = getCalledFunction())
1920 return F->getAttributes().getRetAttr(Kind);
1921 return Attribute();
1922 }
1923
1924 /// Determine whether the argument or parameter has the given attribute.
1925 bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const;
1926
1927 /// Get the attribute of a given kind at a position.
1929 return getAttributes().getAttributeAtIndex(i, Kind);
1930 }
1931
1932 /// Get the attribute of a given kind at a position.
1933 Attribute getAttributeAtIndex(unsigned i, StringRef Kind) const {
1934 return getAttributes().getAttributeAtIndex(i, Kind);
1935 }
1936
1937 /// Get the attribute of a given kind for the function.
1939 Attribute Attr = getAttributes().getFnAttr(Kind);
1940 if (Attr.isValid())
1941 return Attr;
1942 return getFnAttrOnCalledFunction(Kind);
1943 }
1944
1945 /// Get the attribute of a given kind for the function.
1948 if (A.isValid())
1949 return A;
1950 return getFnAttrOnCalledFunction(Kind);
1951 }
1952
1953 /// Get the attribute of a given kind from a given arg
1954 Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {
1955 assert(ArgNo < arg_size() && "Out of bounds");
1956 return getAttributes().getParamAttr(ArgNo, Kind);
1957 }
1958
1959 /// Get the attribute of a given kind from a given arg
1960 Attribute getParamAttr(unsigned ArgNo, StringRef Kind) const {
1961 assert(ArgNo < arg_size() && "Out of bounds");
1962 return getAttributes().getParamAttr(ArgNo, Kind);
1963 }
1964
1965 /// Return true if the data operand at index \p i has the attribute \p
1966 /// A.
1967 ///
1968 /// Data operands include call arguments and values used in operand bundles,
1969 /// but does not include the callee operand.
1970 ///
1971 /// The index \p i is interpreted as
1972 ///
1973 /// \p i in [0, arg_size) -> argument number (\p i)
1974 /// \p i in [arg_size, data_operand_size) -> bundle operand at index
1975 /// (\p i) in the operand list.
1976 bool dataOperandHasImpliedAttr(unsigned i, Attribute::AttrKind Kind) const {
1977 // Note that we have to add one because `i` isn't zero-indexed.
1979 "Data operand index out of bounds!");
1980
1981 // The attribute A can either be directly specified, if the operand in
1982 // question is a call argument; or be indirectly implied by the kind of its
1983 // containing operand bundle, if the operand is a bundle operand.
1984
1985 if (i < arg_size())
1986 return paramHasAttr(i, Kind);
1987
1989 "Must be either a call argument or an operand bundle!");
1990 return bundleOperandHasAttr(i, Kind);
1991 }
1992
1993 /// Determine whether this data operand is not captured.
1994 // FIXME: Once this API is no longer duplicated in `CallSite`, rename this to
1995 // better indicate that this may return a conservative answer.
1996 bool doesNotCapture(unsigned OpNo) const {
1997 return dataOperandHasImpliedAttr(OpNo, Attribute::NoCapture);
1998 }
1999
2000 /// Determine whether this argument is passed by value.
2001 bool isByValArgument(unsigned ArgNo) const {
2002 return paramHasAttr(ArgNo, Attribute::ByVal);
2003 }
2004
2005 /// Determine whether this argument is passed in an alloca.
2006 bool isInAllocaArgument(unsigned ArgNo) const {
2007 return paramHasAttr(ArgNo, Attribute::InAlloca);
2008 }
2009
2010 /// Determine whether this argument is passed by value, in an alloca, or is
2011 /// preallocated.
2012 bool isPassPointeeByValueArgument(unsigned ArgNo) const {
2013 return paramHasAttr(ArgNo, Attribute::ByVal) ||
2014 paramHasAttr(ArgNo, Attribute::InAlloca) ||
2015 paramHasAttr(ArgNo, Attribute::Preallocated);
2016 }
2017
2018 /// Determine whether passing undef to this argument is undefined behavior.
2019 /// If passing undef to this argument is UB, passing poison is UB as well
2020 /// because poison is more undefined than undef.
2021 bool isPassingUndefUB(unsigned ArgNo) const {
2022 return paramHasAttr(ArgNo, Attribute::NoUndef) ||
2023 // dereferenceable implies noundef.
2024 paramHasAttr(ArgNo, Attribute::Dereferenceable) ||
2025 // dereferenceable implies noundef, and null is a well-defined value.
2026 paramHasAttr(ArgNo, Attribute::DereferenceableOrNull);
2027 }
2028
2029 /// Determine if there are is an inalloca argument. Only the last argument can
2030 /// have the inalloca attribute.
2031 bool hasInAllocaArgument() const {
2032 return !arg_empty() && paramHasAttr(arg_size() - 1, Attribute::InAlloca);
2033 }
2034
2035 // FIXME: Once this API is no longer duplicated in `CallSite`, rename this to
2036 // better indicate that this may return a conservative answer.
2037 bool doesNotAccessMemory(unsigned OpNo) const {
2038 return dataOperandHasImpliedAttr(OpNo, Attribute::ReadNone);
2039 }
2040
2041 // FIXME: Once this API is no longer duplicated in `CallSite`, rename this to
2042 // better indicate that this may return a conservative answer.
2043 bool onlyReadsMemory(unsigned OpNo) const {
2044 return dataOperandHasImpliedAttr(OpNo, Attribute::ReadOnly) ||
2045 dataOperandHasImpliedAttr(OpNo, Attribute::ReadNone);
2046 }
2047
2048 // FIXME: Once this API is no longer duplicated in `CallSite`, rename this to
2049 // better indicate that this may return a conservative answer.
2050 bool onlyWritesMemory(unsigned OpNo) const {
2051 return dataOperandHasImpliedAttr(OpNo, Attribute::WriteOnly) ||
2052 dataOperandHasImpliedAttr(OpNo, Attribute::ReadNone);
2053 }
2054
2055 /// Extract the alignment of the return value.
2057 if (auto Align = Attrs.getRetAlignment())
2058 return Align;
2059 if (const Function *F = getCalledFunction())
2060 return F->getAttributes().getRetAlignment();
2061 return std::nullopt;
2062 }
2063
2064 /// Extract the alignment for a call or parameter (0=unknown).
2065 MaybeAlign getParamAlign(unsigned ArgNo) const {
2066 return Attrs.getParamAlignment(ArgNo);
2067 }
2068
2069 MaybeAlign getParamStackAlign(unsigned ArgNo) const {
2070 return Attrs.getParamStackAlignment(ArgNo);
2071 }
2072
2073 /// Extract the byval type for a call or parameter.
2074 Type *getParamByValType(unsigned ArgNo) const {
2075 if (auto *Ty = Attrs.getParamByValType(ArgNo))
2076 return Ty;
2077 if (const Function *F = getCalledFunction())
2078 return F->getAttributes().getParamByValType(ArgNo);
2079 return nullptr;
2080 }
2081
2082 /// Extract the preallocated type for a call or parameter.
2083 Type *getParamPreallocatedType(unsigned ArgNo) const {
2084 if (auto *Ty = Attrs.getParamPreallocatedType(ArgNo))
2085 return Ty;
2086 if (const Function *F = getCalledFunction())
2087 return F->getAttributes().getParamPreallocatedType(ArgNo);
2088 return nullptr;
2089 }
2090
2091 /// Extract the inalloca type for a call or parameter.
2092 Type *getParamInAllocaType(unsigned ArgNo) const {
2093 if (auto *Ty = Attrs.getParamInAllocaType(ArgNo))
2094 return Ty;
2095 if (const Function *F = getCalledFunction())
2096 return F->getAttributes().getParamInAllocaType(ArgNo);
2097 return nullptr;
2098 }
2099
2100 /// Extract the sret type for a call or parameter.
2101 Type *getParamStructRetType(unsigned ArgNo) const {
2102 if (auto *Ty = Attrs.getParamStructRetType(ArgNo))
2103 return Ty;
2104 if (const Function *F = getCalledFunction())
2105 return F->getAttributes().getParamStructRetType(ArgNo);
2106 return nullptr;
2107 }
2108
2109 /// Extract the elementtype type for a parameter.
2110 /// Note that elementtype() can only be applied to call arguments, not
2111 /// function declaration parameters.
2112 Type *getParamElementType(unsigned ArgNo) const {
2113 return Attrs.getParamElementType(ArgNo);
2114 }
2115
2116 /// Extract the number of dereferenceable bytes for a call or
2117 /// parameter (0=unknown).
2120 if (const Function *F = getCalledFunction())
2121 Bytes = std::max(Bytes, F->getAttributes().getRetDereferenceableBytes());
2122 return Bytes;
2123 }
2124
2125 /// Extract the number of dereferenceable bytes for a call or
2126 /// parameter (0=unknown).
2129 }
2130
2131 /// Extract the number of dereferenceable_or_null bytes for a call
2132 /// (0=unknown).
2135 if (const Function *F = getCalledFunction()) {
2136 Bytes = std::max(Bytes,
2137 F->getAttributes().getRetDereferenceableOrNullBytes());
2138 }
2139
2140 return Bytes;
2141 }
2142
2143 /// Extract the number of dereferenceable_or_null bytes for a
2144 /// parameter (0=unknown).
2147 }
2148
2149 /// Extract a test mask for disallowed floating-point value classes for the
2150 /// return value.
2152
2153 /// Extract a test mask for disallowed floating-point value classes for the
2154 /// parameter.
2155 FPClassTest getParamNoFPClass(unsigned i) const;
2156
2157 /// Return true if the return value is known to be not null.
2158 /// This may be because it has the nonnull attribute, or because at least
2159 /// one byte is dereferenceable and the pointer is in addrspace(0).
2160 bool isReturnNonNull() const;
2161
2162 /// Determine if the return value is marked with NoAlias attribute.
2163 bool returnDoesNotAlias() const {
2164 return Attrs.hasRetAttr(Attribute::NoAlias);
2165 }
2166
2167 /// If one of the arguments has the 'returned' attribute, returns its
2168 /// operand value. Otherwise, return nullptr.
2170 return getArgOperandWithAttribute(Attribute::Returned);
2171 }
2172
2173 /// If one of the arguments has the specified attribute, returns its
2174 /// operand value. Otherwise, return nullptr.
2176
2177 /// Return true if the call should not be treated as a call to a
2178 /// builtin.
2179 bool isNoBuiltin() const {
2180 return hasFnAttrImpl(Attribute::NoBuiltin) &&
2181 !hasFnAttrImpl(Attribute::Builtin);
2182 }
2183
2184 /// Determine if the call requires strict floating point semantics.
2185 bool isStrictFP() const { return hasFnAttr(Attribute::StrictFP); }
2186
2187 /// Return true if the call should not be inlined.
2188 bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
2189 void setIsNoInline() { addFnAttr(Attribute::NoInline); }
2190
2193
2194 /// Determine if the call does not access memory.
2195 bool doesNotAccessMemory() const;
2197
2198 /// Determine if the call does not access or only reads memory.
2199 bool onlyReadsMemory() const;
2200 void setOnlyReadsMemory();
2201
2202 /// Determine if the call does not access or only writes memory.
2203 bool onlyWritesMemory() const;
2204 void setOnlyWritesMemory();
2205
2206 /// Determine if the call can access memmory only using pointers based
2207 /// on its arguments.
2208 bool onlyAccessesArgMemory() const;
2210
2211 /// Determine if the function may only access memory that is
2212 /// inaccessible from the IR.
2213 bool onlyAccessesInaccessibleMemory() const;
2215
2216 /// Determine if the function may only access memory that is
2217 /// either inaccessible from the IR or pointed to by its arguments.
2220
2221 /// Determine if the call cannot return.
2222 bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
2223 void setDoesNotReturn() { addFnAttr(Attribute::NoReturn); }
2224
2225 /// Determine if the call should not perform indirect branch tracking.
2226 bool doesNoCfCheck() const { return hasFnAttr(Attribute::NoCfCheck); }
2227
2228 /// Determine if the call cannot unwind.
2229 bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
2230 void setDoesNotThrow() { addFnAttr(Attribute::NoUnwind); }
2231
2232 /// Determine if the invoke cannot be duplicated.
2233 bool cannotDuplicate() const { return hasFnAttr(Attribute::NoDuplicate); }
2234 void setCannotDuplicate() { addFnAttr(Attribute::NoDuplicate); }
2235
2236 /// Determine if the call cannot be tail merged.
2237 bool cannotMerge() const { return hasFnAttr(Attribute::NoMerge); }
2238 void setCannotMerge() { addFnAttr(Attribute::NoMerge); }
2239
2240 /// Determine if the invoke is convergent
2241 bool isConvergent() const { return hasFnAttr(Attribute::Convergent); }
2242 void setConvergent() { addFnAttr(Attribute::Convergent); }
2243 void setNotConvergent() { removeFnAttr(Attribute::Convergent); }
2244
2245 /// Determine if the call returns a structure through first
2246 /// pointer argument.
2247 bool hasStructRetAttr() const {
2248 if (arg_empty())
2249 return false;
2250
2251 // Be friendly and also check the callee.
2252 return paramHasAttr(0, Attribute::StructRet);
2253 }
2254
2255 /// Determine if any call argument is an aggregate passed by value.
2256 bool hasByValArgument() const {
2257 return Attrs.hasAttrSomewhere(Attribute::ByVal);
2258 }
2259
2260 ///@}
2261 // End of attribute API.
2262
2263 /// \name Operand Bundle API
2264 ///
2265 /// This group of methods provides the API to access and manipulate operand
2266 /// bundles on this call.
2267 /// @{
2268
2269 /// Return the number of operand bundles associated with this User.
2270 unsigned getNumOperandBundles() const {
2271 return std::distance(bundle_op_info_begin(), bundle_op_info_end());
2272 }
2273
2274 /// Return true if this User has any operand bundles.
2275 bool hasOperandBundles() const { return getNumOperandBundles() != 0; }
2276
2277 /// Return the index of the first bundle operand in the Use array.
2279 assert(hasOperandBundles() && "Don't call otherwise!");
2280 return bundle_op_info_begin()->Begin;
2281 }
2282
2283 /// Return the index of the last bundle operand in the Use array.
2284 unsigned getBundleOperandsEndIndex() const {
2285 assert(hasOperandBundles() && "Don't call otherwise!");
2286 return bundle_op_info_end()[-1].End;
2287 }
2288
2289 /// Return true if the operand at index \p Idx is a bundle operand.
2290 bool isBundleOperand(unsigned Idx) const {
2293 }
2294
2295 /// Return true if the operand at index \p Idx is a bundle operand that has
2296 /// tag ID \p ID.
2297 bool isOperandBundleOfType(uint32_t ID, unsigned Idx) const {
2298 return isBundleOperand(Idx) &&
2300 }
2301
2302 /// Returns true if the use is a bundle operand.
2303 bool isBundleOperand(const Use *U) const {
2304 assert(this == U->getUser() &&
2305 "Only valid to query with a use of this instruction!");
2306 return hasOperandBundles() && isBundleOperand(U - op_begin());
2307 }
2309 return isBundleOperand(&UI.getUse());
2310 }
2311
2312 /// Return the total number operands (not operand bundles) used by
2313 /// every operand bundle in this OperandBundleUser.
2314 unsigned getNumTotalBundleOperands() const {
2315 if (!hasOperandBundles())
2316 return 0;
2317
2318 unsigned Begin = getBundleOperandsStartIndex();
2319 unsigned End = getBundleOperandsEndIndex();
2320
2321 assert(Begin <= End && "Should be!");
2322 return End - Begin;
2323 }
2324
2325 /// Return the operand bundle at a specific index.
2327 assert(Index < getNumOperandBundles() && "Index out of bounds!");
2329 }
2330
2331 /// Return the number of operand bundles with the tag Name attached to
2332 /// this instruction.
2334 unsigned Count = 0;
2335 for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i)
2336 if (getOperandBundleAt(i).getTagName() == Name)
2337 Count++;
2338
2339 return Count;
2340 }
2341
2342 /// Return the number of operand bundles with the tag ID attached to
2343 /// this instruction.
2345 unsigned Count = 0;
2346 for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i)
2347 if (getOperandBundleAt(i).getTagID() == ID)
2348 Count++;
2349
2350 return Count;
2351 }
2352
2353 /// Return an operand bundle by name, if present.
2354 ///
2355 /// It is an error to call this for operand bundle types that may have
2356 /// multiple instances of them on the same instruction.
2357 std::optional<OperandBundleUse> getOperandBundle(StringRef Name) const {
2358 assert(countOperandBundlesOfType(Name) < 2 && "Precondition violated!");
2359
2360 for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i) {
2362 if (U.getTagName() == Name)
2363 return U;
2364 }
2365
2366 return std::nullopt;
2367 }
2368
2369 /// Return an operand bundle by tag ID, if present.
2370 ///
2371 /// It is an error to call this for operand bundle types that may have
2372 /// multiple instances of them on the same instruction.
2373 std::optional<OperandBundleUse> getOperandBundle(uint32_t ID) const {
2374 assert(countOperandBundlesOfType(ID) < 2 && "Precondition violated!");
2375
2376 for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i) {
2378 if (U.getTagID() == ID)
2379 return U;
2380 }
2381
2382 return std::nullopt;
2383 }
2384
2385 /// Return the list of operand bundles attached to this instruction as
2386 /// a vector of OperandBundleDefs.
2387 ///
2388 /// This function copies the OperandBundeUse instances associated with this
2389 /// OperandBundleUser to a vector of OperandBundleDefs. Note:
2390 /// OperandBundeUses and OperandBundleDefs are non-trivially *different*
2391 /// representations of operand bundles (see documentation above).
2393
2394 /// Return the operand bundle for the operand at index OpIdx.
2395 ///
2396 /// It is an error to call this with an OpIdx that does not correspond to an
2397 /// bundle operand.
2400 }
2401
2402 /// Return true if this operand bundle user has operand bundles that
2403 /// may read from the heap.
2404 bool hasReadingOperandBundles() const;
2405
2406 /// Return true if this operand bundle user has operand bundles that
2407 /// may write to the heap.
2408 bool hasClobberingOperandBundles() const;
2409
2410 /// Return true if the bundle operand at index \p OpIdx has the
2411 /// attribute \p A.
2412 bool bundleOperandHasAttr(unsigned OpIdx, Attribute::AttrKind A) const {
2413 auto &BOI = getBundleOpInfoForOperand(OpIdx);
2414 auto OBU = operandBundleFromBundleOpInfo(BOI);
2415 return OBU.operandHasAttr(OpIdx - BOI.Begin, A);
2416 }
2417
2418 /// Return true if \p Other has the same sequence of operand bundle
2419 /// tags with the same number of operands on each one of them as this
2420 /// OperandBundleUser.
2422 if (getNumOperandBundles() != Other.getNumOperandBundles())
2423 return false;
2424
2425 return std::equal(bundle_op_info_begin(), bundle_op_info_end(),
2426 Other.bundle_op_info_begin());
2427 }
2428
2429 /// Return true if this operand bundle user contains operand bundles
2430 /// with tags other than those specified in \p IDs.
2432 for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i) {
2434 if (!is_contained(IDs, ID))
2435 return true;
2436 }
2437 return false;
2438 }
2439
2440 /// Used to keep track of an operand bundle. See the main comment on
2441 /// OperandBundleUser above.
2443 /// The operand bundle tag, interned by
2444 /// LLVMContextImpl::getOrInsertBundleTag.
2446
2447 /// The index in the Use& vector where operands for this operand
2448 /// bundle starts.
2450
2451 /// The index in the Use& vector where operands for this operand
2452 /// bundle ends.
2454
2455 bool operator==(const BundleOpInfo &Other) const {
2456 return Tag == Other.Tag && Begin == Other.Begin && End == Other.End;
2457 }
2458 };
2459
2460 /// Simple helper function to map a BundleOpInfo to an
2461 /// OperandBundleUse.
2464 const auto *begin = op_begin();
2465 ArrayRef<Use> Inputs(begin + BOI.Begin, begin + BOI.End);
2466 return OperandBundleUse(BOI.Tag, Inputs);
2467 }
2468
2471
2472 /// Return the start of the list of BundleOpInfo instances associated
2473 /// with this OperandBundleUser.
2474 ///
2475 /// OperandBundleUser uses the descriptor area co-allocated with the host User
2476 /// to store some meta information about which operands are "normal" operands,
2477 /// and which ones belong to some operand bundle.
2478 ///
2479 /// The layout of an operand bundle user is
2480 ///
2481 /// +-----------uint32_t End-------------------------------------+
2482 /// | |
2483 /// | +--------uint32_t Begin--------------------+ |
2484 /// | | | |
2485 /// ^ ^ v v
2486 /// |------|------|----|----|----|----|----|---------|----|---------|----|-----
2487 /// | BOI0 | BOI1 | .. | DU | U0 | U1 | .. | BOI0_U0 | .. | BOI1_U0 | .. | Un
2488 /// |------|------|----|----|----|----|----|---------|----|---------|----|-----
2489 /// v v ^ ^
2490 /// | | | |
2491 /// | +--------uint32_t Begin------------+ |
2492 /// | |
2493 /// +-----------uint32_t End-----------------------------+
2494 ///
2495 ///
2496 /// BOI0, BOI1 ... are descriptions of operand bundles in this User's use
2497 /// list. These descriptions are installed and managed by this class, and
2498 /// they're all instances of OperandBundleUser<T>::BundleOpInfo.
2499 ///
2500 /// DU is an additional descriptor installed by User's 'operator new' to keep
2501 /// track of the 'BOI0 ... BOIN' co-allocation. OperandBundleUser does not
2502 /// access or modify DU in any way, it's an implementation detail private to
2503 /// User.
2504 ///
2505 /// The regular Use& vector for the User starts at U0. The operand bundle
2506 /// uses are part of the Use& vector, just like normal uses. In the diagram
2507 /// above, the operand bundle uses start at BOI0_U0. Each instance of
2508 /// BundleOpInfo has information about a contiguous set of uses constituting
2509 /// an operand bundle, and the total set of operand bundle uses themselves
2510 /// form a contiguous set of uses (i.e. there are no gaps between uses
2511 /// corresponding to individual operand bundles).
2512 ///
2513 /// This class does not know the location of the set of operand bundle uses
2514 /// within the use list -- that is decided by the User using this class via
2515 /// the BeginIdx argument in populateBundleOperandInfos.
2516 ///
2517 /// Currently operand bundle users with hung-off operands are not supported.
2519 if (!hasDescriptor())
2520 return nullptr;
2521
2522 uint8_t *BytesBegin = getDescriptor().begin();
2523 return reinterpret_cast<bundle_op_iterator>(BytesBegin);
2524 }
2525
2526 /// Return the start of the list of BundleOpInfo instances associated
2527 /// with this OperandBundleUser.
2529 auto *NonConstThis = const_cast<CallBase *>(this);
2530 return NonConstThis->bundle_op_info_begin();
2531 }
2532
2533 /// Return the end of the list of BundleOpInfo instances associated
2534 /// with this OperandBundleUser.
2536 if (!hasDescriptor())
2537 return nullptr;
2538
2539 uint8_t *BytesEnd = getDescriptor().end();
2540 return reinterpret_cast<bundle_op_iterator>(BytesEnd);
2541 }
2542
2543 /// Return the end of the list of BundleOpInfo instances associated
2544 /// with this OperandBundleUser.
2546 auto *NonConstThis = const_cast<CallBase *>(this);
2547 return NonConstThis->bundle_op_info_end();
2548 }
2549
2550 /// Return the range [\p bundle_op_info_begin, \p bundle_op_info_end).
2553 }
2554
2555 /// Return the range [\p bundle_op_info_begin, \p bundle_op_info_end).
2558 }
2559
2560 /// Populate the BundleOpInfo instances and the Use& vector from \p
2561 /// Bundles. Return the op_iterator pointing to the Use& one past the last
2562 /// last bundle operand use.
2563 ///
2564 /// Each \p OperandBundleDef instance is tracked by a OperandBundleInfo
2565 /// instance allocated in this User's descriptor.
2567 const unsigned BeginIndex);
2568
2569public:
2570 /// Return the BundleOpInfo for the operand at index OpIdx.
2571 ///
2572 /// It is an error to call this with an OpIdx that does not correspond to an
2573 /// bundle operand.
2574 BundleOpInfo &getBundleOpInfoForOperand(unsigned OpIdx);
2575 const BundleOpInfo &getBundleOpInfoForOperand(unsigned OpIdx) const {
2576 return const_cast<CallBase *>(this)->getBundleOpInfoForOperand(OpIdx);
2577 }
2578
2579protected:
2580 /// Return the total number of values used in \p Bundles.
2582 unsigned Total = 0;
2583 for (const auto &B : Bundles)
2584 Total += B.input_size();
2585 return Total;
2586 }
2587
2588 /// @}
2589 // End of operand bundle API.
2590
2591private:
2592 bool hasFnAttrOnCalledFunction(Attribute::AttrKind Kind) const;
2593 bool hasFnAttrOnCalledFunction(StringRef Kind) const;
2594
2595 template <typename AttrKind> bool hasFnAttrImpl(AttrKind Kind) const {
2596 if (Attrs.hasFnAttr(Kind))
2597 return true;
2598
2599 return hasFnAttrOnCalledFunction(Kind);
2600 }
2601 template <typename AK> Attribute getFnAttrOnCalledFunction(AK Kind) const;
2602
2603 /// Determine whether the return value has the given attribute. Supports
2604 /// Attribute::AttrKind and StringRef as \p AttrKind types.
2605 template <typename AttrKind> bool hasRetAttrImpl(AttrKind Kind) const {
2606 if (Attrs.hasRetAttr(Kind))
2607 return true;
2608
2609 // Look at the callee, if available.
2610 if (const Function *F = getCalledFunction())
2611 return F->getAttributes().hasRetAttr(Kind);
2612 return false;
2613 }
2614};
2615
2616template <>
2617struct OperandTraits<CallBase> : public VariadicOperandTraits<CallBase, 1> {};
2618
2620
2621//===----------------------------------------------------------------------===//
2622// FuncletPadInst Class
2623//===----------------------------------------------------------------------===//
2625private:
2626 FuncletPadInst(const FuncletPadInst &CPI);
2627
2629 ArrayRef<Value *> Args, unsigned Values,
2630 const Twine &NameStr,
2631 BasicBlock::iterator InsertBefore);
2633 ArrayRef<Value *> Args, unsigned Values,
2634 const Twine &NameStr, Instruction *InsertBefore);
2636 ArrayRef<Value *> Args, unsigned Values,
2637 const Twine &NameStr, BasicBlock *InsertAtEnd);
2638
2639 void init(Value *ParentPad, ArrayRef<Value *> Args, const Twine &NameStr);
2640
2641protected:
2642 // Note: Instruction needs to be a friend here to call cloneImpl.
2643 friend class Instruction;
2644 friend class CatchPadInst;
2645 friend class CleanupPadInst;
2646
2647 FuncletPadInst *cloneImpl() const;
2648
2649public:
2650 /// Provide fast operand accessors
2652
2653 /// arg_size - Return the number of funcletpad arguments.
2654 ///
2655 unsigned arg_size() const { return getNumOperands() - 1; }
2656
2657 /// Convenience accessors
2658
2659 /// Return the outer EH-pad this funclet is nested within.
2660 ///
2661 /// Note: This returns the associated CatchSwitchInst if this FuncletPadInst
2662 /// is a CatchPadInst.
2663 Value *getParentPad() const { return Op<-1>(); }
2664 void setParentPad(Value *ParentPad) {
2665 assert(ParentPad);
2666 Op<-1>() = ParentPad;
2667 }
2668
2669 /// getArgOperand/setArgOperand - Return/set the i-th funcletpad argument.
2670 ///
2671 Value *getArgOperand(unsigned i) const { return getOperand(i); }
2672 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2673
2674 /// arg_operands - iteration adapter for range-for loops.
2675 op_range arg_operands() { return op_range(op_begin(), op_end() - 1); }
2676
2677 /// arg_operands - iteration adapter for range-for loops.
2679 return const_op_range(op_begin(), op_end() - 1);
2680 }
2681
2682 // Methods for support type inquiry through isa, cast, and dyn_cast:
2683 static bool classof(const Instruction *I) { return I->isFuncletPad(); }
2684 static bool classof(const Value *V) {
2685 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2686 }
2687};
2688
2689template <>
2691 : public VariadicOperandTraits<FuncletPadInst, /*MINARITY=*/1> {};
2692
2694
2695} // end namespace llvm
2696
2697#endif // LLVM_IR_INSTRTYPES_H
OperandBundleDefT< Value * > OperandBundleDef
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file defines the StringMap class.
static const LLT S1
@ RetAttr
Definition: Attributes.cpp:668
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
RelocType Type
Definition: COFFYAML.cpp:391
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
std::string Name
bool End
Definition: ELF_riscv.cpp:480
static bool isSigned(unsigned int Opcode)
#define op(i)
hexagon gen pred
#define DEFINE_HELPERS(OPC, NUWNSWEXACT)
Definition: InstrTypes.h:427
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
#define P(N)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some templates that are useful if you are working with the STL at all.
raw_pwrite_stream & OS
Provides some synthesis utilities to produce sequences of values.
Value * RHS
Value * LHS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Type * getParamStructRetType(unsigned ArgNo) const
Return the sret type for the specified function parameter.
AttributeList addDereferenceableParamAttr(LLVMContext &C, unsigned ArgNo, uint64_t Bytes) const
Add the dereferenceable attribute to the attribute set at the given arg index.
AttributeList removeAttributeAtIndex(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified index from this attribute list.
AttributeList removeParamAttributes(LLVMContext &C, unsigned ArgNo, const AttributeMask &AttrsToRemove) const
Remove the specified attribute at the specified arg index from this attribute list.
Definition: Attributes.h:708
AttributeList addRetAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Add a return value attribute to the list.
Definition: Attributes.h:567
AttributeList addDereferenceableRetAttr(LLVMContext &C, uint64_t Bytes) const
Add the dereferenceable attribute to the attribute set at the given index.
AttributeList removeRetAttributes(LLVMContext &C, const AttributeMask &AttrsToRemove) const
Remove the specified attribute at the return value index from this attribute list.
Definition: Attributes.h:685
Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return the attribute object that exists at the arg index.
Definition: Attributes.h:832
AttributeList addFnAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Add a function attribute to the list.
Definition: Attributes.h:538
bool hasFnAttr(Attribute::AttrKind Kind) const
Return true if the attribute exists for the function.
uint64_t getParamDereferenceableBytes(unsigned Index) const
Get the number of dereferenceable bytes (or zero if unknown) of an arg.
MaybeAlign getParamAlignment(unsigned ArgNo) const
Return the alignment for the specified function parameter.
bool hasAttrSomewhere(Attribute::AttrKind Kind, unsigned *Index=nullptr) const
Return true if the specified attribute is set for at least one parameter or for the return value.
Type * getParamInAllocaType(unsigned ArgNo) const
Return the inalloca type for the specified function parameter.
Attribute getFnAttr(Attribute::AttrKind Kind) const
Return the attribute object that exists for the function.
Definition: Attributes.h:842
MaybeAlign getRetAlignment() const
Return the alignment of the return value.
Type * getParamElementType(unsigned ArgNo) const
Return the elementtype type for the specified function parameter.
Attribute getAttributeAtIndex(unsigned Index, Attribute::AttrKind Kind) const
Return the attribute object that exists at the given index.
Type * getParamPreallocatedType(unsigned ArgNo) const
Return the preallocated type for the specified function parameter.
AttributeList removeParamAttribute(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified arg index from this attribute list.
Definition: Attributes.h:693
Type * getParamByValType(unsigned ArgNo) const
Return the byval type for the specified function parameter.
Attribute getRetAttr(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind for the return value.
Definition: Attributes.h:852
MaybeAlign getParamStackAlignment(unsigned ArgNo) const
Return the stack alignment for the specified function parameter.
uint64_t getRetDereferenceableBytes() const
Get the number of dereferenceable bytes (or zero if unknown) of the return value.
AttributeList removeFnAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Remove the specified attribute at the function index from this attribute list.
Definition: Attributes.h:644
uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const
Get the number of dereferenceable_or_null bytes (or zero if unknown) of an arg.
AttributeList removeFnAttributes(LLVMContext &C, const AttributeMask &AttrsToRemove) const
Remove the specified attribute at the function index from this attribute list.
Definition: Attributes.h:658
AttributeList addAttributeAtIndex(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Add an attribute to the attribute set at the given index.
uint64_t getRetDereferenceableOrNullBytes() const
Get the number of dereferenceable_or_null bytes (or zero if unknown) of the return value.
AttributeList removeRetAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Remove the specified attribute at the return value index from this attribute list.
Definition: Attributes.h:671
AttributeList addParamAttribute(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const
Add an argument attribute to the list.
Definition: Attributes.h:589
bool hasRetAttr(Attribute::AttrKind Kind) const
Return true if the attribute exists for the return value.
Definition: Attributes.h:798
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition: Attributes.h:85
bool isValid() const
Return true if the attribute is any kind of attribute.
Definition: Attributes.h:193
LLVM Basic Block Representation.
Definition: BasicBlock.h:60
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:164
static BinaryOperator * CreateFDivFMF(Value *V1, Value *V2, Instruction *FMFSource, const Twine &Name="")
Definition: InstrTypes.h:328
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name, BasicBlock::iterator InsertBefore)
Construct a binary instruction, given the opcode and the two operands.
static BinaryOperator * CreateNUW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, Instruction *I)
Definition: InstrTypes.h:376
static BinaryOperator * CreateNSWNeg(Value *Op, const Twine &Name, BasicBlock::iterator InsertBefore)
BinaryOps getOpcode() const
Definition: InstrTypes.h:491
static BinaryOperator * CreateNSW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name="")
Definition: InstrTypes.h:339
static BinaryOperator * CreateNeg(Value *Op, const Twine &Name, BasicBlock::iterator InsertBefore)
Helper functions to construct and inspect unary operations (NEG and NOT) via binary operators SUB and...
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
static bool classof(const Value *V)
Definition: InstrTypes.h:506
static BinaryOperator * CreateWithCopiedFlags(BinaryOps Opc, Value *V1, Value *V2, Value *CopyO, const Twine &Name="", Instruction *InsertBefore=nullptr)
Definition: InstrTypes.h:305
static BinaryOperator * CreateFRemFMF(Value *V1, Value *V2, Instruction *FMFSource, const Twine &Name="")
Definition: InstrTypes.h:333
static BinaryOperator * CreateNSW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, BasicBlock::iterator It)
Definition: InstrTypes.h:357
static BinaryOperator * CreateExact(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name="")
Definition: InstrTypes.h:389
static BinaryOperator * CreateFMulFMF(Value *V1, Value *V2, Instruction *FMFSource, const Twine &Name="")
Definition: InstrTypes.h:323
bool swapOperands()
Exchange the two operands to this instruction.
static BinaryOperator * CreateNUWNeg(Value *Op, const Twine &Name, BasicBlock::iterator InsertBefore)
static BinaryOperator * CreateFSubFMF(Value *V1, Value *V2, Instruction *FMFSource, const Twine &Name="")
Definition: InstrTypes.h:318
static BinaryOperator * CreateNUW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name="")
Definition: InstrTypes.h:364
static BinaryOperator * CreateFAddFMF(Value *V1, Value *V2, Instruction *FMFSource, const Twine &Name="")
Definition: InstrTypes.h:313
static BinaryOperator * CreateExact(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, Instruction *I)
Definition: InstrTypes.h:401
static BinaryOperator * CreateNUW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, BasicBlock::iterator It)
Definition: InstrTypes.h:382
static BinaryOperator * CreateNot(Value *Op, const Twine &Name, BasicBlock::iterator InsertBefore)
static BinaryOperator * CreateExact(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, BasicBlock::iterator It)
Definition: InstrTypes.h:407
static BinaryOperator * CreateNSW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, Instruction *I)
Definition: InstrTypes.h:351
static BinaryOperator * CreateDisjoint(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name="")
Definition: InstrTypes.h:541
static BinaryOperator * CreateExact(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, BasicBlock *BB)
Definition: InstrTypes.h:395
static BinaryOperator * CreateNUW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, BasicBlock *BB)
Definition: InstrTypes.h:370
static BinaryOperator * CreateNSW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, BasicBlock *BB)
Definition: InstrTypes.h:345
static BinaryOperator * CreateWithCopiedFlags(BinaryOps Opc, Value *V1, Value *V2, Value *CopyO, const Twine &Name, BasicBlock::iterator InsertBefore)
Definition: InstrTypes.h:297
BinaryOperator * cloneImpl() const
static bool classof(const Instruction *I)
Definition: InstrTypes.h:503
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1455
MaybeAlign getParamStackAlign(unsigned ArgNo) const
Definition: InstrTypes.h:2069
void setCalledFunction(FunctionType *FTy, Value *Fn)
Sets the function called, including updating to the specified function type.
Definition: InstrTypes.h:1753
FPClassTest getParamNoFPClass(unsigned i) const
Extract a test mask for disallowed floating-point value classes for the parameter.
bool isInlineAsm() const
Check if this call is an inline asm statement.
Definition: InstrTypes.h:1770
void addFnAttr(Attribute Attr)
Adds the attribute to the function.
Definition: InstrTypes.h:1817
bool hasDescriptor() const
Definition: InstrTypes.h:1478
BundleOpInfo & getBundleOpInfoForOperand(unsigned OpIdx)
Return the BundleOpInfo for the operand at index OpIdx.
Attribute getRetAttr(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind for the return value.
Definition: InstrTypes.h:1913
void setCallingConv(CallingConv::ID CC)
Definition: InstrTypes.h:1765
void setDoesNotReturn()
Definition: InstrTypes.h:2223
FPClassTest getRetNoFPClass() const
Extract a test mask for disallowed floating-point value classes for the return value.
bool cannotMerge() const
Determine if the call cannot be tail merged.
Definition: InstrTypes.h:2237
unsigned getBundleOperandsEndIndex() const
Return the index of the last bundle operand in the Use array.
Definition: InstrTypes.h:2284
bundle_op_iterator bundle_op_info_begin()
Return the start of the list of BundleOpInfo instances associated with this OperandBundleUser.
Definition: InstrTypes.h:2518
MemoryEffects getMemoryEffects() const
void setDoesNotThrow()
Definition: InstrTypes.h:2230
bool arg_empty() const
Definition: InstrTypes.h:1645
void addFnAttr(Attribute::AttrKind Kind)
Adds the attribute to the function.
Definition: InstrTypes.h:1812
bool hasInAllocaArgument() const
Determine if there are is an inalloca argument.
Definition: InstrTypes.h:2031
void removeParamAttrs(unsigned ArgNo, const AttributeMask &AttrsToRemove)
Removes the attributes from the given argument.
Definition: InstrTypes.h:1891
bool hasByValArgument() const
Determine if any call argument is an aggregate passed by value.
Definition: InstrTypes.h:2256
bool doesNotAccessMemory() const
Determine if the call does not access memory.
MaybeAlign getRetAlign() const
Extract the alignment of the return value.
Definition: InstrTypes.h:2056
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
void setOnlyAccessesArgMemory()
iterator_range< const_bundle_op_iterator > bundle_op_infos() const
Return the range [bundle_op_info_begin, bundle_op_info_end).
Definition: InstrTypes.h:2556
OperandBundleUse getOperandBundleAt(unsigned Index) const
Return the operand bundle at a specific index.
Definition: InstrTypes.h:2326
OperandBundleUse operandBundleFromBundleOpInfo(const BundleOpInfo &BOI) const
Simple helper function to map a BundleOpInfo to an OperandBundleUse.
Definition: InstrTypes.h:2463
bool isPassingUndefUB(unsigned ArgNo) const
Determine whether passing undef to this argument is undefined behavior.
Definition: InstrTypes.h:2021
bool hasArgument(const Value *V) const
Returns true if this CallSite passes the given Value* as an argument to the called function.
Definition: InstrTypes.h:1692
Type * getParamPreallocatedType(unsigned ArgNo) const
Extract the preallocated type for a call or parameter.
Definition: InstrTypes.h:2083
void setOnlyAccessesInaccessibleMemOrArgMem()
bool data_operands_empty() const
Definition: InstrTypes.h:1593
bool isNoBuiltin() const
Return true if the call should not be treated as a call to a builtin.
Definition: InstrTypes.h:2179
bool isOperandBundleOfType(uint32_t ID, unsigned Idx) const
Return true if the operand at index Idx is a bundle operand that has tag ID ID.
Definition: InstrTypes.h:2297
void addAttributeAtIndex(unsigned i, Attribute Attr)
adds the attribute to the list of attributes.
Definition: InstrTypes.h:1807
unsigned getDataOperandNo(const Use *U) const
Given a use for a data operand, get the data operand number that corresponds to it.
Definition: InstrTypes.h:1617
std::optional< OperandBundleUse > getOperandBundle(StringRef Name) const
Return an operand bundle by name, if present.
Definition: InstrTypes.h:2357
bool doesNotCapture(unsigned OpNo) const
Determine whether this data operand is not captured.
Definition: InstrTypes.h:1996
Type * getParamStructRetType(unsigned ArgNo) const
Extract the sret type for a call or parameter.
Definition: InstrTypes.h:2101
Attribute getParamAttr(unsigned ArgNo, StringRef Kind) const
Get the attribute of a given kind from a given arg.
Definition: InstrTypes.h:1960
void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Removes the attribute from the given argument.
Definition: InstrTypes.h:1879
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Definition: InstrTypes.h:1703
Type * getParamInAllocaType(unsigned ArgNo) const
Extract the inalloca type for a call or parameter.
Definition: InstrTypes.h:2092
bool doesNotAccessMemory(unsigned OpNo) const
Definition: InstrTypes.h:2037
void removeRetAttrs(const AttributeMask &AttrsToRemove)
Removes the attributes from the return value.
Definition: InstrTypes.h:1874
void setDoesNotAccessMemory()
bool isInAllocaArgument(unsigned ArgNo) const
Determine whether this argument is passed in an alloca.
Definition: InstrTypes.h:2006
Use & getArgOperandUse(unsigned i)
Definition: InstrTypes.h:1663
bool hasFnAttr(Attribute::AttrKind Kind) const
Determine whether this call has the given attribute.
Definition: InstrTypes.h:1789
bool isStrictFP() const
Determine if the call requires strict floating point semantics.
Definition: InstrTypes.h:2185
User::op_iterator data_operands_begin()
data_operands_begin/data_operands_end - Return iterators iterating over the call / invoke argument li...
Definition: InstrTypes.h:1575
bool cannotDuplicate() const
Determine if the invoke cannot be duplicated.
Definition: InstrTypes.h:2233
bool hasRetAttr(Attribute::AttrKind Kind) const
Determine whether the return value has the given attribute.
Definition: InstrTypes.h:1906
User::const_op_iterator data_operands_end() const
Definition: InstrTypes.h:1584
bool onlyAccessesInaccessibleMemory() const
Determine if the function may only access memory that is inaccessible from the IR.
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
Definition: InstrTypes.h:2270
uint64_t getParamDereferenceableBytes(unsigned i) const
Extract the number of dereferenceable bytes for a call or parameter (0=unknown).
Definition: InstrTypes.h:2127
void removeAttributeAtIndex(unsigned i, StringRef Kind)
removes the attribute from the list of attributes.
Definition: InstrTypes.h:1849
unsigned getDataOperandNo(Value::const_user_iterator UI) const
Given a value use iterator, return the data operand corresponding to it.
Definition: InstrTypes.h:1611
CallingConv::ID getCallingConv() const
Definition: InstrTypes.h:1761
bundle_op_iterator bundle_op_info_end()
Return the end of the list of BundleOpInfo instances associated with this OperandBundleUser.
Definition: InstrTypes.h:2535
unsigned getNumSubclassExtraOperandsDynamic() const
Get the number of extra operands for instructions that don't have a fixed number of extra operands.
void addParamAttr(unsigned ArgNo, Attribute Attr)
Adds the attribute to the indicated argument.
Definition: InstrTypes.h:1838
unsigned getNumSubclassExtraOperands() const
Definition: InstrTypes.h:1480
bool doesNoCfCheck() const
Determine if the call should not perform indirect branch tracking.
Definition: InstrTypes.h:2226
bool hasFnAttr(StringRef Kind) const
Determine whether this call has the given attribute.
Definition: InstrTypes.h:1798
bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Determine whether the argument or parameter has the given attribute.
bool hasIdenticalOperandBundleSchema(const CallBase &Other) const
Return true if Other has the same sequence of operand bundle tags with the same number of operands on...
Definition: InstrTypes.h:2421
User::const_op_iterator arg_begin() const
Definition: InstrTypes.h:1624
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
Definition: InstrTypes.h:1623
bool isMustTailCall() const
Tests if this call site must be tail call optimized.
Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Get the attribute of a given kind from a given arg.
Definition: InstrTypes.h:1954
bool hasRetAttr(StringRef Kind) const
Determine whether the return value has the given attribute.
Definition: InstrTypes.h:1910
static bool classof(const Instruction *I)
Definition: InstrTypes.h:1552
bool isDataOperand(Value::const_user_iterator UI) const
Definition: InstrTypes.h:1605
Use & getCalledOperandUse()
Definition: InstrTypes.h:1699
bool isIndirectCall() const
Return true if the callsite is an indirect call.
bool isNoInline() const
Return true if the call should not be inlined.
Definition: InstrTypes.h:2188
bool dataOperandHasImpliedAttr(unsigned i, Attribute::AttrKind Kind) const
Return true if the data operand at index i has the attribute A.
Definition: InstrTypes.h:1976
static constexpr int CalledOperandOpEndIdx
The last operand is the called operand.
Definition: InstrTypes.h:1467
bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
bool isBundleOperand(const Use *U) const
Returns true if the use is a bundle operand.
Definition: InstrTypes.h:2303
bool isByValArgument(unsigned ArgNo) const
Determine whether this argument is passed by value.
Definition: InstrTypes.h:2001
iterator_range< bundle_op_iterator > bundle_op_infos()
Return the range [bundle_op_info_begin, bundle_op_info_end).
Definition: InstrTypes.h:2551
bool onlyWritesMemory(unsigned OpNo) const
Definition: InstrTypes.h:2050
unsigned countOperandBundlesOfType(StringRef Name) const
Return the number of operand bundles with the tag Name attached to this instruction.
Definition: InstrTypes.h:2333
void setOnlyReadsMemory()
void removeFnAttrs(const AttributeMask &AttrsToRemove)
Removes the attributes from the function.
Definition: InstrTypes.h:1854
iterator_range< User::op_iterator > data_ops()
Definition: InstrTypes.h:1587
const_bundle_op_iterator bundle_op_info_begin() const
Return the start of the list of BundleOpInfo instances associated with this OperandBundleUser.
Definition: InstrTypes.h:2528
void setCannotMerge()
Definition: InstrTypes.h:2238
bool isCallee(Value::const_user_iterator UI) const
Determine whether the passed iterator points to the callee operand's Use.
Definition: InstrTypes.h:1714
iterator_range< User::const_op_iterator > args() const
Definition: InstrTypes.h:1642
MaybeAlign getParamAlign(unsigned ArgNo) const
Extract the alignment for a call or parameter (0=unknown).
Definition: InstrTypes.h:2065
unsigned getBundleOperandsStartIndex() const
Return the index of the first bundle operand in the Use array.
Definition: InstrTypes.h:2278
bool onlyAccessesInaccessibleMemOrArgMem() const
Determine if the function may only access memory that is either inaccessible from the IR or pointed t...
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
static CallBase * Create(CallBase *CB, ArrayRef< OperandBundleDef > Bundles, BasicBlock::iterator InsertPt)
Create a clone of CB with a different set of operand bundles and insert it before InsertPt.
Attribute getFnAttr(Attribute::AttrKind Kind) const
Get the attribute of a given kind for the function.
Definition: InstrTypes.h:1946
User::op_iterator data_operands_end()
Definition: InstrTypes.h:1579
static CallBase * removeOperandBundle(CallBase *CB, uint32_t ID, Instruction *InsertPt=nullptr)
Create a clone of CB with operand bundle ID removed.
bool onlyReadsMemory(unsigned OpNo) const
Definition: InstrTypes.h:2043
void setNotConvergent()
Definition: InstrTypes.h:2243
Type * getParamByValType(unsigned ArgNo) const
Extract the byval type for a call or parameter.
Definition: InstrTypes.h:2074
bool isCallee(const Use *U) const
Determine whether this Use is the callee operand's Use.
Definition: InstrTypes.h:1719
CallBase(AttributeList const &A, FunctionType *FT, ArgsTy &&... Args)
Definition: InstrTypes.h:1473
const BundleOpInfo & getBundleOpInfoForOperand(unsigned OpIdx) const
Definition: InstrTypes.h:2575
Value * getCalledOperand() const
Definition: InstrTypes.h:1696
void setCalledFunction(FunctionCallee Fn)
Sets the function called, including updating the function type.
Definition: InstrTypes.h:1747
const Use & getCalledOperandUse() const
Definition: InstrTypes.h:1698
bool isArgOperand(Value::const_user_iterator UI) const
Definition: InstrTypes.h:1673
void setOnlyWritesMemory()
op_iterator populateBundleOperandInfos(ArrayRef< OperandBundleDef > Bundles, const unsigned BeginIndex)
Populate the BundleOpInfo instances and the Use& vector from Bundles.
void removeRetAttr(Attribute::AttrKind Kind)
Removes the attribute from the return value.
Definition: InstrTypes.h:1869
AttributeList Attrs
parameter attributes for callable
Definition: InstrTypes.h:1469
void addDereferenceableRetAttr(uint64_t Bytes)
adds the dereferenceable attribute to the list of attributes.
Definition: InstrTypes.h:1901
unsigned getArgOperandNo(Value::const_user_iterator UI) const
Given a value use iterator, return the arg operand number corresponding to it.
Definition: InstrTypes.h:1686
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
Definition: InstrTypes.h:1784
Attribute getFnAttr(StringRef Kind) const
Get the attribute of a given kind for the function.
Definition: InstrTypes.h:1938
void addAttributeAtIndex(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
Definition: InstrTypes.h:1802
unsigned countOperandBundlesOfType(uint32_t ID) const
Return the number of operand bundles with the tag ID attached to this instruction.
Definition: InstrTypes.h:2344
const Use & getArgOperandUse(unsigned i) const
Wrappers for getting the Use of a call argument.
Definition: InstrTypes.h:1659
bool hasOperandBundlesOtherThan(ArrayRef< uint32_t > IDs) const
Return true if this operand bundle user contains operand bundles with tags other than those specified...
Definition: InstrTypes.h:2431
static CallBase * Create(CallBase *CB, OperandBundleDef Bundle, BasicBlock::iterator InsertPt)
Create a clone of CB with the operand bundle with the tag matching Bundle's tag replaced with Bundle,...
bool returnDoesNotAlias() const
Determine if the return value is marked with NoAlias attribute.
Definition: InstrTypes.h:2163
OperandBundleUse getOperandBundleForOperand(unsigned OpIdx) const
Return the operand bundle for the operand at index OpIdx.
Definition: InstrTypes.h:2398
bool doesNotThrow() const
Determine if the call cannot unwind.
Definition: InstrTypes.h:2229
void addRetAttr(Attribute::AttrKind Kind)
Adds the attribute to the return value.
Definition: InstrTypes.h:1822
Type * getParamElementType(unsigned ArgNo) const
Extract the elementtype type for a parameter.
Definition: InstrTypes.h:2112
bool isReturnNonNull() const
Return true if the return value is known to be not null.
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1648
FunctionType * FTy
Definition: InstrTypes.h:1470
bool hasStructRetAttr() const
Determine if the call returns a structure through first pointer argument.
Definition: InstrTypes.h:2247
uint64_t getRetDereferenceableBytes() const
Extract the number of dereferenceable bytes for a call or parameter (0=unknown).
Definition: InstrTypes.h:2118
void removeAttributeAtIndex(unsigned i, Attribute::AttrKind Kind)
removes the attribute from the list of attributes.
Definition: InstrTypes.h:1844
void setCannotDuplicate()
Definition: InstrTypes.h:2234
User::const_op_iterator data_operands_begin() const
Definition: InstrTypes.h:1576
void mutateFunctionType(FunctionType *FTy)
Definition: InstrTypes.h:1563
uint64_t getParamDereferenceableOrNullBytes(unsigned i) const
Extract the number of dereferenceable_or_null bytes for a parameter (0=unknown).
Definition: InstrTypes.h:2145
void setArgOperand(unsigned i, Value *v)
Definition: InstrTypes.h:1653
Attribute getAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) const
Get the attribute of a given kind at a position.
Definition: InstrTypes.h:1928
bool bundleOperandHasAttr(unsigned OpIdx, Attribute::AttrKind A) const
Return true if the bundle operand at index OpIdx has the attribute A.
Definition: InstrTypes.h:2412
User::op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
Definition: InstrTypes.h:1629
bool isBundleOperand(unsigned Idx) const
Return true if the operand at index Idx is a bundle operand.
Definition: InstrTypes.h:2290
bool isConvergent() const
Determine if the invoke is convergent.
Definition: InstrTypes.h:2241
FunctionType * getFunctionType() const
Definition: InstrTypes.h:1561
Intrinsic::ID getIntrinsicID() const
Returns the intrinsic ID of the intrinsic called or Intrinsic::not_intrinsic if the called function i...
void setIsNoInline()
Definition: InstrTypes.h:2189
static unsigned CountBundleInputs(ArrayRef< OperandBundleDef > Bundles)
Return the total number of values used in Bundles.
Definition: InstrTypes.h:2581
Value * getArgOperandWithAttribute(Attribute::AttrKind Kind) const
If one of the arguments has the specified attribute, returns its operand value.
Value * getReturnedArgOperand() const
If one of the arguments has the 'returned' attribute, returns its operand value.
Definition: InstrTypes.h:2169
void setOnlyAccessesInaccessibleMemory()
bool onlyWritesMemory() const
Determine if the call does not access or only writes memory.
unsigned data_operands_size() const
Definition: InstrTypes.h:1596
void removeFnAttr(Attribute::AttrKind Kind)
Removes the attribute from the function.
Definition: InstrTypes.h:1859
uint64_t getRetDereferenceableOrNullBytes() const
Extract the number of dereferenceable_or_null bytes for a call (0=unknown).
Definition: InstrTypes.h:2133
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
Definition: InstrTypes.h:1639
unsigned getArgOperandNo(const Use *U) const
Given a use for a arg operand, get the arg operand number that corresponds to it.
Definition: InstrTypes.h:1679
bool isBundleOperand(Value::const_user_iterator UI) const
Definition: InstrTypes.h:2308
bool hasClobberingOperandBundles() const
Return true if this operand bundle user has operand bundles that may write to the heap.
static bool classof(const Value *V)
Definition: InstrTypes.h:1557
void setCalledOperand(Value *V)
Definition: InstrTypes.h:1739
bool doesNotReturn() const
Determine if the call cannot return.
Definition: InstrTypes.h:2222
bool hasReadingOperandBundles() const
Return true if this operand bundle user has operand bundles that may read from the heap.
void removeFnAttr(StringRef Kind)
Removes the attribute from the function.
Definition: InstrTypes.h:1864
void setConvergent()
Definition: InstrTypes.h:2242
bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
unsigned arg_size() const
Definition: InstrTypes.h:1646
void addDereferenceableParamAttr(unsigned i, uint64_t Bytes)
adds the dereferenceable attribute to the list of attributes.
Definition: InstrTypes.h:1896
AttributeList getAttributes() const
Return the parameter attributes for this call.
Definition: InstrTypes.h:1780
std::optional< OperandBundleUse > getOperandBundle(uint32_t ID) const
Return an operand bundle by tag ID, if present.
Definition: InstrTypes.h:2373
void addRetAttr(Attribute Attr)
Adds the attribute to the return value.
Definition: InstrTypes.h:1827
static CallBase * addOperandBundle(CallBase *CB, uint32_t ID, OperandBundleDef OB, Instruction *InsertPt=nullptr)
Create a clone of CB with operand bundle OB added.
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Adds the attribute to the indicated argument.
Definition: InstrTypes.h:1832
iterator_range< User::const_op_iterator > data_ops() const
Definition: InstrTypes.h:1590
bool isArgOperand(const Use *U) const
Definition: InstrTypes.h:1668
bool isDataOperand(const Use *U) const
Definition: InstrTypes.h:1600
void setMemoryEffects(MemoryEffects ME)
bool hasOperandBundles() const
Return true if this User has any operand bundles.
Definition: InstrTypes.h:2275
void setCalledFunction(Function *Fn)
Sets the function called, including updating the function type.
Definition: InstrTypes.h:1742
const_bundle_op_iterator bundle_op_info_end() const
Return the end of the list of BundleOpInfo instances associated with this OperandBundleUser.
Definition: InstrTypes.h:2545
bool isPassPointeeByValueArgument(unsigned ArgNo) const
Determine whether this argument is passed by value, in an alloca, or is preallocated.
Definition: InstrTypes.h:2012
bool isTailCall() const
Tests if this call site is marked as a tail call.
const Function * getCaller() const
Definition: InstrTypes.h:1723
void removeParamAttr(unsigned ArgNo, StringRef Kind)
Removes the attribute from the given argument.
Definition: InstrTypes.h:1885
User::const_op_iterator arg_end() const
Definition: InstrTypes.h:1634
Function * getCaller()
Helper to get the caller (the parent function).
unsigned getNumTotalBundleOperands() const
Return the total number operands (not operand bundles) used by every operand bundle in this OperandBu...
Definition: InstrTypes.h:2314
Attribute getAttributeAtIndex(unsigned i, StringRef Kind) const
Get the attribute of a given kind at a position.
Definition: InstrTypes.h:1933
This is the base class for all instructions that perform data casts.
Definition: InstrTypes.h:579
Type * getSrcTy() const
Return the source type, as a convenience.
Definition: InstrTypes.h:913
static Instruction::CastOps getCastOpcode(const Value *Val, bool SrcIsSigned, Type *Ty, bool DstIsSigned)
Returns the opcode necessary to cast Val into Ty using usual casting rules.
static CastInst * CreateFPCast(Value *S, Type *Ty, const Twine &Name, BasicBlock::iterator InsertBefore)
Create an FPExt, BitCast, or FPTrunc for fp -> fp casts.
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
Definition: InstrTypes.h:908
CastInst(Type *Ty, unsigned iType, Value *S, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics for subclasses.
Definition: InstrTypes.h:588
static CastInst * CreateZExtOrBitCast(Value *S, Type *Ty, const Twine &Name, BasicBlock::iterator InsertBefore)
Create a ZExt or BitCast cast instruction.
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name, BasicBlock::iterator InsertBefore)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
static bool classof(const Value *V)
Definition: InstrTypes.h:930
CastInst(Type *Ty, unsigned iType, Value *S, const Twine &NameStr, BasicBlock *InsertAtEnd)
Constructor with insert-at-end-of-block semantics for subclasses.
Definition: InstrTypes.h:594
CastInst(Type *Ty, unsigned iType, Value *S, const Twine &NameStr, BasicBlock::iterator InsertBefore)
Constructor with insert-before-instruction semantics for subclasses.
Definition: InstrTypes.h:582
static unsigned isEliminableCastPair(Instruction::CastOps firstOpcode, Instruction::CastOps secondOpcode, Type *SrcTy, Type *MidTy, Type *DstTy, Type *SrcIntPtrTy, Type *MidIntPtrTy, Type *DstIntPtrTy)
Determine how a pair of casts can be eliminated, if they can be at all.
static bool isBitOrNoopPointerCastable(Type *SrcTy, Type *DestTy, const DataLayout &DL)
Check whether a bitcast, inttoptr, or ptrtoint cast between these types is valid and a no-op.
static bool castIsValid(Instruction::CastOps op, Value *S, Type *DstTy)
Definition: InstrTypes.h:922
static CastInst * CreatePointerBitCastOrAddrSpaceCast(Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd)
Create a BitCast or an AddrSpaceCast cast instruction.
static bool isBitCastable(Type *SrcTy, Type *DestTy)
Check whether a bitcast between these types is valid.
static CastInst * CreatePointerCast(Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd)
Create a BitCast AddrSpaceCast, or a PtrToInt cast instruction.
static bool isNoopCast(Instruction::CastOps Opcode, Type *SrcTy, Type *DstTy, const DataLayout &DL)
A no-op cast is one that can be effected without changing any bits.
static CastInst * CreateBitOrPointerCast(Value *S, Type *Ty, const Twine &Name, BasicBlock::iterator InsertBefore)
Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
static CastInst * CreateTruncOrBitCast(Value *S, Type *Ty, const Twine &Name, BasicBlock::iterator InsertBefore)
Create a Trunc or BitCast cast instruction.
static CastInst * CreateSExtOrBitCast(Value *S, Type *Ty, const Twine &Name, BasicBlock::iterator InsertBefore)
Create a SExt or BitCast cast instruction.
bool isIntegerCast() const
There are several places where we need to know if a cast instruction only deals with integer source a...
Type * getDestTy() const
Return the destination type, as a convenience.
Definition: InstrTypes.h:915
static CastInst * CreateIntegerCast(Value *S, Type *Ty, bool isSigned, const Twine &Name, BasicBlock::iterator InsertBefore)
Create a ZExt, BitCast, or Trunc for int -> int casts.
static bool castIsValid(Instruction::CastOps op, Type *SrcTy, Type *DstTy)
This method can be used to determine if a cast from SrcTy to DstTy using Opcode op is valid or not.
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: InstrTypes.h:927
This class is the base class for the comparison instructions.
Definition: InstrTypes.h:955
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
Definition: InstrTypes.h:1323
Predicate getStrictPredicate() const
For example, SGE -> SGT, SLE -> SLT, ULE -> ULT, UGE -> UGT.
Definition: InstrTypes.h:1159
bool isEquality() const
Determine if this is an equals/not equals predicate.
Definition: InstrTypes.h:1216
void setPredicate(Predicate P)
Set the predicate for this instruction to the specified value.
Definition: InstrTypes.h:1069
bool isFalseWhenEqual() const
This is just a convenience.
Definition: InstrTypes.h:1281
Predicate getSignedPredicate()
For example, ULT->SLT, ULE->SLE, UGT->SGT, UGE->SGE, SLT->Failed assert.
Definition: InstrTypes.h:1245
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: InstrTypes.h:1314
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:965
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
Definition: InstrTypes.h:968
@ FCMP_TRUE
1 1 1 1 Always true (always folded)
Definition: InstrTypes.h:982
@ ICMP_SLT
signed less than
Definition: InstrTypes.h:994
@ FIRST_ICMP_PREDICATE
Definition: InstrTypes.h:996
@ ICMP_SLE
signed less or equal
Definition: InstrTypes.h:995
@ FCMP_OLT
0 1 0 0 True if ordered and less than
Definition: InstrTypes.h:971
@ FIRST_FCMP_PREDICATE
Definition: InstrTypes.h:983
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
Definition: InstrTypes.h:980
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Definition: InstrTypes.h:969
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition: InstrTypes.h:970
@ ICMP_UGE
unsigned greater or equal
Definition: InstrTypes.h:989
@ ICMP_UGT
unsigned greater than
Definition: InstrTypes.h:988
@ ICMP_SGT
signed greater than
Definition: InstrTypes.h:992
@ FCMP_ULT
1 1 0 0 True if unordered or less than
Definition: InstrTypes.h:979
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
Definition: InstrTypes.h:973
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
Definition: InstrTypes.h:976
@ ICMP_ULT
unsigned less than
Definition: InstrTypes.h:990
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
Definition: InstrTypes.h:977
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition: InstrTypes.h:972
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
Definition: InstrTypes.h:974
@ ICMP_EQ
equal
Definition: InstrTypes.h:986
@ ICMP_NE
not equal
Definition: InstrTypes.h:987
@ ICMP_SGE
signed greater or equal
Definition: InstrTypes.h:993
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
Definition: InstrTypes.h:981
@ ICMP_ULE
unsigned less or equal
Definition: InstrTypes.h:991
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
Definition: InstrTypes.h:978
@ FCMP_FALSE
0 0 0 0 Always false (always folded)
Definition: InstrTypes.h:967
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Definition: InstrTypes.h:975
static auto ICmpPredicates()
Returns the sequence of all ICmp predicates.
Definition: InstrTypes.h:1011
bool isSigned() const
Definition: InstrTypes.h:1226
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
Definition: InstrTypes.h:1128
static auto FCmpPredicates()
Returns the sequence of all FCmp predicates.
Definition: InstrTypes.h:1004
static CmpInst * Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2, const Twine &Name, BasicBlock::iterator InsertBefore)
Construct a compare instruction, given the opcode, the predicate and the two operands.
bool isTrueWhenEqual() const
This is just a convenience.
Definition: InstrTypes.h:1275
Predicate getOrderedPredicate() const
Definition: InstrTypes.h:1101
static bool isFPPredicate(Predicate P)
Definition: InstrTypes.h:1071
Predicate getUnsignedPredicate()
For example, SLT->ULT, SLE->ULE, SGT->UGT, SGE->UGE, ULT->Failed assert.
Definition: InstrTypes.h:1257
Predicate getNonStrictPredicate() const
For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
Definition: InstrTypes.h:1172
bool isNonStrictPredicate() const
Definition: InstrTypes.h:1153
bool isFPPredicate() const
Definition: InstrTypes.h:1083
void swapOperands()
This is just a convenience that dispatches to the subclasses.
static bool isRelational(Predicate P)
Return true if the predicate is relational (not EQ or NE).
Definition: InstrTypes.h:1219
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE,...
Definition: InstrTypes.h:1090
static StringRef getPredicateName(Predicate P)
Predicate getPredicate() const
Return the predicate for this instruction.
Definition: InstrTypes.h:1066
bool isStrictPredicate() const
Definition: InstrTypes.h:1144
static bool isUnordered(Predicate predicate)
Determine if the predicate is an unordered operation.
Predicate getFlippedStrictnessPredicate() const
For predicate of kind "is X or equal to 0" returns the predicate "is X".
Definition: InstrTypes.h:1194
static bool isImpliedTrueByMatchingCmp(Predicate Pred1, Predicate Pred2)
Determine if Pred1 implies Pred2 is true when two compares have matching operands.
static Predicate getOrderedPredicate(Predicate Pred)
Returns the ordered variant of a floating point compare.
Definition: InstrTypes.h:1097
Predicate getFlippedSignednessPredicate()
For example, SLT->ULT, ULT->SLT, SLE->ULE, ULE->SLE, EQ->Failed assert.
Definition: InstrTypes.h:1269
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Provide more efficient getOperand methods.
bool isIntPredicate() const
Definition: InstrTypes.h:1084
static bool isIntPredicate(Predicate P)
Definition: InstrTypes.h:1077
Predicate getUnorderedPredicate() const
Definition: InstrTypes.h:1112
static bool isOrdered(Predicate predicate)
Determine if the predicate is an ordered operation.
static bool classof(const Value *V)
Definition: InstrTypes.h:1318
static bool isImpliedFalseByMatchingCmp(Predicate Pred1, Predicate Pred2)
Determine if Pred1 implies Pred2 is false when two compares have matching operands.
bool isUnsigned() const
Definition: InstrTypes.h:1232
static Predicate getUnorderedPredicate(Predicate Pred)
Returns the unordered variant of a floating point compare.
Definition: InstrTypes.h:1108
OtherOps getOpcode() const
Get the opcode casted to the right type.
Definition: InstrTypes.h:1061
bool isCommutative() const
This is just a convenience that dispatches to the subclasses.
bool isRelational() const
Return true if the predicate is relational (not EQ or NE).
Definition: InstrTypes.h:1222
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
static bool classof(const Instruction *I)
Definition: InstrTypes.h:2683
op_range arg_operands()
arg_operands - iteration adapter for range-for loops.
Definition: InstrTypes.h:2675
void setArgOperand(unsigned i, Value *v)
Definition: InstrTypes.h:2672
unsigned arg_size() const
arg_size - Return the number of funcletpad arguments.
Definition: InstrTypes.h:2655
static bool classof(const Value *V)
Definition: InstrTypes.h:2684
void setParentPad(Value *ParentPad)
Definition: InstrTypes.h:2664
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Provide fast operand accessors.
Value * getParentPad() const
Convenience accessors.
Definition: InstrTypes.h:2663
const_op_range arg_operands() const
arg_operands - iteration adapter for range-for loops.
Definition: InstrTypes.h:2678
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th funcletpad argument.
Definition: InstrTypes.h:2671
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Definition: DerivedTypes.h:168
FunctionType * getFunctionType()
Definition: DerivedTypes.h:185
Class to represent function types.
Definition: DerivedTypes.h:103
Type * getReturnType() const
Definition: DerivedTypes.h:124
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.h:200
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
void copyIRFlags(const Value *V, bool IncludeWrapFlags=true)
Convenience method to copy supported exact, fast-math, and (optionally) wrapping flags from V to this...
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:251
void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag.
Instruction(const Instruction &)=delete
friend class BasicBlock
Various leaf nodes.
Definition: Instruction.h:973
A container for an operand bundle being viewed as a set of values rather than a set of uses.
Definition: InstrTypes.h:1408
size_t input_size() const
Definition: InstrTypes.h:1427
input_iterator input_end() const
Definition: InstrTypes.h:1429
OperandBundleDefT(const OperandBundleUse &OBU)
Definition: InstrTypes.h:1418
ArrayRef< InputTy > inputs() const
Definition: InstrTypes.h:1423
typename std::vector< InputTy >::const_iterator input_iterator
Definition: InstrTypes.h:1425
OperandBundleDefT(std::string Tag, std::vector< InputTy > Inputs)
Definition: InstrTypes.h:1413
input_iterator input_begin() const
Definition: InstrTypes.h:1428
StringRef getTag() const
Definition: InstrTypes.h:1431
OperandBundleDefT(std::string Tag, ArrayRef< InputTy > Inputs)
Definition: InstrTypes.h:1415
An or instruction, which can be marked as "disjoint", indicating that the inputs don't have a 1 in th...
Definition: InstrTypes.h:521
void setIsDisjoint(bool B)
Definition: InstrTypes.h:525
static bool classof(const Value *V)
Definition: InstrTypes.h:536
static bool classof(const Instruction *I)
Definition: InstrTypes.h:532
Instruction that can have a nneg flag (only zext).
Definition: InstrTypes.h:936
static bool classof(const Instruction *I)
Definition: InstrTypes.h:940
static bool classof(const Value *V)
Definition: InstrTypes.h:944
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
static IntegerType * getInt1Ty(LLVMContext &C)
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:129
UnaryInstruction(Type *Ty, unsigned iType, Value *V, BasicBlock::iterator IB)
Definition: InstrTypes.h:57
static bool classof(const Instruction *I)
Definition: InstrTypes.h:80
UnaryInstruction(Type *Ty, unsigned iType, Value *V, Instruction *IB=nullptr)
Definition: InstrTypes.h:61
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
UnaryInstruction(Type *Ty, unsigned iType, Value *V, BasicBlock *IAE)
Definition: InstrTypes.h:66
static bool classof(const Value *V)
Definition: InstrTypes.h:88
static UnaryOperator * CreateFNegFMF(Value *Op, Instruction *FMFSource, const Twine &Name="", Instruction *InsertBefore=nullptr)
Definition: InstrTypes.h:196
static UnaryOperator * CreateWithCopiedFlags(UnaryOps Opc, Value *V, Instruction *CopyO, const Twine &Name, BasicBlock::iterator InsertBefore)
Definition: InstrTypes.h:173
static UnaryOperator * CreateFNegFMF(Value *Op, Instruction *FMFSource, const Twine &Name, BasicBlock::iterator InsertBefore)
Definition: InstrTypes.h:189
UnaryOps getOpcode() const
Definition: InstrTypes.h:203
static UnaryOperator * CreateWithCopiedFlags(UnaryOps Opc, Value *V, Instruction *CopyO, const Twine &Name="", Instruction *InsertBefore=nullptr)
Definition: InstrTypes.h:181
static bool classof(const Value *V)
Definition: InstrTypes.h:211
static bool classof(const Instruction *I)
Definition: InstrTypes.h:208
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
Use * op_iterator
Definition: User.h:229
ArrayRef< const uint8_t > getDescriptor() const
Returns the descriptor co-allocated with this User instance.
Definition: User.cpp:99
op_iterator op_begin()
Definition: User.h:234
const Use & getOperandUse(unsigned i) const
Definition: User.h:182
void setOperand(unsigned i, Value *Val)
Definition: User.h:174
Value * getOperand(unsigned i) const
Definition: User.h:169
op_iterator op_end()
Definition: User.h:236
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
user_iterator_impl< const User > const_user_iterator
Definition: Value.h:391
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:377
void setValueSubclassData(unsigned short D)
Definition: Value.h:867
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:1074
void mutateType(Type *Ty)
Mutate the type of this Value to be of the specified type.
Definition: Value.h:815
unsigned HasDescriptor
Definition: Value.h:115
Base class of all SIMD vector types.
Definition: DerivedTypes.h:403
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
Definition: Type.cpp:676
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
@ MaxID
The highest possible ID. Must be some 2^k - 1.
Definition: CallingConv.h:268
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto enum_seq_inclusive(EnumT Begin, EnumT End)
Iterate over an enum type from Begin to End inclusive.
Definition: Sequence.h:364
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition: STLExtras.h:2082
constexpr force_iteration_on_noniterable_enum_t force_iteration_on_noniterable_enum
Definition: Sequence.h:108
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
@ Other
Any other memory.
@ Or
Bitwise or logical OR of integers.
@ Mul
Product of integers.
@ Add
Sum of integers.
DWARFExpression::Operation Op
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:293
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1858
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1888
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
Describes an element of a Bitfield.
Definition: Bitfields.h:223
static constexpr unsigned NextBit
Definition: Bitfields.h:231
Used to keep track of an operand bundle.
Definition: InstrTypes.h:2442
bool operator==(const BundleOpInfo &Other) const
Definition: InstrTypes.h:2455
StringMapEntry< uint32_t > * Tag
The operand bundle tag, interned by LLVMContextImpl::getOrInsertBundleTag.
Definition: InstrTypes.h:2445
uint32_t End
The index in the Use& vector where operands for this operand bundle ends.
Definition: InstrTypes.h:2453
uint32_t Begin
The index in the Use& vector where operands for this operand bundle starts.
Definition: InstrTypes.h:2449
FixedNumOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
Definition: OperandTraits.h:30
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117
A lightweight accessor for an operand bundle meant to be passed around by value.
Definition: InstrTypes.h:1350
bool isFuncletOperandBundle() const
Return true if this is a "funclet" operand bundle.
Definition: InstrTypes.h:1388
StringRef getTagName() const
Return the tag of this operand bundle as a string.
Definition: InstrTypes.h:1369
bool isDeoptOperandBundle() const
Return true if this is a "deopt" operand bundle.
Definition: InstrTypes.h:1383
OperandBundleUse(StringMapEntry< uint32_t > *Tag, ArrayRef< Use > Inputs)
Definition: InstrTypes.h:1354
uint32_t getTagID() const
Return the tag of this operand bundle as an integer.
Definition: InstrTypes.h:1378
ArrayRef< Use > Inputs
Definition: InstrTypes.h:1351
bool operandHasAttr(unsigned Idx, Attribute::AttrKind A) const
Return true if the operand at index Idx in this operand bundle has the attribute A.
Definition: InstrTypes.h:1359
bool isCFGuardTargetOperandBundle() const
Return true if this is a "cfguardtarget" operand bundle.
Definition: InstrTypes.h:1393
Compile-time customization of User operands.
Definition: User.h:42
VariadicOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
Definition: OperandTraits.h:68