clang 23.0.0git
TargetInfo.h
Go to the documentation of this file.
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 "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
23
24#include <memory>
25#include <utility>
26
27namespace clang::CIRGen {
28
29/// isEmptyFieldForLayout - Return true if the field is "empty", that is,
30/// either a zero-width bit-field or an isEmptyRecordForLayout.
31bool isEmptyFieldForLayout(const ASTContext &context, const FieldDecl *fd);
32
33/// isEmptyRecordForLayout - Return true if a structure contains only empty
34/// base classes (per isEmptyRecordForLayout) and fields (per
35/// isEmptyFieldForLayout). Note, C++ record fields are considered empty
36/// if the [[no_unique_address]] attribute would have made them empty.
37bool isEmptyRecordForLayout(const ASTContext &context, QualType t);
38
39class CIRGenFunction;
40
42 std::unique_ptr<ABIInfo> info;
43
44public:
45 TargetCIRGenInfo(std::unique_ptr<ABIInfo> info) : info(std::move(info)) {}
46
47 virtual ~TargetCIRGenInfo() = default;
48
49 /// Returns ABI info helper for the target.
50 const ABIInfo &getABIInfo() const { return *info; }
51
52 /// Get the address space for alloca.
53 virtual mlir::ptr::MemorySpaceAttrInterface getCIRAllocaAddressSpace() const {
54 return cir::LangAddressSpaceAttr::get(&info->cgt.getMLIRContext(),
55 cir::LangAddressSpace::Default);
56 }
57
58 /// Determine whether a call to an unprototyped functions under
59 /// the given calling convention should use the variadic
60 /// convention or the non-variadic convention.
61 ///
62 /// There's a good reason to make a platform's variadic calling
63 /// convention be different from its non-variadic calling
64 /// convention: the non-variadic arguments can be passed in
65 /// registers (better for performance), and the variadic arguments
66 /// can be passed on the stack (also better for performance). If
67 /// this is done, however, unprototyped functions *must* use the
68 /// non-variadic convention, because C99 states that a call
69 /// through an unprototyped function type must succeed if the
70 /// function was defined with a non-variadic prototype with
71 /// compatible parameters. Therefore, splitting the conventions
72 /// makes it impossible to call a variadic function through an
73 /// unprototyped type. Since function prototypes came out in the
74 /// late 1970s, this is probably an acceptable trade-off.
75 /// Nonetheless, not all platforms are willing to make it, and in
76 /// particularly x86-64 bends over backwards to make the
77 /// conventions compatible.
78 ///
79 /// The default is false. This is correct whenever:
80 /// - the conventions are exactly the same, because it does not
81 /// matter and the resulting IR will be somewhat prettier in
82 /// certain cases; or
83 /// - the conventions are substantively different in how they pass
84 /// arguments, because in this case using the variadic convention
85 /// will lead to C99 violations.
86 ///
87 /// However, some platforms make the conventions identical except
88 /// for passing additional out-of-band information to a variadic
89 /// function: for example, x86-64 passes the number of SSE
90 /// arguments in %al. On these platforms, it is desirable to
91 /// call unprototyped functions using the variadic convention so
92 /// that unprototyped calls to varargs functions still succeed.
93 ///
94 /// Relatedly, platforms which pass the fixed arguments to this:
95 /// A foo(B, C, D);
96 /// differently than they would pass them to this:
97 /// A foo(B, C, D, ...);
98 /// may need to adjust the debugger-support code in Sema to do the
99 /// right thing when calling a function with no know signature.
100 virtual bool isNoProtoCallVariadic(const FunctionNoProtoType *fnType) const;
101
103 mlir::Type ty) const {
104 return false;
105 }
106
107 /// Corrects the MLIR type for a given constraint and "usual"
108 /// type.
109 ///
110 /// \returns A new MLIR type, possibly the same as the original
111 /// on success
112 virtual mlir::Type adjustInlineAsmType(CIRGenFunction &cgf,
113 llvm::StringRef constraint,
114 mlir::Type ty) const {
115 return ty;
116 }
117};
118
119std::unique_ptr<TargetCIRGenInfo> createX8664TargetCIRGenInfo(CIRGenTypes &cgt);
120
121std::unique_ptr<TargetCIRGenInfo> createNVPTXTargetCIRGenInfo(CIRGenTypes &cgt);
122
123} // namespace clang::CIRGen
124
125#endif // LLVM_CLANG_LIB_CIR_TARGETINFO_H
Provides definitions for the various language-specific address spaces.
virtual ~TargetCIRGenInfo()=default
virtual mlir::Type adjustInlineAsmType(CIRGenFunction &cgf, llvm::StringRef constraint, mlir::Type ty) const
Corrects the MLIR type for a given constraint and "usual" type.
Definition TargetInfo.h:112
const ABIInfo & getABIInfo() const
Returns ABI info helper for the target.
Definition TargetInfo.h:50
TargetCIRGenInfo(std::unique_ptr< ABIInfo > info)
Definition TargetInfo.h:45
virtual bool isScalarizableAsmOperand(CIRGenFunction &cgf, mlir::Type ty) const
Definition TargetInfo.h:102
virtual bool isNoProtoCallVariadic(const FunctionNoProtoType *fnType) const
Determine whether a call to an unprototyped functions under the given calling convention should use t...
virtual mlir::ptr::MemorySpaceAttrInterface getCIRAllocaAddressSpace() const
Get the address space for alloca.
Definition TargetInfo.h:53
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition TypeBase.h:4893
std::unique_ptr< TargetCIRGenInfo > createNVPTXTargetCIRGenInfo(CIRGenTypes &cgt)
std::unique_ptr< TargetCIRGenInfo > createX8664TargetCIRGenInfo(CIRGenTypes &cgt)
bool isEmptyFieldForLayout(const ASTContext &context, const FieldDecl *fd)
isEmptyFieldForLayout - Return true if the field is "empty", that is, either a zero-width bit-field o...
bool isEmptyRecordForLayout(const ASTContext &context, QualType t)
isEmptyRecordForLayout - Return true if a structure contains only empty base classes (per isEmptyReco...