| 1 | //===----- FunctionInfo.cpp - ABI Function Information ----------- C++ ----===// |
|---|---|
| 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 | |
| 9 | #include "llvm/ABI/FunctionInfo.h" |
| 10 | #include <optional> |
| 11 | |
| 12 | using namespace llvm; |
| 13 | using namespace llvm::abi; |
| 14 | |
| 15 | std::unique_ptr<FunctionInfo> |
| 16 | FunctionInfo::create(CallingConv::ID CC, const Type *ReturnType, |
| 17 | ArrayRef<const Type *> ArgTypes, |
| 18 | std::optional<unsigned> NumRequired) { |
| 19 | |
| 20 | assert(!NumRequired || *NumRequired <= ArgTypes.size()); |
| 21 | |
| 22 | void *Buffer = operator new(totalSizeToAlloc<ArgEntry>(Counts: ArgTypes.size())); |
| 23 | |
| 24 | // FunctionInfo overloads operator delete, so we can use std::unique_ptr |
| 25 | // without worrying about sized deallocation of trailing objects. |
| 26 | std::unique_ptr<FunctionInfo> FI( |
| 27 | new (Buffer) FunctionInfo(CC, ReturnType, ArgTypes.size(), NumRequired)); |
| 28 | |
| 29 | ArgEntry *Args = FI->getTrailingObjects(); |
| 30 | for (unsigned I = 0; I < ArgTypes.size(); ++I) |
| 31 | new (&Args[I]) ArgEntry(ArgTypes[I]); |
| 32 | |
| 33 | return FI; |
| 34 | } |
| 35 |