Path: blob/main/contrib/llvm-project/llvm/lib/SandboxIR/Function.cpp
213765 views
//===- Function.cpp - The Function class of Sandbox IR --------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/SandboxIR/Function.h"9#include "llvm/IR/Value.h"10#include "llvm/SandboxIR/Context.h"1112namespace llvm::sandboxir {1314FunctionType *Function::getFunctionType() const {15return cast<FunctionType>(16Ctx.getType(cast<llvm::Function>(Val)->getFunctionType()));17}1819void Function::setAlignment(MaybeAlign Align) {20Ctx.getTracker()21.emplaceIfTracking<22GenericSetter<&Function::getAlign, &Function::setAlignment>>(this);23cast<llvm::Function>(Val)->setAlignment(Align);24}2526#ifndef NDEBUG27void Function::dumpNameAndArgs(raw_ostream &OS) const {28auto *F = cast<llvm::Function>(Val);29OS << *F->getReturnType() << " @" << F->getName() << "(";30interleave(31F->args(),32[this, &OS](const llvm::Argument &LLVMArg) {33auto *SBArg = cast_or_null<Argument>(Ctx.getValue(&LLVMArg));34if (SBArg == nullptr)35OS << "NULL";36else37SBArg->printAsOperand(OS);38},39[&] { OS << ", "; });40OS << ")";41}4243void Function::dumpOS(raw_ostream &OS) const {44dumpNameAndArgs(OS);45OS << " {\n";46auto *LLVMF = cast<llvm::Function>(Val);47interleave(48*LLVMF,49[this, &OS](const llvm::BasicBlock &LLVMBB) {50auto *BB = cast_or_null<BasicBlock>(Ctx.getValue(&LLVMBB));51if (BB == nullptr)52OS << "NULL";53else54OS << *BB;55},56[&OS] { OS << "\n"; });57OS << "}\n";58}59#endif // NDEBUG6061} // namespace llvm::sandboxir626364