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