clang 22.0.0git
TargetInfo.cpp
Go to the documentation of this file.
1#include "TargetInfo.h"
2#include "ABIInfo.h"
3#include "CIRGenFunction.h"
6
7using namespace clang;
8using namespace clang::CIRGen;
9
11 QualType t) {
12 const auto *rd = t->getAsRecordDecl();
13 if (!rd)
14 return false;
15
16 // If this is a C++ record, check the bases first.
17 if (const CXXRecordDecl *cxxrd = dyn_cast<CXXRecordDecl>(rd)) {
18 if (cxxrd->isDynamicClass())
19 return false;
20
21 for (const auto &i : cxxrd->bases())
22 if (!isEmptyRecordForLayout(context, i.getType()))
23 return false;
24 }
25
26 for (const auto *i : rd->fields())
27 if (!isEmptyFieldForLayout(context, i))
28 return false;
29
30 return true;
31}
32
34 const FieldDecl *fd) {
35 if (fd->isZeroLengthBitField())
36 return true;
37
38 if (fd->isUnnamedBitField())
39 return false;
40
41 return isEmptyRecordForLayout(context, fd->getType());
42}
43
44namespace {
45
46class X8664ABIInfo : public ABIInfo {
47public:
48 X8664ABIInfo(CIRGenTypes &cgt) : ABIInfo(cgt) {}
49};
50
51class X8664TargetCIRGenInfo : public TargetCIRGenInfo {
52public:
53 X8664TargetCIRGenInfo(CIRGenTypes &cgt)
54 : TargetCIRGenInfo(std::make_unique<X8664ABIInfo>(cgt)) {}
55};
56
57} // namespace
58
59std::unique_ptr<TargetCIRGenInfo>
61 return std::make_unique<X8664TargetCIRGenInfo>(cgt);
62}
63
64ABIInfo::~ABIInfo() noexcept = default;
65
67 const FunctionNoProtoType *fnType) const {
68 // The following conventions are known to require this to be false:
69 // x86_stdcall
70 // MIPS
71 // For everything else, we just prefer false unless we opt out.
72 return false;
73}
74
76 CIRGenFunction &cgf, mlir::Value v, cir::TargetAddressSpaceAttr srcAddr,
77 mlir::Type destTy, bool isNonNull) const {
78 // Since target may map different address spaces in AST to the same address
79 // space, an address space conversion may end up as a bitcast.
80 if (cir::GlobalOp globalOp = v.getDefiningOp<cir::GlobalOp>())
81 cgf.cgm.errorNYI("Global op addrspace cast");
82 // Try to preserve the source's name to make IR more readable.
83 return cgf.getBuilder().createAddrSpaceCast(v, destTy);
84}
mlir::Value createAddrSpaceCast(mlir::Location loc, mlir::Value src, mlir::Type newTy)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:220
CIRGenBuilderTy & getBuilder()
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
This class organizes the cross-module state that is used while lowering AST types to CIR types.
Definition CIRGenTypes.h:48
virtual mlir::Value performAddrSpaceCast(CIRGenFunction &cgf, mlir::Value v, cir::TargetAddressSpaceAttr srcAddr, mlir::Type destTy, bool isNonNull=false) const
Perform address space cast of an expression of pointer type.
TargetCIRGenInfo(std::unique_ptr< ABIInfo > info)
Definition TargetInfo.h:43
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:4755
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition TypeBase.h:4832
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 > 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.