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