Skip to content

Commit c8ba55b

Browse files
authored
[CIR] Centralize feature guarding (#649)
Moves all feature guarding static methods into a to a single header file, centralizing the tracking of missing features in a common place regardless of where it impacts the compilation pipeline. It also moves the feature guarding logic into CIR's root include folder so that any CIR library may use it.
1 parent ce0e60e commit c8ba55b

36 files changed

+392
-426
lines changed

clang/lib/CIR/CodeGen/UnimplementedFeatureGuarding.h renamed to clang/include/clang/CIR/MissingFeatures.h

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===---- UnimplementedFeatureGuarding.h - Checks against NYI ---*- C++ -*-===//
1+
//===---- MissingFeatures.h - Checks for unimplemented features -*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -7,16 +7,17 @@
77
//===----------------------------------------------------------------------===//
88
//
99
// This file introduces some helper classes to guard against features that
10-
// CodeGen supports that we do not have and also do not have great ways to
10+
// CIR dialect supports that we do not have and also do not have great ways to
1111
// assert against.
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
#ifndef LLVM_CLANG_LIB_CIR_UFG
16-
#define LLVM_CLANG_LIB_CIR_UFG
15+
#ifndef CLANG_CIR_MISSINGFEATURES_H
16+
#define CLANG_CIR_MISSINGFEATURES_H
1717

1818
namespace cir {
19-
struct UnimplementedFeature {
19+
20+
struct MissingFeatures {
2021
// TODO(CIR): Implement the CIRGenFunction::buildTypeCheck method that handles
2122
// sanitizer related type check features
2223
static bool buildTypeCheck() { return false; }
@@ -169,12 +170,24 @@ struct UnimplementedFeature {
169170
static bool shouldInstrumentFunction() { return false; }
170171

171172
// Inline assembly
172-
static bool asm_goto() { return false; }
173-
static bool asm_unwind_clobber() { return false; }
174-
static bool asm_memory_effects() { return false; }
175-
static bool asm_vector_type() { return false; }
176-
static bool asm_llvm_assume() { return false; }
173+
static bool asmGoto() { return false; }
174+
static bool asmUnwindClobber() { return false; }
175+
static bool asmMemoryEffects() { return false; }
176+
static bool asmVectorType() { return false; }
177+
static bool asmLLVMAssume() { return false; }
178+
179+
// C++ ABI support
180+
static bool handleBigEndian() { return false; }
181+
static bool handleAArch64Indirect() { return false; }
182+
static bool classifyArgumentTypeForAArch64() { return false; }
183+
static bool supportgetCoerceToTypeForAArch64() { return false; }
184+
static bool supportTySizeQueryForAArch64() { return false; }
185+
static bool supportTyAlignQueryForAArch64() { return false; }
186+
static bool supportisHomogeneousAggregateQueryForAArch64() { return false; }
187+
static bool supportisEndianQueryForAArch64() { return false; }
188+
static bool supportisAggregateTypeForABIAArch64() { return false; }
177189
};
190+
178191
} // namespace cir
179192

180-
#endif
193+
#endif // CLANG_CIR_MISSINGFEATURES_H

clang/lib/CIR/CodeGen/CIRAsm.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "CIRGenFunction.h"
55
#include "TargetInfo.h"
6-
#include "UnimplementedFeatureGuarding.h"
6+
#include "clang/CIR/MissingFeatures.h"
77

88
using namespace cir;
99
using namespace clang;
@@ -285,7 +285,7 @@ static void buildAsmStores(CIRGenFunction &CGF, const AsmStmt &S,
285285
mlir::Type TruncTy = ResultTruncRegTypes[i];
286286

287287
if ((i < ResultRegIsFlagReg.size()) && ResultRegIsFlagReg[i]) {
288-
assert(!UnimplementedFeature::asm_llvm_assume());
288+
assert(!MissingFeatures::asmLLVMAssume());
289289
}
290290

291291
// If the result type of the LLVM IR asm doesn't match the result type of
@@ -311,7 +311,7 @@ static void buildAsmStores(CIRGenFunction &CGF, const AsmStmt &S,
311311
} else if (isa<mlir::cir::IntType>(TruncTy)) {
312312
Tmp = Builder.createIntCast(Tmp, TruncTy);
313313
} else if (false /*TruncTy->isVectorTy()*/) {
314-
assert(!UnimplementedFeature::asm_vector_type());
314+
assert(!MissingFeatures::asmVectorType());
315315
}
316316
}
317317

@@ -468,7 +468,7 @@ mlir::LogicalResult CIRGenFunction::buildAsmStmt(const AsmStmt &S) {
468468
}
469469

470470
// Update largest vector width for any vector types.
471-
assert(!UnimplementedFeature::asm_vector_type());
471+
assert(!MissingFeatures::asmVectorType());
472472
} else {
473473
Address DestAddr = Dest.getAddress();
474474

@@ -504,7 +504,7 @@ mlir::LogicalResult CIRGenFunction::buildAsmStmt(const AsmStmt &S) {
504504
Arg = builder.createBitcast(Arg, AdjTy);
505505

506506
// Update largest vector width for any vector types.
507-
assert(!UnimplementedFeature::asm_vector_type());
507+
assert(!MissingFeatures::asmVectorType());
508508

509509
// Only tie earlyclobber physregs.
510510
if (Info.allowsRegister() && (GCCReg.empty() || Info.earlyClobber()))
@@ -593,7 +593,7 @@ mlir::LogicalResult CIRGenFunction::buildAsmStmt(const AsmStmt &S) {
593593
<< InputExpr->getType() << InputConstraint;
594594

595595
// Update largest vector width for any vector types.
596-
assert(!UnimplementedFeature::asm_vector_type());
596+
assert(!MissingFeatures::asmVectorType());
597597

598598
ArgTypes.push_back(Arg.getType());
599599
ArgElemTypes.push_back(ArgElemType);
@@ -636,11 +636,11 @@ mlir::LogicalResult CIRGenFunction::buildAsmStmt(const AsmStmt &S) {
636636
HasSideEffect, inferFlavor(CGM, S), mlir::ArrayAttr());
637637

638638
if (false /*IsGCCAsmGoto*/) {
639-
assert(!UnimplementedFeature::asm_goto());
639+
assert(!MissingFeatures::asmGoto());
640640
} else if (HasUnwindClobber) {
641-
assert(!UnimplementedFeature::asm_unwind_clobber());
641+
assert(!MissingFeatures::asmUnwindClobber());
642642
} else {
643-
assert(!UnimplementedFeature::asm_memory_effects());
643+
assert(!MissingFeatures::asmMemoryEffects());
644644

645645
mlir::Value result;
646646
if (IA.getNumResults())

clang/lib/CIR/CodeGen/CIRGenAtomic.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
#include "CIRGenModule.h"
1717
#include "CIRGenOpenMPRuntime.h"
1818
#include "TargetInfo.h"
19-
#include "UnimplementedFeatureGuarding.h"
2019
#include "clang/AST/ASTContext.h"
2120
#include "clang/AST/StmtVisitor.h"
2221
#include "clang/CIR/Dialect/IR/CIRAttrs.h"
2322
#include "clang/CIR/Dialect/IR/CIRDataLayout.h"
2423
#include "clang/CIR/Dialect/IR/CIRDialect.h"
2524
#include "clang/CIR/Dialect/IR/CIROpsEnums.h"
2625
#include "clang/CIR/Dialect/IR/CIRTypes.h"
26+
#include "clang/CIR/MissingFeatures.h"
2727
#include "clang/CodeGen/CGFunctionInfo.h"
2828
#include "clang/Frontend/FrontendDiagnostic.h"
2929
#include "llvm/Support/ErrorHandling.h"
@@ -440,7 +440,7 @@ static void buildAtomicOp(CIRGenFunction &CGF, AtomicExpr *E, Address Dest,
440440
mlir::Value IsWeak, mlir::Value FailureOrder,
441441
uint64_t Size, mlir::cir::MemOrder Order,
442442
uint8_t Scope) {
443-
assert(!UnimplementedFeature::syncScopeID());
443+
assert(!MissingFeatures::syncScopeID());
444444
StringRef Op;
445445

446446
auto &builder = CGF.getBuilder();
@@ -487,7 +487,7 @@ static void buildAtomicOp(CIRGenFunction &CGF, AtomicExpr *E, Address Dest,
487487
case AtomicExpr::AO__scoped_atomic_load: {
488488
auto *load = builder.createLoad(loc, Ptr).getDefiningOp();
489489
// FIXME(cir): add scope information.
490-
assert(!UnimplementedFeature::syncScopeID());
490+
assert(!MissingFeatures::syncScopeID());
491491
load->setAttr("mem_order", orderAttr);
492492
if (E->isVolatile())
493493
load->setAttr("is_volatile", mlir::UnitAttr::get(builder.getContext()));
@@ -512,7 +512,7 @@ static void buildAtomicOp(CIRGenFunction &CGF, AtomicExpr *E, Address Dest,
512512
case AtomicExpr::AO__scoped_atomic_store_n: {
513513
auto loadVal1 = builder.createLoad(loc, Val1);
514514
// FIXME(cir): add scope information.
515-
assert(!UnimplementedFeature::syncScopeID());
515+
assert(!MissingFeatures::syncScopeID());
516516
builder.createStore(loc, loadVal1, Ptr, E->isVolatile(),
517517
/*alignment=*/mlir::IntegerAttr{}, orderAttr);
518518
return;
@@ -685,15 +685,15 @@ static void buildAtomicOp(CIRGenFunction &CGF, AtomicExpr *Expr, Address Dest,
685685
// LLVM atomic instructions always have synch scope. If clang atomic
686686
// expression has no scope operand, use default LLVM synch scope.
687687
if (!ScopeModel) {
688-
assert(!UnimplementedFeature::syncScopeID());
688+
assert(!MissingFeatures::syncScopeID());
689689
buildAtomicOp(CGF, Expr, Dest, Ptr, Val1, Val2, IsWeak, FailureOrder, Size,
690690
Order, /*FIXME(cir): LLVM default scope*/ 1);
691691
return;
692692
}
693693

694694
// Handle constant scope.
695695
if (getConstOpIntAttr(Scope)) {
696-
assert(!UnimplementedFeature::syncScopeID());
696+
assert(!MissingFeatures::syncScopeID());
697697
llvm_unreachable("NYI");
698698
return;
699699
}
@@ -1289,7 +1289,7 @@ void CIRGenFunction::buildAtomicStore(RValue rvalue, LValue dest,
12891289
store.setIsVolatile(true);
12901290

12911291
// DecorateInstructionWithTBAA
1292-
assert(!UnimplementedFeature::tbaa());
1292+
assert(!MissingFeatures::tbaa());
12931293
return;
12941294
}
12951295

clang/lib/CIR/CodeGen/CIRGenBuilder.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "Address.h"
1313
#include "CIRGenRecordLayout.h"
1414
#include "CIRGenTypeCache.h"
15-
#include "UnimplementedFeatureGuarding.h"
15+
#include "clang/CIR/MissingFeatures.h"
1616

1717
#include "clang/AST/Decl.h"
1818
#include "clang/AST/Type.h"
@@ -406,7 +406,7 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
406406
// FIXME: replay LLVM codegen for now, perhaps add a vtable ptr special
407407
// type so it's a bit more clear and C++ idiomatic.
408408
auto fnTy = mlir::cir::FuncType::get({}, getUInt32Ty(), isVarArg);
409-
assert(!UnimplementedFeature::isVarArg());
409+
assert(!MissingFeatures::isVarArg());
410410
return getPointerTo(getPointerTo(fnTy));
411411
}
412412

@@ -639,11 +639,11 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
639639
}
640640

641641
mlir::Value createFSub(mlir::Value lhs, mlir::Value rhs) {
642-
assert(!UnimplementedFeature::metaDataNode());
642+
assert(!MissingFeatures::metaDataNode());
643643
if (IsFPConstrained)
644644
llvm_unreachable("Constrained FP NYI");
645645

646-
assert(!UnimplementedFeature::foldBinOpFMF());
646+
assert(!MissingFeatures::foldBinOpFMF());
647647
return create<mlir::cir::BinOp>(lhs.getLoc(), mlir::cir::BinOpKind::Sub,
648648
lhs, rhs);
649649
}
@@ -660,7 +660,7 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
660660
mlir::Value createDynCastToVoid(mlir::Location loc, mlir::Value src,
661661
bool vtableUseRelativeLayout) {
662662
// TODO(cir): consider address space here.
663-
assert(!UnimplementedFeature::addressSpace());
663+
assert(!MissingFeatures::addressSpace());
664664
auto destTy = getVoidPtrTy();
665665
return create<mlir::cir::DynamicCastOp>(
666666
loc, destTy, mlir::cir::DynamicCastKind::ptr, src,
@@ -772,7 +772,7 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
772772
mlir::Value createAlignedLoad(mlir::Location loc, mlir::Type ty,
773773
mlir::Value ptr, llvm::MaybeAlign align) {
774774
// TODO: make sure callsites shouldn't be really passing volatile.
775-
assert(!UnimplementedFeature::volatileLoadOrStore());
775+
assert(!MissingFeatures::volatileLoadOrStore());
776776
return createAlignedLoad(loc, ty, ptr, align, /*isVolatile=*/false);
777777
}
778778

@@ -913,7 +913,7 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
913913
auto memberPtrTy = memberPtr.getType().cast<mlir::cir::DataMemberType>();
914914

915915
// TODO(cir): consider address space.
916-
assert(!UnimplementedFeature::addressSpace());
916+
assert(!MissingFeatures::addressSpace());
917917
auto resultTy = getPointerTo(memberPtrTy.getMemberTy());
918918

919919
return create<mlir::cir::GetRuntimeMemberOp>(loc, resultTy, objectPtr,

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "CIRGenFunction.h"
1717
#include "CIRGenModule.h"
1818
#include "TargetInfo.h"
19-
#include "UnimplementedFeatureGuarding.h"
19+
#include "clang/CIR/MissingFeatures.h"
2020

2121
// TODO(cir): we shouldn't need this but we currently reuse intrinsic IDs for
2222
// convenience.
@@ -717,7 +717,7 @@ RValue CIRGenFunction::buildBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
717717
}
718718
case Builtin::BI__builtin_unpredictable: {
719719
if (CGM.getCodeGenOpts().OptimizationLevel != 0)
720-
assert(!UnimplementedFeature::insertBuiltinUnpredictable());
720+
assert(!MissingFeatures::insertBuiltinUnpredictable());
721721
return RValue::get(buildScalarExpr(E->getArg(0)));
722722
}
723723

@@ -978,7 +978,7 @@ RValue CIRGenFunction::buildBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
978978
// default (e.g. in C / C++ auto vars are in the generic address space). At
979979
// the AST level this is handled within CreateTempAlloca et al., but for the
980980
// builtin / dynamic alloca we have to handle it here.
981-
assert(!UnimplementedFeature::addressSpace());
981+
assert(!MissingFeatures::addressSpace());
982982
LangAS AAS = getASTAllocaAddressSpace();
983983
LangAS EAS = E->getType()->getPointeeType().getAddressSpace();
984984
if (EAS != AAS) {
@@ -1233,7 +1233,7 @@ mlir::Value CIRGenFunction::buildCheckedArgForBuiltin(const Expr *E,
12331233
if (!SanOpts.has(SanitizerKind::Builtin))
12341234
return value;
12351235

1236-
assert(!UnimplementedFeature::sanitizerBuiltin());
1236+
assert(!MissingFeatures::sanitizerBuiltin());
12371237
llvm_unreachable("NYI");
12381238
}
12391239

clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "CIRGenFunction.h"
1717
#include "CIRGenModule.h"
1818
#include "TargetInfo.h"
19-
#include "UnimplementedFeatureGuarding.h"
19+
#include "clang/CIR/MissingFeatures.h"
2020

2121
// TODO(cir): once all builtins are covered, decide whether we still
2222
// need to use LLVM intrinsics or if there's a better approach to follow. Right

clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "CIRGenFunction.h"
1717
#include "CIRGenModule.h"
1818
#include "TargetInfo.h"
19-
#include "UnimplementedFeatureGuarding.h"
19+
#include "clang/CIR/MissingFeatures.h"
2020

2121
#include "mlir/Dialect/Func/IR/FuncOps.h"
2222
#include "mlir/IR/Value.h"

clang/lib/CIR/CodeGen/CIRGenCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ bool CIRGenModule::tryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D) {
3838
// an alias, unless this class owns no members.
3939
if (getCodeGenOpts().SanitizeMemoryUseAfterDtor &&
4040
!D->getParent()->field_empty())
41-
assert(!UnimplementedFeature::sanitizeDtor());
41+
assert(!MissingFeatures::sanitizeDtor());
4242

4343
// If the destructor doesn't have a trivial body, we have to emit it
4444
// separately.

clang/lib/CIR/CodeGen/CIRGenCall.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
#include "llvm/Support/ErrorHandling.h"
2727
#include <cassert>
2828

29-
#include "UnimplementedFeatureGuarding.h"
3029
#include "mlir/Dialect/Func/IR/FuncOps.h"
3130
#include "mlir/IR/Builders.h"
3231
#include "mlir/IR/BuiltinOps.h"
3332
#include "mlir/IR/BuiltinTypes.h"
3433
#include "mlir/IR/SymbolTable.h"
3534
#include "mlir/IR/Types.h"
35+
#include "clang/CIR/MissingFeatures.h"
3636

3737
using namespace cir;
3838
using namespace clang;
@@ -164,7 +164,7 @@ void ClangToCIRArgMapping::construct(const ASTContext &Context,
164164
//
165165
// TODO(cir): a LLVM lowering prepare pass should break this down into
166166
// the appropriated pieces.
167-
assert(!UnimplementedFeature::constructABIArgDirectExtend());
167+
assert(!MissingFeatures::constructABIArgDirectExtend());
168168
CIRArgs.NumberOfArgs = 1;
169169
break;
170170
}
@@ -428,12 +428,12 @@ void CIRGenModule::ConstructAttributeList(StringRef Name,
428428
}
429429

430430
if (TargetDecl->hasAttr<OpenCLKernelAttr>()) {
431-
assert(!UnimplementedFeature::openCL());
431+
assert(!MissingFeatures::openCL());
432432
}
433433

434434
if (TargetDecl->hasAttr<CUDAGlobalAttr>() &&
435435
getLangOpts().OffloadUniformBlock)
436-
assert(!UnimplementedFeature::CUDA());
436+
assert(!MissingFeatures::CUDA());
437437

438438
if (TargetDecl->hasAttr<ArmLocallyStreamingAttr>())
439439
;
@@ -503,7 +503,7 @@ RValue CIRGenFunction::buildCall(const CIRGenFunctionInfo &CallInfo,
503503

504504
// Some architectures (such as x86-64) have the ABI changed based on
505505
// attribute-target/features. Give them a chance to diagnose.
506-
assert(!UnimplementedFeature::checkFunctionCallABI());
506+
assert(!MissingFeatures::checkFunctionCallABI());
507507
}
508508

509509
// TODO: add DNEBUG code
@@ -526,7 +526,7 @@ RValue CIRGenFunction::buildCall(const CIRGenFunctionInfo &CallInfo,
526526
// When passing arguments using temporary allocas, we need to add the
527527
// appropriate lifetime markers. This vector keeps track of all the lifetime
528528
// markers that need to be ended right after the call.
529-
assert(!UnimplementedFeature::shouldEmitLifetimeMarkers() && "NYI");
529+
assert(!MissingFeatures::shouldEmitLifetimeMarkers() && "NYI");
530530

531531
// Translate all of the arguments as necessary to match the CIR lowering.
532532
assert(CallInfo.arg_size() == CallArgs.size() &&
@@ -841,7 +841,7 @@ mlir::Value CIRGenFunction::buildRuntimeCall(mlir::Location loc,
841841
mlir::cir::FuncOp callee,
842842
ArrayRef<mlir::Value> args) {
843843
// TODO(cir): set the calling convention to this runtime call.
844-
assert(!UnimplementedFeature::setCallingConv());
844+
assert(!MissingFeatures::setCallingConv());
845845

846846
auto call = builder.create<mlir::cir::CallOp>(loc, callee, args);
847847
assert(call->getNumResults() <= 1 &&
@@ -1324,7 +1324,7 @@ arrangeFreeFunctionLikeCall(CIRGenTypes &CGT, CIRGenModule &CGM,
13241324
addExtParameterInfosForCall(paramInfos, proto, numExtraRequiredArgs,
13251325
args.size());
13261326
} else if (llvm::isa<FunctionNoProtoType>(fnType)) {
1327-
assert(!UnimplementedFeature::targetCodeGenInfoIsProtoCallVariadic());
1327+
assert(!MissingFeatures::targetCodeGenInfoIsProtoCallVariadic());
13281328
required = RequiredArgs(args.size());
13291329
}
13301330

0 commit comments

Comments
 (0)