Skip to content

Commit 8f699fd

Browse files
bcardosolopeslanza
authored andcommitted
Revert "[CIR][ABI] Apply CC lowering pass by default (#842)"
Fix #895 and it's also missing some more throughout behavior for the pass, it also needs to be enabled by default when emitting object files. This reverts commit db6b7c0.
1 parent cefe6f3 commit 8f699fd

32 files changed

+197
-282
lines changed

clang/include/clang/CIR/Dialect/Passes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ std::unique_ptr<Pass> createGotoSolverPass();
4242
/// Create a pass to lower ABI-independent function definitions/calls.
4343
std::unique_ptr<Pass> createCallConvLoweringPass();
4444

45-
void populateCIRPreLoweringPasses(mlir::OpPassManager &pm, bool useCCLowering);
45+
void populateCIRPreLoweringPasses(mlir::OpPassManager &pm);
4646

4747
//===----------------------------------------------------------------------===//
4848
// Registration

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,6 @@
1515
#ifndef CLANG_CIR_MISSINGFEATURES_H
1616
#define CLANG_CIR_MISSINGFEATURES_H
1717

18-
constexpr bool cirMissingFeatureAssertionMode =
19-
true; // Change to `false` to use llvm_unreachable
20-
21-
#define NOTE \
22-
" Target lowering is now required. Disable it with " \
23-
"-fno-clangir-call-conv-lowering."
24-
25-
// Special assertion to be used in the target lowering library.
26-
#define cir_tl_assert(cond) assert((cond) && NOTE);
27-
28-
// Some assertions knowingly generate incorrect code. This macro allows us to
29-
// switch between using `assert` and `llvm_unreachable` for these cases.
30-
#define cir_assert_or_abort(cond, msg) \
31-
do { \
32-
if (cirMissingFeatureAssertionMode) { \
33-
assert((cond) && msg NOTE); \
34-
} else { \
35-
llvm_unreachable(msg NOTE); \
36-
} \
37-
} while (0)
38-
3918
namespace cir {
4019

4120
struct MissingFeatures {
@@ -233,26 +212,6 @@ struct MissingFeatures {
233212

234213
//===--- ABI lowering --===//
235214

236-
static bool SPIRVABI() { return false; }
237-
238-
static bool AArch64TypeClassification() { return false; }
239-
240-
static bool X86ArgTypeClassification() { return false; }
241-
static bool X86DefaultABITypeConvertion() { return false; }
242-
static bool X86GetFPTypeAtOffset() { return false; }
243-
static bool X86RetTypeClassification() { return false; }
244-
static bool X86TypeClassification() { return false; }
245-
246-
static bool ABIClangTypeKind() { return false; }
247-
static bool ABIEnterStructForCoercedAccess() { return false; }
248-
static bool ABIFuncPtr() { return false; }
249-
static bool ABIInRegAttribute() { return false; }
250-
static bool ABINestedRecordLayout() { return false; }
251-
static bool ABINoProtoFunctions() { return false; }
252-
static bool ABIParameterCoercion() { return false; }
253-
static bool ABIPointerParameterAttrs() { return false; }
254-
static bool ABITransparentUnionHandling() { return false; }
255-
256215
//-- Missing AST queries
257216

258217
static bool CXXRecordDeclIsEmptyCXX11() { return false; }

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3012,6 +3012,10 @@ def fclangir_lib_opt : Flag<["-"], "fclangir-lib-opt">,
30123012
Visibility<[ClangOption, CC1Option]>, Group<f_Group>,
30133013
Alias<fclangir_lib_opt_EQ>,
30143014
HelpText<"Enable C/C++ library based optimizations">;
3015+
def fclangir_call_conv_lowering : Flag<["-"], "fclangir-call-conv-lowering">,
3016+
Visibility<[ClangOption, CC1Option]>, Group<f_Group>,
3017+
HelpText<"Enable ClangIR calling convention lowering">,
3018+
MarshallingInfoFlag<FrontendOpts<"ClangIREnableCallConvLowering">>;
30153019
def fclangir_mem2reg : Flag<["-"], "fclangir-mem2reg">,
30163020
Visibility<[ClangOption, CC1Option]>, Group<f_Group>,
30173021
HelpText<"Enable mem2reg on the flat ClangIR">,
@@ -3042,13 +3046,6 @@ defm clangir_analysis_only : BoolFOption<"clangir-analysis-only",
30423046
PosFlag<SetTrue, [], [ClangOption, CC1Option],
30433047
"Enable CIR analysis but keep traditional LLVM codegen (not through CIR)">,
30443048
NegFlag<SetFalse, [], [ClangOption, CC1Option], "">>;
3045-
// FIXME(cir): Remove this option once all pre-existing tests are compatible with
3046-
// the calling convention lowering pass.
3047-
defm clangir_call_conv_lowering : BoolFOption<"clangir-call-conv-lowering",
3048-
FrontendOpts<"ClangIRCallConvLowering">, DefaultTrue,
3049-
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Transform CIR to abide to calling convetions during lowering">,
3050-
NegFlag<SetFalse, [], [ClangOption, CC1Option], "Ignore calling convetion during lowering">,
3051-
BothFlags<[], [ClangOption, CC1Option], "">>;
30523049

30533050
def emit_cir : Flag<["-"], "emit-cir">, Visibility<[CC1Option]>,
30543051
Group<Action_Group>, HelpText<"Build ASTs and then lower to ClangIR, emit the .cir file">;

clang/include/clang/Frontend/FrontendOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ class FrontendOptions {
449449
unsigned ClangIRLibOpt : 1;
450450

451451
// Enable Clang IR call conv lowering pass.
452-
unsigned ClangIRCallConvLowering : 1;
452+
unsigned ClangIREnableCallConvLowering : 1;
453453

454454
// Enable Clang IR mem2reg pass on the flat CIR.
455455
unsigned ClangIREnableMem2Reg : 1;

clang/lib/CIR/CodeGen/CIRPasses.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,13 @@ mlir::LogicalResult runCIRToCIRPasses(
7171

7272
pm.addPass(mlir::createLoweringPreparePass(&astCtx));
7373

74+
// FIXME(cir): This pass should run by default, but it is lacking support for
75+
// several code bits. Once it's more mature, we should fix this.
76+
if (enableCallConvLowering)
77+
pm.addPass(mlir::createCallConvLoweringPass());
78+
7479
if (flattenCIR || enableMem2Reg)
75-
mlir::populateCIRPreLoweringPasses(pm, enableCallConvLowering);
80+
mlir::populateCIRPreLoweringPasses(pm);
7681

7782
if (enableMem2Reg)
7883
pm.addPass(mlir::createMem2Reg());
@@ -92,9 +97,7 @@ mlir::LogicalResult runCIRToCIRPasses(
9297

9398
namespace mlir {
9499

95-
void populateCIRPreLoweringPasses(OpPassManager &pm, bool useCCLowering) {
96-
if (useCCLowering)
97-
pm.addPass(createCallConvLoweringPass());
100+
void populateCIRPreLoweringPasses(OpPassManager &pm) {
98101
pm.addPass(createFlattenCFGPass());
99102
pm.addPass(createGotoSolverPass());
100103
}

clang/lib/CIR/Dialect/Transforms/CallConvLowering.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
910
#include "TargetLowering/LowerModule.h"
1011
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
1112
#include "mlir/IR/BuiltinOps.h"
1213
#include "mlir/IR/PatternMatch.h"
1314
#include "mlir/Pass/Pass.h"
1415
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
1516
#include "clang/CIR/Dialect/IR/CIRDialect.h"
16-
#include "clang/CIR/MissingFeatures.h"
1717

1818
#define GEN_PASS_DEF_CALLCONVLOWERING
1919
#include "clang/CIR/Dialect/Passes.h.inc"
@@ -44,12 +44,6 @@ struct CallConvLoweringPattern : public OpRewritePattern<FuncOp> {
4444
auto calls = op.getSymbolUses(module);
4545
if (calls.has_value()) {
4646
for (auto call : calls.value()) {
47-
// FIXME(cir): Function pointers are ignored.
48-
if (isa<GetGlobalOp>(call.getUser())) {
49-
cir_assert_or_abort(!::cir::MissingFeatures::ABIFuncPtr(), "NYI");
50-
continue;
51-
}
52-
5347
auto callOp = cast<CallOp>(call.getUser());
5448
if (lowerModule->rewriteFunctionCall(callOp, op).failed())
5549
return failure();

clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ bool ABIInfo::isPromotableIntegerTypeForABI(Type Ty) const {
3737
if (getContext().isPromotableIntegerType(Ty))
3838
return true;
3939

40-
cir_tl_assert(!::cir::MissingFeatures::fixedWidthIntegers());
40+
assert(!::cir::MissingFeatures::fixedWidthIntegers());
4141

4242
return false;
4343
}

clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfoImpl.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,21 @@ bool classifyReturnType(const CIRCXXABI &CXXABI, LowerFunctionInfo &FI,
2626
Type Ty = FI.getReturnType();
2727

2828
if (const auto RT = dyn_cast<StructType>(Ty)) {
29-
cir_tl_assert(!::cir::MissingFeatures::isCXXRecordDecl());
29+
assert(!::cir::MissingFeatures::isCXXRecordDecl());
3030
}
3131

3232
return CXXABI.classifyReturnType(FI);
3333
}
3434

3535
bool isAggregateTypeForABI(Type T) {
36-
cir_tl_assert(!::cir::MissingFeatures::functionMemberPointerType());
36+
assert(!::cir::MissingFeatures::functionMemberPointerType());
3737
return !LowerFunction::hasScalarEvaluationKind(T);
3838
}
3939

4040
Type useFirstFieldIfTransparentUnion(Type Ty) {
4141
if (auto RT = dyn_cast<StructType>(Ty)) {
4242
if (RT.isUnion())
43-
cir_assert_or_abort(
44-
!::cir::MissingFeatures::ABITransparentUnionHandling(), "NYI");
43+
llvm_unreachable("NYI");
4544
}
4645
return Ty;
4746
}

clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRLowerContext.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ clang::TypeInfo CIRLowerContext::getTypeInfoImpl(const Type T) const {
5555
} else if (isa<StructType>(T)) {
5656
typeKind = clang::Type::Record;
5757
} else {
58-
cir_assert_or_abort(!::cir::MissingFeatures::ABIClangTypeKind(),
59-
"Unhandled type class");
60-
// FIXME(cir): Completely wrong. Just here to make it non-blocking.
61-
typeKind = clang::Type::Builtin;
58+
llvm_unreachable("Unhandled type class");
6259
}
6360

6461
// FIXME(cir): Here we fetch the width and alignment of a type considering the
@@ -99,10 +96,10 @@ clang::TypeInfo CIRLowerContext::getTypeInfoImpl(const Type T) const {
9996
}
10097
case clang::Type::Record: {
10198
const auto RT = dyn_cast<StructType>(T);
102-
cir_tl_assert(!::cir::MissingFeatures::tagTypeClassAbstraction());
99+
assert(!::cir::MissingFeatures::tagTypeClassAbstraction());
103100

104101
// Only handle TagTypes (names types) for now.
105-
cir_tl_assert(RT.getName() && "Anonymous record is NYI");
102+
assert(RT.getName() && "Anonymous record is NYI");
106103

107104
// NOTE(cir): Clang does some hanlding of invalid tagged declarations here.
108105
// Not sure if this is necessary in CIR.
@@ -114,22 +111,22 @@ clang::TypeInfo CIRLowerContext::getTypeInfoImpl(const Type T) const {
114111
const CIRRecordLayout &Layout = getCIRRecordLayout(RT);
115112
Width = toBits(Layout.getSize());
116113
Align = toBits(Layout.getAlignment());
117-
cir_tl_assert(!::cir::MissingFeatures::recordDeclHasAlignmentAttr());
114+
assert(!::cir::MissingFeatures::recordDeclHasAlignmentAttr());
118115
break;
119116
}
120117
default:
121118
llvm_unreachable("Unhandled type class");
122119
}
123120

124-
cir_tl_assert(llvm::isPowerOf2_32(Align) && "Alignment must be power of 2");
121+
assert(llvm::isPowerOf2_32(Align) && "Alignment must be power of 2");
125122
return clang::TypeInfo(Width, Align, AlignRequirement);
126123
}
127124

128125
Type CIRLowerContext::initBuiltinType(clang::BuiltinType::Kind K) {
129126
Type Ty;
130127

131128
// NOTE(cir): Clang does more stuff here. Not sure if we need to do the same.
132-
cir_tl_assert(!::cir::MissingFeatures::qualifiedTypes());
129+
assert(!::cir::MissingFeatures::qualifiedTypes());
133130
switch (K) {
134131
case clang::BuiltinType::Char_S:
135132
Ty = IntType::get(getMLIRContext(), 8, true);
@@ -144,7 +141,7 @@ Type CIRLowerContext::initBuiltinType(clang::BuiltinType::Kind K) {
144141

145142
void CIRLowerContext::initBuiltinTypes(const clang::TargetInfo &Target,
146143
const clang::TargetInfo *AuxTarget) {
147-
cir_tl_assert((!this->Target || this->Target == &Target) &&
144+
assert((!this->Target || this->Target == &Target) &&
148145
"Incorrect target reinitialization");
149146
this->Target = &Target;
150147
this->AuxTarget = AuxTarget;

clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRRecordLayout.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ CIRRecordLayout::CIRRecordLayout(
3838
FieldOffsets.insert(FieldOffsets.end(), fieldoffsets.begin(),
3939
fieldoffsets.end());
4040

41-
cir_tl_assert(!PrimaryBase && "Layout for class with inheritance is NYI");
41+
assert(!PrimaryBase && "Layout for class with inheritance is NYI");
4242
// CXXInfo->PrimaryBase.setPointer(PrimaryBase);
43-
cir_tl_assert(!IsPrimaryBaseVirtual && "Layout for virtual base class is NYI");
43+
assert(!IsPrimaryBaseVirtual && "Layout for virtual base class is NYI");
4444
// CXXInfo->PrimaryBase.setInt(IsPrimaryBaseVirtual);
4545
CXXInfo->NonVirtualSize = nonvirtualsize;
4646
CXXInfo->NonVirtualAlignment = nonvirtualalignment;
4747
CXXInfo->PreferredNVAlignment = preferrednvalignment;
4848
CXXInfo->SizeOfLargestEmptySubobject = SizeOfLargestEmptySubobject;
4949
// FIXME(cir): Initialize base classes offsets.
50-
cir_tl_assert(!::cir::MissingFeatures::getCXXRecordBases());
50+
assert(!::cir::MissingFeatures::getCXXRecordBases());
5151
CXXInfo->HasOwnVFPtr = hasOwnVFPtr;
5252
CXXInfo->VBPtrOffset = vbptroffset;
5353
CXXInfo->HasExtendableVFPtr = hasExtendableVFPtr;

0 commit comments

Comments
 (0)