Skip to content

Commit 5c69e08

Browse files
[CIR] Add CIRGenFunction::getTypeSizeInBits and use it for size computation (#1874)
1 parent 3d04a3d commit 5c69e08

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,18 +1053,7 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned BuiltinID,
10531053
unsigned numElts = vecTy.getSize();
10541054
auto eltTy = vecTy.getElementType();
10551055

1056-
assert(isSized(eltTy) && "Element type must be a sized type");
1057-
1058-
unsigned eltBitWidth =
1059-
llvm::TypeSwitch<mlir::Type, unsigned>(eltTy)
1060-
.Case<cir::IntType>([](auto intTy) { return intTy.getWidth(); })
1061-
.Case<cir::SingleType>([](auto) { return 32; })
1062-
.Case<cir::DoubleType>([](auto) { return 64; })
1063-
.Default([](auto) {
1064-
llvm_unreachable("NYI: Unsupported type");
1065-
return 0;
1066-
});
1067-
1056+
unsigned eltBitWidth = getTypeSizeInBits(eltTy).getFixedValue();
10681057
unsigned vecBitWidth = numElts * eltBitWidth;
10691058
unsigned numLanes = vecBitWidth / 128;
10701059
unsigned numLaneElts = numElts / numLanes;

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,6 +1842,13 @@ class CIRGenFunction : public CIRGenTypeCache {
18421842
mlir::Value emitBuiltinObjectSize(const Expr *E, unsigned Type,
18431843
cir::IntType ResType, mlir::Value EmittedE,
18441844
bool IsDynamic);
1845+
1846+
/// Get size of type in bits using SizedTypeInterface
1847+
llvm::TypeSize getTypeSizeInBits(mlir::Type Ty) const {
1848+
assert(cir::isSized(Ty) && "Type must implement SizedTypeInterface");
1849+
return CGM.getDataLayout().getTypeSizeInBits(Ty);
1850+
}
1851+
18451852
template <uint32_t N>
18461853
[[maybe_unused]] RValue
18471854
emitBuiltinWithOneOverloadedType(const CallExpr *E, llvm::StringRef Name) {

0 commit comments

Comments
 (0)