Skip to content

Commit

Permalink
fixup! Add all 32-65536 calling conventions and remove log2ABIVLen
Browse files Browse the repository at this point in the history
  • Loading branch information
4vtomat committed Jan 15, 2025
1 parent 9d1f138 commit 22a5b0e
Show file tree
Hide file tree
Showing 26 changed files with 564 additions and 187 deletions.
13 changes: 12 additions & 1 deletion clang/include/clang-c/Index.h
Original file line number Diff line number Diff line change
Expand Up @@ -3053,7 +3053,18 @@ enum CXCallingConv {
CXCallingConv_M68kRTD = 19,
CXCallingConv_PreserveNone = 20,
CXCallingConv_RISCVVectorCall = 21,
CXCallingConv_RISCVVLSCall = 22,
CXCallingConv_RISCVVLSCall_32 = 22,
CXCallingConv_RISCVVLSCall_64 = 23,
CXCallingConv_RISCVVLSCall_128 = 24,
CXCallingConv_RISCVVLSCall_256 = 25,
CXCallingConv_RISCVVLSCall_512 = 26,
CXCallingConv_RISCVVLSCall_1024 = 27,
CXCallingConv_RISCVVLSCall_2048 = 28,
CXCallingConv_RISCVVLSCall_4096 = 29,
CXCallingConv_RISCVVLSCall_8192 = 30,
CXCallingConv_RISCVVLSCall_16384 = 31,
CXCallingConv_RISCVVLSCall_32768 = 32,
CXCallingConv_RISCVVLSCall_65536 = 33,

CXCallingConv_Invalid = 100,
CXCallingConv_Unexposed = 200
Expand Down
44 changes: 14 additions & 30 deletions clang/include/clang/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -1946,7 +1946,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
/// Extra information which affects how the function is called, like
/// regparm and the calling convention.
LLVM_PREFERRED_TYPE(CallingConv)
unsigned ExtInfo : 18;
unsigned ExtInfo : 14;

/// The ref-qualifier associated with a \c FunctionProtoType.
///
Expand Down Expand Up @@ -4437,40 +4437,36 @@ class FunctionType : public Type {
// Type::FunctionTypeBitfields::ExtInfo as well.

// | CC |noreturn|produces|nocallersavedregs|regparm|nocfcheck|cmsenscall|
// |0 .. 4| 5 | 6 | 7 |8 .. 10| 11 | 12 |
// |RISCV-ABI-VLEN|
// |13 .. 17|
// |0 .. 5| 6 | 7 | 8 |9 .. 11| 12 | 13 |
//
// regparm is either 0 (no regparm attribute) or the regparm value+1.
enum { CallConvMask = 0x1F };
enum { NoReturnMask = 0x20 };
enum { ProducesResultMask = 0x40 };
enum { NoCallerSavedRegsMask = 0x80 };
enum { CallConvMask = 0x3F };
enum { NoReturnMask = 0x40 };
enum { ProducesResultMask = 0x80 };
enum { NoCallerSavedRegsMask = 0x100 };
enum {
RegParmMask = 0x700,
RegParmOffset = 8
RegParmMask = 0xe00,
RegParmOffset = 9
};
enum { NoCfCheckMask = 0x800 };
enum { CmseNSCallMask = 0x1000 };
enum { Log2RISCVABIVLenMask = 0x3E000, Log2RISCVABIVLenOffset = 13 };
uint32_t Bits = CC_C;
enum { NoCfCheckMask = 0x1000 };
enum { CmseNSCallMask = 0x2000 };
uint16_t Bits = CC_C;

ExtInfo(unsigned Bits) : Bits(static_cast<uint32_t>(Bits)) {}
ExtInfo(unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {}

public:
// Constructor with no defaults. Use this when you know that you
// have all the elements (when reading an AST file for example).
ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc,
bool producesResult, bool noCallerSavedRegs, bool NoCfCheck,
bool cmseNSCall, unsigned Log2RISCVABIVLen) {
bool cmseNSCall) {
assert((!hasRegParm || regParm < 7) && "Invalid regparm value");
Bits = ((unsigned)cc) | (noReturn ? NoReturnMask : 0) |
(producesResult ? ProducesResultMask : 0) |
(noCallerSavedRegs ? NoCallerSavedRegsMask : 0) |
(hasRegParm ? ((regParm + 1) << RegParmOffset) : 0) |
(NoCfCheck ? NoCfCheckMask : 0) |
(cmseNSCall ? CmseNSCallMask : 0) |
(Log2RISCVABIVLen << Log2RISCVABIVLenOffset);
(cmseNSCall ? CmseNSCallMask : 0);
}

// Constructor with all defaults. Use when for example creating a
Expand All @@ -4497,10 +4493,6 @@ class FunctionType : public Type {

CallingConv getCC() const { return CallingConv(Bits & CallConvMask); }

unsigned getLog2RISCVABIVLen() const {
return (Bits & Log2RISCVABIVLenMask) >> Log2RISCVABIVLenOffset;
}

bool operator==(ExtInfo Other) const {
return Bits == Other.Bits;
}
Expand Down Expand Up @@ -4556,11 +4548,6 @@ class FunctionType : public Type {
return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc);
}

ExtInfo withLog2RISCVABIVLen(unsigned Log2RISCVABIVLen) const {
return ExtInfo((Bits & ~Log2RISCVABIVLenMask) |
(Log2RISCVABIVLen << Log2RISCVABIVLenOffset));
}

void Profile(llvm::FoldingSetNodeID &ID) const {
ID.AddInteger(Bits);
}
Expand Down Expand Up @@ -4670,9 +4657,6 @@ class FunctionType : public Type {

bool getCmseNSCallAttr() const { return getExtInfo().getCmseNSCall(); }
CallingConv getCallConv() const { return getExtInfo().getCC(); }
unsigned getLog2RISCVABIVLen() const {
return getExtInfo().getLog2RISCVABIVLen();
}
ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); }

static_assert((~Qualifiers::FastMask & Qualifiers::CVRMask) == 0,
Expand Down
7 changes: 2 additions & 5 deletions clang/include/clang/AST/TypeProperties.td
Original file line number Diff line number Diff line change
Expand Up @@ -313,17 +313,14 @@ let Class = FunctionType in {
def : Property<"cmseNSCall", Bool> {
let Read = [{ node->getExtInfo().getCmseNSCall() }];
}
def : Property<"Log2RISCVABIVLen", UInt32> {
let Read = [{ node->getExtInfo().getLog2RISCVABIVLen() }];
}
}

let Class = FunctionNoProtoType in {
def : Creator<[{
auto extInfo = FunctionType::ExtInfo(noReturn, hasRegParm, regParm,
callingConvention, producesResult,
noCallerSavedRegs, noCfCheck,
cmseNSCall, Log2RISCVABIVLen);
cmseNSCall);
return ctx.getFunctionNoProtoType(returnType, extInfo);
}]>;
}
Expand Down Expand Up @@ -366,7 +363,7 @@ let Class = FunctionProtoType in {
auto extInfo = FunctionType::ExtInfo(noReturn, hasRegParm, regParm,
callingConvention, producesResult,
noCallerSavedRegs, noCfCheck,
cmseNSCall, Log2RISCVABIVLen);
cmseNSCall);
FunctionProtoType::ExtProtoInfo epi;
epi.ExtInfo = extInfo;
epi.Variadic = variadic;
Expand Down
62 changes: 37 additions & 25 deletions clang/include/clang/Basic/Specifiers.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,31 +276,43 @@ namespace clang {

/// CallingConv - Specifies the calling convention that a function uses.
enum CallingConv {
CC_C, // __attribute__((cdecl))
CC_X86StdCall, // __attribute__((stdcall))
CC_X86FastCall, // __attribute__((fastcall))
CC_X86ThisCall, // __attribute__((thiscall))
CC_X86VectorCall, // __attribute__((vectorcall))
CC_X86Pascal, // __attribute__((pascal))
CC_Win64, // __attribute__((ms_abi))
CC_X86_64SysV, // __attribute__((sysv_abi))
CC_X86RegCall, // __attribute__((regcall))
CC_AAPCS, // __attribute__((pcs("aapcs")))
CC_AAPCS_VFP, // __attribute__((pcs("aapcs-vfp")))
CC_IntelOclBicc, // __attribute__((intel_ocl_bicc))
CC_SpirFunction, // default for OpenCL functions on SPIR target
CC_OpenCLKernel, // inferred for OpenCL kernels
CC_Swift, // __attribute__((swiftcall))
CC_SwiftAsync, // __attribute__((swiftasynccall))
CC_PreserveMost, // __attribute__((preserve_most))
CC_PreserveAll, // __attribute__((preserve_all))
CC_AArch64VectorCall, // __attribute__((aarch64_vector_pcs))
CC_AArch64SVEPCS, // __attribute__((aarch64_sve_pcs))
CC_AMDGPUKernelCall, // __attribute__((amdgpu_kernel))
CC_M68kRTD, // __attribute__((m68k_rtd))
CC_PreserveNone, // __attribute__((preserve_none))
CC_RISCVVectorCall, // __attribute__((riscv_vector_cc))
CC_RISCVVLSCall, // __attribute__((riscv_vls_cc))
CC_C, // __attribute__((cdecl))
CC_X86StdCall, // __attribute__((stdcall))
CC_X86FastCall, // __attribute__((fastcall))
CC_X86ThisCall, // __attribute__((thiscall))
CC_X86VectorCall, // __attribute__((vectorcall))
CC_X86Pascal, // __attribute__((pascal))
CC_Win64, // __attribute__((ms_abi))
CC_X86_64SysV, // __attribute__((sysv_abi))
CC_X86RegCall, // __attribute__((regcall))
CC_AAPCS, // __attribute__((pcs("aapcs")))
CC_AAPCS_VFP, // __attribute__((pcs("aapcs-vfp")))
CC_IntelOclBicc, // __attribute__((intel_ocl_bicc))
CC_SpirFunction, // default for OpenCL functions on SPIR target
CC_OpenCLKernel, // inferred for OpenCL kernels
CC_Swift, // __attribute__((swiftcall))
CC_SwiftAsync, // __attribute__((swiftasynccall))
CC_PreserveMost, // __attribute__((preserve_most))
CC_PreserveAll, // __attribute__((preserve_all))
CC_AArch64VectorCall, // __attribute__((aarch64_vector_pcs))
CC_AArch64SVEPCS, // __attribute__((aarch64_sve_pcs))
CC_AMDGPUKernelCall, // __attribute__((amdgpu_kernel))
CC_M68kRTD, // __attribute__((m68k_rtd))
CC_PreserveNone, // __attribute__((preserve_none))
CC_RISCVVectorCall, // __attribute__((riscv_vector_cc))
CC_RISCVVLSCall_32, // __attribute__((riscv_vls_cc(32)))
CC_RISCVVLSCall_64, // __attribute__((riscv_vls_cc(64)))
CC_RISCVVLSCall_128, // __attribute__((riscv_vls_cc)) or
// __attribute__((riscv_vls_cc(128)))
CC_RISCVVLSCall_256, // __attribute__((riscv_vls_cc(256)))
CC_RISCVVLSCall_512, // __attribute__((riscv_vls_cc(512)))
CC_RISCVVLSCall_1024, // __attribute__((riscv_vls_cc(1024)))
CC_RISCVVLSCall_2048, // __attribute__((riscv_vls_cc(2048)))
CC_RISCVVLSCall_4096, // __attribute__((riscv_vls_cc(4096)))
CC_RISCVVLSCall_8192, // __attribute__((riscv_vls_cc(8192)))
CC_RISCVVLSCall_16384, // __attribute__((riscv_vls_cc(16384)))
CC_RISCVVLSCall_32768, // __attribute__((riscv_vls_cc(32768)))
CC_RISCVVLSCall_65536, // __attribute__((riscv_vls_cc(65536)))
};

/// Checks whether the given calling convention supports variadic
Expand Down
9 changes: 1 addition & 8 deletions clang/include/clang/CodeGen/CGFunctionInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,6 @@ class CGFunctionInfo final
/// Log 2 of the maximum vector width.
unsigned MaxVectorWidth : 4;

/// Log2 of ABI_VLEN used in RISCV VLS calling convention.
unsigned Log2RISCVABIVLen : 5;

RequiredArgs Required;

/// The struct representing all arguments passed in memory. Only used when
Expand Down Expand Up @@ -738,13 +735,11 @@ class CGFunctionInfo final
bool getHasRegParm() const { return HasRegParm; }
unsigned getRegParm() const { return RegParm; }

unsigned getLog2RISCVABIVLen() const { return Log2RISCVABIVLen; }

FunctionType::ExtInfo getExtInfo() const {
return FunctionType::ExtInfo(isNoReturn(), getHasRegParm(), getRegParm(),
getASTCallingConvention(), isReturnsRetained(),
isNoCallerSavedRegs(), isNoCfCheck(),
isCmseNSCall(), getLog2RISCVABIVLen());
isCmseNSCall());
}

CanQualType getReturnType() const { return getArgsBuffer()[0].type; }
Expand Down Expand Up @@ -798,7 +793,6 @@ class CGFunctionInfo final
ID.AddInteger(RegParm);
ID.AddBoolean(NoCfCheck);
ID.AddBoolean(CmseNSCall);
ID.AddInteger(Log2RISCVABIVLen);
ID.AddInteger(Required.getOpaqueData());
ID.AddBoolean(HasExtParameterInfos);
if (HasExtParameterInfos) {
Expand Down Expand Up @@ -826,7 +820,6 @@ class CGFunctionInfo final
ID.AddInteger(info.getRegParm());
ID.AddBoolean(info.getNoCfCheck());
ID.AddBoolean(info.getCmseNSCall());
ID.AddInteger(info.getLog2RISCVABIVLen());
ID.AddInteger(required.getOpaqueData());
ID.AddBoolean(!paramInfos.empty());
if (!paramInfos.empty()) {
Expand Down
2 changes: 0 additions & 2 deletions clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11108,8 +11108,6 @@ QualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs,
return {};
if (lbaseInfo.getNoCfCheck() != rbaseInfo.getNoCfCheck())
return {};
if (lbaseInfo.getLog2RISCVABIVLen() != rbaseInfo.getLog2RISCVABIVLen())
return {};

// When merging declarations, it's common for supplemental information like
// attributes to only be present in one of the declarations, and we generally
Expand Down
15 changes: 14 additions & 1 deletion clang/lib/AST/ItaniumMangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3489,7 +3489,20 @@ StringRef CXXNameMangler::getCallingConvQualifierName(CallingConv CC) {
case CC_M68kRTD:
case CC_PreserveNone:
case CC_RISCVVectorCall:
case CC_RISCVVLSCall:
#define CC_VLS_CASE(ABI_VLEN) case CC_RISCVVLSCall_##ABI_VLEN:
CC_VLS_CASE(32)
CC_VLS_CASE(64)
CC_VLS_CASE(128)
CC_VLS_CASE(256)
CC_VLS_CASE(512)
CC_VLS_CASE(1024)
CC_VLS_CASE(2048)
CC_VLS_CASE(4096)
CC_VLS_CASE(8192)
CC_VLS_CASE(16384)
CC_VLS_CASE(32768)
CC_VLS_CASE(65536)
#undef CC_VLS_CASE
// FIXME: we should be mangling all of the above.
return "";

Expand Down
16 changes: 15 additions & 1 deletion clang/lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3561,7 +3561,21 @@ StringRef FunctionType::getNameForCallConv(CallingConv CC) {
case CC_PreserveNone: return "preserve_none";
// clang-format off
case CC_RISCVVectorCall: return "riscv_vector_cc";
case CC_RISCVVLSCall: return "riscv_vls_cc";
#define CC_VLS_CASE(ABI_VLEN) \
case CC_RISCVVLSCall_##ABI_VLEN: return "riscv_vls_cc(" #ABI_VLEN ")";
CC_VLS_CASE(32)
CC_VLS_CASE(64)
CC_VLS_CASE(128)
CC_VLS_CASE(256)
CC_VLS_CASE(512)
CC_VLS_CASE(1024)
CC_VLS_CASE(2048)
CC_VLS_CASE(4096)
CC_VLS_CASE(8192)
CC_VLS_CASE(16384)
CC_VLS_CASE(32768)
CC_VLS_CASE(65536)
#undef CC_VLS_CASE
// clang-format on
}

Expand Down
20 changes: 17 additions & 3 deletions clang/lib/AST/TypePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,9 +1136,23 @@ void TypePrinter::printFunctionAfter(const FunctionType::ExtInfo &Info,
case CC_RISCVVectorCall:
OS << "__attribute__((riscv_vector_cc))";
break;
case CC_RISCVVLSCall:
OS << "__attribute__((riscv_vls_cc))";
break;
#define CC_VLS_CASE(ABI_VLEN) \
case CC_RISCVVLSCall_##ABI_VLEN: \
OS << "__attribute__((riscv_vls_cc" #ABI_VLEN "))"; \
break;
CC_VLS_CASE(32)
CC_VLS_CASE(64)
CC_VLS_CASE(128)
CC_VLS_CASE(256)
CC_VLS_CASE(512)
CC_VLS_CASE(1024)
CC_VLS_CASE(2048)
CC_VLS_CASE(4096)
CC_VLS_CASE(8192)
CC_VLS_CASE(16384)
CC_VLS_CASE(32768)
CC_VLS_CASE(65536)
#undef CC_VLS_CASE
}
}

Expand Down
13 changes: 12 additions & 1 deletion clang/lib/Basic/Targets/RISCV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,18 @@ RISCVTargetInfo::checkCallingConvention(CallingConv CC) const {
return CCCR_Warning;
case CC_C:
case CC_RISCVVectorCall:
case CC_RISCVVLSCall:
case CC_RISCVVLSCall_32:
case CC_RISCVVLSCall_64:
case CC_RISCVVLSCall_128:
case CC_RISCVVLSCall_256:
case CC_RISCVVLSCall_512:
case CC_RISCVVLSCall_1024:
case CC_RISCVVLSCall_2048:
case CC_RISCVVLSCall_4096:
case CC_RISCVVLSCall_8192:
case CC_RISCVVLSCall_16384:
case CC_RISCVVLSCall_32768:
case CC_RISCVVLSCall_65536:
return CCCR_OK;
}
}
Expand Down
Loading

0 comments on commit 22a5b0e

Please sign in to comment.