Skip to content

Commit ee9c92f

Browse files
committed
Address code review comments and add getConstantInt
1 parent 4dc1e77 commit ee9c92f

File tree

4 files changed

+9
-13
lines changed

4 files changed

+9
-13
lines changed

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
3232
return create<cir::ConstantOp>(loc, attr.getType(), attr);
3333
}
3434

35+
cir::ConstantOp getConstantInt(mlir::Location loc, mlir::Type ty,
36+
int64_t value) {
37+
return create<cir::ConstantOp>(loc, ty, cir::IntAttr::get(ty, value));
38+
}
39+
3540
// Creates constant null value for integral type ty.
3641
cir::ConstantOp getNullValue(mlir::Type ty, mlir::Location loc) {
3742
return create<cir::ConstantOp>(loc, ty, getZeroInitAttr(ty));

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,6 @@ def PtrStrideOp : CIR_Op<"ptr_stride",
268268
return mlir::cast<cir::PointerType>(getBase().getType()).getPointee();
269269
}
270270
}];
271-
272-
// SameFirstOperandAndResultType already checks all we need.
273-
let hasVerifier = 0;
274271
}
275272

276273
//===----------------------------------------------------------------------===//

clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ void AggExprEmitter::emitArrayInit(Address destPtr, cir::ArrayType arrayTy,
122122
for (uint64_t i = 0; i != numInitElements; ++i) {
123123
// Advance to the next element.
124124
if (i > 0) {
125-
one = builder.create<cir::ConstantOp>(
126-
loc, cgf.PtrDiffTy, cir::IntAttr::get(cgf.PtrDiffTy, i));
125+
one = builder.getConstantInt(loc, cgf.PtrDiffTy, i);
127126
element =
128127
builder.create<cir::PtrStrideOp>(loc, cirElementPtrType, begin, one);
129128
}
@@ -146,8 +145,7 @@ void AggExprEmitter::emitArrayInit(Address destPtr, cir::ArrayType arrayTy,
146145
cgf.getTypes().isZeroInitializable(elementType))) {
147146
// Advance to the start of the rest of the array.
148147
if (numInitElements) {
149-
one = builder.create<cir::ConstantOp>(
150-
loc, cgf.PtrDiffTy, cir::IntAttr::get(cgf.PtrDiffTy, 1));
148+
one = builder.getConstantInt(loc, cgf.PtrDiffTy, 1);
151149
element = builder.create<cir::PtrStrideOp>(loc, cirElementPtrType,
152150
element, one);
153151
}
@@ -173,9 +171,7 @@ void AggExprEmitter::emitArrayInit(Address destPtr, cir::ArrayType arrayTy,
173171
emitNullInitializationToLValue(loc, elementLV);
174172

175173
// Advance pointer and store them to temporary variable
176-
one = builder.create<cir::ConstantOp>(
177-
loc, cgf.PtrDiffTy, cir::IntAttr::get(cgf.PtrDiffTy, 1));
178-
174+
one = builder.getConstantInt(loc, cgf.PtrDiffTy, 1);
179175
auto nextElement = builder.create<cir::PtrStrideOp>(
180176
loc, cirElementPtrType, currentElement, one);
181177
cgf.emitStoreThroughLValue(RValue::get(nextElement), tmpLV);

clang/lib/CIR/CodeGen/CIRGenFunction.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,7 @@ void CIRGenFunction::emitNullInitialization(mlir::Location loc, Address destPtr,
489489
// Builder.CreateMemSet. In CIR just emit a store of #cir.zero to the
490490
// respective address.
491491
// Builder.CreateMemSet(DestPtr, Builder.getInt8(0), SizeVal, false);
492-
auto zeroAttr = cir::ZeroAttr::get(builder.getContext(), convertType(ty));
493-
auto zeroValue =
494-
builder.create<cir::ConstantOp>(loc, convertType(ty), zeroAttr);
492+
auto zeroValue = builder.getNullValue(convertType(ty), loc);
495493
builder.createStore(loc, zeroValue, destPtr.getPointer());
496494
}
497495

0 commit comments

Comments
 (0)