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 "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
7
8using namespace clang;
9using namespace clang::CIRGen;
10
12 QualType t) {
13 const auto *rd = t->getAsRecordDecl();
14 if (!rd)
15 return false;
16
17 // If this is a C++ record, check the bases first.
18 if (const CXXRecordDecl *cxxrd = dyn_cast<CXXRecordDecl>(rd)) {
19 if (cxxrd->isDynamicClass())
20 return false;
21
22 for (const auto &i : cxxrd->bases())
23 if (!isEmptyRecordForLayout(context, i.getType()))
24 return false;
25 }
26
27 for (const auto *i : rd->fields())
28 if (!isEmptyFieldForLayout(context, i))
29 return false;
30
31 return true;
32}
33
35 const FieldDecl *fd) {
36 if (fd->isZeroLengthBitField())
37 return true;
38
39 if (fd->isUnnamedBitField())
40 return false;
41
42 return isEmptyRecordForLayout(context, fd->getType());
43}
44
45namespace {
46
47class X8664ABIInfo : public ABIInfo {
48public:
49 X8664ABIInfo(CIRGenTypes &cgt) : ABIInfo(cgt) {}
50};
51
52class X8664TargetCIRGenInfo : public TargetCIRGenInfo {
53public:
54 X8664TargetCIRGenInfo(CIRGenTypes &cgt)
55 : TargetCIRGenInfo(std::make_unique<X8664ABIInfo>(cgt)) {}
56};
57
58} // namespace
59
60namespace {
61
62class NVPTXABIInfo : public ABIInfo {
63public:
64 NVPTXABIInfo(CIRGenTypes &cgt) : ABIInfo(cgt) {}
65};
66
67class NVPTXTargetCIRGenInfo : public TargetCIRGenInfo {
68public:
69 NVPTXTargetCIRGenInfo(CIRGenTypes &cgt)
70 : TargetCIRGenInfo(std::make_unique<NVPTXABIInfo>(cgt)) {}
71};
72} // namespace
73
74std::unique_ptr<TargetCIRGenInfo>
76 return std::make_unique<NVPTXTargetCIRGenInfo>(cgt);
77}
78
79std::unique_ptr<TargetCIRGenInfo>
81 return std::make_unique<X8664TargetCIRGenInfo>(cgt);
82}
83
84ABIInfo::~ABIInfo() noexcept = default;
85
87 const FunctionNoProtoType *fnType) const {
88 // The following conventions are known to require this to be false:
89 // x86_stdcall
90 // MIPS
91 // For everything else, we just prefer false unless we opt out.
92 return false;
93}
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-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:45
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:3160
bool isUnnamedBitField() const
Determines whether this is an unnamed bitfield.
Definition Decl.h:3266
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:4893
A (possibly-)qualified type.
Definition TypeBase.h:937
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition Type.h:41
QualType getType() const
Definition Decl.h:723
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...
The JSON file list parser is used to communicate input to InstallAPI.