
This is a major change on how we represent nested name qualifications in the AST. * The nested name specifier itself and how it's stored is changed. The prefixes for types are handled within the type hierarchy, which makes canonicalization for them super cheap, no memory allocation required. Also translating a type into nested name specifier form becomes a no-op. An identifier is stored as a DependentNameType. The nested name specifier gains a lightweight handle class, to be used instead of passing around pointers, which is similar to what is implemented for TemplateName. There is still one free bit available, and this handle can be used within a PointerUnion and PointerIntPair, which should keep bit-packing aficionados happy. * The ElaboratedType node is removed, all type nodes in which it could previously apply to can now store the elaborated keyword and name qualifier, tail allocating when present. * TagTypes can now point to the exact declaration found when producing these, as opposed to the previous situation of there only existing one TagType per entity. This increases the amount of type sugar retained, and can have several applications, for example in tracking module ownership, and other tools which care about source file origins, such as IWYU. These TagTypes are lazily allocated, in order to limit the increase in AST size. This patch offers a great performance benefit. It greatly improves compilation time for [stdexec](https://github.com/NVIDIA/stdexec). For one datapoint, for `test_on2.cpp` in that project, which is the slowest compiling test, this patch improves `-c` compilation time by about 7.2%, with the `-fsyntax-only` improvement being at ~12%. This has great results on compile-time-tracker as well:  This patch also further enables other optimziations in the future, and will reduce the performance impact of template specialization resugaring when that lands. It has some other miscelaneous drive-by fixes. About the review: Yes the patch is huge, sorry about that. Part of the reason is that I started by the nested name specifier part, before the ElaboratedType part, but that had a huge performance downside, as ElaboratedType is a big performance hog. I didn't have the steam to go back and change the patch after the fact. There is also a lot of internal API changes, and it made sense to remove ElaboratedType in one go, versus removing it from one type at a time, as that would present much more churn to the users. Also, the nested name specifier having a different API avoids missing changes related to how prefixes work now, which could make existing code compile but not work. How to review: The important changes are all in `clang/include/clang/AST` and `clang/lib/AST`, with also important changes in `clang/lib/Sema/TreeTransform.h`. The rest and bulk of the changes are mostly consequences of the changes in API. PS: TagType::getDecl is renamed to `getOriginalDecl` in this patch, just for easier to rebasing. I plan to rename it back after this lands. Fixes #136624 Fixes https://github.com/llvm/llvm-project/issues/43179 Fixes https://github.com/llvm/llvm-project/issues/68670 Fixes https://github.com/llvm/llvm-project/issues/92757
176 lines
6.3 KiB
C++
176 lines
6.3 KiB
C++
//===- CSKY.cpp -----------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "ABIInfoImpl.h"
|
|
#include "TargetInfo.h"
|
|
|
|
using namespace clang;
|
|
using namespace clang::CodeGen;
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// CSKY ABI Implementation
|
|
//===----------------------------------------------------------------------===//
|
|
namespace {
|
|
class CSKYABIInfo : public DefaultABIInfo {
|
|
static const int NumArgGPRs = 4;
|
|
static const int NumArgFPRs = 4;
|
|
|
|
static const unsigned XLen = 32;
|
|
unsigned FLen;
|
|
|
|
public:
|
|
CSKYABIInfo(CodeGen::CodeGenTypes &CGT, unsigned FLen)
|
|
: DefaultABIInfo(CGT), FLen(FLen) {}
|
|
|
|
void computeInfo(CGFunctionInfo &FI) const override;
|
|
ABIArgInfo classifyArgumentType(QualType Ty, int &ArgGPRsLeft,
|
|
int &ArgFPRsLeft,
|
|
bool isReturnType = false) const;
|
|
ABIArgInfo classifyReturnType(QualType RetTy) const;
|
|
|
|
RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
|
|
AggValueSlot Slot) const override;
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
void CSKYABIInfo::computeInfo(CGFunctionInfo &FI) const {
|
|
QualType RetTy = FI.getReturnType();
|
|
if (!getCXXABI().classifyReturnType(FI))
|
|
FI.getReturnInfo() = classifyReturnType(RetTy);
|
|
|
|
bool IsRetIndirect = FI.getReturnInfo().getKind() == ABIArgInfo::Indirect;
|
|
|
|
// We must track the number of GPRs used in order to conform to the CSKY
|
|
// ABI, as integer scalars passed in registers should have signext/zeroext
|
|
// when promoted.
|
|
int ArgGPRsLeft = IsRetIndirect ? NumArgGPRs - 1 : NumArgGPRs;
|
|
int ArgFPRsLeft = FLen ? NumArgFPRs : 0;
|
|
|
|
for (auto &ArgInfo : FI.arguments()) {
|
|
ArgInfo.info = classifyArgumentType(ArgInfo.type, ArgGPRsLeft, ArgFPRsLeft);
|
|
}
|
|
}
|
|
|
|
RValue CSKYABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
|
|
QualType Ty, AggValueSlot Slot) const {
|
|
CharUnits SlotSize = CharUnits::fromQuantity(XLen / 8);
|
|
|
|
// Empty records are ignored for parameter passing purposes.
|
|
if (isEmptyRecord(getContext(), Ty, true))
|
|
return Slot.asRValue();
|
|
|
|
auto TInfo = getContext().getTypeInfoInChars(Ty);
|
|
|
|
return emitVoidPtrVAArg(CGF, VAListAddr, Ty, false, TInfo, SlotSize,
|
|
/*AllowHigherAlign=*/true, Slot);
|
|
}
|
|
|
|
ABIArgInfo CSKYABIInfo::classifyArgumentType(QualType Ty, int &ArgGPRsLeft,
|
|
int &ArgFPRsLeft,
|
|
bool isReturnType) const {
|
|
assert(ArgGPRsLeft <= NumArgGPRs && "Arg GPR tracking underflow");
|
|
Ty = useFirstFieldIfTransparentUnion(Ty);
|
|
|
|
// Structures with either a non-trivial destructor or a non-trivial
|
|
// copy constructor are always passed indirectly.
|
|
if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(Ty, getCXXABI())) {
|
|
if (ArgGPRsLeft)
|
|
ArgGPRsLeft -= 1;
|
|
return getNaturalAlignIndirect(
|
|
Ty, /*AddrSpace=*/getDataLayout().getAllocaAddrSpace(),
|
|
/*ByVal=*/RAA == CGCXXABI::RAA_DirectInMemory);
|
|
}
|
|
|
|
// Ignore empty structs/unions.
|
|
if (isEmptyRecord(getContext(), Ty, true))
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
if (!Ty->getAsUnionType())
|
|
if (const Type *SeltTy = isSingleElementStruct(Ty, getContext()))
|
|
return ABIArgInfo::getDirect(CGT.ConvertType(QualType(SeltTy, 0)));
|
|
|
|
uint64_t Size = getContext().getTypeSize(Ty);
|
|
// Pass floating point values via FPRs if possible.
|
|
if (Ty->isFloatingType() && !Ty->isComplexType() && FLen >= Size &&
|
|
ArgFPRsLeft) {
|
|
ArgFPRsLeft--;
|
|
return ABIArgInfo::getDirect();
|
|
}
|
|
|
|
// Complex types for the hard float ABI must be passed direct rather than
|
|
// using CoerceAndExpand.
|
|
if (Ty->isComplexType() && FLen && !isReturnType) {
|
|
QualType EltTy = Ty->castAs<ComplexType>()->getElementType();
|
|
if (getContext().getTypeSize(EltTy) <= FLen) {
|
|
ArgFPRsLeft -= 2;
|
|
return ABIArgInfo::getDirect();
|
|
}
|
|
}
|
|
|
|
if (!isAggregateTypeForABI(Ty)) {
|
|
// Treat an enum type as its underlying type.
|
|
if (const EnumType *EnumTy = Ty->getAs<EnumType>())
|
|
Ty = EnumTy->getOriginalDecl()->getDefinitionOrSelf()->getIntegerType();
|
|
|
|
// All integral types are promoted to XLen width, unless passed on the
|
|
// stack.
|
|
if (Size < XLen && Ty->isIntegralOrEnumerationType())
|
|
return ABIArgInfo::getExtend(Ty);
|
|
|
|
if (const auto *EIT = Ty->getAs<BitIntType>()) {
|
|
if (EIT->getNumBits() < XLen)
|
|
return ABIArgInfo::getExtend(Ty);
|
|
}
|
|
|
|
return ABIArgInfo::getDirect();
|
|
}
|
|
|
|
// For argument type, the first 4*XLen parts of aggregate will be passed
|
|
// in registers, and the rest will be passed in stack.
|
|
// So we can coerce to integers directly and let backend handle it correctly.
|
|
// For return type, aggregate which <= 2*XLen will be returned in registers.
|
|
// Otherwise, aggregate will be returned indirectly.
|
|
if (!isReturnType || (isReturnType && Size <= 2 * XLen)) {
|
|
if (Size <= XLen) {
|
|
return ABIArgInfo::getDirect(
|
|
llvm::IntegerType::get(getVMContext(), XLen));
|
|
} else {
|
|
return ABIArgInfo::getDirect(llvm::ArrayType::get(
|
|
llvm::IntegerType::get(getVMContext(), XLen), (Size + 31) / XLen));
|
|
}
|
|
}
|
|
return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
|
|
/*ByVal=*/false);
|
|
}
|
|
|
|
ABIArgInfo CSKYABIInfo::classifyReturnType(QualType RetTy) const {
|
|
if (RetTy->isVoidType())
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
int ArgGPRsLeft = 2;
|
|
int ArgFPRsLeft = FLen ? 1 : 0;
|
|
|
|
// The rules for return and argument types are the same, so defer to
|
|
// classifyArgumentType.
|
|
return classifyArgumentType(RetTy, ArgGPRsLeft, ArgFPRsLeft, true);
|
|
}
|
|
|
|
namespace {
|
|
class CSKYTargetCodeGenInfo : public TargetCodeGenInfo {
|
|
public:
|
|
CSKYTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT, unsigned FLen)
|
|
: TargetCodeGenInfo(std::make_unique<CSKYABIInfo>(CGT, FLen)) {}
|
|
};
|
|
} // end anonymous namespace
|
|
|
|
std::unique_ptr<TargetCodeGenInfo>
|
|
CodeGen::createCSKYTargetCodeGenInfo(CodeGenModule &CGM, unsigned FLen) {
|
|
return std::make_unique<CSKYTargetCodeGenInfo>(CGM.getTypes(), FLen);
|
|
}
|