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