Skip to content

Commit 24c5053

Browse files
Lancernlanza
authored andcommitted
[CIR][NFC] Add unimplemented feature guard for dialect code (llvm#481)
As discussed in pull llvm#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.
1 parent b9dcfba commit 24c5053

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

clang/lib/CIR/Dialect/IR/CIRTypes.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "MissingFeatures.h"
14+
1315
#include "clang/CIR/Dialect/IR/CIRTypes.h"
1416
#include "clang/CIR/Dialect/IR/CIRAttrs.h"
1517
#include "clang/CIR/Dialect/IR/CIRDialect.h"
@@ -32,6 +34,8 @@
3234
#include "llvm/Support/ErrorHandling.h"
3335
#include <optional>
3436

37+
using cir::MissingFeatures;
38+
3539
//===----------------------------------------------------------------------===//
3640
// CIR Custom Parser/Printer Signatures
3741
//===----------------------------------------------------------------------===//
@@ -408,20 +412,23 @@ llvm::TypeSize
408412
DataMemberType::getTypeSizeInBits(const ::mlir::DataLayout &dataLayout,
409413
::mlir::DataLayoutEntryListRef params) const {
410414
// FIXME: consider size differences under different ABIs
415+
assert(!MissingFeatures::cxxABI());
411416
return llvm::TypeSize::getFixed(64);
412417
}
413418

414419
uint64_t
415420
DataMemberType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
416421
::mlir::DataLayoutEntryListRef params) const {
417422
// FIXME: consider alignment differences under different ABIs
423+
assert(!MissingFeatures::cxxABI());
418424
return 8;
419425
}
420426

421427
uint64_t DataMemberType::getPreferredAlignment(
422428
const ::mlir::DataLayout &dataLayout,
423429
::mlir::DataLayoutEntryListRef params) const {
424430
// FIXME: consider alignment differences under different ABIs
431+
assert(!MissingFeatures::cxxABI());
425432
return 8;
426433
}
427434

@@ -443,20 +450,20 @@ ArrayType::getPreferredAlignment(const ::mlir::DataLayout &dataLayout,
443450
return dataLayout.getTypePreferredAlignment(getEltType());
444451
}
445452

446-
llvm::TypeSize cir::VectorType::getTypeSizeInBits(
453+
llvm::TypeSize mlir::cir::VectorType::getTypeSizeInBits(
447454
const ::mlir::DataLayout &dataLayout,
448455
::mlir::DataLayoutEntryListRef params) const {
449456
return llvm::TypeSize::getFixed(getSize() *
450457
dataLayout.getTypeSizeInBits(getEltType()));
451458
}
452459

453-
uint64_t
454-
cir::VectorType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
455-
::mlir::DataLayoutEntryListRef params) const {
460+
uint64_t mlir::cir::VectorType::getABIAlignment(
461+
const ::mlir::DataLayout &dataLayout,
462+
::mlir::DataLayoutEntryListRef params) const {
456463
return getSize() * dataLayout.getTypeABIAlignment(getEltType());
457464
}
458465

459-
uint64_t cir::VectorType::getPreferredAlignment(
466+
uint64_t mlir::cir::VectorType::getPreferredAlignment(
460467
const ::mlir::DataLayout &dataLayout,
461468
::mlir::DataLayoutEntryListRef params) const {
462469
return getSize() * dataLayout.getTypePreferredAlignment(getEltType());
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===---- UnimplementedFeatureGuarding.h - Checks against NYI ---*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file introduces some helper classes to guard against features that
10+
// CIR dialect supports that we do not have and also do not have great ways to
11+
// assert against.
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
#ifndef LLVM_CLANG_LIB_CIR_DIALECT_IR_UFG
16+
#define LLVM_CLANG_LIB_CIR_DIALECT_IR_UFG
17+
18+
namespace cir {
19+
20+
struct MissingFeatures {
21+
// C++ ABI support
22+
static bool cxxABI() { return false; }
23+
};
24+
25+
} // namespace cir
26+
27+
#endif // LLVM_CLANG_LIB_CIR_DIALECT_IR_UFG

0 commit comments

Comments
 (0)