Skip to content

Commit 8311717

Browse files
committed
[CIR][NFC] Massively rename workarounds for callconv lowering
These are not meant to be used by any other component, make sure it's very specific.
1 parent a6c3949 commit 8311717

20 files changed

+382
-373
lines changed

clang/include/clang/CIR/MissingFeatures.h

+11-11
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,37 @@
1717

1818
#include <llvm/Support/raw_ostream.h>
1919

20-
constexpr bool cirMissingFeatureAssertionMode =
20+
constexpr bool cirCConvAssertionMode =
2121
true; // Change to `false` to use llvm_unreachable
2222

23-
#define NOTE \
23+
#define CIR_CCONV_NOTE \
2424
" Target lowering is now required. To workaround use " \
2525
"-fno-clangir-call-conv-lowering. This flag is going to be removed at some" \
2626
" point."
2727

2828
// Special assertion to be used in the target lowering library.
29-
#define cir_tl_assert(cond) \
29+
#define cir_cconv_assert(cond) \
3030
do { \
3131
if (!(cond)) \
32-
llvm::errs() << NOTE << "\n"; \
32+
llvm::errs() << CIR_CCONV_NOTE << "\n"; \
3333
assert((cond)); \
3434
} while (0)
3535

36-
// Special version of cir_unreachable to give more info to the user on how
36+
// Special version of cir_cconv_unreachable to give more info to the user on how
3737
// to temporaruly disable target lowering.
38-
#define cir_unreachable(msg) \
38+
#define cir_cconv_unreachable(msg) \
3939
do { \
40-
llvm_unreachable(msg NOTE); \
40+
llvm_unreachable(msg CIR_CCONV_NOTE); \
4141
} while (0)
4242

4343
// Some assertions knowingly generate incorrect code. This macro allows us to
4444
// switch between using `assert` and `llvm_unreachable` for these cases.
45-
#define cir_assert_or_abort(cond, msg) \
45+
#define cir_cconv_assert_or_abort(cond, msg) \
4646
do { \
47-
if (cirMissingFeatureAssertionMode) { \
48-
assert((cond) && msg NOTE); \
47+
if (cirCConvAssertionMode) { \
48+
assert((cond) && msg CIR_CCONV_NOTE); \
4949
} else { \
50-
llvm_unreachable(msg NOTE); \
50+
llvm_unreachable(msg CIR_CCONV_NOTE); \
5151
} \
5252
} while (0)
5353

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ struct CallConvLoweringPattern : public OpRewritePattern<FuncOp> {
4747
for (auto call : calls.value()) {
4848
// FIXME(cir): Function pointers are ignored.
4949
if (isa<GetGlobalOp>(call.getUser())) {
50-
cir_assert_or_abort(!::cir::MissingFeatures::ABIFuncPtr(), "NYI");
50+
cir_cconv_assert_or_abort(!::cir::MissingFeatures::ABIFuncPtr(),
51+
"NYI");
5152
continue;
5253
}
5354

5455
auto callOp = dyn_cast_or_null<CallOp>(call.getUser());
5556
if (!callOp)
56-
cir_unreachable("NYI empty callOp");
57+
cir_cconv_unreachable("NYI empty callOp");
5758
if (lowerModule->rewriteFunctionCall(callOp, op).failed())
5859
return failure();
5960
}

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

+1-1
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+
cir_cconv_assert(!::cir::MissingFeatures::fixedWidthIntegers());
4141

4242
return false;
4343
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,21 +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+
cir_cconv_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+
cir_cconv_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(
43+
cir_cconv_assert_or_abort(
4444
!::cir::MissingFeatures::ABITransparentUnionHandling(), "NYI");
4545
}
4646
return Ty;
@@ -49,7 +49,7 @@ Type useFirstFieldIfTransparentUnion(Type Ty) {
4949
CIRCXXABI::RecordArgABI getRecordArgABI(const StructType RT,
5050
CIRCXXABI &CXXABI) {
5151
if (::cir::MissingFeatures::typeIsCXXRecordDecl()) {
52-
cir_unreachable("NYI");
52+
cir_cconv_unreachable("NYI");
5353
}
5454
return CXXABI.getRecordArgABI(RT);
5555
}

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

+18-17
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ 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");
58+
cir_cconv_assert_or_abort(!::cir::MissingFeatures::ABIClangTypeKind(),
59+
"Unhandled type class");
6060
// FIXME(cir): Completely wrong. Just here to make it non-blocking.
6161
typeKind = clang::Type::Builtin;
6262
}
@@ -94,48 +94,49 @@ clang::TypeInfo CIRLowerContext::getTypeInfoImpl(const Type T) const {
9494
Align = Target->getDoubleAlign();
9595
break;
9696
}
97-
cir_unreachable("Unknown builtin type!");
97+
cir_cconv_unreachable("Unknown builtin type!");
9898
break;
9999
}
100100
case clang::Type::Record: {
101101
const auto RT = dyn_cast<StructType>(T);
102-
cir_tl_assert(!::cir::MissingFeatures::tagTypeClassAbstraction());
102+
cir_cconv_assert(!::cir::MissingFeatures::tagTypeClassAbstraction());
103103

104104
// Only handle TagTypes (names types) for now.
105-
cir_tl_assert(RT.getName() && "Anonymous record is NYI");
105+
cir_cconv_assert(RT.getName() && "Anonymous record is NYI");
106106

107107
// NOTE(cir): Clang does some hanlding of invalid tagged declarations here.
108108
// Not sure if this is necessary in CIR.
109109

110110
if (::cir::MissingFeatures::typeGetAsEnumType()) {
111-
cir_unreachable("NYI");
111+
cir_cconv_unreachable("NYI");
112112
}
113113

114114
const CIRRecordLayout &Layout = getCIRRecordLayout(RT);
115115
Width = toBits(Layout.getSize());
116116
Align = toBits(Layout.getAlignment());
117-
cir_tl_assert(!::cir::MissingFeatures::recordDeclHasAlignmentAttr());
117+
cir_cconv_assert(!::cir::MissingFeatures::recordDeclHasAlignmentAttr());
118118
break;
119119
}
120120
default:
121-
cir_unreachable("Unhandled type class");
121+
cir_cconv_unreachable("Unhandled type class");
122122
}
123123

124-
cir_tl_assert(llvm::isPowerOf2_32(Align) && "Alignment must be power of 2");
124+
cir_cconv_assert(llvm::isPowerOf2_32(Align) &&
125+
"Alignment must be power of 2");
125126
return clang::TypeInfo(Width, Align, AlignRequirement);
126127
}
127128

128129
Type CIRLowerContext::initBuiltinType(clang::BuiltinType::Kind K) {
129130
Type Ty;
130131

131132
// NOTE(cir): Clang does more stuff here. Not sure if we need to do the same.
132-
cir_tl_assert(!::cir::MissingFeatures::qualifiedTypes());
133+
cir_cconv_assert(!::cir::MissingFeatures::qualifiedTypes());
133134
switch (K) {
134135
case clang::BuiltinType::Char_S:
135136
Ty = IntType::get(getMLIRContext(), 8, true);
136137
break;
137138
default:
138-
cir_unreachable("NYI");
139+
cir_cconv_unreachable("NYI");
139140
}
140141

141142
Types.push_back(Ty);
@@ -144,16 +145,16 @@ Type CIRLowerContext::initBuiltinType(clang::BuiltinType::Kind K) {
144145

145146
void CIRLowerContext::initBuiltinTypes(const clang::TargetInfo &Target,
146147
const clang::TargetInfo *AuxTarget) {
147-
cir_tl_assert((!this->Target || this->Target == &Target) &&
148-
"Incorrect target reinitialization");
148+
cir_cconv_assert((!this->Target || this->Target == &Target) &&
149+
"Incorrect target reinitialization");
149150
this->Target = &Target;
150151
this->AuxTarget = AuxTarget;
151152

152153
// C99 6.2.5p3.
153154
if (LangOpts.CharIsSigned)
154155
CharTy = initBuiltinType(clang::BuiltinType::Char_S);
155156
else
156-
cir_unreachable("NYI");
157+
cir_cconv_unreachable("NYI");
157158
}
158159

159160
/// Convert a size in bits to a size in characters.
@@ -168,7 +169,7 @@ int64_t CIRLowerContext::toBits(clang::CharUnits CharSize) const {
168169

169170
clang::TypeInfoChars CIRLowerContext::getTypeInfoInChars(Type T) const {
170171
if (auto arrTy = dyn_cast<ArrayType>(T))
171-
cir_unreachable("NYI");
172+
cir_cconv_unreachable("NYI");
172173
clang::TypeInfo Info = getTypeInfo(T);
173174
return clang::TypeInfoChars(toCharUnitsFromBits(Info.Width),
174175
toCharUnitsFromBits(Info.Align),
@@ -179,7 +180,7 @@ bool CIRLowerContext::isPromotableIntegerType(Type T) const {
179180
// HLSL doesn't promote all small integer types to int, it
180181
// just uses the rank-based promotion rules for all types.
181182
if (::cir::MissingFeatures::langOpts())
182-
cir_unreachable("NYI");
183+
cir_cconv_unreachable("NYI");
183184

184185
// FIXME(cir): CIR does not distinguish between char, short, etc. So we just
185186
// assume it is promotable if smaller than 32 bits. This is wrong since, for
@@ -198,7 +199,7 @@ bool CIRLowerContext::isPromotableIntegerType(Type T) const {
198199
// TODO(cir): CIR doesn't know if a integer originated from an enum. Improve
199200
// CIR or add an AST query here.
200201
if (::cir::MissingFeatures::typeGetAsEnumType()) {
201-
cir_unreachable("NYI");
202+
cir_cconv_unreachable("NYI");
202203
}
203204

204205
return false;

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ 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+
cir_cconv_assert(!PrimaryBase && "Layout for class with inheritance is NYI");
4242
// CXXInfo->PrimaryBase.setPointer(PrimaryBase);
43-
cir_tl_assert(!IsPrimaryBaseVirtual &&
44-
"Layout for virtual base class is NYI");
43+
cir_cconv_assert(!IsPrimaryBaseVirtual &&
44+
"Layout for virtual base class is NYI");
4545
// CXXInfo->PrimaryBase.setInt(IsPrimaryBaseVirtual);
4646
CXXInfo->NonVirtualSize = nonvirtualsize;
4747
CXXInfo->NonVirtualAlignment = nonvirtualalignment;
4848
CXXInfo->PreferredNVAlignment = preferrednvalignment;
4949
CXXInfo->SizeOfLargestEmptySubobject = SizeOfLargestEmptySubobject;
5050
// FIXME(cir): Initialize base classes offsets.
51-
cir_tl_assert(!::cir::MissingFeatures::getCXXRecordBases());
51+
cir_cconv_assert(!::cir::MissingFeatures::getCXXRecordBases());
5252
CXXInfo->HasOwnVFPtr = hasOwnVFPtr;
5353
CXXInfo->VBPtrOffset = vbptroffset;
5454
CXXInfo->HasExtendableVFPtr = hasExtendableVFPtr;

clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRToCIRArgMapping.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class CIRToCIRArgMapping {
5858
unsigned totalIRArgs() const { return TotalIRArgs; }
5959

6060
bool hasPaddingArg(unsigned ArgNo) const {
61-
cir_tl_assert(ArgNo < ArgInfo.size());
61+
cir_cconv_assert(ArgNo < ArgInfo.size());
6262
return ArgInfo[ArgNo].PaddingArgIndex != InvalidIndex;
6363
}
6464

@@ -69,39 +69,39 @@ class CIRToCIRArgMapping {
6969
const ::cir::ABIArgInfo &RetAI = FI.getReturnInfo();
7070

7171
if (RetAI.getKind() == ::cir::ABIArgInfo::Indirect) {
72-
cir_unreachable("NYI");
72+
cir_cconv_unreachable("NYI");
7373
}
7474

7575
unsigned ArgNo = 0;
7676
unsigned NumArgs =
7777
onlyRequiredArgs ? FI.getNumRequiredArgs() : FI.arg_size();
7878
for (LowerFunctionInfo::const_arg_iterator I = FI.arg_begin();
7979
ArgNo < NumArgs; ++I, ++ArgNo) {
80-
cir_tl_assert(I != FI.arg_end());
80+
cir_cconv_assert(I != FI.arg_end());
8181
// Type ArgType = I->type;
8282
const ::cir::ABIArgInfo &AI = I->info;
8383
// Collect data about IR arguments corresponding to Clang argument ArgNo.
8484
auto &IRArgs = ArgInfo[ArgNo];
8585

8686
if (::cir::MissingFeatures::argumentPadding()) {
87-
cir_unreachable("NYI");
87+
cir_cconv_unreachable("NYI");
8888
}
8989

9090
switch (AI.getKind()) {
9191
case ::cir::ABIArgInfo::Extend:
9292
case ::cir::ABIArgInfo::Direct: {
9393
// FIXME(cir): handle sseregparm someday...
94-
cir_tl_assert(AI.getCoerceToType() && "Missing coerced type!!");
94+
cir_cconv_assert(AI.getCoerceToType() && "Missing coerced type!!");
9595
StructType STy = dyn_cast<StructType>(AI.getCoerceToType());
9696
if (AI.isDirect() && AI.getCanBeFlattened() && STy) {
97-
cir_unreachable("NYI");
97+
cir_cconv_unreachable("NYI");
9898
} else {
9999
IRArgs.NumberOfArgs = 1;
100100
}
101101
break;
102102
}
103103
default:
104-
cir_unreachable("Missing ABIArgInfo::Kind");
104+
cir_cconv_unreachable("Missing ABIArgInfo::Kind");
105105
}
106106

107107
if (IRArgs.NumberOfArgs > 0) {
@@ -114,10 +114,10 @@ class CIRToCIRArgMapping {
114114
if (IRArgNo == 1 && SwapThisWithSRet)
115115
IRArgNo++;
116116
}
117-
cir_tl_assert(ArgNo == ArgInfo.size());
117+
cir_cconv_assert(ArgNo == ArgInfo.size());
118118

119119
if (::cir::MissingFeatures::inallocaArgs()) {
120-
cir_unreachable("NYI");
120+
cir_cconv_unreachable("NYI");
121121
}
122122

123123
TotalIRArgs = IRArgNo;
@@ -126,7 +126,7 @@ class CIRToCIRArgMapping {
126126
/// Returns index of first IR argument corresponding to ArgNo, and their
127127
/// quantity.
128128
std::pair<unsigned, unsigned> getIRArgs(unsigned ArgNo) const {
129-
cir_tl_assert(ArgNo < ArgInfo.size());
129+
cir_cconv_assert(ArgNo < ArgInfo.size());
130130
return std::make_pair(ArgInfo[ArgNo].FirstArgIndex,
131131
ArgInfo[ArgNo].NumberOfArgs);
132132
}

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ class ItaniumCXXABI : public CIRCXXABI {
4646

4747
// FIXME(cir): This expects a CXXRecordDecl! Not any record type.
4848
RecordArgABI getRecordArgABI(const StructType RD) const override {
49-
cir_tl_assert(!::cir::MissingFeatures::recordDeclIsCXXDecl());
49+
cir_cconv_assert(!::cir::MissingFeatures::recordDeclIsCXXDecl());
5050
// If C++ prohibits us from making a copy, pass by address.
51-
cir_tl_assert(!::cir::MissingFeatures::recordDeclCanPassInRegisters());
51+
cir_cconv_assert(!::cir::MissingFeatures::recordDeclCanPassInRegisters());
5252
return RAA_Default;
5353
}
5454
};
@@ -62,7 +62,7 @@ bool ItaniumCXXABI::classifyReturnType(LowerFunctionInfo &FI) const {
6262

6363
// If C++ prohibits us from making a copy, return by address.
6464
if (::cir::MissingFeatures::recordDeclCanPassInRegisters())
65-
cir_unreachable("NYI");
65+
cir_cconv_unreachable("NYI");
6666

6767
return false;
6868
}
@@ -76,20 +76,20 @@ CIRCXXABI *CreateItaniumCXXABI(LowerModule &LM) {
7676
case clang::TargetCXXABI::AppleARM64:
7777
// TODO: this isn't quite right, clang uses AppleARM64CXXABI which inherits
7878
// from ARMCXXABI. We'll have to follow suit.
79-
cir_tl_assert(!::cir::MissingFeatures::appleArm64CXXABI());
79+
cir_cconv_assert(!::cir::MissingFeatures::appleArm64CXXABI());
8080
return new ItaniumCXXABI(LM, /*UseARMMethodPtrABI=*/true,
8181
/*UseARMGuardVarABI=*/true);
8282

8383
case clang::TargetCXXABI::GenericItanium:
8484
return new ItaniumCXXABI(LM);
8585

8686
case clang::TargetCXXABI::Microsoft:
87-
cir_unreachable("Microsoft ABI is not Itanium-based");
87+
cir_cconv_unreachable("Microsoft ABI is not Itanium-based");
8888
default:
89-
cir_unreachable("NYI");
89+
cir_cconv_unreachable("NYI");
9090
}
9191

92-
cir_unreachable("bad ABI kind");
92+
cir_cconv_unreachable("bad ABI kind");
9393
}
9494

9595
} // namespace cir

0 commit comments

Comments
 (0)