LLVM 22.0.0git
Instruction.h
Go to the documentation of this file.
1//===- Instruction.h --------------------------------------------*- 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#ifndef LLVM_SANDBOXIR_INSTRUCTION_H
10#define LLVM_SANDBOXIR_INSTRUCTION_H
11
12#include "llvm/IR/IRBuilder.h"
14#include "llvm/IR/Module.h"
18#include "llvm/SandboxIR/User.h"
20
21namespace llvm::sandboxir {
22
23// Forward declaration for MSVC.
24class IntrinsicInst;
25
27 BBIterator InsertAt;
28
29public:
30 InsertPosition(BasicBlock *InsertAtEnd) {
31 assert(InsertAtEnd != nullptr && "Expected non-null!");
32 InsertAt = InsertAtEnd->end();
33 }
34 InsertPosition(BBIterator InsertAt) : InsertAt(InsertAt) {}
35 operator BBIterator() { return InsertAt; }
36 const BBIterator &getIterator() const { return InsertAt; }
37 Instruction &operator*() { return *InsertAt; }
38 BasicBlock *getBasicBlock() const { return InsertAt.getNodeParent(); }
39};
40
41/// A sandboxir::User with operands, opcode and linked with previous/next
42/// instructions in an instruction list.
43class Instruction : public User {
44public:
45 enum class Opcode {
46#define OP(OPC) OPC,
47#define OPCODES(...) __VA_ARGS__
48#define DEF_INSTR(ID, OPC, CLASS) OPC
49#include "llvm/SandboxIR/Values.def"
50 };
51
52protected:
54 sandboxir::Context &SBCtx)
55 : User(ID, I, SBCtx), Opc(Opc) {}
56
58
59 /// A SandboxIR Instruction may map to multiple LLVM IR Instruction. This
60 /// returns its topmost LLVM IR instruction.
62 friend class VAArgInst; // For getTopmostLLVMInstruction().
63 friend class FreezeInst; // For getTopmostLLVMInstruction().
64 friend class FenceInst; // For getTopmostLLVMInstruction().
65 friend class SelectInst; // For getTopmostLLVMInstruction().
66 friend class ExtractElementInst; // For getTopmostLLVMInstruction().
67 friend class InsertElementInst; // For getTopmostLLVMInstruction().
68 friend class ShuffleVectorInst; // For getTopmostLLVMInstruction().
69 friend class ExtractValueInst; // For getTopmostLLVMInstruction().
70 friend class InsertValueInst; // For getTopmostLLVMInstruction().
71 friend class BranchInst; // For getTopmostLLVMInstruction().
72 friend class LoadInst; // For getTopmostLLVMInstruction().
73 friend class StoreInst; // For getTopmostLLVMInstruction().
74 friend class ReturnInst; // For getTopmostLLVMInstruction().
75 friend class CallInst; // For getTopmostLLVMInstruction().
76 friend class InvokeInst; // For getTopmostLLVMInstruction().
77 friend class CallBrInst; // For getTopmostLLVMInstruction().
78 friend class LandingPadInst; // For getTopmostLLVMInstruction().
79 friend class CatchPadInst; // For getTopmostLLVMInstruction().
80 friend class CleanupPadInst; // For getTopmostLLVMInstruction().
81 friend class CatchReturnInst; // For getTopmostLLVMInstruction().
82 friend class CleanupReturnInst; // For getTopmostLLVMInstruction().
83 friend class GetElementPtrInst; // For getTopmostLLVMInstruction().
84 friend class ResumeInst; // For getTopmostLLVMInstruction().
85 friend class CatchSwitchInst; // For getTopmostLLVMInstruction().
86 friend class SwitchInst; // For getTopmostLLVMInstruction().
87 friend class UnaryOperator; // For getTopmostLLVMInstruction().
88 friend class BinaryOperator; // For getTopmostLLVMInstruction().
89 friend class AtomicRMWInst; // For getTopmostLLVMInstruction().
90 friend class AtomicCmpXchgInst; // For getTopmostLLVMInstruction().
91 friend class AllocaInst; // For getTopmostLLVMInstruction().
92 friend class CastInst; // For getTopmostLLVMInstruction().
93 friend class PHINode; // For getTopmostLLVMInstruction().
94 friend class UnreachableInst; // For getTopmostLLVMInstruction().
95 friend class CmpInst; // For getTopmostLLVMInstruction().
96
97 /// \Returns the LLVM IR Instructions that this SandboxIR maps to in program
98 /// order.
100 friend class EraseFromParent; // For getLLVMInstrs().
101
102 /// Helper function for create(). It sets the builder's insert position
103 /// according to \p Pos.
105 auto *WhereBB = Pos.getBasicBlock();
106 auto WhereIt = Pos.getIterator();
107 auto &Ctx = WhereBB->getContext();
108 auto &Builder = Ctx.getLLVMIRBuilder();
109 if (WhereIt != WhereBB->end())
110 Builder.SetInsertPoint((*Pos).getTopmostLLVMInstruction());
111 else
112 Builder.SetInsertPoint(cast<llvm::BasicBlock>(WhereBB->Val));
113 return Builder;
114 }
115
116public:
117 LLVM_ABI static const char *getOpcodeName(Opcode Opc);
118 /// This is used by BasicBlock::iterator.
119 virtual unsigned getNumOfIRInstrs() const = 0;
120 /// \Returns a BasicBlock::iterator for this Instruction.
122 /// \Returns the next sandboxir::Instruction in the block, or nullptr if at
123 /// the end of the block.
125 /// \Returns the previous sandboxir::Instruction in the block, or nullptr if
126 /// at the beginning of the block.
128 /// \Returns this Instruction's opcode. Note that SandboxIR has its own opcode
129 /// state to allow for new SandboxIR-specific instructions.
130 Opcode getOpcode() const { return Opc; }
131
132 const char *getOpcodeName() const { return getOpcodeName(Opc); }
133
134 const DataLayout &getDataLayout() const {
135 return cast<llvm::Instruction>(Val)->getModule()->getDataLayout();
136 }
137 // Note that these functions below are calling into llvm::Instruction.
138 // A sandbox IR instruction could introduce a new opcode that could change the
139 // behavior of one of these functions. It is better that these functions are
140 // only added as needed and new sandbox IR instructions must explicitly check
141 // if any of these functions could have a different behavior.
142
143 bool isTerminator() const {
144 return cast<llvm::Instruction>(Val)->isTerminator();
145 }
146 bool isUnaryOp() const { return cast<llvm::Instruction>(Val)->isUnaryOp(); }
147 bool isBinaryOp() const { return cast<llvm::Instruction>(Val)->isBinaryOp(); }
148 bool isIntDivRem() const {
149 return cast<llvm::Instruction>(Val)->isIntDivRem();
150 }
151 bool isShift() const { return cast<llvm::Instruction>(Val)->isShift(); }
152 bool isCast() const { return cast<llvm::Instruction>(Val)->isCast(); }
153 bool isFuncletPad() const {
154 return cast<llvm::Instruction>(Val)->isFuncletPad();
155 }
156 bool isSpecialTerminator() const {
157 return cast<llvm::Instruction>(Val)->isSpecialTerminator();
158 }
160 return cast<llvm::Instruction>(Val)->isOnlyUserOfAnyOperand();
161 }
162 bool isLogicalShift() const {
163 return cast<llvm::Instruction>(Val)->isLogicalShift();
164 }
165
166 //===--------------------------------------------------------------------===//
167 // Metadata manipulation.
168 //===--------------------------------------------------------------------===//
169
170 /// Return true if the instruction has any metadata attached to it.
171 bool hasMetadata() const {
172 return cast<llvm::Instruction>(Val)->hasMetadata();
173 }
174
175 /// Return true if this instruction has metadata attached to it other than a
176 /// debug location.
178 return cast<llvm::Instruction>(Val)->hasMetadataOtherThanDebugLoc();
179 }
180
181 /// Return true if this instruction has the given type of metadata attached.
182 bool hasMetadata(unsigned KindID) const {
183 return cast<llvm::Instruction>(Val)->hasMetadata(KindID);
184 }
185
186 // TODO: Implement getMetadata and getAllMetadata after sandboxir::MDNode is
187 // available.
188
189 // TODO: More missing functions
190
191 /// Detach this from its parent BasicBlock without deleting it.
193 /// Detach this Value from its parent and delete it.
195 /// Insert this detached instruction before \p BeforeI.
196 LLVM_ABI void insertBefore(Instruction *BeforeI);
197 /// Insert this detached instruction after \p AfterI.
198 LLVM_ABI void insertAfter(Instruction *AfterI);
199 /// Insert this detached instruction into \p BB at \p WhereIt.
200 LLVM_ABI void insertInto(BasicBlock *BB, const BBIterator &WhereIt);
201 /// Move this instruction to \p WhereIt.
202 LLVM_ABI void moveBefore(BasicBlock &BB, const BBIterator &WhereIt);
203 /// Move this instruction before \p Before.
204 void moveBefore(Instruction *Before) {
205 moveBefore(*Before->getParent(), Before->getIterator());
206 }
207 /// Move this instruction after \p After.
208 void moveAfter(Instruction *After) {
209 moveBefore(*After->getParent(), std::next(After->getIterator()));
210 }
211 // TODO: This currently relies on LLVM IR Instruction::comesBefore which is
212 // can be linear-time.
213 /// Given an instruction Other in the same basic block as this instruction,
214 /// return true if this instruction comes before Other.
215 bool comesBefore(const Instruction *Other) const {
216 return cast<llvm::Instruction>(Val)->comesBefore(
217 cast<llvm::Instruction>(Other->Val));
218 }
219 /// \Returns the BasicBlock containing this Instruction, or null if it is
220 /// detached.
222 /// For isa/dyn_cast.
223 LLVM_ABI static bool classof(const sandboxir::Value *From);
224
225 /// Determine whether the no signed wrap flag is set.
226 bool hasNoUnsignedWrap() const {
227 return cast<llvm::Instruction>(Val)->hasNoUnsignedWrap();
228 }
229 /// Set or clear the nuw flag on this instruction, which must be an operator
230 /// which supports this flag. See LangRef.html for the meaning of this flag.
231 LLVM_ABI void setHasNoUnsignedWrap(bool B = true);
232 /// Determine whether the no signed wrap flag is set.
233 bool hasNoSignedWrap() const {
234 return cast<llvm::Instruction>(Val)->hasNoSignedWrap();
235 }
236 /// Set or clear the nsw flag on this instruction, which must be an operator
237 /// which supports this flag. See LangRef.html for the meaning of this flag.
238 LLVM_ABI void setHasNoSignedWrap(bool B = true);
239 /// Determine whether all fast-math-flags are set.
240 bool isFast() const { return cast<llvm::Instruction>(Val)->isFast(); }
241 /// Set or clear all fast-math-flags on this instruction, which must be an
242 /// operator which supports this flag. See LangRef.html for the meaning of
243 /// this flag.
244 LLVM_ABI void setFast(bool B);
245 /// Determine whether the allow-reassociation flag is set.
246 bool hasAllowReassoc() const {
247 return cast<llvm::Instruction>(Val)->hasAllowReassoc();
248 }
249 /// Set or clear the reassociation flag on this instruction, which must be
250 /// an operator which supports this flag. See LangRef.html for the meaning of
251 /// this flag.
252 LLVM_ABI void setHasAllowReassoc(bool B);
253 /// Determine whether the exact flag is set.
254 bool isExact() const { return cast<llvm::Instruction>(Val)->isExact(); }
255 /// Set or clear the exact flag on this instruction, which must be an operator
256 /// which supports this flag. See LangRef.html for the meaning of this flag.
257 LLVM_ABI void setIsExact(bool B = true);
258 /// Determine whether the no-NaNs flag is set.
259 bool hasNoNaNs() const { return cast<llvm::Instruction>(Val)->hasNoNaNs(); }
260 /// Set or clear the no-nans flag on this instruction, which must be an
261 /// operator which supports this flag. See LangRef.html for the meaning of
262 /// this flag.
263 LLVM_ABI void setHasNoNaNs(bool B);
264 /// Determine whether the no-infs flag is set.
265 bool hasNoInfs() const { return cast<llvm::Instruction>(Val)->hasNoInfs(); }
266 /// Set or clear the no-infs flag on this instruction, which must be an
267 /// operator which supports this flag. See LangRef.html for the meaning of
268 /// this flag.
269 LLVM_ABI void setHasNoInfs(bool B);
270 /// Determine whether the no-signed-zeros flag is set.
271 bool hasNoSignedZeros() const {
272 return cast<llvm::Instruction>(Val)->hasNoSignedZeros();
273 }
274 /// Set or clear the no-signed-zeros flag on this instruction, which must be
275 /// an operator which supports this flag. See LangRef.html for the meaning of
276 /// this flag.
277 LLVM_ABI void setHasNoSignedZeros(bool B);
278 /// Determine whether the allow-reciprocal flag is set.
279 bool hasAllowReciprocal() const {
280 return cast<llvm::Instruction>(Val)->hasAllowReciprocal();
281 }
282 /// Set or clear the allow-reciprocal flag on this instruction, which must be
283 /// an operator which supports this flag. See LangRef.html for the meaning of
284 /// this flag.
286 /// Determine whether the allow-contract flag is set.
287 bool hasAllowContract() const {
288 return cast<llvm::Instruction>(Val)->hasAllowContract();
289 }
290 /// Set or clear the allow-contract flag on this instruction, which must be
291 /// an operator which supports this flag. See LangRef.html for the meaning of
292 /// this flag.
293 LLVM_ABI void setHasAllowContract(bool B);
294 /// Determine whether the approximate-math-functions flag is set.
295 bool hasApproxFunc() const {
296 return cast<llvm::Instruction>(Val)->hasApproxFunc();
297 }
298 /// Set or clear the approximate-math-functions flag on this instruction,
299 /// which must be an operator which supports this flag. See LangRef.html for
300 /// the meaning of this flag.
301 LLVM_ABI void setHasApproxFunc(bool B);
302 /// Convenience function for getting all the fast-math flags, which must be an
303 /// operator which supports these flags. See LangRef.html for the meaning of
304 /// these flags.
306 return cast<llvm::Instruction>(Val)->getFastMathFlags();
307 }
308 /// Convenience function for setting multiple fast-math flags on this
309 /// instruction, which must be an operator which supports these flags. See
310 /// LangRef.html for the meaning of these flags.
312 /// Convenience function for transferring all fast-math flag values to this
313 /// instruction, which must be an operator which supports these flags. See
314 /// LangRef.html for the meaning of these flags.
316
317 bool isAssociative() const {
318 return cast<llvm::Instruction>(Val)->isAssociative();
319 }
320
321 bool isCommutative() const {
322 return cast<llvm::Instruction>(Val)->isCommutative();
323 }
324
325 bool isIdempotent() const {
326 return cast<llvm::Instruction>(Val)->isIdempotent();
327 }
328
329 bool isNilpotent() const {
330 return cast<llvm::Instruction>(Val)->isNilpotent();
331 }
332
333 bool mayWriteToMemory() const {
334 return cast<llvm::Instruction>(Val)->mayWriteToMemory();
335 }
336
337 bool mayReadFromMemory() const {
338 return cast<llvm::Instruction>(Val)->mayReadFromMemory();
339 }
340 bool mayReadOrWriteMemory() const {
341 return cast<llvm::Instruction>(Val)->mayReadOrWriteMemory();
342 }
343
344 bool isAtomic() const { return cast<llvm::Instruction>(Val)->isAtomic(); }
345
346 bool hasAtomicLoad() const {
347 return cast<llvm::Instruction>(Val)->hasAtomicLoad();
348 }
349
350 bool hasAtomicStore() const {
351 return cast<llvm::Instruction>(Val)->hasAtomicStore();
352 }
353
354 bool isVolatile() const { return cast<llvm::Instruction>(Val)->isVolatile(); }
355
356 LLVM_ABI Type *getAccessType() const;
357
358 bool mayThrow(bool IncludePhaseOneUnwind = false) const {
359 return cast<llvm::Instruction>(Val)->mayThrow(IncludePhaseOneUnwind);
360 }
361
362 bool isFenceLike() const {
363 return cast<llvm::Instruction>(Val)->isFenceLike();
364 }
365
366 bool mayHaveSideEffects() const {
367 return cast<llvm::Instruction>(Val)->mayHaveSideEffects();
368 }
369
370 // TODO: Missing functions.
371
372#ifndef NDEBUG
373 void dumpOS(raw_ostream &OS) const override;
374#endif
375};
376
377/// Instructions that contain a single LLVM Instruction can inherit from this.
378template <typename LLVMT> class SingleLLVMInstructionImpl : public Instruction {
380 sandboxir::Context &SBCtx)
381 : Instruction(ID, Opc, I, SBCtx) {}
382
383 // All instructions are friends with this so they can call the constructor.
384#define DEF_INSTR(ID, OPC, CLASS) friend class CLASS;
385#include "llvm/SandboxIR/Values.def"
386 friend class UnaryInstruction;
387 friend class CallBase;
388 friend class FuncletPadInst;
389 friend class CmpInst;
390
391 Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
393 }
394 SmallVector<llvm::Instruction *, 1> getLLVMInstrs() const final {
395 return {cast<llvm::Instruction>(Val)};
396 }
397
398public:
399 unsigned getUseOperandNo(const Use &Use) const final {
401 }
402 unsigned getNumOfIRInstrs() const final { return 1u; }
403#ifndef NDEBUG
404 void verify() const final { assert(isa<LLVMT>(Val) && "Expected LLVMT!"); }
405 void dumpOS(raw_ostream &OS) const override {
408 }
409#endif
410};
411
412class FenceInst : public SingleLLVMInstructionImpl<llvm::FenceInst> {
414 : SingleLLVMInstructionImpl(ClassID::Fence, Opcode::Fence, FI, Ctx) {}
415 friend Context; // For constructor;
416
417public:
419 Context &Ctx,
421 /// Returns the ordering constraint of this fence instruction.
423 return cast<llvm::FenceInst>(Val)->getOrdering();
424 }
425 /// Sets the ordering constraint of this fence instruction. May only be
426 /// Acquire, Release, AcquireRelease, or SequentiallyConsistent.
427 LLVM_ABI void setOrdering(AtomicOrdering Ordering);
428 /// Returns the synchronization scope ID of this fence instruction.
430 return cast<llvm::FenceInst>(Val)->getSyncScopeID();
431 }
432 /// Sets the synchronization scope ID of this fence instruction.
434 static bool classof(const Value *From) {
435 return From->getSubclassID() == ClassID::Fence;
436 }
437};
438
439class SelectInst : public SingleLLVMInstructionImpl<llvm::SelectInst> {
440 /// Use Context::createSelectInst(). Don't call the
441 /// constructor directly.
443 : SingleLLVMInstructionImpl(ClassID::Select, Opcode::Select, CI, Ctx) {}
444 friend Context; // for SelectInst()
445
446public:
447 LLVM_ABI static Value *create(Value *Cond, Value *True, Value *False,
449 const Twine &Name = "");
450
451 const Value *getCondition() const { return getOperand(0); }
452 const Value *getTrueValue() const { return getOperand(1); }
453 const Value *getFalseValue() const { return getOperand(2); }
454 Value *getCondition() { return getOperand(0); }
455 Value *getTrueValue() { return getOperand(1); }
457
458 void setCondition(Value *New) { setOperand(0, New); }
459 void setTrueValue(Value *New) { setOperand(1, New); }
460 void setFalseValue(Value *New) { setOperand(2, New); }
461 LLVM_ABI void swapValues();
462
463 /// Return a string if the specified operands are invalid for a select
464 /// operation, otherwise return null.
465 static const char *areInvalidOperands(Value *Cond, Value *True,
466 Value *False) {
468 False->Val);
469 }
470
471 /// For isa/dyn_cast.
472 LLVM_ABI static bool classof(const Value *From);
473};
474
476 : public SingleLLVMInstructionImpl<llvm::InsertElementInst> {
477 /// Use Context::createInsertElementInst() instead.
479 : SingleLLVMInstructionImpl(ClassID::InsertElement, Opcode::InsertElement,
480 I, Ctx) {}
481 friend class Context; // For accessing the constructor in create*()
482
483public:
484 LLVM_ABI static Value *create(Value *Vec, Value *NewElt, Value *Idx,
486 const Twine &Name = "");
487 static bool classof(const Value *From) {
488 return From->getSubclassID() == ClassID::InsertElement;
489 }
490 static bool isValidOperands(const Value *Vec, const Value *NewElt,
491 const Value *Idx) {
493 Idx->Val);
494 }
495};
496
498 : public SingleLLVMInstructionImpl<llvm::ExtractElementInst> {
499 /// Use Context::createExtractElementInst() instead.
501 : SingleLLVMInstructionImpl(ClassID::ExtractElement,
502 Opcode::ExtractElement, I, Ctx) {}
503 friend class Context; // For accessing the constructor in
504 // create*()
505
506public:
507 LLVM_ABI static Value *create(Value *Vec, Value *Idx, InsertPosition Pos,
508 Context &Ctx, const Twine &Name = "");
509 static bool classof(const Value *From) {
510 return From->getSubclassID() == ClassID::ExtractElement;
511 }
512
513 static bool isValidOperands(const Value *Vec, const Value *Idx) {
515 }
518 const Value *getVectorOperand() const { return getOperand(0); }
519 const Value *getIndexOperand() const { return getOperand(1); }
521};
522
524 : public SingleLLVMInstructionImpl<llvm::ShuffleVectorInst> {
525 /// Use Context::createShuffleVectorInst() instead.
527 : SingleLLVMInstructionImpl(ClassID::ShuffleVector, Opcode::ShuffleVector,
528 I, Ctx) {}
529 friend class Context; // For accessing the constructor in create*()
530
531public:
532 LLVM_ABI static Value *create(Value *V1, Value *V2, Value *Mask,
534 const Twine &Name = "");
535 LLVM_ABI static Value *create(Value *V1, Value *V2, ArrayRef<int> Mask,
537 const Twine &Name = "");
538 static bool classof(const Value *From) {
539 return From->getSubclassID() == ClassID::ShuffleVector;
540 }
541
542 /// Swap the operands and adjust the mask to preserve the semantics of the
543 /// instruction.
544 LLVM_ABI void commute();
545
546 /// Return true if a shufflevector instruction can be formed with the
547 /// specified operands.
548 static bool isValidOperands(const Value *V1, const Value *V2,
549 const Value *Mask) {
551 Mask->Val);
552 }
553 static bool isValidOperands(const Value *V1, const Value *V2,
554 ArrayRef<int> Mask) {
555 return llvm::ShuffleVectorInst::isValidOperands(V1->Val, V2->Val, Mask);
556 }
557
558 /// Overload to return most specific vector type.
559 LLVM_ABI VectorType *getType() const;
560
561 /// Return the shuffle mask value of this instruction for the given element
562 /// index. Return PoisonMaskElem if the element is undef.
563 int getMaskValue(unsigned Elt) const {
564 return cast<llvm::ShuffleVectorInst>(Val)->getMaskValue(Elt);
565 }
566
567 /// Convert the input shuffle mask operand to a vector of integers. Undefined
568 /// elements of the mask are returned as PoisonMaskElem.
569 static void getShuffleMask(const Constant *Mask,
570 SmallVectorImpl<int> &Result) {
571 llvm::ShuffleVectorInst::getShuffleMask(cast<llvm::Constant>(Mask->Val),
572 Result);
573 }
574
575 /// Return the mask for this instruction as a vector of integers. Undefined
576 /// elements of the mask are returned as PoisonMaskElem.
578 cast<llvm::ShuffleVectorInst>(Val)->getShuffleMask(Result);
579 }
580
581 /// Return the mask for this instruction, for use in bitcode.
583
585 Type *ResultTy);
586
588
590 return cast<llvm::ShuffleVectorInst>(Val)->getShuffleMask();
591 }
592
593 /// Return true if this shuffle returns a vector with a different number of
594 /// elements than its source vectors.
595 /// Examples: shufflevector <4 x n> A, <4 x n> B, <1,2,3>
596 /// shufflevector <4 x n> A, <4 x n> B, <1,2,3,4,5>
597 bool changesLength() const {
598 return cast<llvm::ShuffleVectorInst>(Val)->changesLength();
599 }
600
601 /// Return true if this shuffle returns a vector with a greater number of
602 /// elements than its source vectors.
603 /// Example: shufflevector <2 x n> A, <2 x n> B, <1,2,3>
604 bool increasesLength() const {
605 return cast<llvm::ShuffleVectorInst>(Val)->increasesLength();
606 }
607
608 /// Return true if this shuffle mask chooses elements from exactly one source
609 /// vector.
610 /// Example: <7,5,undef,7>
611 /// This assumes that vector operands (of length \p NumSrcElts) are the same
612 /// length as the mask.
613 static bool isSingleSourceMask(ArrayRef<int> Mask, int NumSrcElts) {
614 return llvm::ShuffleVectorInst::isSingleSourceMask(Mask, NumSrcElts);
615 }
616 static bool isSingleSourceMask(const Constant *Mask, int NumSrcElts) {
618 cast<llvm::Constant>(Mask->Val), NumSrcElts);
619 }
620
621 /// Return true if this shuffle chooses elements from exactly one source
622 /// vector without changing the length of that vector.
623 /// Example: shufflevector <4 x n> A, <4 x n> B, <3,0,undef,3>
624 bool isSingleSource() const {
625 return cast<llvm::ShuffleVectorInst>(Val)->isSingleSource();
626 }
627
628 /// Return true if this shuffle mask chooses elements from exactly one source
629 /// vector without lane crossings. A shuffle using this mask is not
630 /// necessarily a no-op because it may change the number of elements from its
631 /// input vectors or it may provide demanded bits knowledge via undef lanes.
632 /// Example: <undef,undef,2,3>
633 static bool isIdentityMask(ArrayRef<int> Mask, int NumSrcElts) {
634 return llvm::ShuffleVectorInst::isIdentityMask(Mask, NumSrcElts);
635 }
636 static bool isIdentityMask(const Constant *Mask, int NumSrcElts) {
638 cast<llvm::Constant>(Mask->Val), NumSrcElts);
639 }
640
641 /// Return true if this shuffle chooses elements from exactly one source
642 /// vector without lane crossings and does not change the number of elements
643 /// from its input vectors.
644 /// Example: shufflevector <4 x n> A, <4 x n> B, <4,undef,6,undef>
645 bool isIdentity() const {
646 return cast<llvm::ShuffleVectorInst>(Val)->isIdentity();
647 }
648
649 /// Return true if this shuffle lengthens exactly one source vector with
650 /// undefs in the high elements.
652 return cast<llvm::ShuffleVectorInst>(Val)->isIdentityWithPadding();
653 }
654
655 /// Return true if this shuffle extracts the first N elements of exactly one
656 /// source vector.
658 return cast<llvm::ShuffleVectorInst>(Val)->isIdentityWithExtract();
659 }
660
661 /// Return true if this shuffle concatenates its 2 source vectors. This
662 /// returns false if either input is undefined. In that case, the shuffle is
663 /// is better classified as an identity with padding operation.
664 bool isConcat() const {
665 return cast<llvm::ShuffleVectorInst>(Val)->isConcat();
666 }
667
668 /// Return true if this shuffle mask chooses elements from its source vectors
669 /// without lane crossings. A shuffle using this mask would be
670 /// equivalent to a vector select with a constant condition operand.
671 /// Example: <4,1,6,undef>
672 /// This returns false if the mask does not choose from both input vectors.
673 /// In that case, the shuffle is better classified as an identity shuffle.
674 /// This assumes that vector operands are the same length as the mask
675 /// (a length-changing shuffle can never be equivalent to a vector select).
676 static bool isSelectMask(ArrayRef<int> Mask, int NumSrcElts) {
677 return llvm::ShuffleVectorInst::isSelectMask(Mask, NumSrcElts);
678 }
679 static bool isSelectMask(const Constant *Mask, int NumSrcElts) {
681 cast<llvm::Constant>(Mask->Val), NumSrcElts);
682 }
683
684 /// Return true if this shuffle chooses elements from its source vectors
685 /// without lane crossings and all operands have the same number of elements.
686 /// In other words, this shuffle is equivalent to a vector select with a
687 /// constant condition operand.
688 /// Example: shufflevector <4 x n> A, <4 x n> B, <undef,1,6,3>
689 /// This returns false if the mask does not choose from both input vectors.
690 /// In that case, the shuffle is better classified as an identity shuffle.
691 bool isSelect() const {
692 return cast<llvm::ShuffleVectorInst>(Val)->isSelect();
693 }
694
695 /// Return true if this shuffle mask swaps the order of elements from exactly
696 /// one source vector.
697 /// Example: <7,6,undef,4>
698 /// This assumes that vector operands (of length \p NumSrcElts) are the same
699 /// length as the mask.
700 static bool isReverseMask(ArrayRef<int> Mask, int NumSrcElts) {
701 return llvm::ShuffleVectorInst::isReverseMask(Mask, NumSrcElts);
702 }
703 static bool isReverseMask(const Constant *Mask, int NumSrcElts) {
705 cast<llvm::Constant>(Mask->Val), NumSrcElts);
706 }
707
708 /// Return true if this shuffle swaps the order of elements from exactly
709 /// one source vector.
710 /// Example: shufflevector <4 x n> A, <4 x n> B, <3,undef,1,undef>
711 bool isReverse() const {
712 return cast<llvm::ShuffleVectorInst>(Val)->isReverse();
713 }
714
715 /// Return true if this shuffle mask chooses all elements with the same value
716 /// as the first element of exactly one source vector.
717 /// Example: <4,undef,undef,4>
718 /// This assumes that vector operands (of length \p NumSrcElts) are the same
719 /// length as the mask.
720 static bool isZeroEltSplatMask(ArrayRef<int> Mask, int NumSrcElts) {
721 return llvm::ShuffleVectorInst::isZeroEltSplatMask(Mask, NumSrcElts);
722 }
723 static bool isZeroEltSplatMask(const Constant *Mask, int NumSrcElts) {
725 cast<llvm::Constant>(Mask->Val), NumSrcElts);
726 }
727
728 /// Return true if all elements of this shuffle are the same value as the
729 /// first element of exactly one source vector without changing the length
730 /// of that vector.
731 /// Example: shufflevector <4 x n> A, <4 x n> B, <undef,0,undef,0>
732 bool isZeroEltSplat() const {
733 return cast<llvm::ShuffleVectorInst>(Val)->isZeroEltSplat();
734 }
735
736 /// Return true if this shuffle mask is a transpose mask.
737 /// Transpose vector masks transpose a 2xn matrix. They read corresponding
738 /// even- or odd-numbered vector elements from two n-dimensional source
739 /// vectors and write each result into consecutive elements of an
740 /// n-dimensional destination vector. Two shuffles are necessary to complete
741 /// the transpose, one for the even elements and another for the odd elements.
742 /// This description closely follows how the TRN1 and TRN2 AArch64
743 /// instructions operate.
744 ///
745 /// For example, a simple 2x2 matrix can be transposed with:
746 ///
747 /// ; Original matrix
748 /// m0 = < a, b >
749 /// m1 = < c, d >
750 ///
751 /// ; Transposed matrix
752 /// t0 = < a, c > = shufflevector m0, m1, < 0, 2 >
753 /// t1 = < b, d > = shufflevector m0, m1, < 1, 3 >
754 ///
755 /// For matrices having greater than n columns, the resulting nx2 transposed
756 /// matrix is stored in two result vectors such that one vector contains
757 /// interleaved elements from all the even-numbered rows and the other vector
758 /// contains interleaved elements from all the odd-numbered rows. For example,
759 /// a 2x4 matrix can be transposed with:
760 ///
761 /// ; Original matrix
762 /// m0 = < a, b, c, d >
763 /// m1 = < e, f, g, h >
764 ///
765 /// ; Transposed matrix
766 /// t0 = < a, e, c, g > = shufflevector m0, m1 < 0, 4, 2, 6 >
767 /// t1 = < b, f, d, h > = shufflevector m0, m1 < 1, 5, 3, 7 >
768 static bool isTransposeMask(ArrayRef<int> Mask, int NumSrcElts) {
769 return llvm::ShuffleVectorInst::isTransposeMask(Mask, NumSrcElts);
770 }
771 static bool isTransposeMask(const Constant *Mask, int NumSrcElts) {
773 cast<llvm::Constant>(Mask->Val), NumSrcElts);
774 }
775
776 /// Return true if this shuffle transposes the elements of its inputs without
777 /// changing the length of the vectors. This operation may also be known as a
778 /// merge or interleave. See the description for isTransposeMask() for the
779 /// exact specification.
780 /// Example: shufflevector <4 x n> A, <4 x n> B, <0,4,2,6>
781 bool isTranspose() const {
782 return cast<llvm::ShuffleVectorInst>(Val)->isTranspose();
783 }
784
785 /// Return true if this shuffle mask is a splice mask, concatenating the two
786 /// inputs together and then extracts an original width vector starting from
787 /// the splice index.
788 /// Example: shufflevector <4 x n> A, <4 x n> B, <1,2,3,4>
789 /// This assumes that vector operands (of length \p NumSrcElts) are the same
790 /// length as the mask.
791 static bool isSpliceMask(ArrayRef<int> Mask, int NumSrcElts, int &Index) {
792 return llvm::ShuffleVectorInst::isSpliceMask(Mask, NumSrcElts, Index);
793 }
794 static bool isSpliceMask(const Constant *Mask, int NumSrcElts, int &Index) {
796 cast<llvm::Constant>(Mask->Val), NumSrcElts, Index);
797 }
798
799 /// Return true if this shuffle splices two inputs without changing the length
800 /// of the vectors. This operation concatenates the two inputs together and
801 /// then extracts an original width vector starting from the splice index.
802 /// Example: shufflevector <4 x n> A, <4 x n> B, <1,2,3,4>
803 bool isSplice(int &Index) const {
804 return cast<llvm::ShuffleVectorInst>(Val)->isSplice(Index);
805 }
806
807 /// Return true if this shuffle mask is an extract subvector mask.
808 /// A valid extract subvector mask returns a smaller vector from a single
809 /// source operand. The base extraction index is returned as well.
810 static bool isExtractSubvectorMask(ArrayRef<int> Mask, int NumSrcElts,
811 int &Index) {
813 Index);
814 }
815 static bool isExtractSubvectorMask(const Constant *Mask, int NumSrcElts,
816 int &Index) {
818 cast<llvm::Constant>(Mask->Val), NumSrcElts, Index);
819 }
820
821 /// Return true if this shuffle mask is an extract subvector mask.
822 bool isExtractSubvectorMask(int &Index) const {
823 return cast<llvm::ShuffleVectorInst>(Val)->isExtractSubvectorMask(Index);
824 }
825
826 /// Return true if this shuffle mask is an insert subvector mask.
827 /// A valid insert subvector mask inserts the lowest elements of a second
828 /// source operand into an in-place first source operand.
829 /// Both the sub vector width and the insertion index is returned.
830 static bool isInsertSubvectorMask(ArrayRef<int> Mask, int NumSrcElts,
831 int &NumSubElts, int &Index) {
833 NumSubElts, Index);
834 }
835 static bool isInsertSubvectorMask(const Constant *Mask, int NumSrcElts,
836 int &NumSubElts, int &Index) {
838 cast<llvm::Constant>(Mask->Val), NumSrcElts, NumSubElts, Index);
839 }
840
841 /// Return true if this shuffle mask is an insert subvector mask.
842 bool isInsertSubvectorMask(int &NumSubElts, int &Index) const {
843 return cast<llvm::ShuffleVectorInst>(Val)->isInsertSubvectorMask(NumSubElts,
844 Index);
845 }
846
847 /// Return true if this shuffle mask replicates each of the \p VF elements
848 /// in a vector \p ReplicationFactor times.
849 /// For example, the mask for \p ReplicationFactor=3 and \p VF=4 is:
850 /// <0,0,0,1,1,1,2,2,2,3,3,3>
851 static bool isReplicationMask(ArrayRef<int> Mask, int &ReplicationFactor,
852 int &VF) {
853 return llvm::ShuffleVectorInst::isReplicationMask(Mask, ReplicationFactor,
854 VF);
855 }
856 static bool isReplicationMask(const Constant *Mask, int &ReplicationFactor,
857 int &VF) {
859 cast<llvm::Constant>(Mask->Val), ReplicationFactor, VF);
860 }
861
862 /// Return true if this shuffle mask is a replication mask.
863 bool isReplicationMask(int &ReplicationFactor, int &VF) const {
864 return cast<llvm::ShuffleVectorInst>(Val)->isReplicationMask(
865 ReplicationFactor, VF);
866 }
867
868 /// Return true if this shuffle mask represents "clustered" mask of size VF,
869 /// i.e. each index between [0..VF) is used exactly once in each submask of
870 /// size VF.
871 /// For example, the mask for \p VF=4 is:
872 /// 0, 1, 2, 3, 3, 2, 0, 1 - "clustered", because each submask of size 4
873 /// (0,1,2,3 and 3,2,0,1) uses indices [0..VF) exactly one time.
874 /// 0, 1, 2, 3, 3, 3, 1, 0 - not "clustered", because
875 /// element 3 is used twice in the second submask
876 /// (3,3,1,0) and index 2 is not used at all.
877 static bool isOneUseSingleSourceMask(ArrayRef<int> Mask, int VF) {
879 }
880
881 /// Return true if this shuffle mask is a one-use-single-source("clustered")
882 /// mask.
883 bool isOneUseSingleSourceMask(int VF) const {
884 return cast<llvm::ShuffleVectorInst>(Val)->isOneUseSingleSourceMask(VF);
885 }
886
887 /// Change values in a shuffle permute mask assuming the two vector operands
888 /// of length InVecNumElts have swapped position.
890 unsigned InVecNumElts) {
892 }
893
894 /// Return if this shuffle interleaves its two input vectors together.
895 bool isInterleave(unsigned Factor) const {
896 return cast<llvm::ShuffleVectorInst>(Val)->isInterleave(Factor);
897 }
898
899 /// Return true if the mask interleaves one or more input vectors together.
900 ///
901 /// I.e. <0, LaneLen, ... , LaneLen*(Factor - 1), 1, LaneLen + 1, ...>
902 /// E.g. For a Factor of 2 (LaneLen=4):
903 /// <0, 4, 1, 5, 2, 6, 3, 7>
904 /// E.g. For a Factor of 3 (LaneLen=4):
905 /// <4, 0, 9, 5, 1, 10, 6, 2, 11, 7, 3, 12>
906 /// E.g. For a Factor of 4 (LaneLen=2):
907 /// <0, 2, 6, 4, 1, 3, 7, 5>
908 ///
909 /// NumInputElts is the total number of elements in the input vectors.
910 ///
911 /// StartIndexes are the first indexes of each vector being interleaved,
912 /// substituting any indexes that were undef
913 /// E.g. <4, -1, 2, 5, 1, 3> (Factor=3): StartIndexes=<4, 0, 2>
914 ///
915 /// Note that this does not check if the input vectors are consecutive:
916 /// It will return true for masks such as
917 /// <0, 4, 6, 1, 5, 7> (Factor=3, LaneLen=2)
918 static bool isInterleaveMask(ArrayRef<int> Mask, unsigned Factor,
919 unsigned NumInputElts,
920 SmallVectorImpl<unsigned> &StartIndexes) {
921 return llvm::ShuffleVectorInst::isInterleaveMask(Mask, Factor, NumInputElts,
922 StartIndexes);
923 }
924 static bool isInterleaveMask(ArrayRef<int> Mask, unsigned Factor,
925 unsigned NumInputElts) {
927 NumInputElts);
928 }
929
930 /// Check if the mask is a DE-interleave mask of the given factor
931 /// \p Factor like:
932 /// <Index, Index+Factor, ..., Index+(NumElts-1)*Factor>
933 static bool isDeInterleaveMaskOfFactor(ArrayRef<int> Mask, unsigned Factor,
934 unsigned &Index) {
936 Index);
937 }
938 static bool isDeInterleaveMaskOfFactor(ArrayRef<int> Mask, unsigned Factor) {
940 }
941
942 /// Checks if the shuffle is a bit rotation of the first operand across
943 /// multiple subelements, e.g:
944 ///
945 /// shuffle <8 x i8> %a, <8 x i8> poison, <8 x i32> <1, 0, 3, 2, 5, 4, 7, 6>
946 ///
947 /// could be expressed as
948 ///
949 /// rotl <4 x i16> %a, 8
950 ///
951 /// If it can be expressed as a rotation, returns the number of subelements to
952 /// group by in NumSubElts and the number of bits to rotate left in RotateAmt.
953 static bool isBitRotateMask(ArrayRef<int> Mask, unsigned EltSizeInBits,
954 unsigned MinSubElts, unsigned MaxSubElts,
955 unsigned &NumSubElts, unsigned &RotateAmt) {
957 Mask, EltSizeInBits, MinSubElts, MaxSubElts, NumSubElts, RotateAmt);
958 }
959};
960
962 : public SingleLLVMInstructionImpl<llvm::InsertValueInst> {
963 /// Use Context::createInsertValueInst(). Don't call the constructor directly.
965 : SingleLLVMInstructionImpl(ClassID::InsertValue, Opcode::InsertValue,
966 IVI, Ctx) {}
967 friend Context; // for InsertValueInst()
968
969public:
972 const Twine &Name = "");
973
974 static bool classof(const Value *From) {
975 return From->getSubclassID() == ClassID::InsertValue;
976 }
977
979 inline idx_iterator idx_begin() const {
980 return cast<llvm::InsertValueInst>(Val)->idx_begin();
981 }
982 inline idx_iterator idx_end() const {
983 return cast<llvm::InsertValueInst>(Val)->idx_end();
984 }
986 return cast<llvm::InsertValueInst>(Val)->indices();
987 }
988
991 }
992 const Value *getAggregateOperand() const {
994 }
995 static unsigned getAggregateOperandIndex() {
997 }
998
1001 }
1004 }
1007 }
1008
1010 return cast<llvm::InsertValueInst>(Val)->getIndices();
1011 }
1012
1013 unsigned getNumIndices() const {
1014 return cast<llvm::InsertValueInst>(Val)->getNumIndices();
1015 }
1016
1017 unsigned hasIndices() const {
1018 return cast<llvm::InsertValueInst>(Val)->hasIndices();
1019 }
1020};
1021
1022class BranchInst : public SingleLLVMInstructionImpl<llvm::BranchInst> {
1023 /// Use Context::createBranchInst(). Don't call the constructor directly.
1025 : SingleLLVMInstructionImpl(ClassID::Br, Opcode::Br, BI, Ctx) {}
1026 friend Context; // for BranchInst()
1027
1028public:
1029 LLVM_ABI static BranchInst *create(BasicBlock *IfTrue, InsertPosition Pos,
1030 Context &Ctx);
1031 LLVM_ABI static BranchInst *create(BasicBlock *IfTrue, BasicBlock *IfFalse,
1033 Context &Ctx);
1034 /// For isa/dyn_cast.
1035 LLVM_ABI static bool classof(const Value *From);
1036 bool isUnconditional() const {
1037 return cast<llvm::BranchInst>(Val)->isUnconditional();
1038 }
1039 bool isConditional() const {
1040 return cast<llvm::BranchInst>(Val)->isConditional();
1041 }
1042 LLVM_ABI Value *getCondition() const;
1043 void setCondition(Value *V) { setOperand(0, V); }
1044 unsigned getNumSuccessors() const { return 1 + isConditional(); }
1045 LLVM_ABI BasicBlock *getSuccessor(unsigned SuccIdx) const;
1046 LLVM_ABI void setSuccessor(unsigned Idx, BasicBlock *NewSucc);
1048
1049private:
1050 struct LLVMBBToSBBB {
1051 Context &Ctx;
1052 LLVMBBToSBBB(Context &Ctx) : Ctx(Ctx) {}
1053 LLVM_ABI BasicBlock *operator()(llvm::BasicBlock *BB) const;
1054 };
1055
1056 struct ConstLLVMBBToSBBB {
1057 Context &Ctx;
1058 ConstLLVMBBToSBBB(Context &Ctx) : Ctx(Ctx) {}
1059 LLVM_ABI const BasicBlock *operator()(const llvm::BasicBlock *BB) const;
1060 };
1061
1062public:
1067 cast<llvm::BranchInst>(Val)->successors();
1068 LLVMBBToSBBB BBMap(Ctx);
1069 sb_succ_op_iterator MappedBegin = map_iterator(LLVMRange.begin(), BBMap);
1070 sb_succ_op_iterator MappedEnd = map_iterator(LLVMRange.end(), BBMap);
1071 return make_range(MappedBegin, MappedEnd);
1072 }
1073
1076 ConstLLVMBBToSBBB>;
1079 static_cast<const llvm::BranchInst *>(cast<llvm::BranchInst>(Val))
1080 ->successors();
1081 ConstLLVMBBToSBBB ConstBBMap(Ctx);
1082 const_sb_succ_op_iterator ConstMappedBegin =
1083 map_iterator(ConstLLVMRange.begin(), ConstBBMap);
1084 const_sb_succ_op_iterator ConstMappedEnd =
1085 map_iterator(ConstLLVMRange.end(), ConstBBMap);
1086 return make_range(ConstMappedBegin, ConstMappedEnd);
1087 }
1088};
1089
1090/// An abstract class, parent of unary instructions.
1092 : public SingleLLVMInstructionImpl<llvm::UnaryInstruction> {
1093protected:
1095 Context &Ctx)
1096 : SingleLLVMInstructionImpl(ID, Opc, LLVMI, Ctx) {}
1097
1098public:
1099 static bool classof(const Instruction *I) {
1100 return isa<LoadInst>(I) || isa<CastInst>(I) || isa<FreezeInst>(I);
1101 }
1102 static bool classof(const Value *V) {
1103 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1104 }
1105};
1106
1108 /// Use Context::createExtractValueInst() instead.
1110 : UnaryInstruction(ClassID::ExtractValue, Opcode::ExtractValue, EVI,
1111 Ctx) {}
1112 friend Context; // for ExtractValueInst()
1113
1114public:
1115 LLVM_ABI static Value *create(Value *Agg, ArrayRef<unsigned> Idxs,
1117 const Twine &Name = "");
1118
1119 static bool classof(const Value *From) {
1120 return From->getSubclassID() == ClassID::ExtractValue;
1121 }
1122
1123 /// Returns the type of the element that would be extracted
1124 /// with an extractvalue instruction with the specified parameters.
1125 ///
1126 /// Null is returned if the indices are invalid for the specified type.
1128
1130
1131 inline idx_iterator idx_begin() const {
1132 return cast<llvm::ExtractValueInst>(Val)->idx_begin();
1133 }
1134 inline idx_iterator idx_end() const {
1135 return cast<llvm::ExtractValueInst>(Val)->idx_end();
1136 }
1138 return cast<llvm::ExtractValueInst>(Val)->indices();
1139 }
1140
1143 }
1146 }
1147 static unsigned getAggregateOperandIndex() {
1149 }
1150
1152 return cast<llvm::ExtractValueInst>(Val)->getIndices();
1153 }
1154
1155 unsigned getNumIndices() const {
1156 return cast<llvm::ExtractValueInst>(Val)->getNumIndices();
1157 }
1158
1159 unsigned hasIndices() const {
1160 return cast<llvm::ExtractValueInst>(Val)->hasIndices();
1161 }
1162};
1163
1166 : UnaryInstruction(ClassID::VAArg, Opcode::VAArg, FI, Ctx) {}
1167 friend Context; // For constructor;
1168
1169public:
1171 Context &Ctx, const Twine &Name = "");
1173 const Value *getPointerOperand() const {
1174 return const_cast<VAArgInst *>(this)->getPointerOperand();
1175 }
1176 static unsigned getPointerOperandIndex() {
1178 }
1179 static bool classof(const Value *From) {
1180 return From->getSubclassID() == ClassID::VAArg;
1181 }
1182};
1183
1186 : UnaryInstruction(ClassID::Freeze, Opcode::Freeze, FI, Ctx) {}
1187 friend Context; // For constructor;
1188
1189public:
1191 const Twine &Name = "");
1192 static bool classof(const Value *From) {
1193 return From->getSubclassID() == ClassID::Freeze;
1194 }
1195};
1196
1197class LoadInst final : public UnaryInstruction {
1198 /// Use LoadInst::create() instead of calling the constructor.
1200 : UnaryInstruction(ClassID::Load, Opcode::Load, LI, Ctx) {}
1201 friend Context; // for LoadInst()
1202
1203public:
1204 /// Return true if this is a load from a volatile memory location.
1205 bool isVolatile() const { return cast<llvm::LoadInst>(Val)->isVolatile(); }
1206 /// Specify whether this is a volatile load or not.
1207 LLVM_ABI void setVolatile(bool V);
1208
1210 InsertPosition Pos, bool IsVolatile,
1211 Context &Ctx, const Twine &Name = "");
1214 const Twine &Name = "") {
1215 return create(Ty, Ptr, Align, Pos, /*IsVolatile=*/false, Ctx, Name);
1216 }
1217
1218 /// For isa/dyn_cast.
1219 LLVM_ABI static bool classof(const Value *From);
1221 Align getAlign() const { return cast<llvm::LoadInst>(Val)->getAlign(); }
1222 bool isUnordered() const { return cast<llvm::LoadInst>(Val)->isUnordered(); }
1223 bool isSimple() const { return cast<llvm::LoadInst>(Val)->isSimple(); }
1224};
1225
1226class StoreInst final : public SingleLLVMInstructionImpl<llvm::StoreInst> {
1227 /// Use StoreInst::create().
1229 : SingleLLVMInstructionImpl(ClassID::Store, Opcode::Store, SI, Ctx) {}
1230 friend Context; // for StoreInst()
1231
1232public:
1233 /// Return true if this is a store from a volatile memory location.
1234 bool isVolatile() const { return cast<llvm::StoreInst>(Val)->isVolatile(); }
1235 /// Specify whether this is a volatile store or not.
1236 LLVM_ABI void setVolatile(bool V);
1237
1239 InsertPosition Pos, bool IsVolatile,
1240 Context &Ctx);
1242 InsertPosition Pos, Context &Ctx) {
1243 return create(V, Ptr, Align, Pos, /*IsVolatile=*/false, Ctx);
1244 }
1245
1246 /// For isa/dyn_cast.
1247 LLVM_ABI static bool classof(const Value *From);
1250 Align getAlign() const { return cast<llvm::StoreInst>(Val)->getAlign(); }
1251 bool isSimple() const { return cast<llvm::StoreInst>(Val)->isSimple(); }
1252 bool isUnordered() const { return cast<llvm::StoreInst>(Val)->isUnordered(); }
1253};
1254
1255class UnreachableInst final : public Instruction {
1256 /// Use UnreachableInst::create() instead of calling the constructor.
1258 : Instruction(ClassID::Unreachable, Opcode::Unreachable, I, Ctx) {}
1259 friend Context;
1260 Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
1262 }
1263 SmallVector<llvm::Instruction *, 1> getLLVMInstrs() const final {
1264 return {cast<llvm::Instruction>(Val)};
1265 }
1266
1267public:
1269 LLVM_ABI static bool classof(const Value *From);
1270 unsigned getNumSuccessors() const { return 0; }
1271 unsigned getUseOperandNo(const Use &Use) const final {
1272 llvm_unreachable("UnreachableInst has no operands!");
1273 }
1274 unsigned getNumOfIRInstrs() const final { return 1u; }
1275};
1276
1277class ReturnInst final : public SingleLLVMInstructionImpl<llvm::ReturnInst> {
1278 /// Use ReturnInst::create() instead of calling the constructor.
1280 : SingleLLVMInstructionImpl(ClassID::Ret, Opcode::Ret, I, Ctx) {}
1282 : SingleLLVMInstructionImpl(SubclassID, Opcode::Ret, I, Ctx) {}
1283 friend class Context; // For accessing the constructor in create*()
1284 static ReturnInst *createCommon(Value *RetVal, IRBuilder<> &Builder,
1285 Context &Ctx);
1286
1287public:
1288 LLVM_ABI static ReturnInst *create(Value *RetVal, InsertPosition Pos,
1289 Context &Ctx);
1290 static bool classof(const Value *From) {
1291 return From->getSubclassID() == ClassID::Ret;
1292 }
1293 /// \Returns null if there is no return value.
1294 LLVM_ABI Value *getReturnValue() const;
1295};
1296
1297class CallBase : public SingleLLVMInstructionImpl<llvm::CallBase> {
1300 friend class CallInst; // For constructor.
1301 friend class InvokeInst; // For constructor.
1302 friend class CallBrInst; // For constructor.
1303
1304public:
1305 static bool classof(const Value *From) {
1306 auto Opc = From->getSubclassID();
1307 return Opc == Instruction::ClassID::Call ||
1308 Opc == Instruction::ClassID::Invoke ||
1309 Opc == Instruction::ClassID::CallBr;
1310 }
1311
1313
1316 return const_cast<CallBase *>(this)->data_operands_begin();
1317 }
1319 auto *LLVMCB = cast<llvm::CallBase>(Val);
1320 auto Dist = LLVMCB->data_operands_end() - LLVMCB->data_operands_begin();
1321 return op_begin() + Dist;
1322 }
1324 auto *LLVMCB = cast<llvm::CallBase>(Val);
1325 auto Dist = LLVMCB->data_operands_end() - LLVMCB->data_operands_begin();
1326 return op_begin() + Dist;
1327 }
1330 }
1333 }
1334 bool data_operands_empty() const {
1336 }
1337 unsigned data_operands_size() const {
1338 return std::distance(data_operands_begin(), data_operands_end());
1339 }
1340 bool isDataOperand(Use U) const {
1341 assert(this == U.getUser() &&
1342 "Only valid to query with a use of this instruction!");
1343 return cast<llvm::CallBase>(Val)->isDataOperand(U.LLVMUse);
1344 }
1345 unsigned getDataOperandNo(Use U) const {
1346 assert(isDataOperand(U) && "Data operand # out of range!");
1347 return cast<llvm::CallBase>(Val)->getDataOperandNo(U.LLVMUse);
1348 }
1349
1350 /// Return the total number operands (not operand bundles) used by
1351 /// every operand bundle in this OperandBundleUser.
1352 unsigned getNumTotalBundleOperands() const {
1353 return cast<llvm::CallBase>(Val)->getNumTotalBundleOperands();
1354 }
1355
1360 }
1362 return const_cast<CallBase *>(this)->arg_end();
1363 }
1365 return make_range(arg_begin(), arg_end());
1366 }
1368 return make_range(arg_begin(), arg_end());
1369 }
1370 bool arg_empty() const { return arg_end() == arg_begin(); }
1371 unsigned arg_size() const { return arg_end() - arg_begin(); }
1372
1373 Value *getArgOperand(unsigned OpIdx) const {
1374 assert(OpIdx < arg_size() && "Out of bounds!");
1375 return getOperand(OpIdx);
1376 }
1377 void setArgOperand(unsigned OpIdx, Value *NewOp) {
1378 assert(OpIdx < arg_size() && "Out of bounds!");
1379 setOperand(OpIdx, NewOp);
1380 }
1381
1382 Use getArgOperandUse(unsigned Idx) const {
1383 assert(Idx < arg_size() && "Out of bounds!");
1384 return getOperandUse(Idx);
1385 }
1387 assert(Idx < arg_size() && "Out of bounds!");
1388 return getOperandUse(Idx);
1389 }
1390
1391 bool isArgOperand(Use U) const {
1392 return cast<llvm::CallBase>(Val)->isArgOperand(U.LLVMUse);
1393 }
1394 unsigned getArgOperandNo(Use U) const {
1395 return cast<llvm::CallBase>(Val)->getArgOperandNo(U.LLVMUse);
1396 }
1397 bool hasArgument(const Value *V) const { return is_contained(args(), V); }
1398
1401
1403 bool isIndirectCall() const {
1404 return cast<llvm::CallBase>(Val)->isIndirectCall();
1405 }
1406 bool isCallee(Use U) const {
1407 return cast<llvm::CallBase>(Val)->isCallee(U.LLVMUse);
1408 }
1410 const Function *getCaller() const {
1411 return const_cast<CallBase *>(this)->getCaller();
1412 }
1413 bool isMustTailCall() const {
1414 return cast<llvm::CallBase>(Val)->isMustTailCall();
1415 }
1416 bool isTailCall() const { return cast<llvm::CallBase>(Val)->isTailCall(); }
1418 return cast<llvm::CallBase>(Val)->getIntrinsicID();
1419 }
1423 return cast<llvm::CallBase>(Val)->getCallingConv();
1424 }
1425 bool isInlineAsm() const { return cast<llvm::CallBase>(Val)->isInlineAsm(); }
1426};
1427
1428class CallInst : public CallBase {
1429 /// Use Context::createCallInst(). Don't call the
1430 /// constructor directly.
1432 : CallBase(ClassID::Call, Opcode::Call, I, Ctx) {}
1433 friend class Context; // For accessing the constructor in create*()
1434 friend class IntrinsicInst; // For constructor
1435
1436public:
1437 LLVM_ABI static CallInst *create(FunctionType *FTy, Value *Func,
1439 Context &Ctx, const Twine &NameStr = "");
1440
1441 static bool classof(const Value *From) {
1442 return From->getSubclassID() == ClassID::Call;
1443 }
1444};
1445
1446class InvokeInst final : public CallBase {
1447 /// Use Context::createInvokeInst(). Don't call the
1448 /// constructor directly.
1450 : CallBase(ClassID::Invoke, Opcode::Invoke, I, Ctx) {}
1451 friend class Context; // For accessing the constructor in
1452 // create*()
1453
1454public:
1455 LLVM_ABI static InvokeInst *create(FunctionType *FTy, Value *Func,
1456 BasicBlock *IfNormal,
1457 BasicBlock *IfException,
1459 Context &Ctx, const Twine &NameStr = "");
1460
1461 static bool classof(const Value *From) {
1462 return From->getSubclassID() == ClassID::Invoke;
1463 }
1469 LLVM_ABI BasicBlock *getSuccessor(unsigned SuccIdx) const;
1470 void setSuccessor(unsigned SuccIdx, BasicBlock *NewSucc) {
1471 assert(SuccIdx < 2 && "Successor # out of range for invoke!");
1472 if (SuccIdx == 0)
1473 setNormalDest(NewSucc);
1474 else
1475 setUnwindDest(NewSucc);
1476 }
1477 unsigned getNumSuccessors() const {
1478 return cast<llvm::InvokeInst>(Val)->getNumSuccessors();
1479 }
1480};
1481
1482class CallBrInst final : public CallBase {
1483 /// Use Context::createCallBrInst(). Don't call the
1484 /// constructor directly.
1486 : CallBase(ClassID::CallBr, Opcode::CallBr, I, Ctx) {}
1487 friend class Context; // For accessing the constructor in
1488 // create*()
1489
1490public:
1491 LLVM_ABI static CallBrInst *create(FunctionType *FTy, Value *Func,
1492 BasicBlock *DefaultDest,
1493 ArrayRef<BasicBlock *> IndirectDests,
1495 Context &Ctx, const Twine &NameStr = "");
1496 static bool classof(const Value *From) {
1497 return From->getSubclassID() == ClassID::CallBr;
1498 }
1499 unsigned getNumIndirectDests() const {
1500 return cast<llvm::CallBrInst>(Val)->getNumIndirectDests();
1501 }
1502 LLVM_ABI Value *getIndirectDestLabel(unsigned Idx) const;
1503 LLVM_ABI Value *getIndirectDestLabelUse(unsigned Idx) const;
1505 LLVM_ABI BasicBlock *getIndirectDest(unsigned Idx) const;
1508 LLVM_ABI void setIndirectDest(unsigned Idx, BasicBlock *BB);
1509 LLVM_ABI BasicBlock *getSuccessor(unsigned Idx) const;
1510 unsigned getNumSuccessors() const {
1511 return cast<llvm::CallBrInst>(Val)->getNumSuccessors();
1512 }
1513};
1514
1515class LandingPadInst : public SingleLLVMInstructionImpl<llvm::LandingPadInst> {
1517 : SingleLLVMInstructionImpl(ClassID::LandingPad, Opcode::LandingPad, LP,
1518 Ctx) {}
1519 friend class Context; // For constructor.
1520
1521public:
1523 unsigned NumReservedClauses,
1525 const Twine &Name = "");
1526 /// Return 'true' if this landingpad instruction is a
1527 /// cleanup. I.e., it should be run when unwinding even if its landing pad
1528 /// doesn't catch the exception.
1529 bool isCleanup() const {
1530 return cast<llvm::LandingPadInst>(Val)->isCleanup();
1531 }
1532 /// Indicate that this landingpad instruction is a cleanup.
1533 LLVM_ABI void setCleanup(bool V);
1534
1535 // TODO: We are not implementing addClause() because we have no way to revert
1536 // it for now.
1537
1538 /// Get the value of the clause at index Idx. Use isCatch/isFilter to
1539 /// determine what type of clause this is.
1540 LLVM_ABI Constant *getClause(unsigned Idx) const;
1541
1542 /// Return 'true' if the clause and index Idx is a catch clause.
1543 bool isCatch(unsigned Idx) const {
1544 return cast<llvm::LandingPadInst>(Val)->isCatch(Idx);
1545 }
1546 /// Return 'true' if the clause and index Idx is a filter clause.
1547 bool isFilter(unsigned Idx) const {
1548 return cast<llvm::LandingPadInst>(Val)->isFilter(Idx);
1549 }
1550 /// Get the number of clauses for this landing pad.
1551 unsigned getNumClauses() const {
1552 return cast<llvm::LandingPadInst>(Val)->getNumOperands();
1553 }
1554 // TODO: We are not implementing reserveClauses() because we can't revert it.
1555 static bool classof(const Value *From) {
1556 return From->getSubclassID() == ClassID::LandingPad;
1557 }
1558};
1559
1560class FuncletPadInst : public SingleLLVMInstructionImpl<llvm::FuncletPadInst> {
1562 Context &Ctx)
1564 friend class CatchPadInst; // For constructor.
1565 friend class CleanupPadInst; // For constructor.
1566
1567public:
1568 /// Return the number of funcletpad arguments.
1569 unsigned arg_size() const {
1570 return cast<llvm::FuncletPadInst>(Val)->arg_size();
1571 }
1572 /// Return the outer EH-pad this funclet is nested within.
1573 ///
1574 /// Note: This returns the associated CatchSwitchInst if this FuncletPadInst
1575 /// is a CatchPadInst.
1576 LLVM_ABI Value *getParentPad() const;
1577 LLVM_ABI void setParentPad(Value *ParentPad);
1578 /// Return the Idx-th funcletpad argument.
1579 LLVM_ABI Value *getArgOperand(unsigned Idx) const;
1580 /// Set the Idx-th funcletpad argument.
1581 LLVM_ABI void setArgOperand(unsigned Idx, Value *V);
1582
1583 // TODO: Implement missing functions: arg_operands().
1584 static bool classof(const Value *From) {
1585 return From->getSubclassID() == ClassID::CatchPad ||
1586 From->getSubclassID() == ClassID::CleanupPad;
1587 }
1588};
1589
1592 : FuncletPadInst(ClassID::CatchPad, Opcode::CatchPad, CPI, Ctx) {}
1593 friend class Context; // For constructor.
1594
1595public:
1597 // TODO: We have not implemented setCatchSwitch() because we can't revert it
1598 // for now, as there is no CatchPadInst member function that can undo it.
1599
1600 LLVM_ABI static CatchPadInst *create(Value *ParentPad, ArrayRef<Value *> Args,
1602 const Twine &Name = "");
1603 static bool classof(const Value *From) {
1604 return From->getSubclassID() == ClassID::CatchPad;
1605 }
1606};
1607
1610 : FuncletPadInst(ClassID::CleanupPad, Opcode::CleanupPad, CPI, Ctx) {}
1611 friend class Context; // For constructor.
1612
1613public:
1614 LLVM_ABI static CleanupPadInst *create(Value *ParentPad,
1615 ArrayRef<Value *> Args,
1617 const Twine &Name = "");
1618 static bool classof(const Value *From) {
1619 return From->getSubclassID() == ClassID::CleanupPad;
1620 }
1621};
1622
1624 : public SingleLLVMInstructionImpl<llvm::CatchReturnInst> {
1626 : SingleLLVMInstructionImpl(ClassID::CatchRet, Opcode::CatchRet, CRI,
1627 Ctx) {}
1628 friend class Context; // For constructor.
1629
1630public:
1631 LLVM_ABI static CatchReturnInst *create(CatchPadInst *CatchPad,
1632 BasicBlock *BB, InsertPosition Pos,
1633 Context &Ctx);
1635 LLVM_ABI void setCatchPad(CatchPadInst *CatchPad);
1637 LLVM_ABI void setSuccessor(BasicBlock *NewSucc);
1638 unsigned getNumSuccessors() {
1639 return cast<llvm::CatchReturnInst>(Val)->getNumSuccessors();
1640 }
1642 static bool classof(const Value *From) {
1643 return From->getSubclassID() == ClassID::CatchRet;
1644 }
1645};
1646
1648 : public SingleLLVMInstructionImpl<llvm::CleanupReturnInst> {
1650 : SingleLLVMInstructionImpl(ClassID::CleanupRet, Opcode::CleanupRet, CRI,
1651 Ctx) {}
1652 friend class Context; // For constructor.
1653
1654public:
1655 LLVM_ABI static CleanupReturnInst *create(CleanupPadInst *CleanupPad,
1656 BasicBlock *UnwindBB,
1657 InsertPosition Pos, Context &Ctx);
1658 bool hasUnwindDest() const {
1659 return cast<llvm::CleanupReturnInst>(Val)->hasUnwindDest();
1660 }
1661 bool unwindsToCaller() const {
1662 return cast<llvm::CleanupReturnInst>(Val)->unwindsToCaller();
1663 }
1665 LLVM_ABI void setCleanupPad(CleanupPadInst *CleanupPad);
1666 unsigned getNumSuccessors() const {
1667 return cast<llvm::CleanupReturnInst>(Val)->getNumSuccessors();
1668 }
1670 LLVM_ABI void setUnwindDest(BasicBlock *NewDest);
1671
1672 static bool classof(const Value *From) {
1673 return From->getSubclassID() == ClassID::CleanupRet;
1674 }
1675};
1676
1678 : public SingleLLVMInstructionImpl<llvm::GetElementPtrInst> {
1679 /// Use Context::createGetElementPtrInst(). Don't call
1680 /// the constructor directly.
1682 : SingleLLVMInstructionImpl(ClassID::GetElementPtr, Opcode::GetElementPtr,
1683 I, Ctx) {}
1685 : SingleLLVMInstructionImpl(SubclassID, Opcode::GetElementPtr, I, Ctx) {}
1686 friend class Context; // For accessing the constructor in
1687 // create*()
1688
1689public:
1690 LLVM_ABI static Value *create(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
1692 const Twine &NameStr = "");
1693
1694 static bool classof(const Value *From) {
1695 return From->getSubclassID() == ClassID::GetElementPtr;
1696 }
1697
1700 unsigned getAddressSpace() const {
1701 return cast<llvm::GetElementPtrInst>(Val)->getAddressSpace();
1702 }
1703
1704 inline op_iterator idx_begin() { return op_begin() + 1; }
1706 return const_cast<GetElementPtrInst *>(this)->idx_begin();
1707 }
1708 inline op_iterator idx_end() { return op_end(); }
1710 return const_cast<GetElementPtrInst *>(this)->idx_end();
1711 }
1713 return make_range(idx_begin(), idx_end());
1714 }
1716 return const_cast<GetElementPtrInst *>(this)->indices();
1717 }
1718
1720 static unsigned getPointerOperandIndex() {
1722 }
1724 unsigned getPointerAddressSpace() const {
1725 return cast<llvm::GetElementPtrInst>(Val)->getPointerAddressSpace();
1726 }
1727 unsigned getNumIndices() const {
1728 return cast<llvm::GetElementPtrInst>(Val)->getNumIndices();
1729 }
1730 bool hasIndices() const {
1731 return cast<llvm::GetElementPtrInst>(Val)->hasIndices();
1732 }
1734 return cast<llvm::GetElementPtrInst>(Val)->hasAllConstantIndices();
1735 }
1737 return cast<llvm::GetElementPtrInst>(Val)->getNoWrapFlags();
1738 }
1739 bool isInBounds() const {
1740 return cast<llvm::GetElementPtrInst>(Val)->isInBounds();
1741 }
1743 return cast<llvm::GetElementPtrInst>(Val)->hasNoUnsignedSignedWrap();
1744 }
1745 bool hasNoUnsignedWrap() const {
1746 return cast<llvm::GetElementPtrInst>(Val)->hasNoUnsignedWrap();
1747 }
1749 return cast<llvm::GetElementPtrInst>(Val)->accumulateConstantOffset(DL,
1750 Offset);
1751 }
1752 // TODO: Add missing member functions.
1753};
1754
1756 : public SingleLLVMInstructionImpl<llvm::CatchSwitchInst> {
1758 : SingleLLVMInstructionImpl(ClassID::CatchSwitch, Opcode::CatchSwitch,
1759 CSI, Ctx) {}
1760 friend class Context; // For accessing the constructor in create*()
1761
1762public:
1763 LLVM_ABI static CatchSwitchInst *
1764 create(Value *ParentPad, BasicBlock *UnwindBB, unsigned NumHandlers,
1765 InsertPosition Pos, Context &Ctx, const Twine &Name = "");
1766
1767 LLVM_ABI Value *getParentPad() const;
1768 LLVM_ABI void setParentPad(Value *ParentPad);
1769
1770 bool hasUnwindDest() const {
1771 return cast<llvm::CatchSwitchInst>(Val)->hasUnwindDest();
1772 }
1773 bool unwindsToCaller() const {
1774 return cast<llvm::CatchSwitchInst>(Val)->unwindsToCaller();
1775 }
1777 LLVM_ABI void setUnwindDest(BasicBlock *UnwindDest);
1778
1779 unsigned getNumHandlers() const {
1780 return cast<llvm::CatchSwitchInst>(Val)->getNumHandlers();
1781 }
1782
1783private:
1784 static BasicBlock *handler_helper(Value *V) { return cast<BasicBlock>(V); }
1785 static const BasicBlock *handler_helper(const Value *V) {
1786 return cast<BasicBlock>(V);
1787 }
1788
1789public:
1790 using DerefFnTy = BasicBlock *(*)(Value *);
1793 using ConstDerefFnTy = const BasicBlock *(*)(const Value *);
1797
1799 op_iterator It = op_begin() + 1;
1800 if (hasUnwindDest())
1801 ++It;
1802 return handler_iterator(It, DerefFnTy(handler_helper));
1803 }
1805 const_op_iterator It = op_begin() + 1;
1806 if (hasUnwindDest())
1807 ++It;
1808 return const_handler_iterator(It, ConstDerefFnTy(handler_helper));
1809 }
1811 return handler_iterator(op_end(), DerefFnTy(handler_helper));
1812 }
1814 return const_handler_iterator(op_end(), ConstDerefFnTy(handler_helper));
1815 }
1818 }
1821 }
1822
1823 LLVM_ABI void addHandler(BasicBlock *Dest);
1824
1825 // TODO: removeHandler() cannot be reverted because there is no equivalent
1826 // addHandler() with a handler_iterator to specify the position. So we can't
1827 // implement it for now.
1828
1829 unsigned getNumSuccessors() const { return getNumOperands() - 1; }
1830 BasicBlock *getSuccessor(unsigned Idx) const {
1832 "Successor # out of range for catchswitch!");
1833 return cast<BasicBlock>(getOperand(Idx + 1));
1834 }
1835 void setSuccessor(unsigned Idx, BasicBlock *NewSucc) {
1837 "Successor # out of range for catchswitch!");
1838 setOperand(Idx + 1, NewSucc);
1839 }
1840
1841 static bool classof(const Value *From) {
1842 return From->getSubclassID() == ClassID::CatchSwitch;
1843 }
1844};
1845
1846class ResumeInst : public SingleLLVMInstructionImpl<llvm::ResumeInst> {
1848 : SingleLLVMInstructionImpl(ClassID::Resume, Opcode::Resume, CSI, Ctx) {}
1849 friend class Context; // For accessing the constructor in create*()
1850
1851public:
1852 LLVM_ABI static ResumeInst *create(Value *Exn, InsertPosition Pos,
1853 Context &Ctx);
1854 LLVM_ABI Value *getValue() const;
1855 unsigned getNumSuccessors() const {
1856 return cast<llvm::ResumeInst>(Val)->getNumSuccessors();
1857 }
1858 static bool classof(const Value *From) {
1859 return From->getSubclassID() == ClassID::Resume;
1860 }
1861};
1862
1863class SwitchInst : public SingleLLVMInstructionImpl<llvm::SwitchInst> {
1865 : SingleLLVMInstructionImpl(ClassID::Switch, Opcode::Switch, SI, Ctx) {}
1866 friend class Context; // For accessing the constructor in create*()
1867
1868public:
1869 static constexpr const unsigned DefaultPseudoIndex =
1871
1872 LLVM_ABI static SwitchInst *create(Value *V, BasicBlock *Dest,
1873 unsigned NumCases, InsertPosition Pos,
1874 Context &Ctx, const Twine &Name = "");
1875
1876 LLVM_ABI Value *getCondition() const;
1877 LLVM_ABI void setCondition(Value *V);
1880 return cast<llvm::SwitchInst>(Val)->defaultDestUnreachable();
1881 }
1882 LLVM_ABI void setDefaultDest(BasicBlock *DefaultCase);
1883 unsigned getNumCases() const {
1884 return cast<llvm::SwitchInst>(Val)->getNumCases();
1885 }
1886
1891 const BasicBlock>;
1894
1895 /// Returns a read/write iterator that points to the first case in the
1896 /// SwitchInst.
1897 CaseIt case_begin() { return CaseIt(this, 0); }
1898 ConstCaseIt case_begin() const { return ConstCaseIt(this, 0); }
1899 /// Returns a read/write iterator that points one past the last in the
1900 /// SwitchInst.
1901 CaseIt case_end() { return CaseIt(this, getNumCases()); }
1902 ConstCaseIt case_end() const { return ConstCaseIt(this, getNumCases()); }
1903 /// Iteration adapter for range-for loops.
1905 return make_range(case_begin(), case_end());
1906 }
1908 return make_range(case_begin(), case_end());
1909 }
1912 return ConstCaseIt(this, DefaultPseudoIndex);
1913 }
1915 return CaseIt(
1916 this,
1917 const_cast<const SwitchInst *>(this)->findCaseValue(C)->getCaseIndex());
1918 }
1920 ConstCaseIt I = llvm::find_if(cases(), [C](const ConstCaseHandle &Case) {
1921 return Case.getCaseValue() == C;
1922 });
1923 if (I != case_end())
1924 return I;
1925 return case_default();
1926 }
1928
1929 LLVM_ABI void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1930 /// This method removes the specified case and its successor from the switch
1931 /// instruction. Note that this operation may reorder the remaining cases at
1932 /// index idx and above.
1933 /// Note:
1934 /// This action invalidates iterators for all cases following the one removed,
1935 /// including the case_end() iterator. It returns an iterator for the next
1936 /// case.
1938
1939 unsigned getNumSuccessors() const {
1940 return cast<llvm::SwitchInst>(Val)->getNumSuccessors();
1941 }
1942 LLVM_ABI BasicBlock *getSuccessor(unsigned Idx) const;
1943 LLVM_ABI void setSuccessor(unsigned Idx, BasicBlock *NewSucc);
1944 static bool classof(const Value *From) {
1945 return From->getSubclassID() == ClassID::Switch;
1946 }
1947};
1948
1950 static Opcode getUnaryOpcode(llvm::Instruction::UnaryOps UnOp) {
1951 switch (UnOp) {
1952 case llvm::Instruction::FNeg:
1953 return Opcode::FNeg;
1954 case llvm::Instruction::UnaryOpsEnd:
1955 llvm_unreachable("Bad UnOp!");
1956 }
1957 llvm_unreachable("Unhandled UnOp!");
1958 }
1960 : UnaryInstruction(ClassID::UnOp, getUnaryOpcode(UO->getOpcode()), UO,
1961 Ctx) {}
1962 friend Context; // for constructor.
1963public:
1966 const Twine &Name = "");
1968 Value *OpV, Value *CopyFrom,
1970 const Twine &Name = "");
1971 /// For isa/dyn_cast.
1972 static bool classof(const Value *From) {
1973 return From->getSubclassID() == ClassID::UnOp;
1974 }
1975};
1976
1977class BinaryOperator : public SingleLLVMInstructionImpl<llvm::BinaryOperator> {
1978protected:
1980 switch (BinOp) {
1981 case llvm::Instruction::Add:
1982 return Opcode::Add;
1983 case llvm::Instruction::FAdd:
1984 return Opcode::FAdd;
1985 case llvm::Instruction::Sub:
1986 return Opcode::Sub;
1987 case llvm::Instruction::FSub:
1988 return Opcode::FSub;
1989 case llvm::Instruction::Mul:
1990 return Opcode::Mul;
1991 case llvm::Instruction::FMul:
1992 return Opcode::FMul;
1993 case llvm::Instruction::UDiv:
1994 return Opcode::UDiv;
1995 case llvm::Instruction::SDiv:
1996 return Opcode::SDiv;
1997 case llvm::Instruction::FDiv:
1998 return Opcode::FDiv;
1999 case llvm::Instruction::URem:
2000 return Opcode::URem;
2001 case llvm::Instruction::SRem:
2002 return Opcode::SRem;
2003 case llvm::Instruction::FRem:
2004 return Opcode::FRem;
2005 case llvm::Instruction::Shl:
2006 return Opcode::Shl;
2007 case llvm::Instruction::LShr:
2008 return Opcode::LShr;
2009 case llvm::Instruction::AShr:
2010 return Opcode::AShr;
2011 case llvm::Instruction::And:
2012 return Opcode::And;
2013 case llvm::Instruction::Or:
2014 return Opcode::Or;
2015 case llvm::Instruction::Xor:
2016 return Opcode::Xor;
2017 case llvm::Instruction::BinaryOpsEnd:
2018 llvm_unreachable("Bad BinOp!");
2019 }
2020 llvm_unreachable("Unhandled BinOp!");
2021 }
2024 getBinOpOpcode(BinOp->getOpcode()), BinOp,
2025 Ctx) {}
2026 friend class Context; // For constructor.
2027
2028public:
2031 const Twine &Name = "");
2032
2034 Value *LHS, Value *RHS,
2035 Value *CopyFrom,
2037 const Twine &Name = "");
2038 /// For isa/dyn_cast.
2039 static bool classof(const Value *From) {
2040 return From->getSubclassID() == ClassID::BinaryOperator;
2041 }
2043};
2044
2045/// An or instruction, which can be marked as "disjoint", indicating that the
2046/// inputs don't have a 1 in the same bit position. Meaning this instruction
2047/// can also be treated as an add.
2049public:
2050 LLVM_ABI void setIsDisjoint(bool B);
2051 bool isDisjoint() const {
2052 return cast<llvm::PossiblyDisjointInst>(Val)->isDisjoint();
2053 }
2054 /// For isa/dyn_cast.
2055 static bool classof(const Value *From) {
2056 return isa<Instruction>(From) &&
2057 cast<Instruction>(From)->getOpcode() == Opcode::Or;
2058 }
2059};
2060
2061class AtomicRMWInst : public SingleLLVMInstructionImpl<llvm::AtomicRMWInst> {
2063 : SingleLLVMInstructionImpl(ClassID::AtomicRMW,
2064 Instruction::Opcode::AtomicRMW, Atomic, Ctx) {
2065 }
2066 friend class Context; // For constructor.
2067
2068public:
2071 return cast<llvm::AtomicRMWInst>(Val)->getOperation();
2072 }
2075 }
2076 static bool isFPOperation(BinOp Op) {
2078 }
2080 cast<llvm::AtomicRMWInst>(Val)->setOperation(Op);
2081 }
2082 Align getAlign() const { return cast<llvm::AtomicRMWInst>(Val)->getAlign(); }
2084 bool isVolatile() const {
2085 return cast<llvm::AtomicRMWInst>(Val)->isVolatile();
2086 }
2087 LLVM_ABI void setVolatile(bool V);
2089 return cast<llvm::AtomicRMWInst>(Val)->getOrdering();
2090 }
2091 LLVM_ABI void setOrdering(AtomicOrdering Ordering);
2093 return cast<llvm::AtomicRMWInst>(Val)->getSyncScopeID();
2094 }
2097 const Value *getPointerOperand() const {
2098 return const_cast<AtomicRMWInst *>(this)->getPointerOperand();
2099 }
2101 const Value *getValOperand() const {
2102 return const_cast<AtomicRMWInst *>(this)->getValOperand();
2103 }
2104 unsigned getPointerAddressSpace() const {
2105 return cast<llvm::AtomicRMWInst>(Val)->getPointerAddressSpace();
2106 }
2108 return cast<llvm::AtomicRMWInst>(Val)->isFloatingPointOperation();
2109 }
2110 static bool classof(const Value *From) {
2111 return From->getSubclassID() == ClassID::AtomicRMW;
2112 }
2113
2114 LLVM_ABI static AtomicRMWInst *
2116 AtomicOrdering Ordering, InsertPosition Pos, Context &Ctx,
2117 SyncScope::ID SSID = SyncScope::System, const Twine &Name = "");
2118};
2119
2121 : public SingleLLVMInstructionImpl<llvm::AtomicCmpXchgInst> {
2123 : SingleLLVMInstructionImpl(ClassID::AtomicCmpXchg,
2124 Instruction::Opcode::AtomicCmpXchg, Atomic,
2125 Ctx) {}
2126 friend class Context; // For constructor.
2127
2128public:
2129 /// Return the alignment of the memory that is being allocated by the
2130 /// instruction.
2131 Align getAlign() const {
2132 return cast<llvm::AtomicCmpXchgInst>(Val)->getAlign();
2133 }
2134
2136 /// Return true if this is a cmpxchg from a volatile memory
2137 /// location.
2138 bool isVolatile() const {
2139 return cast<llvm::AtomicCmpXchgInst>(Val)->isVolatile();
2140 }
2141 /// Specify whether this is a volatile cmpxchg.
2142 LLVM_ABI void setVolatile(bool V);
2143 /// Return true if this cmpxchg may spuriously fail.
2144 bool isWeak() const { return cast<llvm::AtomicCmpXchgInst>(Val)->isWeak(); }
2145 LLVM_ABI void setWeak(bool IsWeak);
2148 }
2151 }
2153 return cast<llvm::AtomicCmpXchgInst>(Val)->getSuccessOrdering();
2154 }
2156
2158 return cast<llvm::AtomicCmpXchgInst>(Val)->getFailureOrdering();
2159 }
2162 return cast<llvm::AtomicCmpXchgInst>(Val)->getMergedOrdering();
2163 }
2165 return cast<llvm::AtomicCmpXchgInst>(Val)->getSyncScopeID();
2166 }
2169 const Value *getPointerOperand() const {
2170 return const_cast<AtomicCmpXchgInst *>(this)->getPointerOperand();
2171 }
2172
2174 const Value *getCompareOperand() const {
2175 return const_cast<AtomicCmpXchgInst *>(this)->getCompareOperand();
2176 }
2177
2179 const Value *getNewValOperand() const {
2180 return const_cast<AtomicCmpXchgInst *>(this)->getNewValOperand();
2181 }
2182
2183 /// Returns the address space of the pointer operand.
2184 unsigned getPointerAddressSpace() const {
2185 return cast<llvm::AtomicCmpXchgInst>(Val)->getPointerAddressSpace();
2186 }
2187
2189 create(Value *Ptr, Value *Cmp, Value *New, MaybeAlign Align,
2190 AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
2192 SyncScope::ID SSID = SyncScope::System, const Twine &Name = "");
2193
2194 static bool classof(const Value *From) {
2195 return From->getSubclassID() == ClassID::AtomicCmpXchg;
2196 }
2197};
2198
2199class AllocaInst final : public UnaryInstruction {
2201 : UnaryInstruction(ClassID::Alloca, Instruction::Opcode::Alloca, AI,
2202 Ctx) {}
2203 friend class Context; // For constructor.
2204
2205public:
2206 LLVM_ABI static AllocaInst *create(Type *Ty, unsigned AddrSpace,
2208 Value *ArraySize = nullptr,
2209 const Twine &Name = "");
2210
2211 /// Return true if there is an allocation size parameter to the allocation
2212 /// instruction that is not 1.
2213 bool isArrayAllocation() const {
2214 return cast<llvm::AllocaInst>(Val)->isArrayAllocation();
2215 }
2216 /// Get the number of elements allocated. For a simple allocation of a single
2217 /// element, this will return a constant 1 value.
2219 const Value *getArraySize() const {
2220 return const_cast<AllocaInst *>(this)->getArraySize();
2221 }
2222 /// Overload to return most specific pointer type.
2223 LLVM_ABI PointerType *getType() const;
2224 /// Return the address space for the allocation.
2225 unsigned getAddressSpace() const {
2226 return cast<llvm::AllocaInst>(Val)->getAddressSpace();
2227 }
2228 /// Get allocation size in bytes. Returns std::nullopt if size can't be
2229 /// determined, e.g. in case of a VLA.
2230 std::optional<TypeSize> getAllocationSize(const DataLayout &DL) const {
2231 return cast<llvm::AllocaInst>(Val)->getAllocationSize(DL);
2232 }
2233 /// Get allocation size in bits. Returns std::nullopt if size can't be
2234 /// determined, e.g. in case of a VLA.
2235 std::optional<TypeSize> getAllocationSizeInBits(const DataLayout &DL) const {
2236 return cast<llvm::AllocaInst>(Val)->getAllocationSizeInBits(DL);
2237 }
2238 /// Return the type that is being allocated by the instruction.
2240 /// for use only in special circumstances that need to generically
2241 /// transform a whole instruction (eg: IR linking and vectorization).
2242 LLVM_ABI void setAllocatedType(Type *Ty);
2243 /// Return the alignment of the memory that is being allocated by the
2244 /// instruction.
2245 Align getAlign() const { return cast<llvm::AllocaInst>(Val)->getAlign(); }
2247 /// Return true if this alloca is in the entry block of the function and is a
2248 /// constant size. If so, the code generator will fold it into the
2249 /// prolog/epilog code, so it is basically free.
2250 bool isStaticAlloca() const {
2251 return cast<llvm::AllocaInst>(Val)->isStaticAlloca();
2252 }
2253 /// Return true if this alloca is used as an inalloca argument to a call. Such
2254 /// allocas are never considered static even if they are in the entry block.
2255 bool isUsedWithInAlloca() const {
2256 return cast<llvm::AllocaInst>(Val)->isUsedWithInAlloca();
2257 }
2258 /// Specify whether this alloca is used to represent the arguments to a call.
2259 LLVM_ABI void setUsedWithInAlloca(bool V);
2260
2261 static bool classof(const Value *From) {
2262 if (auto *I = dyn_cast<Instruction>(From))
2263 return I->getSubclassID() == Instruction::ClassID::Alloca;
2264 return false;
2265 }
2266};
2267
2269 static Opcode getCastOpcode(llvm::Instruction::CastOps CastOp) {
2270 switch (CastOp) {
2271 case llvm::Instruction::ZExt:
2272 return Opcode::ZExt;
2273 case llvm::Instruction::SExt:
2274 return Opcode::SExt;
2275 case llvm::Instruction::FPToUI:
2276 return Opcode::FPToUI;
2277 case llvm::Instruction::FPToSI:
2278 return Opcode::FPToSI;
2279 case llvm::Instruction::FPExt:
2280 return Opcode::FPExt;
2281 case llvm::Instruction::PtrToAddr:
2282 return Opcode::PtrToAddr;
2283 case llvm::Instruction::PtrToInt:
2284 return Opcode::PtrToInt;
2285 case llvm::Instruction::IntToPtr:
2286 return Opcode::IntToPtr;
2287 case llvm::Instruction::SIToFP:
2288 return Opcode::SIToFP;
2289 case llvm::Instruction::UIToFP:
2290 return Opcode::UIToFP;
2291 case llvm::Instruction::Trunc:
2292 return Opcode::Trunc;
2293 case llvm::Instruction::FPTrunc:
2294 return Opcode::FPTrunc;
2295 case llvm::Instruction::BitCast:
2296 return Opcode::BitCast;
2297 case llvm::Instruction::AddrSpaceCast:
2298 return Opcode::AddrSpaceCast;
2299 case llvm::Instruction::CastOpsEnd:
2300 llvm_unreachable("Bad CastOp!");
2301 }
2302 llvm_unreachable("Unhandled CastOp!");
2303 }
2304 /// Use Context::createCastInst(). Don't call the
2305 /// constructor directly.
2307 : UnaryInstruction(ClassID::Cast, getCastOpcode(CI->getOpcode()), CI,
2308 Ctx) {}
2309 friend Context; // for SBCastInstruction()
2310
2311public:
2312 LLVM_ABI static Value *create(Type *DestTy, Opcode Op, Value *Operand,
2314 const Twine &Name = "");
2315 /// For isa/dyn_cast.
2316 LLVM_ABI static bool classof(const Value *From);
2317 LLVM_ABI Type *getSrcTy() const;
2318 LLVM_ABI Type *getDestTy() const;
2319};
2320
2321/// Instruction that can have a nneg flag (zext/uitofp).
2323public:
2324 bool hasNonNeg() const {
2325 return cast<llvm::PossiblyNonNegInst>(Val)->hasNonNeg();
2326 }
2327 LLVM_ABI void setNonNeg(bool B);
2328 /// For isa/dyn_cast.
2329 static bool classof(const Value *From) {
2330 if (auto *I = dyn_cast<Instruction>(From)) {
2331 switch (I->getOpcode()) {
2332 case Opcode::ZExt:
2333 case Opcode::UIToFP:
2334 return true;
2335 default:
2336 return false;
2337 }
2338 }
2339 return false;
2340 }
2341};
2342
2343// Helper class to simplify stamping out CastInst subclasses.
2344template <Instruction::Opcode Op> class CastInstImpl : public CastInst {
2345public:
2346 static Value *create(Value *Src, Type *DestTy, InsertPosition Pos,
2347 Context &Ctx, const Twine &Name = "") {
2348 return CastInst::create(DestTy, Op, Src, Pos, Ctx, Name);
2349 }
2350
2351 static bool classof(const Value *From) {
2352 if (auto *I = dyn_cast<Instruction>(From))
2353 return I->getOpcode() == Op;
2354 return false;
2355 }
2356};
2357
2358class TruncInst final : public CastInstImpl<Instruction::Opcode::Trunc> {};
2359class ZExtInst final : public CastInstImpl<Instruction::Opcode::ZExt> {};
2360class SExtInst final : public CastInstImpl<Instruction::Opcode::SExt> {};
2361class FPTruncInst final : public CastInstImpl<Instruction::Opcode::FPTrunc> {};
2362class FPExtInst final : public CastInstImpl<Instruction::Opcode::FPExt> {};
2363class UIToFPInst final : public CastInstImpl<Instruction::Opcode::UIToFP> {};
2364class SIToFPInst final : public CastInstImpl<Instruction::Opcode::SIToFP> {};
2365class FPToUIInst final : public CastInstImpl<Instruction::Opcode::FPToUI> {};
2366class FPToSIInst final : public CastInstImpl<Instruction::Opcode::FPToSI> {};
2367class IntToPtrInst final : public CastInstImpl<Instruction::Opcode::IntToPtr> {
2368};
2369class PtrToAddrInst final
2370 : public CastInstImpl<Instruction::Opcode::PtrToAddr> {};
2371class PtrToIntInst final : public CastInstImpl<Instruction::Opcode::PtrToInt> {
2372};
2373class BitCastInst final : public CastInstImpl<Instruction::Opcode::BitCast> {};
2375 : public CastInstImpl<Instruction::Opcode::AddrSpaceCast> {
2376public:
2377 /// \Returns the pointer operand.
2379 /// \Returns the pointer operand.
2380 const Value *getPointerOperand() const {
2381 return const_cast<AddrSpaceCastInst *>(this)->getPointerOperand();
2382 }
2383 /// \Returns the operand index of the pointer operand.
2384 static unsigned getPointerOperandIndex() { return 0u; }
2385 /// \Returns the address space of the pointer operand.
2386 unsigned getSrcAddressSpace() const {
2388 }
2389 /// \Returns the address space of the result.
2390 unsigned getDestAddressSpace() const {
2391 return getType()->getPointerAddressSpace();
2392 }
2393};
2394
2395class PHINode final : public SingleLLVMInstructionImpl<llvm::PHINode> {
2396 /// Use Context::createPHINode(). Don't call the constructor directly.
2398 : SingleLLVMInstructionImpl(ClassID::PHI, Opcode::PHI, PHI, Ctx) {}
2399 friend Context; // for PHINode()
2400 /// Helper for mapped_iterator.
2401 struct LLVMBBToBB {
2402 Context &Ctx;
2403 LLVMBBToBB(Context &Ctx) : Ctx(Ctx) {}
2404 LLVM_ABI BasicBlock *operator()(llvm::BasicBlock *LLVMBB) const;
2405 };
2406
2407public:
2408 LLVM_ABI static PHINode *create(Type *Ty, unsigned NumReservedValues,
2410 const Twine &Name = "");
2411 /// For isa/dyn_cast.
2412 LLVM_ABI static bool classof(const Value *From);
2413
2416
2418 LLVMBBToBB BBGetter(Ctx);
2419 return const_block_iterator(cast<llvm::PHINode>(Val)->block_begin(),
2420 BBGetter);
2421 }
2423 LLVMBBToBB BBGetter(Ctx);
2424 return const_block_iterator(cast<llvm::PHINode>(Val)->block_end(),
2425 BBGetter);
2426 }
2428 return make_range(block_begin(), block_end());
2429 }
2430
2432
2434
2435 unsigned getNumIncomingValues() const {
2436 return cast<llvm::PHINode>(Val)->getNumIncomingValues();
2437 }
2438 LLVM_ABI Value *getIncomingValue(unsigned Idx) const;
2439 LLVM_ABI void setIncomingValue(unsigned Idx, Value *V);
2440 static unsigned getOperandNumForIncomingValue(unsigned Idx) {
2442 }
2443 static unsigned getIncomingValueNumForOperand(unsigned Idx) {
2445 }
2446 LLVM_ABI BasicBlock *getIncomingBlock(unsigned Idx) const;
2447 LLVM_ABI BasicBlock *getIncomingBlock(const Use &U) const;
2448
2449 LLVM_ABI void setIncomingBlock(unsigned Idx, BasicBlock *BB);
2450
2451 LLVM_ABI void addIncoming(Value *V, BasicBlock *BB);
2452
2455
2456 LLVM_ABI int getBasicBlockIndex(const BasicBlock *BB) const;
2458
2460
2462 return cast<llvm::PHINode>(Val)->hasConstantOrUndefValue();
2463 }
2464 bool isComplete() const { return cast<llvm::PHINode>(Val)->isComplete(); }
2466 BasicBlock *New);
2468 // TODO: Implement
2469 // void copyIncomingBlocks(iterator_range<const_block_iterator> BBRange,
2470 // uint32_t ToIdx = 0)
2471};
2472
2473// Wraps a static function that takes a single Predicate parameter
2474// LLVMValType should be the type of the wrapped class
2475#define WRAP_STATIC_PREDICATE(FunctionName) \
2476 static auto FunctionName(Predicate P) { return LLVMValType::FunctionName(P); }
2477// Wraps a member function that takes no parameters
2478// LLVMValType should be the type of the wrapped class
2479#define WRAP_MEMBER(FunctionName) \
2480 auto FunctionName() const { return cast<LLVMValType>(Val)->FunctionName(); }
2481// Wraps both--a common idiom in the CmpInst classes
2482#define WRAP_BOTH(FunctionName) \
2483 WRAP_STATIC_PREDICATE(FunctionName) \
2484 WRAP_MEMBER(FunctionName)
2485
2486class CmpInst : public SingleLLVMInstructionImpl<llvm::CmpInst> {
2487protected:
2489 /// Use Context::createCmpInst(). Don't call the constructor directly.
2491 : SingleLLVMInstructionImpl(Id, Opc, CI, Ctx) {}
2492 friend Context; // for CmpInst()
2494 const Twine &Name, IRBuilder<> &Builder,
2495 Context &Ctx);
2496
2497public:
2499
2500 LLVM_ABI static Value *create(Predicate Pred, Value *S1, Value *S2,
2502 const Twine &Name = "");
2504 Value *S2,
2505 const Instruction *FlagsSource,
2507 const Twine &Name = "");
2509 LLVM_ABI void swapOperands();
2510
2511 WRAP_MEMBER(getPredicate);
2512 WRAP_BOTH(isFPPredicate);
2513 WRAP_BOTH(isIntPredicate);
2514 WRAP_STATIC_PREDICATE(getPredicateName);
2515 WRAP_BOTH(getInversePredicate);
2516 WRAP_BOTH(getOrderedPredicate);
2517 WRAP_BOTH(getUnorderedPredicate);
2518 WRAP_BOTH(getSwappedPredicate);
2519 WRAP_BOTH(isStrictPredicate);
2520 WRAP_BOTH(isNonStrictPredicate);
2521 WRAP_BOTH(getStrictPredicate);
2522 WRAP_BOTH(getNonStrictPredicate);
2523 WRAP_BOTH(getFlippedStrictnessPredicate);
2525 WRAP_BOTH(isEquality);
2526 WRAP_BOTH(isRelational);
2528 WRAP_BOTH(isTrueWhenEqual);
2529 WRAP_BOTH(isFalseWhenEqual);
2530 WRAP_BOTH(isUnsigned);
2533
2534 /// Method for support type inquiry through isa, cast, and dyn_cast:
2535 static bool classof(const Value *From) {
2536 return From->getSubclassID() == ClassID::ICmp ||
2537 From->getSubclassID() == ClassID::FCmp;
2538 }
2539
2540 /// Create a result type for fcmp/icmp
2541 LLVM_ABI static Type *makeCmpResultType(Type *OpndType);
2542
2543#ifndef NDEBUG
2544 void dumpOS(raw_ostream &OS) const override;
2545 LLVM_DUMP_METHOD void dump() const;
2546#endif
2547};
2548
2549class ICmpInst : public CmpInst {
2550 /// Use Context::createICmpInst(). Don't call the constructor directly.
2552 : CmpInst(CI, Ctx, ClassID::ICmp, Opcode::ICmp) {}
2553 friend class Context; // For constructor.
2555
2556public:
2557 LLVM_ABI void swapOperands();
2558
2559 WRAP_BOTH(getSignedPredicate);
2560 WRAP_BOTH(getUnsignedPredicate);
2561 WRAP_BOTH(getFlippedSignednessPredicate);
2562 WRAP_BOTH(isEquality);
2564 WRAP_MEMBER(isRelational);
2569
2570 static std::optional<bool> isImpliedByMatchingCmp(CmpPredicate Pred1,
2571 CmpPredicate Pred2) {
2572 return llvm::ICmpInst::isImpliedByMatchingCmp(Pred1, Pred2);
2573 }
2574
2575 static auto predicates() { return llvm::ICmpInst::predicates(); }
2576 static bool compare(const APInt &LHS, const APInt &RHS,
2577 ICmpInst::Predicate Pred) {
2578 return llvm::ICmpInst::compare(LHS, RHS, Pred);
2579 }
2580
2581 static bool classof(const Value *From) {
2582 return From->getSubclassID() == ClassID::ICmp;
2583 }
2584};
2585
2586class FCmpInst : public CmpInst {
2587 /// Use Context::createFCmpInst(). Don't call the constructor directly.
2589 : CmpInst(CI, Ctx, ClassID::FCmp, Opcode::FCmp) {}
2590 friend class Context; // For constructor.
2592
2593public:
2594 LLVM_ABI void swapOperands();
2595
2596 WRAP_BOTH(isEquality);
2598 WRAP_MEMBER(isRelational);
2599
2600 static auto predicates() { return llvm::FCmpInst::predicates(); }
2601 static bool compare(const APFloat &LHS, const APFloat &RHS,
2602 FCmpInst::Predicate Pred) {
2603 return llvm::FCmpInst::compare(LHS, RHS, Pred);
2604 }
2605
2606 static bool classof(const Value *From) {
2607 return From->getSubclassID() == ClassID::FCmp;
2608 }
2609};
2610
2611#undef WRAP_STATIC_PREDICATE
2612#undef WRAP_MEMBER
2613#undef WRAP_BOTH
2614
2615/// An LLLVM Instruction that has no SandboxIR equivalent class gets mapped to
2616/// an OpaqueInstr.
2617class OpaqueInst : public SingleLLVMInstructionImpl<llvm::Instruction> {
2619 : SingleLLVMInstructionImpl(ClassID::Opaque, Opcode::Opaque, I, Ctx) {}
2621 : SingleLLVMInstructionImpl(SubclassID, Opcode::Opaque, I, Ctx) {}
2622 friend class Context; // For constructor.
2623
2624public:
2625 static bool classof(const sandboxir::Value *From) {
2626 return From->getSubclassID() == ClassID::Opaque;
2627 }
2628};
2629
2630} // namespace llvm::sandboxir
2631
2632#endif // LLVM_SANDBOXIR_INSTRUCTION_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
constexpr LLT S1
Rewrite undef for PHI
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition: Compiler.h:213
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:638
return RetTy
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
std::string Name
uint32_t Index
static bool isSigned(unsigned int Opcode)
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
MachineInstr unsigned OpIdx
#define P(N)
ppc ctr loops PowerPC CTR Loops Verify
const SmallVectorImpl< MachineOperand > & Cond
raw_pwrite_stream & OS
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition: APInt.h:78
an instruction to allocate memory on the stack
Definition: Instructions.h:64
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
An instruction that atomically checks whether a specified value is in a memory location,...
Definition: Instructions.h:506
static bool isValidFailureOrdering(AtomicOrdering Ordering)
Definition: Instructions.h:579
static bool isValidSuccessOrdering(AtomicOrdering Ordering)
Definition: Instructions.h:574
an instruction that atomically reads a memory location, combines it with another value,...
Definition: Instructions.h:709
static bool isFPOperation(BinOp Op)
Definition: Instructions.h:823
BinOp
This enumeration lists the possible modifications atomicrmw can make.
Definition: Instructions.h:721
static LLVM_ABI StringRef getOperationName(BinOp Op)
LLVM Basic Block Representation.
Definition: BasicBlock.h:62
Conditional or Unconditional Branch instruction.
This is the base class for all instructions that perform data casts.
Definition: InstrTypes.h:448
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
Definition: InstrTypes.h:612
This class is the base class for the comparison instructions.
Definition: InstrTypes.h:666
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:678
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
Definition: CmpPredicate.h:23
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
static LLVM_ABI bool isValidOperands(const Value *Vec, const Value *Idx)
Return true if an extractelement instruction can be formed with the specified operands.
This instruction extracts a struct member or array element value from an aggregate value.
const unsigned * idx_iterator
static unsigned getAggregateOperandIndex()
This instruction compares its operands according to the predicate given to the constructor.
static LLVM_ABI bool compare(const APFloat &LHS, const APFloat &RHS, FCmpInst::Predicate Pred)
Return result of LHS Pred RHS comparison.
static auto predicates()
Returns the sequence of all FCmp predicates.
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:22
An instruction for ordering other memory operations.
Definition: Instructions.h:429
This class represents a freeze function that returns random concrete value if an operand is either a ...
Represents flags for the getelementptr instruction/expression.
static unsigned getPointerOperandIndex()
This instruction compares its operands according to the predicate given to the constructor.
static LLVM_ABI bool compare(const APInt &LHS, const APInt &RHS, ICmpInst::Predicate Pred)
Return result of LHS Pred RHS comparison.
static LLVM_ABI std::optional< bool > isImpliedByMatchingCmp(CmpPredicate Pred1, CmpPredicate Pred2)
Determine if Pred1 implies Pred2 is true, false, or if nothing can be inferred about the implication,...
static auto predicates()
Returns the sequence of all ICmp predicates.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:2780
static LLVM_ABI bool isValidOperands(const Value *Vec, const Value *NewElt, const Value *Idx)
Return true if an insertelement instruction can be formed with the specified operands.
This instruction inserts a struct field of array element value into an aggregate value.
static unsigned getAggregateOperandIndex()
const unsigned * idx_iterator
static unsigned getInsertedValueOperandIndex()
The landingpad instruction holds all of the information necessary to generate correct exception handl...
An instruction for reading from memory.
Definition: Instructions.h:180
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:303
static unsigned getOperandNumForIncomingValue(unsigned i)
static unsigned getIncomingValueNumForOperand(unsigned i)
Resume the propagation of an exception.
This class represents the LLVM 'select' instruction.
static LLVM_ABI const char * areInvalidOperands(Value *Cond, Value *True, Value *False)
Return a string if the specified operands are invalid for a select operation, otherwise return null.
static LLVM_ABI bool isZeroEltSplatMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses all elements with the same value as the first element of exa...
ArrayRef< int > getShuffleMask() const
static LLVM_ABI bool isSpliceMask(ArrayRef< int > Mask, int NumSrcElts, int &Index)
Return true if this shuffle mask is a splice mask, concatenating the two inputs together and then ext...
static LLVM_ABI bool isValidOperands(const Value *V1, const Value *V2, const Value *Mask)
Return true if a shufflevector instruction can be formed with the specified operands.
static LLVM_ABI bool isSelectMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses elements from its source vectors without lane crossings.
static LLVM_ABI bool isBitRotateMask(ArrayRef< int > Mask, unsigned EltSizeInBits, unsigned MinSubElts, unsigned MaxSubElts, unsigned &NumSubElts, unsigned &RotateAmt)
Checks if the shuffle is a bit rotation of the first operand across multiple subelements,...
static LLVM_ABI bool isOneUseSingleSourceMask(ArrayRef< int > Mask, int VF)
Return true if this shuffle mask represents "clustered" mask of size VF, i.e.
static LLVM_ABI bool isSingleSourceMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses elements from exactly one source vector.
static LLVM_ABI bool isDeInterleaveMaskOfFactor(ArrayRef< int > Mask, unsigned Factor, unsigned &Index)
Check if the mask is a DE-interleave mask of the given factor Factor like: <Index,...
static LLVM_ABI bool isIdentityMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses elements from exactly one source vector without lane crossin...
static LLVM_ABI bool isExtractSubvectorMask(ArrayRef< int > Mask, int NumSrcElts, int &Index)
Return true if this shuffle mask is an extract subvector mask.
static LLVM_ABI bool isReverseMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask swaps the order of elements from exactly one source vector.
static void commuteShuffleMask(MutableArrayRef< int > Mask, unsigned InVecNumElts)
Change values in a shuffle permute mask assuming the two vector operands of length InVecNumElts have ...
static LLVM_ABI bool isTransposeMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask is a transpose mask.
static LLVM_ABI bool isInsertSubvectorMask(ArrayRef< int > Mask, int NumSrcElts, int &NumSubElts, int &Index)
Return true if this shuffle mask is an insert subvector mask.
static LLVM_ABI bool isReplicationMask(ArrayRef< int > Mask, int &ReplicationFactor, int &VF)
Return true if this shuffle mask replicates each of the VF elements in a vector ReplicationFactor tim...
static LLVM_ABI bool isInterleaveMask(ArrayRef< int > Mask, unsigned Factor, unsigned NumInputElts, SmallVectorImpl< unsigned > &StartIndexes)
Return true if the mask interleaves one or more input vectors together.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
An instruction for storing to memory.
Definition: Instructions.h:296
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
ConstantIntT * getCaseValue() const
Resolves case value for current case.
Multiway switch.
static const unsigned DefaultPseudoIndex
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:82
UnaryOps getOpcode() const
Definition: InstrTypes.h:154
This function has undefined behavior.
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
static unsigned getPointerOperandIndex()
LLVM Value Representation.
Definition: Value.h:75
An efficient, type-erasing, non-owning reference to a callable.
A range adaptor for a pair of iterators.
IteratorT end() const
IteratorT begin() const
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
unsigned getSrcAddressSpace() const
\Returns the address space of the pointer operand.
Definition: Instruction.h:2386
Value * getPointerOperand()
\Returns the pointer operand.
Definition: Instruction.h:2378
unsigned getDestAddressSpace() const
\Returns the address space of the result.
Definition: Instruction.h:2390
const Value * getPointerOperand() const
\Returns the pointer operand.
Definition: Instruction.h:2380
static unsigned getPointerOperandIndex()
\Returns the operand index of the pointer operand.
Definition: Instruction.h:2384
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
Definition: Instruction.h:2255
LLVM_ABI Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
bool isStaticAlloca() const
Return true if this alloca is in the entry block of the function and is a constant size.
Definition: Instruction.h:2250
LLVM_ABI void setAllocatedType(Type *Ty)
for use only in special circumstances that need to generically transform a whole instruction (eg: IR ...
bool isArrayAllocation() const
Return true if there is an allocation size parameter to the allocation instruction that is not 1.
Definition: Instruction.h:2213
std::optional< TypeSize > getAllocationSizeInBits(const DataLayout &DL) const
Get allocation size in bits.
Definition: Instruction.h:2235
LLVM_ABI Value * getArraySize()
Get the number of elements allocated.
unsigned getAddressSpace() const
Return the address space for the allocation.
Definition: Instruction.h:2225
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
Definition: Instruction.h:2245
LLVM_ABI PointerType * getType() const
Overload to return most specific pointer type.
LLVM_ABI void setUsedWithInAlloca(bool V)
Specify whether this alloca is used to represent the arguments to a call.
static bool classof(const Value *From)
Definition: Instruction.h:2261
std::optional< TypeSize > getAllocationSize(const DataLayout &DL) const
Get allocation size in bytes.
Definition: Instruction.h:2230
LLVM_ABI void setAlignment(Align Align)
const Value * getArraySize() const
Definition: Instruction.h:2219
static LLVM_ABI AllocaInst * create(Type *Ty, unsigned AddrSpace, InsertPosition Pos, Context &Ctx, Value *ArraySize=nullptr, const Twine &Name="")
const Value * getNewValOperand() const
Definition: Instruction.h:2179
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
Definition: Instruction.h:2184
AtomicOrdering getMergedOrdering() const
Definition: Instruction.h:2161
LLVM_ABI void setSuccessOrdering(AtomicOrdering Ordering)
const Value * getCompareOperand() const
Definition: Instruction.h:2174
LLVM_ABI void setWeak(bool IsWeak)
LLVM_ABI void setVolatile(bool V)
Specify whether this is a volatile cmpxchg.
const Value * getPointerOperand() const
Definition: Instruction.h:2169
LLVM_ABI void setFailureOrdering(AtomicOrdering Ordering)
static bool classof(const Value *From)
Definition: Instruction.h:2194
AtomicOrdering getFailureOrdering() const
Definition: Instruction.h:2157
LLVM_ABI void setAlignment(Align Align)
static LLVM_ABI AtomicCmpXchgInst * create(Value *Ptr, Value *Cmp, Value *New, MaybeAlign Align, AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, InsertPosition Pos, Context &Ctx, SyncScope::ID SSID=SyncScope::System, const Twine &Name="")
static bool isValidFailureOrdering(AtomicOrdering Ordering)
Definition: Instruction.h:2149
bool isVolatile() const
Return true if this is a cmpxchg from a volatile memory location.
Definition: Instruction.h:2138
static bool isValidSuccessOrdering(AtomicOrdering Ordering)
Definition: Instruction.h:2146
LLVM_ABI void setSyncScopeID(SyncScope::ID SSID)
AtomicOrdering getSuccessOrdering() const
Definition: Instruction.h:2152
SyncScope::ID getSyncScopeID() const
Definition: Instruction.h:2164
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
Definition: Instruction.h:2131
bool isWeak() const
Return true if this cmpxchg may spuriously fail.
Definition: Instruction.h:2144
LLVM_ABI Value * getValOperand()
static LLVM_ABI AtomicRMWInst * create(BinOp Op, Value *Ptr, Value *Val, MaybeAlign Align, AtomicOrdering Ordering, InsertPosition Pos, Context &Ctx, SyncScope::ID SSID=SyncScope::System, const Twine &Name="")
const Value * getPointerOperand() const
Definition: Instruction.h:2097
LLVM_ABI void setSyncScopeID(SyncScope::ID SSID)
unsigned getPointerAddressSpace() const
Definition: Instruction.h:2104
llvm::AtomicRMWInst::BinOp BinOp
Definition: Instruction.h:2069
LLVM_ABI void setOrdering(AtomicOrdering Ordering)
SyncScope::ID getSyncScopeID() const
Definition: Instruction.h:2092
LLVM_ABI void setVolatile(bool V)
const Value * getValOperand() const
Definition: Instruction.h:2101
static StringRef getOperationName(BinOp Op)
Definition: Instruction.h:2073
AtomicOrdering getOrdering() const
Definition: Instruction.h:2088
LLVM_ABI Value * getPointerOperand()
static bool classof(const Value *From)
Definition: Instruction.h:2110
static bool isFPOperation(BinOp Op)
Definition: Instruction.h:2076
LLVM_ABI void setAlignment(Align Align)
Iterator for Instructions in a `BasicBlock.
Definition: BasicBlock.h:24
LLVM_ABI BasicBlock * getNodeParent() const
\Returns the parent BB.
Definition: BasicBlock.cpp:43
Contains a list of sandboxir::Instruction's.
Definition: BasicBlock.h:68
iterator end() const
Definition: BasicBlock.h:89
static LLVM_ABI Value * create(Instruction::Opcode Op, Value *LHS, Value *RHS, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static Opcode getBinOpOpcode(llvm::Instruction::BinaryOps BinOp)
Definition: Instruction.h:1979
static bool classof(const Value *From)
For isa/dyn_cast.
Definition: Instruction.h:2039
BinaryOperator(llvm::BinaryOperator *BinOp, Context &Ctx)
Definition: Instruction.h:2022
static LLVM_ABI Value * createWithCopiedFlags(Instruction::Opcode Op, Value *LHS, Value *RHS, Value *CopyFrom, InsertPosition Pos, Context &Ctx, const Twine &Name="")
LLVM_ABI BasicBlock * getSuccessor(unsigned SuccIdx) const
LLVM_ABI Value * getCondition() const
LLVM_ABI void setSuccessor(unsigned Idx, BasicBlock *NewSucc)
unsigned getNumSuccessors() const
Definition: Instruction.h:1044
iterator_range< sb_succ_op_iterator > successors()
Definition: Instruction.h:1065
static LLVM_ABI BranchInst * create(BasicBlock *IfTrue, InsertPosition Pos, Context &Ctx)
static LLVM_ABI bool classof(const Value *From)
For isa/dyn_cast.
iterator_range< const_sb_succ_op_iterator > successors() const
Definition: Instruction.h:1077
iterator_range< const_op_iterator > args() const
Definition: Instruction.h:1367
CallingConv::ID getCallingConv() const
Definition: Instruction.h:1422
const Function * getCaller() const
Definition: Instruction.h:1410
LLVM_ABI Function * getCalledFunction() const
LLVM_ABI Use getCalledOperandUse() const
LLVM_ABI FunctionType * getFunctionType() const
const_op_iterator arg_end() const
Definition: Instruction.h:1361
iterator_range< op_iterator > args()
Definition: Instruction.h:1364
static bool classof(const Value *From)
Definition: Instruction.h:1305
Value * getArgOperand(unsigned OpIdx) const
Definition: Instruction.h:1373
LLVM_ABI void setCalledFunction(Function *F)
Use getArgOperandUse(unsigned Idx)
Definition: Instruction.h:1386
bool isDataOperand(Use U) const
Definition: Instruction.h:1340
unsigned getArgOperandNo(Use U) const
Definition: Instruction.h:1394
const_op_iterator data_operands_end() const
Definition: Instruction.h:1323
op_iterator data_operands_end()
Definition: Instruction.h:1318
LLVM_ABI Function * getCaller()
unsigned getDataOperandNo(Use U) const
Definition: Instruction.h:1345
unsigned getNumTotalBundleOperands() const
Return the total number operands (not operand bundles) used by every operand bundle in this OperandBu...
Definition: Instruction.h:1352
iterator_range< op_iterator > data_ops()
Definition: Instruction.h:1328
const_op_iterator data_operands_begin() const
Definition: Instruction.h:1315
bool data_operands_empty() const
Definition: Instruction.h:1334
bool hasArgument(const Value *V) const
Definition: Instruction.h:1397
LLVM_ABI Value * getCalledOperand() const
void setCalledOperand(Value *V)
Definition: Instruction.h:1420
unsigned arg_size() const
Definition: Instruction.h:1371
unsigned data_operands_size() const
Definition: Instruction.h:1337
const_op_iterator arg_begin() const
Definition: Instruction.h:1357
Intrinsic::ID getIntrinsicID() const
Definition: Instruction.h:1417
Use getArgOperandUse(unsigned Idx) const
Definition: Instruction.h:1382
op_iterator data_operands_begin()
Definition: Instruction.h:1314
bool isArgOperand(Use U) const
Definition: Instruction.h:1391
void setArgOperand(unsigned OpIdx, Value *NewOp)
Definition: Instruction.h:1377
iterator_range< const_op_iterator > data_ops() const
Definition: Instruction.h:1331
bool isCallee(Use U) const
Definition: Instruction.h:1406
LLVM_ABI Value * getIndirectDestLabelUse(unsigned Idx) const
static LLVM_ABI CallBrInst * create(FunctionType *FTy, Value *Func, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, InsertPosition Pos, Context &Ctx, const Twine &NameStr="")
LLVM_ABI Value * getIndirectDestLabel(unsigned Idx) const
LLVM_ABI BasicBlock * getSuccessor(unsigned Idx) const
static bool classof(const Value *From)
Definition: Instruction.h:1496
LLVM_ABI void setIndirectDest(unsigned Idx, BasicBlock *BB)
LLVM_ABI BasicBlock * getDefaultDest() const
unsigned getNumIndirectDests() const
Definition: Instruction.h:1499
LLVM_ABI BasicBlock * getIndirectDest(unsigned Idx) const
LLVM_ABI SmallVector< BasicBlock *, 16 > getIndirectDests() const
unsigned getNumSuccessors() const
Definition: Instruction.h:1510
LLVM_ABI void setDefaultDest(BasicBlock *BB)
static LLVM_ABI CallInst * create(FunctionType *FTy, Value *Func, ArrayRef< Value * > Args, InsertPosition Pos, Context &Ctx, const Twine &NameStr="")
static bool classof(const Value *From)
Definition: Instruction.h:1441
static bool classof(const Value *From)
Definition: Instruction.h:2351
static Value * create(Value *Src, Type *DestTy, InsertPosition Pos, Context &Ctx, const Twine &Name="")
Definition: Instruction.h:2346
LLVM_ABI Type * getSrcTy() const
static LLVM_ABI Value * create(Type *DestTy, Opcode Op, Value *Operand, InsertPosition Pos, Context &Ctx, const Twine &Name="")
LLVM_ABI Type * getDestTy() const
static LLVM_ABI bool classof(const Value *From)
For isa/dyn_cast.
static bool classof(const Value *From)
Definition: Instruction.h:1603
static LLVM_ABI CatchPadInst * create(Value *ParentPad, ArrayRef< Value * > Args, InsertPosition Pos, Context &Ctx, const Twine &Name="")
LLVM_ABI CatchSwitchInst * getCatchSwitch() const
LLVM_ABI CatchPadInst * getCatchPad() const
LLVM_ABI BasicBlock * getSuccessor() const
static bool classof(const Value *From)
Definition: Instruction.h:1642
LLVM_ABI void setSuccessor(BasicBlock *NewSucc)
LLVM_ABI void setCatchPad(CatchPadInst *CatchPad)
LLVM_ABI Value * getCatchSwitchParentPad() const
static LLVM_ABI CatchReturnInst * create(CatchPadInst *CatchPad, BasicBlock *BB, InsertPosition Pos, Context &Ctx)
LLVM_ABI void addHandler(BasicBlock *Dest)
const_handler_iterator handler_begin() const
Definition: Instruction.h:1804
const_handler_iterator handler_end() const
Definition: Instruction.h:1813
const BasicBlock *(*)(const Value *) ConstDerefFnTy
Definition: Instruction.h:1793
BasicBlock *(*)(Value *) DerefFnTy
Definition: Instruction.h:1790
LLVM_ABI void setParentPad(Value *ParentPad)
LLVM_ABI void setUnwindDest(BasicBlock *UnwindDest)
handler_iterator handler_begin()
Definition: Instruction.h:1798
static LLVM_ABI CatchSwitchInst * create(Value *ParentPad, BasicBlock *UnwindBB, unsigned NumHandlers, InsertPosition Pos, Context &Ctx, const Twine &Name="")
mapped_iterator< const_op_iterator, ConstDerefFnTy > const_handler_iterator
Definition: Instruction.h:1795
mapped_iterator< op_iterator, DerefFnTy > handler_iterator
Definition: Instruction.h:1791
static bool classof(const Value *From)
Definition: Instruction.h:1841
handler_iterator handler_end()
Definition: Instruction.h:1810
void setSuccessor(unsigned Idx, BasicBlock *NewSucc)
Definition: Instruction.h:1835
LLVM_ABI BasicBlock * getUnwindDest() const
LLVM_ABI Value * getParentPad() const
BasicBlock * getSuccessor(unsigned Idx) const
Definition: Instruction.h:1830
const_handler_range handlers() const
Definition: Instruction.h:1819
static LLVM_ABI CleanupPadInst * create(Value *ParentPad, ArrayRef< Value * > Args, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static bool classof(const Value *From)
Definition: Instruction.h:1618
LLVM_ABI CleanupPadInst * getCleanupPad() const
LLVM_ABI void setUnwindDest(BasicBlock *NewDest)
static LLVM_ABI CleanupReturnInst * create(CleanupPadInst *CleanupPad, BasicBlock *UnwindBB, InsertPosition Pos, Context &Ctx)
LLVM_ABI BasicBlock * getUnwindDest() const
LLVM_ABI void setCleanupPad(CleanupPadInst *CleanupPad)
static bool classof(const Value *From)
Definition: Instruction.h:1672
WRAP_STATIC_PREDICATE(isUnordered)
WRAP_BOTH(isTrueWhenEqual)
WRAP_BOTH(isFPPredicate)
WRAP_BOTH(getInversePredicate)
static LLVM_ABI Value * createCommon(Value *Cond, Value *True, Value *False, const Twine &Name, IRBuilder<> &Builder, Context &Ctx)
void dumpOS(raw_ostream &OS) const override
LLVM_DUMP_METHOD void dump() const
WRAP_BOTH(getNonStrictPredicate)
static LLVM_ABI Value * createWithCopiedFlags(Predicate Pred, Value *S1, Value *S2, const Instruction *FlagsSource, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static LLVM_ABI Type * makeCmpResultType(Type *OpndType)
Create a result type for fcmp/icmp.
static LLVM_ABI Value * create(Predicate Pred, Value *S1, Value *S2, InsertPosition Pos, Context &Ctx, const Twine &Name="")
LLVM_ABI void setPredicate(Predicate P)
WRAP_BOTH(isIntPredicate)
WRAP_STATIC_PREDICATE(isOrdered)
WRAP_BOTH(isNonStrictPredicate)
WRAP_BOTH(getSwappedPredicate)
WRAP_BOTH(getStrictPredicate)
WRAP_BOTH(isStrictPredicate)
WRAP_STATIC_PREDICATE(getPredicateName)
CmpInst(llvm::CmpInst *CI, Context &Ctx, ClassID Id, Opcode Opc)
Use Context::createCmpInst(). Don't call the constructor directly.
Definition: Instruction.h:2490
WRAP_BOTH(isFalseWhenEqual)
WRAP_MEMBER(getPredicate)
LLVM_ABI void swapOperands()
WRAP_BOTH(getUnorderedPredicate)
WRAP_BOTH(getFlippedStrictnessPredicate)
WRAP_BOTH(getOrderedPredicate)
WRAP_MEMBER(isCommutative)
static bool classof(const Value *From)
Method for support type inquiry through isa, cast, and dyn_cast:
Definition: Instruction.h:2535
auto & getLLVMIRBuilder()
Definition: Context.h:157
const Value * getVectorOperand() const
Definition: Instruction.h:518
const Value * getIndexOperand() const
Definition: Instruction.h:519
static LLVM_ABI Value * create(Value *Vec, Value *Idx, InsertPosition Pos, Context &Ctx, const Twine &Name="")
LLVM_ABI VectorType * getVectorOperandType() const
static bool classof(const Value *From)
Definition: Instruction.h:509
static bool isValidOperands(const Value *Vec, const Value *Idx)
Definition: Instruction.h:513
static LLVM_ABI Value * create(Value *Agg, ArrayRef< unsigned > Idxs, InsertPosition Pos, Context &Ctx, const Twine &Name="")
const Value * getAggregateOperand() const
Definition: Instruction.h:1144
static unsigned getAggregateOperandIndex()
Definition: Instruction.h:1147
idx_iterator idx_begin() const
Definition: Instruction.h:1131
ArrayRef< unsigned > getIndices() const
Definition: Instruction.h:1151
static LLVM_ABI Type * getIndexedType(Type *Agg, ArrayRef< unsigned > Idxs)
Returns the type of the element that would be extracted with an extractvalue instruction with the spe...
static bool classof(const Value *From)
Definition: Instruction.h:1119
iterator_range< idx_iterator > indices() const
Definition: Instruction.h:1137
idx_iterator idx_end() const
Definition: Instruction.h:1134
WRAP_MEMBER(isCommutative)
LLVM_ABI void swapOperands()
static bool compare(const APFloat &LHS, const APFloat &RHS, FCmpInst::Predicate Pred)
Definition: Instruction.h:2601
static bool classof(const Value *From)
Definition: Instruction.h:2606
AtomicOrdering getOrdering() const
Returns the ordering constraint of this fence instruction.
Definition: Instruction.h:422
static LLVM_ABI FenceInst * create(AtomicOrdering Ordering, InsertPosition Pos, Context &Ctx, SyncScope::ID SSID=SyncScope::System)
LLVM_ABI void setOrdering(AtomicOrdering Ordering)
Sets the ordering constraint of this fence instruction.
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this fence instruction.
Definition: Instruction.h:429
static bool classof(const Value *From)
Definition: Instruction.h:434
LLVM_ABI void setSyncScopeID(SyncScope::ID SSID)
Sets the synchronization scope ID of this fence instruction.
static LLVM_ABI FreezeInst * create(Value *V, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static bool classof(const Value *From)
Definition: Instruction.h:1192
static bool classof(const Value *From)
Definition: Instruction.h:1584
LLVM_ABI Value * getArgOperand(unsigned Idx) const
Return the Idx-th funcletpad argument.
LLVM_ABI Value * getParentPad() const
Return the outer EH-pad this funclet is nested within.
unsigned arg_size() const
Return the number of funcletpad arguments.
Definition: Instruction.h:1569
LLVM_ABI void setParentPad(Value *ParentPad)
LLVM_ABI void setArgOperand(unsigned Idx, Value *V)
Set the Idx-th funcletpad argument.
iterator_range< op_iterator > indices()
Definition: Instruction.h:1712
const_op_iterator idx_begin() const
Definition: Instruction.h:1705
unsigned getPointerAddressSpace() const
Definition: Instruction.h:1724
GEPNoWrapFlags getNoWrapFlags() const
Definition: Instruction.h:1736
LLVM_ABI Type * getResultElementType() const
LLVM_ABI Type * getPointerOperandType() const
static unsigned getPointerOperandIndex()
Definition: Instruction.h:1720
LLVM_ABI Type * getSourceElementType() const
static bool classof(const Value *From)
Definition: Instruction.h:1694
const_op_iterator idx_end() const
Definition: Instruction.h:1709
LLVM_ABI Value * getPointerOperand() const
bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const
Definition: Instruction.h:1748
iterator_range< const_op_iterator > indices() const
Definition: Instruction.h:1715
static LLVM_ABI Value * create(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, InsertPosition Pos, Context &Ctx, const Twine &NameStr="")
static std::optional< bool > isImpliedByMatchingCmp(CmpPredicate Pred1, CmpPredicate Pred2)
Definition: Instruction.h:2570
WRAP_BOTH(getSignedPredicate)
static bool compare(const APInt &LHS, const APInt &RHS, ICmpInst::Predicate Pred)
Definition: Instruction.h:2576
LLVM_ABI void swapOperands()
WRAP_BOTH(getUnsignedPredicate)
WRAP_MEMBER(isCommutative)
WRAP_BOTH(getFlippedSignednessPredicate)
static bool classof(const Value *From)
Definition: Instruction.h:2581
static LLVM_ABI Value * create(Value *Vec, Value *NewElt, Value *Idx, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static bool isValidOperands(const Value *Vec, const Value *NewElt, const Value *Idx)
Definition: Instruction.h:490
static bool classof(const Value *From)
Definition: Instruction.h:487
InsertPosition(BBIterator InsertAt)
Definition: Instruction.h:34
InsertPosition(BasicBlock *InsertAtEnd)
Definition: Instruction.h:30
const BBIterator & getIterator() const
Definition: Instruction.h:36
BasicBlock * getBasicBlock() const
Definition: Instruction.h:38
idx_iterator idx_end() const
Definition: Instruction.h:982
iterator_range< idx_iterator > indices() const
Definition: Instruction.h:985
static bool classof(const Value *From)
Definition: Instruction.h:974
const Value * getInsertedValueOperand() const
Definition: Instruction.h:1002
const Value * getAggregateOperand() const
Definition: Instruction.h:992
static unsigned getInsertedValueOperandIndex()
Definition: Instruction.h:1005
ArrayRef< unsigned > getIndices() const
Definition: Instruction.h:1009
static LLVM_ABI Value * create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, InsertPosition Pos, Context &Ctx, const Twine &Name="")
idx_iterator idx_begin() const
Definition: Instruction.h:979
static unsigned getAggregateOperandIndex()
Definition: Instruction.h:995
A sandboxir::User with operands, opcode and linked with previous/next instructions in an instruction ...
Definition: Instruction.h:43
bool hasNoUnsignedWrap() const
Determine whether the no signed wrap flag is set.
Definition: Instruction.h:226
static IRBuilder & setInsertPos(InsertPosition Pos)
Helper function for create().
Definition: Instruction.h:104
LLVM_ABI void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
bool isSpecialTerminator() const
Definition: Instruction.h:156
const DataLayout & getDataLayout() const
Definition: Instruction.h:134
bool hasAllowReassoc() const
Determine whether the allow-reassociation flag is set.
Definition: Instruction.h:246
LLVM_ABI void setHasAllowReassoc(bool B)
Set or clear the reassociation flag on this instruction, which must be an operator which supports thi...
virtual unsigned getNumOfIRInstrs() const =0
This is used by BasicBlock::iterator.
bool hasNoSignedZeros() const
Determine whether the no-signed-zeros flag is set.
Definition: Instruction.h:271
const char * getOpcodeName() const
Definition: Instruction.h:132
LLVM_ABI void setHasNoSignedWrap(bool B=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
LLVM_ABI void insertAfter(Instruction *AfterI)
Insert this detached instruction after AfterI.
bool hasMetadata(unsigned KindID) const
Return true if this instruction has the given type of metadata attached.
Definition: Instruction.h:182
bool hasMetadataOtherThanDebugLoc() const
Return true if this instruction has metadata attached to it other than a debug location.
Definition: Instruction.h:177
void moveAfter(Instruction *After)
Move this instruction after After.
Definition: Instruction.h:208
LLVM_ABI void moveBefore(BasicBlock &BB, const BBIterator &WhereIt)
Move this instruction to WhereIt.
bool hasAllowContract() const
Determine whether the allow-contract flag is set.
Definition: Instruction.h:287
LLVM_ABI void setIsExact(bool B=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag.
bool hasApproxFunc() const
Determine whether the approximate-math-functions flag is set.
Definition: Instruction.h:295
bool hasNoSignedWrap() const
Determine whether the no signed wrap flag is set.
Definition: Instruction.h:233
LLVM_ABI void setHasNoUnsignedWrap(bool B=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
Opcode getOpcode() const
\Returns this Instruction's opcode.
Definition: Instruction.h:130
void dumpOS(raw_ostream &OS) const override
bool isFast() const
Determine whether all fast-math-flags are set.
Definition: Instruction.h:240
LLVM_ABI BBIterator getIterator() const
\Returns a BasicBlock::iterator for this Instruction.
Definition: Instruction.cpp:38
LLVM_ABI void setFast(bool B)
Set or clear all fast-math-flags on this instruction, which must be an operator which supports this f...
LLVM_ABI void setHasApproxFunc(bool B)
Set or clear the approximate-math-functions flag on this instruction, which must be an operator which...
LLVM_ABI void setHasNoNaNs(bool B)
Set or clear the no-nans flag on this instruction, which must be an operator which supports this flag...
LLVM_ABI void copyFastMathFlags(FastMathFlags FMF)
Convenience function for transferring all fast-math flag values to this instruction,...
LLVM_ABI void setHasNoSignedZeros(bool B)
Set or clear the no-signed-zeros flag on this instruction, which must be an operator which supports t...
LLVM_ABI void insertInto(BasicBlock *BB, const BBIterator &WhereIt)
Insert this detached instruction into BB at WhereIt.
bool mayThrow(bool IncludePhaseOneUnwind=false) const
Definition: Instruction.h:358
LLVM_ABI llvm::Instruction * getTopmostLLVMInstruction() const
A SandboxIR Instruction may map to multiple LLVM IR Instruction.
Definition: Instruction.cpp:26
bool hasMetadata() const
Return true if the instruction has any metadata attached to it.
Definition: Instruction.h:171
LLVM_ABI void setHasAllowContract(bool B)
Set or clear the allow-contract flag on this instruction, which must be an operator which supports th...
bool isOnlyUserOfAnyOperand() const
Definition: Instruction.h:159
virtual SmallVector< llvm::Instruction *, 1 > getLLVMInstrs() const =0
\Returns the LLVM IR Instructions that this SandboxIR maps to in program order.
void moveBefore(Instruction *Before)
Move this instruction before Before.
Definition: Instruction.h:204
LLVM_ABI Type * getAccessType() const
bool mayReadOrWriteMemory() const
Definition: Instruction.h:340
bool isExact() const
Determine whether the exact flag is set.
Definition: Instruction.h:254
Instruction(ClassID ID, Opcode Opc, llvm::Instruction *I, sandboxir::Context &SBCtx)
Definition: Instruction.h:53
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
Definition: Instruction.h:305
bool comesBefore(const Instruction *Other) const
Given an instruction Other in the same basic block as this instruction, return true if this instructi...
Definition: Instruction.h:215
LLVM_ABI Instruction * getNextNode() const
\Returns the next sandboxir::Instruction in the block, or nullptr if at the end of the block.
Definition: Instruction.cpp:43
bool hasNoInfs() const
Determine whether the no-infs flag is set.
Definition: Instruction.h:265
LLVM_ABI void removeFromParent()
Detach this from its parent BasicBlock without deleting it.
Definition: Instruction.cpp:66
LLVM_ABI Instruction * getPrevNode() const
\Returns the previous sandboxir::Instruction in the block, or nullptr if at the beginning of the bloc...
Definition: Instruction.cpp:58
bool hasNoNaNs() const
Determine whether the no-NaNs flag is set.
Definition: Instruction.h:259
bool hasAllowReciprocal() const
Determine whether the allow-reciprocal flag is set.
Definition: Instruction.h:279
LLVM_ABI void insertBefore(Instruction *BeforeI)
Insert this detached instruction before BeforeI.
LLVM_ABI void eraseFromParent()
Detach this Value from its parent and delete it.
Definition: Instruction.cpp:74
LLVM_ABI void setHasAllowReciprocal(bool B)
Set or clear the allow-reciprocal flag on this instruction, which must be an operator which supports ...
LLVM_ABI void setHasNoInfs(bool B)
Set or clear the no-infs flag on this instruction, which must be an operator which supports this flag...
LLVM_ABI BasicBlock * getParent() const
\Returns the BasicBlock containing this Instruction, or null if it is detached.
static LLVM_ABI bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
LLVM_ABI BasicBlock * getUnwindDest() const
static LLVM_ABI InvokeInst * create(FunctionType *FTy, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, InsertPosition Pos, Context &Ctx, const Twine &NameStr="")
LLVM_ABI void setNormalDest(BasicBlock *BB)
unsigned getNumSuccessors() const
Definition: Instruction.h:1477
LLVM_ABI void setUnwindDest(BasicBlock *BB)
LLVM_ABI BasicBlock * getSuccessor(unsigned SuccIdx) const
static bool classof(const Value *From)
Definition: Instruction.h:1461
LLVM_ABI BasicBlock * getNormalDest() const
void setSuccessor(unsigned SuccIdx, BasicBlock *NewSucc)
Definition: Instruction.h:1470
LLVM_ABI LandingPadInst * getLandingPadInst() const
bool isFilter(unsigned Idx) const
Return 'true' if the clause and index Idx is a filter clause.
Definition: Instruction.h:1547
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
Definition: Instruction.h:1529
LLVM_ABI void setCleanup(bool V)
Indicate that this landingpad instruction is a cleanup.
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
Definition: Instruction.h:1551
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
Definition: Instruction.h:1543
LLVM_ABI Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
static bool classof(const Value *From)
Definition: Instruction.h:1555
static LLVM_ABI LandingPadInst * create(Type *RetTy, unsigned NumReservedClauses, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static LLVM_ABI LoadInst * create(Type *Ty, Value *Ptr, MaybeAlign Align, InsertPosition Pos, bool IsVolatile, Context &Ctx, const Twine &Name="")
static LoadInst * create(Type *Ty, Value *Ptr, MaybeAlign Align, InsertPosition Pos, Context &Ctx, const Twine &Name="")
Definition: Instruction.h:1212
LLVM_ABI void setVolatile(bool V)
Specify whether this is a volatile load or not.
LLVM_ABI Value * getPointerOperand() const
bool isVolatile() const
Return true if this is a load from a volatile memory location.
Definition: Instruction.h:1205
static LLVM_ABI bool classof(const Value *From)
For isa/dyn_cast.
An LLLVM Instruction that has no SandboxIR equivalent class gets mapped to an OpaqueInstr.
Definition: Instruction.h:2617
static bool classof(const sandboxir::Value *From)
Definition: Instruction.h:2625
Iterator for the Use edges of a User's operands.
Definition: User.h:24
LLVM_ABI Value * hasConstantValue() const
iterator_range< const_block_iterator > blocks() const
Definition: Instruction.h:2427
LLVM_ABI int getBasicBlockIndex(const BasicBlock *BB) const
const_block_iterator block_end() const
Definition: Instruction.h:2422
const_op_range incoming_values() const
Definition: Instruction.h:2433
bool hasConstantOrUndefValue() const
Definition: Instruction.h:2461
unsigned getNumIncomingValues() const
Definition: Instruction.h:2435
LLVM_ABI Value * getIncomingValue(unsigned Idx) const
LLVM_ABI void setIncomingBlock(unsigned Idx, BasicBlock *BB)
LLVM_ABI void removeIncomingValueIf(function_ref< bool(unsigned)> Predicate)
static LLVM_ABI bool classof(const Value *From)
For isa/dyn_cast.
const_block_iterator block_begin() const
Definition: Instruction.h:2417
static LLVM_ABI PHINode * create(Type *Ty, unsigned NumReservedValues, InsertPosition Pos, Context &Ctx, const Twine &Name="")
LLVM_ABI Value * removeIncomingValue(unsigned Idx)
mapped_iterator< llvm::PHINode::const_block_iterator, LLVMBBToBB > const_block_iterator
Definition: Instruction.h:2415
LLVM_ABI void setIncomingValue(unsigned Idx, Value *V)
LLVM_ABI BasicBlock * getIncomingBlock(unsigned Idx) const
static unsigned getIncomingValueNumForOperand(unsigned Idx)
Definition: Instruction.h:2443
LLVM_ABI void replaceIncomingBlockWith(const BasicBlock *Old, BasicBlock *New)
LLVM_ABI Value * getIncomingValueForBlock(const BasicBlock *BB) const
LLVM_ABI void addIncoming(Value *V, BasicBlock *BB)
static unsigned getOperandNumForIncomingValue(unsigned Idx)
Definition: Instruction.h:2440
An or instruction, which can be marked as "disjoint", indicating that the inputs don't have a 1 in th...
Definition: Instruction.h:2048
static bool classof(const Value *From)
For isa/dyn_cast.
Definition: Instruction.h:2055
Instruction that can have a nneg flag (zext/uitofp).
Definition: Instruction.h:2322
static bool classof(const Value *From)
For isa/dyn_cast.
Definition: Instruction.h:2329
static LLVM_ABI ResumeInst * create(Value *Exn, InsertPosition Pos, Context &Ctx)
unsigned getNumSuccessors() const
Definition: Instruction.h:1855
static bool classof(const Value *From)
Definition: Instruction.h:1858
LLVM_ABI Value * getValue() const
static LLVM_ABI ReturnInst * create(Value *RetVal, InsertPosition Pos, Context &Ctx)
static bool classof(const Value *From)
Definition: Instruction.h:1290
LLVM_ABI Value * getReturnValue() const
\Returns null if there is no return value.
static const char * areInvalidOperands(Value *Cond, Value *True, Value *False)
Return a string if the specified operands are invalid for a select operation, otherwise return null.
Definition: Instruction.h:465
static LLVM_ABI bool classof(const Value *From)
For isa/dyn_cast.
const Value * getFalseValue() const
Definition: Instruction.h:453
const Value * getTrueValue() const
Definition: Instruction.h:452
void setTrueValue(Value *New)
Definition: Instruction.h:459
static LLVM_ABI Value * create(Value *Cond, Value *True, Value *False, InsertPosition Pos, Context &Ctx, const Twine &Name="")
void setCondition(Value *New)
Definition: Instruction.h:458
const Value * getCondition() const
Definition: Instruction.h:451
void setFalseValue(Value *New)
Definition: Instruction.h:460
void getShuffleMask(SmallVectorImpl< int > &Result) const
Return the mask for this instruction as a vector of integers.
Definition: Instruction.h:577
static bool isZeroEltSplatMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses all elements with the same value as the first element of exa...
Definition: Instruction.h:720
bool isExtractSubvectorMask(int &Index) const
Return true if this shuffle mask is an extract subvector mask.
Definition: Instruction.h:822
bool changesLength() const
Return true if this shuffle returns a vector with a different number of elements than its source vect...
Definition: Instruction.h:597
bool isReverse() const
Return true if this shuffle swaps the order of elements from exactly one source vector.
Definition: Instruction.h:711
LLVM_ABI VectorType * getType() const
Overload to return most specific vector type.
bool isIdentityWithPadding() const
Return true if this shuffle lengthens exactly one source vector with undefs in the high elements.
Definition: Instruction.h:651
static bool isSingleSourceMask(const Constant *Mask, int NumSrcElts)
Definition: Instruction.h:616
bool isIdentityWithExtract() const
Return true if this shuffle extracts the first N elements of exactly one source vector.
Definition: Instruction.h:657
static bool isIdentityMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses elements from exactly one source vector without lane crossin...
Definition: Instruction.h:633
ArrayRef< int > getShuffleMask() const
Definition: Instruction.h:589
static bool isReverseMask(const Constant *Mask, int NumSrcElts)
Definition: Instruction.h:703
LLVM_ABI Constant * getShuffleMaskForBitcode() const
Return the mask for this instruction, for use in bitcode.
static bool isExtractSubvectorMask(const Constant *Mask, int NumSrcElts, int &Index)
Definition: Instruction.h:815
bool isInterleave(unsigned Factor) const
Return if this shuffle interleaves its two input vectors together.
Definition: Instruction.h:895
static bool isInterleaveMask(ArrayRef< int > Mask, unsigned Factor, unsigned NumInputElts, SmallVectorImpl< unsigned > &StartIndexes)
Return true if the mask interleaves one or more input vectors together.
Definition: Instruction.h:918
static bool isOneUseSingleSourceMask(ArrayRef< int > Mask, int VF)
Return true if this shuffle mask represents "clustered" mask of size VF, i.e.
Definition: Instruction.h:877
static bool isTransposeMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask is a transpose mask.
Definition: Instruction.h:768
static bool isTransposeMask(const Constant *Mask, int NumSrcElts)
Definition: Instruction.h:771
static bool isInterleaveMask(ArrayRef< int > Mask, unsigned Factor, unsigned NumInputElts)
Definition: Instruction.h:924
LLVM_ABI void commute()
Swap the operands and adjust the mask to preserve the semantics of the instruction.
static bool isReplicationMask(ArrayRef< int > Mask, int &ReplicationFactor, int &VF)
Return true if this shuffle mask replicates each of the VF elements in a vector ReplicationFactor tim...
Definition: Instruction.h:851
static LLVM_ABI Value * create(Value *V1, Value *V2, Value *Mask, InsertPosition Pos, Context &Ctx, const Twine &Name="")
bool isIdentity() const
Return true if this shuffle chooses elements from exactly one source vector without lane crossings an...
Definition: Instruction.h:645
static bool isReplicationMask(const Constant *Mask, int &ReplicationFactor, int &VF)
Definition: Instruction.h:856
static bool isIdentityMask(const Constant *Mask, int NumSrcElts)
Definition: Instruction.h:636
static bool isDeInterleaveMaskOfFactor(ArrayRef< int > Mask, unsigned Factor)
Definition: Instruction.h:938
static LLVM_ABI Constant * convertShuffleMaskForBitcode(ArrayRef< int > Mask, Type *ResultTy)
bool isSingleSource() const
Return true if this shuffle chooses elements from exactly one source vector without changing the leng...
Definition: Instruction.h:624
static bool isExtractSubvectorMask(ArrayRef< int > Mask, int NumSrcElts, int &Index)
Return true if this shuffle mask is an extract subvector mask.
Definition: Instruction.h:810
bool isSplice(int &Index) const
Return true if this shuffle splices two inputs without changing the length of the vectors.
Definition: Instruction.h:803
static bool isValidOperands(const Value *V1, const Value *V2, const Value *Mask)
Return true if a shufflevector instruction can be formed with the specified operands.
Definition: Instruction.h:548
static bool isSelectMask(const Constant *Mask, int NumSrcElts)
Definition: Instruction.h:679
static bool isSpliceMask(const Constant *Mask, int NumSrcElts, int &Index)
Definition: Instruction.h:794
static bool isBitRotateMask(ArrayRef< int > Mask, unsigned EltSizeInBits, unsigned MinSubElts, unsigned MaxSubElts, unsigned &NumSubElts, unsigned &RotateAmt)
Checks if the shuffle is a bit rotation of the first operand across multiple subelements,...
Definition: Instruction.h:953
bool isReplicationMask(int &ReplicationFactor, int &VF) const
Return true if this shuffle mask is a replication mask.
Definition: Instruction.h:863
bool isConcat() const
Return true if this shuffle concatenates its 2 source vectors.
Definition: Instruction.h:664
static bool isValidOperands(const Value *V1, const Value *V2, ArrayRef< int > Mask)
Definition: Instruction.h:553
static bool isInsertSubvectorMask(const Constant *Mask, int NumSrcElts, int &NumSubElts, int &Index)
Definition: Instruction.h:835
static bool isSpliceMask(ArrayRef< int > Mask, int NumSrcElts, int &Index)
Return true if this shuffle mask is a splice mask, concatenating the two inputs together and then ext...
Definition: Instruction.h:791
static bool isSelectMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses elements from its source vectors without lane crossings.
Definition: Instruction.h:676
static void commuteShuffleMask(MutableArrayRef< int > Mask, unsigned InVecNumElts)
Change values in a shuffle permute mask assuming the two vector operands of length InVecNumElts have ...
Definition: Instruction.h:889
bool increasesLength() const
Return true if this shuffle returns a vector with a greater number of elements than its source vector...
Definition: Instruction.h:604
bool isZeroEltSplat() const
Return true if all elements of this shuffle are the same value as the first element of exactly one so...
Definition: Instruction.h:732
static bool isInsertSubvectorMask(ArrayRef< int > Mask, int NumSrcElts, int &NumSubElts, int &Index)
Return true if this shuffle mask is an insert subvector mask.
Definition: Instruction.h:830
static void getShuffleMask(const Constant *Mask, SmallVectorImpl< int > &Result)
Convert the input shuffle mask operand to a vector of integers.
Definition: Instruction.h:569
static bool isZeroEltSplatMask(const Constant *Mask, int NumSrcElts)
Definition: Instruction.h:723
LLVM_ABI void setShuffleMask(ArrayRef< int > Mask)
static bool isReverseMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask swaps the order of elements from exactly one source vector.
Definition: Instruction.h:700
static bool isSingleSourceMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses elements from exactly one source vector.
Definition: Instruction.h:613
bool isOneUseSingleSourceMask(int VF) const
Return true if this shuffle mask is a one-use-single-source("clustered") mask.
Definition: Instruction.h:883
static bool isDeInterleaveMaskOfFactor(ArrayRef< int > Mask, unsigned Factor, unsigned &Index)
Check if the mask is a DE-interleave mask of the given factor Factor like: <Index,...
Definition: Instruction.h:933
int getMaskValue(unsigned Elt) const
Return the shuffle mask value of this instruction for the given element index.
Definition: Instruction.h:563
bool isInsertSubvectorMask(int &NumSubElts, int &Index) const
Return true if this shuffle mask is an insert subvector mask.
Definition: Instruction.h:842
bool isSelect() const
Return true if this shuffle chooses elements from its source vectors without lane crossings and all o...
Definition: Instruction.h:691
bool isTranspose() const
Return true if this shuffle transposes the elements of its inputs without changing the length of the ...
Definition: Instruction.h:781
static bool classof(const Value *From)
Definition: Instruction.h:538
Instructions that contain a single LLVM Instruction can inherit from this.
Definition: Instruction.h:378
void dumpOS(raw_ostream &OS) const override
Definition: Instruction.h:405
void verify() const final
Should crash if there is something wrong with the instruction.
Definition: Instruction.h:404
unsigned getUseOperandNo(const Use &Use) const final
\Returns the operand index of Use.
Definition: Instruction.h:399
unsigned getNumOfIRInstrs() const final
This is used by BasicBlock::iterator.
Definition: Instruction.h:402
LLVM_ABI void setVolatile(bool V)
Specify whether this is a volatile store or not.
static LLVM_ABI bool classof(const Value *From)
For isa/dyn_cast.
static StoreInst * create(Value *V, Value *Ptr, MaybeAlign Align, InsertPosition Pos, Context &Ctx)
Definition: Instruction.h:1241
static LLVM_ABI StoreInst * create(Value *V, Value *Ptr, MaybeAlign Align, InsertPosition Pos, bool IsVolatile, Context &Ctx)
LLVM_ABI Value * getPointerOperand() const
bool isVolatile() const
Return true if this is a store from a volatile memory location.
Definition: Instruction.h:1234
LLVM_ABI Value * getValueOperand() const
CaseIt findCaseValue(const ConstantInt *C)
Definition: Instruction.h:1914
iterator_range< ConstCaseIt > cases() const
Definition: Instruction.h:1907
static LLVM_ABI SwitchInst * create(Value *V, BasicBlock *Dest, unsigned NumCases, InsertPosition Pos, Context &Ctx, const Twine &Name="")
LLVM_ABI void addCase(ConstantInt *OnVal, BasicBlock *Dest)
LLVM_ABI BasicBlock * getSuccessor(unsigned Idx) const
CaseIt case_begin()
Returns a read/write iterator that points to the first case in the SwitchInst.
Definition: Instruction.h:1897
LLVM_ABI void setDefaultDest(BasicBlock *DefaultCase)
iterator_range< CaseIt > cases()
Iteration adapter for range-for loops.
Definition: Instruction.h:1904
llvm::SwitchInst::CaseIteratorImpl< CaseHandle > CaseIt
Definition: Instruction.h:1892
ConstCaseIt case_begin() const
Definition: Instruction.h:1898
bool defaultDestUnreachable() const
Definition: Instruction.h:1879
LLVM_ABI BasicBlock * getDefaultDest() const
ConstCaseIt case_end() const
Definition: Instruction.h:1902
llvm::SwitchInst::CaseIteratorImpl< ConstCaseHandle > ConstCaseIt
Definition: Instruction.h:1893
ConstCaseIt case_default() const
Definition: Instruction.h:1911
static bool classof(const Value *From)
Definition: Instruction.h:1944
LLVM_ABI Value * getCondition() const
LLVM_ABI void setSuccessor(unsigned Idx, BasicBlock *NewSucc)
unsigned getNumCases() const
Definition: Instruction.h:1883
unsigned getNumSuccessors() const
Definition: Instruction.h:1939
CaseIt case_end()
Returns a read/write iterator that points one past the last in the SwitchInst.
Definition: Instruction.h:1901
LLVM_ABI void setCondition(Value *V)
ConstCaseIt findCaseValue(const ConstantInt *C) const
Definition: Instruction.h:1919
LLVM_ABI ConstantInt * findCaseDest(BasicBlock *BB)
static constexpr const unsigned DefaultPseudoIndex
Definition: Instruction.h:1869
LLVM_ABI CaseIt removeCase(CaseIt It)
This method removes the specified case and its successor from the switch instruction.
Just like llvm::Type these are immutable, unique, never get freed and can only be created via static ...
Definition: Type.h:47
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: Type.h:283
An abstract class, parent of unary instructions.
Definition: Instruction.h:1092
static bool classof(const Instruction *I)
Definition: Instruction.h:1099
UnaryInstruction(ClassID ID, Opcode Opc, llvm::Instruction *LLVMI, Context &Ctx)
Definition: Instruction.h:1094
static bool classof(const Value *V)
Definition: Instruction.h:1102
static bool classof(const Value *From)
For isa/dyn_cast.
Definition: Instruction.h:1972
static LLVM_ABI Value * createWithCopiedFlags(Instruction::Opcode Op, Value *OpV, Value *CopyFrom, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static LLVM_ABI Value * create(Instruction::Opcode Op, Value *OpV, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static LLVM_ABI UnreachableInst * create(InsertPosition Pos, Context &Ctx)
unsigned getNumOfIRInstrs() const final
This is used by BasicBlock::iterator.
Definition: Instruction.h:1274
unsigned getUseOperandNo(const Use &Use) const final
\Returns the operand index of Use.
Definition: Instruction.h:1271
static LLVM_ABI bool classof(const Value *From)
Represents a Def-use/Use-def edge in SandboxIR.
Definition: Use.h:33
LLVM_ABI void set(Value *V)
Definition: Use.cpp:17
A sandboxir::User has operands.
Definition: User.h:59
virtual op_iterator op_begin()
Definition: User.h:103
unsigned getUseOperandNoDefault(const Use &Use) const
The default implementation works only for single-LLVMIR-instruction Users and only if they match exac...
Definition: User.h:76
virtual void setOperand(unsigned OperandIdx, Value *Operand)
Definition: User.cpp:91
op_range operands()
Definition: User.h:119
Use getOperandUseDefault(unsigned OpIdx, bool Verify) const
\Returns the Use edge that corresponds to OpIdx.
Definition: User.cpp:58
void swapOperandsInternal(unsigned OpIdxA, unsigned OpIdxB)
Definition: User.h:83
virtual unsigned getNumOperands() const
Definition: User.h:129
Use getOperandUse(unsigned OpIdx) const
\Returns the operand edge for OpIdx.
Definition: User.h:126
virtual op_iterator op_end()
Definition: User.h:107
LLVM_ABI Value * getPointerOperand()
static LLVM_ABI VAArgInst * create(Value *List, Type *Ty, InsertPosition Pos, Context &Ctx, const Twine &Name="")
const Value * getPointerOperand() const
Definition: Instruction.h:1173
static bool classof(const Value *From)
Definition: Instruction.h:1179
static unsigned getPointerOperandIndex()
Definition: Instruction.h:1176
A SandboxIR Value has users. This is the base class.
Definition: Value.h:66
llvm::Value * Val
The LLVM Value that corresponds to this SandboxIR Value.
Definition: Value.h:106
void dumpCommonSuffix(raw_ostream &OS) const
Definition: Value.cpp:107
Context & Ctx
All values point to the context.
Definition: Value.h:179
ClassID SubclassID
For isa/dyn_cast.
Definition: Value.h:97
LLVM_ABI Type * getType() const
Definition: Value.cpp:46
void dumpCommonPrefix(raw_ostream &OS) const
Definition: Value.cpp:100
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:81
@ System
Synchronized with respect to all concurrently executing threads.
Definition: LLVMContext.h:58
static bool isOrdered(Instruction *I)
static SmallVector< Value *, 4 > getOperand(ArrayRef< Value * > Bndl, unsigned OpIdx)
Definition: BottomUpVec.cpp:43
@ Offset
Definition: DWP.cpp:477
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
mapped_iterator< ItTy, FuncTy > map_iterator(ItTy I, FuncTy F)
Definition: STLExtras.h:381
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ Other
Any other memory.
DWARFExpression::Operation Op
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1777
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1916
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
The const version of succ_op_iterator.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117