LLVM 24.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#define DEF_DISABLE_AUTO_UNDEF // ValuesDefFilesList.def includes multiple .def
50#include "llvm/SandboxIR/ValuesDefFilesList.def"
51#undef OP
52#undef OPCODES
53#undef DEF_INSTR
54 };
55
56protected:
58 sandboxir::Context &SBCtx)
59 : User(ID, I, SBCtx), Opc(Opc) {}
60
62
63 /// A SandboxIR Instruction may map to multiple LLVM IR Instruction. This
64 /// returns its topmost LLVM IR instruction.
66 friend class VAArgInst; // For getTopmostLLVMInstruction().
67 friend class FreezeInst; // For getTopmostLLVMInstruction().
68 friend class FenceInst; // For getTopmostLLVMInstruction().
69 friend class SelectInst; // For getTopmostLLVMInstruction().
70 friend class ExtractElementInst; // For getTopmostLLVMInstruction().
71 friend class InsertElementInst; // For getTopmostLLVMInstruction().
72 friend class ShuffleVectorInst; // For getTopmostLLVMInstruction().
73 friend class ExtractValueInst; // For getTopmostLLVMInstruction().
74 friend class InsertValueInst; // For getTopmostLLVMInstruction().
75 friend class LoadInst; // For getTopmostLLVMInstruction().
76 friend class StoreInst; // For getTopmostLLVMInstruction().
77 friend class ReturnInst; // For getTopmostLLVMInstruction().
78 friend class CallInst; // For getTopmostLLVMInstruction().
79 friend class InvokeInst; // For getTopmostLLVMInstruction().
80 friend class CallBrInst; // For getTopmostLLVMInstruction().
81 friend class LandingPadInst; // For getTopmostLLVMInstruction().
82 friend class CatchPadInst; // For getTopmostLLVMInstruction().
83 friend class CleanupPadInst; // For getTopmostLLVMInstruction().
84 friend class CatchReturnInst; // For getTopmostLLVMInstruction().
85 friend class CleanupReturnInst; // For getTopmostLLVMInstruction().
86 friend class GetElementPtrInst; // For getTopmostLLVMInstruction().
87 friend class ResumeInst; // For getTopmostLLVMInstruction().
88 friend class CatchSwitchInst; // For getTopmostLLVMInstruction().
89 friend class SwitchInst; // For getTopmostLLVMInstruction().
90 friend class UnaryOperator; // For getTopmostLLVMInstruction().
91 friend class BinaryOperator; // For getTopmostLLVMInstruction().
92 friend class AtomicRMWInst; // For getTopmostLLVMInstruction().
93 friend class AtomicCmpXchgInst; // For getTopmostLLVMInstruction().
94 friend class AllocaInst; // For getTopmostLLVMInstruction().
95 friend class CastInst; // For getTopmostLLVMInstruction().
96 friend class PHINode; // For getTopmostLLVMInstruction().
97 friend class UnreachableInst; // For getTopmostLLVMInstruction().
98 friend class CmpInst; // For getTopmostLLVMInstruction().
99
100 /// \Returns the LLVM IR Instructions that this SandboxIR maps to in program
101 /// order.
103 friend class EraseFromParent; // For getLLVMInstrs().
104
105 /// Helper function for create(). It sets the builder's insert position
106 /// according to \p Pos.
108
109public:
110 static const char *getOpcodeName(Opcode Opc) {
111 switch (Opc) {
112#define OP(OPC) \
113 case Opcode::OPC: \
114 return #OPC;
115#define OPCODES(...) __VA_ARGS__
116#define DEF_INSTR(ID, OPC, CLASS) OPC
117#define DEF_DISABLE_AUTO_UNDEF // ValuesDefFilesList.def includes multiple .def
118#include "llvm/SandboxIR/ValuesDefFilesList.def"
119#undef OPCODES
120#undef DEF_INSTR
121 }
122 llvm_unreachable("Unknown Opcode");
123 }
124
125 /// This is used by BasicBlock::iterator.
126 virtual unsigned getNumOfIRInstrs() const = 0;
127 /// \Returns a BasicBlock::iterator for this Instruction.
128 LLVM_ABI BBIterator getIterator() const;
129 /// \Returns the next sandboxir::Instruction in the block, or nullptr if at
130 /// the end of the block.
132 /// \Returns the previous sandboxir::Instruction in the block, or nullptr if
133 /// at the beginning of the block.
135 /// \Returns this Instruction's opcode. Note that SandboxIR has its own opcode
136 /// state to allow for new SandboxIR-specific instructions.
137 Opcode getOpcode() const { return Opc; }
138
139 const char *getOpcodeName() const { return getOpcodeName(Opc); }
140
141 const DataLayout &getDataLayout() const {
142 return cast<llvm::Instruction>(Val)->getModule()->getDataLayout();
143 }
144 // Note that these functions below are calling into llvm::Instruction.
145 // A sandbox IR instruction could introduce a new opcode that could change the
146 // behavior of one of these functions. It is better that these functions are
147 // only added as needed and new sandbox IR instructions must explicitly check
148 // if any of these functions could have a different behavior.
149
150 bool isTerminator() const {
151 return cast<llvm::Instruction>(Val)->isTerminator();
152 }
153 bool isUnaryOp() const { return cast<llvm::Instruction>(Val)->isUnaryOp(); }
154 bool isBinaryOp() const { return cast<llvm::Instruction>(Val)->isBinaryOp(); }
155 bool isIntDivRem() const {
156 return cast<llvm::Instruction>(Val)->isIntDivRem();
157 }
158 bool isShift() const { return cast<llvm::Instruction>(Val)->isShift(); }
159 bool isCast() const { return cast<llvm::Instruction>(Val)->isCast(); }
160 bool isFuncletPad() const {
161 return cast<llvm::Instruction>(Val)->isFuncletPad();
162 }
163 bool isSpecialTerminator() const {
164 return cast<llvm::Instruction>(Val)->isSpecialTerminator();
165 }
167 return cast<llvm::Instruction>(Val)->isOnlyUserOfAnyOperand();
168 }
169 bool isLogicalShift() const {
170 return cast<llvm::Instruction>(Val)->isLogicalShift();
171 }
172
173 //===--------------------------------------------------------------------===//
174 // Metadata manipulation.
175 //===--------------------------------------------------------------------===//
176
177 /// Return true if the instruction has any metadata attached to it.
178 bool hasMetadata() const {
179 return cast<llvm::Instruction>(Val)->hasMetadata();
180 }
181
182 /// Return true if this instruction has metadata attached to it other than a
183 /// debug location.
185 return cast<llvm::Instruction>(Val)->hasMetadataOtherThanDebugLoc();
186 }
187
188 /// Return true if this instruction has the given type of metadata attached.
189 bool hasMetadata(unsigned KindID) const {
190 return cast<llvm::Instruction>(Val)->hasMetadata(KindID);
191 }
192
193 // TODO: Implement getMetadata and getAllMetadata after sandboxir::MDNode is
194 // available.
195
196 // TODO: More missing functions
197
198 /// Detach this from its parent BasicBlock without deleting it.
200 /// Detach this Value from its parent and delete it.
202 /// Insert this detached instruction before \p BeforeI.
203 LLVM_ABI void insertBefore(Instruction *BeforeI);
204 /// Insert this detached instruction after \p AfterI.
205 LLVM_ABI void insertAfter(Instruction *AfterI);
206 /// Insert this detached instruction into \p BB at \p WhereIt.
207 LLVM_ABI void insertInto(BasicBlock *BB, const BBIterator &WhereIt);
208 /// Move this instruction to \p WhereIt.
209 LLVM_ABI void moveBefore(BasicBlock &BB, const BBIterator &WhereIt);
210 /// Move this instruction before \p Before.
211 void moveBefore(Instruction *Before) {
212 moveBefore(*Before->getParent(), Before->getIterator());
213 }
214 /// Move this instruction after \p After.
215 void moveAfter(Instruction *After) {
216 moveBefore(*After->getParent(), std::next(After->getIterator()));
217 }
218 // TODO: This currently relies on LLVM IR Instruction::comesBefore which is
219 // can be linear-time.
220 /// Given an instruction Other in the same basic block as this instruction,
221 /// return true if this instruction comes before Other.
222 bool comesBefore(const Instruction *Other) const {
223 return cast<llvm::Instruction>(Val)->comesBefore(
225 }
226 /// \Returns the BasicBlock containing this Instruction, or null if it is
227 /// detached.
229 /// For isa/dyn_cast.
230 LLVM_ABI static bool classof(const sandboxir::Value *From);
231
232 /// Determine whether the no signed wrap flag is set.
233 bool hasNoUnsignedWrap() const {
234 return cast<llvm::Instruction>(Val)->hasNoUnsignedWrap();
235 }
236 /// Set or clear the nuw 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 setHasNoUnsignedWrap(bool B = true);
239 /// Determine whether the no signed wrap flag is set.
240 bool hasNoSignedWrap() const {
241 return cast<llvm::Instruction>(Val)->hasNoSignedWrap();
242 }
243 /// Set or clear the nsw flag on this instruction, which must be an operator
244 /// which supports this flag. See LangRef.html for the meaning of this flag.
245 LLVM_ABI void setHasNoSignedWrap(bool B = true);
246 /// Determine whether all fast-math-flags are set.
247 bool isFast() const { return cast<llvm::Instruction>(Val)->isFast(); }
248 /// Set or clear all fast-math-flags on this instruction, which must be an
249 /// operator which supports this flag. See LangRef.html for the meaning of
250 /// this flag.
251 LLVM_ABI void setFast(bool B);
252 /// Determine whether the allow-reassociation flag is set.
253 bool hasAllowReassoc() const {
254 return cast<llvm::Instruction>(Val)->hasAllowReassoc();
255 }
256 /// Set or clear the reassociation flag on this instruction, which must be
257 /// an operator which supports this flag. See LangRef.html for the meaning of
258 /// this flag.
259 LLVM_ABI void setHasAllowReassoc(bool B);
260 /// Determine whether the exact flag is set.
261 bool isExact() const { return cast<llvm::Instruction>(Val)->isExact(); }
262 /// Set or clear the exact flag on this instruction, which must be an operator
263 /// which supports this flag. See LangRef.html for the meaning of this flag.
264 LLVM_ABI void setIsExact(bool B = true);
265 /// Determine whether the no-NaNs flag is set.
266 bool hasNoNaNs() const { return cast<llvm::Instruction>(Val)->hasNoNaNs(); }
267 /// Set or clear the no-nans flag on this instruction, which must be an
268 /// operator which supports this flag. See LangRef.html for the meaning of
269 /// this flag.
270 LLVM_ABI void setHasNoNaNs(bool B);
271 /// Determine whether the no-infs flag is set.
272 bool hasNoInfs() const { return cast<llvm::Instruction>(Val)->hasNoInfs(); }
273 /// Set or clear the no-infs flag on this instruction, which must be an
274 /// operator which supports this flag. See LangRef.html for the meaning of
275 /// this flag.
276 LLVM_ABI void setHasNoInfs(bool B);
277 /// Determine whether the no-signed-zeros flag is set.
278 bool hasNoSignedZeros() const {
279 return cast<llvm::Instruction>(Val)->hasNoSignedZeros();
280 }
281 /// Set or clear the no-signed-zeros flag on this instruction, which must be
282 /// an operator which supports this flag. See LangRef.html for the meaning of
283 /// this flag.
284 LLVM_ABI void setHasNoSignedZeros(bool B);
285 /// Determine whether the allow-reciprocal flag is set.
286 bool hasAllowReciprocal() const {
287 return cast<llvm::Instruction>(Val)->hasAllowReciprocal();
288 }
289 /// Set or clear the allow-reciprocal flag on this instruction, which must be
290 /// an operator which supports this flag. See LangRef.html for the meaning of
291 /// this flag.
293 /// Determine whether the allow-contract flag is set.
294 bool hasAllowContract() const {
295 return cast<llvm::Instruction>(Val)->hasAllowContract();
296 }
297 /// Set or clear the allow-contract flag on this instruction, which must be
298 /// an operator which supports this flag. See LangRef.html for the meaning of
299 /// this flag.
300 LLVM_ABI void setHasAllowContract(bool B);
301 /// Determine whether the approximate-math-functions flag is set.
302 bool hasApproxFunc() const {
303 return cast<llvm::Instruction>(Val)->hasApproxFunc();
304 }
305 /// Set or clear the approximate-math-functions flag on this instruction,
306 /// which must be an operator which supports this flag. See LangRef.html for
307 /// the meaning of this flag.
308 LLVM_ABI void setHasApproxFunc(bool B);
309 /// Convenience function for getting all the fast-math flags, which must be an
310 /// operator which supports these flags. See LangRef.html for the meaning of
311 /// these flags.
313 return cast<llvm::Instruction>(Val)->getFastMathFlags();
314 }
315 /// Convenience function for setting multiple fast-math flags on this
316 /// instruction, which must be an operator which supports these flags. See
317 /// LangRef.html for the meaning of these flags.
319 /// Convenience function for transferring all fast-math flag values to this
320 /// instruction, which must be an operator which supports these flags. See
321 /// LangRef.html for the meaning of these flags.
323
324 bool isAssociative() const {
325 return cast<llvm::Instruction>(Val)->isAssociative();
326 }
327
328 bool isCommutative() const {
329 return cast<llvm::Instruction>(Val)->isCommutative();
330 }
331
332 bool isIdempotent() const {
333 return cast<llvm::Instruction>(Val)->isIdempotent();
334 }
335
336 bool isNilpotent() const {
337 return cast<llvm::Instruction>(Val)->isNilpotent();
338 }
339
340 bool mayWriteToMemory() const {
341 return cast<llvm::Instruction>(Val)->mayWriteToMemory();
342 }
343
344 bool mayReadFromMemory() const {
345 return cast<llvm::Instruction>(Val)->mayReadFromMemory();
346 }
347 bool mayReadOrWriteMemory() const {
348 return cast<llvm::Instruction>(Val)->mayReadOrWriteMemory();
349 }
350
351 bool isAtomic() const { return cast<llvm::Instruction>(Val)->isAtomic(); }
352
353 bool hasAtomicLoad() const {
354 return cast<llvm::Instruction>(Val)->hasAtomicLoad();
355 }
356
357 bool hasAtomicStore() const {
358 return cast<llvm::Instruction>(Val)->hasAtomicStore();
359 }
360
361 bool isVolatile() const { return cast<llvm::Instruction>(Val)->isVolatile(); }
362
363 LLVM_ABI Type *getAccessType() const;
364
365 bool mayThrow(bool IncludePhaseOneUnwind = false) const {
366 return cast<llvm::Instruction>(Val)->mayThrow(IncludePhaseOneUnwind);
367 }
368
369 bool isFenceLike() const {
370 return cast<llvm::Instruction>(Val)->isFenceLike();
371 }
372
373 bool mayHaveSideEffects() const {
374 return cast<llvm::Instruction>(Val)->mayHaveSideEffects();
375 }
376
377 // TODO: Missing functions.
378
379#ifndef NDEBUG
380 void dumpOS(raw_ostream &OS) const override;
381#endif
382};
383
384/// Instructions that contain a single LLVM Instruction can inherit from this.
385template <typename LLVMT> class SingleLLVMInstructionImpl : public Instruction {
386 SingleLLVMInstructionImpl(ClassID ID, Opcode Opc, llvm::Instruction *I,
387 sandboxir::Context &SBCtx)
388 : Instruction(ID, Opc, I, SBCtx) {}
389
390 // All instructions are friends with this so they can call the constructor.
391#define DEF_INSTR(ID, OPC, CLASS) friend class CLASS;
392#include "llvm/SandboxIR/Values.def"
393 friend class UnaryInstruction;
394 friend class CallBase;
395 friend class FuncletPadInst;
396 friend class CmpInst;
397
398 Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
399 return getOperandUseDefault(OpIdx, Verify);
400 }
403 }
404
405public:
406 unsigned getUseOperandNo(const Use &Use) const final {
408 }
409 unsigned getNumOfIRInstrs() const final { return 1u; }
410#ifndef NDEBUG
411 void verify() const final { assert(isa<LLVMT>(Val) && "Expected LLVMT!"); }
412 void dumpOS(raw_ostream &OS) const override {
415 }
416#endif
417};
418
419class FenceInst : public SingleLLVMInstructionImpl<llvm::FenceInst> {
420 FenceInst(llvm::FenceInst *FI, Context &Ctx)
421 : SingleLLVMInstructionImpl(ClassID::Fence, Opcode::Fence, FI, Ctx) {}
422 friend Context; // For constructor;
423
424public:
425 LLVM_ABI static FenceInst *create(AtomicOrdering Ordering, InsertPosition Pos,
426 Context &Ctx,
428 /// Returns the ordering constraint of this fence instruction.
430 return cast<llvm::FenceInst>(Val)->getOrdering();
431 }
432 /// Sets the ordering constraint of this fence instruction. May only be
433 /// Acquire, Release, AcquireRelease, or SequentiallyConsistent.
434 LLVM_ABI void setOrdering(AtomicOrdering Ordering);
435 /// Returns the synchronization scope ID of this fence instruction.
437 return cast<llvm::FenceInst>(Val)->getSyncScopeID();
438 }
439 /// Sets the synchronization scope ID of this fence instruction.
441 static bool classof(const Value *From) {
442 return From->getSubclassID() == ClassID::Fence;
443 }
444};
445
446class SelectInst : public SingleLLVMInstructionImpl<llvm::SelectInst> {
447 /// Use Context::createSelectInst(). Don't call the
448 /// constructor directly.
449 SelectInst(llvm::SelectInst *CI, Context &Ctx)
450 : SingleLLVMInstructionImpl(ClassID::Select, Opcode::Select, CI, Ctx) {}
451 friend Context; // for SelectInst()
452
453public:
455 InsertPosition Pos, Context &Ctx,
456 const Twine &Name = "");
457
458 const Value *getCondition() const { return getOperand(0); }
459 const Value *getTrueValue() const { return getOperand(1); }
460 const Value *getFalseValue() const { return getOperand(2); }
461 Value *getCondition() { return getOperand(0); }
462 Value *getTrueValue() { return getOperand(1); }
464
465 void setCondition(Value *New) { setOperand(0, New); }
466 void setTrueValue(Value *New) { setOperand(1, New); }
467 void setFalseValue(Value *New) { setOperand(2, New); }
468 LLVM_ABI void swapValues();
469
470 /// Return a string if the specified operands are invalid for a select
471 /// operation, otherwise return null.
472 static const char *areInvalidOperands(Value *Cond, Value *True,
473 Value *False) {
475 False->Val);
476 }
477
478 /// For isa/dyn_cast.
479 LLVM_ABI static bool classof(const Value *From);
480};
481
482class InsertElementInst final
483 : public SingleLLVMInstructionImpl<llvm::InsertElementInst> {
484 /// Use Context::createInsertElementInst() instead.
486 : SingleLLVMInstructionImpl(ClassID::InsertElement, Opcode::InsertElement,
487 I, Ctx) {}
488 friend class Context; // For accessing the constructor in create*()
489
490public:
491 LLVM_ABI static Value *create(Value *Vec, Value *NewElt, Value *Idx,
493 const Twine &Name = "");
494 static bool classof(const Value *From) {
495 return From->getSubclassID() == ClassID::InsertElement;
496 }
497 static bool isValidOperands(const Value *Vec, const Value *NewElt,
498 const Value *Idx) {
500 Idx->Val);
501 }
502};
503
504class ExtractElementInst final
505 : public SingleLLVMInstructionImpl<llvm::ExtractElementInst> {
506 /// Use Context::createExtractElementInst() instead.
508 : SingleLLVMInstructionImpl(ClassID::ExtractElement,
509 Opcode::ExtractElement, I, Ctx) {}
510 friend class Context; // For accessing the constructor in
511 // create*()
512
513public:
514 LLVM_ABI static Value *create(Value *Vec, Value *Idx, InsertPosition Pos,
515 Context &Ctx, const Twine &Name = "");
516 static bool classof(const Value *From) {
517 return From->getSubclassID() == ClassID::ExtractElement;
518 }
519
520 static bool isValidOperands(const Value *Vec, const Value *Idx) {
521 return llvm::ExtractElementInst::isValidOperands(Vec->Val, Idx->Val);
522 }
525 const Value *getVectorOperand() const { return getOperand(0); }
526 const Value *getIndexOperand() const { return getOperand(1); }
528};
529
530class ShuffleVectorInst final
531 : public SingleLLVMInstructionImpl<llvm::ShuffleVectorInst> {
532 /// Use Context::createShuffleVectorInst() instead.
534 : SingleLLVMInstructionImpl(ClassID::ShuffleVector, Opcode::ShuffleVector,
535 I, Ctx) {}
536 friend class Context; // For accessing the constructor in create*()
537
538public:
539 LLVM_ABI static Value *create(Value *V1, Value *V2, Value *Mask,
541 const Twine &Name = "");
542 LLVM_ABI static Value *create(Value *V1, Value *V2, ArrayRef<int> Mask,
544 const Twine &Name = "");
545 static bool classof(const Value *From) {
546 return From->getSubclassID() == ClassID::ShuffleVector;
547 }
548
549 /// Swap the operands and adjust the mask to preserve the semantics of the
550 /// instruction.
551 LLVM_ABI void commute();
552
553 /// Return true if a shufflevector instruction can be formed with the
554 /// specified operands.
555 static bool isValidOperands(const Value *V1, const Value *V2,
556 const Value *Mask) {
558 Mask->Val);
559 }
560 static bool isValidOperands(const Value *V1, const Value *V2,
561 ArrayRef<int> Mask) {
562 return llvm::ShuffleVectorInst::isValidOperands(V1->Val, V2->Val, Mask);
563 }
564
565 /// Overload to return most specific vector type.
566 LLVM_ABI VectorType *getType() const;
567
568 /// Return the shuffle mask value of this instruction for the given element
569 /// index. Return PoisonMaskElem if the element is undef.
570 int getMaskValue(unsigned Elt) const {
571 return cast<llvm::ShuffleVectorInst>(Val)->getMaskValue(Elt);
572 }
573
574 /// Convert the input shuffle mask operand to a vector of integers. Undefined
575 /// elements of the mask are returned as PoisonMaskElem.
576 static void getShuffleMask(const Constant *Mask,
577 SmallVectorImpl<int> &Result) {
579 Result);
580 }
581
582 /// Return the mask for this instruction as a vector of integers. Undefined
583 /// elements of the mask are returned as PoisonMaskElem.
585 cast<llvm::ShuffleVectorInst>(Val)->getShuffleMask(Result);
586 }
587
588 /// Return the mask for this instruction, for use in bitcode.
590
592 Type *ResultTy);
593
595
597 return cast<llvm::ShuffleVectorInst>(Val)->getShuffleMask();
598 }
599
600 /// Return true if this shuffle returns a vector with a different number of
601 /// elements than its source vectors.
602 /// Examples: shufflevector <4 x n> A, <4 x n> B, <1,2,3>
603 /// shufflevector <4 x n> A, <4 x n> B, <1,2,3,4,5>
604 bool changesLength() const {
605 return cast<llvm::ShuffleVectorInst>(Val)->changesLength();
606 }
607
608 /// Return true if this shuffle returns a vector with a greater number of
609 /// elements than its source vectors.
610 /// Example: shufflevector <2 x n> A, <2 x n> B, <1,2,3>
611 bool increasesLength() const {
612 return cast<llvm::ShuffleVectorInst>(Val)->increasesLength();
613 }
614
615 /// Return true if this shuffle mask chooses elements from exactly one source
616 /// vector.
617 /// Example: <7,5,undef,7>
618 /// This assumes that vector operands (of length \p NumSrcElts) are the same
619 /// length as the mask.
620 static bool isSingleSourceMask(ArrayRef<int> Mask, int NumSrcElts) {
621 return llvm::ShuffleVectorInst::isSingleSourceMask(Mask, NumSrcElts);
622 }
623 static bool isSingleSourceMask(const Constant *Mask, int NumSrcElts) {
625 cast<llvm::Constant>(Mask->Val), NumSrcElts);
626 }
627
628 /// Return true if this shuffle chooses elements from exactly one source
629 /// vector without changing the length of that vector.
630 /// Example: shufflevector <4 x n> A, <4 x n> B, <3,0,undef,3>
631 bool isSingleSource() const {
632 return cast<llvm::ShuffleVectorInst>(Val)->isSingleSource();
633 }
634
635 /// Return true if this shuffle mask chooses elements from exactly one source
636 /// vector without lane crossings. A shuffle using this mask is not
637 /// necessarily a no-op because it may change the number of elements from its
638 /// input vectors or it may provide demanded bits knowledge via undef lanes.
639 /// Example: <undef,undef,2,3>
640 static bool isIdentityMask(ArrayRef<int> Mask, int NumSrcElts) {
641 return llvm::ShuffleVectorInst::isIdentityMask(Mask, NumSrcElts);
642 }
643 static bool isIdentityMask(const Constant *Mask, int NumSrcElts) {
645 cast<llvm::Constant>(Mask->Val), NumSrcElts);
646 }
647
648 /// Return true if this shuffle chooses elements from exactly one source
649 /// vector without lane crossings and does not change the number of elements
650 /// from its input vectors.
651 /// Example: shufflevector <4 x n> A, <4 x n> B, <4,undef,6,undef>
652 bool isIdentity() const {
653 return cast<llvm::ShuffleVectorInst>(Val)->isIdentity();
654 }
655
656 /// Return true if this shuffle lengthens exactly one source vector with
657 /// undefs in the high elements.
659 return cast<llvm::ShuffleVectorInst>(Val)->isIdentityWithPadding();
660 }
661
662 /// Return true if this shuffle extracts the first N elements of exactly one
663 /// source vector.
665 return cast<llvm::ShuffleVectorInst>(Val)->isIdentityWithExtract();
666 }
667
668 /// Return true if this shuffle concatenates its 2 source vectors. This
669 /// returns false if either input is undefined. In that case, the shuffle is
670 /// is better classified as an identity with padding operation.
671 bool isConcat() const {
672 return cast<llvm::ShuffleVectorInst>(Val)->isConcat();
673 }
674
675 /// Return true if this shuffle mask chooses elements from its source vectors
676 /// without lane crossings. A shuffle using this mask would be
677 /// equivalent to a vector select with a constant condition operand.
678 /// Example: <4,1,6,undef>
679 /// This returns false if the mask does not choose from both input vectors.
680 /// In that case, the shuffle is better classified as an identity shuffle.
681 /// This assumes that vector operands are the same length as the mask
682 /// (a length-changing shuffle can never be equivalent to a vector select).
683 static bool isSelectMask(ArrayRef<int> Mask, int NumSrcElts) {
684 return llvm::ShuffleVectorInst::isSelectMask(Mask, NumSrcElts);
685 }
686 static bool isSelectMask(const Constant *Mask, int NumSrcElts) {
688 cast<llvm::Constant>(Mask->Val), NumSrcElts);
689 }
690
691 /// Return true if this shuffle chooses elements from its source vectors
692 /// without lane crossings and all operands have the same number of elements.
693 /// In other words, this shuffle is equivalent to a vector select with a
694 /// constant condition operand.
695 /// Example: shufflevector <4 x n> A, <4 x n> B, <undef,1,6,3>
696 /// This returns false if the mask does not choose from both input vectors.
697 /// In that case, the shuffle is better classified as an identity shuffle.
698 bool isSelect() const {
699 return cast<llvm::ShuffleVectorInst>(Val)->isSelect();
700 }
701
702 /// Return true if this shuffle mask swaps the order of elements from exactly
703 /// one source vector.
704 /// Example: <7,6,undef,4>
705 /// This assumes that vector operands (of length \p NumSrcElts) are the same
706 /// length as the mask.
707 static bool isReverseMask(ArrayRef<int> Mask, int NumSrcElts) {
708 return llvm::ShuffleVectorInst::isReverseMask(Mask, NumSrcElts);
709 }
710 static bool isReverseMask(const Constant *Mask, int NumSrcElts) {
712 cast<llvm::Constant>(Mask->Val), NumSrcElts);
713 }
714
715 /// Return true if this shuffle swaps the order of elements from exactly
716 /// one source vector.
717 /// Example: shufflevector <4 x n> A, <4 x n> B, <3,undef,1,undef>
718 bool isReverse() const {
719 return cast<llvm::ShuffleVectorInst>(Val)->isReverse();
720 }
721
722 /// Return true if this shuffle mask chooses all elements with the same value
723 /// as the first element of exactly one source vector.
724 /// Example: <4,undef,undef,4>
725 /// This assumes that vector operands (of length \p NumSrcElts) are the same
726 /// length as the mask.
727 static bool isZeroEltSplatMask(ArrayRef<int> Mask, int NumSrcElts) {
728 return llvm::ShuffleVectorInst::isZeroEltSplatMask(Mask, NumSrcElts);
729 }
730 static bool isZeroEltSplatMask(const Constant *Mask, int NumSrcElts) {
732 cast<llvm::Constant>(Mask->Val), NumSrcElts);
733 }
734
735 /// Return true if all elements of this shuffle are the same value as the
736 /// first element of exactly one source vector without changing the length
737 /// of that vector.
738 /// Example: shufflevector <4 x n> A, <4 x n> B, <undef,0,undef,0>
739 bool isZeroEltSplat() const {
740 return cast<llvm::ShuffleVectorInst>(Val)->isZeroEltSplat();
741 }
742
743 /// Return true if this shuffle mask is a transpose mask.
744 /// Transpose vector masks transpose a 2xn matrix. They read corresponding
745 /// even- or odd-numbered vector elements from two n-dimensional source
746 /// vectors and write each result into consecutive elements of an
747 /// n-dimensional destination vector. Two shuffles are necessary to complete
748 /// the transpose, one for the even elements and another for the odd elements.
749 /// This description closely follows how the TRN1 and TRN2 AArch64
750 /// instructions operate.
751 ///
752 /// For example, a simple 2x2 matrix can be transposed with:
753 ///
754 /// ; Original matrix
755 /// m0 = < a, b >
756 /// m1 = < c, d >
757 ///
758 /// ; Transposed matrix
759 /// t0 = < a, c > = shufflevector m0, m1, < 0, 2 >
760 /// t1 = < b, d > = shufflevector m0, m1, < 1, 3 >
761 ///
762 /// For matrices having greater than n columns, the resulting nx2 transposed
763 /// matrix is stored in two result vectors such that one vector contains
764 /// interleaved elements from all the even-numbered rows and the other vector
765 /// contains interleaved elements from all the odd-numbered rows. For example,
766 /// a 2x4 matrix can be transposed with:
767 ///
768 /// ; Original matrix
769 /// m0 = < a, b, c, d >
770 /// m1 = < e, f, g, h >
771 ///
772 /// ; Transposed matrix
773 /// t0 = < a, e, c, g > = shufflevector m0, m1 < 0, 4, 2, 6 >
774 /// t1 = < b, f, d, h > = shufflevector m0, m1 < 1, 5, 3, 7 >
775 static bool isTransposeMask(ArrayRef<int> Mask, int NumSrcElts) {
776 return llvm::ShuffleVectorInst::isTransposeMask(Mask, NumSrcElts);
777 }
778 static bool isTransposeMask(const Constant *Mask, int NumSrcElts) {
780 cast<llvm::Constant>(Mask->Val), NumSrcElts);
781 }
782
783 /// Return true if this shuffle transposes the elements of its inputs without
784 /// changing the length of the vectors. This operation may also be known as a
785 /// merge or interleave. See the description for isTransposeMask() for the
786 /// exact specification.
787 /// Example: shufflevector <4 x n> A, <4 x n> B, <0,4,2,6>
788 bool isTranspose() const {
789 return cast<llvm::ShuffleVectorInst>(Val)->isTranspose();
790 }
791
792 /// Return true if this shuffle mask is a splice mask, concatenating the two
793 /// inputs together and then extracts an original width vector starting from
794 /// the splice index.
795 /// Example: shufflevector <4 x n> A, <4 x n> B, <1,2,3,4>
796 /// This assumes that vector operands (of length \p NumSrcElts) are the same
797 /// length as the mask.
798 static bool isSpliceMask(ArrayRef<int> Mask, int NumSrcElts, int &Index) {
799 return llvm::ShuffleVectorInst::isSpliceMask(Mask, NumSrcElts, Index);
800 }
801 static bool isSpliceMask(const Constant *Mask, int NumSrcElts, int &Index) {
803 cast<llvm::Constant>(Mask->Val), NumSrcElts, Index);
804 }
805
806 /// Return true if this shuffle splices two inputs without changing the length
807 /// of the vectors. This operation concatenates the two inputs together and
808 /// then extracts an original width vector starting from the splice index.
809 /// Example: shufflevector <4 x n> A, <4 x n> B, <1,2,3,4>
810 bool isSplice(int &Index) const {
811 return cast<llvm::ShuffleVectorInst>(Val)->isSplice(Index);
812 }
813
814 /// Return true if this shuffle mask is an extract subvector mask.
815 /// A valid extract subvector mask returns a smaller vector from a single
816 /// source operand. The base extraction index is returned as well.
817 static bool isExtractSubvectorMask(ArrayRef<int> Mask, int NumSrcElts,
818 int &Index) {
820 Index);
821 }
822 static bool isExtractSubvectorMask(const Constant *Mask, int NumSrcElts,
823 int &Index) {
825 cast<llvm::Constant>(Mask->Val), NumSrcElts, Index);
826 }
827
828 /// Return true if this shuffle mask is an extract subvector mask.
829 bool isExtractSubvectorMask(int &Index) const {
830 return cast<llvm::ShuffleVectorInst>(Val)->isExtractSubvectorMask(Index);
831 }
832
833 /// Return true if this shuffle mask is an insert subvector mask.
834 /// A valid insert subvector mask inserts the lowest elements of a second
835 /// source operand into an in-place first source operand.
836 /// Both the sub vector width and the insertion index is returned.
837 static bool isInsertSubvectorMask(ArrayRef<int> Mask, int NumSrcElts,
838 int &NumSubElts, int &Index) {
840 NumSubElts, Index);
841 }
842 static bool isInsertSubvectorMask(const Constant *Mask, int NumSrcElts,
843 int &NumSubElts, int &Index) {
845 cast<llvm::Constant>(Mask->Val), NumSrcElts, NumSubElts, Index);
846 }
847
848 /// Return true if this shuffle mask is an insert subvector mask.
849 bool isInsertSubvectorMask(int &NumSubElts, int &Index) const {
850 return cast<llvm::ShuffleVectorInst>(Val)->isInsertSubvectorMask(NumSubElts,
851 Index);
852 }
853
854 /// Return true if this shuffle mask replicates each of the \p VF elements
855 /// in a vector \p ReplicationFactor times.
856 /// For example, the mask for \p ReplicationFactor=3 and \p VF=4 is:
857 /// <0,0,0,1,1,1,2,2,2,3,3,3>
858 static bool isReplicationMask(ArrayRef<int> Mask, int &ReplicationFactor,
859 int &VF) {
860 return llvm::ShuffleVectorInst::isReplicationMask(Mask, ReplicationFactor,
861 VF);
862 }
863 static bool isReplicationMask(const Constant *Mask, int &ReplicationFactor,
864 int &VF) {
866 cast<llvm::Constant>(Mask->Val), ReplicationFactor, VF);
867 }
868
869 /// Return true if this shuffle mask is a replication mask.
870 bool isReplicationMask(int &ReplicationFactor, int &VF) const {
871 return cast<llvm::ShuffleVectorInst>(Val)->isReplicationMask(
872 ReplicationFactor, VF);
873 }
874
875 /// Return true if this shuffle mask represents "clustered" mask of size VF,
876 /// i.e. each index between [0..VF) is used exactly once in each submask of
877 /// size VF.
878 /// For example, the mask for \p VF=4 is:
879 /// 0, 1, 2, 3, 3, 2, 0, 1 - "clustered", because each submask of size 4
880 /// (0,1,2,3 and 3,2,0,1) uses indices [0..VF) exactly one time.
881 /// 0, 1, 2, 3, 3, 3, 1, 0 - not "clustered", because
882 /// element 3 is used twice in the second submask
883 /// (3,3,1,0) and index 2 is not used at all.
884 static bool isOneUseSingleSourceMask(ArrayRef<int> Mask, int VF) {
886 }
887
888 /// Return true if this shuffle mask is a one-use-single-source("clustered")
889 /// mask.
890 bool isOneUseSingleSourceMask(int VF) const {
891 return cast<llvm::ShuffleVectorInst>(Val)->isOneUseSingleSourceMask(VF);
892 }
893
894 /// Change values in a shuffle permute mask assuming the two vector operands
895 /// of length InVecNumElts have swapped position.
897 unsigned InVecNumElts) {
899 }
900
901 /// Return if this shuffle interleaves its two input vectors together.
902 bool isInterleave(unsigned Factor) const {
903 return cast<llvm::ShuffleVectorInst>(Val)->isInterleave(Factor);
904 }
905
906 /// Return true if the mask interleaves one or more input vectors together.
907 ///
908 /// I.e. <0, LaneLen, ... , LaneLen*(Factor - 1), 1, LaneLen + 1, ...>
909 /// E.g. For a Factor of 2 (LaneLen=4):
910 /// <0, 4, 1, 5, 2, 6, 3, 7>
911 /// E.g. For a Factor of 3 (LaneLen=4):
912 /// <4, 0, 9, 5, 1, 10, 6, 2, 11, 7, 3, 12>
913 /// E.g. For a Factor of 4 (LaneLen=2):
914 /// <0, 2, 6, 4, 1, 3, 7, 5>
915 ///
916 /// NumInputElts is the total number of elements in the input vectors.
917 ///
918 /// StartIndexes are the first indexes of each vector being interleaved,
919 /// substituting any indexes that were undef
920 /// E.g. <4, -1, 2, 5, 1, 3> (Factor=3): StartIndexes=<4, 0, 2>
921 ///
922 /// Note that this does not check if the input vectors are consecutive:
923 /// It will return true for masks such as
924 /// <0, 4, 6, 1, 5, 7> (Factor=3, LaneLen=2)
925 static bool isInterleaveMask(ArrayRef<int> Mask, unsigned Factor,
926 unsigned NumInputElts,
927 SmallVectorImpl<unsigned> &StartIndexes) {
928 return llvm::ShuffleVectorInst::isInterleaveMask(Mask, Factor, NumInputElts,
929 StartIndexes);
930 }
931 static bool isInterleaveMask(ArrayRef<int> Mask, unsigned Factor,
932 unsigned NumInputElts) {
934 NumInputElts);
935 }
936
937 /// Check if the mask is a DE-interleave mask of the given factor
938 /// \p Factor like:
939 /// <Index, Index+Factor, ..., Index+(NumElts-1)*Factor>
940 static bool isDeInterleaveMaskOfFactor(ArrayRef<int> Mask, unsigned Factor,
941 unsigned &Index) {
943 Index);
944 }
945 static bool isDeInterleaveMaskOfFactor(ArrayRef<int> Mask, unsigned Factor) {
947 }
948
949 /// Checks if the shuffle is a bit rotation of the first operand across
950 /// multiple subelements, e.g:
951 ///
952 /// shuffle <8 x i8> %a, <8 x i8> poison, <8 x i32> <1, 0, 3, 2, 5, 4, 7, 6>
953 ///
954 /// could be expressed as
955 ///
956 /// rotl <4 x i16> %a, 8
957 ///
958 /// If it can be expressed as a rotation, returns the number of subelements to
959 /// group by in NumSubElts and the number of bits to rotate left in RotateAmt.
960 static bool isBitRotateMask(ArrayRef<int> Mask, unsigned EltSizeInBits,
961 unsigned MinSubElts, unsigned MaxSubElts,
962 unsigned &NumSubElts, unsigned &RotateAmt) {
964 Mask, EltSizeInBits, MinSubElts, MaxSubElts, NumSubElts, RotateAmt);
965 }
966};
967
968class InsertValueInst
969 : public SingleLLVMInstructionImpl<llvm::InsertValueInst> {
970 /// Use Context::createInsertValueInst(). Don't call the constructor directly.
972 : SingleLLVMInstructionImpl(ClassID::InsertValue, Opcode::InsertValue,
973 IVI, Ctx) {}
974 friend Context; // for InsertValueInst()
975
976public:
978 InsertPosition Pos, Context &Ctx,
979 const Twine &Name = "");
980
981 static bool classof(const Value *From) {
982 return From->getSubclassID() == ClassID::InsertValue;
983 }
984
986 inline idx_iterator idx_begin() const {
987 return cast<llvm::InsertValueInst>(Val)->idx_begin();
988 }
989 inline idx_iterator idx_end() const {
990 return cast<llvm::InsertValueInst>(Val)->idx_end();
991 }
993 return cast<llvm::InsertValueInst>(Val)->indices();
994 }
995
999 const Value *getAggregateOperand() const {
1001 }
1005
1015
1017 return cast<llvm::InsertValueInst>(Val)->getIndices();
1018 }
1019
1020 unsigned getNumIndices() const {
1021 return cast<llvm::InsertValueInst>(Val)->getNumIndices();
1022 }
1023
1024 unsigned hasIndices() const {
1025 return cast<llvm::InsertValueInst>(Val)->hasIndices();
1026 }
1027};
1028
1029/// Both UncondBrInst and CondBrInst inherit from this to avoid duplication of
1030/// the successor iterators and successors(). Does not hold any state.
1032private:
1033 struct LLVMBBToSBBB {
1034 Context &Ctx;
1035 LLVMBBToSBBB(Context &Ctx) : Ctx(Ctx) {}
1036 LLVM_ABI BasicBlock *operator()(llvm::BasicBlock *BB) const;
1037 };
1038
1039 struct ConstLLVMBBToSBBB {
1040 Context &Ctx;
1041 ConstLLVMBBToSBBB(Context &Ctx) : Ctx(Ctx) {}
1042 LLVM_ABI const BasicBlock *operator()(const llvm::BasicBlock *BB) const;
1043 };
1044
1045protected:
1046 template <typename LLVMBrTy>
1049 template <typename LLVMBrTy>
1051 Context &Ctx) {
1053 cast<LLVMBrTy>(Val)->successors();
1054 LLVMBBToSBBB BBMap(Ctx);
1055 sb_succ_op_iterator<LLVMBrTy> MappedBegin =
1056 map_iterator(LLVMRange.begin(), BBMap);
1058 map_iterator(LLVMRange.end(), BBMap);
1059 return make_range(MappedBegin, MappedEnd);
1060 }
1061
1062 template <typename LLVMBrTy>
1064 mapped_iterator<typename LLVMBrTy::const_succ_iterator,
1065 ConstLLVMBBToSBBB>;
1066 template <typename LLVMBrTy>
1068 successors(llvm::Value *Val, Context &Ctx) const {
1070 ConstLLVMRange =
1071 static_cast<const LLVMBrTy *>(cast<LLVMBrTy>(Val))->successors();
1072 ConstLLVMBBToSBBB ConstBBMap(Ctx);
1073 const_sb_succ_op_iterator<LLVMBrTy> ConstMappedBegin =
1074 map_iterator(ConstLLVMRange.begin(), ConstBBMap);
1076 map_iterator(ConstLLVMRange.end(), ConstBBMap);
1077 return make_range(ConstMappedBegin, ConstMappedEnd);
1078 }
1079};
1080
1081class UncondBrInst : public SingleLLVMInstructionImpl<llvm::UncondBrInst>,
1082 public BrInstCommon {
1083 /// Use Context::createUncondBrInst(). Don't call the constructor directly.
1084 UncondBrInst(llvm::UncondBrInst *UBI, Context &Ctx)
1085 : SingleLLVMInstructionImpl(ClassID::UncondBr, Opcode::UncondBr, UBI,
1086 Ctx) {}
1087 friend Context; // for UncondBrInst()
1088
1089public:
1090 LLVM_ABI static UncondBrInst *
1091 create(BasicBlock *Target, InsertPosition InsertBefore, Context &Ctx);
1093 LLVM_ABI void setSuccessor(BasicBlock *NewSucc);
1094 unsigned getNumSuccessors() const { return 1; }
1103
1104 /// For isa/dyn_cast.
1105 LLVM_ABI static bool classof(const Value *From);
1106};
1107
1108class CondBrInst : public SingleLLVMInstructionImpl<llvm::CondBrInst>,
1109 public BrInstCommon {
1110 /// Use Context::createUncondBrInst(). Don't call the constructor directly.
1111 CondBrInst(llvm::CondBrInst *CBI, Context &Ctx)
1112 : SingleLLVMInstructionImpl(ClassID::CondBr, Opcode::CondBr, CBI, Ctx) {}
1113 friend Context; // for UcnondBrInst()
1114
1115public:
1116 LLVM_ABI static CondBrInst *create(Value *Cond, BasicBlock *IfTrue,
1117 BasicBlock *IfFalse,
1118 InsertPosition InsertBefore, Context &Ctx);
1119 LLVM_ABI Value *getCondition() const;
1120 LLVM_ABI void setCondition(Value *V);
1121 LLVM_ABI BasicBlock *getSuccessor(unsigned SuccIdx) const;
1122 LLVM_ABI void setSuccessor(unsigned Idx, BasicBlock *NewSucc);
1123 unsigned getNumSuccessors() const { return 2; }
1133
1134 /// For isa/dyn_cast.
1135 LLVM_ABI static bool classof(const Value *From);
1136};
1137
1138/// An abstract class, parent of unary instructions.
1140 : public SingleLLVMInstructionImpl<llvm::UnaryInstruction> {
1141protected:
1143 Context &Ctx)
1144 : SingleLLVMInstructionImpl(ID, Opc, LLVMI, Ctx) {}
1145
1146public:
1147 static bool classof(const Instruction *I) {
1149 }
1150 static bool classof(const Value *V) {
1152 }
1153};
1154
1155class ExtractValueInst : public UnaryInstruction {
1156 /// Use Context::createExtractValueInst() instead.
1158 : UnaryInstruction(ClassID::ExtractValue, Opcode::ExtractValue, EVI,
1159 Ctx) {}
1160 friend Context; // for ExtractValueInst()
1161
1162public:
1163 LLVM_ABI static Value *create(Value *Agg, ArrayRef<unsigned> Idxs,
1164 InsertPosition Pos, Context &Ctx,
1165 const Twine &Name = "");
1166
1167 static bool classof(const Value *From) {
1168 return From->getSubclassID() == ClassID::ExtractValue;
1169 }
1170
1171 /// Returns the type of the element that would be extracted
1172 /// with an extractvalue instruction with the specified parameters.
1173 ///
1174 /// Null is returned if the indices are invalid for the specified type.
1176
1178
1179 inline idx_iterator idx_begin() const {
1180 return cast<llvm::ExtractValueInst>(Val)->idx_begin();
1181 }
1182 inline idx_iterator idx_end() const {
1183 return cast<llvm::ExtractValueInst>(Val)->idx_end();
1184 }
1186 return cast<llvm::ExtractValueInst>(Val)->indices();
1187 }
1188
1194 }
1198
1200 return cast<llvm::ExtractValueInst>(Val)->getIndices();
1201 }
1202
1203 unsigned getNumIndices() const {
1204 return cast<llvm::ExtractValueInst>(Val)->getNumIndices();
1205 }
1206
1207 unsigned hasIndices() const {
1208 return cast<llvm::ExtractValueInst>(Val)->hasIndices();
1209 }
1210};
1211
1212class VAArgInst : public UnaryInstruction {
1213 VAArgInst(llvm::VAArgInst *FI, Context &Ctx)
1214 : UnaryInstruction(ClassID::VAArg, Opcode::VAArg, FI, Ctx) {}
1215 friend Context; // For constructor;
1216
1217public:
1218 LLVM_ABI static VAArgInst *create(Value *List, Type *Ty, InsertPosition Pos,
1219 Context &Ctx, const Twine &Name = "");
1221 const Value *getPointerOperand() const {
1222 return const_cast<VAArgInst *>(this)->getPointerOperand();
1223 }
1224 static unsigned getPointerOperandIndex() {
1226 }
1227 static bool classof(const Value *From) {
1228 return From->getSubclassID() == ClassID::VAArg;
1229 }
1230};
1231
1232class FreezeInst : public UnaryInstruction {
1233 FreezeInst(llvm::FreezeInst *FI, Context &Ctx)
1234 : UnaryInstruction(ClassID::Freeze, Opcode::Freeze, FI, Ctx) {}
1235 friend Context; // For constructor;
1236
1237public:
1238 LLVM_ABI static FreezeInst *create(Value *V, InsertPosition Pos, Context &Ctx,
1239 const Twine &Name = "");
1240 static bool classof(const Value *From) {
1241 return From->getSubclassID() == ClassID::Freeze;
1242 }
1243};
1244
1245class LoadInst final : public UnaryInstruction {
1246 /// Use LoadInst::create() instead of calling the constructor.
1247 LoadInst(llvm::LoadInst *LI, Context &Ctx)
1248 : UnaryInstruction(ClassID::Load, Opcode::Load, LI, Ctx) {}
1249 friend Context; // for LoadInst()
1250
1251public:
1252 /// Return true if this is a load from a volatile memory location.
1253 bool isVolatile() const { return cast<llvm::LoadInst>(Val)->isVolatile(); }
1254 /// Specify whether this is a volatile load or not.
1255 LLVM_ABI void setVolatile(bool V);
1256
1257 LLVM_ABI static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align,
1258 InsertPosition Pos, bool IsVolatile,
1259 Context &Ctx, const Twine &Name = "");
1260 static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align,
1261 InsertPosition Pos, Context &Ctx,
1262 const Twine &Name = "") {
1263 return create(Ty, Ptr, Align, Pos, /*IsVolatile=*/false, Ctx, Name);
1264 }
1265
1266 /// For isa/dyn_cast.
1267 LLVM_ABI static bool classof(const Value *From);
1270 unsigned getPointerAddressSpace() const {
1272 }
1273 Align getAlign() const { return cast<llvm::LoadInst>(Val)->getAlign(); }
1274 bool isUnordered() const { return cast<llvm::LoadInst>(Val)->isUnordered(); }
1275 bool isSimple() const { return cast<llvm::LoadInst>(Val)->isSimple(); }
1276};
1277
1278class StoreInst final : public SingleLLVMInstructionImpl<llvm::StoreInst> {
1279 /// Use StoreInst::create().
1280 StoreInst(llvm::StoreInst *SI, Context &Ctx)
1281 : SingleLLVMInstructionImpl(ClassID::Store, Opcode::Store, SI, Ctx) {}
1282 friend Context; // for StoreInst()
1283
1284public:
1285 /// Return true if this is a store from a volatile memory location.
1286 bool isVolatile() const { return cast<llvm::StoreInst>(Val)->isVolatile(); }
1287 /// Specify whether this is a volatile store or not.
1288 LLVM_ABI void setVolatile(bool V);
1289
1291 InsertPosition Pos, bool IsVolatile,
1292 Context &Ctx);
1293 static StoreInst *create(Value *V, Value *Ptr, MaybeAlign Align,
1294 InsertPosition Pos, Context &Ctx) {
1295 return create(V, Ptr, Align, Pos, /*IsVolatile=*/false, Ctx);
1296 }
1297
1298 /// For isa/dyn_cast.
1299 LLVM_ABI static bool classof(const Value *From);
1303 unsigned getPointerAddressSpace() const {
1305 }
1306 Align getAlign() const { return cast<llvm::StoreInst>(Val)->getAlign(); }
1307 bool isSimple() const { return cast<llvm::StoreInst>(Val)->isSimple(); }
1308 bool isUnordered() const { return cast<llvm::StoreInst>(Val)->isUnordered(); }
1309};
1310
1311class UnreachableInst final : public Instruction {
1312 /// Use UnreachableInst::create() instead of calling the constructor.
1314 : Instruction(ClassID::Unreachable, Opcode::Unreachable, I, Ctx) {}
1315 friend Context;
1316 Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
1317 return getOperandUseDefault(OpIdx, Verify);
1318 }
1320 return {cast<llvm::Instruction>(Val)};
1321 }
1322
1323public:
1324 LLVM_ABI static UnreachableInst *create(InsertPosition Pos, Context &Ctx);
1325 LLVM_ABI static bool classof(const Value *From);
1326 unsigned getNumSuccessors() const { return 0; }
1327 unsigned getUseOperandNo(const Use &Use) const final {
1328 llvm_unreachable("UnreachableInst has no operands!");
1329 }
1330 unsigned getNumOfIRInstrs() const final { return 1u; }
1331};
1332
1333class ReturnInst final : public SingleLLVMInstructionImpl<llvm::ReturnInst> {
1334 /// Use ReturnInst::create() instead of calling the constructor.
1336 : SingleLLVMInstructionImpl(ClassID::Ret, Opcode::Ret, I, Ctx) {}
1338 : SingleLLVMInstructionImpl(SubclassID, Opcode::Ret, I, Ctx) {}
1339 friend class Context; // For accessing the constructor in create*()
1340 static ReturnInst *createCommon(Value *RetVal, IRBuilder<> &Builder,
1341 Context &Ctx);
1342
1343public:
1344 LLVM_ABI static ReturnInst *create(Value *RetVal, InsertPosition Pos,
1345 Context &Ctx);
1346 static bool classof(const Value *From) {
1347 return From->getSubclassID() == ClassID::Ret;
1348 }
1349 /// \Returns null if there is no return value.
1350 LLVM_ABI Value *getReturnValue() const;
1351};
1352
1353class CallBase : public SingleLLVMInstructionImpl<llvm::CallBase> {
1355 : SingleLLVMInstructionImpl(ID, Opc, I, Ctx) {}
1356 friend class CallInst; // For constructor.
1357 friend class InvokeInst; // For constructor.
1358 friend class CallBrInst; // For constructor.
1359
1360public:
1361 static bool classof(const Value *From) {
1362 auto Opc = From->getSubclassID();
1363 return Opc == Instruction::ClassID::Call ||
1364 Opc == Instruction::ClassID::Invoke ||
1365 Opc == Instruction::ClassID::CallBr;
1366 }
1367
1369
1372 return const_cast<CallBase *>(this)->data_operands_begin();
1373 }
1375 auto *LLVMCB = cast<llvm::CallBase>(Val);
1376 auto Dist = LLVMCB->data_operands_end() - LLVMCB->data_operands_begin();
1377 return op_begin() + Dist;
1378 }
1380 auto *LLVMCB = cast<llvm::CallBase>(Val);
1381 auto Dist = LLVMCB->data_operands_end() - LLVMCB->data_operands_begin();
1382 return op_begin() + Dist;
1383 }
1390 bool data_operands_empty() const {
1392 }
1393 unsigned data_operands_size() const {
1394 return std::distance(data_operands_begin(), data_operands_end());
1395 }
1396 bool isDataOperand(Use U) const {
1397 assert(this == U.getUser() &&
1398 "Only valid to query with a use of this instruction!");
1399 return cast<llvm::CallBase>(Val)->isDataOperand(U.LLVMUse);
1400 }
1401 unsigned getDataOperandNo(Use U) const {
1402 assert(isDataOperand(U) && "Data operand # out of range!");
1403 return cast<llvm::CallBase>(Val)->getDataOperandNo(U.LLVMUse);
1404 }
1405
1406 /// Return the total number operands (not operand bundles) used by
1407 /// every operand bundle in this OperandBundleUser.
1408 unsigned getNumTotalBundleOperands() const {
1409 return cast<llvm::CallBase>(Val)->getNumTotalBundleOperands();
1410 }
1411
1418 return const_cast<CallBase *>(this)->arg_end();
1419 }
1426 bool arg_empty() const { return arg_end() == arg_begin(); }
1427 unsigned arg_size() const { return arg_end() - arg_begin(); }
1428
1429 Value *getArgOperand(unsigned OpIdx) const {
1430 assert(OpIdx < arg_size() && "Out of bounds!");
1431 return getOperand(OpIdx);
1432 }
1433 void setArgOperand(unsigned OpIdx, Value *NewOp) {
1434 assert(OpIdx < arg_size() && "Out of bounds!");
1435 setOperand(OpIdx, NewOp);
1436 }
1437
1438 Use getArgOperandUse(unsigned Idx) const {
1439 assert(Idx < arg_size() && "Out of bounds!");
1440 return getOperandUse(Idx);
1441 }
1442 Use getArgOperandUse(unsigned Idx) {
1443 assert(Idx < arg_size() && "Out of bounds!");
1444 return getOperandUse(Idx);
1445 }
1446
1447 bool isArgOperand(Use U) const {
1448 return cast<llvm::CallBase>(Val)->isArgOperand(U.LLVMUse);
1449 }
1450 unsigned getArgOperandNo(Use U) const {
1451 return cast<llvm::CallBase>(Val)->getArgOperandNo(U.LLVMUse);
1452 }
1453 bool hasArgument(const Value *V) const { return is_contained(args(), V); }
1454
1457
1459 bool isIndirectCall() const {
1460 return cast<llvm::CallBase>(Val)->isIndirectCall();
1461 }
1462 bool isCallee(Use U) const {
1463 return cast<llvm::CallBase>(Val)->isCallee(U.LLVMUse);
1464 }
1466 const Function *getCaller() const {
1467 return const_cast<CallBase *>(this)->getCaller();
1468 }
1469 bool isMustTailCall() const {
1470 return cast<llvm::CallBase>(Val)->isMustTailCall();
1471 }
1472 bool isTailCall() const { return cast<llvm::CallBase>(Val)->isTailCall(); }
1474 return cast<llvm::CallBase>(Val)->getIntrinsicID();
1475 }
1479 return cast<llvm::CallBase>(Val)->getCallingConv();
1480 }
1481 bool isInlineAsm() const { return cast<llvm::CallBase>(Val)->isInlineAsm(); }
1482};
1483
1484class CallInst : public CallBase {
1485 /// Use Context::createCallInst(). Don't call the
1486 /// constructor directly.
1488 : CallBase(ClassID::Call, Opcode::Call, I, Ctx) {}
1489 friend class Context; // For accessing the constructor in create*()
1490 friend class IntrinsicInst; // For constructor
1491
1492public:
1493 LLVM_ABI static CallInst *create(FunctionType *FTy, Value *Func,
1495 Context &Ctx, const Twine &NameStr = "");
1496
1497 static bool classof(const Value *From) {
1498 return From->getSubclassID() == ClassID::Call;
1499 }
1500};
1501
1502class InvokeInst final : public CallBase {
1503 /// Use Context::createInvokeInst(). Don't call the
1504 /// constructor directly.
1506 : CallBase(ClassID::Invoke, Opcode::Invoke, I, Ctx) {}
1507 friend class Context; // For accessing the constructor in
1508 // create*()
1509
1510public:
1511 LLVM_ABI static InvokeInst *create(FunctionType *FTy, Value *Func,
1512 BasicBlock *IfNormal,
1513 BasicBlock *IfException,
1515 Context &Ctx, const Twine &NameStr = "");
1516
1517 static bool classof(const Value *From) {
1518 return From->getSubclassID() == ClassID::Invoke;
1519 }
1525 LLVM_ABI BasicBlock *getSuccessor(unsigned SuccIdx) const;
1526 void setSuccessor(unsigned SuccIdx, BasicBlock *NewSucc) {
1527 assert(SuccIdx < 2 && "Successor # out of range for invoke!");
1528 if (SuccIdx == 0)
1529 setNormalDest(NewSucc);
1530 else
1531 setUnwindDest(NewSucc);
1532 }
1533 unsigned getNumSuccessors() const {
1534 return cast<llvm::InvokeInst>(Val)->getNumSuccessors();
1535 }
1536};
1537
1538class CallBrInst final : public CallBase {
1539 /// Use Context::createCallBrInst(). Don't call the
1540 /// constructor directly.
1542 : CallBase(ClassID::CallBr, Opcode::CallBr, I, Ctx) {}
1543 friend class Context; // For accessing the constructor in
1544 // create*()
1545
1546public:
1547 LLVM_ABI static CallBrInst *create(FunctionType *FTy, Value *Func,
1548 BasicBlock *DefaultDest,
1549 ArrayRef<BasicBlock *> IndirectDests,
1551 Context &Ctx, const Twine &NameStr = "");
1552 static bool classof(const Value *From) {
1553 return From->getSubclassID() == ClassID::CallBr;
1554 }
1555 unsigned getNumIndirectDests() const {
1556 return cast<llvm::CallBrInst>(Val)->getNumIndirectDests();
1557 }
1558 LLVM_ABI Value *getIndirectDestLabel(unsigned Idx) const;
1559 LLVM_ABI Value *getIndirectDestLabelUse(unsigned Idx) const;
1561 LLVM_ABI BasicBlock *getIndirectDest(unsigned Idx) const;
1564 LLVM_ABI void setIndirectDest(unsigned Idx, BasicBlock *BB);
1565 LLVM_ABI BasicBlock *getSuccessor(unsigned Idx) const;
1566 unsigned getNumSuccessors() const {
1567 return cast<llvm::CallBrInst>(Val)->getNumSuccessors();
1568 }
1569};
1570
1571class LandingPadInst : public SingleLLVMInstructionImpl<llvm::LandingPadInst> {
1573 : SingleLLVMInstructionImpl(ClassID::LandingPad, Opcode::LandingPad, LP,
1574 Ctx) {}
1575 friend class Context; // For constructor.
1576
1577public:
1578 LLVM_ABI static LandingPadInst *create(Type *RetTy,
1579 unsigned NumReservedClauses,
1581 const Twine &Name = "");
1582 /// Return 'true' if this landingpad instruction is a
1583 /// cleanup. I.e., it should be run when unwinding even if its landing pad
1584 /// doesn't catch the exception.
1585 bool isCleanup() const {
1586 return cast<llvm::LandingPadInst>(Val)->isCleanup();
1587 }
1588 /// Indicate that this landingpad instruction is a cleanup.
1589 LLVM_ABI void setCleanup(bool V);
1590
1591 // TODO: We are not implementing addClause() because we have no way to revert
1592 // it for now.
1593
1594 /// Get the value of the clause at index Idx. Use isCatch/isFilter to
1595 /// determine what type of clause this is.
1596 LLVM_ABI Constant *getClause(unsigned Idx) const;
1597
1598 /// Return 'true' if the clause and index Idx is a catch clause.
1599 bool isCatch(unsigned Idx) const {
1600 return cast<llvm::LandingPadInst>(Val)->isCatch(Idx);
1601 }
1602 /// Return 'true' if the clause and index Idx is a filter clause.
1603 bool isFilter(unsigned Idx) const {
1604 return cast<llvm::LandingPadInst>(Val)->isFilter(Idx);
1605 }
1606 /// Get the number of clauses for this landing pad.
1607 unsigned getNumClauses() const {
1608 return cast<llvm::LandingPadInst>(Val)->getNumOperands();
1609 }
1610 // TODO: We are not implementing reserveClauses() because we can't revert it.
1611 static bool classof(const Value *From) {
1612 return From->getSubclassID() == ClassID::LandingPad;
1613 }
1614};
1615
1616class FuncletPadInst : public SingleLLVMInstructionImpl<llvm::FuncletPadInst> {
1618 Context &Ctx)
1619 : SingleLLVMInstructionImpl(SubclassID, Opc, I, Ctx) {}
1620 friend class CatchPadInst; // For constructor.
1621 friend class CleanupPadInst; // For constructor.
1622
1623public:
1624 /// Return the number of funcletpad arguments.
1625 unsigned arg_size() const {
1626 return cast<llvm::FuncletPadInst>(Val)->arg_size();
1627 }
1628 /// Return the outer EH-pad this funclet is nested within.
1629 ///
1630 /// Note: This returns the associated CatchSwitchInst if this FuncletPadInst
1631 /// is a CatchPadInst.
1632 LLVM_ABI Value *getParentPad() const;
1633 LLVM_ABI void setParentPad(Value *ParentPad);
1634 /// Return the Idx-th funcletpad argument.
1635 LLVM_ABI Value *getArgOperand(unsigned Idx) const;
1636 /// Set the Idx-th funcletpad argument.
1637 LLVM_ABI void setArgOperand(unsigned Idx, Value *V);
1638
1639 // TODO: Implement missing functions: arg_operands().
1640 static bool classof(const Value *From) {
1641 return From->getSubclassID() == ClassID::CatchPad ||
1642 From->getSubclassID() == ClassID::CleanupPad;
1643 }
1644};
1645
1646class CatchPadInst : public FuncletPadInst {
1648 : FuncletPadInst(ClassID::CatchPad, Opcode::CatchPad, CPI, Ctx) {}
1649 friend class Context; // For constructor.
1650
1651public:
1653 // TODO: We have not implemented setCatchSwitch() because we can't revert it
1654 // for now, as there is no CatchPadInst member function that can undo it.
1655
1656 LLVM_ABI static CatchPadInst *create(Value *ParentPad, ArrayRef<Value *> Args,
1658 const Twine &Name = "");
1659 static bool classof(const Value *From) {
1660 return From->getSubclassID() == ClassID::CatchPad;
1661 }
1662};
1663
1664class CleanupPadInst : public FuncletPadInst {
1666 : FuncletPadInst(ClassID::CleanupPad, Opcode::CleanupPad, CPI, Ctx) {}
1667 friend class Context; // For constructor.
1668
1669public:
1670 LLVM_ABI static CleanupPadInst *create(Value *ParentPad,
1671 ArrayRef<Value *> Args,
1673 const Twine &Name = "");
1674 static bool classof(const Value *From) {
1675 return From->getSubclassID() == ClassID::CleanupPad;
1676 }
1677};
1678
1679class CatchReturnInst
1680 : public SingleLLVMInstructionImpl<llvm::CatchReturnInst> {
1682 : SingleLLVMInstructionImpl(ClassID::CatchRet, Opcode::CatchRet, CRI,
1683 Ctx) {}
1684 friend class Context; // For constructor.
1685
1686public:
1687 LLVM_ABI static CatchReturnInst *create(CatchPadInst *CatchPad,
1688 BasicBlock *BB, InsertPosition Pos,
1689 Context &Ctx);
1691 LLVM_ABI void setCatchPad(CatchPadInst *CatchPad);
1693 LLVM_ABI void setSuccessor(BasicBlock *NewSucc);
1694 unsigned getNumSuccessors() {
1695 return cast<llvm::CatchReturnInst>(Val)->getNumSuccessors();
1696 }
1698 static bool classof(const Value *From) {
1699 return From->getSubclassID() == ClassID::CatchRet;
1700 }
1701};
1702
1703class CleanupReturnInst
1704 : public SingleLLVMInstructionImpl<llvm::CleanupReturnInst> {
1706 : SingleLLVMInstructionImpl(ClassID::CleanupRet, Opcode::CleanupRet, CRI,
1707 Ctx) {}
1708 friend class Context; // For constructor.
1709
1710public:
1711 LLVM_ABI static CleanupReturnInst *create(CleanupPadInst *CleanupPad,
1712 BasicBlock *UnwindBB,
1713 InsertPosition Pos, Context &Ctx);
1714 bool hasUnwindDest() const {
1715 return cast<llvm::CleanupReturnInst>(Val)->hasUnwindDest();
1716 }
1717 bool unwindsToCaller() const {
1718 return cast<llvm::CleanupReturnInst>(Val)->unwindsToCaller();
1719 }
1721 LLVM_ABI void setCleanupPad(CleanupPadInst *CleanupPad);
1722 unsigned getNumSuccessors() const {
1723 return cast<llvm::CleanupReturnInst>(Val)->getNumSuccessors();
1724 }
1726 LLVM_ABI void setUnwindDest(BasicBlock *NewDest);
1727
1728 static bool classof(const Value *From) {
1729 return From->getSubclassID() == ClassID::CleanupRet;
1730 }
1731};
1732
1733class GetElementPtrInst final
1734 : public SingleLLVMInstructionImpl<llvm::GetElementPtrInst> {
1735 /// Use Context::createGetElementPtrInst(). Don't call
1736 /// the constructor directly.
1738 : SingleLLVMInstructionImpl(ClassID::GetElementPtr, Opcode::GetElementPtr,
1739 I, Ctx) {}
1741 : SingleLLVMInstructionImpl(SubclassID, Opcode::GetElementPtr, I, Ctx) {}
1742 friend class Context; // For accessing the constructor in
1743 // create*()
1744
1745public:
1746 LLVM_ABI static Value *create(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
1748 const Twine &NameStr = "");
1749
1750 static bool classof(const Value *From) {
1751 return From->getSubclassID() == ClassID::GetElementPtr;
1752 }
1753
1756 unsigned getAddressSpace() const {
1757 return cast<llvm::GetElementPtrInst>(Val)->getAddressSpace();
1758 }
1759
1760 inline op_iterator idx_begin() { return op_begin() + 1; }
1762 return const_cast<GetElementPtrInst *>(this)->idx_begin();
1763 }
1764 inline op_iterator idx_end() { return op_end(); }
1766 return const_cast<GetElementPtrInst *>(this)->idx_end();
1767 }
1772 return const_cast<GetElementPtrInst *>(this)->indices();
1773 }
1774
1780 unsigned getPointerAddressSpace() const {
1781 return cast<llvm::GetElementPtrInst>(Val)->getPointerAddressSpace();
1782 }
1783 unsigned getNumIndices() const {
1784 return cast<llvm::GetElementPtrInst>(Val)->getNumIndices();
1785 }
1786 bool hasIndices() const {
1787 return cast<llvm::GetElementPtrInst>(Val)->hasIndices();
1788 }
1790 return cast<llvm::GetElementPtrInst>(Val)->hasAllConstantIndices();
1791 }
1793 return cast<llvm::GetElementPtrInst>(Val)->getNoWrapFlags();
1794 }
1795 bool isInBounds() const {
1796 return cast<llvm::GetElementPtrInst>(Val)->isInBounds();
1797 }
1799 return cast<llvm::GetElementPtrInst>(Val)->hasNoUnsignedSignedWrap();
1800 }
1801 bool hasNoUnsignedWrap() const {
1802 return cast<llvm::GetElementPtrInst>(Val)->hasNoUnsignedWrap();
1803 }
1805 return cast<llvm::GetElementPtrInst>(Val)->accumulateConstantOffset(DL,
1806 Offset);
1807 }
1808 // TODO: Add missing member functions.
1809};
1810
1811class CatchSwitchInst
1812 : public SingleLLVMInstructionImpl<llvm::CatchSwitchInst> {
1814 : SingleLLVMInstructionImpl(ClassID::CatchSwitch, Opcode::CatchSwitch,
1815 CSI, Ctx) {}
1816 friend class Context; // For accessing the constructor in create*()
1817
1818public:
1819 LLVM_ABI static CatchSwitchInst *
1820 create(Value *ParentPad, BasicBlock *UnwindBB, unsigned NumHandlers,
1821 InsertPosition Pos, Context &Ctx, const Twine &Name = "");
1822
1823 LLVM_ABI Value *getParentPad() const;
1824 LLVM_ABI void setParentPad(Value *ParentPad);
1825
1826 bool hasUnwindDest() const {
1827 return cast<llvm::CatchSwitchInst>(Val)->hasUnwindDest();
1828 }
1829 bool unwindsToCaller() const {
1830 return cast<llvm::CatchSwitchInst>(Val)->unwindsToCaller();
1831 }
1833 LLVM_ABI void setUnwindDest(BasicBlock *UnwindDest);
1834
1835 unsigned getNumHandlers() const {
1836 return cast<llvm::CatchSwitchInst>(Val)->getNumHandlers();
1837 }
1838
1839private:
1840 static BasicBlock *handler_helper(Value *V) { return cast<BasicBlock>(V); }
1841 static const BasicBlock *handler_helper(const Value *V) {
1842 return cast<BasicBlock>(V);
1843 }
1844
1845public:
1846 using DerefFnTy = BasicBlock *(*)(Value *);
1849 using ConstDerefFnTy = const BasicBlock *(*)(const Value *);
1853
1855 op_iterator It = op_begin() + 1;
1856 if (hasUnwindDest())
1857 ++It;
1858 return handler_iterator(It, DerefFnTy(handler_helper));
1859 }
1861 const_op_iterator It = op_begin() + 1;
1862 if (hasUnwindDest())
1863 ++It;
1864 return const_handler_iterator(It, ConstDerefFnTy(handler_helper));
1865 }
1867 return handler_iterator(op_end(), DerefFnTy(handler_helper));
1868 }
1870 return const_handler_iterator(op_end(), ConstDerefFnTy(handler_helper));
1871 }
1878
1879 LLVM_ABI void addHandler(BasicBlock *Dest);
1880
1881 // TODO: removeHandler() cannot be reverted because there is no equivalent
1882 // addHandler() with a handler_iterator to specify the position. So we can't
1883 // implement it for now.
1884
1885 unsigned getNumSuccessors() const { return getNumOperands() - 1; }
1886 BasicBlock *getSuccessor(unsigned Idx) const {
1887 assert(Idx < getNumSuccessors() &&
1888 "Successor # out of range for catchswitch!");
1889 return cast<BasicBlock>(getOperand(Idx + 1));
1890 }
1891 void setSuccessor(unsigned Idx, BasicBlock *NewSucc) {
1892 assert(Idx < getNumSuccessors() &&
1893 "Successor # out of range for catchswitch!");
1894 setOperand(Idx + 1, NewSucc);
1895 }
1896
1897 static bool classof(const Value *From) {
1898 return From->getSubclassID() == ClassID::CatchSwitch;
1899 }
1900};
1901
1902class ResumeInst : public SingleLLVMInstructionImpl<llvm::ResumeInst> {
1904 : SingleLLVMInstructionImpl(ClassID::Resume, Opcode::Resume, CSI, Ctx) {}
1905 friend class Context; // For accessing the constructor in create*()
1906
1907public:
1908 LLVM_ABI static ResumeInst *create(Value *Exn, InsertPosition Pos,
1909 Context &Ctx);
1910 LLVM_ABI Value *getValue() const;
1911 unsigned getNumSuccessors() const {
1912 return cast<llvm::ResumeInst>(Val)->getNumSuccessors();
1913 }
1914 static bool classof(const Value *From) {
1915 return From->getSubclassID() == ClassID::Resume;
1916 }
1917};
1918
1919class SwitchInst : public SingleLLVMInstructionImpl<llvm::SwitchInst> {
1921 : SingleLLVMInstructionImpl(ClassID::Switch, Opcode::Switch, SI, Ctx) {}
1922 friend class Context; // For accessing the constructor in create*()
1923
1924public:
1925 static constexpr unsigned DefaultPseudoIndex =
1927
1928 LLVM_ABI static SwitchInst *create(Value *V, BasicBlock *Dest,
1929 unsigned NumCases, InsertPosition Pos,
1930 Context &Ctx, const Twine &Name = "");
1931
1932 LLVM_ABI Value *getCondition() const;
1933 LLVM_ABI void setCondition(Value *V);
1936 return cast<llvm::SwitchInst>(Val)->defaultDestUnreachable();
1937 }
1938 LLVM_ABI void setDefaultDest(BasicBlock *DefaultCase);
1939 unsigned getNumCases() const {
1940 return cast<llvm::SwitchInst>(Val)->getNumCases();
1941 }
1942
1943 template <typename LLVMCaseItT, typename BlockT, typename ConstT>
1944 class CaseItImpl;
1945
1946 // The template helps avoid code duplication for const and non-const
1947 // CaseHandle variants.
1948 template <typename LLVMCaseItT, typename BlockT, typename ConstT>
1950 Context &Ctx;
1951 // NOTE: We are not wrapping an LLVM CaseHande here because it is not
1952 // default-constructible. Instead we are wrapping the LLVM CaseIt
1953 // iterator, as we can always get an LLVM CaseHandle by de-referencing it.
1954 LLVMCaseItT LLVMCaseIt;
1955 template <typename T1, typename T2, typename T3> friend class CaseItImpl;
1956
1957 public:
1958 CaseHandleImpl(Context &Ctx, LLVMCaseItT LLVMCaseIt)
1959 : Ctx(Ctx), LLVMCaseIt(LLVMCaseIt) {}
1960 ConstT *getCaseValue() const;
1961 BlockT *getCaseSuccessor() const;
1962 unsigned getCaseIndex() const {
1963 const auto &LLVMCaseHandle = *LLVMCaseIt;
1964 return LLVMCaseHandle.getCaseIndex();
1965 }
1966 unsigned getSuccessorIndex() const {
1967 const auto &LLVMCaseHandle = *LLVMCaseIt;
1968 return LLVMCaseHandle.getSuccessorIndex();
1969 }
1970 };
1971
1972 // The template helps avoid code duplication for const and non-const CaseIt
1973 // variants.
1974 template <typename LLVMCaseItT, typename BlockT, typename ConstT>
1976 CaseItImpl<LLVMCaseItT, BlockT, ConstT>,
1977 std::random_access_iterator_tag,
1978 const CaseHandleImpl<LLVMCaseItT, BlockT, ConstT>> {
1980
1981 public:
1982 CaseItImpl(Context &Ctx, LLVMCaseItT It) : CH(Ctx, It) {}
1983 CaseItImpl(SwitchInst *SI, ptrdiff_t CaseNum)
1984 : CH(SI->getContext(), llvm::SwitchInst::CaseIt(
1985 cast<llvm::SwitchInst>(SI->Val), CaseNum)) {}
1987 CH.LLVMCaseIt += N;
1988 return *this;
1989 }
1991 CH.LLVMCaseIt -= N;
1992 return *this;
1993 }
1995 return CH.LLVMCaseIt - Other.CH.LLVMCaseIt;
1996 }
1997 bool operator==(const CaseItImpl &Other) const {
1998 return CH.LLVMCaseIt == Other.CH.LLVMCaseIt;
1999 }
2000 bool operator<(const CaseItImpl &Other) const {
2001 return CH.LLVMCaseIt < Other.CH.LLVMCaseIt;
2002 }
2004 return CH;
2005 }
2006 };
2007
2011
2013 const BasicBlock, const ConstantInt>;
2015 const BasicBlock, const ConstantInt>;
2016
2017 /// Returns a read/write iterator that points to the first case in the
2018 /// SwitchInst.
2025 /// Returns a read/write iterator that points one past the last in the
2026 /// SwitchInst.
2033 /// Iteration adapter for range-for loops.
2055
2056 LLVM_ABI void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2057 /// This method removes the specified case and its successor from the switch
2058 /// instruction. Note that this operation may reorder the remaining cases at
2059 /// index idx and above.
2060 /// Note:
2061 /// This action invalidates iterators for all cases following the one removed,
2062 /// including the case_end() iterator. It returns an iterator for the next
2063 /// case.
2065
2066 unsigned getNumSuccessors() const {
2067 return cast<llvm::SwitchInst>(Val)->getNumSuccessors();
2068 }
2069 LLVM_ABI BasicBlock *getSuccessor(unsigned Idx) const;
2070 LLVM_ABI void setSuccessor(unsigned Idx, BasicBlock *NewSucc);
2071 static bool classof(const Value *From) {
2072 return From->getSubclassID() == ClassID::Switch;
2073 }
2074};
2075
2076extern template class LLVM_TEMPLATE_ABI SwitchInst::CaseHandleImpl<
2078extern template class LLVM_TEMPLATE_ABI SwitchInst::CaseHandleImpl<
2080
2081class UnaryOperator : public UnaryInstruction {
2082 static Opcode getUnaryOpcode(llvm::Instruction::UnaryOps UnOp) {
2083 switch (UnOp) {
2084 case llvm::Instruction::FNeg:
2085 return Opcode::FNeg;
2086 case llvm::Instruction::UnaryOpsEnd:
2087 llvm_unreachable("Bad UnOp!");
2088 }
2089 llvm_unreachable("Unhandled UnOp!");
2090 }
2092 : UnaryInstruction(ClassID::UnOp, getUnaryOpcode(UO->getOpcode()), UO,
2093 Ctx) {}
2094 friend Context; // for constructor.
2095public:
2097 InsertPosition Pos, Context &Ctx,
2098 const Twine &Name = "");
2100 Value *OpV, Value *CopyFrom,
2101 InsertPosition Pos, Context &Ctx,
2102 const Twine &Name = "");
2103 /// For isa/dyn_cast.
2104 static bool classof(const Value *From) {
2105 return From->getSubclassID() == ClassID::UnOp;
2106 }
2107};
2108
2109class BinaryOperator : public SingleLLVMInstructionImpl<llvm::BinaryOperator> {
2110protected:
2112 switch (BinOp) {
2113 case llvm::Instruction::Add:
2114 return Opcode::Add;
2115 case llvm::Instruction::FAdd:
2116 return Opcode::FAdd;
2117 case llvm::Instruction::Sub:
2118 return Opcode::Sub;
2119 case llvm::Instruction::FSub:
2120 return Opcode::FSub;
2121 case llvm::Instruction::Mul:
2122 return Opcode::Mul;
2123 case llvm::Instruction::FMul:
2124 return Opcode::FMul;
2125 case llvm::Instruction::UDiv:
2126 return Opcode::UDiv;
2127 case llvm::Instruction::SDiv:
2128 return Opcode::SDiv;
2129 case llvm::Instruction::FDiv:
2130 return Opcode::FDiv;
2131 case llvm::Instruction::URem:
2132 return Opcode::URem;
2133 case llvm::Instruction::SRem:
2134 return Opcode::SRem;
2135 case llvm::Instruction::FRem:
2136 return Opcode::FRem;
2137 case llvm::Instruction::Shl:
2138 return Opcode::Shl;
2139 case llvm::Instruction::LShr:
2140 return Opcode::LShr;
2141 case llvm::Instruction::AShr:
2142 return Opcode::AShr;
2143 case llvm::Instruction::And:
2144 return Opcode::And;
2145 case llvm::Instruction::Or:
2146 return Opcode::Or;
2147 case llvm::Instruction::Xor:
2148 return Opcode::Xor;
2149 case llvm::Instruction::BinaryOpsEnd:
2150 llvm_unreachable("Bad BinOp!");
2151 }
2152 llvm_unreachable("Unhandled BinOp!");
2153 }
2155 : SingleLLVMInstructionImpl(ClassID::BinaryOperator,
2156 getBinOpOpcode(BinOp->getOpcode()), BinOp,
2157 Ctx) {}
2158 friend class Context; // For constructor.
2159
2160public:
2163 const Twine &Name = "");
2164
2166 Value *LHS, Value *RHS,
2167 Value *CopyFrom,
2169 const Twine &Name = "");
2170 /// For isa/dyn_cast.
2171 static bool classof(const Value *From) {
2172 return From->getSubclassID() == ClassID::BinaryOperator;
2173 }
2175};
2176
2177/// An or instruction, which can be marked as "disjoint", indicating that the
2178/// inputs don't have a 1 in the same bit position. Meaning this instruction
2179/// can also be treated as an add.
2181public:
2182 LLVM_ABI void setIsDisjoint(bool B);
2183 bool isDisjoint() const {
2184 return cast<llvm::PossiblyDisjointInst>(Val)->isDisjoint();
2185 }
2186 /// For isa/dyn_cast.
2187 static bool classof(const Value *From) {
2188 return isa<Instruction>(From) &&
2189 cast<Instruction>(From)->getOpcode() == Opcode::Or;
2190 }
2191};
2192
2193class AtomicRMWInst : public SingleLLVMInstructionImpl<llvm::AtomicRMWInst> {
2195 : SingleLLVMInstructionImpl(ClassID::AtomicRMW,
2196 Instruction::Opcode::AtomicRMW, Atomic, Ctx) {
2197 }
2198 friend class Context; // For constructor.
2199
2200public:
2203 return cast<llvm::AtomicRMWInst>(Val)->getOperation();
2204 }
2208 static bool isFPOperation(BinOp Op) {
2210 }
2212 cast<llvm::AtomicRMWInst>(Val)->setOperation(Op);
2213 }
2214 Align getAlign() const { return cast<llvm::AtomicRMWInst>(Val)->getAlign(); }
2216 bool isVolatile() const {
2217 return cast<llvm::AtomicRMWInst>(Val)->isVolatile();
2218 }
2219 LLVM_ABI void setVolatile(bool V);
2221 return cast<llvm::AtomicRMWInst>(Val)->getOrdering();
2222 }
2223 LLVM_ABI void setOrdering(AtomicOrdering Ordering);
2225 return cast<llvm::AtomicRMWInst>(Val)->getSyncScopeID();
2226 }
2229 const Value *getPointerOperand() const {
2230 return const_cast<AtomicRMWInst *>(this)->getPointerOperand();
2231 }
2233 const Value *getValOperand() const {
2234 return const_cast<AtomicRMWInst *>(this)->getValOperand();
2235 }
2236 unsigned getPointerAddressSpace() const {
2237 return cast<llvm::AtomicRMWInst>(Val)->getPointerAddressSpace();
2238 }
2240 return cast<llvm::AtomicRMWInst>(Val)->isFloatingPointOperation();
2241 }
2242 static bool classof(const Value *From) {
2243 return From->getSubclassID() == ClassID::AtomicRMW;
2244 }
2245
2246 LLVM_ABI static AtomicRMWInst *
2248 AtomicOrdering Ordering, InsertPosition Pos, Context &Ctx,
2249 SyncScope::ID SSID = SyncScope::System, const Twine &Name = "");
2250};
2251
2252class AtomicCmpXchgInst
2253 : public SingleLLVMInstructionImpl<llvm::AtomicCmpXchgInst> {
2255 : SingleLLVMInstructionImpl(ClassID::AtomicCmpXchg,
2256 Instruction::Opcode::AtomicCmpXchg, Atomic,
2257 Ctx) {}
2258 friend class Context; // For constructor.
2259
2260public:
2261 /// Return the alignment of the memory that is being allocated by the
2262 /// instruction.
2263 Align getAlign() const {
2264 return cast<llvm::AtomicCmpXchgInst>(Val)->getAlign();
2265 }
2266
2268 /// Return true if this is a cmpxchg from a volatile memory
2269 /// location.
2270 bool isVolatile() const {
2271 return cast<llvm::AtomicCmpXchgInst>(Val)->isVolatile();
2272 }
2273 /// Specify whether this is a volatile cmpxchg.
2274 LLVM_ABI void setVolatile(bool V);
2275 /// Return true if this cmpxchg may spuriously fail.
2276 bool isWeak() const { return cast<llvm::AtomicCmpXchgInst>(Val)->isWeak(); }
2277 LLVM_ABI void setWeak(bool IsWeak);
2285 return cast<llvm::AtomicCmpXchgInst>(Val)->getSuccessOrdering();
2286 }
2288
2290 return cast<llvm::AtomicCmpXchgInst>(Val)->getFailureOrdering();
2291 }
2294 return cast<llvm::AtomicCmpXchgInst>(Val)->getMergedOrdering();
2295 }
2297 return cast<llvm::AtomicCmpXchgInst>(Val)->getSyncScopeID();
2298 }
2301 const Value *getPointerOperand() const {
2302 return const_cast<AtomicCmpXchgInst *>(this)->getPointerOperand();
2303 }
2304
2306 const Value *getCompareOperand() const {
2307 return const_cast<AtomicCmpXchgInst *>(this)->getCompareOperand();
2308 }
2309
2311 const Value *getNewValOperand() const {
2312 return const_cast<AtomicCmpXchgInst *>(this)->getNewValOperand();
2313 }
2314
2315 /// Returns the address space of the pointer operand.
2316 unsigned getPointerAddressSpace() const {
2317 return cast<llvm::AtomicCmpXchgInst>(Val)->getPointerAddressSpace();
2318 }
2319
2321 create(Value *Ptr, Value *Cmp, Value *New, MaybeAlign Align,
2322 AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
2323 InsertPosition Pos, Context &Ctx,
2324 SyncScope::ID SSID = SyncScope::System, const Twine &Name = "");
2325
2326 static bool classof(const Value *From) {
2327 return From->getSubclassID() == ClassID::AtomicCmpXchg;
2328 }
2329};
2330
2331class AllocaInst final : public UnaryInstruction {
2333 : UnaryInstruction(ClassID::Alloca, Instruction::Opcode::Alloca, AI,
2334 Ctx) {}
2335 friend class Context; // For constructor.
2336
2337public:
2338 LLVM_ABI static AllocaInst *create(Type *Ty, unsigned AddrSpace,
2340 Value *ArraySize = nullptr,
2341 const Twine &Name = "");
2342
2343 /// Return true if there is an allocation size parameter to the allocation
2344 /// instruction that is not 1.
2345 bool isArrayAllocation() const {
2346 return cast<llvm::AllocaInst>(Val)->isArrayAllocation();
2347 }
2348 /// Get the number of elements allocated. For a simple allocation of a single
2349 /// element, this will return a constant 1 value.
2351 const Value *getArraySize() const {
2352 return const_cast<AllocaInst *>(this)->getArraySize();
2353 }
2354 /// Overload to return most specific pointer type.
2355 LLVM_ABI PointerType *getType() const;
2356 /// Return the address space for the allocation.
2357 unsigned getAddressSpace() const {
2358 return cast<llvm::AllocaInst>(Val)->getAddressSpace();
2359 }
2360 /// Get allocation size in bytes. Returns std::nullopt if size can't be
2361 /// determined, e.g. in case of a VLA.
2362 std::optional<TypeSize> getAllocationSize(const DataLayout &DL) const {
2363 return cast<llvm::AllocaInst>(Val)->getAllocationSize(DL);
2364 }
2365 /// Get allocation size in bits. Returns std::nullopt if size can't be
2366 /// determined, e.g. in case of a VLA.
2367 std::optional<TypeSize> getAllocationSizeInBits(const DataLayout &DL) const {
2368 return cast<llvm::AllocaInst>(Val)->getAllocationSizeInBits(DL);
2369 }
2370 /// Return the type that is being allocated by the instruction.
2372 /// for use only in special circumstances that need to generically
2373 /// transform a whole instruction (eg: IR linking and vectorization).
2374 LLVM_ABI void setAllocatedType(Type *Ty);
2375 /// Return the alignment of the memory that is being allocated by the
2376 /// instruction.
2377 Align getAlign() const { return cast<llvm::AllocaInst>(Val)->getAlign(); }
2379 /// Return true if this alloca is in the entry block of the function and is a
2380 /// constant size. If so, the code generator will fold it into the
2381 /// prolog/epilog code, so it is basically free.
2382 bool isStaticAlloca() const {
2383 return cast<llvm::AllocaInst>(Val)->isStaticAlloca();
2384 }
2385 /// Return true if this alloca is used as an inalloca argument to a call. Such
2386 /// allocas are never considered static even if they are in the entry block.
2387 bool isUsedWithInAlloca() const {
2388 return cast<llvm::AllocaInst>(Val)->isUsedWithInAlloca();
2389 }
2390 /// Specify whether this alloca is used to represent the arguments to a call.
2391 LLVM_ABI void setUsedWithInAlloca(bool V);
2392
2393 static bool classof(const Value *From) {
2394 if (auto *I = dyn_cast<Instruction>(From))
2395 return I->getSubclassID() == Instruction::ClassID::Alloca;
2396 return false;
2397 }
2398};
2399
2400class CastInst : public UnaryInstruction {
2401 static Opcode getCastOpcode(llvm::Instruction::CastOps CastOp) {
2402 switch (CastOp) {
2403 case llvm::Instruction::ZExt:
2404 return Opcode::ZExt;
2405 case llvm::Instruction::SExt:
2406 return Opcode::SExt;
2407 case llvm::Instruction::FPToUI:
2408 return Opcode::FPToUI;
2409 case llvm::Instruction::FPToSI:
2410 return Opcode::FPToSI;
2411 case llvm::Instruction::FPExt:
2412 return Opcode::FPExt;
2413 case llvm::Instruction::PtrToAddr:
2414 return Opcode::PtrToAddr;
2415 case llvm::Instruction::PtrToInt:
2416 return Opcode::PtrToInt;
2417 case llvm::Instruction::IntToPtr:
2418 return Opcode::IntToPtr;
2419 case llvm::Instruction::SIToFP:
2420 return Opcode::SIToFP;
2421 case llvm::Instruction::UIToFP:
2422 return Opcode::UIToFP;
2423 case llvm::Instruction::Trunc:
2424 return Opcode::Trunc;
2425 case llvm::Instruction::FPTrunc:
2426 return Opcode::FPTrunc;
2427 case llvm::Instruction::BitCast:
2428 return Opcode::BitCast;
2429 case llvm::Instruction::AddrSpaceCast:
2430 return Opcode::AddrSpaceCast;
2431 case llvm::Instruction::CastOpsEnd:
2432 llvm_unreachable("Bad CastOp!");
2433 }
2434 llvm_unreachable("Unhandled CastOp!");
2435 }
2436 /// Use Context::createCastInst(). Don't call the
2437 /// constructor directly.
2438 CastInst(llvm::CastInst *CI, Context &Ctx)
2439 : UnaryInstruction(ClassID::Cast, getCastOpcode(CI->getOpcode()), CI,
2440 Ctx) {}
2441 friend Context; // for SBCastInstruction()
2442
2443public:
2444 LLVM_ABI static Value *create(Type *DestTy, Opcode Op, Value *Operand,
2445 InsertPosition Pos, Context &Ctx,
2446 const Twine &Name = "");
2447 /// For isa/dyn_cast.
2448 LLVM_ABI static bool classof(const Value *From);
2449 LLVM_ABI Type *getSrcTy() const;
2450 LLVM_ABI Type *getDestTy() const;
2451};
2452
2453/// Instruction that can have a nneg flag (zext/uitofp).
2454class PossiblyNonNegInst : public CastInst {
2455public:
2456 bool hasNonNeg() const {
2457 return cast<llvm::PossiblyNonNegInst>(Val)->hasNonNeg();
2458 }
2459 LLVM_ABI void setNonNeg(bool B);
2460 /// For isa/dyn_cast.
2461 static bool classof(const Value *From) {
2462 if (auto *I = dyn_cast<Instruction>(From)) {
2463 switch (I->getOpcode()) {
2464 case Opcode::ZExt:
2465 case Opcode::UIToFP:
2466 return true;
2467 default:
2468 return false;
2469 }
2470 }
2471 return false;
2472 }
2473};
2474
2475// Helper class to simplify stamping out CastInst subclasses.
2476template <Instruction::Opcode Op> class CastInstImpl : public CastInst {
2477public:
2478 static Value *create(Value *Src, Type *DestTy, InsertPosition Pos,
2479 Context &Ctx, const Twine &Name = "") {
2480 return CastInst::create(DestTy, Op, Src, Pos, Ctx, Name);
2481 }
2482
2483 static bool classof(const Value *From) {
2484 if (auto *I = dyn_cast<Instruction>(From))
2485 return I->getOpcode() == Op;
2486 return false;
2487 }
2488};
2489
2490class TruncInst final : public CastInstImpl<Instruction::Opcode::Trunc> {};
2491class ZExtInst final : public CastInstImpl<Instruction::Opcode::ZExt> {};
2492class SExtInst final : public CastInstImpl<Instruction::Opcode::SExt> {};
2493class FPTruncInst final : public CastInstImpl<Instruction::Opcode::FPTrunc> {};
2494class FPExtInst final : public CastInstImpl<Instruction::Opcode::FPExt> {};
2495class UIToFPInst final : public CastInstImpl<Instruction::Opcode::UIToFP> {};
2496class SIToFPInst final : public CastInstImpl<Instruction::Opcode::SIToFP> {};
2497class FPToUIInst final : public CastInstImpl<Instruction::Opcode::FPToUI> {};
2498class FPToSIInst final : public CastInstImpl<Instruction::Opcode::FPToSI> {};
2499class IntToPtrInst final : public CastInstImpl<Instruction::Opcode::IntToPtr> {
2500};
2501class PtrToAddrInst final
2502 : public CastInstImpl<Instruction::Opcode::PtrToAddr> {};
2503class PtrToIntInst final : public CastInstImpl<Instruction::Opcode::PtrToInt> {
2504};
2505class BitCastInst final : public CastInstImpl<Instruction::Opcode::BitCast> {};
2507 : public CastInstImpl<Instruction::Opcode::AddrSpaceCast> {
2508public:
2509 /// \Returns the pointer operand.
2511 /// \Returns the pointer operand.
2512 const Value *getPointerOperand() const {
2513 return const_cast<AddrSpaceCastInst *>(this)->getPointerOperand();
2514 }
2515 /// \Returns the operand index of the pointer operand.
2516 static unsigned getPointerOperandIndex() { return 0u; }
2517 /// \Returns the address space of the pointer operand.
2518 unsigned getSrcAddressSpace() const {
2520 }
2521 /// \Returns the address space of the result.
2522 unsigned getDestAddressSpace() const {
2523 return getType()->getPointerAddressSpace();
2524 }
2525};
2526
2527class PHINode final : public SingleLLVMInstructionImpl<llvm::PHINode> {
2528 /// Use Context::createPHINode(). Don't call the constructor directly.
2529 PHINode(llvm::PHINode *PHI, Context &Ctx)
2530 : SingleLLVMInstructionImpl(ClassID::PHI, Opcode::PHI, PHI, Ctx) {}
2531 friend Context; // for PHINode()
2532 /// Helper for mapped_iterator.
2533 struct LLVMBBToBB {
2534 Context &Ctx;
2535 LLVMBBToBB(Context &Ctx) : Ctx(Ctx) {}
2536 LLVM_ABI BasicBlock *operator()(llvm::BasicBlock *LLVMBB) const;
2537 };
2538
2539public:
2540 LLVM_ABI static PHINode *create(Type *Ty, unsigned NumReservedValues,
2541 InsertPosition Pos, Context &Ctx,
2542 const Twine &Name = "");
2543 /// For isa/dyn_cast.
2544 LLVM_ABI static bool classof(const Value *From);
2545
2548
2550 LLVMBBToBB BBGetter(Ctx);
2552 BBGetter);
2553 }
2555 LLVMBBToBB BBGetter(Ctx);
2557 BBGetter);
2558 }
2562
2564
2566
2567 unsigned getNumIncomingValues() const {
2568 return cast<llvm::PHINode>(Val)->getNumIncomingValues();
2569 }
2570 LLVM_ABI Value *getIncomingValue(unsigned Idx) const;
2571 LLVM_ABI void setIncomingValue(unsigned Idx, Value *V);
2572 static unsigned getOperandNumForIncomingValue(unsigned Idx) {
2574 }
2575 static unsigned getIncomingValueNumForOperand(unsigned Idx) {
2577 }
2578 LLVM_ABI BasicBlock *getIncomingBlock(unsigned Idx) const;
2579 LLVM_ABI BasicBlock *getIncomingBlock(const Use &U) const;
2580
2581 LLVM_ABI void setIncomingBlock(unsigned Idx, BasicBlock *BB);
2582
2583 LLVM_ABI void addIncoming(Value *V, BasicBlock *BB);
2584
2585 LLVM_ABI Value *removeIncomingValue(unsigned Idx);
2587
2588 LLVM_ABI int getBasicBlockIndex(const BasicBlock *BB) const;
2590
2592
2594 return cast<llvm::PHINode>(Val)->hasConstantOrUndefValue();
2595 }
2596 bool isComplete() const { return cast<llvm::PHINode>(Val)->isComplete(); }
2598 BasicBlock *New);
2600 // TODO: Implement
2601 // void copyIncomingBlocks(iterator_range<const_block_iterator> BBRange,
2602 // uint32_t ToIdx = 0)
2603};
2604
2605// Wraps a static function that takes a single Predicate parameter
2606// LLVMValType should be the type of the wrapped class
2607#define WRAP_STATIC_PREDICATE(FunctionName) \
2608 static auto FunctionName(Predicate P) { return LLVMValType::FunctionName(P); }
2609// Wraps a member function that takes no parameters
2610// LLVMValType should be the type of the wrapped class
2611#define WRAP_MEMBER(FunctionName) \
2612 auto FunctionName() const { return cast<LLVMValType>(Val)->FunctionName(); }
2613// Wraps both--a common idiom in the CmpInst classes
2614#define WRAP_BOTH(FunctionName) \
2615 WRAP_STATIC_PREDICATE(FunctionName) \
2616 WRAP_MEMBER(FunctionName)
2617
2618class CmpInst : public SingleLLVMInstructionImpl<llvm::CmpInst> {
2619protected:
2621 /// Use Context::createCmpInst(). Don't call the constructor directly.
2623 : SingleLLVMInstructionImpl(Id, Opc, CI, Ctx) {}
2624 friend Context; // for CmpInst()
2625
2626public:
2628
2629 LLVM_ABI static Value *create(Predicate Pred, Value *S1, Value *S2,
2631 const Twine &Name = "");
2633 Value *S2,
2634 const Instruction *FlagsSource,
2636 const Twine &Name = "");
2638 LLVM_ABI void swapOperands();
2639
2640 WRAP_MEMBER(getPredicate);
2641 WRAP_BOTH(isFPPredicate);
2642 WRAP_BOTH(isIntPredicate);
2643 WRAP_STATIC_PREDICATE(getPredicateName);
2644 WRAP_BOTH(getInversePredicate);
2645 WRAP_BOTH(getOrderedPredicate);
2646 WRAP_BOTH(getUnorderedPredicate);
2647 WRAP_BOTH(getSwappedPredicate);
2648 WRAP_BOTH(isStrictPredicate);
2649 WRAP_BOTH(isNonStrictPredicate);
2650 WRAP_BOTH(getStrictPredicate);
2651 WRAP_BOTH(getNonStrictPredicate);
2652 WRAP_BOTH(getFlippedStrictnessPredicate);
2654 WRAP_BOTH(isEquality);
2655 WRAP_BOTH(isRelational);
2657 WRAP_BOTH(isTrueWhenEqual);
2658 WRAP_BOTH(isFalseWhenEqual);
2659 WRAP_BOTH(isUnsigned);
2662
2663 /// Method for support type inquiry through isa, cast, and dyn_cast:
2664 static bool classof(const Value *From) {
2665 return From->getSubclassID() == ClassID::ICmp ||
2666 From->getSubclassID() == ClassID::FCmp;
2667 }
2668
2669 /// Create a result type for fcmp/icmp
2670 LLVM_ABI static Type *makeCmpResultType(Type *OpndType);
2671
2672#ifndef NDEBUG
2673 void dumpOS(raw_ostream &OS) const override;
2674 LLVM_DUMP_METHOD void dump() const;
2675#endif
2676};
2677
2678class ICmpInst : public CmpInst {
2679 /// Use Context::createICmpInst(). Don't call the constructor directly.
2680 ICmpInst(llvm::ICmpInst *CI, Context &Ctx)
2681 : CmpInst(CI, Ctx, ClassID::ICmp, Opcode::ICmp) {}
2682 friend class Context; // For constructor.
2683 using LLVMValType = llvm::ICmpInst;
2684
2685public:
2686 LLVM_ABI void swapOperands();
2687
2688 WRAP_BOTH(getSignedPredicate);
2689 WRAP_BOTH(getUnsignedPredicate);
2690 WRAP_BOTH(getFlippedSignednessPredicate);
2691 WRAP_BOTH(isEquality);
2693 WRAP_MEMBER(isRelational);
2698
2699 static std::optional<bool> isImpliedByMatchingCmp(CmpPredicate Pred1,
2700 CmpPredicate Pred2) {
2701 return llvm::ICmpInst::isImpliedByMatchingCmp(Pred1, Pred2);
2702 }
2703
2704 static auto predicates() { return llvm::ICmpInst::predicates(); }
2705 static bool compare(const APInt &LHS, const APInt &RHS,
2706 ICmpInst::Predicate Pred) {
2707 return llvm::ICmpInst::compare(LHS, RHS, Pred);
2708 }
2709
2710 static bool classof(const Value *From) {
2711 return From->getSubclassID() == ClassID::ICmp;
2712 }
2713};
2714
2715class FCmpInst : public CmpInst {
2716 /// Use Context::createFCmpInst(). Don't call the constructor directly.
2717 FCmpInst(llvm::FCmpInst *CI, Context &Ctx)
2718 : CmpInst(CI, Ctx, ClassID::FCmp, Opcode::FCmp) {}
2719 friend class Context; // For constructor.
2720 using LLVMValType = llvm::FCmpInst;
2721
2722public:
2723 LLVM_ABI void swapOperands();
2724
2725 WRAP_BOTH(isEquality);
2727 WRAP_MEMBER(isRelational);
2728
2729 static auto predicates() { return llvm::FCmpInst::predicates(); }
2730 static bool compare(const APFloat &LHS, const APFloat &RHS,
2731 FCmpInst::Predicate Pred) {
2732 return llvm::FCmpInst::compare(LHS, RHS, Pred);
2733 }
2734
2735 static bool classof(const Value *From) {
2736 return From->getSubclassID() == ClassID::FCmp;
2737 }
2738};
2739
2740#undef WRAP_STATIC_PREDICATE
2741#undef WRAP_MEMBER
2742#undef WRAP_BOTH
2743
2744/// An LLLVM Instruction that has no SandboxIR equivalent class gets mapped to
2745/// an OpaqueInstr.
2746class OpaqueInst : public SingleLLVMInstructionImpl<llvm::Instruction> {
2748 : SingleLLVMInstructionImpl(ClassID::Opaque, Opcode::Opaque, I, Ctx) {}
2750 : SingleLLVMInstructionImpl(SubclassID, Opcode::Opaque, I, Ctx) {}
2751 friend class Context; // For constructor.
2752
2753public:
2754 static bool classof(const sandboxir::Value *From) {
2755 return From->getSubclassID() == ClassID::Opaque;
2756 }
2757};
2758
2759//===----------------------------------------------------------------------===//
2760// Helper functions
2761//===----------------------------------------------------------------------===//
2762
2763/// A helper function that returns the address space of the pointer operand of
2764/// load or store instruction.
2765inline unsigned getLoadStoreAddressSpace(const Instruction *I) {
2767 "Expected Load or Store instruction");
2768 if (auto *LI = dyn_cast<LoadInst>(I))
2769 return LI->getPointerAddressSpace();
2770 return cast<StoreInst>(I)->getPointerAddressSpace();
2771}
2772
2773/// A helper function that returns the alignment of load or store instruction.
2776 "Expected Load or Store instruction");
2777 if (auto *LI = dyn_cast<LoadInst>(I))
2778 return LI->getAlign();
2779 return cast<StoreInst>(I)->getAlign();
2780}
2781
2782} // namespace llvm::sandboxir
2783
2784#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
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:215
#define LLVM_TEMPLATE_ABI
Definition Compiler.h:216
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:686
static bool isSigned(unsigned Opcode)
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define P(N)
ppc ctr loops PowerPC CTR Loops Verify
const SmallVectorImpl< MachineOperand > & Cond
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition APInt.h:78
an instruction to allocate memory on the stack
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
An instruction that atomically checks whether a specified value is in a memory location,...
static bool isValidFailureOrdering(AtomicOrdering Ordering)
static bool isValidSuccessOrdering(AtomicOrdering Ordering)
an instruction that atomically reads a memory location, combines it with another value,...
static bool isFPOperation(BinOp Op)
BinOp
This enumeration lists the possible modifications atomicrmw can make.
static LLVM_ABI StringRef getOperationName(BinOp Op)
LLVM Basic Block Representation.
Definition BasicBlock.h:62
iterator end()
Definition BasicBlock.h:459
This is the base class for all instructions that perform data casts.
Definition InstrTypes.h:512
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
Definition InstrTypes.h:674
This class is the base class for the comparison instructions.
Definition InstrTypes.h:728
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
Conditional Branch instruction.
This is the shared class of boolean and integer constants.
Definition Constants.h:87
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
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:23
An instruction for ordering other memory operations.
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:2918
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.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:294
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...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
A handle to a particular switch case.
Multiway switch.
CaseIteratorImpl< ConstCaseHandle > ConstCaseIt
static const unsigned DefaultPseudoIndex
CaseIteratorImpl< CaseHandle > CaseIt
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
UnaryOps getOpcode() const
Definition InstrTypes.h:163
Unconditional Branch instruction.
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.
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition iterator.h:80
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.
Value * getPointerOperand()
\Returns the pointer operand.
unsigned getDestAddressSpace() const
\Returns the address space of the result.
const Value * getPointerOperand() const
\Returns the pointer operand.
static unsigned getPointerOperandIndex()
\Returns the operand index of the pointer operand.
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
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.
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.
std::optional< TypeSize > getAllocationSizeInBits(const DataLayout &DL) const
Get allocation size in bits.
LLVM_ABI Value * getArraySize()
Get the number of elements allocated.
unsigned getAddressSpace() const
Return the address space for the allocation.
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
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)
std::optional< TypeSize > getAllocationSize(const DataLayout &DL) const
Get allocation size in bytes.
LLVM_ABI void setAlignment(Align Align)
const Value * getArraySize() const
static LLVM_ABI AllocaInst * create(Type *Ty, unsigned AddrSpace, InsertPosition Pos, Context &Ctx, Value *ArraySize=nullptr, const Twine &Name="")
const Value * getNewValOperand() const
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
AtomicOrdering getMergedOrdering() const
LLVM_ABI void setSuccessOrdering(AtomicOrdering Ordering)
const Value * getCompareOperand() const
LLVM_ABI void setWeak(bool IsWeak)
LLVM_ABI void setVolatile(bool V)
Specify whether this is a volatile cmpxchg.
const Value * getPointerOperand() const
LLVM_ABI void setFailureOrdering(AtomicOrdering Ordering)
static bool classof(const Value *From)
AtomicOrdering getFailureOrdering() const
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)
bool isVolatile() const
Return true if this is a cmpxchg from a volatile memory location.
static bool isValidSuccessOrdering(AtomicOrdering Ordering)
LLVM_ABI void setSyncScopeID(SyncScope::ID SSID)
AtomicOrdering getSuccessOrdering() const
SyncScope::ID getSyncScopeID() const
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
bool isWeak() const
Return true if this cmpxchg may spuriously fail.
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
LLVM_ABI void setSyncScopeID(SyncScope::ID SSID)
unsigned getPointerAddressSpace() const
llvm::AtomicRMWInst::BinOp BinOp
LLVM_ABI void setOrdering(AtomicOrdering Ordering)
SyncScope::ID getSyncScopeID() const
LLVM_ABI void setVolatile(bool V)
const Value * getValOperand() const
static StringRef getOperationName(BinOp Op)
AtomicOrdering getOrdering() const
LLVM_ABI Value * getPointerOperand()
static bool classof(const Value *From)
static bool isFPOperation(BinOp Op)
LLVM_ABI void setAlignment(Align Align)
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)
static bool classof(const Value *From)
For isa/dyn_cast.
BinaryOperator(llvm::BinaryOperator *BinOp, Context &Ctx)
static LLVM_ABI Value * createWithCopiedFlags(Instruction::Opcode Op, Value *LHS, Value *RHS, Value *CopyFrom, InsertPosition Pos, Context &Ctx, const Twine &Name="")
Both UncondBrInst and CondBrInst inherit from this to avoid duplication of the successor iterators an...
mapped_iterator< typename LLVMBrTy::succ_iterator, LLVMBBToSBBB > sb_succ_op_iterator
mapped_iterator< typename LLVMBrTy::const_succ_iterator, ConstLLVMBBToSBBB > const_sb_succ_op_iterator
iterator_range< const_sb_succ_op_iterator< LLVMBrTy > > successors(llvm::Value *Val, Context &Ctx) const
iterator_range< sb_succ_op_iterator< LLVMBrTy > > successors(llvm::Value *Val, Context &Ctx)
iterator_range< const_op_iterator > args() const
CallingConv::ID getCallingConv() const
const Function * getCaller() const
LLVM_ABI Function * getCalledFunction() const
LLVM_ABI Use getCalledOperandUse() const
LLVM_ABI FunctionType * getFunctionType() const
const_op_iterator arg_end() const
iterator_range< op_iterator > args()
static bool classof(const Value *From)
Value * getArgOperand(unsigned OpIdx) const
LLVM_ABI void setCalledFunction(Function *F)
Use getArgOperandUse(unsigned Idx)
bool isDataOperand(Use U) const
unsigned getArgOperandNo(Use U) const
const_op_iterator data_operands_end() const
op_iterator data_operands_end()
LLVM_ABI Function * getCaller()
unsigned getDataOperandNo(Use U) const
unsigned getNumTotalBundleOperands() const
Return the total number operands (not operand bundles) used by every operand bundle in this OperandBu...
iterator_range< op_iterator > data_ops()
const_op_iterator data_operands_begin() const
bool data_operands_empty() const
bool hasArgument(const Value *V) const
LLVM_ABI Value * getCalledOperand() const
void setCalledOperand(Value *V)
unsigned arg_size() const
unsigned data_operands_size() const
const_op_iterator arg_begin() const
Intrinsic::ID getIntrinsicID() const
Use getArgOperandUse(unsigned Idx) const
op_iterator data_operands_begin()
bool isArgOperand(Use U) const
void setArgOperand(unsigned OpIdx, Value *NewOp)
iterator_range< const_op_iterator > data_ops() const
bool isCallee(Use U) const
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)
LLVM_ABI void setIndirectDest(unsigned Idx, BasicBlock *BB)
LLVM_ABI BasicBlock * getDefaultDest() const
unsigned getNumIndirectDests() const
LLVM_ABI BasicBlock * getIndirectDest(unsigned Idx) const
LLVM_ABI SmallVector< BasicBlock *, 16 > getIndirectDests() const
unsigned getNumSuccessors() const
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)
static bool classof(const Value *From)
static Value * create(Value *Src, Type *DestTy, InsertPosition Pos, Context &Ctx, const Twine &Name="")
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)
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)
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
const_handler_iterator handler_end() const
const BasicBlock *(*)(const Value *) ConstDerefFnTy
iterator_range< const_handler_iterator > const_handler_range
BasicBlock *(*)(Value *) DerefFnTy
iterator_range< handler_iterator > handler_range
LLVM_ABI void setParentPad(Value *ParentPad)
LLVM_ABI void setUnwindDest(BasicBlock *UnwindDest)
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
mapped_iterator< op_iterator, DerefFnTy > handler_iterator
static bool classof(const Value *From)
void setSuccessor(unsigned Idx, BasicBlock *NewSucc)
LLVM_ABI BasicBlock * getUnwindDest() const
LLVM_ABI Value * getParentPad() const
BasicBlock * getSuccessor(unsigned Idx) const
const_handler_range handlers() const
static LLVM_ABI CleanupPadInst * create(Value *ParentPad, ArrayRef< Value * > Args, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static bool classof(const Value *From)
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)
llvm::CmpInst::Predicate Predicate
WRAP_STATIC_PREDICATE(isUnordered)
WRAP_BOTH(isTrueWhenEqual)
WRAP_BOTH(isFPPredicate)
WRAP_BOTH(getInversePredicate)
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.
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:
static LLVM_ABI CondBrInst * create(Value *Cond, BasicBlock *IfTrue, BasicBlock *IfFalse, InsertPosition InsertBefore, Context &Ctx)
LLVM_ABI BasicBlock * getSuccessor(unsigned SuccIdx) const
static LLVM_ABI bool classof(const Value *From)
For isa/dyn_cast.
const_sb_succ_op_iterator< llvm::CondBrInst > const_succ_op_iterator
sb_succ_op_iterator< llvm::CondBrInst > succ_op_iterator
LLVM_ABI void setSuccessor(unsigned Idx, BasicBlock *NewSucc)
unsigned getNumSuccessors() const
iterator_range< const_succ_op_iterator > successors() const
LLVM_ABI Value * getCondition() const
LLVM_ABI void setCondition(Value *V)
iterator_range< succ_op_iterator > successors()
const Value * getVectorOperand() const
const Value * getIndexOperand() const
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)
static bool isValidOperands(const Value *Vec, const Value *Idx)
static LLVM_ABI Value * create(Value *Agg, ArrayRef< unsigned > Idxs, InsertPosition Pos, Context &Ctx, const Twine &Name="")
const Value * getAggregateOperand() const
static unsigned getAggregateOperandIndex()
ArrayRef< unsigned > getIndices() const
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...
llvm::ExtractValueInst::idx_iterator idx_iterator
static bool classof(const Value *From)
iterator_range< idx_iterator > indices() const
WRAP_MEMBER(isCommutative)
static bool compare(const APFloat &LHS, const APFloat &RHS, FCmpInst::Predicate Pred)
static bool classof(const Value *From)
AtomicOrdering getOrdering() const
Returns the ordering constraint of this fence instruction.
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.
static bool classof(const Value *From)
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)
static bool classof(const Value *From)
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.
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()
const_op_iterator idx_begin() const
GEPNoWrapFlags getNoWrapFlags() const
LLVM_ABI Type * getResultElementType() const
LLVM_ABI Type * getPointerOperandType() const
static unsigned getPointerOperandIndex()
LLVM_ABI Type * getSourceElementType() const
static bool classof(const Value *From)
const_op_iterator idx_end() const
LLVM_ABI Value * getPointerOperand() const
bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const
iterator_range< const_op_iterator > indices() const
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)
WRAP_BOTH(getSignedPredicate)
static bool compare(const APInt &LHS, const APInt &RHS, ICmpInst::Predicate Pred)
WRAP_BOTH(getUnsignedPredicate)
WRAP_MEMBER(isCommutative)
WRAP_BOTH(getFlippedSignednessPredicate)
static bool classof(const Value *From)
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)
static bool classof(const Value *From)
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
llvm::InsertValueInst::idx_iterator idx_iterator
idx_iterator idx_end() const
iterator_range< idx_iterator > indices() const
static bool classof(const Value *From)
const Value * getInsertedValueOperand() const
const Value * getAggregateOperand() const
static unsigned getInsertedValueOperandIndex()
ArrayRef< unsigned > getIndices() const
static LLVM_ABI Value * create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, InsertPosition Pos, Context &Ctx, const Twine &Name="")
idx_iterator idx_begin() const
static unsigned getAggregateOperandIndex()
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.
LLVM_ABI void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
const DataLayout & getDataLayout() const
bool hasAllowReassoc() const
Determine whether the allow-reassociation flag is set.
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.
const char * getOpcodeName() const
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.
bool hasMetadataOtherThanDebugLoc() const
Return true if this instruction has metadata attached to it other than a debug location.
void moveAfter(Instruction *After)
Move this instruction after After.
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.
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.
bool hasNoSignedWrap() const
Determine whether the no signed wrap flag is set.
static const char * getOpcodeName(Opcode Opc)
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.
void dumpOS(raw_ostream &OS) const override
bool isFast() const
Determine whether all fast-math-flags are set.
LLVM_ABI BBIterator getIterator() const
\Returns a BasicBlock::iterator for this Instruction.
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
LLVM_ABI llvm::Instruction * getTopmostLLVMInstruction() const
A SandboxIR Instruction may map to multiple LLVM IR Instruction.
bool hasMetadata() const
Return true if the instruction has any metadata attached to it.
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
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.
LLVM_ABI Type * getAccessType() const
bool isExact() const
Determine whether the exact flag is set.
Instruction(ClassID ID, Opcode Opc, llvm::Instruction *I, sandboxir::Context &SBCtx)
Definition Instruction.h:57
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
bool comesBefore(const Instruction *Other) const
Given an instruction Other in the same basic block as this instruction, return true if this instructi...
LLVM_ABI Instruction * getNextNode() const
\Returns the next sandboxir::Instruction in the block, or nullptr if at the end of the block.
bool hasNoInfs() const
Determine whether the no-infs flag is set.
LLVM_ABI void removeFromParent()
Detach this from its parent BasicBlock without deleting it.
LLVM_ABI Instruction * getPrevNode() const
\Returns the previous sandboxir::Instruction in the block, or nullptr if at the beginning of the bloc...
bool hasNoNaNs() const
Determine whether the no-NaNs flag is set.
static LLVM_ABI IRBuilder & setInsertPos(InsertPosition Pos)
Helper function for create().
bool hasAllowReciprocal() const
Determine whether the allow-reciprocal flag is set.
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.
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
LLVM_ABI void setUnwindDest(BasicBlock *BB)
LLVM_ABI BasicBlock * getSuccessor(unsigned SuccIdx) const
static bool classof(const Value *From)
LLVM_ABI BasicBlock * getNormalDest() const
void setSuccessor(unsigned SuccIdx, BasicBlock *NewSucc)
LLVM_ABI LandingPadInst * getLandingPadInst() const
bool isFilter(unsigned Idx) const
Return 'true' if the clause and index Idx is a filter clause.
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
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.
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
LLVM_ABI Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
static bool classof(const Value *From)
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="")
unsigned getPointerAddressSpace() const
LLVM_ABI void setVolatile(bool V)
Specify whether this is a volatile load or not.
LLVM_ABI Value * getPointerOperand() const
Type * getPointerOperandType() const
bool isVolatile() const
Return true if this is a load from a volatile memory location.
static LLVM_ABI bool classof(const Value *From)
For isa/dyn_cast.
static bool classof(const sandboxir::Value *From)
LLVM_ABI Value * hasConstantValue() const
iterator_range< const_block_iterator > blocks() const
LLVM_ABI int getBasicBlockIndex(const BasicBlock *BB) const
const_block_iterator block_end() const
const_op_range incoming_values() const
bool hasConstantOrUndefValue() const
unsigned getNumIncomingValues() const
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
static LLVM_ABI PHINode * create(Type *Ty, unsigned NumReservedValues, InsertPosition Pos, Context &Ctx, const Twine &Name="")
mapped_iterator< llvm::PHINode::const_block_iterator, LLVMBBToBB > const_block_iterator
LLVM_ABI Value * removeIncomingValue(unsigned Idx)
LLVM_ABI void setIncomingValue(unsigned Idx, Value *V)
LLVM_ABI BasicBlock * getIncomingBlock(unsigned Idx) const
static unsigned getIncomingValueNumForOperand(unsigned Idx)
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)
An or instruction, which can be marked as "disjoint", indicating that the inputs don't have a 1 in th...
static bool classof(const Value *From)
For isa/dyn_cast.
Instruction that can have a nneg flag (zext/uitofp).
static bool classof(const Value *From)
For isa/dyn_cast.
static LLVM_ABI ResumeInst * create(Value *Exn, InsertPosition Pos, Context &Ctx)
unsigned getNumSuccessors() const
static bool classof(const Value *From)
LLVM_ABI Value * getValue() const
static LLVM_ABI ReturnInst * create(Value *RetVal, InsertPosition Pos, Context &Ctx)
static bool classof(const Value *From)
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.
static LLVM_ABI bool classof(const Value *From)
For isa/dyn_cast.
const Value * getFalseValue() const
const Value * getTrueValue() const
void setTrueValue(Value *New)
static LLVM_ABI Value * create(Value *Cond, Value *True, Value *False, InsertPosition Pos, Context &Ctx, const Twine &Name="")
void setCondition(Value *New)
const Value * getCondition() const
void setFalseValue(Value *New)
void getShuffleMask(SmallVectorImpl< int > &Result) const
Return the mask for this instruction as a vector of integers.
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...
bool isExtractSubvectorMask(int &Index) const
Return true if this shuffle mask is an extract subvector mask.
bool changesLength() const
Return true if this shuffle returns a vector with a different number of elements than its source vect...
bool isReverse() const
Return true if this shuffle swaps the order of elements from exactly one source vector.
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.
static bool isSingleSourceMask(const Constant *Mask, int NumSrcElts)
bool isIdentityWithExtract() const
Return true if this shuffle extracts the first N elements of exactly one source vector.
static bool isIdentityMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses elements from exactly one source vector without lane crossin...
ArrayRef< int > getShuffleMask() const
static bool isReverseMask(const Constant *Mask, int NumSrcElts)
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)
bool isInterleave(unsigned Factor) const
Return if this shuffle interleaves its two input vectors together.
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.
static bool isOneUseSingleSourceMask(ArrayRef< int > Mask, int VF)
Return true if this shuffle mask represents "clustered" mask of size VF, i.e.
static bool isTransposeMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask is a transpose mask.
static bool isTransposeMask(const Constant *Mask, int NumSrcElts)
static bool isInterleaveMask(ArrayRef< int > Mask, unsigned Factor, unsigned NumInputElts)
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...
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...
static bool isReplicationMask(const Constant *Mask, int &ReplicationFactor, int &VF)
static bool isIdentityMask(const Constant *Mask, int NumSrcElts)
static bool isDeInterleaveMaskOfFactor(ArrayRef< int > Mask, unsigned Factor)
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...
static bool isExtractSubvectorMask(ArrayRef< int > Mask, int NumSrcElts, int &Index)
Return true if this shuffle mask is an extract subvector mask.
bool isSplice(int &Index) const
Return true if this shuffle splices two inputs without changing the length of the vectors.
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.
static bool isSelectMask(const Constant *Mask, int NumSrcElts)
static bool isSpliceMask(const Constant *Mask, int NumSrcElts, int &Index)
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,...
bool isReplicationMask(int &ReplicationFactor, int &VF) const
Return true if this shuffle mask is a replication mask.
bool isConcat() const
Return true if this shuffle concatenates its 2 source vectors.
static bool isValidOperands(const Value *V1, const Value *V2, ArrayRef< int > Mask)
static bool isInsertSubvectorMask(const Constant *Mask, int NumSrcElts, int &NumSubElts, int &Index)
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...
static bool isSelectMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses elements from its source vectors without lane crossings.
static void commuteShuffleMask(MutableArrayRef< int > Mask, unsigned InVecNumElts)
Change values in a shuffle permute mask assuming the two vector operands of length InVecNumElts have ...
bool increasesLength() const
Return true if this shuffle returns a vector with a greater number of elements than its source vector...
bool isZeroEltSplat() const
Return true if all elements of this shuffle are the same value as the first element of exactly one so...
static bool isInsertSubvectorMask(ArrayRef< int > Mask, int NumSrcElts, int &NumSubElts, int &Index)
Return true if this shuffle mask is an insert subvector mask.
static void getShuffleMask(const Constant *Mask, SmallVectorImpl< int > &Result)
Convert the input shuffle mask operand to a vector of integers.
static bool isZeroEltSplatMask(const Constant *Mask, int NumSrcElts)
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.
static bool isSingleSourceMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses elements from exactly one source vector.
bool isOneUseSingleSourceMask(int VF) const
Return true if this shuffle mask is a one-use-single-source("clustered") mask.
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,...
int getMaskValue(unsigned Elt) const
Return the shuffle mask value of this instruction for the given element index.
bool isInsertSubvectorMask(int &NumSubElts, int &Index) const
Return true if this shuffle mask is an insert subvector mask.
bool isSelect() const
Return true if this shuffle chooses elements from its source vectors without lane crossings and all o...
bool isTranspose() const
Return true if this shuffle transposes the elements of its inputs without changing the length of the ...
static bool classof(const Value *From)
void dumpOS(raw_ostream &OS) const override
void verify() const final
Should crash if there is something wrong with the instruction.
unsigned getUseOperandNo(const Use &Use) const final
\Returns the operand index of Use.
unsigned getNumOfIRInstrs() const final
This is used by BasicBlock::iterator.
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.
unsigned getPointerAddressSpace() const
static StoreInst * create(Value *V, Value *Ptr, MaybeAlign Align, InsertPosition Pos, Context &Ctx)
static LLVM_ABI StoreInst * create(Value *V, Value *Ptr, MaybeAlign Align, InsertPosition Pos, bool IsVolatile, Context &Ctx)
Type * getPointerOperandType() const
LLVM_ABI Value * getPointerOperand() const
bool isVolatile() const
Return true if this is a store from a volatile memory location.
LLVM_ABI Value * getValueOperand() const
CaseHandleImpl(Context &Ctx, LLVMCaseItT LLVMCaseIt)
bool operator<(const CaseItImpl &Other) const
CaseItImpl & operator+=(ptrdiff_t N)
CaseItImpl & operator-=(ptrdiff_t N)
CaseItImpl(SwitchInst *SI, ptrdiff_t CaseNum)
bool operator==(const CaseItImpl &Other) const
CaseItImpl(Context &Ctx, LLVMCaseItT It)
const CaseHandleImpl< LLVMCaseItT, BlockT, ConstT > & operator*() const
ptrdiff_t operator-(const CaseItImpl &Other) const
CaseIt findCaseValue(const ConstantInt *C)
iterator_range< ConstCaseIt > cases() const
static LLVM_ABI SwitchInst * create(Value *V, BasicBlock *Dest, unsigned NumCases, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static constexpr unsigned DefaultPseudoIndex
CaseItImpl< llvm::SwitchInst::ConstCaseIt, const BasicBlock, const ConstantInt > ConstCaseIt
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.
LLVM_ABI void setDefaultDest(BasicBlock *DefaultCase)
iterator_range< CaseIt > cases()
Iteration adapter for range-for loops.
ConstCaseIt case_begin() const
bool defaultDestUnreachable() const
CaseHandleImpl< llvm::SwitchInst::ConstCaseIt, const BasicBlock, const ConstantInt > ConstCaseHandle
LLVM_ABI BasicBlock * getDefaultDest() const
ConstCaseIt case_end() const
CaseItImpl< llvm::SwitchInst::CaseIt, BasicBlock, ConstantInt > CaseIt
ConstCaseIt case_default() const
static bool classof(const Value *From)
LLVM_ABI Value * getCondition() const
LLVM_ABI void setSuccessor(unsigned Idx, BasicBlock *NewSucc)
unsigned getNumCases() const
unsigned getNumSuccessors() const
CaseIt case_end()
Returns a read/write iterator that points one past the last in the SwitchInst.
LLVM_ABI void setCondition(Value *V)
CaseHandleImpl< llvm::SwitchInst::CaseIt, BasicBlock, ConstantInt > CaseHandle
ConstCaseIt findCaseValue(const ConstantInt *C) const
LLVM_ABI ConstantInt * findCaseDest(BasicBlock *BB)
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:49
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition Type.h:302
static bool classof(const Instruction *I)
UnaryInstruction(ClassID ID, Opcode Opc, llvm::Instruction *LLVMI, Context &Ctx)
static bool classof(const Value *V)
static bool classof(const Value *From)
For isa/dyn_cast.
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 UncondBrInst * create(BasicBlock *Target, InsertPosition InsertBefore, Context &Ctx)
sb_succ_op_iterator< llvm::UncondBrInst > succ_op_iterator
LLVM_ABI BasicBlock * getSuccessor() const
unsigned getNumSuccessors() const
iterator_range< succ_op_iterator > successors()
static LLVM_ABI bool classof(const Value *From)
For isa/dyn_cast.
const_sb_succ_op_iterator< llvm::UncondBrInst > const_succ_op_iterator
iterator_range< const_succ_op_iterator > successors() const
LLVM_ABI void setSuccessor(BasicBlock *NewSucc)
static LLVM_ABI UnreachableInst * create(InsertPosition Pos, Context &Ctx)
unsigned getNumOfIRInstrs() const final
This is used by BasicBlock::iterator.
unsigned getUseOperandNo(const Use &Use) const final
\Returns the operand index of Use.
static LLVM_ABI bool classof(const Value *From)
Represents a Def-use/Use-def edge in SandboxIR.
Definition Use.h:43
LLVM_ABI void set(Value *V)
Definition Use.cpp:17
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
OperandUseIterator const_op_iterator
Definition User.h:99
virtual void setOperand(unsigned OperandIdx, Value *Operand)
Definition User.cpp:92
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
OperandUseIterator op_iterator
Definition User.h:98
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
iterator_range< const_op_iterator > const_op_range
Definition User.h:101
virtual op_iterator op_end()
Definition User.h:107
iterator_range< op_iterator > op_range
Definition User.h:100
User(ClassID ID, llvm::Value *V, Context &Ctx)
Definition User.h:61
LLVM_ABI Value * getPointerOperand()
static LLVM_ABI VAArgInst * create(Value *List, Type *Ty, InsertPosition Pos, Context &Ctx, const Twine &Name="")
const Value * getPointerOperand() const
static bool classof(const Value *From)
static unsigned getPointerOperandIndex()
A SandboxIR Value has users. This is the base class.
Definition Value.h:72
llvm::Value * Val
The LLVM Value that corresponds to this SandboxIR Value.
Definition Value.h:122
ClassID getSubclassID() const
Definition Value.h:213
void dumpCommonSuffix(raw_ostream &OS) const
Definition Value.cpp:143
Context & Ctx
All values point to the context.
Definition Value.h:201
ClassID SubclassID
For isa/dyn_cast.
Definition Value.h:113
LLVM_ABI Type * getType() const
Definition Value.cpp:46
friend class UncondBrInst
Definition Value.h:136
void dumpCommonPrefix(raw_ostream &OS) const
Definition Value.cpp:136
friend class CondBrInst
Definition Value.h:137
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ System
Synchronized with respect to all concurrently executing threads.
Definition LLVMContext.h:58
static bool isOrdered(Instruction *I)
Context & getContext() const
Definition BasicBlock.h:99
BasicBlock(llvm::BasicBlock *BB, Context &SBCtx)
Definition BasicBlock.h:75
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition BasicBlock.h:73
static BundleTy getOperand(BndlRef< Value * > Bndl, unsigned OpIdx)
Definition BundleVec.cpp:44
unsigned getLoadStoreAddressSpace(const Instruction *I)
A helper function that returns the address space of the pointer operand of load or store instruction.
Align getLoadStoreAlignment(const Value *I)
A helper function that returns the alignment of load or store instruction.
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
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:359
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ Other
Any other memory.
Definition ModRef.h:68
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1963
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:106