LLVM 24.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
21 Ctx.getTracker()
22 .emplaceIfTracking<
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
45 hash_code Hash(0);
46 for (auto &BB : *this)
47 Hash = hash_combine(Hash, BB.hash());
48 return Hash;
49}
50
53 OS << " {\n";
54 auto *LLVMF = cast<llvm::Function>(Val);
56 *LLVMF,
57 [this, &OS](const llvm::BasicBlock &LLVMBB) {
58 auto *BB = cast_or_null<BasicBlock>(Ctx.getValue(&LLVMBB));
59 if (BB == nullptr)
60 OS << "NULL";
61 else
62 OS << *BB;
63 },
64 [&OS] { OS << "\n"; });
65 OS << "}\n";
66}
67#endif // NDEBUG
68
69} // namespace llvm::sandboxir
#define F(x, y, z)
Definition MD5.cpp:54
This class represents an incoming formal argument to a Function.
Definition Argument.h:32
LLVM Basic Block Representation.
Definition BasicBlock.h:62
An opaque object representing a hash code.
Definition Hashing.h:77
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
hash_code hash() const final
Definition Function.cpp:44
LLVM_ABI FunctionType * getFunctionType() const
Definition Function.cpp:15
LLVM_ABI void dumpOS(raw_ostream &OS) const final
Definition Function.cpp:51
LLVM_ABI void setAlignment(MaybeAlign Align)
Sets the alignment attribute of the Function.
Definition Function.cpp:20
LLVM_ABI void dumpNameAndArgs(raw_ostream &OS) const
Definition Function.cpp:28
This class can be used for tracking most instruction setters.
Definition Tracker.h:285
llvm::Value * Val
The LLVM Value that corresponds to this SandboxIR Value.
Definition Value.h:122
Context & Ctx
All values point to the context.
Definition Value.h:201
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:2296
auto cast_or_null(const Y &Val)
Definition Casting.h:714
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition Hashing.h:307
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:111