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