| 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 |
#include "clang/Basic/AddressSpaces.h" |
| 20 |
#include "clang/CIR/Dialect/IR/CIRAttrs.h" |
| 21 |
|
| 22 |
#include <memory> |
| 23 |
#include <utility> |
| 24 |
|
| 25 |
namespace clang::CIRGen { |
| 26 |
|
| 27 |
/// isEmptyFieldForLayout - Return true if the field is "empty", that is, |
| 28 |
/// either a zero-width bit-field or an isEmptyRecordForLayout. |
| 29 |
bool isEmptyFieldForLayout(const ASTContext &context, const FieldDecl *fd); |
| 30 |
|
| 31 |
/// isEmptyRecordForLayout - Return true if a structure contains only empty |
| 32 |
/// base classes (per isEmptyRecordForLayout) and fields (per |
| 33 |
/// isEmptyFieldForLayout). Note, C++ record fields are considered empty |
| 34 |
/// if the [[no_unique_address]] attribute would have made them empty. |
| 35 |
bool isEmptyRecordForLayout(const ASTContext &context, QualType t); |
| 36 |
|
| 37 |
class CIRGenFunction; |
| 38 |
|
| 39 |
class TargetCIRGenInfo { |
| 40 |
std::unique_ptr<ABIInfo> info; |
| 41 |
|
| 42 |
public: |
| 43 |
TargetCIRGenInfo(std::unique_ptr<ABIInfo> info) : info(std::move(info)) {} |
| 44 |
|
| 45 |
virtual ~TargetCIRGenInfo() = default; |
| 46 |
|
| 47 |
/// Returns ABI info helper for the target. |
| 48 |
const ABIInfo &getABIInfo() const { return *info; } |
| 49 |
|
| 50 |
/// Get the address space for alloca. |
| 51 |
virtual cir::TargetAddressSpaceAttr getCIRAllocaAddressSpace() const { |
| 52 |
return {}; |
| 53 |
} |
| 54 |
/// Perform address space cast of an expression of pointer type. |
| 55 |
/// \param V is the value to be casted to another address space. |
| 56 |
/// \param DestTy is the destination pointer type. |
| 57 |
/// \param srcAS is theaddress space of \p V. |
| 58 |
/// \param IsNonNull is the flag indicating \p V is known to be non null. |
| 59 |
virtual mlir::Value performAddrSpaceCast(CIRGenFunction &cgf, mlir::Value v, |
| 60 |
cir::TargetAddressSpaceAttr srcAddr, |
| 61 |
mlir::Type destTy, |
| 62 |
bool isNonNull = false) const; |
| 63 |
|
| 64 |
/// Determine whether a call to an unprototyped functions under |
| 65 |
/// the given calling convention should use the variadic |
| 66 |
/// convention or the non-variadic convention. |
| 67 |
/// |
| 68 |
/// There's a good reason to make a platform's variadic calling |
| 69 |
/// convention be different from its non-variadic calling |
| 70 |
/// convention: the non-variadic arguments can be passed in |
| 71 |
/// registers (better for performance), and the variadic arguments |
| 72 |
/// can be passed on the stack (also better for performance). If |
| 73 |
/// this is done, however, unprototyped functions *must* use the |
| 74 |
/// non-variadic convention, because C99 states that a call |
| 75 |
/// through an unprototyped function type must succeed if the |
| 76 |
/// function was defined with a non-variadic prototype with |
| 77 |
/// compatible parameters. Therefore, splitting the conventions |
| 78 |
/// makes it impossible to call a variadic function through an |
| 79 |
/// unprototyped type. Since function prototypes came out in the |
| 80 |
/// late 1970s, this is probably an acceptable trade-off. |
| 81 |
/// Nonetheless, not all platforms are willing to make it, and in |
| 82 |
/// particularly x86-64 bends over backwards to make the |
| 83 |
/// conventions compatible. |
| 84 |
/// |
| 85 |
/// The default is false. This is correct whenever: |
| 86 |
/// - the conventions are exactly the same, because it does not |
| 87 |
/// matter and the resulting IR will be somewhat prettier in |
| 88 |
/// certain cases; or |
| 89 |
/// - the conventions are substantively different in how they pass |
| 90 |
/// arguments, because in this case using the variadic convention |
| 91 |
/// will lead to C99 violations. |
| 92 |
/// |
| 93 |
/// However, some platforms make the conventions identical except |
| 94 |
/// for passing additional out-of-band information to a variadic |
| 95 |
/// function: for example, x86-64 passes the number of SSE |
| 96 |
/// arguments in %al. On these platforms, it is desirable to |
| 97 |
/// call unprototyped functions using the variadic convention so |
| 98 |
/// that unprototyped calls to varargs functions still succeed. |
| 99 |
/// |
| 100 |
/// Relatedly, platforms which pass the fixed arguments to this: |
| 101 |
/// A foo(B, C, D); |
| 102 |
/// differently than they would pass them to this: |
| 103 |
/// A foo(B, C, D, ...); |
| 104 |
/// may need to adjust the debugger-support code in Sema to do the |
| 105 |
/// right thing when calling a function with no know signature. |
| 106 |
virtual bool isNoProtoCallVariadic(const FunctionNoProtoType *fnType) const; |
| 107 |
}; |
| 108 |
|
| 109 |
std::unique_ptr<TargetCIRGenInfo> createX8664TargetCIRGenInfo(CIRGenTypes &cgt); |
| 110 |
|
| 111 |
} // namespace clang::CIRGen |
| 112 |
|
| 113 |
#endif // LLVM_CLANG_LIB_CIR_TARGETINFO_H |