[clang] Add test for CWG190 "Layout-compatible POD-struct types" (#121668)
[llvm-project.git] / llvm / lib / SandboxIR / Function.cpp
blobf7a1d35b00465df203ae444b7c3a53dc757d8b63
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 //===----------------------------------------------------------------------===//
9 #include "llvm/SandboxIR/Function.h"
10 #include "llvm/IR/Value.h"
11 #include "llvm/SandboxIR/Context.h"
13 namespace llvm::sandboxir {
15 FunctionType *Function::getFunctionType() const {
16 return cast<FunctionType>(
17 Ctx.getType(cast<llvm::Function>(Val)->getFunctionType()));
20 #ifndef NDEBUG
21 void Function::dumpNameAndArgs(raw_ostream &OS) const {
22 auto *F = cast<llvm::Function>(Val);
23 OS << *F->getReturnType() << " @" << F->getName() << "(";
24 interleave(
25 F->args(),
26 [this, &OS](const llvm::Argument &LLVMArg) {
27 auto *SBArg = cast_or_null<Argument>(Ctx.getValue(&LLVMArg));
28 if (SBArg == nullptr)
29 OS << "NULL";
30 else
31 SBArg->printAsOperand(OS);
33 [&] { OS << ", "; });
34 OS << ")";
37 void Function::dumpOS(raw_ostream &OS) const {
38 dumpNameAndArgs(OS);
39 OS << " {\n";
40 auto *LLVMF = cast<llvm::Function>(Val);
41 interleave(
42 *LLVMF,
43 [this, &OS](const llvm::BasicBlock &LLVMBB) {
44 auto *BB = cast_or_null<BasicBlock>(Ctx.getValue(&LLVMBB));
45 if (BB == nullptr)
46 OS << "NULL";
47 else
48 OS << *BB;
50 [&OS] { OS << "\n"; });
51 OS << "}\n";
53 #endif // NDEBUG
55 } // namespace llvm::sandboxir