Skip to content

[CIR][CodeGen][NFC] Replace the calling convention in CodeGen with the one in dialect #772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRGenCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ using namespace cir;
using namespace clang;

CIRGenFunctionInfo *CIRGenFunctionInfo::create(
unsigned cirCC, bool instanceMethod, bool chainCall,
mlir::cir::CallingConv cirCC, bool instanceMethod, bool chainCall,
const FunctionType::ExtInfo &info,
llvm::ArrayRef<ExtParameterInfo> paramInfos, CanQualType resultType,
llvm::ArrayRef<CanQualType> argTypes, RequiredArgs required) {
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ class CIRGenFunctionInfo final
typedef clang::FunctionProtoType::ExtParameterInfo ExtParameterInfo;

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

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

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

public:
static CIRGenFunctionInfo *create(unsigned cirCC, bool instanceMethod,
static CIRGenFunctionInfo *create(mlir::cir::CallingConv cirCC, bool instanceMethod,
bool chainCall,
const clang::FunctionType::ExtInfo &extInfo,
llvm::ArrayRef<ExtParameterInfo> paramInfos,
Expand Down Expand Up @@ -252,7 +252,7 @@ class CIRGenFunctionInfo final

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

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

Expand Down
10 changes: 6 additions & 4 deletions clang/lib/CIR/CodeGen/CIRGenTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#include "CIRGenCall.h"
#include "CIRGenFunctionInfo.h"
#include "CIRGenModule.h"
#include "CallingConv.h"
#include "TargetInfo.h"

#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinTypes.h"
#include "clang/CIR/Dialect/IR/CIRTypes.h"
#include "clang/CIR/Dialect/IR/CIRAttrs.h"

#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclCXX.h"
Expand All @@ -24,12 +24,14 @@
using namespace clang;
using namespace cir;

unsigned CIRGenTypes::ClangCallConvToCIRCallConv(clang::CallingConv CC) {
mlir::cir::CallingConv CIRGenTypes::ClangCallConvToCIRCallConv(clang::CallingConv CC) {
switch (CC) {
case CC_C:
return cir::CallingConv::C;
return mlir::cir::CallingConv::C;
case CC_OpenCLKernel:
return CGM.getTargetCIRGenInfo().getOpenCLKernelCallingConv();
case CC_SpirFunction:
return mlir::cir::CallingConv::SpirFunction;
default:
llvm_unreachable("No other calling conventions implemented.");
}
Expand Down Expand Up @@ -761,7 +763,7 @@ const CIRGenFunctionInfo &CIRGenTypes::arrangeCIRFunctionInfo(
if (FI)
return *FI;

unsigned CC = ClangCallConvToCIRCallConv(info.getCC());
mlir::cir::CallingConv CC = ClangCallConvToCIRCallConv(info.getCC());

// Construction the function info. We co-allocate the ArgInfos.
FI = CIRGenFunctionInfo::create(CC, instanceMethod, chainCall, info,
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CIR/CodeGen/CIRGenTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ class CIRGenTypes {
bool isFuncTypeConvertible(const clang::FunctionType *FT);
bool isFuncParamTypeConvertible(clang::QualType Ty);

/// Convert clang calling convention to LLVM calling convention.
unsigned ClangCallConvToCIRCallConv(clang::CallingConv CC);
/// Convert clang calling convention to CIR calling convention.
mlir::cir::CallingConv ClangCallConvToCIRCallConv(clang::CallingConv CC);

/// Derives the 'this' type for CIRGen purposes, i.e. ignoring method CVR
/// qualification.
Expand Down
49 changes: 0 additions & 49 deletions clang/lib/CIR/CodeGen/CallingConv.h

This file was deleted.

8 changes: 4 additions & 4 deletions clang/lib/CIR/CodeGen/TargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,15 @@ class SPIRVABIInfo : public CommonSPIRABIInfo {
void computeInfo(CIRGenFunctionInfo &FI) const override {
// The logic is same as in DefaultABIInfo with an exception on the kernel
// arguments handling.
llvm::CallingConv::ID CC = FI.getCallingConvention();
mlir::cir::CallingConv CC = FI.getCallingConvention();

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

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

for (auto &I : FI.arguments()) {
if (CC == llvm::CallingConv::SPIR_KERNEL) {
if (CC == mlir::cir::CallingConv::SpirKernel) {
I.info = classifyKernelArgumentType(I.type);
} else {
I.info = classifyArgumentType(I.type);
Expand Down Expand Up @@ -277,8 +277,8 @@ class CommonSPIRTargetCIRGenInfo : public TargetCIRGenInfo {
mlir::cir::AddressSpaceAttr::Kind::offload_private);
}

unsigned getOpenCLKernelCallingConv() const override {
return llvm::CallingConv::SPIR_KERNEL;
mlir::cir::CallingConv getOpenCLKernelCallingConv() const override {
return mlir::cir::CallingConv::SpirKernel;
}
};

Expand Down
6 changes: 3 additions & 3 deletions clang/lib/CIR/CodeGen/TargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ class TargetCIRGenInfo {
mlir::Type DestTy,
bool IsNonNull = false) const;

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

virtual ~TargetCIRGenInfo() {}
Expand Down
Loading