llvm-project/clang/lib/CIR/CodeGen/TargetInfo.cpp
Jameson Nash d040788af6
[clang] remove unused SrcAddr parameter from performAddrSpaceCast (#179330)
The conversion code always ended up just getting the type of Src from
the Src argument itself, with no virtual users of this, so there is no
point in also providing this API hook. Fix the documentation as well,
since it seems DestAddr must have been similarly removed at some point
in the past from the API but was still documented.

Also fixes CIR to actually return the casted value!
2026-02-05 14:03:19 -05:00

93 lines
2.3 KiB
C++

#include "TargetInfo.h"
#include "ABIInfo.h"
#include "CIRGenFunction.h"
#include "clang/CIR/Dialect/IR/CIRAttrs.h"
#include "clang/CIR/Dialect/IR/CIRDialect.h"
using namespace clang;
using namespace clang::CIRGen;
bool clang::CIRGen::isEmptyRecordForLayout(const ASTContext &context,
QualType t) {
const auto *rd = t->getAsRecordDecl();
if (!rd)
return false;
// If this is a C++ record, check the bases first.
if (const CXXRecordDecl *cxxrd = dyn_cast<CXXRecordDecl>(rd)) {
if (cxxrd->isDynamicClass())
return false;
for (const auto &i : cxxrd->bases())
if (!isEmptyRecordForLayout(context, i.getType()))
return false;
}
for (const auto *i : rd->fields())
if (!isEmptyFieldForLayout(context, i))
return false;
return true;
}
bool clang::CIRGen::isEmptyFieldForLayout(const ASTContext &context,
const FieldDecl *fd) {
if (fd->isZeroLengthBitField())
return true;
if (fd->isUnnamedBitField())
return false;
return isEmptyRecordForLayout(context, fd->getType());
}
namespace {
class X8664ABIInfo : public ABIInfo {
public:
X8664ABIInfo(CIRGenTypes &cgt) : ABIInfo(cgt) {}
};
class X8664TargetCIRGenInfo : public TargetCIRGenInfo {
public:
X8664TargetCIRGenInfo(CIRGenTypes &cgt)
: TargetCIRGenInfo(std::make_unique<X8664ABIInfo>(cgt)) {}
};
} // namespace
namespace {
class NVPTXABIInfo : public ABIInfo {
public:
NVPTXABIInfo(CIRGenTypes &cgt) : ABIInfo(cgt) {}
};
class NVPTXTargetCIRGenInfo : public TargetCIRGenInfo {
public:
NVPTXTargetCIRGenInfo(CIRGenTypes &cgt)
: TargetCIRGenInfo(std::make_unique<NVPTXABIInfo>(cgt)) {}
};
} // namespace
std::unique_ptr<TargetCIRGenInfo>
clang::CIRGen::createNVPTXTargetCIRGenInfo(CIRGenTypes &cgt) {
return std::make_unique<NVPTXTargetCIRGenInfo>(cgt);
}
std::unique_ptr<TargetCIRGenInfo>
clang::CIRGen::createX8664TargetCIRGenInfo(CIRGenTypes &cgt) {
return std::make_unique<X8664TargetCIRGenInfo>(cgt);
}
ABIInfo::~ABIInfo() noexcept = default;
bool TargetCIRGenInfo::isNoProtoCallVariadic(
const FunctionNoProtoType *fnType) const {
// The following conventions are known to require this to be false:
// x86_stdcall
// MIPS
// For everything else, we just prefer false unless we opt out.
return false;
}