LLVM 22.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"
15
16namespace llvm::sandboxir {
17
18class Function : public GlobalWithNodeAPI<Function, llvm::Function,
19 GlobalObject, llvm::GlobalObject> {
20 /// Helper for mapped_iterator.
21 struct LLVMBBToBB {
22 Context &Ctx;
23 LLVMBBToBB(Context &Ctx) : Ctx(Ctx) {}
24 BasicBlock &operator()(llvm::BasicBlock &LLVMBB) const {
25 return *cast<BasicBlock>(Ctx.getValue(&LLVMBB));
26 }
27 };
28 /// Use Context::createFunction() instead.
30 : GlobalWithNodeAPI(ClassID::Function, F, Ctx) {}
31 friend class Context; // For constructor.
32
33public:
34 /// For isa/dyn_cast.
35 static bool classof(const sandboxir::Value *From) {
36 return From->getSubclassID() == ClassID::Function;
37 }
38
40 return Ctx.getModule(cast<llvm::Function>(Val)->getParent());
41 }
42
43 Argument *getArg(unsigned Idx) const {
44 llvm::Argument *Arg = cast<llvm::Function>(Val)->getArg(Idx);
45 return cast<Argument>(Ctx.getValue(Arg));
46 }
47
48 size_t arg_size() const { return cast<llvm::Function>(Val)->arg_size(); }
49 bool arg_empty() const { return cast<llvm::Function>(Val)->arg_empty(); }
50
52 iterator begin() const {
53 LLVMBBToBB BBGetter(Ctx);
54 return iterator(cast<llvm::Function>(Val)->begin(), BBGetter);
55 }
56 iterator end() const {
57 LLVMBBToBB BBGetter(Ctx);
58 return iterator(cast<llvm::Function>(Val)->end(), BBGetter);
59 }
61
62 /// Returns the alignment of the given function.
63 MaybeAlign getAlign() const { return cast<llvm::Function>(Val)->getAlign(); }
64
65 // TODO: Add missing: setAligment(Align)
66
67 /// Sets the alignment attribute of the Function.
68 /// This method will be deprecated as the alignment property should always be
69 /// defined.
71
72#ifndef NDEBUG
73 void verify() const final {
74 assert(isa<llvm::Function>(Val) && "Expected Function!");
75 }
76 void dumpNameAndArgs(raw_ostream &OS) const;
77 void dumpOS(raw_ostream &OS) const final;
78#endif
79};
80
81} // namespace llvm::sandboxir
82
83#endif // LLVM_SANDBOXIR_FUNCTION_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
BlockVerifier::State From
#define LLVM_ABI
Definition: Compiler.h:213
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
raw_pwrite_stream & OS
This class represents an incoming formal argument to a Function.
Definition: Argument.h:32
LLVM Basic Block Representation.
Definition: BasicBlock.h:62
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
Argument of a sandboxir::Function.
Definition: Argument.h:18
Contains a list of sandboxir::Instruction's.
Definition: BasicBlock.h:68
LLVM_ABI sandboxir::Value * getValue(llvm::Value *V) const
Definition: Context.cpp:629
LLVM_ABI Module * getModule(llvm::Module *LLVMM) const
Definition: Context.cpp:648
Argument * getArg(unsigned Idx) const
Definition: Function.h:43
LLVM_ABI FunctionType * getFunctionType() const
Definition: Function.cpp:15
iterator begin() const
Definition: Function.h:52
void dumpOS(raw_ostream &OS) const final
Definition: Function.cpp:44
LLVM_ABI void setAlignment(MaybeAlign Align)
Sets the alignment attribute of the Function.
Definition: Function.cpp:20
void dumpNameAndArgs(raw_ostream &OS) const
Definition: Function.cpp:28
size_t arg_size() const
Definition: Function.h:48
MaybeAlign getAlign() const
Returns the alignment of the given function.
Definition: Function.h:63
bool arg_empty() const
Definition: Function.h:49
void verify() const final
Should crash if there is something wrong with the instruction.
Definition: Function.h:73
static bool classof(const sandboxir::Value *From)
For isa/dyn_cast.
Definition: Function.h:35
mapped_iterator< llvm::Function::iterator, LLVMBBToBB > iterator
Definition: Function.h:51
iterator end() const
Definition: Function.h:56
Provides API functions, like getIterator() and getReverseIterator() to GlobalIFunc,...
Definition: Constant.h:1031
In SandboxIR the Module is mainly used to access the list of global objects.
Definition: Module.h:32
A SandboxIR Value has users. This is the base class.
Definition: Value.h:66
llvm::Value * Val
The LLVM Value that corresponds to this SandboxIR Value.
Definition: Value.h:106
Context & Ctx
All values point to the context.
Definition: Value.h:179
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117