LLVM 20.0.0git
SandboxIR.h
Go to the documentation of this file.
1//===- SandboxIR.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// Sandbox IR is a lightweight overlay transactional IR on top of LLVM IR.
10// Features:
11// - You can save/rollback the state of the IR at any time.
12// - Any changes made to Sandbox IR will automatically update the underlying
13// LLVM IR so both IRs are always in sync.
14// - Feels like LLVM IR, similar API.
15//
16// SandboxIR forms a class hierarchy that resembles that of LLVM IR
17// but is in the `sandboxir` namespace:
18//
19// namespace sandboxir {
20//
21// Value -+- Argument
22// |
23// +- BasicBlock
24// |
25// +- User ------+- Constant ------ Function
26// |
27// +- Instruction -+- BinaryOperator
28// |
29// +- BranchInst
30// |
31// +- CastInst --------+- AddrSpaceCastInst
32// | |
33// | +- BitCastInst
34// | |
35// | +- FPExtInst
36// | |
37// | +- FPToSIInst
38// | |
39// | +- FPToUIInst
40// | |
41// | +- FPTruncInst
42// | |
43// | +- IntToPtrInst
44// | |
45// | +- PtrToIntInst
46// | |
47// | +- SExtInst
48// | |
49// | +- SIToFPInst
50// | |
51// | +- TruncInst
52// | |
53// | +- UIToFPInst
54// | |
55// | +- ZExtInst
56// |
57// +- CallBase -----------+- CallBrInst
58// | |
59// +- CmpInst +- CallInst
60// | |
61// +- ExtractElementInst +- InvokeInst
62// |
63// +- GetElementPtrInst
64// |
65// +- InsertElementInst
66// |
67// +- OpaqueInst
68// |
69// +- PHINode
70// |
71// +- ReturnInst
72// |
73// +- SelectInst
74// |
75// +- ShuffleVectorInst
76// |
77// +- StoreInst
78// |
79// +- UnaryInstruction -+- LoadInst
80// | |
81// | +- CastInst
82// |
83// +- UnaryOperator
84// |
85// +- UnreachableInst
86//
87// Use
88//
89// } // namespace sandboxir
90//
91
92#ifndef LLVM_SANDBOXIR_SANDBOXIR_H
93#define LLVM_SANDBOXIR_SANDBOXIR_H
94
95#include "llvm/IR/Function.h"
96#include "llvm/IR/IRBuilder.h"
97#include "llvm/IR/Instruction.h"
98#include "llvm/IR/User.h"
99#include "llvm/IR/Value.h"
101#include "llvm/SandboxIR/Use.h"
103#include <iterator>
104
105namespace llvm {
106
107namespace sandboxir {
108
109class BasicBlock;
110class ConstantInt;
111class Context;
112class Function;
113class Instruction;
114class SelectInst;
117class BranchInst;
118class UnaryInstruction;
119class LoadInst;
120class ReturnInst;
121class StoreInst;
122class User;
123class UnreachableInst;
124class Value;
125class CallBase;
126class CallInst;
127class InvokeInst;
128class CallBrInst;
130class CastInst;
131class PtrToIntInst;
132class BitCastInst;
133class AllocaInst;
134class CatchSwitchInst;
135class SwitchInst;
136class UnaryOperator;
137class BinaryOperator;
138class AtomicRMWInst;
140
141/// Iterator for the `Use` edges of a User's operands.
142/// \Returns the operand `Use` when dereferenced.
145 /// Don't let the user create a non-empty OperandUseIterator.
146 OperandUseIterator(const class Use &Use) : Use(Use) {}
147 friend class User; // For constructor
148#define DEF_INSTR(ID, OPC, CLASS) friend class CLASS; // For constructor
149#include "llvm/SandboxIR/SandboxIRValues.def"
150
151public:
152 using difference_type = std::ptrdiff_t;
156 using iterator_category = std::input_iterator_tag;
157
159 value_type operator*() const;
162 auto Copy = *this;
163 this->operator++();
164 return Copy;
165 }
167 return Use == Other.Use;
168 }
170 return !(*this == Other);
171 }
172 OperandUseIterator operator+(unsigned Num) const;
173 OperandUseIterator operator-(unsigned Num) const;
174 int operator-(const OperandUseIterator &Other) const;
175};
176
177/// Iterator for the `Use` edges of a Value's users.
178/// \Returns a `Use` when dereferenced.
181 /// Don't let the user create a non-empty UserUseIterator.
182 UserUseIterator(const class Use &Use) : Use(Use) {}
183 friend class Value; // For constructor
184
185public:
186 using difference_type = std::ptrdiff_t;
190 using iterator_category = std::input_iterator_tag;
191
192 UserUseIterator() = default;
193 value_type operator*() const { return Use; }
195 bool operator==(const UserUseIterator &Other) const {
196 return Use == Other.Use;
197 }
198 bool operator!=(const UserUseIterator &Other) const {
199 return !(*this == Other);
200 }
201 const sandboxir::Use &getUse() const { return Use; }
202};
203
204/// A SandboxIR Value has users. This is the base class.
205class Value {
206public:
207 enum class ClassID : unsigned {
208#define DEF_VALUE(ID, CLASS) ID,
209#define DEF_USER(ID, CLASS) ID,
210#define DEF_INSTR(ID, OPC, CLASS) ID,
211#include "llvm/SandboxIR/SandboxIRValues.def"
212 };
213
214protected:
215 static const char *getSubclassIDStr(ClassID ID) {
216 switch (ID) {
217#define DEF_VALUE(ID, CLASS) \
218 case ClassID::ID: \
219 return #ID;
220#define DEF_USER(ID, CLASS) \
221 case ClassID::ID: \
222 return #ID;
223#define DEF_INSTR(ID, OPC, CLASS) \
224 case ClassID::ID: \
225 return #ID;
226#include "llvm/SandboxIR/SandboxIRValues.def"
227 }
228 llvm_unreachable("Unimplemented ID");
229 }
230
231 /// For isa/dyn_cast.
233#ifndef NDEBUG
234 /// A unique ID used for forming the name (used for debugging).
235 unsigned UID;
236#endif
237 /// The LLVM Value that corresponds to this SandboxIR Value.
238 /// NOTE: Some sandboxir Instructions, like Packs, may include more than one
239 /// value and in these cases `Val` points to the last instruction in program
240 /// order.
241 llvm::Value *Val = nullptr;
242
243 friend class Context; // For getting `Val`.
244 friend class User; // For getting `Val`.
245 friend class Use; // For getting `Val`.
246 friend class SelectInst; // For getting `Val`.
247 friend class ExtractElementInst; // For getting `Val`.
248 friend class InsertElementInst; // For getting `Val`.
249 friend class BranchInst; // For getting `Val`.
250 friend class LoadInst; // For getting `Val`.
251 friend class StoreInst; // For getting `Val`.
252 friend class ReturnInst; // For getting `Val`.
253 friend class CallBase; // For getting `Val`.
254 friend class CallInst; // For getting `Val`.
255 friend class InvokeInst; // For getting `Val`.
256 friend class CallBrInst; // For getting `Val`.
257 friend class GetElementPtrInst; // For getting `Val`.
258 friend class CatchSwitchInst; // For getting `Val`.
259 friend class SwitchInst; // For getting `Val`.
260 friend class UnaryOperator; // For getting `Val`.
261 friend class BinaryOperator; // For getting `Val`.
262 friend class AtomicRMWInst; // For getting `Val`.
263 friend class AtomicCmpXchgInst; // For getting `Val`.
264 friend class AllocaInst; // For getting `Val`.
265 friend class CastInst; // For getting `Val`.
266 friend class PHINode; // For getting `Val`.
267 friend class UnreachableInst; // For getting `Val`.
268 friend class CatchSwitchAddHandler; // For `Val`.
269
270 /// All values point to the context.
272 // This is used by eraseFromParent().
273 void clearValue() { Val = nullptr; }
274 template <typename ItTy, typename SBTy> friend class LLVMOpUserItToSBTy;
275
277 /// Disable copies.
278 Value(const Value &) = delete;
279 Value &operator=(const Value &) = delete;
280
281public:
282 virtual ~Value() = default;
283 ClassID getSubclassID() const { return SubclassID; }
284
287
290 return const_cast<Value *>(this)->use_begin();
291 }
292 use_iterator use_end() { return use_iterator(Use(nullptr, nullptr, Ctx)); }
294 return const_cast<Value *>(this)->use_end();
295 }
296
298 return make_range<use_iterator>(use_begin(), use_end());
299 }
301 return make_range<const_use_iterator>(use_begin(), use_end());
302 }
303
304 /// Helper for mapped_iterator.
305 struct UseToUser {
306 User *operator()(const Use &Use) const { return &*Use.getUser(); }
307 };
308
311
314 return user_iterator(Use(nullptr, nullptr, Ctx), UseToUser());
315 }
317 return const_cast<Value *>(this)->user_begin();
318 }
320 return const_cast<Value *>(this)->user_end();
321 }
322
324 return make_range<user_iterator>(user_begin(), user_end());
325 }
327 return make_range<const_user_iterator>(user_begin(), user_end());
328 }
329 /// \Returns the number of user edges (not necessarily to unique users).
330 /// WARNING: This is a linear-time operation.
331 unsigned getNumUses() const;
332 /// Return true if this value has N uses or more.
333 /// This is logically equivalent to getNumUses() >= N.
334 /// WARNING: This can be expensive, as it is linear to the number of users.
335 bool hasNUsesOrMore(unsigned Num) const {
336 unsigned Cnt = 0;
337 for (auto It = use_begin(), ItE = use_end(); It != ItE; ++It) {
338 if (++Cnt >= Num)
339 return true;
340 }
341 return false;
342 }
343 /// Return true if this Value has exactly N uses.
344 bool hasNUses(unsigned Num) const {
345 unsigned Cnt = 0;
346 for (auto It = use_begin(), ItE = use_end(); It != ItE; ++It) {
347 if (++Cnt > Num)
348 return false;
349 }
350 return Cnt == Num;
351 }
352
353 Type *getType() const { return Val->getType(); }
354
355 Context &getContext() const { return Ctx; }
356
357 void replaceUsesWithIf(Value *OtherV,
358 llvm::function_ref<bool(const Use &)> ShouldReplace);
360
361 /// \Returns the LLVM IR name of the bottom-most LLVM value.
362 StringRef getName() const { return Val->getName(); }
363
364#ifndef NDEBUG
365 /// Should crash if there is something wrong with the instruction.
366 virtual void verify() const = 0;
367 /// Returns the unique id in the form 'SB<number>.' like 'SB1.'
368 std::string getUid() const;
369 virtual void dumpCommonHeader(raw_ostream &OS) const;
370 void dumpCommonFooter(raw_ostream &OS) const;
371 void dumpCommonPrefix(raw_ostream &OS) const;
372 void dumpCommonSuffix(raw_ostream &OS) const;
375 V.dumpOS(OS);
376 return OS;
377 }
378 virtual void dumpOS(raw_ostream &OS) const = 0;
379 LLVM_DUMP_METHOD void dump() const;
380#endif
381};
382
383/// Argument of a sandboxir::Function.
386 : sandboxir::Value(ClassID::Argument, Arg, Ctx) {}
387 friend class Context; // For constructor.
388
389public:
390 static bool classof(const sandboxir::Value *From) {
391 return From->getSubclassID() == ClassID::Argument;
392 }
393#ifndef NDEBUG
394 void verify() const final {
395 assert(isa<llvm::Argument>(Val) && "Expected Argument!");
396 }
397 void printAsOperand(raw_ostream &OS) const;
398 void dumpOS(raw_ostream &OS) const final;
399#endif
400};
401
402/// A sandboxir::User has operands.
403class User : public Value {
404protected:
406
407 /// \Returns the Use edge that corresponds to \p OpIdx.
408 /// Note: This is the default implementation that works for instructions that
409 /// match the underlying LLVM instruction. All others should use a different
410 /// implementation.
411 Use getOperandUseDefault(unsigned OpIdx, bool Verify) const;
412 /// \Returns the Use for the \p OpIdx'th operand. This is virtual to allow
413 /// instructions to deviate from the LLVM IR operands, which is a requirement
414 /// for sandboxir Instructions that consist of more than one LLVM Instruction.
415 virtual Use getOperandUseInternal(unsigned OpIdx, bool Verify) const = 0;
416 friend class OperandUseIterator; // for getOperandUseInternal()
417
418 /// The default implementation works only for single-LLVMIR-instruction
419 /// Users and only if they match exactly the LLVM instruction.
420 unsigned getUseOperandNoDefault(const Use &Use) const {
421 return Use.LLVMUse->getOperandNo();
422 }
423 /// \Returns the operand index of \p Use.
424 virtual unsigned getUseOperandNo(const Use &Use) const = 0;
425 friend unsigned Use::getOperandNo() const; // For getUseOperandNo()
426
427 void swapOperandsInternal(unsigned OpIdxA, unsigned OpIdxB) {
428 assert(OpIdxA < getNumOperands() && "OpIdxA out of bounds!");
429 assert(OpIdxB < getNumOperands() && "OpIdxB out of bounds!");
430 auto UseA = getOperandUse(OpIdxA);
431 auto UseB = getOperandUse(OpIdxB);
432 UseA.swap(UseB);
433 }
434
435#ifndef NDEBUG
436 void verifyUserOfLLVMUse(const llvm::Use &Use) const;
437#endif // NDEBUG
438
439public:
440 /// For isa/dyn_cast.
441 static bool classof(const Value *From);
446
448 assert(isa<llvm::User>(Val) && "Expect User value!");
449 return op_iterator(getOperandUseInternal(0, /*Verify=*/false));
450 }
451 virtual op_iterator op_end() {
452 assert(isa<llvm::User>(Val) && "Expect User value!");
453 return op_iterator(
454 getOperandUseInternal(getNumOperands(), /*Verify=*/false));
455 }
456 virtual const_op_iterator op_begin() const {
457 return const_cast<User *>(this)->op_begin();
458 }
459 virtual const_op_iterator op_end() const {
460 return const_cast<User *>(this)->op_end();
461 }
462
463 op_range operands() { return make_range<op_iterator>(op_begin(), op_end()); }
465 return make_range<const_op_iterator>(op_begin(), op_end());
466 }
467 Value *getOperand(unsigned OpIdx) const { return getOperandUse(OpIdx).get(); }
468 /// \Returns the operand edge for \p OpIdx. NOTE: This should also work for
469 /// OpIdx == getNumOperands(), which is used for op_end().
470 Use getOperandUse(unsigned OpIdx) const {
471 return getOperandUseInternal(OpIdx, /*Verify=*/true);
472 }
473 virtual unsigned getNumOperands() const {
474 return isa<llvm::User>(Val) ? cast<llvm::User>(Val)->getNumOperands() : 0;
475 }
476
477 virtual void setOperand(unsigned OperandIdx, Value *Operand);
478 /// Replaces any operands that match \p FromV with \p ToV. Returns whether any
479 /// operands were replaced.
480 bool replaceUsesOfWith(Value *FromV, Value *ToV);
481
482#ifndef NDEBUG
483 void verify() const override {
484 assert(isa<llvm::User>(Val) && "Expected User!");
485 }
486 void dumpCommonHeader(raw_ostream &OS) const final;
487 void dumpOS(raw_ostream &OS) const override {
488 // TODO: Remove this tmp implementation once we get the Instruction classes.
489 }
490#endif
491};
492
493class Constant : public sandboxir::User {
495 : sandboxir::User(ClassID::Constant, C, SBCtx) {}
497 : sandboxir::User(ID, C, SBCtx) {}
498 friend class ConstantInt; // For constructor.
499 friend class Function; // For constructor
500 friend class Context; // For constructor.
501 Use getOperandUseInternal(unsigned OpIdx, bool Verify) const override {
502 return getOperandUseDefault(OpIdx, Verify);
503 }
504
505public:
506 /// For isa/dyn_cast.
507 static bool classof(const sandboxir::Value *From) {
508 return From->getSubclassID() == ClassID::Constant ||
509 From->getSubclassID() == ClassID::ConstantInt ||
510 From->getSubclassID() == ClassID::Function;
511 }
513 unsigned getUseOperandNo(const Use &Use) const override {
515 }
516#ifndef NDEBUG
517 void verify() const override {
518 assert(isa<llvm::Constant>(Val) && "Expected Constant!");
519 }
520 void dumpOS(raw_ostream &OS) const override;
521#endif
522};
523
524class ConstantInt : public Constant {
526 : Constant(ClassID::ConstantInt, C, Ctx) {}
527 friend class Context; // For constructor.
528
529 Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
530 llvm_unreachable("ConstantInt has no operands!");
531 }
532
533public:
534 /// If Ty is a vector type, return a Constant with a splat of the given
535 /// value. Otherwise return a ConstantInt for the given value.
536 static ConstantInt *get(Type *Ty, uint64_t V, Context &Ctx,
537 bool IsSigned = false);
538
539 // TODO: Implement missing functions.
540
541 /// For isa/dyn_cast.
542 static bool classof(const sandboxir::Value *From) {
543 return From->getSubclassID() == ClassID::ConstantInt;
544 }
545 unsigned getUseOperandNo(const Use &Use) const override {
546 llvm_unreachable("ConstantInt has no operands!");
547 }
548#ifndef NDEBUG
549 void verify() const override {
550 assert(isa<llvm::ConstantInt>(Val) && "Expected a ConstantInst!");
551 }
552 void dumpOS(raw_ostream &OS) const override {
555 }
556#endif
557};
558
559/// Iterator for `Instruction`s in a `BasicBlock.
560/// \Returns an sandboxir::Instruction & when derereferenced.
562public:
563 using difference_type = std::ptrdiff_t;
567 using iterator_category = std::bidirectional_iterator_tag;
568
569private:
572 Context *Ctx;
573 pointer getInstr(llvm::BasicBlock::iterator It) const;
574
575public:
576 BBIterator() : BB(nullptr), Ctx(nullptr) {}
578 : BB(BB), It(It), Ctx(Ctx) {}
579 reference operator*() const { return *getInstr(It); }
582 auto Copy = *this;
583 ++*this;
584 return Copy;
585 }
588 auto Copy = *this;
589 --*this;
590 return Copy;
591 }
592 bool operator==(const BBIterator &Other) const {
593 assert(Ctx == Other.Ctx && "BBIterators in different context!");
594 return It == Other.It;
595 }
596 bool operator!=(const BBIterator &Other) const { return !(*this == Other); }
597 /// \Returns the SBInstruction that corresponds to this iterator, or null if
598 /// the instruction is not found in the IR-to-SandboxIR tables.
599 pointer get() const { return getInstr(It); }
600};
601
602/// Contains a list of sandboxir::Instruction's.
603class BasicBlock : public Value {
604 /// Builds a graph that contains all values in \p BB in their original form
605 /// i.e., no vectorization is taking place here.
606 void buildBasicBlockFromLLVMIR(llvm::BasicBlock *LLVMBB);
607 friend class Context; // For `buildBasicBlockFromIR`
608 friend class Instruction; // For LLVM Val.
609
611 : Value(ClassID::Block, BB, SBCtx) {
612 buildBasicBlockFromLLVMIR(BB);
613 }
614
615public:
616 ~BasicBlock() = default;
617 /// For isa/dyn_cast.
618 static bool classof(const Value *From) {
619 return From->getSubclassID() == Value::ClassID::Block;
620 }
621 Function *getParent() const;
623 iterator begin() const;
624 iterator end() const {
625 auto *BB = cast<llvm::BasicBlock>(Val);
626 return iterator(BB, BB->end(), &Ctx);
627 }
628 std::reverse_iterator<iterator> rbegin() const {
629 return std::make_reverse_iterator(end());
630 }
631 std::reverse_iterator<iterator> rend() const {
632 return std::make_reverse_iterator(begin());
633 }
634 Context &getContext() const { return Ctx; }
635 Instruction *getTerminator() const;
636 bool empty() const { return begin() == end(); }
637 Instruction &front() const;
638 Instruction &back() const;
639
640#ifndef NDEBUG
641 void verify() const final {
642 assert(isa<llvm::BasicBlock>(Val) && "Expected BasicBlock!");
643 }
644 void dumpOS(raw_ostream &OS) const final;
645#endif
646};
647
648/// A sandboxir::User with operands, opcode and linked with previous/next
649/// instructions in an instruction list.
651public:
652 enum class Opcode {
653#define OP(OPC) OPC,
654#define OPCODES(...) __VA_ARGS__
655#define DEF_INSTR(ID, OPC, CLASS) OPC
656#include "llvm/SandboxIR/SandboxIRValues.def"
657 };
658
659protected:
661 sandboxir::Context &SBCtx)
662 : sandboxir::User(ID, I, SBCtx), Opc(Opc) {}
663
665
666 /// A SandboxIR Instruction may map to multiple LLVM IR Instruction. This
667 /// returns its topmost LLVM IR instruction.
669 friend class SelectInst; // For getTopmostLLVMInstruction().
670 friend class ExtractElementInst; // For getTopmostLLVMInstruction().
671 friend class InsertElementInst; // For getTopmostLLVMInstruction().
672 friend class BranchInst; // For getTopmostLLVMInstruction().
673 friend class LoadInst; // For getTopmostLLVMInstruction().
674 friend class StoreInst; // For getTopmostLLVMInstruction().
675 friend class ReturnInst; // For getTopmostLLVMInstruction().
676 friend class CallInst; // For getTopmostLLVMInstruction().
677 friend class InvokeInst; // For getTopmostLLVMInstruction().
678 friend class CallBrInst; // For getTopmostLLVMInstruction().
679 friend class GetElementPtrInst; // For getTopmostLLVMInstruction().
680 friend class CatchSwitchInst; // For getTopmostLLVMInstruction().
681 friend class SwitchInst; // For getTopmostLLVMInstruction().
682 friend class UnaryOperator; // For getTopmostLLVMInstruction().
683 friend class BinaryOperator; // For getTopmostLLVMInstruction().
684 friend class AtomicRMWInst; // For getTopmostLLVMInstruction().
685 friend class AtomicCmpXchgInst; // For getTopmostLLVMInstruction().
686 friend class AllocaInst; // For getTopmostLLVMInstruction().
687 friend class CastInst; // For getTopmostLLVMInstruction().
688 friend class PHINode; // For getTopmostLLVMInstruction().
689 friend class UnreachableInst; // For getTopmostLLVMInstruction().
690
691 /// \Returns the LLVM IR Instructions that this SandboxIR maps to in program
692 /// order.
694 friend class EraseFromParent; // For getLLVMInstrs().
695
696public:
697 static const char *getOpcodeName(Opcode Opc);
698 /// This is used by BasicBlock::iterator.
699 virtual unsigned getNumOfIRInstrs() const = 0;
700 /// \Returns a BasicBlock::iterator for this Instruction.
701 BBIterator getIterator() const;
702 /// \Returns the next sandboxir::Instruction in the block, or nullptr if at
703 /// the end of the block.
704 Instruction *getNextNode() const;
705 /// \Returns the previous sandboxir::Instruction in the block, or nullptr if
706 /// at the beginning of the block.
707 Instruction *getPrevNode() const;
708 /// \Returns this Instruction's opcode. Note that SandboxIR has its own opcode
709 /// state to allow for new SandboxIR-specific instructions.
710 Opcode getOpcode() const { return Opc; }
711 /// Detach this from its parent BasicBlock without deleting it.
712 void removeFromParent();
713 /// Detach this Value from its parent and delete it.
714 void eraseFromParent();
715 /// Insert this detached instruction before \p BeforeI.
716 void insertBefore(Instruction *BeforeI);
717 /// Insert this detached instruction after \p AfterI.
718 void insertAfter(Instruction *AfterI);
719 /// Insert this detached instruction into \p BB at \p WhereIt.
720 void insertInto(BasicBlock *BB, const BBIterator &WhereIt);
721 /// Move this instruction to \p WhereIt.
722 void moveBefore(BasicBlock &BB, const BBIterator &WhereIt);
723 /// Move this instruction before \p Before.
725 moveBefore(*Before->getParent(), Before->getIterator());
726 }
727 /// Move this instruction after \p After.
729 moveBefore(*After->getParent(), std::next(After->getIterator()));
730 }
731 /// \Returns the BasicBlock containing this Instruction, or null if it is
732 /// detached.
733 BasicBlock *getParent() const;
734 /// For isa/dyn_cast.
735 static bool classof(const sandboxir::Value *From);
736
737 /// Determine whether the no signed wrap flag is set.
738 bool hasNoUnsignedWrap() const {
739 return cast<llvm::Instruction>(Val)->hasNoUnsignedWrap();
740 }
741 /// Set or clear the nuw flag on this instruction, which must be an operator
742 /// which supports this flag. See LangRef.html for the meaning of this flag.
743 void setHasNoUnsignedWrap(bool B = true);
744 /// Determine whether the no signed wrap flag is set.
745 bool hasNoSignedWrap() const {
746 return cast<llvm::Instruction>(Val)->hasNoSignedWrap();
747 }
748 /// Set or clear the nsw flag on this instruction, which must be an operator
749 /// which supports this flag. See LangRef.html for the meaning of this flag.
750 void setHasNoSignedWrap(bool B = true);
751 /// Determine whether all fast-math-flags are set.
752 bool isFast() const { return cast<llvm::Instruction>(Val)->isFast(); }
753 /// Set or clear all fast-math-flags on this instruction, which must be an
754 /// operator which supports this flag. See LangRef.html for the meaning of
755 /// this flag.
756 void setFast(bool B);
757 /// Determine whether the allow-reassociation flag is set.
758 bool hasAllowReassoc() const {
759 return cast<llvm::Instruction>(Val)->hasAllowReassoc();
760 }
761 /// Set or clear the reassociation flag on this instruction, which must be
762 /// an operator which supports this flag. See LangRef.html for the meaning of
763 /// this flag.
764 void setHasAllowReassoc(bool B);
765 /// Determine whether the exact flag is set.
766 bool isExact() const { return cast<llvm::Instruction>(Val)->isExact(); }
767 /// Set or clear the exact flag on this instruction, which must be an operator
768 /// which supports this flag. See LangRef.html for the meaning of this flag.
769 void setIsExact(bool B = true);
770 /// Determine whether the no-NaNs flag is set.
771 bool hasNoNaNs() const { return cast<llvm::Instruction>(Val)->hasNoNaNs(); }
772 /// Set or clear the no-nans flag on this instruction, which must be an
773 /// operator which supports this flag. See LangRef.html for the meaning of
774 /// this flag.
775 void setHasNoNaNs(bool B);
776 /// Determine whether the no-infs flag is set.
777 bool hasNoInfs() const { return cast<llvm::Instruction>(Val)->hasNoInfs(); }
778 /// Set or clear the no-infs flag on this instruction, which must be an
779 /// operator which supports this flag. See LangRef.html for the meaning of
780 /// this flag.
781 void setHasNoInfs(bool B);
782 /// Determine whether the no-signed-zeros flag is set.
783 bool hasNoSignedZeros() const {
784 return cast<llvm::Instruction>(Val)->hasNoSignedZeros();
785 }
786 /// Set or clear the no-signed-zeros flag on this instruction, which must be
787 /// an operator which supports this flag. See LangRef.html for the meaning of
788 /// this flag.
789 void setHasNoSignedZeros(bool B);
790 /// Determine whether the allow-reciprocal flag is set.
791 bool hasAllowReciprocal() const {
792 return cast<llvm::Instruction>(Val)->hasAllowReciprocal();
793 }
794 /// Set or clear the allow-reciprocal flag on this instruction, which must be
795 /// an operator which supports this flag. See LangRef.html for the meaning of
796 /// this flag.
797 void setHasAllowReciprocal(bool B);
798 /// Determine whether the allow-contract flag is set.
799 bool hasAllowContract() const {
800 return cast<llvm::Instruction>(Val)->hasAllowContract();
801 }
802 /// Set or clear the allow-contract flag on this instruction, which must be
803 /// an operator which supports this flag. See LangRef.html for the meaning of
804 /// this flag.
805 void setHasAllowContract(bool B);
806 /// Determine whether the approximate-math-functions flag is set.
807 bool hasApproxFunc() const {
808 return cast<llvm::Instruction>(Val)->hasApproxFunc();
809 }
810 /// Set or clear the approximate-math-functions flag on this instruction,
811 /// which must be an operator which supports this flag. See LangRef.html for
812 /// the meaning of this flag.
813 void setHasApproxFunc(bool B);
814 /// Convenience function for getting all the fast-math flags, which must be an
815 /// operator which supports these flags. See LangRef.html for the meaning of
816 /// these flags.
818 return cast<llvm::Instruction>(Val)->getFastMathFlags();
819 }
820 /// Convenience function for setting multiple fast-math flags on this
821 /// instruction, which must be an operator which supports these flags. See
822 /// LangRef.html for the meaning of these flags.
824 /// Convenience function for transferring all fast-math flag values to this
825 /// instruction, which must be an operator which supports these flags. See
826 /// LangRef.html for the meaning of these flags.
828
829#ifndef NDEBUG
830 void dumpOS(raw_ostream &OS) const override;
831#endif
832};
833
834/// Instructions that contain a single LLVM Instruction can inherit from this.
835template <typename LLVMT> class SingleLLVMInstructionImpl : public Instruction {
837 sandboxir::Context &SBCtx)
838 : Instruction(ID, Opc, I, SBCtx) {}
839
840 // All instructions are friends with this so they can call the constructor.
841#define DEF_INSTR(ID, OPC, CLASS) friend class CLASS;
842#include "llvm/SandboxIR/SandboxIRValues.def"
843 friend class UnaryInstruction;
844 friend class CallBase;
845
846 Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
847 return getOperandUseDefault(OpIdx, Verify);
848 }
849 SmallVector<llvm::Instruction *, 1> getLLVMInstrs() const final {
850 return {cast<llvm::Instruction>(Val)};
851 }
852
853public:
854 unsigned getUseOperandNo(const Use &Use) const final {
856 }
857 unsigned getNumOfIRInstrs() const final { return 1u; }
858#ifndef NDEBUG
859 void verify() const final { assert(isa<LLVMT>(Val) && "Expected LLVMT!"); }
860 void dumpOS(raw_ostream &OS) const override {
863 }
864#endif
865};
866
867class SelectInst : public SingleLLVMInstructionImpl<llvm::SelectInst> {
868 /// Use Context::createSelectInst(). Don't call the
869 /// constructor directly.
871 : SingleLLVMInstructionImpl(ClassID::Select, Opcode::Select, CI, Ctx) {}
872 friend Context; // for SelectInst()
873 static Value *createCommon(Value *Cond, Value *True, Value *False,
874 const Twine &Name, IRBuilder<> &Builder,
875 Context &Ctx);
876
877public:
878 static Value *create(Value *Cond, Value *True, Value *False,
879 Instruction *InsertBefore, Context &Ctx,
880 const Twine &Name = "");
881 static Value *create(Value *Cond, Value *True, Value *False,
882 BasicBlock *InsertAtEnd, Context &Ctx,
883 const Twine &Name = "");
884 Value *getCondition() { return getOperand(0); }
885 Value *getTrueValue() { return getOperand(1); }
887
888 void setCondition(Value *New) { setOperand(0, New); }
889 void setTrueValue(Value *New) { setOperand(1, New); }
890 void setFalseValue(Value *New) { setOperand(2, New); }
891 void swapValues() { cast<llvm::SelectInst>(Val)->swapValues(); }
892 /// For isa/dyn_cast.
893 static bool classof(const Value *From);
894};
895
897 : public SingleLLVMInstructionImpl<llvm::InsertElementInst> {
898 /// Use Context::createInsertElementInst() instead.
900 : SingleLLVMInstructionImpl(ClassID::InsertElement, Opcode::InsertElement,
901 I, Ctx) {}
902 friend class Context; // For accessing the constructor in create*()
903
904public:
905 static Value *create(Value *Vec, Value *NewElt, Value *Idx,
906 Instruction *InsertBefore, Context &Ctx,
907 const Twine &Name = "");
908 static Value *create(Value *Vec, Value *NewElt, Value *Idx,
909 BasicBlock *InsertAtEnd, Context &Ctx,
910 const Twine &Name = "");
911 static bool classof(const Value *From) {
912 return From->getSubclassID() == ClassID::InsertElement;
913 }
914 static bool isValidOperands(const Value *Vec, const Value *NewElt,
915 const Value *Idx) {
917 Idx->Val);
918 }
919};
920
922 : public SingleLLVMInstructionImpl<llvm::ExtractElementInst> {
923 /// Use Context::createExtractElementInst() instead.
925 : SingleLLVMInstructionImpl(ClassID::ExtractElement,
926 Opcode::ExtractElement, I, Ctx) {}
927 friend class Context; // For accessing the constructor in
928 // create*()
929
930public:
931 static Value *create(Value *Vec, Value *Idx, Instruction *InsertBefore,
932 Context &Ctx, const Twine &Name = "");
933 static Value *create(Value *Vec, Value *Idx, BasicBlock *InsertAtEnd,
934 Context &Ctx, const Twine &Name = "");
935 static bool classof(const Value *From) {
936 return From->getSubclassID() == ClassID::ExtractElement;
937 }
938
939 static bool isValidOperands(const Value *Vec, const Value *Idx) {
941 }
944 const Value *getVectorOperand() const { return getOperand(0); }
945 const Value *getIndexOperand() const { return getOperand(1); }
946
948 return cast<VectorType>(getVectorOperand()->getType());
949 }
950};
951
952class BranchInst : public SingleLLVMInstructionImpl<llvm::BranchInst> {
953 /// Use Context::createBranchInst(). Don't call the constructor directly.
955 : SingleLLVMInstructionImpl(ClassID::Br, Opcode::Br, BI, Ctx) {}
956 friend Context; // for BranchInst()
957
958public:
959 static BranchInst *create(BasicBlock *IfTrue, Instruction *InsertBefore,
960 Context &Ctx);
961 static BranchInst *create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd,
962 Context &Ctx);
963 static BranchInst *create(BasicBlock *IfTrue, BasicBlock *IfFalse,
964 Value *Cond, Instruction *InsertBefore,
965 Context &Ctx);
966 static BranchInst *create(BasicBlock *IfTrue, BasicBlock *IfFalse,
967 Value *Cond, BasicBlock *InsertAtEnd, Context &Ctx);
968 /// For isa/dyn_cast.
969 static bool classof(const Value *From);
970 bool isUnconditional() const {
971 return cast<llvm::BranchInst>(Val)->isUnconditional();
972 }
973 bool isConditional() const {
974 return cast<llvm::BranchInst>(Val)->isConditional();
975 }
976 Value *getCondition() const;
977 void setCondition(Value *V) { setOperand(0, V); }
978 unsigned getNumSuccessors() const { return 1 + isConditional(); }
979 BasicBlock *getSuccessor(unsigned SuccIdx) const;
980 void setSuccessor(unsigned Idx, BasicBlock *NewSucc);
982
983private:
984 struct LLVMBBToSBBB {
985 Context &Ctx;
986 LLVMBBToSBBB(Context &Ctx) : Ctx(Ctx) {}
987 BasicBlock *operator()(llvm::BasicBlock *BB) const;
988 };
989
990 struct ConstLLVMBBToSBBB {
991 Context &Ctx;
992 ConstLLVMBBToSBBB(Context &Ctx) : Ctx(Ctx) {}
993 const BasicBlock *operator()(const llvm::BasicBlock *BB) const;
994 };
995
996public:
1001 cast<llvm::BranchInst>(Val)->successors();
1002 LLVMBBToSBBB BBMap(Ctx);
1003 sb_succ_op_iterator MappedBegin = map_iterator(LLVMRange.begin(), BBMap);
1004 sb_succ_op_iterator MappedEnd = map_iterator(LLVMRange.end(), BBMap);
1005 return make_range(MappedBegin, MappedEnd);
1006 }
1007
1010 ConstLLVMBBToSBBB>;
1013 static_cast<const llvm::BranchInst *>(cast<llvm::BranchInst>(Val))
1014 ->successors();
1015 ConstLLVMBBToSBBB ConstBBMap(Ctx);
1016 const_sb_succ_op_iterator ConstMappedBegin =
1017 map_iterator(ConstLLVMRange.begin(), ConstBBMap);
1018 const_sb_succ_op_iterator ConstMappedEnd =
1019 map_iterator(ConstLLVMRange.end(), ConstBBMap);
1020 return make_range(ConstMappedBegin, ConstMappedEnd);
1021 }
1022};
1023
1024/// An abstract class, parent of unary instructions.
1026 : public SingleLLVMInstructionImpl<llvm::UnaryInstruction> {
1027protected:
1029 Context &Ctx)
1030 : SingleLLVMInstructionImpl(ID, Opc, LLVMI, Ctx) {}
1031
1032public:
1033 static bool classof(const Instruction *I) {
1034 return isa<LoadInst>(I) || isa<CastInst>(I);
1035 }
1036 static bool classof(const Value *V) {
1037 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1038 }
1039};
1040
1041class LoadInst final : public UnaryInstruction {
1042 /// Use LoadInst::create() instead of calling the constructor.
1044 : UnaryInstruction(ClassID::Load, Opcode::Load, LI, Ctx) {}
1045 friend Context; // for LoadInst()
1046
1047public:
1048 /// Return true if this is a load from a volatile memory location.
1049 bool isVolatile() const { return cast<llvm::LoadInst>(Val)->isVolatile(); }
1050 /// Specify whether this is a volatile load or not.
1051 void setVolatile(bool V);
1052
1053 static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align,
1054 Instruction *InsertBefore, Context &Ctx,
1055 const Twine &Name = "");
1056 static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align,
1057 Instruction *InsertBefore, bool IsVolatile,
1058 Context &Ctx, const Twine &Name = "");
1059 static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align,
1060 BasicBlock *InsertAtEnd, Context &Ctx,
1061 const Twine &Name = "");
1062 static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align,
1063 BasicBlock *InsertAtEnd, bool IsVolatile,
1064 Context &Ctx, const Twine &Name = "");
1065
1066 /// For isa/dyn_cast.
1067 static bool classof(const Value *From);
1068 Value *getPointerOperand() const;
1069 Align getAlign() const { return cast<llvm::LoadInst>(Val)->getAlign(); }
1070 bool isUnordered() const { return cast<llvm::LoadInst>(Val)->isUnordered(); }
1071 bool isSimple() const { return cast<llvm::LoadInst>(Val)->isSimple(); }
1072};
1073
1074class StoreInst final : public SingleLLVMInstructionImpl<llvm::StoreInst> {
1075 /// Use StoreInst::create().
1077 : SingleLLVMInstructionImpl(ClassID::Store, Opcode::Store, SI, Ctx) {}
1078 friend Context; // for StoreInst()
1079
1080public:
1081 /// Return true if this is a store from a volatile memory location.
1082 bool isVolatile() const { return cast<llvm::StoreInst>(Val)->isVolatile(); }
1083 /// Specify whether this is a volatile store or not.
1084 void setVolatile(bool V);
1085
1087 Instruction *InsertBefore, Context &Ctx);
1089 Instruction *InsertBefore, bool IsVolatile,
1090 Context &Ctx);
1092 BasicBlock *InsertAtEnd, Context &Ctx);
1094 BasicBlock *InsertAtEnd, bool IsVolatile,
1095 Context &Ctx);
1096 /// For isa/dyn_cast.
1097 static bool classof(const Value *From);
1098 Value *getValueOperand() const;
1099 Value *getPointerOperand() const;
1100 Align getAlign() const { return cast<llvm::StoreInst>(Val)->getAlign(); }
1101 bool isSimple() const { return cast<llvm::StoreInst>(Val)->isSimple(); }
1102 bool isUnordered() const { return cast<llvm::StoreInst>(Val)->isUnordered(); }
1103};
1104
1105class UnreachableInst final : public Instruction {
1106 /// Use UnreachableInst::create() instead of calling the constructor.
1108 : Instruction(ClassID::Unreachable, Opcode::Unreachable, I, Ctx) {}
1109 friend Context;
1110 Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
1111 return getOperandUseDefault(OpIdx, Verify);
1112 }
1113 SmallVector<llvm::Instruction *, 1> getLLVMInstrs() const final {
1114 return {cast<llvm::Instruction>(Val)};
1115 }
1116
1117public:
1118 static UnreachableInst *create(Instruction *InsertBefore, Context &Ctx);
1119 static UnreachableInst *create(BasicBlock *InsertAtEnd, Context &Ctx);
1120 static bool classof(const Value *From);
1121 unsigned getNumSuccessors() const { return 0; }
1122 unsigned getUseOperandNo(const Use &Use) const final {
1123 llvm_unreachable("UnreachableInst has no operands!");
1124 }
1125 unsigned getNumOfIRInstrs() const final { return 1u; }
1126};
1127
1128class ReturnInst final : public SingleLLVMInstructionImpl<llvm::ReturnInst> {
1129 /// Use ReturnInst::create() instead of calling the constructor.
1131 : SingleLLVMInstructionImpl(ClassID::Ret, Opcode::Ret, I, Ctx) {}
1133 : SingleLLVMInstructionImpl(SubclassID, Opcode::Ret, I, Ctx) {}
1134 friend class Context; // For accessing the constructor in create*()
1135 static ReturnInst *createCommon(Value *RetVal, IRBuilder<> &Builder,
1136 Context &Ctx);
1137
1138public:
1139 static ReturnInst *create(Value *RetVal, Instruction *InsertBefore,
1140 Context &Ctx);
1141 static ReturnInst *create(Value *RetVal, BasicBlock *InsertAtEnd,
1142 Context &Ctx);
1143 static bool classof(const Value *From) {
1144 return From->getSubclassID() == ClassID::Ret;
1145 }
1146 /// \Returns null if there is no return value.
1147 Value *getReturnValue() const;
1148};
1149
1150class CallBase : public SingleLLVMInstructionImpl<llvm::CallBase> {
1153 friend class CallInst; // For constructor.
1154 friend class InvokeInst; // For constructor.
1155 friend class CallBrInst; // For constructor.
1156
1157public:
1158 static bool classof(const Value *From) {
1159 auto Opc = From->getSubclassID();
1160 return Opc == Instruction::ClassID::Call ||
1161 Opc == Instruction::ClassID::Invoke ||
1162 Opc == Instruction::ClassID::CallBr;
1163 }
1164
1166 return cast<llvm::CallBase>(Val)->getFunctionType();
1167 }
1168
1171 return const_cast<CallBase *>(this)->data_operands_begin();
1172 }
1174 auto *LLVMCB = cast<llvm::CallBase>(Val);
1175 auto Dist = LLVMCB->data_operands_end() - LLVMCB->data_operands_begin();
1176 return op_begin() + Dist;
1177 }
1179 auto *LLVMCB = cast<llvm::CallBase>(Val);
1180 auto Dist = LLVMCB->data_operands_end() - LLVMCB->data_operands_begin();
1181 return op_begin() + Dist;
1182 }
1185 }
1188 }
1189 bool data_operands_empty() const {
1191 }
1192 unsigned data_operands_size() const {
1193 return std::distance(data_operands_begin(), data_operands_end());
1194 }
1195 bool isDataOperand(Use U) const {
1196 assert(this == U.getUser() &&
1197 "Only valid to query with a use of this instruction!");
1198 return cast<llvm::CallBase>(Val)->isDataOperand(U.LLVMUse);
1199 }
1200 unsigned getDataOperandNo(Use U) const {
1201 assert(isDataOperand(U) && "Data operand # out of range!");
1202 return cast<llvm::CallBase>(Val)->getDataOperandNo(U.LLVMUse);
1203 }
1204
1205 /// Return the total number operands (not operand bundles) used by
1206 /// every operand bundle in this OperandBundleUser.
1207 unsigned getNumTotalBundleOperands() const {
1208 return cast<llvm::CallBase>(Val)->getNumTotalBundleOperands();
1209 }
1210
1215 }
1217 return const_cast<CallBase *>(this)->arg_end();
1218 }
1220 return make_range(arg_begin(), arg_end());
1221 }
1223 return make_range(arg_begin(), arg_end());
1224 }
1225 bool arg_empty() const { return arg_end() == arg_begin(); }
1226 unsigned arg_size() const { return arg_end() - arg_begin(); }
1227
1228 Value *getArgOperand(unsigned OpIdx) const {
1229 assert(OpIdx < arg_size() && "Out of bounds!");
1230 return getOperand(OpIdx);
1231 }
1232 void setArgOperand(unsigned OpIdx, Value *NewOp) {
1233 assert(OpIdx < arg_size() && "Out of bounds!");
1234 setOperand(OpIdx, NewOp);
1235 }
1236
1237 Use getArgOperandUse(unsigned Idx) const {
1238 assert(Idx < arg_size() && "Out of bounds!");
1239 return getOperandUse(Idx);
1240 }
1242 assert(Idx < arg_size() && "Out of bounds!");
1243 return getOperandUse(Idx);
1244 }
1245
1246 bool isArgOperand(Use U) const {
1247 return cast<llvm::CallBase>(Val)->isArgOperand(U.LLVMUse);
1248 }
1249 unsigned getArgOperandNo(Use U) const {
1250 return cast<llvm::CallBase>(Val)->getArgOperandNo(U.LLVMUse);
1251 }
1252 bool hasArgument(const Value *V) const { return is_contained(args(), V); }
1253
1254 Value *getCalledOperand() const;
1255 Use getCalledOperandUse() const;
1256
1257 Function *getCalledFunction() const;
1258 bool isIndirectCall() const {
1259 return cast<llvm::CallBase>(Val)->isIndirectCall();
1260 }
1261 bool isCallee(Use U) const {
1262 return cast<llvm::CallBase>(Val)->isCallee(U.LLVMUse);
1263 }
1265 const Function *getCaller() const {
1266 return const_cast<CallBase *>(this)->getCaller();
1267 }
1268 bool isMustTailCall() const {
1269 return cast<llvm::CallBase>(Val)->isMustTailCall();
1270 }
1271 bool isTailCall() const { return cast<llvm::CallBase>(Val)->isTailCall(); }
1273 return cast<llvm::CallBase>(Val)->getIntrinsicID();
1274 }
1278 return cast<llvm::CallBase>(Val)->getCallingConv();
1279 }
1280 bool isInlineAsm() const { return cast<llvm::CallBase>(Val)->isInlineAsm(); }
1281};
1282
1283class CallInst final : public CallBase {
1284 /// Use Context::createCallInst(). Don't call the
1285 /// constructor directly.
1287 : CallBase(ClassID::Call, Opcode::Call, I, Ctx) {}
1288 friend class Context; // For accessing the constructor in
1289 // create*()
1290
1291public:
1292 static CallInst *create(FunctionType *FTy, Value *Func,
1293 ArrayRef<Value *> Args, BBIterator WhereIt,
1294 BasicBlock *WhereBB, Context &Ctx,
1295 const Twine &NameStr = "");
1296 static CallInst *create(FunctionType *FTy, Value *Func,
1297 ArrayRef<Value *> Args, Instruction *InsertBefore,
1298 Context &Ctx, const Twine &NameStr = "");
1299 static CallInst *create(FunctionType *FTy, Value *Func,
1300 ArrayRef<Value *> Args, BasicBlock *InsertAtEnd,
1301 Context &Ctx, const Twine &NameStr = "");
1302
1303 static bool classof(const Value *From) {
1304 return From->getSubclassID() == ClassID::Call;
1305 }
1306};
1307
1308class InvokeInst final : public CallBase {
1309 /// Use Context::createInvokeInst(). Don't call the
1310 /// constructor directly.
1312 : CallBase(ClassID::Invoke, Opcode::Invoke, I, Ctx) {}
1313 friend class Context; // For accessing the constructor in
1314 // create*()
1315
1316public:
1317 static InvokeInst *create(FunctionType *FTy, Value *Func,
1318 BasicBlock *IfNormal, BasicBlock *IfException,
1319 ArrayRef<Value *> Args, BBIterator WhereIt,
1320 BasicBlock *WhereBB, Context &Ctx,
1321 const Twine &NameStr = "");
1322 static InvokeInst *create(FunctionType *FTy, Value *Func,
1323 BasicBlock *IfNormal, BasicBlock *IfException,
1324 ArrayRef<Value *> Args, Instruction *InsertBefore,
1325 Context &Ctx, const Twine &NameStr = "");
1326 static InvokeInst *create(FunctionType *FTy, Value *Func,
1327 BasicBlock *IfNormal, BasicBlock *IfException,
1328 ArrayRef<Value *> Args, BasicBlock *InsertAtEnd,
1329 Context &Ctx, const Twine &NameStr = "");
1330
1331 static bool classof(const Value *From) {
1332 return From->getSubclassID() == ClassID::Invoke;
1333 }
1334 BasicBlock *getNormalDest() const;
1335 BasicBlock *getUnwindDest() const;
1336 void setNormalDest(BasicBlock *BB);
1337 void setUnwindDest(BasicBlock *BB);
1338 // TODO: Return a `LandingPadInst` once implemented.
1340 BasicBlock *getSuccessor(unsigned SuccIdx) const;
1341 void setSuccessor(unsigned SuccIdx, BasicBlock *NewSucc) {
1342 assert(SuccIdx < 2 && "Successor # out of range for invoke!");
1343 if (SuccIdx == 0)
1344 setNormalDest(NewSucc);
1345 else
1346 setUnwindDest(NewSucc);
1347 }
1348 unsigned getNumSuccessors() const {
1349 return cast<llvm::InvokeInst>(Val)->getNumSuccessors();
1350 }
1351};
1352
1353class CallBrInst final : public CallBase {
1354 /// Use Context::createCallBrInst(). Don't call the
1355 /// constructor directly.
1357 : CallBase(ClassID::CallBr, Opcode::CallBr, I, Ctx) {}
1358 friend class Context; // For accessing the constructor in
1359 // create*()
1360
1361public:
1362 static CallBrInst *create(FunctionType *FTy, Value *Func,
1363 BasicBlock *DefaultDest,
1364 ArrayRef<BasicBlock *> IndirectDests,
1365 ArrayRef<Value *> Args, BBIterator WhereIt,
1366 BasicBlock *WhereBB, Context &Ctx,
1367 const Twine &NameStr = "");
1368 static CallBrInst *create(FunctionType *FTy, Value *Func,
1369 BasicBlock *DefaultDest,
1370 ArrayRef<BasicBlock *> IndirectDests,
1371 ArrayRef<Value *> Args, Instruction *InsertBefore,
1372 Context &Ctx, const Twine &NameStr = "");
1373 static CallBrInst *create(FunctionType *FTy, Value *Func,
1374 BasicBlock *DefaultDest,
1375 ArrayRef<BasicBlock *> IndirectDests,
1376 ArrayRef<Value *> Args, BasicBlock *InsertAtEnd,
1377 Context &Ctx, const Twine &NameStr = "");
1378 static bool classof(const Value *From) {
1379 return From->getSubclassID() == ClassID::CallBr;
1380 }
1381 unsigned getNumIndirectDests() const {
1382 return cast<llvm::CallBrInst>(Val)->getNumIndirectDests();
1383 }
1384 Value *getIndirectDestLabel(unsigned Idx) const;
1385 Value *getIndirectDestLabelUse(unsigned Idx) const;
1386 BasicBlock *getDefaultDest() const;
1387 BasicBlock *getIndirectDest(unsigned Idx) const;
1389 void setDefaultDest(BasicBlock *BB);
1390 void setIndirectDest(unsigned Idx, BasicBlock *BB);
1391 BasicBlock *getSuccessor(unsigned Idx) const;
1392 unsigned getNumSuccessors() const {
1393 return cast<llvm::CallBrInst>(Val)->getNumSuccessors();
1394 }
1395};
1396
1398 : public SingleLLVMInstructionImpl<llvm::GetElementPtrInst> {
1399 /// Use Context::createGetElementPtrInst(). Don't call
1400 /// the constructor directly.
1402 : SingleLLVMInstructionImpl(ClassID::GetElementPtr, Opcode::GetElementPtr,
1403 I, Ctx) {}
1405 : SingleLLVMInstructionImpl(SubclassID, Opcode::GetElementPtr, I, Ctx) {}
1406 friend class Context; // For accessing the constructor in
1407 // create*()
1408
1409public:
1410 static Value *create(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
1411 BBIterator WhereIt, BasicBlock *WhereBB, Context &Ctx,
1412 const Twine &NameStr = "");
1413 static Value *create(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
1414 Instruction *InsertBefore, Context &Ctx,
1415 const Twine &NameStr = "");
1416 static Value *create(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
1417 BasicBlock *InsertAtEnd, Context &Ctx,
1418 const Twine &NameStr = "");
1419
1420 static bool classof(const Value *From) {
1421 return From->getSubclassID() == ClassID::GetElementPtr;
1422 }
1423
1425 return cast<llvm::GetElementPtrInst>(Val)->getSourceElementType();
1426 }
1428 return cast<llvm::GetElementPtrInst>(Val)->getResultElementType();
1429 }
1430 unsigned getAddressSpace() const {
1431 return cast<llvm::GetElementPtrInst>(Val)->getAddressSpace();
1432 }
1433
1434 inline op_iterator idx_begin() { return op_begin() + 1; }
1436 return const_cast<GetElementPtrInst *>(this)->idx_begin();
1437 }
1438 inline op_iterator idx_end() { return op_end(); }
1440 return const_cast<GetElementPtrInst *>(this)->idx_end();
1441 }
1443 return make_range(idx_begin(), idx_end());
1444 }
1446 return const_cast<GetElementPtrInst *>(this)->indices();
1447 }
1448
1449 Value *getPointerOperand() const;
1450 static unsigned getPointerOperandIndex() {
1452 }
1454 return cast<llvm::GetElementPtrInst>(Val)->getPointerOperandType();
1455 }
1456 unsigned getPointerAddressSpace() const {
1457 return cast<llvm::GetElementPtrInst>(Val)->getPointerAddressSpace();
1458 }
1459 unsigned getNumIndices() const {
1460 return cast<llvm::GetElementPtrInst>(Val)->getNumIndices();
1461 }
1462 bool hasIndices() const {
1463 return cast<llvm::GetElementPtrInst>(Val)->hasIndices();
1464 }
1466 return cast<llvm::GetElementPtrInst>(Val)->hasAllConstantIndices();
1467 }
1469 return cast<llvm::GetElementPtrInst>(Val)->getNoWrapFlags();
1470 }
1471 bool isInBounds() const {
1472 return cast<llvm::GetElementPtrInst>(Val)->isInBounds();
1473 }
1475 return cast<llvm::GetElementPtrInst>(Val)->hasNoUnsignedSignedWrap();
1476 }
1477 bool hasNoUnsignedWrap() const {
1478 return cast<llvm::GetElementPtrInst>(Val)->hasNoUnsignedWrap();
1479 }
1481 return cast<llvm::GetElementPtrInst>(Val)->accumulateConstantOffset(DL,
1482 Offset);
1483 }
1484 // TODO: Add missing member functions.
1485};
1486
1488 : public SingleLLVMInstructionImpl<llvm::CatchSwitchInst> {
1489public:
1491 : SingleLLVMInstructionImpl(ClassID::CatchSwitch, Opcode::CatchSwitch,
1492 CSI, Ctx) {}
1493
1494 static CatchSwitchInst *create(Value *ParentPad, BasicBlock *UnwindBB,
1495 unsigned NumHandlers, BBIterator WhereIt,
1496 BasicBlock *WhereBB, Context &Ctx,
1497 const Twine &Name = "");
1498
1499 Value *getParentPad() const;
1500 void setParentPad(Value *ParentPad);
1501
1502 bool hasUnwindDest() const {
1503 return cast<llvm::CatchSwitchInst>(Val)->hasUnwindDest();
1504 }
1505 bool unwindsToCaller() const {
1506 return cast<llvm::CatchSwitchInst>(Val)->unwindsToCaller();
1507 }
1508 BasicBlock *getUnwindDest() const;
1509 void setUnwindDest(BasicBlock *UnwindDest);
1510
1511 unsigned getNumHandlers() const {
1512 return cast<llvm::CatchSwitchInst>(Val)->getNumHandlers();
1513 }
1514
1515private:
1516 static BasicBlock *handler_helper(Value *V) { return cast<BasicBlock>(V); }
1517 static const BasicBlock *handler_helper(const Value *V) {
1518 return cast<BasicBlock>(V);
1519 }
1520
1521public:
1522 using DerefFnTy = BasicBlock *(*)(Value *);
1525 using ConstDerefFnTy = const BasicBlock *(*)(const Value *);
1529
1531 op_iterator It = op_begin() + 1;
1532 if (hasUnwindDest())
1533 ++It;
1534 return handler_iterator(It, DerefFnTy(handler_helper));
1535 }
1537 const_op_iterator It = op_begin() + 1;
1538 if (hasUnwindDest())
1539 ++It;
1540 return const_handler_iterator(It, ConstDerefFnTy(handler_helper));
1541 }
1543 return handler_iterator(op_end(), DerefFnTy(handler_helper));
1544 }
1546 return const_handler_iterator(op_end(), ConstDerefFnTy(handler_helper));
1547 }
1550 }
1553 }
1554
1555 void addHandler(BasicBlock *Dest);
1556
1557 // TODO: removeHandler() cannot be reverted because there is no equivalent
1558 // addHandler() with a handler_iterator to specify the position. So we can't
1559 // implement it for now.
1560
1561 unsigned getNumSuccessors() const { return getNumOperands() - 1; }
1562 BasicBlock *getSuccessor(unsigned Idx) const {
1564 "Successor # out of range for catchswitch!");
1565 return cast<BasicBlock>(getOperand(Idx + 1));
1566 }
1567 void setSuccessor(unsigned Idx, BasicBlock *NewSucc) {
1569 "Successor # out of range for catchswitch!");
1570 setOperand(Idx + 1, NewSucc);
1571 }
1572
1573 static bool classof(const Value *From) {
1574 return From->getSubclassID() == ClassID::CatchSwitch;
1575 }
1576};
1577
1578class SwitchInst : public SingleLLVMInstructionImpl<llvm::SwitchInst> {
1579public:
1581 : SingleLLVMInstructionImpl(ClassID::Switch, Opcode::Switch, SI, Ctx) {}
1582
1583 static constexpr const unsigned DefaultPseudoIndex =
1585
1586 static SwitchInst *create(Value *V, BasicBlock *Dest, unsigned NumCases,
1587 BasicBlock::iterator WhereIt, BasicBlock *WhereBB,
1588 Context &Ctx, const Twine &Name = "");
1589
1590 Value *getCondition() const;
1591 void setCondition(Value *V);
1592 BasicBlock *getDefaultDest() const;
1594 return cast<llvm::SwitchInst>(Val)->defaultDestUndefined();
1595 }
1596 void setDefaultDest(BasicBlock *DefaultCase);
1597 unsigned getNumCases() const {
1598 return cast<llvm::SwitchInst>(Val)->getNumCases();
1599 }
1600
1605 const BasicBlock>;
1608
1609 /// Returns a read/write iterator that points to the first case in the
1610 /// SwitchInst.
1611 CaseIt case_begin() { return CaseIt(this, 0); }
1612 ConstCaseIt case_begin() const { return ConstCaseIt(this, 0); }
1613 /// Returns a read/write iterator that points one past the last in the
1614 /// SwitchInst.
1615 CaseIt case_end() { return CaseIt(this, getNumCases()); }
1616 ConstCaseIt case_end() const { return ConstCaseIt(this, getNumCases()); }
1617 /// Iteration adapter for range-for loops.
1619 return make_range(case_begin(), case_end());
1620 }
1622 return make_range(case_begin(), case_end());
1623 }
1626 return ConstCaseIt(this, DefaultPseudoIndex);
1627 }
1629 return CaseIt(
1630 this,
1631 const_cast<const SwitchInst *>(this)->findCaseValue(C)->getCaseIndex());
1632 }
1634 ConstCaseIt I = llvm::find_if(cases(), [C](const ConstCaseHandle &Case) {
1635 return Case.getCaseValue() == C;
1636 });
1637 if (I != case_end())
1638 return I;
1639 return case_default();
1640 }
1642
1643 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1644 /// This method removes the specified case and its successor from the switch
1645 /// instruction. Note that this operation may reorder the remaining cases at
1646 /// index idx and above.
1647 /// Note:
1648 /// This action invalidates iterators for all cases following the one removed,
1649 /// including the case_end() iterator. It returns an iterator for the next
1650 /// case.
1652
1653 unsigned getNumSuccessors() const {
1654 return cast<llvm::SwitchInst>(Val)->getNumSuccessors();
1655 }
1656 BasicBlock *getSuccessor(unsigned Idx) const;
1657 void setSuccessor(unsigned Idx, BasicBlock *NewSucc);
1658 static bool classof(const Value *From) {
1659 return From->getSubclassID() == ClassID::Switch;
1660 }
1661};
1662
1664 static Opcode getUnaryOpcode(llvm::Instruction::UnaryOps UnOp) {
1665 switch (UnOp) {
1666 case llvm::Instruction::FNeg:
1667 return Opcode::FNeg;
1668 case llvm::Instruction::UnaryOpsEnd:
1669 llvm_unreachable("Bad UnOp!");
1670 }
1671 llvm_unreachable("Unhandled UnOp!");
1672 }
1674 : UnaryInstruction(ClassID::UnOp, getUnaryOpcode(UO->getOpcode()), UO,
1675 Ctx) {}
1676 friend Context; // for constructor.
1677public:
1678 static Value *create(Instruction::Opcode Op, Value *OpV, BBIterator WhereIt,
1679 BasicBlock *WhereBB, Context &Ctx,
1680 const Twine &Name = "");
1681 static Value *create(Instruction::Opcode Op, Value *OpV,
1682 Instruction *InsertBefore, Context &Ctx,
1683 const Twine &Name = "");
1684 static Value *create(Instruction::Opcode Op, Value *OpV,
1685 BasicBlock *InsertAtEnd, Context &Ctx,
1686 const Twine &Name = "");
1688 Value *CopyFrom, BBIterator WhereIt,
1689 BasicBlock *WhereBB, Context &Ctx,
1690 const Twine &Name = "");
1692 Value *CopyFrom,
1693 Instruction *InsertBefore, Context &Ctx,
1694 const Twine &Name = "");
1696 Value *CopyFrom, BasicBlock *InsertAtEnd,
1697 Context &Ctx, const Twine &Name = "");
1698 /// For isa/dyn_cast.
1699 static bool classof(const Value *From) {
1700 return From->getSubclassID() == ClassID::UnOp;
1701 }
1702};
1703
1704class BinaryOperator : public SingleLLVMInstructionImpl<llvm::BinaryOperator> {
1705 static Opcode getBinOpOpcode(llvm::Instruction::BinaryOps BinOp) {
1706 switch (BinOp) {
1707 case llvm::Instruction::Add:
1708 return Opcode::Add;
1709 case llvm::Instruction::FAdd:
1710 return Opcode::FAdd;
1711 case llvm::Instruction::Sub:
1712 return Opcode::Sub;
1713 case llvm::Instruction::FSub:
1714 return Opcode::FSub;
1715 case llvm::Instruction::Mul:
1716 return Opcode::Mul;
1717 case llvm::Instruction::FMul:
1718 return Opcode::FMul;
1719 case llvm::Instruction::UDiv:
1720 return Opcode::UDiv;
1721 case llvm::Instruction::SDiv:
1722 return Opcode::SDiv;
1723 case llvm::Instruction::FDiv:
1724 return Opcode::FDiv;
1725 case llvm::Instruction::URem:
1726 return Opcode::URem;
1727 case llvm::Instruction::SRem:
1728 return Opcode::SRem;
1729 case llvm::Instruction::FRem:
1730 return Opcode::FRem;
1731 case llvm::Instruction::Shl:
1732 return Opcode::Shl;
1733 case llvm::Instruction::LShr:
1734 return Opcode::LShr;
1735 case llvm::Instruction::AShr:
1736 return Opcode::AShr;
1737 case llvm::Instruction::And:
1738 return Opcode::And;
1739 case llvm::Instruction::Or:
1740 return Opcode::Or;
1741 case llvm::Instruction::Xor:
1742 return Opcode::Xor;
1743 case llvm::Instruction::BinaryOpsEnd:
1744 llvm_unreachable("Bad BinOp!");
1745 }
1746 llvm_unreachable("Unhandled BinOp!");
1747 }
1749 : SingleLLVMInstructionImpl(ClassID::BinaryOperator,
1750 getBinOpOpcode(BinOp->getOpcode()), BinOp,
1751 Ctx) {}
1752 friend class Context; // For constructor.
1753
1754public:
1756 BBIterator WhereIt, BasicBlock *WhereBB, Context &Ctx,
1757 const Twine &Name = "");
1759 Instruction *InsertBefore, Context &Ctx,
1760 const Twine &Name = "");
1762 BasicBlock *InsertAtEnd, Context &Ctx,
1763 const Twine &Name = "");
1764
1766 Value *RHS, Value *CopyFrom,
1767 BBIterator WhereIt, BasicBlock *WhereBB,
1768 Context &Ctx, const Twine &Name = "");
1770 Value *RHS, Value *CopyFrom,
1771 Instruction *InsertBefore, Context &Ctx,
1772 const Twine &Name = "");
1774 Value *RHS, Value *CopyFrom,
1775 BasicBlock *InsertAtEnd, Context &Ctx,
1776 const Twine &Name = "");
1777 /// For isa/dyn_cast.
1778 static bool classof(const Value *From) {
1779 return From->getSubclassID() == ClassID::BinaryOperator;
1780 }
1782};
1783
1784class AtomicRMWInst : public SingleLLVMInstructionImpl<llvm::AtomicRMWInst> {
1786 : SingleLLVMInstructionImpl(ClassID::AtomicRMW,
1787 Instruction::Opcode::AtomicRMW, Atomic, Ctx) {
1788 }
1789 friend class Context; // For constructor.
1790
1791public:
1794 return cast<llvm::AtomicRMWInst>(Val)->getOperation();
1795 }
1798 }
1799 static bool isFPOperation(BinOp Op) {
1801 }
1803 cast<llvm::AtomicRMWInst>(Val)->setOperation(Op);
1804 }
1805 Align getAlign() const { return cast<llvm::AtomicRMWInst>(Val)->getAlign(); }
1806 void setAlignment(Align Align);
1807 bool isVolatile() const {
1808 return cast<llvm::AtomicRMWInst>(Val)->isVolatile();
1809 }
1810 void setVolatile(bool V);
1812 return cast<llvm::AtomicRMWInst>(Val)->getOrdering();
1813 }
1814 void setOrdering(AtomicOrdering Ordering);
1816 return cast<llvm::AtomicRMWInst>(Val)->getSyncScopeID();
1817 }
1818 void setSyncScopeID(SyncScope::ID SSID);
1820 const Value *getPointerOperand() const {
1821 return const_cast<AtomicRMWInst *>(this)->getPointerOperand();
1822 }
1824 const Value *getValOperand() const {
1825 return const_cast<AtomicRMWInst *>(this)->getValOperand();
1826 }
1827 unsigned getPointerAddressSpace() const {
1828 return cast<llvm::AtomicRMWInst>(Val)->getPointerAddressSpace();
1829 }
1831 return cast<llvm::AtomicRMWInst>(Val)->isFloatingPointOperation();
1832 }
1833 static bool classof(const Value *From) {
1834 return From->getSubclassID() == ClassID::AtomicRMW;
1835 }
1836
1839 BBIterator WhereIt, BasicBlock *WhereBB,
1840 Context &Ctx,
1842 const Twine &Name = "");
1845 Instruction *InsertBefore, Context &Ctx,
1847 const Twine &Name = "");
1850 BasicBlock *InsertAtEnd, Context &Ctx,
1852 const Twine &Name = "");
1853};
1854
1856 : public SingleLLVMInstructionImpl<llvm::AtomicCmpXchgInst> {
1858 : SingleLLVMInstructionImpl(ClassID::AtomicCmpXchg,
1859 Instruction::Opcode::AtomicCmpXchg, Atomic,
1860 Ctx) {}
1861 friend class Context; // For constructor.
1862
1863public:
1864 /// Return the alignment of the memory that is being allocated by the
1865 /// instruction.
1866 Align getAlign() const {
1867 return cast<llvm::AtomicCmpXchgInst>(Val)->getAlign();
1868 }
1869
1870 void setAlignment(Align Align);
1871 /// Return true if this is a cmpxchg from a volatile memory
1872 /// location.
1873 bool isVolatile() const {
1874 return cast<llvm::AtomicCmpXchgInst>(Val)->isVolatile();
1875 }
1876 /// Specify whether this is a volatile cmpxchg.
1877 void setVolatile(bool V);
1878 /// Return true if this cmpxchg may spuriously fail.
1879 bool isWeak() const { return cast<llvm::AtomicCmpXchgInst>(Val)->isWeak(); }
1880 void setWeak(bool IsWeak);
1883 }
1886 }
1888 return cast<llvm::AtomicCmpXchgInst>(Val)->getSuccessOrdering();
1889 }
1890 void setSuccessOrdering(AtomicOrdering Ordering);
1891
1893 return cast<llvm::AtomicCmpXchgInst>(Val)->getFailureOrdering();
1894 }
1895 void setFailureOrdering(AtomicOrdering Ordering);
1897 return cast<llvm::AtomicCmpXchgInst>(Val)->getMergedOrdering();
1898 }
1900 return cast<llvm::AtomicCmpXchgInst>(Val)->getSyncScopeID();
1901 }
1902 void setSyncScopeID(SyncScope::ID SSID);
1904 const Value *getPointerOperand() const {
1905 return const_cast<AtomicCmpXchgInst *>(this)->getPointerOperand();
1906 }
1907
1909 const Value *getCompareOperand() const {
1910 return const_cast<AtomicCmpXchgInst *>(this)->getCompareOperand();
1911 }
1912
1914 const Value *getNewValOperand() const {
1915 return const_cast<AtomicCmpXchgInst *>(this)->getNewValOperand();
1916 }
1917
1918 /// Returns the address space of the pointer operand.
1919 unsigned getPointerAddressSpace() const {
1920 return cast<llvm::AtomicCmpXchgInst>(Val)->getPointerAddressSpace();
1921 }
1922
1923 static AtomicCmpXchgInst *
1924 create(Value *Ptr, Value *Cmp, Value *New, MaybeAlign Align,
1925 AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
1926 BBIterator WhereIt, BasicBlock *WhereBB, Context &Ctx,
1927 SyncScope::ID SSID = SyncScope::System, const Twine &Name = "");
1928 static AtomicCmpXchgInst *
1929 create(Value *Ptr, Value *Cmp, Value *New, MaybeAlign Align,
1930 AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
1931 Instruction *InsertBefore, Context &Ctx,
1932 SyncScope::ID SSID = SyncScope::System, const Twine &Name = "");
1933 static AtomicCmpXchgInst *
1934 create(Value *Ptr, Value *Cmp, Value *New, MaybeAlign Align,
1935 AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
1936 BasicBlock *InsertAtEnd, Context &Ctx,
1937 SyncScope::ID SSID = SyncScope::System, const Twine &Name = "");
1938};
1939
1940class AllocaInst final : public UnaryInstruction {
1942 : UnaryInstruction(ClassID::Alloca, Instruction::Opcode::Alloca, AI,
1943 Ctx) {}
1944 friend class Context; // For constructor.
1945
1946public:
1947 static AllocaInst *create(Type *Ty, unsigned AddrSpace, BBIterator WhereIt,
1948 BasicBlock *WhereBB, Context &Ctx,
1949 Value *ArraySize = nullptr, const Twine &Name = "");
1950 static AllocaInst *create(Type *Ty, unsigned AddrSpace,
1951 Instruction *InsertBefore, Context &Ctx,
1952 Value *ArraySize = nullptr, const Twine &Name = "");
1953 static AllocaInst *create(Type *Ty, unsigned AddrSpace,
1954 BasicBlock *InsertAtEnd, Context &Ctx,
1955 Value *ArraySize = nullptr, const Twine &Name = "");
1956
1957 /// Return true if there is an allocation size parameter to the allocation
1958 /// instruction that is not 1.
1959 bool isArrayAllocation() const {
1960 return cast<llvm::AllocaInst>(Val)->isArrayAllocation();
1961 }
1962 /// Get the number of elements allocated. For a simple allocation of a single
1963 /// element, this will return a constant 1 value.
1965 const Value *getArraySize() const {
1966 return const_cast<AllocaInst *>(this)->getArraySize();
1967 }
1968 /// Overload to return most specific pointer type.
1970 return cast<llvm::AllocaInst>(Val)->getType();
1971 }
1972 /// Return the address space for the allocation.
1973 unsigned getAddressSpace() const {
1974 return cast<llvm::AllocaInst>(Val)->getAddressSpace();
1975 }
1976 /// Get allocation size in bytes. Returns std::nullopt if size can't be
1977 /// determined, e.g. in case of a VLA.
1978 std::optional<TypeSize> getAllocationSize(const DataLayout &DL) const {
1979 return cast<llvm::AllocaInst>(Val)->getAllocationSize(DL);
1980 }
1981 /// Get allocation size in bits. Returns std::nullopt if size can't be
1982 /// determined, e.g. in case of a VLA.
1983 std::optional<TypeSize> getAllocationSizeInBits(const DataLayout &DL) const {
1984 return cast<llvm::AllocaInst>(Val)->getAllocationSizeInBits(DL);
1985 }
1986 /// Return the type that is being allocated by the instruction.
1988 return cast<llvm::AllocaInst>(Val)->getAllocatedType();
1989 }
1990 /// for use only in special circumstances that need to generically
1991 /// transform a whole instruction (eg: IR linking and vectorization).
1992 void setAllocatedType(Type *Ty);
1993 /// Return the alignment of the memory that is being allocated by the
1994 /// instruction.
1995 Align getAlign() const { return cast<llvm::AllocaInst>(Val)->getAlign(); }
1996 void setAlignment(Align Align);
1997 /// Return true if this alloca is in the entry block of the function and is a
1998 /// constant size. If so, the code generator will fold it into the
1999 /// prolog/epilog code, so it is basically free.
2000 bool isStaticAlloca() const {
2001 return cast<llvm::AllocaInst>(Val)->isStaticAlloca();
2002 }
2003 /// Return true if this alloca is used as an inalloca argument to a call. Such
2004 /// allocas are never considered static even if they are in the entry block.
2005 bool isUsedWithInAlloca() const {
2006 return cast<llvm::AllocaInst>(Val)->isUsedWithInAlloca();
2007 }
2008 /// Specify whether this alloca is used to represent the arguments to a call.
2009 void setUsedWithInAlloca(bool V);
2010
2011 static bool classof(const Value *From) {
2012 if (auto *I = dyn_cast<Instruction>(From))
2013 return I->getSubclassID() == Instruction::ClassID::Alloca;
2014 return false;
2015 }
2016};
2017
2019 static Opcode getCastOpcode(llvm::Instruction::CastOps CastOp) {
2020 switch (CastOp) {
2021 case llvm::Instruction::ZExt:
2022 return Opcode::ZExt;
2023 case llvm::Instruction::SExt:
2024 return Opcode::SExt;
2025 case llvm::Instruction::FPToUI:
2026 return Opcode::FPToUI;
2027 case llvm::Instruction::FPToSI:
2028 return Opcode::FPToSI;
2029 case llvm::Instruction::FPExt:
2030 return Opcode::FPExt;
2031 case llvm::Instruction::PtrToInt:
2032 return Opcode::PtrToInt;
2033 case llvm::Instruction::IntToPtr:
2034 return Opcode::IntToPtr;
2035 case llvm::Instruction::SIToFP:
2036 return Opcode::SIToFP;
2037 case llvm::Instruction::UIToFP:
2038 return Opcode::UIToFP;
2039 case llvm::Instruction::Trunc:
2040 return Opcode::Trunc;
2041 case llvm::Instruction::FPTrunc:
2042 return Opcode::FPTrunc;
2043 case llvm::Instruction::BitCast:
2044 return Opcode::BitCast;
2045 case llvm::Instruction::AddrSpaceCast:
2046 return Opcode::AddrSpaceCast;
2047 case llvm::Instruction::CastOpsEnd:
2048 llvm_unreachable("Bad CastOp!");
2049 }
2050 llvm_unreachable("Unhandled CastOp!");
2051 }
2052 /// Use Context::createCastInst(). Don't call the
2053 /// constructor directly.
2055 : UnaryInstruction(ClassID::Cast, getCastOpcode(CI->getOpcode()), CI,
2056 Ctx) {}
2057 friend Context; // for SBCastInstruction()
2058
2059public:
2060 static Value *create(Type *DestTy, Opcode Op, Value *Operand,
2061 BBIterator WhereIt, BasicBlock *WhereBB, Context &Ctx,
2062 const Twine &Name = "");
2063 static Value *create(Type *DestTy, Opcode Op, Value *Operand,
2064 Instruction *InsertBefore, Context &Ctx,
2065 const Twine &Name = "");
2066 static Value *create(Type *DestTy, Opcode Op, Value *Operand,
2067 BasicBlock *InsertAtEnd, Context &Ctx,
2068 const Twine &Name = "");
2069 /// For isa/dyn_cast.
2070 static bool classof(const Value *From);
2071 Type *getSrcTy() const { return cast<llvm::CastInst>(Val)->getSrcTy(); }
2072 Type *getDestTy() const { return cast<llvm::CastInst>(Val)->getDestTy(); }
2073};
2074
2075// Helper class to simplify stamping out CastInst subclasses.
2076template <Instruction::Opcode Op> class CastInstImpl : public CastInst {
2077public:
2078 static Value *create(Value *Src, Type *DestTy, BBIterator WhereIt,
2079 BasicBlock *WhereBB, Context &Ctx,
2080 const Twine &Name = "") {
2081 return CastInst::create(DestTy, Op, Src, WhereIt, WhereBB, Ctx, Name);
2082 }
2083 static Value *create(Value *Src, Type *DestTy, Instruction *InsertBefore,
2084 Context &Ctx, const Twine &Name = "") {
2085 return create(Src, DestTy, InsertBefore->getIterator(),
2086 InsertBefore->getParent(), Ctx, Name);
2087 }
2088 static Value *create(Value *Src, Type *DestTy, BasicBlock *InsertAtEnd,
2089 Context &Ctx, const Twine &Name = "") {
2090 return create(Src, DestTy, InsertAtEnd->end(), InsertAtEnd, Ctx, Name);
2091 }
2092
2093 static bool classof(const Value *From) {
2094 if (auto *I = dyn_cast<Instruction>(From))
2095 return I->getOpcode() == Op;
2096 return false;
2097 }
2098};
2099
2100class TruncInst final : public CastInstImpl<Instruction::Opcode::Trunc> {};
2101class ZExtInst final : public CastInstImpl<Instruction::Opcode::ZExt> {};
2102class SExtInst final : public CastInstImpl<Instruction::Opcode::SExt> {};
2103class FPTruncInst final : public CastInstImpl<Instruction::Opcode::FPTrunc> {};
2104class FPExtInst final : public CastInstImpl<Instruction::Opcode::FPExt> {};
2105class UIToFPInst final : public CastInstImpl<Instruction::Opcode::UIToFP> {};
2106class SIToFPInst final : public CastInstImpl<Instruction::Opcode::SIToFP> {};
2107class FPToUIInst final : public CastInstImpl<Instruction::Opcode::FPToUI> {};
2108class FPToSIInst final : public CastInstImpl<Instruction::Opcode::FPToSI> {};
2109class IntToPtrInst final : public CastInstImpl<Instruction::Opcode::IntToPtr> {
2110};
2111class PtrToIntInst final : public CastInstImpl<Instruction::Opcode::PtrToInt> {
2112};
2113class BitCastInst final : public CastInstImpl<Instruction::Opcode::BitCast> {};
2115 : public CastInstImpl<Instruction::Opcode::AddrSpaceCast> {
2116public:
2117 /// \Returns the pointer operand.
2119 /// \Returns the pointer operand.
2120 const Value *getPointerOperand() const {
2121 return const_cast<AddrSpaceCastInst *>(this)->getPointerOperand();
2122 }
2123 /// \Returns the operand index of the pointer operand.
2124 static unsigned getPointerOperandIndex() { return 0u; }
2125 /// \Returns the address space of the pointer operand.
2126 unsigned getSrcAddressSpace() const {
2128 }
2129 /// \Returns the address space of the result.
2130 unsigned getDestAddressSpace() const {
2131 return getType()->getPointerAddressSpace();
2132 }
2133};
2134
2135class PHINode final : public SingleLLVMInstructionImpl<llvm::PHINode> {
2136 /// Use Context::createPHINode(). Don't call the constructor directly.
2138 : SingleLLVMInstructionImpl(ClassID::PHI, Opcode::PHI, PHI, Ctx) {}
2139 friend Context; // for PHINode()
2140 /// Helper for mapped_iterator.
2141 struct LLVMBBToBB {
2142 Context &Ctx;
2143 LLVMBBToBB(Context &Ctx) : Ctx(Ctx) {}
2144 BasicBlock *operator()(llvm::BasicBlock *LLVMBB) const;
2145 };
2146
2147public:
2148 static PHINode *create(Type *Ty, unsigned NumReservedValues,
2149 Instruction *InsertBefore, Context &Ctx,
2150 const Twine &Name = "");
2151 /// For isa/dyn_cast.
2152 static bool classof(const Value *From);
2153
2156
2158 LLVMBBToBB BBGetter(Ctx);
2159 return const_block_iterator(cast<llvm::PHINode>(Val)->block_begin(),
2160 BBGetter);
2161 }
2163 LLVMBBToBB BBGetter(Ctx);
2164 return const_block_iterator(cast<llvm::PHINode>(Val)->block_end(),
2165 BBGetter);
2166 }
2168 return make_range(block_begin(), block_end());
2169 }
2170
2172
2174
2175 unsigned getNumIncomingValues() const {
2176 return cast<llvm::PHINode>(Val)->getNumIncomingValues();
2177 }
2178 Value *getIncomingValue(unsigned Idx) const;
2179 void setIncomingValue(unsigned Idx, Value *V);
2180 static unsigned getOperandNumForIncomingValue(unsigned Idx) {
2182 }
2183 static unsigned getIncomingValueNumForOperand(unsigned Idx) {
2185 }
2186 BasicBlock *getIncomingBlock(unsigned Idx) const;
2187 BasicBlock *getIncomingBlock(const Use &U) const;
2188
2189 void setIncomingBlock(unsigned Idx, BasicBlock *BB);
2190
2191 void addIncoming(Value *V, BasicBlock *BB);
2192
2193 Value *removeIncomingValue(unsigned Idx);
2195
2196 int getBasicBlockIndex(const BasicBlock *BB) const;
2197 Value *getIncomingValueForBlock(const BasicBlock *BB) const;
2198
2199 Value *hasConstantValue() const;
2200
2202 return cast<llvm::PHINode>(Val)->hasConstantOrUndefValue();
2203 }
2204 bool isComplete() const { return cast<llvm::PHINode>(Val)->isComplete(); }
2205 void replaceIncomingBlockWith(const BasicBlock *Old, BasicBlock *New);
2206 void removeIncomingValueIf(function_ref<bool(unsigned)> Predicate);
2207 // TODO: Implement
2208 // void copyIncomingBlocks(iterator_range<const_block_iterator> BBRange,
2209 // uint32_t ToIdx = 0)
2210};
2211
2212/// An LLLVM Instruction that has no SandboxIR equivalent class gets mapped to
2213/// an OpaqueInstr.
2214class OpaqueInst : public SingleLLVMInstructionImpl<llvm::Instruction> {
2216 : SingleLLVMInstructionImpl(ClassID::Opaque, Opcode::Opaque, I, Ctx) {}
2218 : SingleLLVMInstructionImpl(SubclassID, Opcode::Opaque, I, Ctx) {}
2219 friend class Context; // For constructor.
2220
2221public:
2222 static bool classof(const sandboxir::Value *From) {
2223 return From->getSubclassID() == ClassID::Opaque;
2224 }
2225};
2226
2227class Context {
2228protected:
2231
2232 /// Maps LLVM Value to the corresponding sandboxir::Value. Owns all
2233 /// SandboxIR objects.
2236
2237 /// Remove \p V from the maps and returns the unique_ptr.
2238 std::unique_ptr<Value> detachLLVMValue(llvm::Value *V);
2239 /// Remove \p SBV from all SandboxIR maps and stop owning it. This effectively
2240 /// detaches \p V from the underlying IR.
2241 std::unique_ptr<Value> detach(Value *V);
2242 friend void Instruction::eraseFromParent(); // For detach().
2243 /// Take ownership of VPtr and store it in `LLVMValueToValueMap`.
2244 Value *registerValue(std::unique_ptr<Value> &&VPtr);
2245 friend class EraseFromParent; // For registerValue().
2246 /// This is the actual function that creates sandboxir values for \p V,
2247 /// and among others handles all instruction types.
2249 /// Get or create a sandboxir::Argument for an existing LLVM IR \p LLVMArg.
2251 auto Pair = LLVMValueToValueMap.insert({LLVMArg, nullptr});
2252 auto It = Pair.first;
2253 if (Pair.second) {
2254 It->second = std::unique_ptr<Argument>(new Argument(LLVMArg, *this));
2255 return cast<Argument>(It->second.get());
2256 }
2257 return cast<Argument>(It->second.get());
2258 }
2259 /// Get or create a sandboxir::Value for an existing LLVM IR \p LLVMV.
2261 return getOrCreateValueInternal(LLVMV, 0);
2262 }
2263 /// Get or create a sandboxir::Constant from an existing LLVM IR \p LLVMC.
2265 return cast<Constant>(getOrCreateValueInternal(LLVMC, 0));
2266 }
2267 friend class ConstantInt; // For getOrCreateConstant().
2268 /// Create a sandboxir::BasicBlock for an existing LLVM IR \p BB. This will
2269 /// also create all contents of the block.
2271
2272 friend class BasicBlock; // For getOrCreateValue().
2273
2276
2278 friend SelectInst; // For createSelectInst()
2280 friend InsertElementInst; // For createInsertElementInst()
2282 friend ExtractElementInst; // For createExtractElementInst()
2284 friend BranchInst; // For createBranchInst()
2286 friend LoadInst; // For createLoadInst()
2288 friend StoreInst; // For createStoreInst()
2290 friend ReturnInst; // For createReturnInst()
2292 friend CallInst; // For createCallInst()
2294 friend InvokeInst; // For createInvokeInst()
2296 friend CallBrInst; // For createCallBrInst()
2298 friend GetElementPtrInst; // For createGetElementPtrInst()
2300 friend CatchSwitchInst; // For createCatchSwitchInst()
2302 friend SwitchInst; // For createSwitchInst()
2304 friend UnaryOperator; // For createUnaryOperator()
2306 friend BinaryOperator; // For createBinaryOperator()
2308 friend AtomicRMWInst; // For createAtomicRMWInst()
2310 friend AtomicCmpXchgInst; // For createAtomicCmpXchgInst()
2312 friend AllocaInst; // For createAllocaInst()
2314 friend CastInst; // For createCastInst()
2316 friend PHINode; // For createPHINode()
2318 friend UnreachableInst; // For createUnreachableInst()
2319
2320public:
2322 : LLVMCtx(LLVMCtx), IRTracker(*this),
2324
2326 /// Convenience function for `getTracker().save()`
2327 void save() { IRTracker.save(); }
2328 /// Convenience function for `getTracker().revert()`
2330 /// Convenience function for `getTracker().accept()`
2332
2334 const sandboxir::Value *getValue(const llvm::Value *V) const {
2335 return getValue(const_cast<llvm::Value *>(V));
2336 }
2337 /// Create a sandboxir::Function for an existing LLVM IR \p F, including all
2338 /// blocks and instructions.
2339 /// This is the main API function for creating Sandbox IR.
2341
2342 /// \Returns the number of values registered with Context.
2343 size_t getNumValues() const { return LLVMValueToValueMap.size(); }
2344};
2345
2346class Function : public Constant {
2347 /// Helper for mapped_iterator.
2348 struct LLVMBBToBB {
2349 Context &Ctx;
2350 LLVMBBToBB(Context &Ctx) : Ctx(Ctx) {}
2351 BasicBlock &operator()(llvm::BasicBlock &LLVMBB) const {
2352 return *cast<BasicBlock>(Ctx.getValue(&LLVMBB));
2353 }
2354 };
2355 /// Use Context::createFunction() instead.
2357 : Constant(ClassID::Function, F, Ctx) {}
2358 friend class Context; // For constructor.
2359
2360public:
2361 /// For isa/dyn_cast.
2362 static bool classof(const sandboxir::Value *From) {
2363 return From->getSubclassID() == ClassID::Function;
2364 }
2365
2366 Argument *getArg(unsigned Idx) const {
2367 llvm::Argument *Arg = cast<llvm::Function>(Val)->getArg(Idx);
2368 return cast<Argument>(Ctx.getValue(Arg));
2369 }
2370
2371 size_t arg_size() const { return cast<llvm::Function>(Val)->arg_size(); }
2372 bool arg_empty() const { return cast<llvm::Function>(Val)->arg_empty(); }
2373
2375 iterator begin() const {
2376 LLVMBBToBB BBGetter(Ctx);
2377 return iterator(cast<llvm::Function>(Val)->begin(), BBGetter);
2378 }
2379 iterator end() const {
2380 LLVMBBToBB BBGetter(Ctx);
2381 return iterator(cast<llvm::Function>(Val)->end(), BBGetter);
2382 }
2384 return cast<llvm::Function>(Val)->getFunctionType();
2385 }
2386
2387#ifndef NDEBUG
2388 void verify() const final {
2389 assert(isa<llvm::Function>(Val) && "Expected Function!");
2390 }
2391 void dumpNameAndArgs(raw_ostream &OS) const;
2392 void dumpOS(raw_ostream &OS) const final;
2393#endif
2394};
2395
2396} // namespace sandboxir
2397} // namespace llvm
2398
2399#endif // LLVM_SANDBOXIR_SANDBOXIR_H
aarch64 promote const
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:533
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
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
ppc ctr loops PowerPC CTR Loops Verify
StandardInstrumentations SI(Mod->getContext(), Debug, VerifyEach)
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:61
This class represents an incoming formal argument to a Function.
Definition: Argument.h:31
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:495
static bool isValidFailureOrdering(AtomicOrdering Ordering)
Definition: Instructions.h:566
static bool isValidSuccessOrdering(AtomicOrdering Ordering)
Definition: Instructions.h:561
an instruction that atomically reads a memory location, combines it with another value,...
Definition: Instructions.h:696
static bool isFPOperation(BinOp Op)
Definition: Instructions.h:791
BinOp
This enumeration lists the possible modifications atomicrmw can make.
Definition: Instructions.h:708
static StringRef getOperationName(BinOp Op)
LLVM Basic Block Representation.
Definition: BasicBlock.h:61
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:177
Conditional or Unconditional Branch instruction.
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
This class represents a function call, abstracting a target machine's calling convention.
This is the base class for all instructions that perform data casts.
Definition: InstrTypes.h:530
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
Definition: InstrTypes.h:694
ConstantFolder - Create constants with minimum, target independent, folding.
This is the shared class of boolean and integer constants.
Definition: Constants.h:81
This is an important base class in LLVM.
Definition: Constant.h:42
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
This instruction extracts a single (scalar) element from a VectorType value.
static bool isValidOperands(const Value *Vec, const Value *Idx)
Return true if an extractelement instruction can be formed with the specified operands.
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:20
Class to represent function types.
Definition: DerivedTypes.h:103
Represents flags for the getelementptr instruction/expression.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
Definition: Instructions.h:915
static unsigned getPointerOperandIndex()
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:2686
This instruction inserts a single (scalar) element into a VectorType value.
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.
Invoke instruction.
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
An instruction for reading from memory.
Definition: Instructions.h:174
static unsigned getOperandNumForIncomingValue(unsigned i)
static unsigned getIncomingValueNumForOperand(unsigned i)
Class to represent pointers.
Definition: DerivedTypes.h:646
Return a value (possibly void), from a function.
This class represents the LLVM 'select' instruction.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
An instruction for storing to memory.
Definition: Instructions.h:290
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
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
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
UnaryOps getOpcode() const
Definition: InstrTypes.h:171
This function has undefined behavior.
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:309
Base class of all SIMD vector types.
Definition: DerivedTypes.h:403
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: SandboxIR.h:2126
Value * getPointerOperand()
\Returns the pointer operand.
Definition: SandboxIR.h:2118
unsigned getDestAddressSpace() const
\Returns the address space of the result.
Definition: SandboxIR.h:2130
const Value * getPointerOperand() const
\Returns the pointer operand.
Definition: SandboxIR.h:2120
static unsigned getPointerOperandIndex()
\Returns the operand index of the pointer operand.
Definition: SandboxIR.h:2124
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
Definition: SandboxIR.h:2005
Value * getArraySize()
Get the number of elements allocated.
Definition: SandboxIR.cpp:1732
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
Definition: SandboxIR.h:1987
bool isStaticAlloca() const
Return true if this alloca is in the entry block of the function and is a constant size.
Definition: SandboxIR.h:2000
bool isArrayAllocation() const
Return true if there is an allocation size parameter to the allocation instruction that is not 1.
Definition: SandboxIR.h:1959
std::optional< TypeSize > getAllocationSizeInBits(const DataLayout &DL) const
Get allocation size in bits.
Definition: SandboxIR.h:1983
void setAlignment(Align Align)
Definition: SandboxIR.cpp:1717
unsigned getAddressSpace() const
Return the address space for the allocation.
Definition: SandboxIR.h:1973
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
Definition: SandboxIR.h:1995
PointerType * getType() const
Overload to return most specific pointer type.
Definition: SandboxIR.h:1969
void setUsedWithInAlloca(bool V)
Specify whether this alloca is used to represent the arguments to a call.
Definition: SandboxIR.cpp:1725
static AllocaInst * create(Type *Ty, unsigned AddrSpace, BBIterator WhereIt, BasicBlock *WhereBB, Context &Ctx, Value *ArraySize=nullptr, const Twine &Name="")
Definition: SandboxIR.cpp:1684
static bool classof(const Value *From)
Definition: SandboxIR.h:2011
std::optional< TypeSize > getAllocationSize(const DataLayout &DL) const
Get allocation size in bytes.
Definition: SandboxIR.h:1978
const Value * getArraySize() const
Definition: SandboxIR.h:1965
void setAllocatedType(Type *Ty)
for use only in special circumstances that need to generically transform a whole instruction (eg: IR ...
Definition: SandboxIR.cpp:1710
Argument of a sandboxir::Function.
Definition: SandboxIR.h:384
void dumpOS(raw_ostream &OS) const final
Definition: SandboxIR.cpp:214
void printAsOperand(raw_ostream &OS) const
Definition: SandboxIR.cpp:211
void verify() const final
Should crash if there is something wrong with the instruction.
Definition: SandboxIR.h:394
static bool classof(const sandboxir::Value *From)
Definition: SandboxIR.h:390
void setSyncScopeID(SyncScope::ID SSID)
Definition: SandboxIR.cpp:1586
void setVolatile(bool V)
Specify whether this is a volatile cmpxchg.
Definition: SandboxIR.cpp:1654
const Value * getNewValOperand() const
Definition: SandboxIR.h:1914
void setSuccessOrdering(AtomicOrdering Ordering)
Definition: SandboxIR.cpp:1668
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
Definition: SandboxIR.h:1919
AtomicOrdering getMergedOrdering() const
Definition: SandboxIR.h:1896
const Value * getCompareOperand() const
Definition: SandboxIR.h:1909
static AtomicCmpXchgInst * create(Value *Ptr, Value *Cmp, Value *New, MaybeAlign Align, AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, BBIterator WhereIt, BasicBlock *WhereBB, Context &Ctx, SyncScope::ID SSID=SyncScope::System, const Twine &Name="")
Definition: SandboxIR.cpp:1607
const Value * getPointerOperand() const
Definition: SandboxIR.h:1904
AtomicOrdering getFailureOrdering() const
Definition: SandboxIR.h:1892
static bool isValidFailureOrdering(AtomicOrdering Ordering)
Definition: SandboxIR.h:1884
bool isVolatile() const
Return true if this is a cmpxchg from a volatile memory location.
Definition: SandboxIR.h:1873
static bool isValidSuccessOrdering(AtomicOrdering Ordering)
Definition: SandboxIR.h:1881
AtomicOrdering getSuccessOrdering() const
Definition: SandboxIR.h:1887
void setFailureOrdering(AtomicOrdering Ordering)
Definition: SandboxIR.cpp:1676
SyncScope::ID getSyncScopeID() const
Definition: SandboxIR.h:1899
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
Definition: SandboxIR.h:1866
bool isWeak() const
Return true if this cmpxchg may spuriously fail.
Definition: SandboxIR.h:1879
static AtomicRMWInst * create(BinOp Op, Value *Ptr, Value *Val, MaybeAlign Align, AtomicOrdering Ordering, BBIterator WhereIt, BasicBlock *WhereBB, Context &Ctx, SyncScope::ID SSID=SyncScope::System, const Twine &Name="")
Definition: SandboxIR.cpp:1554
const Value * getPointerOperand() const
Definition: SandboxIR.h:1820
unsigned getPointerAddressSpace() const
Definition: SandboxIR.h:1827
llvm::AtomicRMWInst::BinOp BinOp
Definition: SandboxIR.h:1792
SyncScope::ID getSyncScopeID() const
Definition: SandboxIR.h:1815
void setAlignment(Align Align)
Definition: SandboxIR.cpp:1518
const Value * getValOperand() const
Definition: SandboxIR.h:1824
void setSyncScopeID(SyncScope::ID SSID)
Definition: SandboxIR.cpp:1539
static StringRef getOperationName(BinOp Op)
Definition: SandboxIR.h:1796
void setOrdering(AtomicOrdering Ordering)
Definition: SandboxIR.cpp:1532
AtomicOrdering getOrdering() const
Definition: SandboxIR.h:1811
static bool classof(const Value *From)
Definition: SandboxIR.h:1833
bool isFloatingPointOperation() const
Definition: SandboxIR.h:1830
static bool isFPOperation(BinOp Op)
Definition: SandboxIR.h:1799
Iterator for Instructions in a `BasicBlock.
Definition: SandboxIR.h:561
BBIterator operator++(int)
Definition: SandboxIR.h:581
bool operator!=(const BBIterator &Other) const
Definition: SandboxIR.h:596
BBIterator operator--(int)
Definition: SandboxIR.h:587
pointer get() const
\Returns the SBInstruction that corresponds to this iterator, or null if the instruction is not found...
Definition: SandboxIR.h:599
reference operator*() const
Definition: SandboxIR.h:579
std::bidirectional_iterator_tag iterator_category
Definition: SandboxIR.h:567
std::ptrdiff_t difference_type
Definition: SandboxIR.h:563
BBIterator(llvm::BasicBlock *BB, llvm::BasicBlock::iterator It, Context *Ctx)
Definition: SandboxIR.h:577
bool operator==(const BBIterator &Other) const
Definition: SandboxIR.h:592
Contains a list of sandboxir::Instruction's.
Definition: SandboxIR.h:603
void dumpOS(raw_ostream &OS) const final
Definition: SandboxIR.cpp:2298
std::reverse_iterator< iterator > rbegin() const
Definition: SandboxIR.h:628
static bool classof(const Value *From)
For isa/dyn_cast.
Definition: SandboxIR.h:618
void verify() const final
Should crash if there is something wrong with the instruction.
Definition: SandboxIR.h:641
std::reverse_iterator< iterator > rend() const
Definition: SandboxIR.h:631
Function * getParent() const
Definition: SandboxIR.cpp:2230
Instruction & front() const
Definition: SandboxIR.cpp:2281
Instruction * getTerminator() const
Definition: SandboxIR.cpp:2275
Context & getContext() const
Definition: SandboxIR.h:634
Instruction & back() const
Definition: SandboxIR.cpp:2289
iterator end() const
Definition: SandboxIR.h:624
static Value * create(Instruction::Opcode Op, Value *LHS, Value *RHS, BBIterator WhereIt, BasicBlock *WhereBB, Context &Ctx, const Twine &Name="")
Definition: SandboxIR.cpp:1460
static bool classof(const Value *From)
For isa/dyn_cast.
Definition: SandboxIR.h:1778
static Value * createWithCopiedFlags(Instruction::Opcode Op, Value *LHS, Value *RHS, Value *CopyFrom, BBIterator WhereIt, BasicBlock *WhereBB, Context &Ctx, const Twine &Name="")
Definition: SandboxIR.cpp:1489
unsigned getNumSuccessors() const
Definition: SandboxIR.h:978
iterator_range< sb_succ_op_iterator > successors()
Definition: SandboxIR.h:999
iterator_range< const_sb_succ_op_iterator > successors() const
Definition: SandboxIR.h:1011
static bool classof(const Value *From)
For isa/dyn_cast.
Definition: SandboxIR.cpp:653
void setCondition(Value *V)
Definition: SandboxIR.h:977
bool isConditional() const
Definition: SandboxIR.h:973
void setSuccessor(unsigned Idx, BasicBlock *NewSucc)
Definition: SandboxIR.cpp:669
bool isUnconditional() const
Definition: SandboxIR.h:970
BasicBlock * getSuccessor(unsigned SuccIdx) const
Definition: SandboxIR.cpp:662
static BranchInst * create(BasicBlock *IfTrue, Instruction *InsertBefore, Context &Ctx)
Definition: SandboxIR.cpp:611
Value * getCondition() const
Definition: SandboxIR.cpp:657
iterator_range< const_op_iterator > args() const
Definition: SandboxIR.h:1222
CallingConv::ID getCallingConv() const
Definition: SandboxIR.h:1277
bool isMustTailCall() const
Definition: SandboxIR.h:1268
const Function * getCaller() const
Definition: SandboxIR.h:1265
FunctionType * getFunctionType() const
Definition: SandboxIR.h:1165
void setCalledFunction(Function *F)
Definition: SandboxIR.cpp:851
op_iterator arg_begin()
Definition: SandboxIR.h:1211
const_op_iterator arg_end() const
Definition: SandboxIR.h:1216
iterator_range< op_iterator > args()
Definition: SandboxIR.h:1219
static bool classof(const Value *From)
Definition: SandboxIR.h:1158
Value * getArgOperand(unsigned OpIdx) const
Definition: SandboxIR.h:1228
bool isInlineAsm() const
Definition: SandboxIR.h:1280
Function * getCalledFunction() const
Definition: SandboxIR.cpp:843
Use getArgOperandUse(unsigned Idx)
Definition: SandboxIR.h:1241
bool isDataOperand(Use U) const
Definition: SandboxIR.h:1195
unsigned getArgOperandNo(Use U) const
Definition: SandboxIR.h:1249
const_op_iterator data_operands_end() const
Definition: SandboxIR.h:1178
op_iterator data_operands_end()
Definition: SandboxIR.h:1173
unsigned getDataOperandNo(Use U) const
Definition: SandboxIR.h:1200
unsigned getNumTotalBundleOperands() const
Return the total number operands (not operand bundles) used by every operand bundle in this OperandBu...
Definition: SandboxIR.h:1207
iterator_range< op_iterator > data_ops()
Definition: SandboxIR.h:1183
const_op_iterator data_operands_begin() const
Definition: SandboxIR.h:1170
bool data_operands_empty() const
Definition: SandboxIR.h:1189
bool hasArgument(const Value *V) const
Definition: SandboxIR.h:1252
void setCalledOperand(Value *V)
Definition: SandboxIR.h:1275
unsigned arg_size() const
Definition: SandboxIR.h:1226
unsigned data_operands_size() const
Definition: SandboxIR.h:1192
const_op_iterator arg_begin() const
Definition: SandboxIR.h:1212
Intrinsic::ID getIntrinsicID() const
Definition: SandboxIR.h:1272
Use getArgOperandUse(unsigned Idx) const
Definition: SandboxIR.h:1237
Value * getCalledOperand() const
Definition: SandboxIR.cpp:834
op_iterator data_operands_begin()
Definition: SandboxIR.h:1169
bool isArgOperand(Use U) const
Definition: SandboxIR.h:1246
void setArgOperand(unsigned OpIdx, Value *NewOp)
Definition: SandboxIR.h:1232
iterator_range< const_op_iterator > data_ops() const
Definition: SandboxIR.h:1186
Use getCalledOperandUse() const
Definition: SandboxIR.cpp:838
bool isCallee(Use U) const
Definition: SandboxIR.h:1261
bool isIndirectCall() const
Definition: SandboxIR.h:1258
static CallBrInst * create(FunctionType *FTy, Value *Func, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, BBIterator WhereIt, BasicBlock *WhereBB, Context &Ctx, const Twine &NameStr="")
Definition: SandboxIR.cpp:958
BasicBlock * getIndirectDest(unsigned Idx) const
Definition: SandboxIR.cpp:1016
static bool classof(const Value *From)
Definition: SandboxIR.h:1378
void setDefaultDest(BasicBlock *BB)
Definition: SandboxIR.cpp:1027
Value * getIndirectDestLabel(unsigned Idx) const
Definition: SandboxIR.cpp:1005
Value * getIndirectDestLabelUse(unsigned Idx) const
Definition: SandboxIR.cpp:1008
unsigned getNumIndirectDests() const
Definition: SandboxIR.h:1381
SmallVector< BasicBlock *, 16 > getIndirectDests() const
Definition: SandboxIR.cpp:1020
BasicBlock * getDefaultDest() const
Definition: SandboxIR.cpp:1012
BasicBlock * getSuccessor(unsigned Idx) const
Definition: SandboxIR.cpp:1041
void setIndirectDest(unsigned Idx, BasicBlock *BB)
Definition: SandboxIR.cpp:1033
unsigned getNumSuccessors() const
Definition: SandboxIR.h:1392
static CallInst * create(FunctionType *FTy, Value *Func, ArrayRef< Value * > Args, BBIterator WhereIt, BasicBlock *WhereBB, Context &Ctx, const Twine &NameStr="")
static bool classof(const Value *From)
Definition: SandboxIR.h:1303
static Value * create(Value *Src, Type *DestTy, Instruction *InsertBefore, Context &Ctx, const Twine &Name="")
Definition: SandboxIR.h:2083
static bool classof(const Value *From)
Definition: SandboxIR.h:2093
static Value * create(Value *Src, Type *DestTy, BBIterator WhereIt, BasicBlock *WhereBB, Context &Ctx, const Twine &Name="")
Definition: SandboxIR.h:2078
static Value * create(Value *Src, Type *DestTy, BasicBlock *InsertAtEnd, Context &Ctx, const Twine &Name="")
Definition: SandboxIR.h:2088
static Value * create(Type *DestTy, Opcode Op, Value *Operand, BBIterator WhereIt, BasicBlock *WhereBB, Context &Ctx, const Twine &Name="")
Definition: SandboxIR.cpp:1736
Type * getSrcTy() const
Definition: SandboxIR.h:2071
static bool classof(const Value *From)
For isa/dyn_cast.
Definition: SandboxIR.cpp:1767
Type * getDestTy() const
Definition: SandboxIR.h:2072
const_handler_iterator handler_begin() const
Definition: SandboxIR.h:1536
void setParentPad(Value *ParentPad)
Definition: SandboxIR.cpp:1258
const_handler_iterator handler_end() const
Definition: SandboxIR.h:1545
static CatchSwitchInst * create(Value *ParentPad, BasicBlock *UnwindBB, unsigned NumHandlers, BBIterator WhereIt, BasicBlock *WhereBB, Context &Ctx, const Twine &Name="")
Definition: SandboxIR.cpp:1239
const BasicBlock *(*)(const Value *) ConstDerefFnTy
Definition: SandboxIR.h:1525
BasicBlock *(*)(Value *) DerefFnTy
Definition: SandboxIR.h:1522
unsigned getNumSuccessors() const
Definition: SandboxIR.h:1561
void addHandler(BasicBlock *Dest)
Definition: SandboxIR.cpp:1278
handler_iterator handler_begin()
Definition: SandboxIR.h:1530
mapped_iterator< const_op_iterator, ConstDerefFnTy > const_handler_iterator
Definition: SandboxIR.h:1527
void setUnwindDest(BasicBlock *UnwindDest)
Definition: SandboxIR.cpp:1270
mapped_iterator< op_iterator, DerefFnTy > handler_iterator
Definition: SandboxIR.h:1523
static bool classof(const Value *From)
Definition: SandboxIR.h:1573
BasicBlock * getUnwindDest() const
Definition: SandboxIR.cpp:1265
CatchSwitchInst(llvm::CatchSwitchInst *CSI, Context &Ctx)
Definition: SandboxIR.h:1490
handler_iterator handler_end()
Definition: SandboxIR.h:1542
unsigned getNumHandlers() const
Definition: SandboxIR.h:1511
void setSuccessor(unsigned Idx, BasicBlock *NewSucc)
Definition: SandboxIR.h:1567
BasicBlock * getSuccessor(unsigned Idx) const
Definition: SandboxIR.h:1562
const_handler_range handlers() const
Definition: SandboxIR.h:1551
static ConstantInt * get(Type *Ty, uint64_t V, Context &Ctx, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: SandboxIR.cpp:1828
void verify() const override
Should crash if there is something wrong with the instruction.
Definition: SandboxIR.h:549
unsigned getUseOperandNo(const Use &Use) const override
\Returns the operand index of Use.
Definition: SandboxIR.h:545
void dumpOS(raw_ostream &OS) const override
Definition: SandboxIR.h:552
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition: SandboxIR.h:542
sandboxir::Context & getParent() const
Definition: SandboxIR.h:512
void verify() const override
Should crash if there is something wrong with the instruction.
Definition: SandboxIR.h:517
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition: SandboxIR.h:507
void dumpOS(raw_ostream &OS) const override
Definition: SandboxIR.cpp:1822
unsigned getUseOperandNo(const Use &Use) const override
\Returns the operand index of Use.
Definition: SandboxIR.h:513
friend class ConstantInt
Definition: SandboxIR.h:498
CallBrInst * createCallBrInst(llvm::CallBrInst *I)
Definition: SandboxIR.cpp:2154
GetElementPtrInst * createGetElementPtrInst(llvm::GetElementPtrInst *I)
Definition: SandboxIR.cpp:2166
DenseMap< llvm::Value *, std::unique_ptr< sandboxir::Value > > LLVMValueToValueMap
Maps LLVM Value to the corresponding sandboxir::Value.
Definition: SandboxIR.h:2235
Value * registerValue(std::unique_ptr< Value > &&VPtr)
Take ownership of VPtr and store it in LLVMValueToValueMap.
Definition: SandboxIR.cpp:1891
sandboxir::Value * getValue(llvm::Value *V) const
Definition: SandboxIR.cpp:2210
IRBuilder< ConstantFolder > LLVMIRBuilder
Definition: SandboxIR.h:2274
Argument * getOrCreateArgument(llvm::Argument *LLVMArg)
Get or create a sandboxir::Argument for an existing LLVM IR LLVMArg.
Definition: SandboxIR.h:2250
Function * createFunction(llvm::Function *F)
Create a sandboxir::Function for an existing LLVM IR F, including all blocks and instructions.
Definition: SandboxIR.cpp:2217
Value * getOrCreateValueInternal(llvm::Value *V, llvm::User *U=nullptr)
This is the actual function that creates sandboxir values for V, and among others handles all instruc...
Definition: SandboxIR.cpp:1909
std::unique_ptr< Value > detach(Value *V)
Remove SBV from all SandboxIR maps and stop owning it.
Definition: SandboxIR.cpp:1884
SwitchInst * createSwitchInst(llvm::SwitchInst *I)
Definition: SandboxIR.cpp:2175
UnreachableInst * createUnreachableInst(llvm::UnreachableInst *UI)
Definition: SandboxIR.cpp:2159
const sandboxir::Value * getValue(const llvm::Value *V) const
Definition: SandboxIR.h:2334
void accept()
Convenience function for getTracker().accept()
Definition: SandboxIR.h:2331
BranchInst * createBranchInst(llvm::BranchInst *I)
Definition: SandboxIR.cpp:2124
Constant * getOrCreateConstant(llvm::Constant *LLVMC)
Get or create a sandboxir::Constant from an existing LLVM IR LLVMC.
Definition: SandboxIR.h:2264
BasicBlock * createBasicBlock(llvm::BasicBlock *BB)
Create a sandboxir::BasicBlock for an existing LLVM IR BB.
Definition: SandboxIR.cpp:2096
UnaryOperator * createUnaryOperator(llvm::UnaryOperator *I)
Definition: SandboxIR.cpp:2179
ExtractElementInst * createExtractElementInst(llvm::ExtractElementInst *EEI)
Definition: SandboxIR.cpp:2111
LoadInst * createLoadInst(llvm::LoadInst *LI)
Definition: SandboxIR.cpp:2129
AllocaInst * createAllocaInst(llvm::AllocaInst *I)
Definition: SandboxIR.cpp:2197
Context(LLVMContext &LLVMCtx)
Definition: SandboxIR.h:2321
void revert()
Convenience function for getTracker().revert()
Definition: SandboxIR.h:2329
CallInst * createCallInst(llvm::CallInst *I)
Definition: SandboxIR.cpp:2144
AtomicRMWInst * createAtomicRMWInst(llvm::AtomicRMWInst *I)
Definition: SandboxIR.cpp:2187
std::unique_ptr< Value > detachLLVMValue(llvm::Value *V)
Remove V from the maps and returns the unique_ptr.
Definition: SandboxIR.cpp:1873
StoreInst * createStoreInst(llvm::StoreInst *SI)
Definition: SandboxIR.cpp:2134
void save()
Convenience function for getTracker().save()
Definition: SandboxIR.h:2327
Value * getOrCreateValue(llvm::Value *LLVMV)
Get or create a sandboxir::Value for an existing LLVM IR LLVMV.
Definition: SandboxIR.h:2260
InsertElementInst * createInsertElementInst(llvm::InsertElementInst *IEI)
Definition: SandboxIR.cpp:2118
AtomicCmpXchgInst * createAtomicCmpXchgInst(llvm::AtomicCmpXchgInst *I)
Definition: SandboxIR.cpp:2192
CatchSwitchInst * createCatchSwitchInst(llvm::CatchSwitchInst *I)
Definition: SandboxIR.cpp:2171
ReturnInst * createReturnInst(llvm::ReturnInst *I)
Definition: SandboxIR.cpp:2139
PHINode * createPHINode(llvm::PHINode *I)
Definition: SandboxIR.cpp:2205
SelectInst * createSelectInst(llvm::SelectInst *SI)
Definition: SandboxIR.cpp:2105
CastInst * createCastInst(llvm::CastInst *I)
Definition: SandboxIR.cpp:2201
LLVMContext & LLVMCtx
Definition: SandboxIR.h:2229
BinaryOperator * createBinaryOperator(llvm::BinaryOperator *I)
Definition: SandboxIR.cpp:2183
InvokeInst * createInvokeInst(llvm::InvokeInst *I)
Definition: SandboxIR.cpp:2149
size_t getNumValues() const
\Returns the number of values registered with Context.
Definition: SandboxIR.h:2343
static Value * create(Value *Vec, Value *Idx, Instruction *InsertBefore, Context &Ctx, const Twine &Name="")
Definition: SandboxIR.cpp:1797
const Value * getVectorOperand() const
Definition: SandboxIR.h:944
const Value * getIndexOperand() const
Definition: SandboxIR.h:945
VectorType * getVectorOperandType() const
Definition: SandboxIR.h:947
static bool classof(const Value *From)
Definition: SandboxIR.h:935
static bool isValidOperands(const Value *Vec, const Value *Idx)
Definition: SandboxIR.h:939
Argument * getArg(unsigned Idx) const
Definition: SandboxIR.h:2366
FunctionType * getFunctionType() const
Definition: SandboxIR.h:2383
iterator begin() const
Definition: SandboxIR.h:2375
void dumpNameAndArgs(raw_ostream &OS) const
Definition: SandboxIR.cpp:1835
size_t arg_size() const
Definition: SandboxIR.h:2371
void dumpOS(raw_ostream &OS) const final
Definition: SandboxIR.cpp:1850
void verify() const final
Should crash if there is something wrong with the instruction.
Definition: SandboxIR.h:2388
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition: SandboxIR.h:2362
mapped_iterator< llvm::Function::iterator, LLVMBBToBB > iterator
Definition: SandboxIR.h:2374
iterator end() const
Definition: SandboxIR.h:2379
iterator_range< op_iterator > indices()
Definition: SandboxIR.h:1442
const_op_iterator idx_begin() const
Definition: SandboxIR.h:1435
unsigned getPointerAddressSpace() const
Definition: SandboxIR.h:1456
GEPNoWrapFlags getNoWrapFlags() const
Definition: SandboxIR.h:1468
static Value * create(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, BBIterator WhereIt, BasicBlock *WhereBB, Context &Ctx, const Twine &NameStr="")
static unsigned getPointerOperandIndex()
Definition: SandboxIR.h:1450
static bool classof(const Value *From)
Definition: SandboxIR.h:1420
const_op_iterator idx_end() const
Definition: SandboxIR.h:1439
bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const
Definition: SandboxIR.h:1480
iterator_range< const_op_iterator > indices() const
Definition: SandboxIR.h:1445
static Value * create(Value *Vec, Value *NewElt, Value *Idx, Instruction *InsertBefore, Context &Ctx, const Twine &Name="")
Definition: SandboxIR.cpp:1771
static bool isValidOperands(const Value *Vec, const Value *NewElt, const Value *Idx)
Definition: SandboxIR.h:914
static bool classof(const Value *From)
Definition: SandboxIR.h:911
A sandboxir::User with operands, opcode and linked with previous/next instructions in an instruction ...
Definition: SandboxIR.h:650
bool hasNoUnsignedWrap() const
Determine whether the no signed wrap flag is set.
Definition: SandboxIR.h:738
friend class UnreachableInst
Definition: SandboxIR.h:689
BBIterator getIterator() const
\Returns a BasicBlock::iterator for this Instruction.
Definition: SandboxIR.cpp:331
void removeFromParent()
Detach this from its parent BasicBlock without deleting it.
Definition: SandboxIR.cpp:359
bool hasAllowReassoc() const
Determine whether the allow-reassociation flag is set.
Definition: SandboxIR.h:758
virtual unsigned getNumOfIRInstrs() const =0
This is used by BasicBlock::iterator.
bool hasNoSignedZeros() const
Determine whether the no-signed-zeros flag is set.
Definition: SandboxIR.h:783
void copyFastMathFlags(FastMathFlags FMF)
Convenience function for transferring all fast-math flag values to this instruction,...
Definition: SandboxIR.cpp:558
void setHasNoSignedZeros(bool B)
Set or clear the no-signed-zeros flag on this instruction, which must be an operator which supports t...
Definition: SandboxIR.cpp:527
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition: SandboxIR.cpp:464
void moveAfter(Instruction *After)
Move this instruction after After.
Definition: SandboxIR.h:728
bool hasAllowContract() const
Determine whether the allow-contract flag is set.
Definition: SandboxIR.h:799
void setHasAllowContract(bool B)
Set or clear the allow-contract flag on this instruction, which must be an operator which supports th...
Definition: SandboxIR.cpp:543
void setIsExact(bool B=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag.
Definition: SandboxIR.cpp:497
bool hasApproxFunc() const
Determine whether the approximate-math-functions flag is set.
Definition: SandboxIR.h:807
bool hasNoSignedWrap() const
Determine whether the no signed wrap flag is set.
Definition: SandboxIR.h:745
void setHasNoNaNs(bool B)
Set or clear the no-nans flag on this instruction, which must be an operator which supports this flag...
Definition: SandboxIR.cpp:511
void insertInto(BasicBlock *BB, const BBIterator &WhereIt)
Insert this detached instruction into BB at WhereIt.
Definition: SandboxIR.cpp:433
Opcode getOpcode() const
\Returns this Instruction's opcode.
Definition: SandboxIR.h:710
void setHasApproxFunc(bool B)
Set or clear the approximate-math-functions flag on this instruction, which must be an operator which...
Definition: SandboxIR.cpp:565
bool isFast() const
Determine whether all fast-math-flags are set.
Definition: SandboxIR.h:752
static const char * getOpcodeName(Opcode Opc)
Definition: SandboxIR.cpp:307
void setHasAllowReassoc(bool B)
Set or clear the reassociation flag on this instruction, which must be an operator which supports thi...
Definition: SandboxIR.cpp:504
void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
Definition: SandboxIR.cpp:551
void eraseFromParent()
Detach this Value from its parent and delete it.
Definition: SandboxIR.cpp:367
Instruction * getNextNode() const
\Returns the next sandboxir::Instruction in the block, or nullptr if at the end of the block.
Definition: SandboxIR.cpp:336
void moveBefore(BasicBlock &BB, const BBIterator &WhereIt)
Move this instruction to WhereIt.
Definition: SandboxIR.cpp:391
llvm::Instruction * getTopmostLLVMInstruction() const
A SandboxIR Instruction may map to multiple LLVM IR Instruction.
Definition: SandboxIR.cpp:319
void setHasNoInfs(bool B)
Set or clear the no-infs flag on this instruction, which must be an operator which supports this flag...
Definition: SandboxIR.cpp:519
void insertAfter(Instruction *AfterI)
Insert this detached instruction after AfterI.
Definition: SandboxIR.cpp:429
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: SandboxIR.h:724
void dumpOS(raw_ostream &OS) const override
Definition: SandboxIR.cpp:573
bool isExact() const
Determine whether the exact flag is set.
Definition: SandboxIR.h:766
Instruction * getPrevNode() const
\Returns the previous sandboxir::Instruction in the block, or nullptr if at the beginning of the bloc...
Definition: SandboxIR.cpp:351
Instruction(ClassID ID, Opcode Opc, llvm::Instruction *I, sandboxir::Context &SBCtx)
Definition: SandboxIR.h:660
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
Definition: SandboxIR.h:817
void setHasNoSignedWrap(bool B=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
Definition: SandboxIR.cpp:483
void setHasAllowReciprocal(bool B)
Set or clear the allow-reciprocal flag on this instruction, which must be an operator which supports ...
Definition: SandboxIR.cpp:535
bool hasNoInfs() const
Determine whether the no-infs flag is set.
Definition: SandboxIR.h:777
bool hasNoNaNs() const
Determine whether the no-NaNs flag is set.
Definition: SandboxIR.h:771
bool hasAllowReciprocal() const
Determine whether the allow-reciprocal flag is set.
Definition: SandboxIR.h:791
void setFast(bool B)
Set or clear all fast-math-flags on this instruction, which must be an operator which supports this f...
Definition: SandboxIR.cpp:490
void setHasNoUnsignedWrap(bool B=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
Definition: SandboxIR.cpp:475
void insertBefore(Instruction *BeforeI)
Insert this detached instruction before BeforeI.
Definition: SandboxIR.cpp:415
BasicBlock * getParent() const
\Returns the BasicBlock containing this Instruction, or null if it is detached.
Definition: SandboxIR.cpp:455
Instruction * getLandingPadInst() const
Definition: SandboxIR.cpp:948
BasicBlock * getSuccessor(unsigned SuccIdx) const
Definition: SandboxIR.cpp:953
void setNormalDest(BasicBlock *BB)
Definition: SandboxIR.cpp:940
unsigned getNumSuccessors() const
Definition: SandboxIR.h:1348
static InvokeInst * create(FunctionType *FTy, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, BBIterator WhereIt, BasicBlock *WhereBB, Context &Ctx, const Twine &NameStr="")
Definition: SandboxIR.cpp:894
static bool classof(const Value *From)
Definition: SandboxIR.h:1331
void setUnwindDest(BasicBlock *BB)
Definition: SandboxIR.cpp:944
void setSuccessor(unsigned SuccIdx, BasicBlock *NewSucc)
Definition: SandboxIR.h:1341
BasicBlock * getNormalDest() const
Definition: SandboxIR.cpp:932
BasicBlock * getUnwindDest() const
Definition: SandboxIR.cpp:936
static bool classof(const Value *From)
For isa/dyn_cast.
Definition: SandboxIR.cpp:724
bool isUnordered() const
Definition: SandboxIR.h:1070
static LoadInst * create(Type *Ty, Value *Ptr, MaybeAlign Align, Instruction *InsertBefore, Context &Ctx, const Twine &Name="")
Definition: SandboxIR.cpp:689
void setVolatile(bool V)
Specify whether this is a volatile load or not.
Definition: SandboxIR.cpp:682
Align getAlign() const
Definition: SandboxIR.h:1069
bool isVolatile() const
Return true if this is a load from a volatile memory location.
Definition: SandboxIR.h:1049
Value * getPointerOperand() const
Definition: SandboxIR.cpp:728
An LLLVM Instruction that has no SandboxIR equivalent class gets mapped to an OpaqueInstr.
Definition: SandboxIR.h:2214
static bool classof(const sandboxir::Value *From)
Definition: SandboxIR.h:2222
Iterator for the Use edges of a User's operands.
Definition: SandboxIR.h:143
std::input_iterator_tag iterator_category
Definition: SandboxIR.h:156
OperandUseIterator operator++(int)
Definition: SandboxIR.h:161
OperandUseIterator operator+(unsigned Num) const
Definition: SandboxIR.cpp:89
bool operator!=(const OperandUseIterator &Other) const
Definition: SandboxIR.h:169
bool operator==(const OperandUseIterator &Other) const
Definition: SandboxIR.h:166
OperandUseIterator operator-(unsigned Num) const
Definition: SandboxIR.cpp:95
OperandUseIterator & operator++()
Definition: SandboxIR.cpp:66
iterator_range< const_block_iterator > blocks() const
Definition: SandboxIR.h:2167
const_block_iterator block_end() const
Definition: SandboxIR.h:2162
static bool classof(const Value *From)
For isa/dyn_cast.
Definition: SandboxIR.cpp:1100
const_op_range incoming_values() const
Definition: SandboxIR.h:2173
void setIncomingBlock(unsigned Idx, BasicBlock *BB)
Definition: SandboxIR.cpp:1123
bool hasConstantOrUndefValue() const
Definition: SandboxIR.h:2201
void replaceIncomingBlockWith(const BasicBlock *Old, BasicBlock *New)
Definition: SandboxIR.cpp:1173
void setIncomingValue(unsigned Idx, Value *V)
Definition: SandboxIR.cpp:1107
unsigned getNumIncomingValues() const
Definition: SandboxIR.h:2175
void addIncoming(Value *V, BasicBlock *BB)
Definition: SandboxIR.cpp:1134
bool isComplete() const
Definition: SandboxIR.h:2204
const_block_iterator block_begin() const
Definition: SandboxIR.h:2157
int getBasicBlockIndex(const BasicBlock *BB) const
Definition: SandboxIR.cpp:1159
mapped_iterator< llvm::PHINode::const_block_iterator, LLVMBBToBB > const_block_iterator
Definition: SandboxIR.h:2155
Value * removeIncomingValue(unsigned Idx)
Definition: SandboxIR.cpp:1141
void removeIncomingValueIf(function_ref< bool(unsigned)> Predicate)
Definition: SandboxIR.cpp:1180
Value * hasConstantValue() const
Definition: SandboxIR.cpp:1169
op_range incoming_values()
Definition: SandboxIR.h:2171
static unsigned getIncomingValueNumForOperand(unsigned Idx)
Definition: SandboxIR.h:2183
Value * getIncomingValueForBlock(const BasicBlock *BB) const
Definition: SandboxIR.cpp:1163
BasicBlock * getIncomingBlock(unsigned Idx) const
Definition: SandboxIR.cpp:1114
static unsigned getOperandNumForIncomingValue(unsigned Idx)
Definition: SandboxIR.h:2180
static PHINode * create(Type *Ty, unsigned NumReservedValues, Instruction *InsertBefore, Context &Ctx, const Twine &Name="")
Definition: SandboxIR.cpp:1092
Value * getIncomingValue(unsigned Idx) const
Definition: SandboxIR.cpp:1104
static bool classof(const Value *From)
Definition: SandboxIR.h:1143
Value * getReturnValue() const
\Returns null if there is no return value.
Definition: SandboxIR.cpp:829
static ReturnInst * create(Value *RetVal, Instruction *InsertBefore, Context &Ctx)
Definition: SandboxIR.cpp:814
static Value * create(Value *Cond, Value *True, Value *False, Instruction *InsertBefore, Context &Ctx, const Twine &Name="")
Definition: SandboxIR.cpp:589
void setTrueValue(Value *New)
Definition: SandboxIR.h:889
static bool classof(const Value *From)
For isa/dyn_cast.
Definition: SandboxIR.cpp:607
void setCondition(Value *New)
Definition: SandboxIR.h:888
void setFalseValue(Value *New)
Definition: SandboxIR.h:890
Instructions that contain a single LLVM Instruction can inherit from this.
Definition: SandboxIR.h:835
void dumpOS(raw_ostream &OS) const override
Definition: SandboxIR.h:860
void verify() const final
Should crash if there is something wrong with the instruction.
Definition: SandboxIR.h:859
unsigned getUseOperandNo(const Use &Use) const final
\Returns the operand index of Use.
Definition: SandboxIR.h:854
unsigned getNumOfIRInstrs() const final
This is used by BasicBlock::iterator.
Definition: SandboxIR.h:857
static bool classof(const Value *From)
For isa/dyn_cast.
Definition: SandboxIR.cpp:771
void setVolatile(bool V)
Specify whether this is a volatile store or not.
Definition: SandboxIR.cpp:732
static StoreInst * create(Value *V, Value *Ptr, MaybeAlign Align, Instruction *InsertBefore, Context &Ctx)
Definition: SandboxIR.cpp:739
bool isVolatile() const
Return true if this is a store from a volatile memory location.
Definition: SandboxIR.h:1082
Value * getPointerOperand() const
Definition: SandboxIR.cpp:779
Value * getValueOperand() const
Definition: SandboxIR.cpp:775
BasicBlock * getSuccessor(unsigned Idx) const
Definition: SandboxIR.cpp:1348
CaseIt findCaseValue(const ConstantInt *C)
Definition: SandboxIR.h:1628
iterator_range< ConstCaseIt > cases() const
Definition: SandboxIR.h:1621
bool defaultDestUndefined() const
Definition: SandboxIR.h:1593
void setSuccessor(unsigned Idx, BasicBlock *NewSucc)
Definition: SandboxIR.cpp:1353
void setDefaultDest(BasicBlock *DefaultCase)
Definition: SandboxIR.cpp:1315
CaseIt case_begin()
Returns a read/write iterator that points to the first case in the SwitchInst.
Definition: SandboxIR.h:1611
iterator_range< CaseIt > cases()
Iteration adapter for range-for loops.
Definition: SandboxIR.h:1618
void addCase(ConstantInt *OnVal, BasicBlock *Dest)
Definition: SandboxIR.cpp:1328
llvm::SwitchInst::CaseIteratorImpl< CaseHandle > CaseIt
Definition: SandboxIR.h:1606
SwitchInst(llvm::SwitchInst *SI, Context &Ctx)
Definition: SandboxIR.h:1580
ConstCaseIt case_begin() const
Definition: SandboxIR.h:1612
ConstCaseIt case_end() const
Definition: SandboxIR.h:1616
llvm::SwitchInst::CaseIteratorImpl< ConstCaseHandle > ConstCaseIt
Definition: SandboxIR.h:1607
ConstCaseIt case_default() const
Definition: SandboxIR.h:1625
static bool classof(const Value *From)
Definition: SandboxIR.h:1658
BasicBlock * getDefaultDest() const
Definition: SandboxIR.cpp:1310
static SwitchInst * create(Value *V, BasicBlock *Dest, unsigned NumCases, BasicBlock::iterator WhereIt, BasicBlock *WhereBB, Context &Ctx, const Twine &Name="")
Definition: SandboxIR.cpp:1284
Value * getCondition() const
Definition: SandboxIR.cpp:1298
unsigned getNumCases() const
Definition: SandboxIR.h:1597
unsigned getNumSuccessors() const
Definition: SandboxIR.h:1653
CaseIt case_end()
Returns a read/write iterator that points one past the last in the SwitchInst.
Definition: SandboxIR.h:1615
ConstCaseIt findCaseValue(const ConstantInt *C) const
Definition: SandboxIR.h:1633
ConstantInt * findCaseDest(BasicBlock *BB)
Definition: SandboxIR.cpp:1322
static constexpr const unsigned DefaultPseudoIndex
Definition: SandboxIR.h:1583
CaseIt removeCase(CaseIt It)
This method removes the specified case and its successor from the switch instruction.
Definition: SandboxIR.cpp:1335
The tracker collects all the change objects and implements the main API for saving / reverting / acce...
Definition: Tracker.h:360
void revert()
Stops tracking and reverts to saved state.
Definition: Tracker.cpp:239
void save()
Turns on IR tracking.
Definition: Tracker.cpp:237
void accept()
Stops tracking and accept changes.
Definition: Tracker.cpp:247
An abstract class, parent of unary instructions.
Definition: SandboxIR.h:1026
static bool classof(const Instruction *I)
Definition: SandboxIR.h:1033
UnaryInstruction(ClassID ID, Opcode Opc, llvm::Instruction *LLVMI, Context &Ctx)
Definition: SandboxIR.h:1028
static bool classof(const Value *V)
Definition: SandboxIR.h:1036
static bool classof(const Value *From)
For isa/dyn_cast.
Definition: SandboxIR.h:1699
static Value * create(Instruction::Opcode Op, Value *OpV, BBIterator WhereIt, BasicBlock *WhereBB, Context &Ctx, const Twine &Name="")
Definition: SandboxIR.cpp:1362
static Value * createWithCopiedFlags(Instruction::Opcode Op, Value *OpV, Value *CopyFrom, BBIterator WhereIt, BasicBlock *WhereBB, Context &Ctx, const Twine &Name="")
Definition: SandboxIR.cpp:1391
static bool classof(const Value *From)
Definition: SandboxIR.cpp:800
static UnreachableInst * create(Instruction *InsertBefore, Context &Ctx)
Definition: SandboxIR.cpp:783
unsigned getNumOfIRInstrs() const final
This is used by BasicBlock::iterator.
Definition: SandboxIR.h:1125
unsigned getUseOperandNo(const Use &Use) const final
\Returns the operand index of Use.
Definition: SandboxIR.h:1122
unsigned getNumSuccessors() const
Definition: SandboxIR.h:1121
Represents a Def-use/Use-def edge in SandboxIR.
Definition: Use.h:32
unsigned getOperandNo() const
Definition: SandboxIR.cpp:25
Value * get() const
Definition: SandboxIR.cpp:18
void set(Value *V)
Definition: SandboxIR.cpp:20
class User * getUser() const
Definition: Use.h:54
Iterator for the Use edges of a Value's users.
Definition: SandboxIR.h:179
const sandboxir::Use & getUse() const
Definition: SandboxIR.h:201
std::input_iterator_tag iterator_category
Definition: SandboxIR.h:190
bool operator!=(const UserUseIterator &Other) const
Definition: SandboxIR.h:198
UserUseIterator & operator++()
Definition: SandboxIR.cpp:73
value_type operator*() const
Definition: SandboxIR.h:193
bool operator==(const UserUseIterator &Other) const
Definition: SandboxIR.h:195
A sandboxir::User has operands.
Definition: SandboxIR.h:403
virtual op_iterator op_begin()
Definition: SandboxIR.h:447
void dumpOS(raw_ostream &OS) const override
Definition: SandboxIR.h:487
friend class OperandUseIterator
Definition: SandboxIR.h:416
Value * getOperand(unsigned OpIdx) const
Definition: SandboxIR.h:467
virtual unsigned getUseOperandNo(const Use &Use) const =0
\Returns the operand index of Use.
unsigned getUseOperandNoDefault(const Use &Use) const
The default implementation works only for single-LLVMIR-instruction Users and only if they match exac...
Definition: SandboxIR.h:420
virtual const_op_iterator op_end() const
Definition: SandboxIR.h:459
static bool classof(const Value *From)
For isa/dyn_cast.
Definition: SandboxIR.cpp:238
bool replaceUsesOfWith(Value *FromV, Value *ToV)
Replaces any operands that match FromV with ToV.
Definition: SandboxIR.cpp:260
void verifyUserOfLLVMUse(const llvm::Use &Use) const
Definition: SandboxIR.cpp:232
op_range operands()
Definition: SandboxIR.h:463
void verify() const override
Should crash if there is something wrong with the instruction.
Definition: SandboxIR.h:483
Use getOperandUseDefault(unsigned OpIdx, bool Verify) const
\Returns the Use edge that corresponds to OpIdx.
Definition: SandboxIR.cpp:220
OperandUseIterator op_iterator
Definition: SandboxIR.h:442
const_op_range operands() const
Definition: SandboxIR.h:464
virtual void setOperand(unsigned OperandIdx, Value *Operand)
Definition: SandboxIR.cpp:253
virtual Use getOperandUseInternal(unsigned OpIdx, bool Verify) const =0
\Returns the Use for the OpIdx'th operand.
void swapOperandsInternal(unsigned OpIdxA, unsigned OpIdxB)
Definition: SandboxIR.h:427
virtual unsigned getNumOperands() const
Definition: SandboxIR.h:473
virtual const_op_iterator op_begin() const
Definition: SandboxIR.h:456
Use getOperandUse(unsigned OpIdx) const
\Returns the operand edge for OpIdx.
Definition: SandboxIR.h:470
virtual op_iterator op_end()
Definition: SandboxIR.h:451
User(ClassID ID, llvm::Value *V, Context &Ctx)
Definition: SandboxIR.h:405
void dumpCommonHeader(raw_ostream &OS) const final
Definition: SandboxIR.cpp:274
A SandboxIR Value has users. This is the base class.
Definition: SandboxIR.h:205
mapped_iterator< sandboxir::UserUseIterator, UseToUser > user_iterator
Definition: SandboxIR.h:309
LLVM_DUMP_METHOD void dump() const
Definition: SandboxIR.cpp:206
use_iterator use_begin()
Definition: SandboxIR.cpp:115
llvm::Value * Val
The LLVM Value that corresponds to this SandboxIR Value.
Definition: SandboxIR.h:241
std::string getUid() const
Returns the unique id in the form 'SB<number>.' like 'SB1.'.
Definition: SandboxIR.cpp:169
const_use_iterator use_end() const
Definition: SandboxIR.h:293
user_iterator user_begin()
Definition: SandboxIR.cpp:125
void replaceAllUsesWith(Value *Other)
Definition: SandboxIR.cpp:156
ClassID getSubclassID() const
Definition: SandboxIR.h:283
StringRef getName() const
\Returns the LLVM IR name of the bottom-most LLVM value.
Definition: SandboxIR.h:362
virtual void verify() const =0
Should crash if there is something wrong with the instruction.
void dumpCommonFooter(raw_ostream &OS) const
Definition: SandboxIR.cpp:179
virtual void dumpCommonHeader(raw_ostream &OS) const
Definition: SandboxIR.cpp:175
UserUseIterator use_iterator
Definition: SandboxIR.h:285
Context & Ctx
All values point to the context.
Definition: SandboxIR.h:271
ClassID SubclassID
For isa/dyn_cast.
Definition: SandboxIR.h:232
user_iterator user_end()
Definition: SandboxIR.h:313
void dumpCommonSuffix(raw_ostream &OS) const
Definition: SandboxIR.cpp:195
Type * getType() const
Definition: SandboxIR.h:353
friend class Use
Definition: SandboxIR.h:245
friend class LLVMOpUserItToSBTy
Definition: SandboxIR.h:274
virtual ~Value()=default
const_use_iterator use_begin() const
Definition: SandboxIR.h:289
Context & getContext() const
Definition: SandboxIR.h:355
const_user_iterator user_begin() const
Definition: SandboxIR.h:316
bool hasNUsesOrMore(unsigned Num) const
Return true if this value has N uses or more.
Definition: SandboxIR.h:335
Value & operator=(const Value &)=delete
iterator_range< const_user_iterator > users() const
Definition: SandboxIR.h:326
iterator_range< user_iterator > users()
Definition: SandboxIR.h:323
void replaceUsesWithIf(Value *OtherV, llvm::function_ref< bool(const Use &)> ShouldReplace)
Definition: SandboxIR.cpp:138
unsigned getNumUses() const
\Returns the number of user edges (not necessarily to unique users).
Definition: SandboxIR.cpp:136
bool hasNUses(unsigned Num) const
Return true if this Value has exactly N uses.
Definition: SandboxIR.h:344
unsigned UID
A unique ID used for forming the name (used for debugging).
Definition: SandboxIR.h:235
virtual void dumpOS(raw_ostream &OS) const =0
use_iterator use_end()
Definition: SandboxIR.h:292
iterator_range< use_iterator > uses()
Definition: SandboxIR.h:297
const_user_iterator user_end() const
Definition: SandboxIR.h:319
void dumpCommonPrefix(raw_ostream &OS) const
Definition: SandboxIR.cpp:188
void printAsOperandCommon(raw_ostream &OS) const
Definition: SandboxIR.cpp:199
static const char * getSubclassIDStr(ClassID ID)
Definition: SandboxIR.h:215
Value(const Value &)=delete
Disable copies.
friend raw_ostream & operator<<(raw_ostream &OS, const sandboxir::Value &V)
Definition: SandboxIR.h:374
iterator_range< const_use_iterator > uses() const
Definition: SandboxIR.h:300
#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
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ 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:1749
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1886
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
Helper for mapped_iterator.
Definition: SandboxIR.h:305
User * operator()(const Use &Use) const
Definition: SandboxIR.h:306