| 1 |
#include "TargetInfo.h" |
| 2 |
#include "ABIInfo.h" |
| 3 |
#include "CIRGenFunction.h" |
| 4 |
#include "clang/CIR/Dialect/IR/CIRAttrs.h" |
| 5 |
#include "clang/CIR/Dialect/IR/CIRDialect.h" |
| 6 |
|
| 7 |
using namespace clang; |
| 8 |
using namespace clang::CIRGen; |
| 9 |
|
| 10 |
bool clang::CIRGen::isEmptyRecordForLayout(const ASTContext &context, |
| 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 |
|
| 33 |
bool clang::CIRGen::isEmptyFieldForLayout(const ASTContext &context, |
| 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 |
|
| 44 |
namespace { |
| 45 |
|
| 46 |
class X8664ABIInfo : public ABIInfo { |
| 47 |
public: |
| 48 |
X8664ABIInfo(CIRGenTypes &cgt) : ABIInfo(cgt) {} |
| 49 |
}; |
| 50 |
|
| 51 |
class X8664TargetCIRGenInfo : public TargetCIRGenInfo { |
| 52 |
public: |
| 53 |
X8664TargetCIRGenInfo(CIRGenTypes &cgt) |
| 54 |
: TargetCIRGenInfo(std::make_unique<X8664ABIInfo>(cgt)) {} |
| 55 |
}; |
| 56 |
|
| 57 |
} // namespace |
| 58 |
|
| 59 |
std::unique_ptr<TargetCIRGenInfo> |
| 60 |
clang::CIRGen::createX8664TargetCIRGenInfo(CIRGenTypes &cgt) { |
| 61 |
return std::make_unique<X8664TargetCIRGenInfo>(cgt); |
| 62 |
} |
| 63 |
|
| 64 |
ABIInfo::~ABIInfo() noexcept = default; |
| 65 |
|
| 66 |
bool TargetCIRGenInfo::isNoProtoCallVariadic( |
| 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 |
|
| 75 |
mlir::Value TargetCIRGenInfo::performAddrSpaceCast( |
| 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 |
} |