Skip to content

Commit

Permalink
[CIR][NFC] Massively rename workarounds for callconv lowering
Browse files Browse the repository at this point in the history
These are not meant to be used by any other component, make sure it's very
specific.
  • Loading branch information
bcardosolopes committed Oct 15, 2024
1 parent a6c3949 commit 8311717
Show file tree
Hide file tree
Showing 20 changed files with 382 additions and 373 deletions.
22 changes: 11 additions & 11 deletions clang/include/clang/CIR/MissingFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,37 @@

#include <llvm/Support/raw_ostream.h>

constexpr bool cirMissingFeatureAssertionMode =
constexpr bool cirCConvAssertionMode =
true; // Change to `false` to use llvm_unreachable

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

// Special assertion to be used in the target lowering library.
#define cir_tl_assert(cond) \
#define cir_cconv_assert(cond) \
do { \
if (!(cond)) \
llvm::errs() << NOTE << "\n"; \
llvm::errs() << CIR_CCONV_NOTE << "\n"; \
assert((cond)); \
} while (0)

// Special version of cir_unreachable to give more info to the user on how
// Special version of cir_cconv_unreachable to give more info to the user on how
// to temporaruly disable target lowering.
#define cir_unreachable(msg) \
#define cir_cconv_unreachable(msg) \
do { \
llvm_unreachable(msg NOTE); \
llvm_unreachable(msg CIR_CCONV_NOTE); \
} while (0)

// Some assertions knowingly generate incorrect code. This macro allows us to
// switch between using `assert` and `llvm_unreachable` for these cases.
#define cir_assert_or_abort(cond, msg) \
#define cir_cconv_assert_or_abort(cond, msg) \
do { \
if (cirMissingFeatureAssertionMode) { \
assert((cond) && msg NOTE); \
if (cirCConvAssertionMode) { \
assert((cond) && msg CIR_CCONV_NOTE); \
} else { \
llvm_unreachable(msg NOTE); \
llvm_unreachable(msg CIR_CCONV_NOTE); \
} \
} while (0)

Expand Down
5 changes: 3 additions & 2 deletions clang/lib/CIR/Dialect/Transforms/CallConvLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ struct CallConvLoweringPattern : public OpRewritePattern<FuncOp> {
for (auto call : calls.value()) {
// FIXME(cir): Function pointers are ignored.
if (isa<GetGlobalOp>(call.getUser())) {
cir_assert_or_abort(!::cir::MissingFeatures::ABIFuncPtr(), "NYI");
cir_cconv_assert_or_abort(!::cir::MissingFeatures::ABIFuncPtr(),
"NYI");
continue;
}

auto callOp = dyn_cast_or_null<CallOp>(call.getUser());
if (!callOp)
cir_unreachable("NYI empty callOp");
cir_cconv_unreachable("NYI empty callOp");
if (lowerModule->rewriteFunctionCall(callOp, op).failed())
return failure();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bool ABIInfo::isPromotableIntegerTypeForABI(Type Ty) const {
if (getContext().isPromotableIntegerType(Ty))
return true;

cir_tl_assert(!::cir::MissingFeatures::fixedWidthIntegers());
cir_cconv_assert(!::cir::MissingFeatures::fixedWidthIntegers());

return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ bool classifyReturnType(const CIRCXXABI &CXXABI, LowerFunctionInfo &FI,
Type Ty = FI.getReturnType();

if (const auto RT = dyn_cast<StructType>(Ty)) {
cir_tl_assert(!::cir::MissingFeatures::isCXXRecordDecl());
cir_cconv_assert(!::cir::MissingFeatures::isCXXRecordDecl());
}

return CXXABI.classifyReturnType(FI);
}

bool isAggregateTypeForABI(Type T) {
cir_tl_assert(!::cir::MissingFeatures::functionMemberPointerType());
cir_cconv_assert(!::cir::MissingFeatures::functionMemberPointerType());
return !LowerFunction::hasScalarEvaluationKind(T);
}

Type useFirstFieldIfTransparentUnion(Type Ty) {
if (auto RT = dyn_cast<StructType>(Ty)) {
if (RT.isUnion())
cir_assert_or_abort(
cir_cconv_assert_or_abort(
!::cir::MissingFeatures::ABITransparentUnionHandling(), "NYI");
}
return Ty;
Expand All @@ -49,7 +49,7 @@ Type useFirstFieldIfTransparentUnion(Type Ty) {
CIRCXXABI::RecordArgABI getRecordArgABI(const StructType RT,
CIRCXXABI &CXXABI) {
if (::cir::MissingFeatures::typeIsCXXRecordDecl()) {
cir_unreachable("NYI");
cir_cconv_unreachable("NYI");
}
return CXXABI.getRecordArgABI(RT);
}
Expand Down
35 changes: 18 additions & 17 deletions clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRLowerContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ clang::TypeInfo CIRLowerContext::getTypeInfoImpl(const Type T) const {
} else if (isa<StructType>(T)) {
typeKind = clang::Type::Record;
} else {
cir_assert_or_abort(!::cir::MissingFeatures::ABIClangTypeKind(),
"Unhandled type class");
cir_cconv_assert_or_abort(!::cir::MissingFeatures::ABIClangTypeKind(),
"Unhandled type class");
// FIXME(cir): Completely wrong. Just here to make it non-blocking.
typeKind = clang::Type::Builtin;
}
Expand Down Expand Up @@ -94,48 +94,49 @@ clang::TypeInfo CIRLowerContext::getTypeInfoImpl(const Type T) const {
Align = Target->getDoubleAlign();
break;
}
cir_unreachable("Unknown builtin type!");
cir_cconv_unreachable("Unknown builtin type!");
break;
}
case clang::Type::Record: {
const auto RT = dyn_cast<StructType>(T);
cir_tl_assert(!::cir::MissingFeatures::tagTypeClassAbstraction());
cir_cconv_assert(!::cir::MissingFeatures::tagTypeClassAbstraction());

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

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

if (::cir::MissingFeatures::typeGetAsEnumType()) {
cir_unreachable("NYI");
cir_cconv_unreachable("NYI");
}

const CIRRecordLayout &Layout = getCIRRecordLayout(RT);
Width = toBits(Layout.getSize());
Align = toBits(Layout.getAlignment());
cir_tl_assert(!::cir::MissingFeatures::recordDeclHasAlignmentAttr());
cir_cconv_assert(!::cir::MissingFeatures::recordDeclHasAlignmentAttr());
break;
}
default:
cir_unreachable("Unhandled type class");
cir_cconv_unreachable("Unhandled type class");
}

cir_tl_assert(llvm::isPowerOf2_32(Align) && "Alignment must be power of 2");
cir_cconv_assert(llvm::isPowerOf2_32(Align) &&
"Alignment must be power of 2");
return clang::TypeInfo(Width, Align, AlignRequirement);
}

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

// NOTE(cir): Clang does more stuff here. Not sure if we need to do the same.
cir_tl_assert(!::cir::MissingFeatures::qualifiedTypes());
cir_cconv_assert(!::cir::MissingFeatures::qualifiedTypes());
switch (K) {
case clang::BuiltinType::Char_S:
Ty = IntType::get(getMLIRContext(), 8, true);
break;
default:
cir_unreachable("NYI");
cir_cconv_unreachable("NYI");
}

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

void CIRLowerContext::initBuiltinTypes(const clang::TargetInfo &Target,
const clang::TargetInfo *AuxTarget) {
cir_tl_assert((!this->Target || this->Target == &Target) &&
"Incorrect target reinitialization");
cir_cconv_assert((!this->Target || this->Target == &Target) &&
"Incorrect target reinitialization");
this->Target = &Target;
this->AuxTarget = AuxTarget;

// C99 6.2.5p3.
if (LangOpts.CharIsSigned)
CharTy = initBuiltinType(clang::BuiltinType::Char_S);
else
cir_unreachable("NYI");
cir_cconv_unreachable("NYI");
}

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

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

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

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ CIRRecordLayout::CIRRecordLayout(
FieldOffsets.insert(FieldOffsets.end(), fieldoffsets.begin(),
fieldoffsets.end());

cir_tl_assert(!PrimaryBase && "Layout for class with inheritance is NYI");
cir_cconv_assert(!PrimaryBase && "Layout for class with inheritance is NYI");
// CXXInfo->PrimaryBase.setPointer(PrimaryBase);
cir_tl_assert(!IsPrimaryBaseVirtual &&
"Layout for virtual base class is NYI");
cir_cconv_assert(!IsPrimaryBaseVirtual &&
"Layout for virtual base class is NYI");
// CXXInfo->PrimaryBase.setInt(IsPrimaryBaseVirtual);
CXXInfo->NonVirtualSize = nonvirtualsize;
CXXInfo->NonVirtualAlignment = nonvirtualalignment;
CXXInfo->PreferredNVAlignment = preferrednvalignment;
CXXInfo->SizeOfLargestEmptySubobject = SizeOfLargestEmptySubobject;
// FIXME(cir): Initialize base classes offsets.
cir_tl_assert(!::cir::MissingFeatures::getCXXRecordBases());
cir_cconv_assert(!::cir::MissingFeatures::getCXXRecordBases());
CXXInfo->HasOwnVFPtr = hasOwnVFPtr;
CXXInfo->VBPtrOffset = vbptroffset;
CXXInfo->HasExtendableVFPtr = hasExtendableVFPtr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class CIRToCIRArgMapping {
unsigned totalIRArgs() const { return TotalIRArgs; }

bool hasPaddingArg(unsigned ArgNo) const {
cir_tl_assert(ArgNo < ArgInfo.size());
cir_cconv_assert(ArgNo < ArgInfo.size());
return ArgInfo[ArgNo].PaddingArgIndex != InvalidIndex;
}

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

if (RetAI.getKind() == ::cir::ABIArgInfo::Indirect) {
cir_unreachable("NYI");
cir_cconv_unreachable("NYI");
}

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

if (::cir::MissingFeatures::argumentPadding()) {
cir_unreachable("NYI");
cir_cconv_unreachable("NYI");
}

switch (AI.getKind()) {
case ::cir::ABIArgInfo::Extend:
case ::cir::ABIArgInfo::Direct: {
// FIXME(cir): handle sseregparm someday...
cir_tl_assert(AI.getCoerceToType() && "Missing coerced type!!");
cir_cconv_assert(AI.getCoerceToType() && "Missing coerced type!!");
StructType STy = dyn_cast<StructType>(AI.getCoerceToType());
if (AI.isDirect() && AI.getCanBeFlattened() && STy) {
cir_unreachable("NYI");
cir_cconv_unreachable("NYI");
} else {
IRArgs.NumberOfArgs = 1;
}
break;
}
default:
cir_unreachable("Missing ABIArgInfo::Kind");
cir_cconv_unreachable("Missing ABIArgInfo::Kind");
}

if (IRArgs.NumberOfArgs > 0) {
Expand All @@ -114,10 +114,10 @@ class CIRToCIRArgMapping {
if (IRArgNo == 1 && SwapThisWithSRet)
IRArgNo++;
}
cir_tl_assert(ArgNo == ArgInfo.size());
cir_cconv_assert(ArgNo == ArgInfo.size());

if (::cir::MissingFeatures::inallocaArgs()) {
cir_unreachable("NYI");
cir_cconv_unreachable("NYI");
}

TotalIRArgs = IRArgNo;
Expand All @@ -126,7 +126,7 @@ class CIRToCIRArgMapping {
/// Returns index of first IR argument corresponding to ArgNo, and their
/// quantity.
std::pair<unsigned, unsigned> getIRArgs(unsigned ArgNo) const {
cir_tl_assert(ArgNo < ArgInfo.size());
cir_cconv_assert(ArgNo < ArgInfo.size());
return std::make_pair(ArgInfo[ArgNo].FirstArgIndex,
ArgInfo[ArgNo].NumberOfArgs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class ItaniumCXXABI : public CIRCXXABI {

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

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

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

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

case clang::TargetCXXABI::Microsoft:
cir_unreachable("Microsoft ABI is not Itanium-based");
cir_cconv_unreachable("Microsoft ABI is not Itanium-based");
default:
cir_unreachable("NYI");
cir_cconv_unreachable("NYI");
}

cir_unreachable("bad ABI kind");
cir_cconv_unreachable("bad ABI kind");
}

} // namespace cir
Expand Down
Loading

0 comments on commit 8311717

Please sign in to comment.