Skip to content

Commit 8f9c95e

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 78f1d8a commit 8f9c95e

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
//===----------------------------------------------------------------------===//
@@ -407,20 +411,23 @@ llvm::TypeSize
407411
DataMemberType::getTypeSizeInBits(const ::mlir::DataLayout &dataLayout,
408412
::mlir::DataLayoutEntryListRef params) const {
409413
// FIXME: consider size differences under different ABIs
414+
assert(!MissingFeatures::cxxABI());
410415
return llvm::TypeSize::getFixed(64);
411416
}
412417

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

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

@@ -442,20 +449,20 @@ ArrayType::getPreferredAlignment(const ::mlir::DataLayout &dataLayout,
442449
return dataLayout.getTypePreferredAlignment(getEltType());
443450
}
444451

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

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

458-
uint64_t cir::VectorType::getPreferredAlignment(
465+
uint64_t mlir::cir::VectorType::getPreferredAlignment(
459466
const ::mlir::DataLayout &dataLayout,
460467
::mlir::DataLayoutEntryListRef params) const {
461468
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)