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 /// Returns true if the target supports math library calls.
54 virtual bool supportsLibCall() const { return true; }
55
56 /// Get target favored AST address space of a global variable for languages
57 /// other than OpenCL and CUDA.
58 /// If \p d is nullptr, returns the default target favored address space
59 /// for global variable.
61 const clang::VarDecl *d) const;
62
63 /// Get the address space for alloca.
64 virtual mlir::ptr::MemorySpaceAttrInterface getCIRAllocaAddressSpace() const {
65 return cir::LangAddressSpaceAttr::get(&info->cgt.getMLIRContext(),
66 cir::LangAddressSpace::Default);
67 }
68
69 virtual mlir::Type getCUDADeviceBuiltinSurfaceDeviceType() const {
70 return nullptr;
71 }
72
73 /// Determine whether a call to an unprototyped functions under
74 /// the given calling convention should use the variadic
75 /// convention or the non-variadic convention.
76 ///
77 /// There's a good reason to make a platform's variadic calling
78 /// convention be different from its non-variadic calling
79 /// convention: the non-variadic arguments can be passed in
80 /// registers (better for performance), and the variadic arguments
81 /// can be passed on the stack (also better for performance). If
82 /// this is done, however, unprototyped functions *must* use the
83 /// non-variadic convention, because C99 states that a call
84 /// through an unprototyped function type must succeed if the
85 /// function was defined with a non-variadic prototype with
86 /// compatible parameters. Therefore, splitting the conventions
87 /// makes it impossible to call a variadic function through an
88 /// unprototyped type. Since function prototypes came out in the
89 /// late 1970s, this is probably an acceptable trade-off.
90 /// Nonetheless, not all platforms are willing to make it, and in
91 /// particularly x86-64 bends over backwards to make the
92 /// conventions compatible.
93 ///
94 /// The default is false. This is correct whenever:
95 /// - the conventions are exactly the same, because it does not
96 /// matter and the resulting IR will be somewhat prettier in
97 /// certain cases; or
98 /// - the conventions are substantively different in how they pass
99 /// arguments, because in this case using the variadic convention
100 /// will lead to C99 violations.
101 ///
102 /// However, some platforms make the conventions identical except
103 /// for passing additional out-of-band information to a variadic
104 /// function: for example, x86-64 passes the number of SSE
105 /// arguments in %al. On these platforms, it is desirable to
106 /// call unprototyped functions using the variadic convention so
107 /// that unprototyped calls to varargs functions still succeed.
108 ///
109 /// Relatedly, platforms which pass the fixed arguments to this:
110 /// A foo(B, C, D);
111 /// differently than they would pass them to this:
112 /// A foo(B, C, D, ...);
113 /// may need to adjust the debugger-support code in Sema to do the
114 /// right thing when calling a function with no know signature.
115 virtual bool isNoProtoCallVariadic(const FunctionNoProtoType *fnType) const;
116
117 /// Provides a convenient hook to handle extra target-specific attributes
118 /// for the given global.
119 /// In OG, the function receives an llvm::GlobalValue. However, functions
120 /// and global variables are separate types in Clang IR, so we use a general
121 /// mlir::Operation*.
123 mlir::Operation *global,
124 CIRGenModule &module) const {}
125
127 mlir::Type ty) const {
128 return false;
129 }
130
131 /// Corrects the MLIR type for a given constraint and "usual"
132 /// type.
133 ///
134 /// \returns A new MLIR type, possibly the same as the original
135 /// on success
136 virtual mlir::Type adjustInlineAsmType(CIRGenFunction &cgf,
137 llvm::StringRef constraint,
138 mlir::Type ty) const {
139 return ty;
140 }
141};
142
143std::unique_ptr<TargetCIRGenInfo>
144createAMDGPUTargetCIRGenInfo(CIRGenTypes &cgt);
145
146/// Check if AMDGPU protected visibility is required.
148 cir::VisibilityKind visibility);
149
150/// Set AMDGPU-specific function attributes for HIP kernels.
152 cir::FuncOp func, CIRGenModule &cgm);
153
154std::unique_ptr<TargetCIRGenInfo> createX8664TargetCIRGenInfo(CIRGenTypes &cgt);
155
156std::unique_ptr<TargetCIRGenInfo> createNVPTXTargetCIRGenInfo(CIRGenTypes &cgt);
157
158std::unique_ptr<TargetCIRGenInfo> createSPIRVTargetCIRGenInfo(CIRGenTypes &cgt);
159
160} // namespace clang::CIRGen
161
162#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:136
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 bool supportsLibCall() const
Returns true if the target supports math library calls.
Definition TargetInfo.h:54
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:126
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::Type getCUDADeviceBuiltinSurfaceDeviceType() const
Definition TargetInfo.h:69
virtual mlir::ptr::MemorySpaceAttrInterface getCIRAllocaAddressSpace() const
Get the address space for alloca.
Definition TargetInfo.h:64
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:122
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:4949
Represents a variable declaration or definition.
Definition Decl.h:932
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)
Definition NVPTX.cpp:85
std::unique_ptr< TargetCIRGenInfo > createX8664TargetCIRGenInfo(CIRGenTypes &cgt)
std::unique_ptr< TargetCIRGenInfo > createSPIRVTargetCIRGenInfo(CIRGenTypes &cgt)
Definition SPIRV.cpp:56
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.