@@ -75,6 +75,7 @@ class BasicBlock;
7575class Context ;
7676class Function ;
7777class Instruction ;
78+ class SelectInst ;
7879class LoadInst ;
7980class ReturnInst ;
8081class StoreInst ;
@@ -177,6 +178,7 @@ class Value {
177178 friend class Context ; // For getting `Val`.
178179 friend class User ; // For getting `Val`.
179180 friend class Use ; // For getting `Val`.
181+ friend class SelectInst ; // For getting `Val`.
180182 friend class LoadInst ; // For getting `Val`.
181183 friend class StoreInst ; // For getting `Val`.
182184 friend class ReturnInst ; // For getting `Val`.
@@ -411,6 +413,8 @@ class Constant : public sandboxir::User {
411413 }
412414
413415public:
416+ static Constant *createInt (Type *Ty, uint64_t V, Context &Ctx,
417+ bool IsSigned = false );
414418 // / For isa/dyn_cast.
415419 static bool classof (const sandboxir::Value *From) {
416420 return From->getSubclassID () == ClassID::Constant ||
@@ -499,6 +503,7 @@ class Instruction : public sandboxir::User {
499503 // / A SandboxIR Instruction may map to multiple LLVM IR Instruction. This
500504 // / returns its topmost LLVM IR instruction.
501505 llvm::Instruction *getTopmostLLVMInstruction () const ;
506+ friend class SelectInst ; // For getTopmostLLVMInstruction().
502507 friend class LoadInst ; // For getTopmostLLVMInstruction().
503508 friend class StoreInst ; // For getTopmostLLVMInstruction().
504509 friend class ReturnInst ; // For getTopmostLLVMInstruction().
@@ -566,6 +571,52 @@ class Instruction : public sandboxir::User {
566571#endif
567572};
568573
574+ class SelectInst : public Instruction {
575+ // / Use Context::createSelectInst(). Don't call the
576+ // / constructor directly.
577+ SelectInst (llvm::SelectInst *CI, Context &Ctx)
578+ : Instruction(ClassID::Select, Opcode::Select, CI, Ctx) {}
579+ friend Context; // for SelectInst()
580+ Use getOperandUseInternal (unsigned OpIdx, bool Verify) const final {
581+ return getOperandUseDefault (OpIdx, Verify);
582+ }
583+ SmallVector<llvm::Instruction *, 1 > getLLVMInstrs () const final {
584+ return {cast<llvm::Instruction>(Val)};
585+ }
586+ static Value *createCommon (Value *Cond, Value *True, Value *False,
587+ const Twine &Name, IRBuilder<> &Builder,
588+ Context &Ctx);
589+
590+ public:
591+ unsigned getUseOperandNo (const Use &Use) const final {
592+ return getUseOperandNoDefault (Use);
593+ }
594+ unsigned getNumOfIRInstrs () const final { return 1u ; }
595+ static Value *create (Value *Cond, Value *True, Value *False,
596+ Instruction *InsertBefore, Context &Ctx,
597+ const Twine &Name = " " );
598+ static Value *create (Value *Cond, Value *True, Value *False,
599+ BasicBlock *InsertAtEnd, Context &Ctx,
600+ const Twine &Name = " " );
601+ Value *getCondition () { return getOperand (0 ); }
602+ Value *getTrueValue () { return getOperand (1 ); }
603+ Value *getFalseValue () { return getOperand (2 ); }
604+
605+ void setCondition (Value *New) { setOperand (0 , New); }
606+ void setTrueValue (Value *New) { setOperand (1 , New); }
607+ void setFalseValue (Value *New) { setOperand (2 , New); }
608+ void swapValues () { cast<llvm::SelectInst>(Val)->swapValues (); }
609+ // / For isa/dyn_cast.
610+ static bool classof (const Value *From);
611+ #ifndef NDEBUG
612+ void verify () const final {
613+ assert (isa<llvm::SelectInst>(Val) && " Expected SelectInst!" );
614+ }
615+ void dump (raw_ostream &OS) const override ;
616+ LLVM_DUMP_METHOD void dump () const override ;
617+ #endif
618+ };
619+
569620class LoadInst final : public Instruction {
570621 // / Use LoadInst::create() instead of calling the constructor.
571622 LoadInst (llvm::LoadInst *LI, Context &Ctx)
@@ -803,6 +854,11 @@ class Context {
803854 Value *getOrCreateValue (llvm::Value *LLVMV) {
804855 return getOrCreateValueInternal (LLVMV, 0 );
805856 }
857+ // / Get or create a sandboxir::Constant from an existing LLVM IR \p LLVMC.
858+ Constant *getOrCreateConstant (llvm::Constant *LLVMC) {
859+ return cast<Constant>(getOrCreateValueInternal (LLVMC, 0 ));
860+ }
861+ friend class Constant ; // For getOrCreateConstant().
806862 // / Create a sandboxir::BasicBlock for an existing LLVM IR \p BB. This will
807863 // / also create all contents of the block.
808864 BasicBlock *createBasicBlock (llvm::BasicBlock *BB);
@@ -812,6 +868,8 @@ class Context {
812868 IRBuilder<ConstantFolder> LLVMIRBuilder;
813869 auto &getLLVMIRBuilder () { return LLVMIRBuilder; }
814870
871+ SelectInst *createSelectInst (llvm::SelectInst *SI);
872+ friend SelectInst; // For createSelectInst()
815873 LoadInst *createLoadInst (llvm::LoadInst *LI);
816874 friend LoadInst; // For createLoadInst()
817875 StoreInst *createStoreInst (llvm::StoreInst *SI);
0 commit comments