clang 23.0.0git
TargetInfo.cpp
Go to the documentation of this file.
1#include "TargetInfo.h"
2#include "ABIInfo.h"
3#include "CIRGenFunction.h"
4#include "CIRGenModule.h"
5#include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
8
9using namespace clang;
10using namespace clang::CIRGen;
11
13 QualType t) {
14 const auto *rd = t->getAsRecordDecl();
15 if (!rd)
16 return false;
17
18 // If this is a C++ record, check the bases first.
19 if (const CXXRecordDecl *cxxrd = dyn_cast<CXXRecordDecl>(rd)) {
20 if (cxxrd->isDynamicClass())
21 return false;
22
23 for (const auto &i : cxxrd->bases())
24 if (!isEmptyRecordForLayout(context, i.getType()))
25 return false;
26 }
27
28 for (const auto *i : rd->fields())
29 if (!isEmptyFieldForLayout(context, i))
30 return false;
31
32 return true;
33}
34
36 const FieldDecl *fd) {
37 if (fd->isZeroLengthBitField())
38 return true;
39
40 if (fd->isUnnamedBitField())
41 return false;
42
43 return isEmptyRecordForLayout(context, fd->getType());
44}
45
46namespace {
47
48class AMDGPUABIInfo : public ABIInfo {
49public:
50 AMDGPUABIInfo(CIRGenTypes &cgt) : ABIInfo(cgt) {}
51};
52
53class AMDGPUTargetCIRGenInfo : public TargetCIRGenInfo {
54public:
55 AMDGPUTargetCIRGenInfo(CIRGenTypes &cgt)
56 : TargetCIRGenInfo(std::make_unique<AMDGPUABIInfo>(cgt)) {}
57
58 void setTargetAttributes(const clang::Decl *decl, mlir::Operation *global,
59 CIRGenModule &cgm) const override {
60 if (auto func = mlir::dyn_cast<cir::FuncOp>(global)) {
61 if (requiresAMDGPUProtectedVisibility(decl, func.getGlobalVisibility())) {
62 func.setGlobalVisibility(cir::VisibilityKind::Protected);
63 func.setDSOLocal(true);
64 }
66 } else if (auto gv = mlir::dyn_cast<cir::GlobalOp>(global)) {
67 if (requiresAMDGPUProtectedVisibility(decl, gv.getGlobalVisibility())) {
68 gv.setGlobalVisibility(cir::VisibilityKind::Protected);
69 gv.setDSOLocal(true);
70 }
71 }
72 }
73};
74
75} // namespace
76
77namespace {
78
79class X8664ABIInfo : public ABIInfo {
80public:
81 X8664ABIInfo(CIRGenTypes &cgt) : ABIInfo(cgt) {}
82};
83
84class X8664TargetCIRGenInfo : public TargetCIRGenInfo {
85public:
86 X8664TargetCIRGenInfo(CIRGenTypes &cgt)
87 : TargetCIRGenInfo(std::make_unique<X8664ABIInfo>(cgt)) {}
88};
89
90} // namespace
91
92namespace {
93
94class NVPTXABIInfo : public ABIInfo {
95public:
96 NVPTXABIInfo(CIRGenTypes &cgt) : ABIInfo(cgt) {}
97};
98
99class NVPTXTargetCIRGenInfo : public TargetCIRGenInfo {
100public:
101 NVPTXTargetCIRGenInfo(CIRGenTypes &cgt)
102 : TargetCIRGenInfo(std::make_unique<NVPTXABIInfo>(cgt)) {}
103};
104} // namespace
105
106std::unique_ptr<TargetCIRGenInfo>
108 return std::make_unique<AMDGPUTargetCIRGenInfo>(cgt);
109}
110
111std::unique_ptr<TargetCIRGenInfo>
113 return std::make_unique<NVPTXTargetCIRGenInfo>(cgt);
114}
115
116std::unique_ptr<TargetCIRGenInfo>
118 return std::make_unique<X8664TargetCIRGenInfo>(cgt);
119}
120
121ABIInfo::~ABIInfo() noexcept = default;
122
124 const FunctionNoProtoType *fnType) const {
125 // The following conventions are known to require this to be false:
126 // x86_stdcall
127 // MIPS
128 // For everything else, we just prefer false unless we opt out.
129 return false;
130}
131
134 const clang::VarDecl *d) const {
135 assert(!cgm.getLangOpts().OpenCL &&
136 !(cgm.getLangOpts().CUDA && cgm.getLangOpts().CUDAIsDevice) &&
137 "Address space agnostic languages only");
138 return d ? d->getType().getAddressSpace() : LangAS::Default;
139}
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:226
This class organizes the cross-function state that is used while generating CIR code.
const clang::LangOptions & getLangOpts() const
This class organizes the cross-module state that is used while lowering AST types to CIR types.
Definition CIRGenTypes.h:48
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 isNoProtoCallVariadic(const FunctionNoProtoType *fnType) const
Determine whether a call to an unprototyped functions under the given calling convention should use t...
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
Represents a member of a struct/union/class.
Definition Decl.h:3175
bool isUnnamedBitField() const
Determines whether this is an unnamed bitfield.
Definition Decl.h:3281
bool isZeroLengthBitField() const
Is this a zero-length bit-field?
Definition Decl.cpp:4762
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition TypeBase.h:4935
A (possibly-)qualified type.
Definition TypeBase.h:937
LangAS getAddressSpace() const
Return the address space of this type.
Definition TypeBase.h:8557
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition Type.h:41
QualType getType() const
Definition Decl.h:723
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.
The JSON file list parser is used to communicate input to InstallAPI.
LangAS
Defines the address space values used by the address space qualifier of QualType.