Skip to content

Commit ed0a86b

Browse files
committed
Address code review comments
1 parent 9e10f04 commit ed0a86b

File tree

2 files changed

+7
-22
lines changed

2 files changed

+7
-22
lines changed

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

+4-17
Original file line numberDiff line numberDiff line change
@@ -682,19 +682,6 @@ mlir::LogicalResult CIRToLLVMStoreOpLowering::matchAndRewrite(
682682
return mlir::LogicalResult::success();
683683
}
684684

685-
/// Switches on the type of attribute and calls the appropriate conversion.
686-
mlir::Value lowerCirAttrAsValue(mlir::Operation *parentOp,
687-
const mlir::Attribute attr,
688-
mlir::ConversionPatternRewriter &rewriter,
689-
const mlir::TypeConverter *converter,
690-
mlir::DataLayout const &dataLayout) {
691-
CIRAttrToValue valueConverter(parentOp, rewriter, converter);
692-
const mlir::Value value = valueConverter.visit(attr);
693-
if (!value)
694-
llvm_unreachable("unhandled attribute type");
695-
return value;
696-
}
697-
698685
bool hasTrailingZeros(cir::ConstArrayAttr attr) {
699686
auto array = mlir::dyn_cast<mlir::ArrayAttr>(attr.getElts());
700687
return attr.hasTrailingZeros() ||
@@ -749,16 +736,16 @@ mlir::LogicalResult CIRToLLVMConstantOpLowering::matchAndRewrite(
749736

750737
std::optional<mlir::Attribute> denseAttr;
751738
if (constArr && hasTrailingZeros(constArr)) {
752-
const mlir::Value newOp = lowerCirAttrAsValue(
753-
op, constArr, rewriter, getTypeConverter(), dataLayout);
739+
const mlir::Value newOp =
740+
lowerCirAttrAsValue(op, constArr, rewriter, getTypeConverter());
754741
rewriter.replaceOp(op, newOp);
755742
return mlir::success();
756743
} else if (constArr &&
757744
(denseAttr = lowerConstArrayAttr(constArr, typeConverter))) {
758745
attr = denseAttr.value();
759746
} else {
760-
const mlir::Value initVal = lowerCirAttrAsValue(
761-
op, op.getValue(), rewriter, typeConverter, dataLayout);
747+
const mlir::Value initVal =
748+
lowerCirAttrAsValue(op, op.getValue(), rewriter, typeConverter);
762749
rewriter.replaceAllUsesWith(op, initVal);
763750
rewriter.eraseOp(op);
764751
return mlir::success();

clang/lib/CIR/Lowering/LoweringHelpers.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,11 @@ mlir::DenseElementsAttr convertToDenseElementsAttr(
117117
std::optional<mlir::Attribute>
118118
lowerConstArrayAttr(cir::ConstArrayAttr constArr,
119119
const mlir::TypeConverter *converter) {
120-
121120
// Ensure ConstArrayAttr has a type.
122-
auto typedConstArr = mlir::dyn_cast<mlir::TypedAttr>(constArr);
123-
assert(typedConstArr && "cir::ConstArrayAttr is not a mlir::TypedAttr");
121+
const auto typedConstArr = mlir::cast<mlir::TypedAttr>(constArr);
124122

125123
// Ensure ConstArrayAttr type is a ArrayType.
126-
auto cirArrayType = mlir::dyn_cast<cir::ArrayType>(typedConstArr.getType());
127-
assert(cirArrayType && "cir::ConstArrayAttr is not a cir::ArrayType");
124+
const auto cirArrayType = mlir::cast<cir::ArrayType>(typedConstArr.getType());
128125

129126
// Is a ConstArrayAttr with an cir::ArrayType: fetch element type.
130127
mlir::Type type = cirArrayType;
@@ -140,6 +137,7 @@ lowerConstArrayAttr(cir::ConstArrayAttr constArr,
140137
if (mlir::isa<cir::IntType>(type))
141138
return convertToDenseElementsAttr<cir::IntAttr, mlir::APInt>(
142139
constArr, dims, type, converter->convertType(type));
140+
143141
if (mlir::isa<cir::CIRFPTypeInterface>(type))
144142
return convertToDenseElementsAttr<cir::FPAttr, mlir::APFloat>(
145143
constArr, dims, type, converter->convertType(type));

0 commit comments

Comments
 (0)