Skip to content

Commit

Permalink
fix clang-format issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gitoleg committed Jan 11, 2024
1 parent 73c6676 commit 11b8b05
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRGenBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {

mlir::cir::ConstArrayAttr getConstArray(mlir::Attribute attrs,
mlir::cir::ArrayType arrayTy,
int trailingZeros=0) {
int trailingZeros = 0) {
return mlir::cir::ConstArrayAttr::get(arrayTy, attrs, trailingZeros);
}

Expand Down
3 changes: 2 additions & 1 deletion clang/lib/CIR/CodeGen/CIRGenExprConst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,8 @@ buildArrayConstant(CIRGenModule &CGM, mlir::Type DesiredType,
return builder.getConstArray(
mlir::ArrayAttr::get(builder.getContext(), Eles),
mlir::cir::ArrayType::get(builder.getContext(), CommonElementType,
ArrayBound), TrailingZeroes);
ArrayBound),
TrailingZeroes);

// TODO(cir): If all the elements had the same type up to the trailing
// zeroes, emit a struct of two arrays (the nonzero data and the
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/CIR/Dialect/IR/CIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2295,7 +2295,7 @@ ::mlir::Attribute ConstArrayAttr::parse(::mlir::AsmParser &parser,
return {};
}
}

int zeros = 0;
if (parser.parseOptionalComma().succeeded()) {
if (parser.parseInteger(zeros).failed())
Expand All @@ -2308,8 +2308,8 @@ ::mlir::Attribute ConstArrayAttr::parse(::mlir::AsmParser &parser,
if (parser.parseGreater())
return {};

return parser.getChecked<ConstArrayAttr>(loc, parser.getContext(),
resultTy.value(), resultVal.value(), zeros);
return parser.getChecked<ConstArrayAttr>(
loc, parser.getContext(), resultTy.value(), resultVal.value(), zeros);
}

void ConstArrayAttr::print(::mlir::AsmPrinter &printer) const {
Expand Down
24 changes: 12 additions & 12 deletions clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ mlir::Value lowerCirAttrAsValue(mlir::Operation *parentOp,
auto loc = parentOp->getLoc();
mlir::Value result;

if (auto zeros = constArr.getTrailingZerosNum()) {
auto arrayTy = constArr.getType();
result = rewriter.create<mlir::cir::ZeroInitConstOp>(
loc, converter->convertType(arrayTy));
if (auto zeros = constArr.getTrailingZerosNum()) {
auto arrayTy = constArr.getType();
result = rewriter.create<mlir::cir::ZeroInitConstOp>(
loc, converter->convertType(arrayTy));
} else {
result = rewriter.create<mlir::LLVM::UndefOp>(loc, llvmTy);
}
Expand Down Expand Up @@ -1002,15 +1002,14 @@ bool hasTrailingZeros(mlir::cir::ConstArrayAttr attr) {
auto array = attr.getElts().dyn_cast<mlir::ArrayAttr>();
return attr.hasTrailingZeros() ||
(array && std::count_if(array.begin(), array.end(), [](auto elt) {
auto ar = dyn_cast<mlir::cir::ConstArrayAttr>(elt);
return ar && hasTrailingZeros(ar);
}));
auto ar = dyn_cast<mlir::cir::ConstArrayAttr>(elt);
return ar && hasTrailingZeros(ar);
}));
}

std::optional<mlir::Attribute>
lowerConstArrayAttr(mlir::cir::ConstArrayAttr constArr,
const mlir::TypeConverter *converter,
mlir::MLIRContext *context) {
const mlir::TypeConverter *converter) {

// Ensure ConstArrayAttr has a type.
auto typedConstArr = constArr.dyn_cast<mlir::TypedAttr>();
Expand Down Expand Up @@ -1091,13 +1090,14 @@ class CIRConstantLowering
if (auto constArr = op.getValue().dyn_cast<mlir::cir::ConstArrayAttr>()) {

if (hasTrailingZeros(constArr)) {
auto newOp = lowerCirAttrAsValue(op, constArr, rewriter, getTypeConverter());
auto newOp =
lowerCirAttrAsValue(op, constArr, rewriter, getTypeConverter());
rewriter.replaceOp(op, newOp);
return mlir::success();
}

// Lower constant array initializer.
auto denseAttr = lowerConstArrayAttr(constArr, typeConverter, getContext());
auto denseAttr = lowerConstArrayAttr(constArr, typeConverter);
if (!denseAttr.has_value()) {
op.emitError()
<< "unsupported lowering for #cir.const_array with element type "
Expand Down Expand Up @@ -1511,7 +1511,7 @@ class CIRGlobalOpLowering
} else if (auto attr = constArr.getElts().dyn_cast<mlir::ArrayAttr>()) {
// Failed to use a compact attribute as an initializer:
// initialize elements individually.
if (!(init = lowerConstArrayAttr(constArr, getTypeConverter(), getContext()))) {
if (!(init = lowerConstArrayAttr(constArr, getTypeConverter()))) {
setupRegionInitializedLLVMGlobalOp(op, rewriter);
rewriter.create<mlir::LLVM::ReturnOp>(
op->getLoc(),
Expand Down

0 comments on commit 11b8b05

Please sign in to comment.