1//===---- TargetInfo.h - Encapsulate target details -------------*- 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// These classes wrap the information about a call or function definition used
10// to handle ABI compliancy.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_LIB_CIR_TARGETINFO_H
15#define LLVM_CLANG_LIB_CIR_TARGETINFO_H
16
17#include "ABIInfo.h"
18#include "CIRGenTypes.h"
19
20#include <memory>
21#include <utility>
22
23namespace clang::CIRGen {
24
25class TargetCIRGenInfo {
26 std::unique_ptr<ABIInfo> info;
27
28public:
29 TargetCIRGenInfo(std::unique_ptr<ABIInfo> info) : info(std::move(info)) {}
30
31 virtual ~TargetCIRGenInfo() = default;
32
33 /// Returns ABI info helper for the target.
34 const ABIInfo &getABIInfo() const { return *info; }
35
36 /// Determine whether a call to an unprototyped functions under
37 /// the given calling convention should use the variadic
38 /// convention or the non-variadic convention.
39 ///
40 /// There's a good reason to make a platform's variadic calling
41 /// convention be different from its non-variadic calling
42 /// convention: the non-variadic arguments can be passed in
43 /// registers (better for performance), and the variadic arguments
44 /// can be passed on the stack (also better for performance). If
45 /// this is done, however, unprototyped functions *must* use the
46 /// non-variadic convention, because C99 states that a call
47 /// through an unprototyped function type must succeed if the
48 /// function was defined with a non-variadic prototype with
49 /// compatible parameters. Therefore, splitting the conventions
50 /// makes it impossible to call a variadic function through an
51 /// unprototyped type. Since function prototypes came out in the
52 /// late 1970s, this is probably an acceptable trade-off.
53 /// Nonetheless, not all platforms are willing to make it, and in
54 /// particularly x86-64 bends over backwards to make the
55 /// conventions compatible.
56 ///
57 /// The default is false. This is correct whenever:
58 /// - the conventions are exactly the same, because it does not
59 /// matter and the resulting IR will be somewhat prettier in
60 /// certain cases; or
61 /// - the conventions are substantively different in how they pass
62 /// arguments, because in this case using the variadic convention
63 /// will lead to C99 violations.
64 ///
65 /// However, some platforms make the conventions identical except
66 /// for passing additional out-of-band information to a variadic
67 /// function: for example, x86-64 passes the number of SSE
68 /// arguments in %al. On these platforms, it is desirable to
69 /// call unprototyped functions using the variadic convention so
70 /// that unprototyped calls to varargs functions still succeed.
71 ///
72 /// Relatedly, platforms which pass the fixed arguments to this:
73 /// A foo(B, C, D);
74 /// differently than they would pass them to this:
75 /// A foo(B, C, D, ...);
76 /// may need to adjust the debugger-support code in Sema to do the
77 /// right thing when calling a function with no know signature.
78 virtual bool isNoProtoCallVariadic(const FunctionNoProtoType *fnType) const;
79};
80
81std::unique_ptr<TargetCIRGenInfo> createX8664TargetCIRGenInfo(CIRGenTypes &cgt);
82
83} // namespace clang::CIRGen
84
85#endif // LLVM_CLANG_LIB_CIR_TARGETINFO_H
86

source code of clang/lib/CIR/CodeGen/TargetInfo.h