Skip to content

Commit 6093d7b

Browse files
[Sim] Rename FormatLitOp to FormatLiteralOp, NFC (#9015)
1 parent eb82591 commit 6093d7b

File tree

10 files changed

+94
-91
lines changed

10 files changed

+94
-91
lines changed

include/circt/Dialect/Sim/SimOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def DPICallOp : SimOp<"func.dpi.call",
151151
// String Formatting
152152
//===----------------------------------------------------------------------===//
153153

154-
def FormatLitOp : SimOp<"fmt.lit", [Pure, ConstantLike]> {
154+
def FormatLiteralOp : SimOp<"fmt.literal", [Pure, ConstantLike]> {
155155
let summary = "Literal string fragment";
156156
let description = [{
157157
Creates a constant, raw ASCII string literal for formatted printing.

lib/Conversion/MooreToCore/MooreToCore.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,7 +1586,7 @@ struct FormatLiteralOpConversion : public OpConversionPattern<FormatLiteralOp> {
15861586
LogicalResult
15871587
matchAndRewrite(FormatLiteralOp op, OpAdaptor adaptor,
15881588
ConversionPatternRewriter &rewriter) const override {
1589-
rewriter.replaceOpWithNewOp<sim::FormatLitOp>(op, adaptor.getLiteral());
1589+
rewriter.replaceOpWithNewOp<sim::FormatLiteralOp>(op, adaptor.getLiteral());
15901590
return success();
15911591
}
15921592
};
@@ -1680,7 +1680,8 @@ static LogicalResult convert(SeverityBIOp op, SeverityBIOp::Adaptor adaptor,
16801680
return failure();
16811681
}
16821682

1683-
auto prefix = rewriter.create<sim::FormatLitOp>(op.getLoc(), severityString);
1683+
auto prefix =
1684+
rewriter.create<sim::FormatLiteralOp>(op.getLoc(), severityString);
16841685
auto message = rewriter.create<sim::FormatStringConcatOp>(
16851686
op.getLoc(), ValueRange{prefix, adaptor.getMessage()});
16861687
rewriter.replaceOpWithNewOp<sim::PrintFormattedProcOp>(op, message);

lib/Dialect/Sim/SimDialect.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Operation *SimDialect::materializeConstant(::mlir::OpBuilder &builder,
4141
::mlir::Location loc) {
4242

4343
if (auto fmtStrType = llvm::dyn_cast<FormatStringType>(type))
44-
return FormatLitOp::create(builder, loc, fmtStrType,
45-
llvm::cast<StringAttr>(value));
44+
return FormatLiteralOp::create(builder, loc, fmtStrType,
45+
llvm::cast<StringAttr>(value));
4646
return nullptr;
4747
}

lib/Dialect/Sim/SimOps.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ void DPIFuncOp::print(OpAsmPrinter &p) {
110110
getPerArgumentAttrsAttrName(), getArgumentLocsAttrName()});
111111
}
112112

113-
OpFoldResult FormatLitOp::fold(FoldAdaptor adaptor) { return getLiteralAttr(); }
113+
OpFoldResult FormatLiteralOp::fold(FoldAdaptor adaptor) {
114+
return getLiteralAttr();
115+
}
114116

115117
OpFoldResult FormatDecOp::fold(FoldAdaptor adaptor) {
116118
if (getValue().getType() == IntegerType::get(getContext(), 0U))
@@ -296,11 +298,11 @@ LogicalResult FormatStringConcatOp::canonicalize(FormatStringConcatOp op,
296298
SmallVector<StringRef> litSequence;
297299
SmallVector<Value> newOperands;
298300
newOperands.reserve(op.getNumOperands());
299-
FormatLitOp prevLitOp;
301+
FormatLiteralOp prevLitOp;
300302

301303
auto oldOperands = hasBeenFlattened ? flatOperands : op.getOperands();
302304
for (auto operand : oldOperands) {
303-
if (auto litOp = operand.getDefiningOp<FormatLitOp>()) {
305+
if (auto litOp = operand.getDefiningOp<FormatLiteralOp>()) {
304306
if (!litOp.getLiteral().empty()) {
305307
prevLitOp = litOp;
306308
litSequence.push_back(litOp.getLiteral());
@@ -309,7 +311,7 @@ LogicalResult FormatStringConcatOp::canonicalize(FormatStringConcatOp op,
309311
if (!litSequence.empty()) {
310312
if (litSequence.size() > 1) {
311313
// Create a fused literal.
312-
auto newLit = rewriter.createOrFold<FormatLitOp>(
314+
auto newLit = rewriter.createOrFold<FormatLiteralOp>(
313315
op.getLoc(), fmtStrType,
314316
concatLiterals(op.getContext(), litSequence));
315317
newOperands.push_back(newLit);
@@ -327,7 +329,7 @@ LogicalResult FormatStringConcatOp::canonicalize(FormatStringConcatOp op,
327329
if (!litSequence.empty()) {
328330
if (litSequence.size() > 1) {
329331
// Create a fused literal.
330-
auto newLit = rewriter.createOrFold<FormatLitOp>(
332+
auto newLit = rewriter.createOrFold<FormatLiteralOp>(
331333
op.getLoc(), fmtStrType,
332334
concatLiterals(op.getContext(), litSequence));
333335
newOperands.push_back(newLit);
@@ -341,8 +343,8 @@ LogicalResult FormatStringConcatOp::canonicalize(FormatStringConcatOp op,
341343
return failure(); // Nothing changed
342344

343345
if (newOperands.empty())
344-
rewriter.replaceOpWithNewOp<FormatLitOp>(op, fmtStrType,
345-
rewriter.getStringAttr(""));
346+
rewriter.replaceOpWithNewOp<FormatLiteralOp>(op, fmtStrType,
347+
rewriter.getStringAttr(""));
346348
else if (newOperands.size() == 1)
347349
rewriter.replaceOp(op, newOperands);
348350
else
@@ -389,7 +391,7 @@ LogicalResult PrintFormattedProcOp::verify() {
389391
LogicalResult PrintFormattedProcOp::canonicalize(PrintFormattedProcOp op,
390392
PatternRewriter &rewriter) {
391393
// Remove empty prints.
392-
if (auto litInput = op.getInput().getDefiningOp<FormatLitOp>()) {
394+
if (auto litInput = op.getInput().getDefiningOp<FormatLiteralOp>()) {
393395
if (litInput.getLiteral().empty()) {
394396
rewriter.eraseOp(op);
395397
return success();

lib/Dialect/Sim/Transforms/ProceduralizeSim.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ LogicalResult ProceduralizeSimPass::proceduralizePrintOps(
109109
fragmentList.push_back(fmtOp);
110110
// For non-literal fragments, the value to be formatted has to become an
111111
// argument.
112-
if (!llvm::isa<FormatLitOp>(fmtOp)) {
112+
if (!llvm::isa<FormatLiteralOp>(fmtOp)) {
113113
auto fmtVal = getFormattedValue(fmtOp);
114114
assert(!!fmtVal && "Unexpected foramtting fragment op.");
115115
arguments.insert(fmtVal);

test/Conversion/MooreToCore/basic.mlir

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ func.func @Statements(%arg0: !moore.i42) {
373373

374374
// CHECK-LABEL: func @FormatStrings
375375
func.func @FormatStrings(%arg0: !moore.i42) {
376-
// CHECK: [[TMP:%.+]] = sim.fmt.lit "hello"
376+
// CHECK: [[TMP:%.+]] = sim.fmt.literal "hello"
377377
%0 = moore.fmt.literal "hello"
378378
// CHECK: sim.fmt.concat ([[TMP]], [[TMP]])
379379
%1 = moore.fmt.concat (%0, %0)
@@ -1255,22 +1255,22 @@ func.func @SimulationControl() {
12551255

12561256
// CHECK-LABEL: @SeverityToPrint
12571257
func.func @SeverityToPrint() {
1258-
// CHECK: [[MSG:%.*]] = sim.fmt.lit "Fatal condition met!"
1259-
// CHECK-NEXT: [[PFX:%.*]] = sim.fmt.lit "Fatal: "
1258+
// CHECK: [[MSG:%.*]] = sim.fmt.literal "Fatal condition met!"
1259+
// CHECK-NEXT: [[PFX:%.*]] = sim.fmt.literal "Fatal: "
12601260
// CHECK-NEXT: [[CONCAT:%.*]] = sim.fmt.concat ([[PFX]], [[MSG]])
12611261
// CHECK-NEXT: sim.proc.print [[CONCAT]]
12621262
%0 = moore.fmt.literal "Fatal condition met!"
12631263
moore.builtin.severity fatal %0
12641264

1265-
// CHECK: [[MSG:%.*]] = sim.fmt.lit "Error condition met!"
1266-
// CHECK-NEXT: [[PFX:%.*]] = sim.fmt.lit "Error: "
1265+
// CHECK: [[MSG:%.*]] = sim.fmt.literal "Error condition met!"
1266+
// CHECK-NEXT: [[PFX:%.*]] = sim.fmt.literal "Error: "
12671267
// CHECK-NEXT: [[CONCAT:%.*]] = sim.fmt.concat ([[PFX]], [[MSG]])
12681268
// CHECK-NEXT: sim.proc.print [[CONCAT]]
12691269
%1 = moore.fmt.literal "Error condition met!"
12701270
moore.builtin.severity error %1
12711271

1272-
// CHECK: [[MSG:%.*]] = sim.fmt.lit "Warning condition met!"
1273-
// CHECK-NEXT: [[PFX:%.*]] = sim.fmt.lit "Warning: "
1272+
// CHECK: [[MSG:%.*]] = sim.fmt.literal "Warning condition met!"
1273+
// CHECK-NEXT: [[PFX:%.*]] = sim.fmt.literal "Warning: "
12741274
// CHECK-NEXT: [[CONCAT:%.*]] = sim.fmt.concat ([[PFX]], [[MSG]])
12751275
// CHECK-NEXT: sim.proc.print [[CONCAT]]
12761276
%2 = moore.fmt.literal "Warning condition met!"

test/Dialect/Sim/format-strings.mlir

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// RUN: circt-opt %s --canonicalize | FileCheck --strict-whitespace %s
22

33
// CHECK-LABEL: hw.module @constant_fold0
4-
// CHECK: sim.fmt.lit ",0,0,;0,0, 0,0;1,1,-1,1;0011, 3, 3,3;01010,10, 10,0a;10000000,128,-128,80;0000001100101011111110, 51966, 51966,00cafe"
4+
// CHECK: sim.fmt.literal ",0,0,;0,0, 0,0;1,1,-1,1;0011, 3, 3,3;01010,10, 10,0a;10000000,128,-128,80;0000001100101011111110, 51966, 51966,00cafe"
55
hw.module @constant_fold0(in %zeroWitdh: i0, out res: !sim.fstring) {
6-
%comma = sim.fmt.lit ","
7-
%semicolon = sim.fmt.lit ";"
6+
%comma = sim.fmt.literal ","
7+
%semicolon = sim.fmt.literal ";"
88

99
%nocat = sim.fmt.concat ()
1010

@@ -62,13 +62,13 @@ hw.module @constant_fold0(in %zeroWitdh: i0, out res: !sim.fstring) {
6262
}
6363

6464
// CHECK-LABEL: hw.module @constant_fold1
65-
// CHECK: sim.fmt.lit " %b: '111111111111111111111111111111111111111111111111111000110100000010010001001010111001101011110010101010110010011011001001110' %u: '10633823966279322740806214058000332366' %d: ' -4242424242424242424242' %x: '7ffffffffffff1a04895cd79559364e'"
65+
// CHECK: sim.fmt.literal " %b: '111111111111111111111111111111111111111111111111111000110100000010010001001010111001101011110010101010110010011011001001110' %u: '10633823966279322740806214058000332366' %d: ' -4242424242424242424242' %x: '7ffffffffffff1a04895cd79559364e'"
6666
hw.module @constant_fold1(out res: !sim.fstring) {
67-
%preb = sim.fmt.lit " %b: '"
68-
%preu = sim.fmt.lit " %u: '"
69-
%pres = sim.fmt.lit " %d: '"
70-
%preh = sim.fmt.lit " %x: '"
71-
%q = sim.fmt.lit "'"
67+
%preb = sim.fmt.literal " %b: '"
68+
%preu = sim.fmt.literal " %u: '"
69+
%pres = sim.fmt.literal " %d: '"
70+
%preh = sim.fmt.literal " %x: '"
71+
%q = sim.fmt.literal "'"
7272

7373
%cst42_123 = hw.constant -4242424242424242424242 : i123
7474
%w123b42 = sim.fmt.bin %cst42_123 : i123
@@ -82,22 +82,22 @@ hw.module @constant_fold1(out res: !sim.fstring) {
8282

8383
// CHECK-LABEL: hw.module @constant_fold2
8484
hw.module @constant_fold2(in %foo: i1027, out res: !sim.fstring) {
85-
// CHECK: [[SDS:%.+]] = sim.fmt.lit " - "
85+
// CHECK: [[SDS:%.+]] = sim.fmt.literal " - "
8686
// CHECK: [[HEX:%.+]] = sim.fmt.hex %foo : i1027
8787
// CHECK: [[CAT:%.+]] = sim.fmt.concat ([[SDS]], [[HEX]], [[SDS]])
8888
// CHECK: hw.output [[CAT]] : !sim.fstring
8989

90-
%space = sim.fmt.lit " "
91-
%dash = sim.fmt.lit "-"
92-
%spaceDashSpace = sim.fmt.lit " - "
90+
%space = sim.fmt.literal " "
91+
%dash = sim.fmt.literal "-"
92+
%spaceDashSpace = sim.fmt.literal " - "
9393
%hex = sim.fmt.hex %foo : i1027
9494

9595
%res = sim.fmt.concat (%spaceDashSpace, %hex, %space, %dash, %space)
9696
hw.output %res : !sim.fstring
9797
}
9898

9999
// CHECK-LABEL: hw.module @constant_fold3
100-
// CHECK: sim.fmt.lit "Foo\0A\0D\00Foo\00\C8"
100+
// CHECK: sim.fmt.literal "Foo\0A\0D\00Foo\00\C8"
101101
hw.module @constant_fold3(in %zeroWitdh: i0, out res: !sim.fstring) {
102102
%F = hw.constant 70 : i7
103103
%o = hw.constant 111 : i8
@@ -120,27 +120,27 @@ hw.module @constant_fold3(in %zeroWitdh: i0, out res: !sim.fstring) {
120120

121121

122122
// CHECK-LABEL: hw.module @flatten_concat1
123-
// CHECK-DAG: %[[LH:.+]] = sim.fmt.lit "Hex: "
124-
// CHECK-DAG: %[[LD:.+]] = sim.fmt.lit "Dec: "
125-
// CHECK-DAG: %[[LB:.+]] = sim.fmt.lit "Bin: "
123+
// CHECK-DAG: %[[LH:.+]] = sim.fmt.literal "Hex: "
124+
// CHECK-DAG: %[[LD:.+]] = sim.fmt.literal "Dec: "
125+
// CHECK-DAG: %[[LB:.+]] = sim.fmt.literal "Bin: "
126126
// CHECK-DAG: %[[FH:.+]] = sim.fmt.hex %val : i8
127127
// CHECK-DAG: %[[FD:.+]] = sim.fmt.dec %val : i8
128128
// CHECK-DAG: %[[FB:.+]] = sim.fmt.bin %val : i8
129129
// CHECK-DAG: %[[CAT:.+]] = sim.fmt.concat (%[[LB]], %[[FB]], %[[LD]], %[[FD]], %[[LH]], %[[FH]])
130130
// CHECK: hw.output %[[CAT]] : !sim.fstring
131131

132132
hw.module @flatten_concat1(in %val : i8, out res: !sim.fstring) {
133-
%binLit = sim.fmt.lit "Bin: "
133+
%binLit = sim.fmt.literal "Bin: "
134134
%binVal = sim.fmt.bin %val : i8
135135
%binCat = sim.fmt.concat (%binLit, %binVal)
136136

137-
%decLit = sim.fmt.lit "Dec: "
137+
%decLit = sim.fmt.literal "Dec: "
138138
%decVal = sim.fmt.dec %val : i8
139139
%decCat = sim.fmt.concat (%decLit, %decVal, %nocat)
140140

141141
%nocat = sim.fmt.concat ()
142142

143-
%hexLit = sim.fmt.lit "Hex: "
143+
%hexLit = sim.fmt.literal "Hex: "
144144
%hexVal = sim.fmt.hex %val : i8
145145
%hexCat = sim.fmt.concat (%hexLit, %hexVal)
146146

@@ -149,14 +149,14 @@ hw.module @flatten_concat1(in %val : i8, out res: !sim.fstring) {
149149
}
150150

151151
// CHECK-LABEL: hw.module @flatten_concat2
152-
// CHECK-DAG: %[[F:.+]] = sim.fmt.lit "Foo"
153-
// CHECK-DAG: %[[FF:.+]] = sim.fmt.lit "FooFoo"
152+
// CHECK-DAG: %[[F:.+]] = sim.fmt.literal "Foo"
153+
// CHECK-DAG: %[[FF:.+]] = sim.fmt.literal "FooFoo"
154154
// CHECK-DAG: %[[CHR:.+]] = sim.fmt.char %val : i8
155155
// CHECK-DAG: %[[CAT:.+]] = sim.fmt.concat (%[[F]], %[[CHR]], %[[FF]], %[[CHR]], %[[FF]], %[[CHR]], %[[FF]], %[[CHR]], %[[FF]], %[[CHR]], %[[F]])
156156
// CHECK: hw.output %[[CAT]] : !sim.fstring
157157

158158
hw.module @flatten_concat2(in %val : i8, out res: !sim.fstring) {
159-
%foo = sim.fmt.lit "Foo"
159+
%foo = sim.fmt.literal "Foo"
160160
%char = sim.fmt.char %val : i8
161161

162162
%c = sim.fmt.concat (%foo, %char, %foo)

test/Dialect/Sim/print-canon.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
// CHECK-NOT: sim.print
55
hw.module @always_disabled(in %clock: !seq.clock) {
66
%false = hw.constant false
7-
%lit = sim.fmt.lit "Foo"
7+
%lit = sim.fmt.literal "Foo"
88
sim.print %lit on %clock if %false
99
}
1010

1111
// CHECK-LABEL: hw.module @emtpy_proc_print
1212
// CHECK-NOT: sim.proc.print
1313
hw.module @emtpy_proc_print(in %trigger: i1) {
1414
hw.triggered posedge %trigger {
15-
%epsilon = sim.fmt.lit ""
15+
%epsilon = sim.fmt.literal ""
1616
sim.proc.print %epsilon
1717
}
1818
}

0 commit comments

Comments
 (0)