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