brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · f400389 Raw
63 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "llvm/SandboxIR/Function.h"10#include "llvm/IR/Value.h"11#include "llvm/SandboxIR/Context.h"12 13namespace llvm::sandboxir {14 15FunctionType *Function::getFunctionType() const {16  return cast<FunctionType>(17      Ctx.getType(cast<llvm::Function>(Val)->getFunctionType()));18}19 20void Function::setAlignment(MaybeAlign Align) {21  Ctx.getTracker()22      .emplaceIfTracking<23          GenericSetter<&Function::getAlign, &Function::setAlignment>>(this);24  cast<llvm::Function>(Val)->setAlignment(Align);25}26 27#ifndef NDEBUG28void Function::dumpNameAndArgs(raw_ostream &OS) const {29  auto *F = cast<llvm::Function>(Val);30  OS << *F->getReturnType() << " @" << F->getName() << "(";31  interleave(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        else38          SBArg->printAsOperand(OS);39      },40      [&] { OS << ", "; });41  OS << ")";42}43 44void Function::dumpOS(raw_ostream &OS) const {45  dumpNameAndArgs(OS);46  OS << " {\n";47  auto *LLVMF = cast<llvm::Function>(Val);48  interleave(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        else55          OS << *BB;56      },57      [&OS] { OS << "\n"; });58  OS << "}\n";59}60#endif // NDEBUG61 62} // namespace llvm::sandboxir63