Skip to content

Commit

Permalink
[CIR][NFC] Add unimplemented feature guard for dialect code (#481)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Lancern authored Feb 29, 2024
1 parent 0853a01 commit 74fa75f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
17 changes: 12 additions & 5 deletions clang/lib/CIR/Dialect/IR/CIRTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -32,6 +34,8 @@
#include "llvm/Support/ErrorHandling.h"
#include <optional>

using cir::MissingFeatures;

//===----------------------------------------------------------------------===//
// CIR Custom Parser/Printer Signatures
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -408,20 +412,23 @@ 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);
}

uint64_t
DataMemberType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
::mlir::DataLayoutEntryListRef params) const {
// FIXME: consider alignment differences under different ABIs
assert(!MissingFeatures::cxxABI());
return 8;
}

uint64_t DataMemberType::getPreferredAlignment(
const ::mlir::DataLayout &dataLayout,
::mlir::DataLayoutEntryListRef params) const {
// FIXME: consider alignment differences under different ABIs
assert(!MissingFeatures::cxxABI());
return 8;
}

Expand All @@ -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());
Expand Down
27 changes: 27 additions & 0 deletions clang/lib/CIR/Dialect/IR/MissingFeatures.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 74fa75f

Please sign in to comment.