[llvm] [SandboxIR] Implement AllocaInst (PR #102027)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 6 10:22:41 PDT 2024
================
@@ -1393,6 +1396,108 @@ class GetElementPtrInst final : public Instruction {
#endif
};
+class AllocaInst final : public UnaryInstruction {
+ Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
+ return getOperandUseDefault(OpIdx, Verify);
+ }
+ SmallVector<llvm::Instruction *, 1> getLLVMInstrs() const final {
+ return {cast<llvm::Instruction>(Val)};
+ }
+
+public:
+ AllocaInst(llvm::AllocaInst *AI, Context &Ctx)
+ : UnaryInstruction(ClassID::Alloca, Instruction::Opcode::Alloca, AI,
+ Ctx) {}
+
+ static AllocaInst *create(Type *Ty, unsigned AddrSpace, BBIterator WhereIt,
+ BasicBlock *WhereBB, Context &Ctx,
+ Value *ArraySize = nullptr, const Twine &Name = "");
+ static AllocaInst *create(Type *Ty, unsigned AddrSpace,
+ Instruction *InsertBefore, Context &Ctx,
+ Value *ArraySize = nullptr, const Twine &Name = "");
+ static AllocaInst *create(Type *Ty, unsigned AddrSpace,
+ BasicBlock *InsertAtEnd, Context &Ctx,
+ Value *ArraySize = nullptr, const Twine &Name = "");
+
+ unsigned getUseOperandNo(const Use &Use) const final {
+ return getUseOperandNoDefault(Use);
+ }
+ unsigned getNumOfIRInstrs() const final { return 1u; }
+
+ /// Return true if there is an allocation size parameter to the allocation
+ /// instruction that is not 1.
+ bool isArrayAllocation() const {
+ return cast<llvm::AllocaInst>(Val)->isArrayAllocation();
+ }
+ /// Get the number of elements allocated. For a simple allocation of a single
+ /// element, this will return a constant 1 value.
+ Value *getArraySize();
+ const Value *getArraySize() const {
+ return const_cast<AllocaInst *>(this)->getArraySize();
+ }
+ /// Overload to return most specific pointer type.
+ PointerType *getType() const {
+ return cast<llvm::AllocaInst>(Val)->getType();
+ }
+ /// Return the address space for the allocation.
+ unsigned getAddressSpace() const {
+ return cast<llvm::AllocaInst>(Val)->getAddressSpace();
+ }
+ /// Get allocation size in bytes. Returns std::nullopt if size can't be
+ /// determined, e.g. in case of a VLA.
+ std::optional<TypeSize> getAllocationSize(const DataLayout &DL) const {
+ return cast<llvm::AllocaInst>(Val)->getAllocationSize(DL);
+ }
+ /// Get allocation size in bits. Returns std::nullopt if size can't be
+ /// determined, e.g. in case of a VLA.
+ std::optional<TypeSize> getAllocationSizeInBits(const DataLayout &DL) const {
+ return cast<llvm::AllocaInst>(Val)->getAllocationSizeInBits(DL);
+ }
+ /// Return the type that is being allocated by the instruction.
+ Type *getAllocatedType() const {
+ return cast<llvm::AllocaInst>(Val)->getAllocatedType();
+ }
+ /// for use only in special circumstances that need to generically
+ /// transform a whole instruction (eg: IR linking and vectorization).
+ void setAllocatedType(Type *Ty);
+ /// Return the alignment of the memory that is being allocated by the
+ /// instruction.
+ Align getAlign() const { return cast<llvm::AllocaInst>(Val)->getAlign(); }
+ void setAlignment(Align Align);
+ /// Return true if this alloca is in the entry block of the function and is a
+ /// constant size. If so, the code generator will fold it into the
+ /// prolog/epilog code, so it is basically free.
+ bool isStaticAlloca() const {
+ return cast<llvm::AllocaInst>(Val)->isStaticAlloca();
+ }
+ /// Return true if this alloca is used as an inalloca argument to a call. Such
+ /// allocas are never considered static even if they are in the entry block.
+ bool isUsedWithInAlloca() const {
----------------
vporpo wrote:
I recall having to add some special casing for `inalloca` in the scheduler's DAG, because of some instruction ordering issue related to it. So I would rather keep it.
Yeah I can drop the swifterror one.
https://github.com/llvm/llvm-project/pull/102027
More information about the llvm-commits
mailing list