Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:25

0001 //===- Function.h -----------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_SANDBOXIR_FUNCTION_H
0010 #define LLVM_SANDBOXIR_FUNCTION_H
0011 
0012 #include "llvm/IR/Function.h"
0013 #include "llvm/SandboxIR/Constant.h"
0014 
0015 namespace llvm::sandboxir {
0016 
0017 class Function : public GlobalWithNodeAPI<Function, llvm::Function,
0018                                           GlobalObject, llvm::GlobalObject> {
0019   /// Helper for mapped_iterator.
0020   struct LLVMBBToBB {
0021     Context &Ctx;
0022     LLVMBBToBB(Context &Ctx) : Ctx(Ctx) {}
0023     BasicBlock &operator()(llvm::BasicBlock &LLVMBB) const {
0024       return *cast<BasicBlock>(Ctx.getValue(&LLVMBB));
0025     }
0026   };
0027   /// Use Context::createFunction() instead.
0028   Function(llvm::Function *F, sandboxir::Context &Ctx)
0029       : GlobalWithNodeAPI(ClassID::Function, F, Ctx) {}
0030   friend class Context; // For constructor.
0031 
0032 public:
0033   /// For isa/dyn_cast.
0034   static bool classof(const sandboxir::Value *From) {
0035     return From->getSubclassID() == ClassID::Function;
0036   }
0037 
0038   Module *getParent() {
0039     return Ctx.getModule(cast<llvm::Function>(Val)->getParent());
0040   }
0041 
0042   Argument *getArg(unsigned Idx) const {
0043     llvm::Argument *Arg = cast<llvm::Function>(Val)->getArg(Idx);
0044     return cast<Argument>(Ctx.getValue(Arg));
0045   }
0046 
0047   size_t arg_size() const { return cast<llvm::Function>(Val)->arg_size(); }
0048   bool arg_empty() const { return cast<llvm::Function>(Val)->arg_empty(); }
0049 
0050   using iterator = mapped_iterator<llvm::Function::iterator, LLVMBBToBB>;
0051   iterator begin() const {
0052     LLVMBBToBB BBGetter(Ctx);
0053     return iterator(cast<llvm::Function>(Val)->begin(), BBGetter);
0054   }
0055   iterator end() const {
0056     LLVMBBToBB BBGetter(Ctx);
0057     return iterator(cast<llvm::Function>(Val)->end(), BBGetter);
0058   }
0059   FunctionType *getFunctionType() const;
0060 
0061 #ifndef NDEBUG
0062   void verify() const final {
0063     assert(isa<llvm::Function>(Val) && "Expected Function!");
0064   }
0065   void dumpNameAndArgs(raw_ostream &OS) const;
0066   void dumpOS(raw_ostream &OS) const final;
0067 #endif
0068 };
0069 
0070 } // namespace llvm::sandboxir
0071 
0072 #endif // LLVM_SANDBOXIR_FUNCTION_H