LLVM 20.0.0git
Function.h
Go to the documentation of this file.
1//===- Function.h -----------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_SANDBOXIR_FUNCTION_H
10#define LLVM_SANDBOXIR_FUNCTION_H
11
12#include "llvm/IR/Function.h"
14
15namespace llvm::sandboxir {
16
17class Function : public GlobalWithNodeAPI<Function, llvm::Function,
18 GlobalObject, llvm::GlobalObject> {
19 /// Helper for mapped_iterator.
20 struct LLVMBBToBB {
21 Context &Ctx;
22 LLVMBBToBB(Context &Ctx) : Ctx(Ctx) {}
23 BasicBlock &operator()(llvm::BasicBlock &LLVMBB) const {
24 return *cast<BasicBlock>(Ctx.getValue(&LLVMBB));
25 }
26 };
27 /// Use Context::createFunction() instead.
29 : GlobalWithNodeAPI(ClassID::Function, F, Ctx) {}
30 friend class Context; // For constructor.
31
32public:
33 /// For isa/dyn_cast.
34 static bool classof(const sandboxir::Value *From) {
35 return From->getSubclassID() == ClassID::Function;
36 }
37
39 return Ctx.getModule(cast<llvm::Function>(Val)->getParent());
40 }
41
42 Argument *getArg(unsigned Idx) const {
43 llvm::Argument *Arg = cast<llvm::Function>(Val)->getArg(Idx);
44 return cast<Argument>(Ctx.getValue(Arg));
45 }
46
47 size_t arg_size() const { return cast<llvm::Function>(Val)->arg_size(); }
48 bool arg_empty() const { return cast<llvm::Function>(Val)->arg_empty(); }
49
51 iterator begin() const {
52 LLVMBBToBB BBGetter(Ctx);
53 return iterator(cast<llvm::Function>(Val)->begin(), BBGetter);
54 }
55 iterator end() const {
56 LLVMBBToBB BBGetter(Ctx);
57 return iterator(cast<llvm::Function>(Val)->end(), BBGetter);
58 }
60
61#ifndef NDEBUG
62 void verify() const final {
63 assert(isa<llvm::Function>(Val) && "Expected Function!");
64 }
65 void dumpNameAndArgs(raw_ostream &OS) const;
66 void dumpOS(raw_ostream &OS) const final;
67#endif
68};
69
70} // namespace llvm::sandboxir
71
72#endif // LLVM_SANDBOXIR_FUNCTION_H
aarch64 promote const
BlockVerifier::State From
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
#define F(x, y, z)
Definition: MD5.cpp:55
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
This class represents an incoming formal argument to a Function.
Definition: Argument.h:31
LLVM Basic Block Representation.
Definition: BasicBlock.h:61
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
Argument of a sandboxir::Function.
Definition: Argument.h:18
Contains a list of sandboxir::Instruction's.
Definition: BasicBlock.h:67
sandboxir::Value * getValue(llvm::Value *V) const
Definition: Context.cpp:601
Module * getModule(llvm::Module *LLVMM) const
Definition: Context.cpp:614
Argument * getArg(unsigned Idx) const
Definition: Function.h:42
FunctionType * getFunctionType() const
Definition: Function.cpp:15
iterator begin() const
Definition: Function.h:51
void dumpOS(raw_ostream &OS) const final
Definition: Function.cpp:37
void dumpNameAndArgs(raw_ostream &OS) const
Definition: Function.cpp:21
size_t arg_size() const
Definition: Function.h:47
bool arg_empty() const
Definition: Function.h:48
void verify() const final
Should crash if there is something wrong with the instruction.
Definition: Function.h:62
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition: Function.h:34
mapped_iterator< llvm::Function::iterator, LLVMBBToBB > iterator
Definition: Function.h:50
iterator end() const
Definition: Function.h:55
Provides API functions, like getIterator() and getReverseIterator() to GlobalIFunc,...
Definition: Constant.h:767
In SandboxIR the Module is mainly used to access the list of global objects.
Definition: Module.h:31
A SandboxIR Value has users. This is the base class.
Definition: Value.h:63
llvm::Value * Val
The LLVM Value that corresponds to this SandboxIR Value.
Definition: Value.h:103
Context & Ctx
All values point to the context.
Definition: Value.h:172