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