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
11using namespace llvm;
12using namespace llvm::abi;
13
14std::unique_ptr<FunctionInfo>
15FunctionInfo::create(CallingConv::ID CC, const Type *ReturnType,
16 ArrayRef<const Type *> ArgTypes, RequiredArgs Required) {
17
18 assert((!Required.allowsOptionalArgs() ||
19 Required.getNumRequiredArgs() <= ArgTypes.size()) &&
20 "declared parameters cannot outnumber the arguments");
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(), Required));
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