Skip to content

Commit

Permalink
[NFC][Sim] Rename "formatting token" to "formatting fragment"
Browse files Browse the repository at this point in the history
Avoid the ambigous "token" term and use the same naming as the Moore dialect for
a part of a formatting string.

Signed-off-by: Leon Hielscher <hielscher@fzi.de>
  • Loading branch information
fzi-hielscher committed Oct 31, 2024
1 parent 9d92072 commit f91b47e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions include/circt/Dialect/Sim/SimOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def DPICallOp : SimOp<"func.dpi.call",
}

def FormatLitOp : SimOp<"fmt.lit", [Pure, ConstantLike]> {
let summary = "Literal string token";
let summary = "Literal string fragment";
let description = [{
Creates a constant, raw ASCII string literal for formatted printing.
The given string attribute will be outputted as is,
Expand Down Expand Up @@ -300,7 +300,7 @@ def FormatStringConcatOp : SimOp<"fmt.concat", [Pure]> {

let extraClassDeclaration = [{
/// Returns true iff all of the input strings are primitive
/// (i.e. non-concatenated) tokens or block arguments.
/// (i.e. non-concatenated) fragments or block arguments.
bool isFlat() {
return llvm::none_of(getInputs(), [](Value operand) {
return !!operand.getDefiningOp<circt::sim::FormatStringConcatOp>();
Expand Down
8 changes: 4 additions & 4 deletions include/circt/Dialect/Sim/SimTypes.td
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ def FormatStringType : SimTypeDef<"FormatString"> {

let summary = "Format string type";
let description = [{
A format string type represents either a single formatting token or the
concatenation of an arbitrary but finite number of tokens.
A formatting token is either a static string literal or the association of
a dynamic hardware value with a format specifier.
A format string type represents either a single formatting fragment or the
concatenation of an arbitrary but finite number of fragments.
A formatting fragment is either a static string literal or the association
of a dynamic hardware value with a format specifier.
}];
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Dialect/Sim/SimOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ LogicalResult FormatStringConcatOp::getFlattenedInputs(
bool isCyclic = false;

// Perform a DFS on this operation's concatenated operands,
// collect the leaf format string tokens.
// collect the leaf format string fragments.
concatStack.insert({*this, 0});
while (!concatStack.empty()) {
auto &top = concatStack.back();
Expand Down
38 changes: 19 additions & 19 deletions lib/Dialect/Sim/Transforms/ProceduralizeSim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct ProceduralizeSimPass : impl::ProceduralizeSimBase<ProceduralizeSimPass> {
private:
LogicalResult proceduralizePrintOps(Value clock,
ArrayRef<PrintFormattedOp> printOps);
SmallVector<Operation *> getPrintTokens(PrintFormattedOp op);
SmallVector<Operation *> getPrintFragments(PrintFormattedOp op);
void cleanup();

// Mapping Clock -> List of printf ops
Expand All @@ -60,8 +60,8 @@ LogicalResult ProceduralizeSimPass::proceduralizePrintOps(

// List of uniqued values to become arguments of the TriggeredOp.
SmallSetVector<Value, 4> arguments;
// Map printf ops -> flattened list of tokens
SmallDenseMap<PrintFormattedOp, SmallVector<Operation *>, 4> tokenMap;
// Map printf ops -> flattened list of fragments
SmallDenseMap<PrintFormattedOp, SmallVector<Operation *>, 4> fragmentMap;
SmallVector<Location> locs;
SmallDenseSet<Value, 1> alwaysEnabledConditions;

Expand All @@ -82,7 +82,7 @@ LogicalResult ProceduralizeSimPass::proceduralizePrintOps(
// Accumulate locations
locs.push_back(printOp.getLoc());

// Get the flat list of formatting tokens and collect leaf tokens
// Get the flat list of formatting fragments and collect leaf fragments
SmallVector<Value> flatString;
if (auto concatInput =
printOp.getInput().getDefiningOp<FormatStringConcatOp>()) {
Expand All @@ -96,22 +96,22 @@ LogicalResult ProceduralizeSimPass::proceduralizePrintOps(
flatString.push_back(printOp.getInput());
}

auto &tokenList = tokenMap[printOp];
assert(tokenList.empty() && "printf operation visited twice.");
auto &fragmentList = fragmentMap[printOp];
assert(fragmentList.empty() && "printf operation visited twice.");

for (auto &token : flatString) {
auto *fmtOp = token.getDefiningOp();
for (auto &fragment : flatString) {
auto *fmtOp = fragment.getDefiningOp();
if (!fmtOp) {
printOp.emitError("Proceduralization of format strings passed as block "
"argument is unsupported.");
return failure();
}
tokenList.push_back(fmtOp);
// For non-literal tokens, the value to be formatted has to become an
fragmentList.push_back(fmtOp);
// For non-literal fragments, the value to be formatted has to become an
// argument.
if (!llvm::isa<FormatLitOp>(fmtOp)) {
auto fmtVal = getFormattedValue(fmtOp);
assert(!!fmtVal && "Unexpected foramtting token op.");
assert(!!fmtVal && "Unexpected foramtting fragment op.");
arguments.insert(fmtVal);
}
}
Expand Down Expand Up @@ -161,18 +161,18 @@ LogicalResult ProceduralizeSimPass::proceduralizePrintOps(
}
}

// Create a copy of the required token operations within the TriggeredOp's
// body.
auto tokens = tokenMap[printOp];
// Create a copy of the required fragment operations within the
// TriggeredOp's body.
auto fragments = fragmentMap[printOp];
SmallVector<Value> clonedOperands;
builder.setInsertionPointToStart(trigOp.getBodyBlock());
for (auto *token : tokens) {
auto &fmtCloned = cloneMap[token];
for (auto *fragment : fragments) {
auto &fmtCloned = cloneMap[fragment];
if (!fmtCloned)
fmtCloned = builder.clone(*token, argumentMapper);
fmtCloned = builder.clone(*fragment, argumentMapper);
clonedOperands.push_back(fmtCloned->getResult(0));
}
// Concatenate tokens to a single value if necessary.
// Concatenate fragments to a single value if necessary.
Value procPrintInput;
if (clonedOperands.size() != 1)
procPrintInput = builder.createOrFold<FormatStringConcatOp>(
Expand Down Expand Up @@ -208,7 +208,7 @@ LogicalResult ProceduralizeSimPass::proceduralizePrintOps(
return success();
}

// Prune the DAGs of formatting tokens left outside of the newly created
// Prune the DAGs of formatting fragments left outside of the newly created
// TriggeredOps.
void ProceduralizeSimPass::cleanup() {
SmallVector<Operation *> cleanupNextList;
Expand Down

0 comments on commit f91b47e

Please sign in to comment.