LLVM 22.0.0git
Function.cpp
Go to the documentation of this file.
1//===- Function.cpp - The Function class of Sandbox IR --------------------===//
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
10#include "llvm/IR/Value.h"
12
13namespace llvm::sandboxir {
14
16 return cast<FunctionType>(
17 Ctx.getType(cast<llvm::Function>(Val)->getFunctionType()));
18}
19
24 cast<llvm::Function>(Val)->setAlignment(Align);
25}
26
27#ifndef NDEBUG
29 auto *F = cast<llvm::Function>(Val);
30 OS << *F->getReturnType() << " @" << F->getName() << "(";
32 F->args(),
33 [this, &OS](const llvm::Argument &LLVMArg) {
34 auto *SBArg = cast_or_null<Argument>(Ctx.getValue(&LLVMArg));
35 if (SBArg == nullptr)
36 OS << "NULL";
37 else
38 SBArg->printAsOperand(OS);
39 },
40 [&] { OS << ", "; });
41 OS << ")";
42}
43
46 OS << " {\n";
47 auto *LLVMF = cast<llvm::Function>(Val);
49 *LLVMF,
50 [this, &OS](const llvm::BasicBlock &LLVMBB) {
51 auto *BB = cast_or_null<BasicBlock>(Ctx.getValue(&LLVMBB));
52 if (BB == nullptr)
53 OS << "NULL";
54 else
55 OS << *BB;
56 },
57 [&OS] { OS << "\n"; });
58 OS << "}\n";
60#endif // NDEBUG
61
62} // namespace llvm::sandboxir
#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
LLVM_ABI sandboxir::Value * getValue(llvm::Value *V) const
Definition: Context.cpp:629
Type * getType(llvm::Type *LLVMTy)
Definition: Context.h:262
Tracker & getTracker()
Definition: Context.h:245
LLVM_ABI FunctionType * getFunctionType() const
Definition: Function.cpp:15
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
This class can be used for tracking most instruction setters.
Definition: Tracker.h:277
bool emplaceIfTracking(ArgsT... Args)
A convenience wrapper for track() that constructs and tracks the Change object if tracking is enabled...
Definition: Tracker.h:500
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
void interleave(ForwardIterator begin, ForwardIterator end, UnaryFunctor each_fn, NullaryFunctor between_fn)
An STL-style algorithm similar to std::for_each that applies a second functor between every pair of e...
Definition: STLExtras.h:2212
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