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

source code of llvm/include/llvm/IR/InstrTypes.h