LLVM 23.0.0git
Instruction.h
Go to the documentation of this file.
1//===- Instruction.h --------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_SANDBOXIR_INSTRUCTION_H
10#define LLVM_SANDBOXIR_INSTRUCTION_H
11
12#include "llvm/IR/IRBuilder.h"
14#include "llvm/IR/Module.h"
18#include "llvm/SandboxIR/User.h"
20
21namespace llvm::sandboxir {
22
23// Forward declaration for MSVC.
24class IntrinsicInst;
25
27 BBIterator InsertAt;
28
29public:
30 InsertPosition(BasicBlock *InsertAtEnd) {
31 assert(InsertAtEnd != nullptr && "Expected non-null!");
32 InsertAt = InsertAtEnd->end();
33 }
34 InsertPosition(BBIterator InsertAt) : InsertAt(InsertAt) {}
35 operator BBIterator() { return InsertAt; }
36 const BBIterator &getIterator() const { return InsertAt; }
37 Instruction &operator*() { return *InsertAt; }
38 BasicBlock *getBasicBlock() const { return InsertAt.getNodeParent(); }
39};
40
41/// A sandboxir::User with operands, opcode and linked with previous/next
42/// instructions in an instruction list.
43class Instruction : public User {
44public:
45 enum class Opcode {
46#define OP(OPC) OPC,
47#define OPCODES(...) __VA_ARGS__
48#define DEF_INSTR(ID, OPC, CLASS) OPC
49#include "llvm/SandboxIR/Values.def"
50 };
51
52protected:
56
58
59 /// A SandboxIR Instruction may map to multiple LLVM IR Instruction. This
60 /// returns its topmost LLVM IR instruction.
62 friend class VAArgInst; // For getTopmostLLVMInstruction().
63 friend class FreezeInst; // For getTopmostLLVMInstruction().
64 friend class FenceInst; // For getTopmostLLVMInstruction().
65 friend class SelectInst; // For getTopmostLLVMInstruction().
66 friend class ExtractElementInst; // For getTopmostLLVMInstruction().
67 friend class InsertElementInst; // For getTopmostLLVMInstruction().
68 friend class ShuffleVectorInst; // For getTopmostLLVMInstruction().
69 friend class ExtractValueInst; // For getTopmostLLVMInstruction().
70 friend class InsertValueInst; // For getTopmostLLVMInstruction().
71 friend class LoadInst; // For getTopmostLLVMInstruction().
72 friend class StoreInst; // For getTopmostLLVMInstruction().
73 friend class ReturnInst; // For getTopmostLLVMInstruction().
74 friend class CallInst; // For getTopmostLLVMInstruction().
75 friend class InvokeInst; // For getTopmostLLVMInstruction().
76 friend class CallBrInst; // For getTopmostLLVMInstruction().
77 friend class LandingPadInst; // For getTopmostLLVMInstruction().
78 friend class CatchPadInst; // For getTopmostLLVMInstruction().
79 friend class CleanupPadInst; // For getTopmostLLVMInstruction().
80 friend class CatchReturnInst; // For getTopmostLLVMInstruction().
81 friend class CleanupReturnInst; // For getTopmostLLVMInstruction().
82 friend class GetElementPtrInst; // For getTopmostLLVMInstruction().
83 friend class ResumeInst; // For getTopmostLLVMInstruction().
84 friend class CatchSwitchInst; // For getTopmostLLVMInstruction().
85 friend class SwitchInst; // For getTopmostLLVMInstruction().
86 friend class UnaryOperator; // For getTopmostLLVMInstruction().
87 friend class BinaryOperator; // For getTopmostLLVMInstruction().
88 friend class AtomicRMWInst; // For getTopmostLLVMInstruction().
89 friend class AtomicCmpXchgInst; // For getTopmostLLVMInstruction().
90 friend class AllocaInst; // For getTopmostLLVMInstruction().
91 friend class CastInst; // For getTopmostLLVMInstruction().
92 friend class PHINode; // For getTopmostLLVMInstruction().
93 friend class UnreachableInst; // For getTopmostLLVMInstruction().
94 friend class CmpInst; // For getTopmostLLVMInstruction().
95
96 /// \Returns the LLVM IR Instructions that this SandboxIR maps to in program
97 /// order.
99 friend class EraseFromParent; // For getLLVMInstrs().
100
101 /// Helper function for create(). It sets the builder's insert position
102 /// according to \p Pos.
104 auto *WhereBB = Pos.getBasicBlock();
105 auto WhereIt = Pos.getIterator();
106 auto &Ctx = WhereBB->getContext();
107 auto &Builder = Ctx.getLLVMIRBuilder();
108 if (WhereIt != WhereBB->end())
109 Builder.SetInsertPoint((*Pos).getTopmostLLVMInstruction());
110 else
111 Builder.SetInsertPoint(cast<llvm::BasicBlock>(WhereBB->Val));
112 return Builder;
113 }
114
115public:
116 LLVM_ABI static const char *getOpcodeName(Opcode Opc);
117 /// This is used by BasicBlock::iterator.
118 virtual unsigned getNumOfIRInstrs() const = 0;
119 /// \Returns a BasicBlock::iterator for this Instruction.
120 LLVM_ABI BBIterator getIterator() const;
121 /// \Returns the next sandboxir::Instruction in the block, or nullptr if at
122 /// the end of the block.
124 /// \Returns the previous sandboxir::Instruction in the block, or nullptr if
125 /// at the beginning of the block.
127 /// \Returns this Instruction's opcode. Note that SandboxIR has its own opcode
128 /// state to allow for new SandboxIR-specific instructions.
129 Opcode getOpcode() const { return Opc; }
130
131 const char *getOpcodeName() const { return getOpcodeName(Opc); }
132
133 const DataLayout &getDataLayout() const {
134 return cast<llvm::Instruction>(Val)->getModule()->getDataLayout();
135 }
136 // Note that these functions below are calling into llvm::Instruction.
137 // A sandbox IR instruction could introduce a new opcode that could change the
138 // behavior of one of these functions. It is better that these functions are
139 // only added as needed and new sandbox IR instructions must explicitly check
140 // if any of these functions could have a different behavior.
141
142 bool isTerminator() const {
143 return cast<llvm::Instruction>(Val)->isTerminator();
144 }
145 bool isUnaryOp() const { return cast<llvm::Instruction>(Val)->isUnaryOp(); }
146 bool isBinaryOp() const { return cast<llvm::Instruction>(Val)->isBinaryOp(); }
147 bool isIntDivRem() const {
148 return cast<llvm::Instruction>(Val)->isIntDivRem();
149 }
150 bool isShift() const { return cast<llvm::Instruction>(Val)->isShift(); }
151 bool isCast() const { return cast<llvm::Instruction>(Val)->isCast(); }
152 bool isFuncletPad() const {
153 return cast<llvm::Instruction>(Val)->isFuncletPad();
154 }
155 bool isSpecialTerminator() const {
156 return cast<llvm::Instruction>(Val)->isSpecialTerminator();
157 }
159 return cast<llvm::Instruction>(Val)->isOnlyUserOfAnyOperand();
160 }
161 bool isLogicalShift() const {
162 return cast<llvm::Instruction>(Val)->isLogicalShift();
163 }
164
165 //===--------------------------------------------------------------------===//
166 // Metadata manipulation.
167 //===--------------------------------------------------------------------===//
168
169 /// Return true if the instruction has any metadata attached to it.
170 bool hasMetadata() const {
171 return cast<llvm::Instruction>(Val)->hasMetadata();
172 }
173
174 /// Return true if this instruction has metadata attached to it other than a
175 /// debug location.
177 return cast<llvm::Instruction>(Val)->hasMetadataOtherThanDebugLoc();
178 }
179
180 /// Return true if this instruction has the given type of metadata attached.
181 bool hasMetadata(unsigned KindID) const {
182 return cast<llvm::Instruction>(Val)->hasMetadata(KindID);
183 }
184
185 // TODO: Implement getMetadata and getAllMetadata after sandboxir::MDNode is
186 // available.
187
188 // TODO: More missing functions
189
190 /// Detach this from its parent BasicBlock without deleting it.
192 /// Detach this Value from its parent and delete it.
194 /// Insert this detached instruction before \p BeforeI.
195 LLVM_ABI void insertBefore(Instruction *BeforeI);
196 /// Insert this detached instruction after \p AfterI.
197 LLVM_ABI void insertAfter(Instruction *AfterI);
198 /// Insert this detached instruction into \p BB at \p WhereIt.
199 LLVM_ABI void insertInto(BasicBlock *BB, const BBIterator &WhereIt);
200 /// Move this instruction to \p WhereIt.
201 LLVM_ABI void moveBefore(BasicBlock &BB, const BBIterator &WhereIt);
202 /// Move this instruction before \p Before.
203 void moveBefore(Instruction *Before) {
204 moveBefore(*Before->getParent(), Before->getIterator());
205 }
206 /// Move this instruction after \p After.
207 void moveAfter(Instruction *After) {
208 moveBefore(*After->getParent(), std::next(After->getIterator()));
209 }
210 // TODO: This currently relies on LLVM IR Instruction::comesBefore which is
211 // can be linear-time.
212 /// Given an instruction Other in the same basic block as this instruction,
213 /// return true if this instruction comes before Other.
214 bool comesBefore(const Instruction *Other) const {
215 return cast<llvm::Instruction>(Val)->comesBefore(
217 }
218 /// \Returns the BasicBlock containing this Instruction, or null if it is
219 /// detached.
221 /// For isa/dyn_cast.
222 LLVM_ABI static bool classof(const sandboxir::Value *From);
223
224 /// Determine whether the no signed wrap flag is set.
225 bool hasNoUnsignedWrap() const {
226 return cast<llvm::Instruction>(Val)->hasNoUnsignedWrap();
227 }
228 /// Set or clear the nuw flag on this instruction, which must be an operator
229 /// which supports this flag. See LangRef.html for the meaning of this flag.
230 LLVM_ABI void setHasNoUnsignedWrap(bool B = true);
231 /// Determine whether the no signed wrap flag is set.
232 bool hasNoSignedWrap() const {
233 return cast<llvm::Instruction>(Val)->hasNoSignedWrap();
234 }
235 /// Set or clear the nsw flag on this instruction, which must be an operator
236 /// which supports this flag. See LangRef.html for the meaning of this flag.
237 LLVM_ABI void setHasNoSignedWrap(bool B = true);
238 /// Determine whether all fast-math-flags are set.
239 bool isFast() const { return cast<llvm::Instruction>(Val)->isFast(); }
240 /// Set or clear all fast-math-flags on this instruction, which must be an
241 /// operator which supports this flag. See LangRef.html for the meaning of
242 /// this flag.
243 LLVM_ABI void setFast(bool B);
244 /// Determine whether the allow-reassociation flag is set.
245 bool hasAllowReassoc() const {
246 return cast<llvm::Instruction>(Val)->hasAllowReassoc();
247 }
248 /// Set or clear the reassociation flag on this instruction, which must be
249 /// an operator which supports this flag. See LangRef.html for the meaning of
250 /// this flag.
251 LLVM_ABI void setHasAllowReassoc(bool B);
252 /// Determine whether the exact flag is set.
253 bool isExact() const { return cast<llvm::Instruction>(Val)->isExact(); }
254 /// Set or clear the exact flag on this instruction, which must be an operator
255 /// which supports this flag. See LangRef.html for the meaning of this flag.
256 LLVM_ABI void setIsExact(bool B = true);
257 /// Determine whether the no-NaNs flag is set.
258 bool hasNoNaNs() const { return cast<llvm::Instruction>(Val)->hasNoNaNs(); }
259 /// Set or clear the no-nans flag on this instruction, which must be an
260 /// operator which supports this flag. See LangRef.html for the meaning of
261 /// this flag.
262 LLVM_ABI void setHasNoNaNs(bool B);
263 /// Determine whether the no-infs flag is set.
264 bool hasNoInfs() const { return cast<llvm::Instruction>(Val)->hasNoInfs(); }
265 /// Set or clear the no-infs flag on this instruction, which must be an
266 /// operator which supports this flag. See LangRef.html for the meaning of
267 /// this flag.
268 LLVM_ABI void setHasNoInfs(bool B);
269 /// Determine whether the no-signed-zeros flag is set.
270 bool hasNoSignedZeros() const {
271 return cast<llvm::Instruction>(Val)->hasNoSignedZeros();
272 }
273 /// Set or clear the no-signed-zeros flag on this instruction, which must be
274 /// an operator which supports this flag. See LangRef.html for the meaning of
275 /// this flag.
276 LLVM_ABI void setHasNoSignedZeros(bool B);
277 /// Determine whether the allow-reciprocal flag is set.
278 bool hasAllowReciprocal() const {
279 return cast<llvm::Instruction>(Val)->hasAllowReciprocal();
280 }
281 /// Set or clear the allow-reciprocal flag on this instruction, which must be
282 /// an operator which supports this flag. See LangRef.html for the meaning of
283 /// this flag.
285 /// Determine whether the allow-contract flag is set.
286 bool hasAllowContract() const {
287 return cast<llvm::Instruction>(Val)->hasAllowContract();
288 }
289 /// Set or clear the allow-contract flag on this instruction, which must be
290 /// an operator which supports this flag. See LangRef.html for the meaning of
291 /// this flag.
292 LLVM_ABI void setHasAllowContract(bool B);
293 /// Determine whether the approximate-math-functions flag is set.
294 bool hasApproxFunc() const {
295 return cast<llvm::Instruction>(Val)->hasApproxFunc();
296 }
297 /// Set or clear the approximate-math-functions flag on this instruction,
298 /// which must be an operator which supports this flag. See LangRef.html for
299 /// the meaning of this flag.
300 LLVM_ABI void setHasApproxFunc(bool B);
301 /// Convenience function for getting all the fast-math flags, which must be an
302 /// operator which supports these flags. See LangRef.html for the meaning of
303 /// these flags.
305 return cast<llvm::Instruction>(Val)->getFastMathFlags();
306 }
307 /// Convenience function for setting multiple fast-math flags on this
308 /// instruction, which must be an operator which supports these flags. See
309 /// LangRef.html for the meaning of these flags.
311 /// Convenience function for transferring all fast-math flag values to this
312 /// instruction, which must be an operator which supports these flags. See
313 /// LangRef.html for the meaning of these flags.
315
316 bool isAssociative() const {
317 return cast<llvm::Instruction>(Val)->isAssociative();
318 }
319
320 bool isCommutative() const {
321 return cast<llvm::Instruction>(Val)->isCommutative();
322 }
323
324 bool isIdempotent() const {
325 return cast<llvm::Instruction>(Val)->isIdempotent();
326 }
327
328 bool isNilpotent() const {
329 return cast<llvm::Instruction>(Val)->isNilpotent();
330 }
331
332 bool mayWriteToMemory() const {
333 return cast<llvm::Instruction>(Val)->mayWriteToMemory();
334 }
335
336 bool mayReadFromMemory() const {
337 return cast<llvm::Instruction>(Val)->mayReadFromMemory();
338 }
339 bool mayReadOrWriteMemory() const {
340 return cast<llvm::Instruction>(Val)->mayReadOrWriteMemory();
341 }
342
343 bool isAtomic() const { return cast<llvm::Instruction>(Val)->isAtomic(); }
344
345 bool hasAtomicLoad() const {
346 return cast<llvm::Instruction>(Val)->hasAtomicLoad();
347 }
348
349 bool hasAtomicStore() const {
350 return cast<llvm::Instruction>(Val)->hasAtomicStore();
351 }
352
353 bool isVolatile() const { return cast<llvm::Instruction>(Val)->isVolatile(); }
354
355 LLVM_ABI Type *getAccessType() const;
356
357 bool mayThrow(bool IncludePhaseOneUnwind = false) const {
358 return cast<llvm::Instruction>(Val)->mayThrow(IncludePhaseOneUnwind);
359 }
360
361 bool isFenceLike() const {
362 return cast<llvm::Instruction>(Val)->isFenceLike();
363 }
364
365 bool mayHaveSideEffects() const {
366 return cast<llvm::Instruction>(Val)->mayHaveSideEffects();
367 }
368
369 // TODO: Missing functions.
370
371#ifndef NDEBUG
372 void dumpOS(raw_ostream &OS) const override;
373#endif
374};
375
376/// Instructions that contain a single LLVM Instruction can inherit from this.
377template <typename LLVMT> class SingleLLVMInstructionImpl : public Instruction {
378 SingleLLVMInstructionImpl(ClassID ID, Opcode Opc, llvm::Instruction *I,
379 sandboxir::Context &SBCtx)
380 : Instruction(ID, Opc, I, SBCtx) {}
381
382 // All instructions are friends with this so they can call the constructor.
383#define DEF_INSTR(ID, OPC, CLASS) friend class CLASS;
384#include "llvm/SandboxIR/Values.def"
385 friend class UnaryInstruction;
386 friend class CallBase;
387 friend class FuncletPadInst;
388 friend class CmpInst;
389
390 Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
392 }
395 }
396
397public:
398 unsigned getUseOperandNo(const Use &Use) const final {
400 }
401 unsigned getNumOfIRInstrs() const final { return 1u; }
402#ifndef NDEBUG
403 void verify() const final { assert(isa<LLVMT>(Val) && "Expected LLVMT!"); }
404 void dumpOS(raw_ostream &OS) const override {
407 }
408#endif
409};
410
411class FenceInst : public SingleLLVMInstructionImpl<llvm::FenceInst> {
412 FenceInst(llvm::FenceInst *FI, Context &Ctx)
413 : SingleLLVMInstructionImpl(ClassID::Fence, Opcode::Fence, FI, Ctx) {}
414 friend Context; // For constructor;
415
416public:
417 LLVM_ABI static FenceInst *create(AtomicOrdering Ordering, InsertPosition Pos,
418 Context &Ctx,
420 /// Returns the ordering constraint of this fence instruction.
422 return cast<llvm::FenceInst>(Val)->getOrdering();
423 }
424 /// Sets the ordering constraint of this fence instruction. May only be
425 /// Acquire, Release, AcquireRelease, or SequentiallyConsistent.
426 LLVM_ABI void setOrdering(AtomicOrdering Ordering);
427 /// Returns the synchronization scope ID of this fence instruction.
429 return cast<llvm::FenceInst>(Val)->getSyncScopeID();
430 }
431 /// Sets the synchronization scope ID of this fence instruction.
433 static bool classof(const Value *From) {
434 return From->getSubclassID() == ClassID::Fence;
435 }
436};
437
438class SelectInst : public SingleLLVMInstructionImpl<llvm::SelectInst> {
439 /// Use Context::createSelectInst(). Don't call the
440 /// constructor directly.
441 SelectInst(llvm::SelectInst *CI, Context &Ctx)
442 : SingleLLVMInstructionImpl(ClassID::Select, Opcode::Select, CI, Ctx) {}
443 friend Context; // for SelectInst()
444
445public:
446 LLVM_ABI static Value *create(Value *Cond, Value *True, Value *False,
447 InsertPosition Pos, Context &Ctx,
448 const Twine &Name = "");
449
450 const Value *getCondition() const { return getOperand(0); }
451 const Value *getTrueValue() const { return getOperand(1); }
452 const Value *getFalseValue() const { return getOperand(2); }
453 Value *getCondition() { return getOperand(0); }
454 Value *getTrueValue() { return getOperand(1); }
456
457 void setCondition(Value *New) { setOperand(0, New); }
458 void setTrueValue(Value *New) { setOperand(1, New); }
459 void setFalseValue(Value *New) { setOperand(2, New); }
460 LLVM_ABI void swapValues();
461
462 /// Return a string if the specified operands are invalid for a select
463 /// operation, otherwise return null.
464 static const char *areInvalidOperands(Value *Cond, Value *True,
465 Value *False) {
467 False->Val);
468 }
469
470 /// For isa/dyn_cast.
471 LLVM_ABI static bool classof(const Value *From);
472};
473
474class InsertElementInst final
475 : public SingleLLVMInstructionImpl<llvm::InsertElementInst> {
476 /// Use Context::createInsertElementInst() instead.
478 : SingleLLVMInstructionImpl(ClassID::InsertElement, Opcode::InsertElement,
479 I, Ctx) {}
480 friend class Context; // For accessing the constructor in create*()
481
482public:
483 LLVM_ABI static Value *create(Value *Vec, Value *NewElt, Value *Idx,
485 const Twine &Name = "");
486 static bool classof(const Value *From) {
487 return From->getSubclassID() == ClassID::InsertElement;
488 }
489 static bool isValidOperands(const Value *Vec, const Value *NewElt,
490 const Value *Idx) {
492 Idx->Val);
493 }
494};
495
496class ExtractElementInst final
497 : public SingleLLVMInstructionImpl<llvm::ExtractElementInst> {
498 /// Use Context::createExtractElementInst() instead.
500 : SingleLLVMInstructionImpl(ClassID::ExtractElement,
501 Opcode::ExtractElement, I, Ctx) {}
502 friend class Context; // For accessing the constructor in
503 // create*()
504
505public:
506 LLVM_ABI static Value *create(Value *Vec, Value *Idx, InsertPosition Pos,
507 Context &Ctx, const Twine &Name = "");
508 static bool classof(const Value *From) {
509 return From->getSubclassID() == ClassID::ExtractElement;
510 }
511
512 static bool isValidOperands(const Value *Vec, const Value *Idx) {
514 }
517 const Value *getVectorOperand() const { return getOperand(0); }
518 const Value *getIndexOperand() const { return getOperand(1); }
520};
521
522class ShuffleVectorInst final
523 : public SingleLLVMInstructionImpl<llvm::ShuffleVectorInst> {
524 /// Use Context::createShuffleVectorInst() instead.
526 : SingleLLVMInstructionImpl(ClassID::ShuffleVector, Opcode::ShuffleVector,
527 I, Ctx) {}
528 friend class Context; // For accessing the constructor in create*()
529
530public:
531 LLVM_ABI static Value *create(Value *V1, Value *V2, Value *Mask,
533 const Twine &Name = "");
534 LLVM_ABI static Value *create(Value *V1, Value *V2, ArrayRef<int> Mask,
536 const Twine &Name = "");
537 static bool classof(const Value *From) {
538 return From->getSubclassID() == ClassID::ShuffleVector;
539 }
540
541 /// Swap the operands and adjust the mask to preserve the semantics of the
542 /// instruction.
543 LLVM_ABI void commute();
544
545 /// Return true if a shufflevector instruction can be formed with the
546 /// specified operands.
547 static bool isValidOperands(const Value *V1, const Value *V2,
548 const Value *Mask) {
550 Mask->Val);
551 }
552 static bool isValidOperands(const Value *V1, const Value *V2,
553 ArrayRef<int> Mask) {
554 return llvm::ShuffleVectorInst::isValidOperands(V1->Val, V2->Val, Mask);
555 }
556
557 /// Overload to return most specific vector type.
558 LLVM_ABI VectorType *getType() const;
559
560 /// Return the shuffle mask value of this instruction for the given element
561 /// index. Return PoisonMaskElem if the element is undef.
562 int getMaskValue(unsigned Elt) const {
563 return cast<llvm::ShuffleVectorInst>(Val)->getMaskValue(Elt);
564 }
565
566 /// Convert the input shuffle mask operand to a vector of integers. Undefined
567 /// elements of the mask are returned as PoisonMaskElem.
568 static void getShuffleMask(const Constant *Mask,
569 SmallVectorImpl<int> &Result) {
571 Result);
572 }
573
574 /// Return the mask for this instruction as a vector of integers. Undefined
575 /// elements of the mask are returned as PoisonMaskElem.
577 cast<llvm::ShuffleVectorInst>(Val)->getShuffleMask(Result);
578 }
579
580 /// Return the mask for this instruction, for use in bitcode.
582
584 Type *ResultTy);
585
587
589 return cast<llvm::ShuffleVectorInst>(Val)->getShuffleMask();
590 }
591
592 /// Return true if this shuffle returns a vector with a different number of
593 /// elements than its source vectors.
594 /// Examples: shufflevector <4 x n> A, <4 x n> B, <1,2,3>
595 /// shufflevector <4 x n> A, <4 x n> B, <1,2,3,4,5>
596 bool changesLength() const {
597 return cast<llvm::ShuffleVectorInst>(Val)->changesLength();
598 }
599
600 /// Return true if this shuffle returns a vector with a greater number of
601 /// elements than its source vectors.
602 /// Example: shufflevector <2 x n> A, <2 x n> B, <1,2,3>
603 bool increasesLength() const {
604 return cast<llvm::ShuffleVectorInst>(Val)->increasesLength();
605 }
606
607 /// Return true if this shuffle mask chooses elements from exactly one source
608 /// vector.
609 /// Example: <7,5,undef,7>
610 /// This assumes that vector operands (of length \p NumSrcElts) are the same
611 /// length as the mask.
612 static bool isSingleSourceMask(ArrayRef<int> Mask, int NumSrcElts) {
613 return llvm::ShuffleVectorInst::isSingleSourceMask(Mask, NumSrcElts);
614 }
615 static bool isSingleSourceMask(const Constant *Mask, int NumSrcElts) {
617 cast<llvm::Constant>(Mask->Val), NumSrcElts);
618 }
619
620 /// Return true if this shuffle chooses elements from exactly one source
621 /// vector without changing the length of that vector.
622 /// Example: shufflevector <4 x n> A, <4 x n> B, <3,0,undef,3>
623 bool isSingleSource() const {
624 return cast<llvm::ShuffleVectorInst>(Val)->isSingleSource();
625 }
626
627 /// Return true if this shuffle mask chooses elements from exactly one source
628 /// vector without lane crossings. A shuffle using this mask is not
629 /// necessarily a no-op because it may change the number of elements from its
630 /// input vectors or it may provide demanded bits knowledge via undef lanes.
631 /// Example: <undef,undef,2,3>
632 static bool isIdentityMask(ArrayRef<int> Mask, int NumSrcElts) {
633 return llvm::ShuffleVectorInst::isIdentityMask(Mask, NumSrcElts);
634 }
635 static bool isIdentityMask(const Constant *Mask, int NumSrcElts) {
637 cast<llvm::Constant>(Mask->Val), NumSrcElts);
638 }
639
640 /// Return true if this shuffle chooses elements from exactly one source
641 /// vector without lane crossings and does not change the number of elements
642 /// from its input vectors.
643 /// Example: shufflevector <4 x n> A, <4 x n> B, <4,undef,6,undef>
644 bool isIdentity() const {
645 return cast<llvm::ShuffleVectorInst>(Val)->isIdentity();
646 }
647
648 /// Return true if this shuffle lengthens exactly one source vector with
649 /// undefs in the high elements.
651 return cast<llvm::ShuffleVectorInst>(Val)->isIdentityWithPadding();
652 }
653
654 /// Return true if this shuffle extracts the first N elements of exactly one
655 /// source vector.
657 return cast<llvm::ShuffleVectorInst>(Val)->isIdentityWithExtract();
658 }
659
660 /// Return true if this shuffle concatenates its 2 source vectors. This
661 /// returns false if either input is undefined. In that case, the shuffle is
662 /// is better classified as an identity with padding operation.
663 bool isConcat() const {
664 return cast<llvm::ShuffleVectorInst>(Val)->isConcat();
665 }
666
667 /// Return true if this shuffle mask chooses elements from its source vectors
668 /// without lane crossings. A shuffle using this mask would be
669 /// equivalent to a vector select with a constant condition operand.
670 /// Example: <4,1,6,undef>
671 /// This returns false if the mask does not choose from both input vectors.
672 /// In that case, the shuffle is better classified as an identity shuffle.
673 /// This assumes that vector operands are the same length as the mask
674 /// (a length-changing shuffle can never be equivalent to a vector select).
675 static bool isSelectMask(ArrayRef<int> Mask, int NumSrcElts) {
676 return llvm::ShuffleVectorInst::isSelectMask(Mask, NumSrcElts);
677 }
678 static bool isSelectMask(const Constant *Mask, int NumSrcElts) {
680 cast<llvm::Constant>(Mask->Val), NumSrcElts);
681 }
682
683 /// Return true if this shuffle chooses elements from its source vectors
684 /// without lane crossings and all operands have the same number of elements.
685 /// In other words, this shuffle is equivalent to a vector select with a
686 /// constant condition operand.
687 /// Example: shufflevector <4 x n> A, <4 x n> B, <undef,1,6,3>
688 /// This returns false if the mask does not choose from both input vectors.
689 /// In that case, the shuffle is better classified as an identity shuffle.
690 bool isSelect() const {
691 return cast<llvm::ShuffleVectorInst>(Val)->isSelect();
692 }
693
694 /// Return true if this shuffle mask swaps the order of elements from exactly
695 /// one source vector.
696 /// Example: <7,6,undef,4>
697 /// This assumes that vector operands (of length \p NumSrcElts) are the same
698 /// length as the mask.
699 static bool isReverseMask(ArrayRef<int> Mask, int NumSrcElts) {
700 return llvm::ShuffleVectorInst::isReverseMask(Mask, NumSrcElts);
701 }
702 static bool isReverseMask(const Constant *Mask, int NumSrcElts) {
704 cast<llvm::Constant>(Mask->Val), NumSrcElts);
705 }
706
707 /// Return true if this shuffle swaps the order of elements from exactly
708 /// one source vector.
709 /// Example: shufflevector <4 x n> A, <4 x n> B, <3,undef,1,undef>
710 bool isReverse() const {
711 return cast<llvm::ShuffleVectorInst>(Val)->isReverse();
712 }
713
714 /// Return true if this shuffle mask chooses all elements with the same value
715 /// as the first element of exactly one source vector.
716 /// Example: <4,undef,undef,4>
717 /// This assumes that vector operands (of length \p NumSrcElts) are the same
718 /// length as the mask.
719 static bool isZeroEltSplatMask(ArrayRef<int> Mask, int NumSrcElts) {
720 return llvm::ShuffleVectorInst::isZeroEltSplatMask(Mask, NumSrcElts);
721 }
722 static bool isZeroEltSplatMask(const Constant *Mask, int NumSrcElts) {
724 cast<llvm::Constant>(Mask->Val), NumSrcElts);
725 }
726
727 /// Return true if all elements of this shuffle are the same value as the
728 /// first element of exactly one source vector without changing the length
729 /// of that vector.
730 /// Example: shufflevector <4 x n> A, <4 x n> B, <undef,0,undef,0>
731 bool isZeroEltSplat() const {
732 return cast<llvm::ShuffleVectorInst>(Val)->isZeroEltSplat();
733 }
734
735 /// Return true if this shuffle mask is a transpose mask.
736 /// Transpose vector masks transpose a 2xn matrix. They read corresponding
737 /// even- or odd-numbered vector elements from two n-dimensional source
738 /// vectors and write each result into consecutive elements of an
739 /// n-dimensional destination vector. Two shuffles are necessary to complete
740 /// the transpose, one for the even elements and another for the odd elements.
741 /// This description closely follows how the TRN1 and TRN2 AArch64
742 /// instructions operate.
743 ///
744 /// For example, a simple 2x2 matrix can be transposed with:
745 ///
746 /// ; Original matrix
747 /// m0 = < a, b >
748 /// m1 = < c, d >
749 ///
750 /// ; Transposed matrix
751 /// t0 = < a, c > = shufflevector m0, m1, < 0, 2 >
752 /// t1 = < b, d > = shufflevector m0, m1, < 1, 3 >
753 ///
754 /// For matrices having greater than n columns, the resulting nx2 transposed
755 /// matrix is stored in two result vectors such that one vector contains
756 /// interleaved elements from all the even-numbered rows and the other vector
757 /// contains interleaved elements from all the odd-numbered rows. For example,
758 /// a 2x4 matrix can be transposed with:
759 ///
760 /// ; Original matrix
761 /// m0 = < a, b, c, d >
762 /// m1 = < e, f, g, h >
763 ///
764 /// ; Transposed matrix
765 /// t0 = < a, e, c, g > = shufflevector m0, m1 < 0, 4, 2, 6 >
766 /// t1 = < b, f, d, h > = shufflevector m0, m1 < 1, 5, 3, 7 >
767 static bool isTransposeMask(ArrayRef<int> Mask, int NumSrcElts) {
768 return llvm::ShuffleVectorInst::isTransposeMask(Mask, NumSrcElts);
769 }
770 static bool isTransposeMask(const Constant *Mask, int NumSrcElts) {
772 cast<llvm::Constant>(Mask->Val), NumSrcElts);
773 }
774
775 /// Return true if this shuffle transposes the elements of its inputs without
776 /// changing the length of the vectors. This operation may also be known as a
777 /// merge or interleave. See the description for isTransposeMask() for the
778 /// exact specification.
779 /// Example: shufflevector <4 x n> A, <4 x n> B, <0,4,2,6>
780 bool isTranspose() const {
781 return cast<llvm::ShuffleVectorInst>(Val)->isTranspose();
782 }
783
784 /// Return true if this shuffle mask is a splice mask, concatenating the two
785 /// inputs together and then extracts an original width vector starting from
786 /// the splice index.
787 /// Example: shufflevector <4 x n> A, <4 x n> B, <1,2,3,4>
788 /// This assumes that vector operands (of length \p NumSrcElts) are the same
789 /// length as the mask.
790 static bool isSpliceMask(ArrayRef<int> Mask, int NumSrcElts, int &Index) {
791 return llvm::ShuffleVectorInst::isSpliceMask(Mask, NumSrcElts, Index);
792 }
793 static bool isSpliceMask(const Constant *Mask, int NumSrcElts, int &Index) {
795 cast<llvm::Constant>(Mask->Val), NumSrcElts, Index);
796 }
797
798 /// Return true if this shuffle splices two inputs without changing the length
799 /// of the vectors. This operation concatenates the two inputs together and
800 /// then extracts an original width vector starting from the splice index.
801 /// Example: shufflevector <4 x n> A, <4 x n> B, <1,2,3,4>
802 bool isSplice(int &Index) const {
803 return cast<llvm::ShuffleVectorInst>(Val)->isSplice(Index);
804 }
805
806 /// Return true if this shuffle mask is an extract subvector mask.
807 /// A valid extract subvector mask returns a smaller vector from a single
808 /// source operand. The base extraction index is returned as well.
809 static bool isExtractSubvectorMask(ArrayRef<int> Mask, int NumSrcElts,
810 int &Index) {
812 Index);
813 }
814 static bool isExtractSubvectorMask(const Constant *Mask, int NumSrcElts,
815 int &Index) {
817 cast<llvm::Constant>(Mask->Val), NumSrcElts, Index);
818 }
819
820 /// Return true if this shuffle mask is an extract subvector mask.
821 bool isExtractSubvectorMask(int &Index) const {
822 return cast<llvm::ShuffleVectorInst>(Val)->isExtractSubvectorMask(Index);
823 }
824
825 /// Return true if this shuffle mask is an insert subvector mask.
826 /// A valid insert subvector mask inserts the lowest elements of a second
827 /// source operand into an in-place first source operand.
828 /// Both the sub vector width and the insertion index is returned.
829 static bool isInsertSubvectorMask(ArrayRef<int> Mask, int NumSrcElts,
830 int &NumSubElts, int &Index) {
832 NumSubElts, Index);
833 }
834 static bool isInsertSubvectorMask(const Constant *Mask, int NumSrcElts,
835 int &NumSubElts, int &Index) {
837 cast<llvm::Constant>(Mask->Val), NumSrcElts, NumSubElts, Index);
838 }
839
840 /// Return true if this shuffle mask is an insert subvector mask.
841 bool isInsertSubvectorMask(int &NumSubElts, int &Index) const {
842 return cast<llvm::ShuffleVectorInst>(Val)->isInsertSubvectorMask(NumSubElts,
843 Index);
844 }
845
846 /// Return true if this shuffle mask replicates each of the \p VF elements
847 /// in a vector \p ReplicationFactor times.
848 /// For example, the mask for \p ReplicationFactor=3 and \p VF=4 is:
849 /// <0,0,0,1,1,1,2,2,2,3,3,3>
850 static bool isReplicationMask(ArrayRef<int> Mask, int &ReplicationFactor,
851 int &VF) {
852 return llvm::ShuffleVectorInst::isReplicationMask(Mask, ReplicationFactor,
853 VF);
854 }
855 static bool isReplicationMask(const Constant *Mask, int &ReplicationFactor,
856 int &VF) {
858 cast<llvm::Constant>(Mask->Val), ReplicationFactor, VF);
859 }
860
861 /// Return true if this shuffle mask is a replication mask.
862 bool isReplicationMask(int &ReplicationFactor, int &VF) const {
863 return cast<llvm::ShuffleVectorInst>(Val)->isReplicationMask(
864 ReplicationFactor, VF);
865 }
866
867 /// Return true if this shuffle mask represents "clustered" mask of size VF,
868 /// i.e. each index between [0..VF) is used exactly once in each submask of
869 /// size VF.
870 /// For example, the mask for \p VF=4 is:
871 /// 0, 1, 2, 3, 3, 2, 0, 1 - "clustered", because each submask of size 4
872 /// (0,1,2,3 and 3,2,0,1) uses indices [0..VF) exactly one time.
873 /// 0, 1, 2, 3, 3, 3, 1, 0 - not "clustered", because
874 /// element 3 is used twice in the second submask
875 /// (3,3,1,0) and index 2 is not used at all.
876 static bool isOneUseSingleSourceMask(ArrayRef<int> Mask, int VF) {
878 }
879
880 /// Return true if this shuffle mask is a one-use-single-source("clustered")
881 /// mask.
882 bool isOneUseSingleSourceMask(int VF) const {
883 return cast<llvm::ShuffleVectorInst>(Val)->isOneUseSingleSourceMask(VF);
884 }
885
886 /// Change values in a shuffle permute mask assuming the two vector operands
887 /// of length InVecNumElts have swapped position.
889 unsigned InVecNumElts) {
891 }
892
893 /// Return if this shuffle interleaves its two input vectors together.
894 bool isInterleave(unsigned Factor) const {
895 return cast<llvm::ShuffleVectorInst>(Val)->isInterleave(Factor);
896 }
897
898 /// Return true if the mask interleaves one or more input vectors together.
899 ///
900 /// I.e. <0, LaneLen, ... , LaneLen*(Factor - 1), 1, LaneLen + 1, ...>
901 /// E.g. For a Factor of 2 (LaneLen=4):
902 /// <0, 4, 1, 5, 2, 6, 3, 7>
903 /// E.g. For a Factor of 3 (LaneLen=4):
904 /// <4, 0, 9, 5, 1, 10, 6, 2, 11, 7, 3, 12>
905 /// E.g. For a Factor of 4 (LaneLen=2):
906 /// <0, 2, 6, 4, 1, 3, 7, 5>
907 ///
908 /// NumInputElts is the total number of elements in the input vectors.
909 ///
910 /// StartIndexes are the first indexes of each vector being interleaved,
911 /// substituting any indexes that were undef
912 /// E.g. <4, -1, 2, 5, 1, 3> (Factor=3): StartIndexes=<4, 0, 2>
913 ///
914 /// Note that this does not check if the input vectors are consecutive:
915 /// It will return true for masks such as
916 /// <0, 4, 6, 1, 5, 7> (Factor=3, LaneLen=2)
917 static bool isInterleaveMask(ArrayRef<int> Mask, unsigned Factor,
918 unsigned NumInputElts,
919 SmallVectorImpl<unsigned> &StartIndexes) {
920 return llvm::ShuffleVectorInst::isInterleaveMask(Mask, Factor, NumInputElts,
921 StartIndexes);
922 }
923 static bool isInterleaveMask(ArrayRef<int> Mask, unsigned Factor,
924 unsigned NumInputElts) {
926 NumInputElts);
927 }
928
929 /// Check if the mask is a DE-interleave mask of the given factor
930 /// \p Factor like:
931 /// <Index, Index+Factor, ..., Index+(NumElts-1)*Factor>
932 static bool isDeInterleaveMaskOfFactor(ArrayRef<int> Mask, unsigned Factor,
933 unsigned &Index) {
935 Index);
936 }
937 static bool isDeInterleaveMaskOfFactor(ArrayRef<int> Mask, unsigned Factor) {
939 }
940
941 /// Checks if the shuffle is a bit rotation of the first operand across
942 /// multiple subelements, e.g:
943 ///
944 /// shuffle <8 x i8> %a, <8 x i8> poison, <8 x i32> <1, 0, 3, 2, 5, 4, 7, 6>
945 ///
946 /// could be expressed as
947 ///
948 /// rotl <4 x i16> %a, 8
949 ///
950 /// If it can be expressed as a rotation, returns the number of subelements to
951 /// group by in NumSubElts and the number of bits to rotate left in RotateAmt.
952 static bool isBitRotateMask(ArrayRef<int> Mask, unsigned EltSizeInBits,
953 unsigned MinSubElts, unsigned MaxSubElts,
954 unsigned &NumSubElts, unsigned &RotateAmt) {
956 Mask, EltSizeInBits, MinSubElts, MaxSubElts, NumSubElts, RotateAmt);
957 }
958};
959
960class InsertValueInst
961 : public SingleLLVMInstructionImpl<llvm::InsertValueInst> {
962 /// Use Context::createInsertValueInst(). Don't call the constructor directly.
964 : SingleLLVMInstructionImpl(ClassID::InsertValue, Opcode::InsertValue,
965 IVI, Ctx) {}
966 friend Context; // for InsertValueInst()
967
968public:
970 InsertPosition Pos, Context &Ctx,
971 const Twine &Name = "");
972
973 static bool classof(const Value *From) {
974 return From->getSubclassID() == ClassID::InsertValue;
975 }
976
978 inline idx_iterator idx_begin() const {
979 return cast<llvm::InsertValueInst>(Val)->idx_begin();
980 }
981 inline idx_iterator idx_end() const {
982 return cast<llvm::InsertValueInst>(Val)->idx_end();
983 }
985 return cast<llvm::InsertValueInst>(Val)->indices();
986 }
987
991 const Value *getAggregateOperand() const {
993 }
997
1007
1009 return cast<llvm::InsertValueInst>(Val)->getIndices();
1010 }
1011
1012 unsigned getNumIndices() const {
1013 return cast<llvm::InsertValueInst>(Val)->getNumIndices();
1014 }
1015
1016 unsigned hasIndices() const {
1017 return cast<llvm::InsertValueInst>(Val)->hasIndices();
1018 }
1019};
1020
1021/// Both UncondBrInst and CondBrInst inherit from this to avoid duplication of
1022/// the successor iterators and successors(). Does not hold any state.
1024private:
1025 struct LLVMBBToSBBB {
1026 Context &Ctx;
1027 LLVMBBToSBBB(Context &Ctx) : Ctx(Ctx) {}
1028 LLVM_ABI BasicBlock *operator()(llvm::BasicBlock *BB) const;
1029 };
1030
1031 struct ConstLLVMBBToSBBB {
1032 Context &Ctx;
1033 ConstLLVMBBToSBBB(Context &Ctx) : Ctx(Ctx) {}
1034 LLVM_ABI const BasicBlock *operator()(const llvm::BasicBlock *BB) const;
1035 };
1036
1037protected:
1038 template <typename LLVMBrTy>
1041 template <typename LLVMBrTy>
1043 Context &Ctx) {
1045 cast<LLVMBrTy>(Val)->successors();
1046 LLVMBBToSBBB BBMap(Ctx);
1047 sb_succ_op_iterator<LLVMBrTy> MappedBegin =
1048 map_iterator(LLVMRange.begin(), BBMap);
1050 map_iterator(LLVMRange.end(), BBMap);
1051 return make_range(MappedBegin, MappedEnd);
1052 }
1053
1054 template <typename LLVMBrTy>
1056 mapped_iterator<typename LLVMBrTy::const_succ_iterator,
1057 ConstLLVMBBToSBBB>;
1058 template <typename LLVMBrTy>
1060 successors(llvm::Value *Val, Context &Ctx) const {
1062 ConstLLVMRange =
1063 static_cast<const LLVMBrTy *>(cast<LLVMBrTy>(Val))->successors();
1064 ConstLLVMBBToSBBB ConstBBMap(Ctx);
1065 const_sb_succ_op_iterator<LLVMBrTy> ConstMappedBegin =
1066 map_iterator(ConstLLVMRange.begin(), ConstBBMap);
1068 map_iterator(ConstLLVMRange.end(), ConstBBMap);
1069 return make_range(ConstMappedBegin, ConstMappedEnd);
1070 }
1071};
1072
1073class UncondBrInst : public SingleLLVMInstructionImpl<llvm::UncondBrInst>,
1074 public BrInstCommon {
1075 /// Use Context::createUncondBrInst(). Don't call the constructor directly.
1076 UncondBrInst(llvm::UncondBrInst *UBI, Context &Ctx)
1077 : SingleLLVMInstructionImpl(ClassID::UncondBr, Opcode::UncondBr, UBI,
1078 Ctx) {}
1079 friend Context; // for UncondBrInst()
1080
1081public:
1082 static UncondBrInst *create(BasicBlock *Target, InsertPosition InsertBefore,
1083 Context &Ctx);
1085 LLVM_ABI void setSuccessor(BasicBlock *NewSucc);
1086 unsigned getNumSuccessors() const { return 1; }
1095
1096 /// For isa/dyn_cast.
1097 LLVM_ABI static bool classof(const Value *From);
1098};
1099
1100class CondBrInst : public SingleLLVMInstructionImpl<llvm::CondBrInst>,
1101 public BrInstCommon {
1102 /// Use Context::createUncondBrInst(). Don't call the constructor directly.
1103 CondBrInst(llvm::CondBrInst *CBI, Context &Ctx)
1104 : SingleLLVMInstructionImpl(ClassID::CondBr, Opcode::CondBr, CBI, Ctx) {}
1105 friend Context; // for UcnondBrInst()
1106
1107public:
1108 static CondBrInst *create(Value *Cond, BasicBlock *IfTrue,
1109 BasicBlock *IfFalse, InsertPosition InsertBefore,
1110 Context &Ctx);
1111 LLVM_ABI Value *getCondition() const;
1112 void setCondition(Value *V);
1113 LLVM_ABI BasicBlock *getSuccessor(unsigned SuccIdx) const;
1114 LLVM_ABI void setSuccessor(unsigned Idx, BasicBlock *NewSucc);
1115 unsigned getNumSuccessors() const { return 2; }
1125
1126 /// For isa/dyn_cast.
1127 LLVM_ABI static bool classof(const Value *From);
1128};
1129
1130/// An abstract class, parent of unary instructions.
1132 : public SingleLLVMInstructionImpl<llvm::UnaryInstruction> {
1133protected:
1135 Context &Ctx)
1136 : SingleLLVMInstructionImpl(ID, Opc, LLVMI, Ctx) {}
1137
1138public:
1139 static bool classof(const Instruction *I) {
1141 }
1142 static bool classof(const Value *V) {
1144 }
1145};
1146
1147class ExtractValueInst : public UnaryInstruction {
1148 /// Use Context::createExtractValueInst() instead.
1150 : UnaryInstruction(ClassID::ExtractValue, Opcode::ExtractValue, EVI,
1151 Ctx) {}
1152 friend Context; // for ExtractValueInst()
1153
1154public:
1155 LLVM_ABI static Value *create(Value *Agg, ArrayRef<unsigned> Idxs,
1156 InsertPosition Pos, Context &Ctx,
1157 const Twine &Name = "");
1158
1159 static bool classof(const Value *From) {
1160 return From->getSubclassID() == ClassID::ExtractValue;
1161 }
1162
1163 /// Returns the type of the element that would be extracted
1164 /// with an extractvalue instruction with the specified parameters.
1165 ///
1166 /// Null is returned if the indices are invalid for the specified type.
1168
1170
1171 inline idx_iterator idx_begin() const {
1172 return cast<llvm::ExtractValueInst>(Val)->idx_begin();
1173 }
1174 inline idx_iterator idx_end() const {
1175 return cast<llvm::ExtractValueInst>(Val)->idx_end();
1176 }
1178 return cast<llvm::ExtractValueInst>(Val)->indices();
1179 }
1180
1186 }
1190
1192 return cast<llvm::ExtractValueInst>(Val)->getIndices();
1193 }
1194
1195 unsigned getNumIndices() const {
1196 return cast<llvm::ExtractValueInst>(Val)->getNumIndices();
1197 }
1198
1199 unsigned hasIndices() const {
1200 return cast<llvm::ExtractValueInst>(Val)->hasIndices();
1201 }
1202};
1203
1204class VAArgInst : public UnaryInstruction {
1205 VAArgInst(llvm::VAArgInst *FI, Context &Ctx)
1206 : UnaryInstruction(ClassID::VAArg, Opcode::VAArg, FI, Ctx) {}
1207 friend Context; // For constructor;
1208
1209public:
1210 LLVM_ABI static VAArgInst *create(Value *List, Type *Ty, InsertPosition Pos,
1211 Context &Ctx, const Twine &Name = "");
1213 const Value *getPointerOperand() const {
1214 return const_cast<VAArgInst *>(this)->getPointerOperand();
1215 }
1216 static unsigned getPointerOperandIndex() {
1218 }
1219 static bool classof(const Value *From) {
1220 return From->getSubclassID() == ClassID::VAArg;
1221 }
1222};
1223
1224class FreezeInst : public UnaryInstruction {
1225 FreezeInst(llvm::FreezeInst *FI, Context &Ctx)
1226 : UnaryInstruction(ClassID::Freeze, Opcode::Freeze, FI, Ctx) {}
1227 friend Context; // For constructor;
1228
1229public:
1230 LLVM_ABI static FreezeInst *create(Value *V, InsertPosition Pos, Context &Ctx,
1231 const Twine &Name = "");
1232 static bool classof(const Value *From) {
1233 return From->getSubclassID() == ClassID::Freeze;
1234 }
1235};
1236
1237class LoadInst final : public UnaryInstruction {
1238 /// Use LoadInst::create() instead of calling the constructor.
1239 LoadInst(llvm::LoadInst *LI, Context &Ctx)
1240 : UnaryInstruction(ClassID::Load, Opcode::Load, LI, Ctx) {}
1241 friend Context; // for LoadInst()
1242
1243public:
1244 /// Return true if this is a load from a volatile memory location.
1245 bool isVolatile() const { return cast<llvm::LoadInst>(Val)->isVolatile(); }
1246 /// Specify whether this is a volatile load or not.
1247 LLVM_ABI void setVolatile(bool V);
1248
1249 LLVM_ABI static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align,
1250 InsertPosition Pos, bool IsVolatile,
1251 Context &Ctx, const Twine &Name = "");
1252 static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align,
1253 InsertPosition Pos, Context &Ctx,
1254 const Twine &Name = "") {
1255 return create(Ty, Ptr, Align, Pos, /*IsVolatile=*/false, Ctx, Name);
1256 }
1257
1258 /// For isa/dyn_cast.
1259 LLVM_ABI static bool classof(const Value *From);
1261 Align getAlign() const { return cast<llvm::LoadInst>(Val)->getAlign(); }
1262 bool isUnordered() const { return cast<llvm::LoadInst>(Val)->isUnordered(); }
1263 bool isSimple() const { return cast<llvm::LoadInst>(Val)->isSimple(); }
1264};
1265
1266class StoreInst final : public SingleLLVMInstructionImpl<llvm::StoreInst> {
1267 /// Use StoreInst::create().
1268 StoreInst(llvm::StoreInst *SI, Context &Ctx)
1269 : SingleLLVMInstructionImpl(ClassID::Store, Opcode::Store, SI, Ctx) {}
1270 friend Context; // for StoreInst()
1271
1272public:
1273 /// Return true if this is a store from a volatile memory location.
1274 bool isVolatile() const { return cast<llvm::StoreInst>(Val)->isVolatile(); }
1275 /// Specify whether this is a volatile store or not.
1276 LLVM_ABI void setVolatile(bool V);
1277
1279 InsertPosition Pos, bool IsVolatile,
1280 Context &Ctx);
1281 static StoreInst *create(Value *V, Value *Ptr, MaybeAlign Align,
1282 InsertPosition Pos, Context &Ctx) {
1283 return create(V, Ptr, Align, Pos, /*IsVolatile=*/false, Ctx);
1284 }
1285
1286 /// For isa/dyn_cast.
1287 LLVM_ABI static bool classof(const Value *From);
1290 Align getAlign() const { return cast<llvm::StoreInst>(Val)->getAlign(); }
1291 bool isSimple() const { return cast<llvm::StoreInst>(Val)->isSimple(); }
1292 bool isUnordered() const { return cast<llvm::StoreInst>(Val)->isUnordered(); }
1293};
1294
1295class UnreachableInst final : public Instruction {
1296 /// Use UnreachableInst::create() instead of calling the constructor.
1298 : Instruction(ClassID::Unreachable, Opcode::Unreachable, I, Ctx) {}
1299 friend Context;
1300 Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
1302 }
1304 return {cast<llvm::Instruction>(Val)};
1305 }
1306
1307public:
1308 LLVM_ABI static UnreachableInst *create(InsertPosition Pos, Context &Ctx);
1309 LLVM_ABI static bool classof(const Value *From);
1310 unsigned getNumSuccessors() const { return 0; }
1311 unsigned getUseOperandNo(const Use &Use) const final {
1312 llvm_unreachable("UnreachableInst has no operands!");
1313 }
1314 unsigned getNumOfIRInstrs() const final { return 1u; }
1315};
1316
1317class ReturnInst final : public SingleLLVMInstructionImpl<llvm::ReturnInst> {
1318 /// Use ReturnInst::create() instead of calling the constructor.
1320 : SingleLLVMInstructionImpl(ClassID::Ret, Opcode::Ret, I, Ctx) {}
1322 : SingleLLVMInstructionImpl(SubclassID, Opcode::Ret, I, Ctx) {}
1323 friend class Context; // For accessing the constructor in create*()
1324 static ReturnInst *createCommon(Value *RetVal, IRBuilder<> &Builder,
1325 Context &Ctx);
1326
1327public:
1328 LLVM_ABI static ReturnInst *create(Value *RetVal, InsertPosition Pos,
1329 Context &Ctx);
1330 static bool classof(const Value *From) {
1331 return From->getSubclassID() == ClassID::Ret;
1332 }
1333 /// \Returns null if there is no return value.
1334 LLVM_ABI Value *getReturnValue() const;
1335};
1336
1337class CallBase : public SingleLLVMInstructionImpl<llvm::CallBase> {
1339 : SingleLLVMInstructionImpl(ID, Opc, I, Ctx) {}
1340 friend class CallInst; // For constructor.
1341 friend class InvokeInst; // For constructor.
1342 friend class CallBrInst; // For constructor.
1343
1344public:
1345 static bool classof(const Value *From) {
1346 auto Opc = From->getSubclassID();
1347 return Opc == Instruction::ClassID::Call ||
1348 Opc == Instruction::ClassID::Invoke ||
1349 Opc == Instruction::ClassID::CallBr;
1350 }
1351
1353
1356 return const_cast<CallBase *>(this)->data_operands_begin();
1357 }
1359 auto *LLVMCB = cast<llvm::CallBase>(Val);
1360 auto Dist = LLVMCB->data_operands_end() - LLVMCB->data_operands_begin();
1361 return op_begin() + Dist;
1362 }
1364 auto *LLVMCB = cast<llvm::CallBase>(Val);
1365 auto Dist = LLVMCB->data_operands_end() - LLVMCB->data_operands_begin();
1366 return op_begin() + Dist;
1367 }
1374 bool data_operands_empty() const {
1376 }
1377 unsigned data_operands_size() const {
1378 return std::distance(data_operands_begin(), data_operands_end());
1379 }
1380 bool isDataOperand(Use U) const {
1381 assert(this == U.getUser() &&
1382 "Only valid to query with a use of this instruction!");
1383 return cast<llvm::CallBase>(Val)->isDataOperand(U.LLVMUse);
1384 }
1385 unsigned getDataOperandNo(Use U) const {
1386 assert(isDataOperand(U) && "Data operand # out of range!");
1387 return cast<llvm::CallBase>(Val)->getDataOperandNo(U.LLVMUse);
1388 }
1389
1390 /// Return the total number operands (not operand bundles) used by
1391 /// every operand bundle in this OperandBundleUser.
1392 unsigned getNumTotalBundleOperands() const {
1393 return cast<llvm::CallBase>(Val)->getNumTotalBundleOperands();
1394 }
1395
1402 return const_cast<CallBase *>(this)->arg_end();
1403 }
1410 bool arg_empty() const { return arg_end() == arg_begin(); }
1411 unsigned arg_size() const { return arg_end() - arg_begin(); }
1412
1413 Value *getArgOperand(unsigned OpIdx) const {
1414 assert(OpIdx < arg_size() && "Out of bounds!");
1415 return getOperand(OpIdx);
1416 }
1417 void setArgOperand(unsigned OpIdx, Value *NewOp) {
1418 assert(OpIdx < arg_size() && "Out of bounds!");
1419 setOperand(OpIdx, NewOp);
1420 }
1421
1422 Use getArgOperandUse(unsigned Idx) const {
1423 assert(Idx < arg_size() && "Out of bounds!");
1424 return getOperandUse(Idx);
1425 }
1426 Use getArgOperandUse(unsigned Idx) {
1427 assert(Idx < arg_size() && "Out of bounds!");
1428 return getOperandUse(Idx);
1429 }
1430
1431 bool isArgOperand(Use U) const {
1432 return cast<llvm::CallBase>(Val)->isArgOperand(U.LLVMUse);
1433 }
1434 unsigned getArgOperandNo(Use U) const {
1435 return cast<llvm::CallBase>(Val)->getArgOperandNo(U.LLVMUse);
1436 }
1437 bool hasArgument(const Value *V) const { return is_contained(args(), V); }
1438
1441
1443 bool isIndirectCall() const {
1444 return cast<llvm::CallBase>(Val)->isIndirectCall();
1445 }
1446 bool isCallee(Use U) const {
1447 return cast<llvm::CallBase>(Val)->isCallee(U.LLVMUse);
1448 }
1450 const Function *getCaller() const {
1451 return const_cast<CallBase *>(this)->getCaller();
1452 }
1453 bool isMustTailCall() const {
1454 return cast<llvm::CallBase>(Val)->isMustTailCall();
1455 }
1456 bool isTailCall() const { return cast<llvm::CallBase>(Val)->isTailCall(); }
1458 return cast<llvm::CallBase>(Val)->getIntrinsicID();
1459 }
1463 return cast<llvm::CallBase>(Val)->getCallingConv();
1464 }
1465 bool isInlineAsm() const { return cast<llvm::CallBase>(Val)->isInlineAsm(); }
1466};
1467
1468class CallInst : public CallBase {
1469 /// Use Context::createCallInst(). Don't call the
1470 /// constructor directly.
1472 : CallBase(ClassID::Call, Opcode::Call, I, Ctx) {}
1473 friend class Context; // For accessing the constructor in create*()
1474 friend class IntrinsicInst; // For constructor
1475
1476public:
1477 LLVM_ABI static CallInst *create(FunctionType *FTy, Value *Func,
1479 Context &Ctx, const Twine &NameStr = "");
1480
1481 static bool classof(const Value *From) {
1482 return From->getSubclassID() == ClassID::Call;
1483 }
1484};
1485
1486class InvokeInst final : public CallBase {
1487 /// Use Context::createInvokeInst(). Don't call the
1488 /// constructor directly.
1490 : CallBase(ClassID::Invoke, Opcode::Invoke, I, Ctx) {}
1491 friend class Context; // For accessing the constructor in
1492 // create*()
1493
1494public:
1495 LLVM_ABI static InvokeInst *create(FunctionType *FTy, Value *Func,
1496 BasicBlock *IfNormal,
1497 BasicBlock *IfException,
1499 Context &Ctx, const Twine &NameStr = "");
1500
1501 static bool classof(const Value *From) {
1502 return From->getSubclassID() == ClassID::Invoke;
1503 }
1509 LLVM_ABI BasicBlock *getSuccessor(unsigned SuccIdx) const;
1510 void setSuccessor(unsigned SuccIdx, BasicBlock *NewSucc) {
1511 assert(SuccIdx < 2 && "Successor # out of range for invoke!");
1512 if (SuccIdx == 0)
1513 setNormalDest(NewSucc);
1514 else
1515 setUnwindDest(NewSucc);
1516 }
1517 unsigned getNumSuccessors() const {
1518 return cast<llvm::InvokeInst>(Val)->getNumSuccessors();
1519 }
1520};
1521
1522class CallBrInst final : public CallBase {
1523 /// Use Context::createCallBrInst(). Don't call the
1524 /// constructor directly.
1526 : CallBase(ClassID::CallBr, Opcode::CallBr, I, Ctx) {}
1527 friend class Context; // For accessing the constructor in
1528 // create*()
1529
1530public:
1531 LLVM_ABI static CallBrInst *create(FunctionType *FTy, Value *Func,
1532 BasicBlock *DefaultDest,
1533 ArrayRef<BasicBlock *> IndirectDests,
1535 Context &Ctx, const Twine &NameStr = "");
1536 static bool classof(const Value *From) {
1537 return From->getSubclassID() == ClassID::CallBr;
1538 }
1539 unsigned getNumIndirectDests() const {
1540 return cast<llvm::CallBrInst>(Val)->getNumIndirectDests();
1541 }
1542 LLVM_ABI Value *getIndirectDestLabel(unsigned Idx) const;
1543 LLVM_ABI Value *getIndirectDestLabelUse(unsigned Idx) const;
1545 LLVM_ABI BasicBlock *getIndirectDest(unsigned Idx) const;
1548 LLVM_ABI void setIndirectDest(unsigned Idx, BasicBlock *BB);
1549 LLVM_ABI BasicBlock *getSuccessor(unsigned Idx) const;
1550 unsigned getNumSuccessors() const {
1551 return cast<llvm::CallBrInst>(Val)->getNumSuccessors();
1552 }
1553};
1554
1555class LandingPadInst : public SingleLLVMInstructionImpl<llvm::LandingPadInst> {
1557 : SingleLLVMInstructionImpl(ClassID::LandingPad, Opcode::LandingPad, LP,
1558 Ctx) {}
1559 friend class Context; // For constructor.
1560
1561public:
1562 LLVM_ABI static LandingPadInst *create(Type *RetTy,
1563 unsigned NumReservedClauses,
1565 const Twine &Name = "");
1566 /// Return 'true' if this landingpad instruction is a
1567 /// cleanup. I.e., it should be run when unwinding even if its landing pad
1568 /// doesn't catch the exception.
1569 bool isCleanup() const {
1570 return cast<llvm::LandingPadInst>(Val)->isCleanup();
1571 }
1572 /// Indicate that this landingpad instruction is a cleanup.
1573 LLVM_ABI void setCleanup(bool V);
1574
1575 // TODO: We are not implementing addClause() because we have no way to revert
1576 // it for now.
1577
1578 /// Get the value of the clause at index Idx. Use isCatch/isFilter to
1579 /// determine what type of clause this is.
1580 LLVM_ABI Constant *getClause(unsigned Idx) const;
1581
1582 /// Return 'true' if the clause and index Idx is a catch clause.
1583 bool isCatch(unsigned Idx) const {
1584 return cast<llvm::LandingPadInst>(Val)->isCatch(Idx);
1585 }
1586 /// Return 'true' if the clause and index Idx is a filter clause.
1587 bool isFilter(unsigned Idx) const {
1588 return cast<llvm::LandingPadInst>(Val)->isFilter(Idx);
1589 }
1590 /// Get the number of clauses for this landing pad.
1591 unsigned getNumClauses() const {
1592 return cast<llvm::LandingPadInst>(Val)->getNumOperands();
1593 }
1594 // TODO: We are not implementing reserveClauses() because we can't revert it.
1595 static bool classof(const Value *From) {
1596 return From->getSubclassID() == ClassID::LandingPad;
1597 }
1598};
1599
1600class FuncletPadInst : public SingleLLVMInstructionImpl<llvm::FuncletPadInst> {
1602 Context &Ctx)
1603 : SingleLLVMInstructionImpl(SubclassID, Opc, I, Ctx) {}
1604 friend class CatchPadInst; // For constructor.
1605 friend class CleanupPadInst; // For constructor.
1606
1607public:
1608 /// Return the number of funcletpad arguments.
1609 unsigned arg_size() const {
1610 return cast<llvm::FuncletPadInst>(Val)->arg_size();
1611 }
1612 /// Return the outer EH-pad this funclet is nested within.
1613 ///
1614 /// Note: This returns the associated CatchSwitchInst if this FuncletPadInst
1615 /// is a CatchPadInst.
1616 LLVM_ABI Value *getParentPad() const;
1617 LLVM_ABI void setParentPad(Value *ParentPad);
1618 /// Return the Idx-th funcletpad argument.
1619 LLVM_ABI Value *getArgOperand(unsigned Idx) const;
1620 /// Set the Idx-th funcletpad argument.
1621 LLVM_ABI void setArgOperand(unsigned Idx, Value *V);
1622
1623 // TODO: Implement missing functions: arg_operands().
1624 static bool classof(const Value *From) {
1625 return From->getSubclassID() == ClassID::CatchPad ||
1626 From->getSubclassID() == ClassID::CleanupPad;
1627 }
1628};
1629
1630class CatchPadInst : public FuncletPadInst {
1632 : FuncletPadInst(ClassID::CatchPad, Opcode::CatchPad, CPI, Ctx) {}
1633 friend class Context; // For constructor.
1634
1635public:
1637 // TODO: We have not implemented setCatchSwitch() because we can't revert it
1638 // for now, as there is no CatchPadInst member function that can undo it.
1639
1640 LLVM_ABI static CatchPadInst *create(Value *ParentPad, ArrayRef<Value *> Args,
1642 const Twine &Name = "");
1643 static bool classof(const Value *From) {
1644 return From->getSubclassID() == ClassID::CatchPad;
1645 }
1646};
1647
1648class CleanupPadInst : public FuncletPadInst {
1650 : FuncletPadInst(ClassID::CleanupPad, Opcode::CleanupPad, CPI, Ctx) {}
1651 friend class Context; // For constructor.
1652
1653public:
1654 LLVM_ABI static CleanupPadInst *create(Value *ParentPad,
1655 ArrayRef<Value *> Args,
1657 const Twine &Name = "");
1658 static bool classof(const Value *From) {
1659 return From->getSubclassID() == ClassID::CleanupPad;
1660 }
1661};
1662
1663class CatchReturnInst
1664 : public SingleLLVMInstructionImpl<llvm::CatchReturnInst> {
1666 : SingleLLVMInstructionImpl(ClassID::CatchRet, Opcode::CatchRet, CRI,
1667 Ctx) {}
1668 friend class Context; // For constructor.
1669
1670public:
1671 LLVM_ABI static CatchReturnInst *create(CatchPadInst *CatchPad,
1672 BasicBlock *BB, InsertPosition Pos,
1673 Context &Ctx);
1675 LLVM_ABI void setCatchPad(CatchPadInst *CatchPad);
1677 LLVM_ABI void setSuccessor(BasicBlock *NewSucc);
1678 unsigned getNumSuccessors() {
1679 return cast<llvm::CatchReturnInst>(Val)->getNumSuccessors();
1680 }
1682 static bool classof(const Value *From) {
1683 return From->getSubclassID() == ClassID::CatchRet;
1684 }
1685};
1686
1687class CleanupReturnInst
1688 : public SingleLLVMInstructionImpl<llvm::CleanupReturnInst> {
1690 : SingleLLVMInstructionImpl(ClassID::CleanupRet, Opcode::CleanupRet, CRI,
1691 Ctx) {}
1692 friend class Context; // For constructor.
1693
1694public:
1695 LLVM_ABI static CleanupReturnInst *create(CleanupPadInst *CleanupPad,
1696 BasicBlock *UnwindBB,
1697 InsertPosition Pos, Context &Ctx);
1698 bool hasUnwindDest() const {
1699 return cast<llvm::CleanupReturnInst>(Val)->hasUnwindDest();
1700 }
1701 bool unwindsToCaller() const {
1702 return cast<llvm::CleanupReturnInst>(Val)->unwindsToCaller();
1703 }
1705 LLVM_ABI void setCleanupPad(CleanupPadInst *CleanupPad);
1706 unsigned getNumSuccessors() const {
1707 return cast<llvm::CleanupReturnInst>(Val)->getNumSuccessors();
1708 }
1710 LLVM_ABI void setUnwindDest(BasicBlock *NewDest);
1711
1712 static bool classof(const Value *From) {
1713 return From->getSubclassID() == ClassID::CleanupRet;
1714 }
1715};
1716
1717class GetElementPtrInst final
1718 : public SingleLLVMInstructionImpl<llvm::GetElementPtrInst> {
1719 /// Use Context::createGetElementPtrInst(). Don't call
1720 /// the constructor directly.
1722 : SingleLLVMInstructionImpl(ClassID::GetElementPtr, Opcode::GetElementPtr,
1723 I, Ctx) {}
1725 : SingleLLVMInstructionImpl(SubclassID, Opcode::GetElementPtr, I, Ctx) {}
1726 friend class Context; // For accessing the constructor in
1727 // create*()
1728
1729public:
1730 LLVM_ABI static Value *create(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
1732 const Twine &NameStr = "");
1733
1734 static bool classof(const Value *From) {
1735 return From->getSubclassID() == ClassID::GetElementPtr;
1736 }
1737
1740 unsigned getAddressSpace() const {
1741 return cast<llvm::GetElementPtrInst>(Val)->getAddressSpace();
1742 }
1743
1744 inline op_iterator idx_begin() { return op_begin() + 1; }
1746 return const_cast<GetElementPtrInst *>(this)->idx_begin();
1747 }
1748 inline op_iterator idx_end() { return op_end(); }
1750 return const_cast<GetElementPtrInst *>(this)->idx_end();
1751 }
1756 return const_cast<GetElementPtrInst *>(this)->indices();
1757 }
1758
1764 unsigned getPointerAddressSpace() const {
1765 return cast<llvm::GetElementPtrInst>(Val)->getPointerAddressSpace();
1766 }
1767 unsigned getNumIndices() const {
1768 return cast<llvm::GetElementPtrInst>(Val)->getNumIndices();
1769 }
1770 bool hasIndices() const {
1771 return cast<llvm::GetElementPtrInst>(Val)->hasIndices();
1772 }
1774 return cast<llvm::GetElementPtrInst>(Val)->hasAllConstantIndices();
1775 }
1777 return cast<llvm::GetElementPtrInst>(Val)->getNoWrapFlags();
1778 }
1779 bool isInBounds() const {
1780 return cast<llvm::GetElementPtrInst>(Val)->isInBounds();
1781 }
1783 return cast<llvm::GetElementPtrInst>(Val)->hasNoUnsignedSignedWrap();
1784 }
1785 bool hasNoUnsignedWrap() const {
1786 return cast<llvm::GetElementPtrInst>(Val)->hasNoUnsignedWrap();
1787 }
1789 return cast<llvm::GetElementPtrInst>(Val)->accumulateConstantOffset(DL,
1790 Offset);
1791 }
1792 // TODO: Add missing member functions.
1793};
1794
1795class CatchSwitchInst
1796 : public SingleLLVMInstructionImpl<llvm::CatchSwitchInst> {
1798 : SingleLLVMInstructionImpl(ClassID::CatchSwitch, Opcode::CatchSwitch,
1799 CSI, Ctx) {}
1800 friend class Context; // For accessing the constructor in create*()
1801
1802public:
1803 LLVM_ABI static CatchSwitchInst *
1804 create(Value *ParentPad, BasicBlock *UnwindBB, unsigned NumHandlers,
1805 InsertPosition Pos, Context &Ctx, const Twine &Name = "");
1806
1807 LLVM_ABI Value *getParentPad() const;
1808 LLVM_ABI void setParentPad(Value *ParentPad);
1809
1810 bool hasUnwindDest() const {
1811 return cast<llvm::CatchSwitchInst>(Val)->hasUnwindDest();
1812 }
1813 bool unwindsToCaller() const {
1814 return cast<llvm::CatchSwitchInst>(Val)->unwindsToCaller();
1815 }
1817 LLVM_ABI void setUnwindDest(BasicBlock *UnwindDest);
1818
1819 unsigned getNumHandlers() const {
1820 return cast<llvm::CatchSwitchInst>(Val)->getNumHandlers();
1821 }
1822
1823private:
1824 static BasicBlock *handler_helper(Value *V) { return cast<BasicBlock>(V); }
1825 static const BasicBlock *handler_helper(const Value *V) {
1826 return cast<BasicBlock>(V);
1827 }
1828
1829public:
1830 using DerefFnTy = BasicBlock *(*)(Value *);
1833 using ConstDerefFnTy = const BasicBlock *(*)(const Value *);
1837
1839 op_iterator It = op_begin() + 1;
1840 if (hasUnwindDest())
1841 ++It;
1842 return handler_iterator(It, DerefFnTy(handler_helper));
1843 }
1845 const_op_iterator It = op_begin() + 1;
1846 if (hasUnwindDest())
1847 ++It;
1848 return const_handler_iterator(It, ConstDerefFnTy(handler_helper));
1849 }
1851 return handler_iterator(op_end(), DerefFnTy(handler_helper));
1852 }
1854 return const_handler_iterator(op_end(), ConstDerefFnTy(handler_helper));
1855 }
1862
1863 LLVM_ABI void addHandler(BasicBlock *Dest);
1864
1865 // TODO: removeHandler() cannot be reverted because there is no equivalent
1866 // addHandler() with a handler_iterator to specify the position. So we can't
1867 // implement it for now.
1868
1869 unsigned getNumSuccessors() const { return getNumOperands() - 1; }
1870 BasicBlock *getSuccessor(unsigned Idx) const {
1871 assert(Idx < getNumSuccessors() &&
1872 "Successor # out of range for catchswitch!");
1873 return cast<BasicBlock>(getOperand(Idx + 1));
1874 }
1875 void setSuccessor(unsigned Idx, BasicBlock *NewSucc) {
1876 assert(Idx < getNumSuccessors() &&
1877 "Successor # out of range for catchswitch!");
1878 setOperand(Idx + 1, NewSucc);
1879 }
1880
1881 static bool classof(const Value *From) {
1882 return From->getSubclassID() == ClassID::CatchSwitch;
1883 }
1884};
1885
1886class ResumeInst : public SingleLLVMInstructionImpl<llvm::ResumeInst> {
1888 : SingleLLVMInstructionImpl(ClassID::Resume, Opcode::Resume, CSI, Ctx) {}
1889 friend class Context; // For accessing the constructor in create*()
1890
1891public:
1892 LLVM_ABI static ResumeInst *create(Value *Exn, InsertPosition Pos,
1893 Context &Ctx);
1894 LLVM_ABI Value *getValue() const;
1895 unsigned getNumSuccessors() const {
1896 return cast<llvm::ResumeInst>(Val)->getNumSuccessors();
1897 }
1898 static bool classof(const Value *From) {
1899 return From->getSubclassID() == ClassID::Resume;
1900 }
1901};
1902
1903class SwitchInst : public SingleLLVMInstructionImpl<llvm::SwitchInst> {
1905 : SingleLLVMInstructionImpl(ClassID::Switch, Opcode::Switch, SI, Ctx) {}
1906 friend class Context; // For accessing the constructor in create*()
1907
1908public:
1909 static constexpr unsigned DefaultPseudoIndex =
1911
1912 LLVM_ABI static SwitchInst *create(Value *V, BasicBlock *Dest,
1913 unsigned NumCases, InsertPosition Pos,
1914 Context &Ctx, const Twine &Name = "");
1915
1916 LLVM_ABI Value *getCondition() const;
1917 LLVM_ABI void setCondition(Value *V);
1920 return cast<llvm::SwitchInst>(Val)->defaultDestUnreachable();
1921 }
1922 LLVM_ABI void setDefaultDest(BasicBlock *DefaultCase);
1923 unsigned getNumCases() const {
1924 return cast<llvm::SwitchInst>(Val)->getNumCases();
1925 }
1926
1927 template <typename LLVMCaseItT, typename BlockT, typename ConstT>
1928 class CaseItImpl;
1929
1930 // The template helps avoid code duplication for const and non-const
1931 // CaseHandle variants.
1932 template <typename LLVMCaseItT, typename BlockT, typename ConstT>
1934 Context &Ctx;
1935 // NOTE: We are not wrapping an LLVM CaseHande here because it is not
1936 // default-constructible. Instead we are wrapping the LLVM CaseIt
1937 // iterator, as we can always get an LLVM CaseHandle by de-referencing it.
1938 LLVMCaseItT LLVMCaseIt;
1939 template <typename T1, typename T2, typename T3> friend class CaseItImpl;
1940
1941 public:
1942 CaseHandleImpl(Context &Ctx, LLVMCaseItT LLVMCaseIt)
1943 : Ctx(Ctx), LLVMCaseIt(LLVMCaseIt) {}
1946 unsigned getCaseIndex() const {
1947 const auto &LLVMCaseHandle = *LLVMCaseIt;
1948 return LLVMCaseHandle.getCaseIndex();
1949 }
1950 unsigned getSuccessorIndex() const {
1951 const auto &LLVMCaseHandle = *LLVMCaseIt;
1952 return LLVMCaseHandle.getSuccessorIndex();
1953 }
1954 };
1955
1956 // The template helps avoid code duplication for const and non-const CaseIt
1957 // variants.
1958 template <typename LLVMCaseItT, typename BlockT, typename ConstT>
1960 CaseItImpl<LLVMCaseItT, BlockT, ConstT>,
1961 std::random_access_iterator_tag,
1962 const CaseHandleImpl<LLVMCaseItT, BlockT, ConstT>> {
1964
1965 public:
1966 CaseItImpl(Context &Ctx, LLVMCaseItT It) : CH(Ctx, It) {}
1967 CaseItImpl(SwitchInst *SI, ptrdiff_t CaseNum)
1968 : CH(SI->getContext(), llvm::SwitchInst::CaseIt(
1969 cast<llvm::SwitchInst>(SI->Val), CaseNum)) {}
1971 CH.LLVMCaseIt += N;
1972 return *this;
1973 }
1975 CH.LLVMCaseIt -= N;
1976 return *this;
1977 }
1979 return CH.LLVMCaseIt - Other.CH.LLVMCaseIt;
1980 }
1981 bool operator==(const CaseItImpl &Other) const {
1982 return CH.LLVMCaseIt == Other.CH.LLVMCaseIt;
1983 }
1984 bool operator<(const CaseItImpl &Other) const {
1985 return CH.LLVMCaseIt < Other.CH.LLVMCaseIt;
1986 }
1988 return CH;
1989 }
1990 };
1991
1995
1997 const BasicBlock, const ConstantInt>;
1999 const BasicBlock, const ConstantInt>;
2000
2001 /// Returns a read/write iterator that points to the first case in the
2002 /// SwitchInst.
2009 /// Returns a read/write iterator that points one past the last in the
2010 /// SwitchInst.
2017 /// Iteration adapter for range-for loops.
2039
2040 LLVM_ABI void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2041 /// This method removes the specified case and its successor from the switch
2042 /// instruction. Note that this operation may reorder the remaining cases at
2043 /// index idx and above.
2044 /// Note:
2045 /// This action invalidates iterators for all cases following the one removed,
2046 /// including the case_end() iterator. It returns an iterator for the next
2047 /// case.
2049
2050 unsigned getNumSuccessors() const {
2051 return cast<llvm::SwitchInst>(Val)->getNumSuccessors();
2052 }
2053 LLVM_ABI BasicBlock *getSuccessor(unsigned Idx) const;
2054 LLVM_ABI void setSuccessor(unsigned Idx, BasicBlock *NewSucc);
2055 static bool classof(const Value *From) {
2056 return From->getSubclassID() == ClassID::Switch;
2057 }
2058};
2059
2060class UnaryOperator : public UnaryInstruction {
2061 static Opcode getUnaryOpcode(llvm::Instruction::UnaryOps UnOp) {
2062 switch (UnOp) {
2063 case llvm::Instruction::FNeg:
2064 return Opcode::FNeg;
2065 case llvm::Instruction::UnaryOpsEnd:
2066 llvm_unreachable("Bad UnOp!");
2067 }
2068 llvm_unreachable("Unhandled UnOp!");
2069 }
2071 : UnaryInstruction(ClassID::UnOp, getUnaryOpcode(UO->getOpcode()), UO,
2072 Ctx) {}
2073 friend Context; // for constructor.
2074public:
2076 InsertPosition Pos, Context &Ctx,
2077 const Twine &Name = "");
2079 Value *OpV, Value *CopyFrom,
2080 InsertPosition Pos, Context &Ctx,
2081 const Twine &Name = "");
2082 /// For isa/dyn_cast.
2083 static bool classof(const Value *From) {
2084 return From->getSubclassID() == ClassID::UnOp;
2085 }
2086};
2087
2088class BinaryOperator : public SingleLLVMInstructionImpl<llvm::BinaryOperator> {
2089protected:
2091 switch (BinOp) {
2092 case llvm::Instruction::Add:
2093 return Opcode::Add;
2094 case llvm::Instruction::FAdd:
2095 return Opcode::FAdd;
2096 case llvm::Instruction::Sub:
2097 return Opcode::Sub;
2098 case llvm::Instruction::FSub:
2099 return Opcode::FSub;
2100 case llvm::Instruction::Mul:
2101 return Opcode::Mul;
2102 case llvm::Instruction::FMul:
2103 return Opcode::FMul;
2104 case llvm::Instruction::UDiv:
2105 return Opcode::UDiv;
2106 case llvm::Instruction::SDiv:
2107 return Opcode::SDiv;
2108 case llvm::Instruction::FDiv:
2109 return Opcode::FDiv;
2110 case llvm::Instruction::URem:
2111 return Opcode::URem;
2112 case llvm::Instruction::SRem:
2113 return Opcode::SRem;
2114 case llvm::Instruction::FRem:
2115 return Opcode::FRem;
2116 case llvm::Instruction::Shl:
2117 return Opcode::Shl;
2118 case llvm::Instruction::LShr:
2119 return Opcode::LShr;
2120 case llvm::Instruction::AShr:
2121 return Opcode::AShr;
2122 case llvm::Instruction::And:
2123 return Opcode::And;
2124 case llvm::Instruction::Or:
2125 return Opcode::Or;
2126 case llvm::Instruction::Xor:
2127 return Opcode::Xor;
2128 case llvm::Instruction::BinaryOpsEnd:
2129 llvm_unreachable("Bad BinOp!");
2130 }
2131 llvm_unreachable("Unhandled BinOp!");
2132 }
2134 : SingleLLVMInstructionImpl(ClassID::BinaryOperator,
2135 getBinOpOpcode(BinOp->getOpcode()), BinOp,
2136 Ctx) {}
2137 friend class Context; // For constructor.
2138
2139public:
2142 const Twine &Name = "");
2143
2145 Value *LHS, Value *RHS,
2146 Value *CopyFrom,
2148 const Twine &Name = "");
2149 /// For isa/dyn_cast.
2150 static bool classof(const Value *From) {
2151 return From->getSubclassID() == ClassID::BinaryOperator;
2152 }
2154};
2155
2156/// An or instruction, which can be marked as "disjoint", indicating that the
2157/// inputs don't have a 1 in the same bit position. Meaning this instruction
2158/// can also be treated as an add.
2160public:
2161 LLVM_ABI void setIsDisjoint(bool B);
2162 bool isDisjoint() const {
2163 return cast<llvm::PossiblyDisjointInst>(Val)->isDisjoint();
2164 }
2165 /// For isa/dyn_cast.
2166 static bool classof(const Value *From) {
2167 return isa<Instruction>(From) &&
2168 cast<Instruction>(From)->getOpcode() == Opcode::Or;
2169 }
2170};
2171
2172class AtomicRMWInst : public SingleLLVMInstructionImpl<llvm::AtomicRMWInst> {
2174 : SingleLLVMInstructionImpl(ClassID::AtomicRMW,
2175 Instruction::Opcode::AtomicRMW, Atomic, Ctx) {
2176 }
2177 friend class Context; // For constructor.
2178
2179public:
2182 return cast<llvm::AtomicRMWInst>(Val)->getOperation();
2183 }
2187 static bool isFPOperation(BinOp Op) {
2189 }
2191 cast<llvm::AtomicRMWInst>(Val)->setOperation(Op);
2192 }
2193 Align getAlign() const { return cast<llvm::AtomicRMWInst>(Val)->getAlign(); }
2195 bool isVolatile() const {
2196 return cast<llvm::AtomicRMWInst>(Val)->isVolatile();
2197 }
2198 LLVM_ABI void setVolatile(bool V);
2200 return cast<llvm::AtomicRMWInst>(Val)->getOrdering();
2201 }
2202 LLVM_ABI void setOrdering(AtomicOrdering Ordering);
2204 return cast<llvm::AtomicRMWInst>(Val)->getSyncScopeID();
2205 }
2208 const Value *getPointerOperand() const {
2209 return const_cast<AtomicRMWInst *>(this)->getPointerOperand();
2210 }
2212 const Value *getValOperand() const {
2213 return const_cast<AtomicRMWInst *>(this)->getValOperand();
2214 }
2215 unsigned getPointerAddressSpace() const {
2216 return cast<llvm::AtomicRMWInst>(Val)->getPointerAddressSpace();
2217 }
2219 return cast<llvm::AtomicRMWInst>(Val)->isFloatingPointOperation();
2220 }
2221 static bool classof(const Value *From) {
2222 return From->getSubclassID() == ClassID::AtomicRMW;
2223 }
2224
2225 LLVM_ABI static AtomicRMWInst *
2227 AtomicOrdering Ordering, InsertPosition Pos, Context &Ctx,
2228 SyncScope::ID SSID = SyncScope::System, const Twine &Name = "");
2229};
2230
2231class AtomicCmpXchgInst
2232 : public SingleLLVMInstructionImpl<llvm::AtomicCmpXchgInst> {
2234 : SingleLLVMInstructionImpl(ClassID::AtomicCmpXchg,
2235 Instruction::Opcode::AtomicCmpXchg, Atomic,
2236 Ctx) {}
2237 friend class Context; // For constructor.
2238
2239public:
2240 /// Return the alignment of the memory that is being allocated by the
2241 /// instruction.
2242 Align getAlign() const {
2243 return cast<llvm::AtomicCmpXchgInst>(Val)->getAlign();
2244 }
2245
2247 /// Return true if this is a cmpxchg from a volatile memory
2248 /// location.
2249 bool isVolatile() const {
2250 return cast<llvm::AtomicCmpXchgInst>(Val)->isVolatile();
2251 }
2252 /// Specify whether this is a volatile cmpxchg.
2253 LLVM_ABI void setVolatile(bool V);
2254 /// Return true if this cmpxchg may spuriously fail.
2255 bool isWeak() const { return cast<llvm::AtomicCmpXchgInst>(Val)->isWeak(); }
2256 LLVM_ABI void setWeak(bool IsWeak);
2264 return cast<llvm::AtomicCmpXchgInst>(Val)->getSuccessOrdering();
2265 }
2267
2269 return cast<llvm::AtomicCmpXchgInst>(Val)->getFailureOrdering();
2270 }
2273 return cast<llvm::AtomicCmpXchgInst>(Val)->getMergedOrdering();
2274 }
2276 return cast<llvm::AtomicCmpXchgInst>(Val)->getSyncScopeID();
2277 }
2280 const Value *getPointerOperand() const {
2281 return const_cast<AtomicCmpXchgInst *>(this)->getPointerOperand();
2282 }
2283
2285 const Value *getCompareOperand() const {
2286 return const_cast<AtomicCmpXchgInst *>(this)->getCompareOperand();
2287 }
2288
2290 const Value *getNewValOperand() const {
2291 return const_cast<AtomicCmpXchgInst *>(this)->getNewValOperand();
2292 }
2293
2294 /// Returns the address space of the pointer operand.
2295 unsigned getPointerAddressSpace() const {
2296 return cast<llvm::AtomicCmpXchgInst>(Val)->getPointerAddressSpace();
2297 }
2298
2300 create(Value *Ptr, Value *Cmp, Value *New, MaybeAlign Align,
2301 AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
2302 InsertPosition Pos, Context &Ctx,
2303 SyncScope::ID SSID = SyncScope::System, const Twine &Name = "");
2304
2305 static bool classof(const Value *From) {
2306 return From->getSubclassID() == ClassID::AtomicCmpXchg;
2307 }
2308};
2309
2310class AllocaInst final : public UnaryInstruction {
2312 : UnaryInstruction(ClassID::Alloca, Instruction::Opcode::Alloca, AI,
2313 Ctx) {}
2314 friend class Context; // For constructor.
2315
2316public:
2317 LLVM_ABI static AllocaInst *create(Type *Ty, unsigned AddrSpace,
2319 Value *ArraySize = nullptr,
2320 const Twine &Name = "");
2321
2322 /// Return true if there is an allocation size parameter to the allocation
2323 /// instruction that is not 1.
2324 bool isArrayAllocation() const {
2325 return cast<llvm::AllocaInst>(Val)->isArrayAllocation();
2326 }
2327 /// Get the number of elements allocated. For a simple allocation of a single
2328 /// element, this will return a constant 1 value.
2330 const Value *getArraySize() const {
2331 return const_cast<AllocaInst *>(this)->getArraySize();
2332 }
2333 /// Overload to return most specific pointer type.
2334 LLVM_ABI PointerType *getType() const;
2335 /// Return the address space for the allocation.
2336 unsigned getAddressSpace() const {
2337 return cast<llvm::AllocaInst>(Val)->getAddressSpace();
2338 }
2339 /// Get allocation size in bytes. Returns std::nullopt if size can't be
2340 /// determined, e.g. in case of a VLA.
2341 std::optional<TypeSize> getAllocationSize(const DataLayout &DL) const {
2342 return cast<llvm::AllocaInst>(Val)->getAllocationSize(DL);
2343 }
2344 /// Get allocation size in bits. Returns std::nullopt if size can't be
2345 /// determined, e.g. in case of a VLA.
2346 std::optional<TypeSize> getAllocationSizeInBits(const DataLayout &DL) const {
2347 return cast<llvm::AllocaInst>(Val)->getAllocationSizeInBits(DL);
2348 }
2349 /// Return the type that is being allocated by the instruction.
2351 /// for use only in special circumstances that need to generically
2352 /// transform a whole instruction (eg: IR linking and vectorization).
2353 LLVM_ABI void setAllocatedType(Type *Ty);
2354 /// Return the alignment of the memory that is being allocated by the
2355 /// instruction.
2356 Align getAlign() const { return cast<llvm::AllocaInst>(Val)->getAlign(); }
2358 /// Return true if this alloca is in the entry block of the function and is a
2359 /// constant size. If so, the code generator will fold it into the
2360 /// prolog/epilog code, so it is basically free.
2361 bool isStaticAlloca() const {
2362 return cast<llvm::AllocaInst>(Val)->isStaticAlloca();
2363 }
2364 /// Return true if this alloca is used as an inalloca argument to a call. Such
2365 /// allocas are never considered static even if they are in the entry block.
2366 bool isUsedWithInAlloca() const {
2367 return cast<llvm::AllocaInst>(Val)->isUsedWithInAlloca();
2368 }
2369 /// Specify whether this alloca is used to represent the arguments to a call.
2370 LLVM_ABI void setUsedWithInAlloca(bool V);
2371
2372 static bool classof(const Value *From) {
2373 if (auto *I = dyn_cast<Instruction>(From))
2374 return I->getSubclassID() == Instruction::ClassID::Alloca;
2375 return false;
2376 }
2377};
2378
2379class CastInst : public UnaryInstruction {
2380 static Opcode getCastOpcode(llvm::Instruction::CastOps CastOp) {
2381 switch (CastOp) {
2382 case llvm::Instruction::ZExt:
2383 return Opcode::ZExt;
2384 case llvm::Instruction::SExt:
2385 return Opcode::SExt;
2386 case llvm::Instruction::FPToUI:
2387 return Opcode::FPToUI;
2388 case llvm::Instruction::FPToSI:
2389 return Opcode::FPToSI;
2390 case llvm::Instruction::FPExt:
2391 return Opcode::FPExt;
2392 case llvm::Instruction::PtrToAddr:
2393 return Opcode::PtrToAddr;
2394 case llvm::Instruction::PtrToInt:
2395 return Opcode::PtrToInt;
2396 case llvm::Instruction::IntToPtr:
2397 return Opcode::IntToPtr;
2398 case llvm::Instruction::SIToFP:
2399 return Opcode::SIToFP;
2400 case llvm::Instruction::UIToFP:
2401 return Opcode::UIToFP;
2402 case llvm::Instruction::Trunc:
2403 return Opcode::Trunc;
2404 case llvm::Instruction::FPTrunc:
2405 return Opcode::FPTrunc;
2406 case llvm::Instruction::BitCast:
2407 return Opcode::BitCast;
2408 case llvm::Instruction::AddrSpaceCast:
2409 return Opcode::AddrSpaceCast;
2410 case llvm::Instruction::CastOpsEnd:
2411 llvm_unreachable("Bad CastOp!");
2412 }
2413 llvm_unreachable("Unhandled CastOp!");
2414 }
2415 /// Use Context::createCastInst(). Don't call the
2416 /// constructor directly.
2417 CastInst(llvm::CastInst *CI, Context &Ctx)
2418 : UnaryInstruction(ClassID::Cast, getCastOpcode(CI->getOpcode()), CI,
2419 Ctx) {}
2420 friend Context; // for SBCastInstruction()
2421
2422public:
2423 LLVM_ABI static Value *create(Type *DestTy, Opcode Op, Value *Operand,
2424 InsertPosition Pos, Context &Ctx,
2425 const Twine &Name = "");
2426 /// For isa/dyn_cast.
2427 LLVM_ABI static bool classof(const Value *From);
2428 LLVM_ABI Type *getSrcTy() const;
2429 LLVM_ABI Type *getDestTy() const;
2430};
2431
2432/// Instruction that can have a nneg flag (zext/uitofp).
2433class PossiblyNonNegInst : public CastInst {
2434public:
2435 bool hasNonNeg() const {
2436 return cast<llvm::PossiblyNonNegInst>(Val)->hasNonNeg();
2437 }
2438 LLVM_ABI void setNonNeg(bool B);
2439 /// For isa/dyn_cast.
2440 static bool classof(const Value *From) {
2441 if (auto *I = dyn_cast<Instruction>(From)) {
2442 switch (I->getOpcode()) {
2443 case Opcode::ZExt:
2444 case Opcode::UIToFP:
2445 return true;
2446 default:
2447 return false;
2448 }
2449 }
2450 return false;
2451 }
2452};
2453
2454// Helper class to simplify stamping out CastInst subclasses.
2455template <Instruction::Opcode Op> class CastInstImpl : public CastInst {
2456public:
2457 static Value *create(Value *Src, Type *DestTy, InsertPosition Pos,
2458 Context &Ctx, const Twine &Name = "") {
2459 return CastInst::create(DestTy, Op, Src, Pos, Ctx, Name);
2460 }
2461
2462 static bool classof(const Value *From) {
2463 if (auto *I = dyn_cast<Instruction>(From))
2464 return I->getOpcode() == Op;
2465 return false;
2466 }
2467};
2468
2469class TruncInst final : public CastInstImpl<Instruction::Opcode::Trunc> {};
2470class ZExtInst final : public CastInstImpl<Instruction::Opcode::ZExt> {};
2471class SExtInst final : public CastInstImpl<Instruction::Opcode::SExt> {};
2472class FPTruncInst final : public CastInstImpl<Instruction::Opcode::FPTrunc> {};
2473class FPExtInst final : public CastInstImpl<Instruction::Opcode::FPExt> {};
2474class UIToFPInst final : public CastInstImpl<Instruction::Opcode::UIToFP> {};
2475class SIToFPInst final : public CastInstImpl<Instruction::Opcode::SIToFP> {};
2476class FPToUIInst final : public CastInstImpl<Instruction::Opcode::FPToUI> {};
2477class FPToSIInst final : public CastInstImpl<Instruction::Opcode::FPToSI> {};
2478class IntToPtrInst final : public CastInstImpl<Instruction::Opcode::IntToPtr> {
2479};
2480class PtrToAddrInst final
2481 : public CastInstImpl<Instruction::Opcode::PtrToAddr> {};
2482class PtrToIntInst final : public CastInstImpl<Instruction::Opcode::PtrToInt> {
2483};
2484class BitCastInst final : public CastInstImpl<Instruction::Opcode::BitCast> {};
2486 : public CastInstImpl<Instruction::Opcode::AddrSpaceCast> {
2487public:
2488 /// \Returns the pointer operand.
2490 /// \Returns the pointer operand.
2491 const Value *getPointerOperand() const {
2492 return const_cast<AddrSpaceCastInst *>(this)->getPointerOperand();
2493 }
2494 /// \Returns the operand index of the pointer operand.
2495 static unsigned getPointerOperandIndex() { return 0u; }
2496 /// \Returns the address space of the pointer operand.
2497 unsigned getSrcAddressSpace() const {
2499 }
2500 /// \Returns the address space of the result.
2501 unsigned getDestAddressSpace() const {
2502 return getType()->getPointerAddressSpace();
2503 }
2504};
2505
2506class PHINode final : public SingleLLVMInstructionImpl<llvm::PHINode> {
2507 /// Use Context::createPHINode(). Don't call the constructor directly.
2508 PHINode(llvm::PHINode *PHI, Context &Ctx)
2509 : SingleLLVMInstructionImpl(ClassID::PHI, Opcode::PHI, PHI, Ctx) {}
2510 friend Context; // for PHINode()
2511 /// Helper for mapped_iterator.
2512 struct LLVMBBToBB {
2513 Context &Ctx;
2514 LLVMBBToBB(Context &Ctx) : Ctx(Ctx) {}
2515 LLVM_ABI BasicBlock *operator()(llvm::BasicBlock *LLVMBB) const;
2516 };
2517
2518public:
2519 LLVM_ABI static PHINode *create(Type *Ty, unsigned NumReservedValues,
2520 InsertPosition Pos, Context &Ctx,
2521 const Twine &Name = "");
2522 /// For isa/dyn_cast.
2523 LLVM_ABI static bool classof(const Value *From);
2524
2527
2529 LLVMBBToBB BBGetter(Ctx);
2531 BBGetter);
2532 }
2534 LLVMBBToBB BBGetter(Ctx);
2536 BBGetter);
2537 }
2541
2543
2545
2546 unsigned getNumIncomingValues() const {
2547 return cast<llvm::PHINode>(Val)->getNumIncomingValues();
2548 }
2549 LLVM_ABI Value *getIncomingValue(unsigned Idx) const;
2550 LLVM_ABI void setIncomingValue(unsigned Idx, Value *V);
2551 static unsigned getOperandNumForIncomingValue(unsigned Idx) {
2553 }
2554 static unsigned getIncomingValueNumForOperand(unsigned Idx) {
2556 }
2557 LLVM_ABI BasicBlock *getIncomingBlock(unsigned Idx) const;
2558 LLVM_ABI BasicBlock *getIncomingBlock(const Use &U) const;
2559
2560 LLVM_ABI void setIncomingBlock(unsigned Idx, BasicBlock *BB);
2561
2562 LLVM_ABI void addIncoming(Value *V, BasicBlock *BB);
2563
2564 LLVM_ABI Value *removeIncomingValue(unsigned Idx);
2566
2567 LLVM_ABI int getBasicBlockIndex(const BasicBlock *BB) const;
2569
2571
2573 return cast<llvm::PHINode>(Val)->hasConstantOrUndefValue();
2574 }
2575 bool isComplete() const { return cast<llvm::PHINode>(Val)->isComplete(); }
2577 BasicBlock *New);
2579 // TODO: Implement
2580 // void copyIncomingBlocks(iterator_range<const_block_iterator> BBRange,
2581 // uint32_t ToIdx = 0)
2582};
2583
2584// Wraps a static function that takes a single Predicate parameter
2585// LLVMValType should be the type of the wrapped class
2586#define WRAP_STATIC_PREDICATE(FunctionName) \
2587 static auto FunctionName(Predicate P) { return LLVMValType::FunctionName(P); }
2588// Wraps a member function that takes no parameters
2589// LLVMValType should be the type of the wrapped class
2590#define WRAP_MEMBER(FunctionName) \
2591 auto FunctionName() const { return cast<LLVMValType>(Val)->FunctionName(); }
2592// Wraps both--a common idiom in the CmpInst classes
2593#define WRAP_BOTH(FunctionName) \
2594 WRAP_STATIC_PREDICATE(FunctionName) \
2595 WRAP_MEMBER(FunctionName)
2596
2597class CmpInst : public SingleLLVMInstructionImpl<llvm::CmpInst> {
2598protected:
2600 /// Use Context::createCmpInst(). Don't call the constructor directly.
2602 : SingleLLVMInstructionImpl(Id, Opc, CI, Ctx) {}
2603 friend Context; // for CmpInst()
2605 const Twine &Name, IRBuilder<> &Builder,
2606 Context &Ctx);
2607
2608public:
2610
2611 LLVM_ABI static Value *create(Predicate Pred, Value *S1, Value *S2,
2613 const Twine &Name = "");
2615 Value *S2,
2616 const Instruction *FlagsSource,
2618 const Twine &Name = "");
2620 LLVM_ABI void swapOperands();
2621
2622 WRAP_MEMBER(getPredicate);
2623 WRAP_BOTH(isFPPredicate);
2624 WRAP_BOTH(isIntPredicate);
2625 WRAP_STATIC_PREDICATE(getPredicateName);
2626 WRAP_BOTH(getInversePredicate);
2627 WRAP_BOTH(getOrderedPredicate);
2628 WRAP_BOTH(getUnorderedPredicate);
2629 WRAP_BOTH(getSwappedPredicate);
2630 WRAP_BOTH(isStrictPredicate);
2631 WRAP_BOTH(isNonStrictPredicate);
2632 WRAP_BOTH(getStrictPredicate);
2633 WRAP_BOTH(getNonStrictPredicate);
2634 WRAP_BOTH(getFlippedStrictnessPredicate);
2636 WRAP_BOTH(isEquality);
2637 WRAP_BOTH(isRelational);
2638 WRAP_BOTH(isSigned);
2639 WRAP_BOTH(isTrueWhenEqual);
2640 WRAP_BOTH(isFalseWhenEqual);
2641 WRAP_BOTH(isUnsigned);
2644
2645 /// Method for support type inquiry through isa, cast, and dyn_cast:
2646 static bool classof(const Value *From) {
2647 return From->getSubclassID() == ClassID::ICmp ||
2648 From->getSubclassID() == ClassID::FCmp;
2649 }
2650
2651 /// Create a result type for fcmp/icmp
2652 LLVM_ABI static Type *makeCmpResultType(Type *OpndType);
2653
2654#ifndef NDEBUG
2655 void dumpOS(raw_ostream &OS) const override;
2656 LLVM_DUMP_METHOD void dump() const;
2657#endif
2658};
2659
2660class ICmpInst : public CmpInst {
2661 /// Use Context::createICmpInst(). Don't call the constructor directly.
2662 ICmpInst(llvm::ICmpInst *CI, Context &Ctx)
2663 : CmpInst(CI, Ctx, ClassID::ICmp, Opcode::ICmp) {}
2664 friend class Context; // For constructor.
2665 using LLVMValType = llvm::ICmpInst;
2666
2667public:
2668 LLVM_ABI void swapOperands();
2669
2670 WRAP_BOTH(getSignedPredicate);
2671 WRAP_BOTH(getUnsignedPredicate);
2672 WRAP_BOTH(getFlippedSignednessPredicate);
2673 WRAP_BOTH(isEquality);
2675 WRAP_MEMBER(isRelational);
2680
2681 static std::optional<bool> isImpliedByMatchingCmp(CmpPredicate Pred1,
2682 CmpPredicate Pred2) {
2683 return llvm::ICmpInst::isImpliedByMatchingCmp(Pred1, Pred2);
2684 }
2685
2686 static auto predicates() { return llvm::ICmpInst::predicates(); }
2687 static bool compare(const APInt &LHS, const APInt &RHS,
2688 ICmpInst::Predicate Pred) {
2689 return llvm::ICmpInst::compare(LHS, RHS, Pred);
2690 }
2691
2692 static bool classof(const Value *From) {
2693 return From->getSubclassID() == ClassID::ICmp;
2694 }
2695};
2696
2697class FCmpInst : public CmpInst {
2698 /// Use Context::createFCmpInst(). Don't call the constructor directly.
2699 FCmpInst(llvm::FCmpInst *CI, Context &Ctx)
2700 : CmpInst(CI, Ctx, ClassID::FCmp, Opcode::FCmp) {}
2701 friend class Context; // For constructor.
2702 using LLVMValType = llvm::FCmpInst;
2703
2704public:
2705 LLVM_ABI void swapOperands();
2706
2707 WRAP_BOTH(isEquality);
2709 WRAP_MEMBER(isRelational);
2710
2711 static auto predicates() { return llvm::FCmpInst::predicates(); }
2712 static bool compare(const APFloat &LHS, const APFloat &RHS,
2713 FCmpInst::Predicate Pred) {
2714 return llvm::FCmpInst::compare(LHS, RHS, Pred);
2715 }
2716
2717 static bool classof(const Value *From) {
2718 return From->getSubclassID() == ClassID::FCmp;
2719 }
2720};
2721
2722#undef WRAP_STATIC_PREDICATE
2723#undef WRAP_MEMBER
2724#undef WRAP_BOTH
2725
2726/// An LLLVM Instruction that has no SandboxIR equivalent class gets mapped to
2727/// an OpaqueInstr.
2728class OpaqueInst : public SingleLLVMInstructionImpl<llvm::Instruction> {
2730 : SingleLLVMInstructionImpl(ClassID::Opaque, Opcode::Opaque, I, Ctx) {}
2732 : SingleLLVMInstructionImpl(SubclassID, Opcode::Opaque, I, Ctx) {}
2733 friend class Context; // For constructor.
2734
2735public:
2736 static bool classof(const sandboxir::Value *From) {
2737 return From->getSubclassID() == ClassID::Opaque;
2738 }
2739};
2740
2741} // namespace llvm::sandboxir
2742
2743#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< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:213
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:661
#define LLVM_ABI_FOR_TEST
Definition Compiler.h:218
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
MachineInstr unsigned OpIdx
#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
ArrayRef - 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:462
This is the base class for all instructions that perform data casts.
Definition InstrTypes.h:448
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
Definition InstrTypes.h:610
This class is the base class for the comparison instructions.
Definition InstrTypes.h:664
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:676
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:2811
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.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition ArrayRef.h:298
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.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Multiway switch.
CaseIteratorImpl< ConstCaseHandle > ConstCaseIt
static const unsigned DefaultPseudoIndex
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:154
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)
static LLVM_ABI Value * createCommon(Value *Cond, Value *True, Value *False, const Twine &Name, IRBuilder<> &Builder, Context &Ctx)
void dumpOS(raw_ostream &OS) const override
LLVM_DUMP_METHOD void dump() const
WRAP_BOTH(getNonStrictPredicate)
static LLVM_ABI Value * createWithCopiedFlags(Predicate Pred, Value *S1, Value *S2, const Instruction *FlagsSource, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static LLVM_ABI Type * makeCmpResultType(Type *OpndType)
Create a result type for fcmp/icmp.
static LLVM_ABI Value * create(Predicate Pred, Value *S1, Value *S2, InsertPosition Pos, Context &Ctx, const Twine &Name="")
LLVM_ABI void setPredicate(Predicate P)
WRAP_BOTH(isIntPredicate)
WRAP_STATIC_PREDICATE(isOrdered)
WRAP_BOTH(isNonStrictPredicate)
WRAP_BOTH(getSwappedPredicate)
WRAP_BOTH(getStrictPredicate)
WRAP_BOTH(isStrictPredicate)
WRAP_STATIC_PREDICATE(getPredicateName)
CmpInst(llvm::CmpInst *CI, Context &Ctx, ClassID Id, Opcode Opc)
Use Context::createCmpInst(). Don't call the constructor directly.
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 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
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.
static IRBuilder & setInsertPos(InsertPosition Pos)
Helper function for create().
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.
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:53
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.
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="")
LLVM_ABI void setVolatile(bool V)
Specify whether this is a volatile load or not.
LLVM_ABI Value * getPointerOperand() const
bool isVolatile() const
Return true if this is a load from a volatile memory location.
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.
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)
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
LLVM_ABI_FOR_TEST BlockT * getCaseSuccessor() const
CaseHandleImpl(Context &Ctx, LLVMCaseItT LLVMCaseIt)
LLVM_ABI_FOR_TEST ConstT * getCaseValue() const
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:47
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition Type.h:283
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 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:33
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:91
op_range operands()
Definition User.h:119
Use getOperandUseDefault(unsigned OpIdx, bool Verify) const
\Returns the Use edge that corresponds to OpIdx.
Definition User.cpp:58
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:68
llvm::Value * Val
The LLVM Value that corresponds to this SandboxIR Value.
Definition Value.h:108
ClassID getSubclassID() const
Definition Value.h:194
void dumpCommonSuffix(raw_ostream &OS) const
Definition Value.cpp:107
Context & Ctx
All values point to the context.
Definition Value.h:182
ClassID SubclassID
For isa/dyn_cast.
Definition Value.h:99
LLVM_ABI Type * getType() const
Definition Value.cpp:46
friend class UncondBrInst
Definition Value.h:122
void dumpCommonPrefix(raw_ostream &OS) const
Definition Value.cpp:100
friend class CondBrInst
Definition Value.h:123
#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
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
@ 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 SmallVector< Value *, 4 > getOperand(ArrayRef< Value * > Bndl, unsigned OpIdx)
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
@ Offset
Definition DWP.cpp:532
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:1947
#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