Skip to content

Commit a995452

Browse files
dkolsen-pgilanza
authored andcommitted
[CIR] Cleanup: convert from Clang type to CIR type (#1271)
Class `CIRGenFunction` contained three identical functions that converted from a Clang AST type (`clang::QualType`) to a ClangIR type (`mlir::Type`): `convertType`, `ConvertType`, and `getCIRType`. This embarrassment of duplication needed to be fixed, along with cleaning up other functions that convert from Clang types to ClangIR types. The three functions `CIRGenFunction::ConvertType`, `CIRGenFunction::convertType`, and `CIRGenFunction::getCIRType` were combined into a single function `CIRGenFunction::convertType`. Other functions were renamed as follows: - `CIRGenTypes::ConvertType` to `CIRGenTypes::convertType` - `CIRGenTypes::ConvertFunctionTypeInternal` to `CIRGenTypes::convertFunctionTypeInternal` - `CIRGenModule::getCIRType` to `CIRGenModule::convertType` - `ConstExprEmitter::ConvertType` to `ConstExprEmitter::convertType` - `ScalarExprEmitter::ConvertType` to `ScalarExprEmitter::convertType` Many cases of `getTypes().convertType(t)` and `getTypes().convertTypeForMem(t)` were changed to just `convertType(t)` and `convertTypeForMem(t)`, respectively, because the forwarding functions in `CIRGenModule` and `CIRGenFunction` make the explicit call to `getTypes()` unnecessary.
1 parent df3c39a commit a995452

22 files changed

+162
-185
lines changed

clang/lib/CIR/CodeGen/CIRAsm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ mlir::LogicalResult CIRGenFunction::emitAsmStmt(const AsmStmt &S) {
455455
uint64_t InputSize = getContext().getTypeSize(InputTy);
456456
if (getContext().getTypeSize(OutputType) < InputSize) {
457457
// Form the asm to return the value as a larger integer or fp type.
458-
ResultRegTypes.back() = ConvertType(InputTy);
458+
ResultRegTypes.back() = convertType(InputTy);
459459
}
460460
}
461461
if (mlir::Type AdjTy = getTargetHooks().adjustInlineAsmType(
@@ -478,7 +478,7 @@ mlir::LogicalResult CIRGenFunction::emitAsmStmt(const AsmStmt &S) {
478478
// Otherwise there will be a mis-match if the matrix is also an
479479
// input-argument which is represented as vector.
480480
if (isa<MatrixType>(OutExpr->getType().getCanonicalType()))
481-
DestAddr = DestAddr.withElementType(ConvertType(OutExpr->getType()));
481+
DestAddr = DestAddr.withElementType(convertType(OutExpr->getType()));
482482

483483
ArgTypes.push_back(DestAddr.getType());
484484
ArgElemTypes.push_back(DestAddr.getElementType());

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static RValue emitUnaryFPBuiltin(CIRGenFunction &CGF, const CallExpr &E) {
7272
template <typename Op>
7373
static RValue emitUnaryMaybeConstrainedFPToIntBuiltin(CIRGenFunction &CGF,
7474
const CallExpr &E) {
75-
auto ResultType = CGF.ConvertType(E.getType());
75+
auto ResultType = CGF.convertType(E.getType());
7676
auto Src = CGF.emitScalarExpr(E.getArg(0));
7777

7878
if (CGF.getBuilder().getIsFPConstrained())
@@ -88,7 +88,7 @@ static RValue emitBinaryFPBuiltin(CIRGenFunction &CGF, const CallExpr &E) {
8888
auto Arg1 = CGF.emitScalarExpr(E.getArg(1));
8989

9090
auto Loc = CGF.getLoc(E.getExprLoc());
91-
auto Ty = CGF.ConvertType(E.getType());
91+
auto Ty = CGF.convertType(E.getType());
9292
auto Call = CGF.getBuilder().create<Op>(Loc, Ty, Arg0, Arg1);
9393

9494
return RValue::get(Call->getResult(0));
@@ -101,7 +101,7 @@ static mlir::Value emitBinaryMaybeConstrainedFPBuiltin(CIRGenFunction &CGF,
101101
auto Arg1 = CGF.emitScalarExpr(E.getArg(1));
102102

103103
auto Loc = CGF.getLoc(E.getExprLoc());
104-
auto Ty = CGF.ConvertType(E.getType());
104+
auto Ty = CGF.convertType(E.getType());
105105

106106
if (CGF.getBuilder().getIsFPConstrained()) {
107107
CIRGenFunction::CIRGenFPOptionsRAII FPOptsRAII(CGF, &E);
@@ -122,7 +122,7 @@ emitBuiltinBitOp(CIRGenFunction &CGF, const CallExpr *E,
122122
else
123123
arg = CGF.emitScalarExpr(E->getArg(0));
124124

125-
auto resultTy = CGF.ConvertType(E->getType());
125+
auto resultTy = CGF.convertType(E->getType());
126126
auto op =
127127
CGF.getBuilder().create<Op>(CGF.getLoc(E->getExprLoc()), resultTy, arg);
128128
return RValue::get(op);
@@ -415,7 +415,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
415415
// of the type. We feel it should be Ok to use expression type because
416416
// it is hard to imagine a builtin function evaluates to
417417
// a value that over/underflows its own defined type.
418-
mlir::Type resTy = getCIRType(E->getType());
418+
mlir::Type resTy = convertType(E->getType());
419419
return RValue::get(builder.getConstFP(getLoc(E->getExprLoc()), resTy,
420420
Result.Val.getFloat()));
421421
}
@@ -1173,7 +1173,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
11731173
return emitRotate(E, true);
11741174

11751175
case Builtin::BI__builtin_constant_p: {
1176-
mlir::Type ResultType = ConvertType(E->getType());
1176+
mlir::Type ResultType = convertType(E->getType());
11771177

11781178
const Expr *Arg = E->getArg(0);
11791179
QualType ArgType = Arg->getType();
@@ -1199,7 +1199,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
11991199
// Convert Objective-C objects to id because we cannot distinguish between
12001200
// LLVM types for Obj-C classes as they are opaque.
12011201
ArgType = CGM.getASTContext().getObjCIdType();
1202-
ArgValue = builder.createBitcast(ArgValue, ConvertType(ArgType));
1202+
ArgValue = builder.createBitcast(ArgValue, convertType(ArgType));
12031203

12041204
mlir::Value Result = builder.create<cir::IsConstantOp>(
12051205
getLoc(E->getSourceRange()), ArgValue);
@@ -1215,7 +1215,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
12151215
case Builtin::BI__builtin_object_size: {
12161216
unsigned Type =
12171217
E->getArg(1)->EvaluateKnownConstInt(getContext()).getZExtValue();
1218-
auto ResType = mlir::dyn_cast<cir::IntType>(ConvertType(E->getType()));
1218+
auto ResType = mlir::dyn_cast<cir::IntType>(convertType(E->getType()));
12191219
assert(ResType && "not sure what to do?");
12201220

12211221
// We pass this builtin onto the optimizer so that it can figure out the
@@ -1306,7 +1306,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
13061306
llvm_unreachable("BI__builtin_nondeterministic_value NYI");
13071307

13081308
case Builtin::BI__builtin_elementwise_abs: {
1309-
mlir::Type cirTy = ConvertType(E->getArg(0)->getType());
1309+
mlir::Type cirTy = convertType(E->getArg(0)->getType());
13101310
bool isIntTy = cir::isIntOrIntVectorTy(cirTy);
13111311
if (!isIntTy) {
13121312
mlir::Type eltTy = cirTy;
@@ -1851,7 +1851,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
18511851
auto loc = getLoc(E->getBeginLoc());
18521852
return RValue::get(builder.createZExtOrBitCast(
18531853
loc, emitSignBit(loc, *this, emitScalarExpr(E->getArg(0))),
1854-
ConvertType(E->getType())));
1854+
convertType(E->getType())));
18551855
}
18561856

18571857
case Builtin::BI__warn_memset_zero_len:
@@ -1897,8 +1897,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
18971897

18981898
auto EncompassingCIRTy = cir::IntType::get(
18991899
&getMLIRContext(), EncompassingInfo.Width, EncompassingInfo.Signed);
1900-
auto ResultCIRTy =
1901-
mlir::cast<cir::IntType>(CGM.getTypes().ConvertType(ResultQTy));
1900+
auto ResultCIRTy = mlir::cast<cir::IntType>(CGM.convertType(ResultQTy));
19021901

19031902
mlir::Value Left = emitScalarExpr(LeftArg);
19041903
mlir::Value Right = emitScalarExpr(RightArg);
@@ -2008,8 +2007,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
20082007

20092008
clang::QualType ResultQTy =
20102009
ResultArg->getType()->castAs<clang::PointerType>()->getPointeeType();
2011-
auto ResultCIRTy =
2012-
mlir::cast<cir::IntType>(CGM.getTypes().ConvertType(ResultQTy));
2010+
auto ResultCIRTy = mlir::cast<cir::IntType>(CGM.convertType(ResultQTy));
20132011

20142012
auto Loc = getLoc(E->getSourceRange());
20152013
auto ArithResult =
@@ -2304,7 +2302,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
23042302
// FIXME: We should use builder.createZExt once createZExt is available.
23052303
return RValue::get(builder.createZExtOrBitCast(
23062304
Loc, builder.createIsFPClass(Loc, V, FPClassTest::fcNan),
2307-
ConvertType(E->getType())));
2305+
convertType(E->getType())));
23082306
}
23092307

23102308
case Builtin::BI__builtin_issignaling: {
@@ -2314,7 +2312,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
23142312
// FIXME: We should use builder.createZExt once createZExt is available.
23152313
return RValue::get(builder.createZExtOrBitCast(
23162314
Loc, builder.createIsFPClass(Loc, V, FPClassTest::fcSNan),
2317-
ConvertType(E->getType())));
2315+
convertType(E->getType())));
23182316
}
23192317

23202318
case Builtin::BI__builtin_isinf: {
@@ -2326,7 +2324,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
23262324
// FIXME: We should use builder.createZExt once createZExt is available.
23272325
return RValue::get(builder.createZExtOrBitCast(
23282326
Loc, builder.createIsFPClass(Loc, V, FPClassTest::fcInf),
2329-
ConvertType(E->getType())));
2327+
convertType(E->getType())));
23302328
}
23312329

23322330
case Builtin::BIfinite:
@@ -2344,7 +2342,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
23442342
// FIXME: We should use builder.createZExt once createZExt is available.
23452343
return RValue::get(builder.createZExtOrBitCast(
23462344
Loc, builder.createIsFPClass(Loc, V, FPClassTest::fcFinite),
2347-
ConvertType(E->getType())));
2345+
convertType(E->getType())));
23482346
}
23492347

23502348
case Builtin::BI__builtin_isnormal: {
@@ -2354,7 +2352,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
23542352
// FIXME: We should use builder.createZExt once createZExt is available.
23552353
return RValue::get(builder.createZExtOrBitCast(
23562354
Loc, builder.createIsFPClass(Loc, V, FPClassTest::fcNormal),
2357-
ConvertType(E->getType())));
2355+
convertType(E->getType())));
23582356
}
23592357

23602358
case Builtin::BI__builtin_issubnormal: {
@@ -2364,7 +2362,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
23642362
// FIXME: We should use builder.createZExt once createZExt is available.
23652363
return RValue::get(builder.createZExtOrBitCast(
23662364
Loc, builder.createIsFPClass(Loc, V, FPClassTest::fcSubnormal),
2367-
ConvertType(E->getType())));
2365+
convertType(E->getType())));
23682366
}
23692367

23702368
case Builtin::BI__builtin_iszero: {
@@ -2374,7 +2372,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
23742372
// FIXME: We should use builder.createZExt once createZExt is available.
23752373
return RValue::get(builder.createZExtOrBitCast(
23762374
Loc, builder.createIsFPClass(Loc, V, FPClassTest::fcZero),
2377-
ConvertType(E->getType())));
2375+
convertType(E->getType())));
23782376
}
23792377

23802378
case Builtin::BI__builtin_isfpclass: {
@@ -2389,7 +2387,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
23892387

23902388
// FIXME: We should use builder.createZExt once createZExt is available.
23912389
return RValue::get(builder.createZExtOrBitCast(
2392-
Loc, builder.createIsFPClass(Loc, V, Test), ConvertType(E->getType())));
2390+
Loc, builder.createIsFPClass(Loc, V, Test), convertType(E->getType())));
23932391
}
23942392
}
23952393

@@ -2706,6 +2704,6 @@ cir::FuncOp CIRGenModule::getBuiltinLibFunction(const FunctionDecl *FD,
27062704
Name = astContext.BuiltinInfo.getName(BuiltinID).substr(10);
27072705
}
27082706

2709-
auto Ty = getTypes().ConvertType(FD->getType());
2707+
auto Ty = convertType(FD->getType());
27102708
return GetOrCreateCIRFunction(Name, Ty, D, /*ForVTable=*/false);
27112709
}

clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,7 +2133,7 @@ static mlir::Value emitArmLdrexNon128Intrinsic(unsigned int builtinID,
21332133
// Get Instrinc call
21342134
CIRGenBuilderTy &builder = cgf.getBuilder();
21352135
QualType clangResTy = clangCallExpr->getType();
2136-
mlir::Type realResTy = cgf.ConvertType(clangResTy);
2136+
mlir::Type realResTy = cgf.convertType(clangResTy);
21372137
// Return type of LLVM intrinsic is defined in Intrinsic<arch_type>.td,
21382138
// which can be found under LLVM IR directory.
21392139
mlir::Type funcResTy = builder.getSInt64Ty();
@@ -2345,7 +2345,7 @@ emitCommonNeonCallPattern0(CIRGenFunction &cgf, llvm::StringRef intrincsName,
23452345
mlir::Value res =
23462346
emitNeonCall(builder, std::move(argTypes), ops, intrincsName, funcResTy,
23472347
cgf.getLoc(e->getExprLoc()));
2348-
mlir::Type resultType = cgf.ConvertType(e->getType());
2348+
mlir::Type resultType = cgf.convertType(e->getType());
23492349
return builder.createBitcast(res, resultType);
23502350
}
23512351

clang/lib/CIR/CodeGen/CIRGenCall.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1610,7 +1610,7 @@ void CIRGenFunction::emitNonNullArgCheck(RValue RV, QualType ArgType,
16101610
mlir::Value CIRGenFunction::emitVAArg(VAArgExpr *VE, Address &VAListAddr) {
16111611
assert(!VE->isMicrosoftABI() && "NYI");
16121612
auto loc = CGM.getLoc(VE->getExprLoc());
1613-
auto type = ConvertType(VE->getType());
1613+
auto type = convertType(VE->getType());
16141614
auto vaList = emitVAListRef(VE->getSubExpr()).getPointer();
16151615
return builder.create<cir::VAArgOp>(loc, type, vaList);
16161616
}

clang/lib/CIR/CodeGen/CIRGenClass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ Address CIRGenFunction::getAddressOfDirectBaseInCompleteClass(
582582
mlir::Location loc, Address This, const CXXRecordDecl *Derived,
583583
const CXXRecordDecl *Base, bool BaseIsVirtual) {
584584
// 'this' must be a pointer (in some address space) to Derived.
585-
assert(This.getElementType() == ConvertType(Derived));
585+
assert(This.getElementType() == convertType(Derived));
586586

587587
// Compute the offset of the virtual base.
588588
CharUnits Offset;
@@ -592,7 +592,7 @@ Address CIRGenFunction::getAddressOfDirectBaseInCompleteClass(
592592
else
593593
Offset = Layout.getBaseClassOffset(Base);
594594

595-
return builder.createBaseClassAddr(loc, This, ConvertType(Base),
595+
return builder.createBaseClassAddr(loc, This, convertType(Base),
596596
Offset.getQuantity(),
597597
/*assume_not_null=*/true);
598598
}
@@ -1591,7 +1591,7 @@ Address CIRGenFunction::getAddressOfDerivedClass(
15911591

15921592
QualType derivedTy =
15931593
getContext().getCanonicalType(getContext().getTagDeclType(derived));
1594-
mlir::Type derivedValueTy = ConvertType(derivedTy);
1594+
mlir::Type derivedValueTy = convertType(derivedTy);
15951595
CharUnits nonVirtualOffset =
15961596
CGM.getNonVirtualBaseClassOffset(derived, pathBegin, pathEnd);
15971597

clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ CIRGenFunction::emitCoroutineBody(const CoroutineBodyStmt &S) {
262262

263263
// Initialize address of coroutine frame to null
264264
auto astVoidPtrTy = CGM.getASTContext().VoidPtrTy;
265-
auto allocaTy = getTypes().convertTypeForMem(astVoidPtrTy);
265+
auto allocaTy = convertTypeForMem(astVoidPtrTy);
266266
Address coroFrame =
267267
CreateTempAlloca(allocaTy, getContext().getTypeAlignInChars(astVoidPtrTy),
268268
openCurlyLoc, "__coro_frame_addr",

clang/lib/CIR/CodeGen/CIRGenDecl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ CIRGenFunction::emitAutoVarAlloca(const VarDecl &D,
139139
if (isEscapingByRef)
140140
llvm_unreachable("NYI");
141141

142-
mlir::Type allocaTy = getTypes().convertTypeForMem(Ty);
142+
mlir::Type allocaTy = convertTypeForMem(Ty);
143143
CharUnits allocaAlignment = alignment;
144144
// Create the temp alloca and declare variable using it.
145145
mlir::Value addrVal;
@@ -482,7 +482,7 @@ CIRGenModule::getOrCreateStaticVarDecl(const VarDecl &D,
482482
if (D.hasAttr<CUDASharedAttr>() || D.hasAttr<LoaderUninitializedAttr>())
483483
llvm_unreachable("CUDA is NYI");
484484
else if (Ty.getAddressSpace() != LangAS::opencl_local)
485-
Init = builder.getZeroInitAttr(getTypes().ConvertType(Ty));
485+
Init = builder.getZeroInitAttr(convertType(Ty));
486486

487487
cir::GlobalOp GV = builder.createVersionedGlobal(
488488
getModule(), getLoc(D.getLocation()), Name, LTy, false, Linkage, AS);
@@ -620,7 +620,7 @@ void CIRGenFunction::emitStaticVarDecl(const VarDecl &D,
620620

621621
// Store into LocalDeclMap before generating initializer to handle
622622
// circular references.
623-
mlir::Type elemTy = getTypes().convertTypeForMem(D.getType());
623+
mlir::Type elemTy = convertTypeForMem(D.getType());
624624
setAddrOfLocalVar(&D, Address(addr, elemTy, alignment));
625625

626626
// We can't have a VLA here, but we can have a pointer to a VLA,

0 commit comments

Comments
 (0)