From 74fa75fc2282d49282cfded7332cefac00a8b02a Mon Sep 17 00:00:00 2001 From: Sirui Mu Date: Fri, 1 Mar 2024 07:50:37 +0800 Subject: [PATCH] [CIR][NFC] Add unimplemented feature guard for dialect code (#481) As discussed in pull #401 , The present `UnimplementedFeature` class is made for the CIRGen submodule and we need similar facilities for code under `clang/lib/CIR/Dialect/IR`. This NFC patch adds a new `CIRDialectUnimplementedFeature` class that provides unimplemented feature guards for CIR dialect code. --- clang/lib/CIR/Dialect/IR/CIRTypes.cpp | 17 ++++++++++---- clang/lib/CIR/Dialect/IR/MissingFeatures.h | 27 ++++++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 clang/lib/CIR/Dialect/IR/MissingFeatures.h diff --git a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp index 34409841d637..48af4509890b 100644 --- a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp @@ -10,6 +10,8 @@ // //===----------------------------------------------------------------------===// +#include "MissingFeatures.h" + #include "clang/CIR/Dialect/IR/CIRTypes.h" #include "clang/CIR/Dialect/IR/CIRAttrs.h" #include "clang/CIR/Dialect/IR/CIRDialect.h" @@ -32,6 +34,8 @@ #include "llvm/Support/ErrorHandling.h" #include +using cir::MissingFeatures; + //===----------------------------------------------------------------------===// // CIR Custom Parser/Printer Signatures //===----------------------------------------------------------------------===// @@ -408,6 +412,7 @@ llvm::TypeSize DataMemberType::getTypeSizeInBits(const ::mlir::DataLayout &dataLayout, ::mlir::DataLayoutEntryListRef params) const { // FIXME: consider size differences under different ABIs + assert(!MissingFeatures::cxxABI()); return llvm::TypeSize::getFixed(64); } @@ -415,6 +420,7 @@ uint64_t DataMemberType::getABIAlignment(const ::mlir::DataLayout &dataLayout, ::mlir::DataLayoutEntryListRef params) const { // FIXME: consider alignment differences under different ABIs + assert(!MissingFeatures::cxxABI()); return 8; } @@ -422,6 +428,7 @@ uint64_t DataMemberType::getPreferredAlignment( const ::mlir::DataLayout &dataLayout, ::mlir::DataLayoutEntryListRef params) const { // FIXME: consider alignment differences under different ABIs + assert(!MissingFeatures::cxxABI()); return 8; } @@ -443,20 +450,20 @@ ArrayType::getPreferredAlignment(const ::mlir::DataLayout &dataLayout, return dataLayout.getTypePreferredAlignment(getEltType()); } -llvm::TypeSize cir::VectorType::getTypeSizeInBits( +llvm::TypeSize mlir::cir::VectorType::getTypeSizeInBits( const ::mlir::DataLayout &dataLayout, ::mlir::DataLayoutEntryListRef params) const { return llvm::TypeSize::getFixed(getSize() * dataLayout.getTypeSizeInBits(getEltType())); } -uint64_t -cir::VectorType::getABIAlignment(const ::mlir::DataLayout &dataLayout, - ::mlir::DataLayoutEntryListRef params) const { +uint64_t mlir::cir::VectorType::getABIAlignment( + const ::mlir::DataLayout &dataLayout, + ::mlir::DataLayoutEntryListRef params) const { return getSize() * dataLayout.getTypeABIAlignment(getEltType()); } -uint64_t cir::VectorType::getPreferredAlignment( +uint64_t mlir::cir::VectorType::getPreferredAlignment( const ::mlir::DataLayout &dataLayout, ::mlir::DataLayoutEntryListRef params) const { return getSize() * dataLayout.getTypePreferredAlignment(getEltType()); diff --git a/clang/lib/CIR/Dialect/IR/MissingFeatures.h b/clang/lib/CIR/Dialect/IR/MissingFeatures.h new file mode 100644 index 000000000000..d8271533cd98 --- /dev/null +++ b/clang/lib/CIR/Dialect/IR/MissingFeatures.h @@ -0,0 +1,27 @@ +//===---- UnimplementedFeatureGuarding.h - Checks against NYI ---*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// +// +// This file introduces some helper classes to guard against features that +// CIR dialect supports that we do not have and also do not have great ways to +// assert against. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_LIB_CIR_DIALECT_IR_UFG +#define LLVM_CLANG_LIB_CIR_DIALECT_IR_UFG + +namespace cir { + +struct MissingFeatures { + // C++ ABI support + static bool cxxABI() { return false; } +}; + +} // namespace cir + +#endif // LLVM_CLANG_LIB_CIR_DIALECT_IR_UFG