Skip to content

Commit 14aca60

Browse files
authored
[CIR][CodeGen][NFC] Replace the calling convention in CodeGen with the one in dialect (#772)
This PR remove the header `CIR/CodeGen/CallingConv.h` and migrates all `::cir::CallingConv` stuff to `::mlir::cir::CallingConv` in `CIRGenTypes` and `CIRGenFunctionInfo`. In TargetLowering library, LowerTypes and LowerFunctionInfo basically have the same clangCallConvToLLVMCallConv stuff. The CC there is the LLVM one. But those changes are not included because of the potential conflicts. We can still easily switch to the dialect when it's needed.
1 parent 38c1348 commit 14aca60

File tree

7 files changed

+20
-67
lines changed

7 files changed

+20
-67
lines changed

clang/lib/CIR/CodeGen/CIRGenCall.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ using namespace cir;
3939
using namespace clang;
4040

4141
CIRGenFunctionInfo *CIRGenFunctionInfo::create(
42-
unsigned cirCC, bool instanceMethod, bool chainCall,
42+
mlir::cir::CallingConv cirCC, bool instanceMethod, bool chainCall,
4343
const FunctionType::ExtInfo &info,
4444
llvm::ArrayRef<ExtParameterInfo> paramInfos, CanQualType resultType,
4545
llvm::ArrayRef<CanQualType> argTypes, RequiredArgs required) {

clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ class CIRGenFunctionInfo final
8888
typedef clang::FunctionProtoType::ExtParameterInfo ExtParameterInfo;
8989

9090
/// The cir::CallingConv to use for this function (as specified by the user).
91-
unsigned CallingConvention : 8;
91+
mlir::cir::CallingConv CallingConvention : 8;
9292

9393
/// The cir::CallingConv to actually use for this function, which may depend
9494
/// on the ABI.
95-
unsigned EffectiveCallingConvention : 8;
95+
mlir::cir::CallingConv EffectiveCallingConvention : 8;
9696

9797
/// The clang::CallingConv that this was originally created with.
9898
unsigned ASTCallingConvention : 6;
@@ -150,7 +150,7 @@ class CIRGenFunctionInfo final
150150
CIRGenFunctionInfo() : Required(RequiredArgs::All) {}
151151

152152
public:
153-
static CIRGenFunctionInfo *create(unsigned cirCC, bool instanceMethod,
153+
static CIRGenFunctionInfo *create(mlir::cir::CallingConv cirCC, bool instanceMethod,
154154
bool chainCall,
155155
const clang::FunctionType::ExtInfo &extInfo,
156156
llvm::ArrayRef<ExtParameterInfo> paramInfos,
@@ -252,7 +252,7 @@ class CIRGenFunctionInfo final
252252

253253
/// getCallingConvention - REturn the user specified calling convention, which
254254
/// has been translated into a CIR CC.
255-
unsigned getCallingConvention() const { return CallingConvention; }
255+
mlir::cir::CallingConv getCallingConvention() const { return CallingConvention; }
256256

257257
clang::CanQualType getReturnType() const { return getArgsBuffer()[0].type; }
258258

clang/lib/CIR/CodeGen/CIRGenTypes.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
#include "CIRGenCall.h"
33
#include "CIRGenFunctionInfo.h"
44
#include "CIRGenModule.h"
5-
#include "CallingConv.h"
65
#include "TargetInfo.h"
76

87
#include "mlir/IR/Builders.h"
98
#include "mlir/IR/BuiltinTypes.h"
109
#include "clang/CIR/Dialect/IR/CIRTypes.h"
10+
#include "clang/CIR/Dialect/IR/CIRAttrs.h"
1111

1212
#include "clang/AST/ASTContext.h"
1313
#include "clang/AST/DeclCXX.h"
@@ -24,12 +24,14 @@
2424
using namespace clang;
2525
using namespace cir;
2626

27-
unsigned CIRGenTypes::ClangCallConvToCIRCallConv(clang::CallingConv CC) {
27+
mlir::cir::CallingConv CIRGenTypes::ClangCallConvToCIRCallConv(clang::CallingConv CC) {
2828
switch (CC) {
2929
case CC_C:
30-
return cir::CallingConv::C;
30+
return mlir::cir::CallingConv::C;
3131
case CC_OpenCLKernel:
3232
return CGM.getTargetCIRGenInfo().getOpenCLKernelCallingConv();
33+
case CC_SpirFunction:
34+
return mlir::cir::CallingConv::SpirFunction;
3335
default:
3436
llvm_unreachable("No other calling conventions implemented.");
3537
}
@@ -761,7 +763,7 @@ const CIRGenFunctionInfo &CIRGenTypes::arrangeCIRFunctionInfo(
761763
if (FI)
762764
return *FI;
763765

764-
unsigned CC = ClangCallConvToCIRCallConv(info.getCC());
766+
mlir::cir::CallingConv CC = ClangCallConvToCIRCallConv(info.getCC());
765767

766768
// Construction the function info. We co-allocate the ArgInfos.
767769
FI = CIRGenFunctionInfo::create(CC, instanceMethod, chainCall, info,

clang/lib/CIR/CodeGen/CIRGenTypes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ class CIRGenTypes {
126126
bool isFuncTypeConvertible(const clang::FunctionType *FT);
127127
bool isFuncParamTypeConvertible(clang::QualType Ty);
128128

129-
/// Convert clang calling convention to LLVM calling convention.
130-
unsigned ClangCallConvToCIRCallConv(clang::CallingConv CC);
129+
/// Convert clang calling convention to CIR calling convention.
130+
mlir::cir::CallingConv ClangCallConvToCIRCallConv(clang::CallingConv CC);
131131

132132
/// Derives the 'this' type for CIRGen purposes, i.e. ignoring method CVR
133133
/// qualification.

clang/lib/CIR/CodeGen/CallingConv.h

Lines changed: 0 additions & 49 deletions
This file was deleted.

clang/lib/CIR/CodeGen/TargetInfo.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,15 @@ class SPIRVABIInfo : public CommonSPIRABIInfo {
241241
void computeInfo(CIRGenFunctionInfo &FI) const override {
242242
// The logic is same as in DefaultABIInfo with an exception on the kernel
243243
// arguments handling.
244-
llvm::CallingConv::ID CC = FI.getCallingConvention();
244+
mlir::cir::CallingConv CC = FI.getCallingConvention();
245245

246246
bool cxxabiHit = getCXXABI().classifyReturnType(FI);
247247
assert(!cxxabiHit && "C++ ABI not considered");
248248

249249
FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
250250

251251
for (auto &I : FI.arguments()) {
252-
if (CC == llvm::CallingConv::SPIR_KERNEL) {
252+
if (CC == mlir::cir::CallingConv::SpirKernel) {
253253
I.info = classifyKernelArgumentType(I.type);
254254
} else {
255255
I.info = classifyArgumentType(I.type);
@@ -277,8 +277,8 @@ class CommonSPIRTargetCIRGenInfo : public TargetCIRGenInfo {
277277
mlir::cir::AddressSpaceAttr::Kind::offload_private);
278278
}
279279

280-
unsigned getOpenCLKernelCallingConv() const override {
281-
return llvm::CallingConv::SPIR_KERNEL;
280+
mlir::cir::CallingConv getOpenCLKernelCallingConv() const override {
281+
return mlir::cir::CallingConv::SpirKernel;
282282
}
283283
};
284284

clang/lib/CIR/CodeGen/TargetInfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ class TargetCIRGenInfo {
8181
mlir::Type DestTy,
8282
bool IsNonNull = false) const;
8383

84-
/// Get LLVM calling convention for OpenCL kernel.
85-
virtual unsigned getOpenCLKernelCallingConv() const {
84+
/// Get CIR calling convention for OpenCL kernel.
85+
virtual mlir::cir::CallingConv getOpenCLKernelCallingConv() const {
8686
// OpenCL kernels are called via an explicit runtime API with arguments
8787
// set with clSetKernelArg(), not as normal sub-functions.
8888
// Return SPIR_KERNEL by default as the kernel calling convention to
@@ -93,7 +93,7 @@ class TargetCIRGenInfo {
9393
// clSetKernelArg() might break depending on the target-specific
9494
// conventions; different targets might split structs passed as values
9595
// to multiple function arguments etc.
96-
return llvm::CallingConv::SPIR_KERNEL;
96+
return mlir::cir::CallingConv::SpirKernel;
9797
}
9898

9999
virtual ~TargetCIRGenInfo() {}

0 commit comments

Comments
 (0)