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"
24
25#include <memory>
26#include <utility>
27
28namespace clang::CIRGen {
29
30/// isEmptyFieldForLayout - Return true if the field is "empty", that is,
31/// either a zero-width bit-field or an isEmptyRecordForLayout.
32bool isEmptyFieldForLayout(const ASTContext &context, const FieldDecl *fd);
33
34/// isEmptyRecordForLayout - Return true if a structure contains only empty
35/// base classes (per isEmptyRecordForLayout) and fields (per
36/// isEmptyFieldForLayout). Note, C++ record fields are considered empty
37/// if the [[no_unique_address]] attribute would have made them empty.
38bool isEmptyRecordForLayout(const ASTContext &context, QualType t);
39
40class CIRGenFunction;
41
43 std::unique_ptr<ABIInfo> info;
44
45public:
46 TargetCIRGenInfo(std::unique_ptr<ABIInfo> info) : info(std::move(info)) {}
47
48 virtual ~TargetCIRGenInfo() = default;
49
50 /// Returns ABI info helper for the target.
51 const ABIInfo &getABIInfo() const { return *info; }
52
53 /// Get target favored AST address space of a global variable for languages
54 /// other than OpenCL and CUDA.
55 /// If \p d is nullptr, returns the default target favored address space
56 /// for global variable.
58 const clang::VarDecl *d) const;
59
60 /// Get the address space for alloca.
61 virtual mlir::ptr::MemorySpaceAttrInterface getCIRAllocaAddressSpace() const {
62 return cir::LangAddressSpaceAttr::get(&info->cgt.getMLIRContext(),
63 cir::LangAddressSpace::Default);
64 }
65
66 /// Determine whether a call to an unprototyped functions under
67 /// the given calling convention should use the variadic
68 /// convention or the non-variadic convention.
69 ///
70 /// There's a good reason to make a platform's variadic calling
71 /// convention be different from its non-variadic calling
72 /// convention: the non-variadic arguments can be passed in
73 /// registers (better for performance), and the variadic arguments
74 /// can be passed on the stack (also better for performance). If
75 /// this is done, however, unprototyped functions *must* use the
76 /// non-variadic convention, because C99 states that a call
77 /// through an unprototyped function type must succeed if the
78 /// function was defined with a non-variadic prototype with
79 /// compatible parameters. Therefore, splitting the conventions
80 /// makes it impossible to call a variadic function through an
81 /// unprototyped type. Since function prototypes came out in the
82 /// late 1970s, this is probably an acceptable trade-off.
83 /// Nonetheless, not all platforms are willing to make it, and in
84 /// particularly x86-64 bends over backwards to make the
85 /// conventions compatible.
86 ///
87 /// The default is false. This is correct whenever:
88 /// - the conventions are exactly the same, because it does not
89 /// matter and the resulting IR will be somewhat prettier in
90 /// certain cases; or
91 /// - the conventions are substantively different in how they pass
92 /// arguments, because in this case using the variadic convention
93 /// will lead to C99 violations.
94 ///
95 /// However, some platforms make the conventions identical except
96 /// for passing additional out-of-band information to a variadic
97 /// function: for example, x86-64 passes the number of SSE
98 /// arguments in %al. On these platforms, it is desirable to
99 /// call unprototyped functions using the variadic convention so
100 /// that unprototyped calls to varargs functions still succeed.
101 ///
102 /// Relatedly, platforms which pass the fixed arguments to this:
103 /// A foo(B, C, D);
104 /// differently than they would pass them to this:
105 /// A foo(B, C, D, ...);
106 /// may need to adjust the debugger-support code in Sema to do the
107 /// right thing when calling a function with no know signature.
108 virtual bool isNoProtoCallVariadic(const FunctionNoProtoType *fnType) const;
109
110 /// Provides a convenient hook to handle extra target-specific attributes
111 /// for the given global.
112 /// In OG, the function receives an llvm::GlobalValue. However, functions
113 /// and global variables are separate types in Clang IR, so we use a general
114 /// mlir::Operation*.
116 mlir::Operation *global,
117 CIRGenModule &module) const {}
118
120 mlir::Type ty) const {
121 return false;
122 }
123
124 /// Corrects the MLIR type for a given constraint and "usual"
125 /// type.
126 ///
127 /// \returns A new MLIR type, possibly the same as the original
128 /// on success
129 virtual mlir::Type adjustInlineAsmType(CIRGenFunction &cgf,
130 llvm::StringRef constraint,
131 mlir::Type ty) const {
132 return ty;
133 }
134};
135
136std::unique_ptr<TargetCIRGenInfo>
137createAMDGPUTargetCIRGenInfo(CIRGenTypes &cgt);
138
139/// Check if AMDGPU protected visibility is required.
141 cir::VisibilityKind visibility);
142
143/// Set AMDGPU-specific function attributes for HIP kernels.
145 cir::FuncOp func, CIRGenModule &cgm);
146
147std::unique_ptr<TargetCIRGenInfo> createX8664TargetCIRGenInfo(CIRGenTypes &cgt);
148
149std::unique_ptr<TargetCIRGenInfo> createNVPTXTargetCIRGenInfo(CIRGenTypes &cgt);
150
151} // namespace clang::CIRGen
152
153#endif // LLVM_CLANG_LIB_CIR_TARGETINFO_H
Provides definitions for the various language-specific address spaces.
This class organizes the cross-function state that is used while generating CIR code.
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:129
const ABIInfo & getABIInfo() const
Returns ABI info helper for the target.
Definition TargetInfo.h:51
TargetCIRGenInfo(std::unique_ptr< ABIInfo > info)
Definition TargetInfo.h:46
virtual clang::LangAS getGlobalVarAddressSpace(CIRGenModule &cgm, const clang::VarDecl *d) const
Get target favored AST address space of a global variable for languages other than OpenCL and CUDA.
virtual bool isScalarizableAsmOperand(CIRGenFunction &cgf, mlir::Type ty) const
Definition TargetInfo.h:119
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:61
virtual void setTargetAttributes(const clang::Decl *decl, mlir::Operation *global, CIRGenModule &module) const
Provides a convenient hook to handle extra target-specific attributes for the given global.
Definition TargetInfo.h:115
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition TypeBase.h:4935
Represents a variable declaration or definition.
Definition Decl.h:926
void setAMDGPUTargetFunctionAttributes(const clang::Decl *decl, cir::FuncOp func, CIRGenModule &cgm)
Set AMDGPU-specific function attributes for HIP kernels.
Definition AMDGPU.cpp:228
std::unique_ptr< TargetCIRGenInfo > createAMDGPUTargetCIRGenInfo(CIRGenTypes &cgt)
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...
bool requiresAMDGPUProtectedVisibility(const clang::Decl *d, cir::VisibilityKind visibility)
Check if AMDGPU protected visibility is required.
Definition AMDGPU.cpp:26
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
LangAS
Defines the address space values used by the address space qualifier of QualType.