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