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