Skip to content

Commit

Permalink
Make defered emission ops print inline constants again
Browse files Browse the repository at this point in the history
  • Loading branch information
lmendesp-amd committed Dec 11, 2024
1 parent ed4fee6 commit 5981c2f
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions mlir/lib/Target/Cpp/TranslateToCpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ struct CppEmitter {
return emittedExpressionPrecedence.back();
}

/// Emits value as an operands of an operation to the specified stream.
LogicalResult emitOperandToStream(Value value, raw_ostream &ss);

/// Emits attribute to the specified stream or returns failure.
LogicalResult emitAttributeToStream(Location loc, Attribute attr,
raw_ostream &ss);
Expand Down Expand Up @@ -1319,7 +1322,9 @@ std::string CppEmitter::getSubscriptName(emitc::SubscriptOp op) {
llvm::raw_string_ostream ss(out);
ss << getOrCreateName(op.getValue());
for (auto index : op.getIndices()) {
ss << "[" << getOrCreateName(index) << "]";
ss << "[";
emitOperandToStream(index, ss);
ss << "]";
}
return out;
}
Expand Down Expand Up @@ -1527,16 +1532,20 @@ LogicalResult CppEmitter::emitExpression(ExpressionOp expressionOp) {
}

LogicalResult CppEmitter::emitOperand(Value value) {
return emitOperandToStream(value, os);
}

LogicalResult CppEmitter::emitOperandToStream(Value value, raw_ostream &ss) {
Operation *def = value.getDefiningOp();

if (auto constant = dyn_cast_if_present<ConstantOp>(def);
constant && !shouldUseConstantsAsVariables()) {
os << "(";
if (failed(emitType(value.getLoc(), constant.getType())))
ss << "(";
if (failed(emitTypeToStream(value.getLoc(), constant.getType(), ss)))
return failure();
os << ") ";
ss << ") ";

if (failed(emitAttribute(value.getLoc(), constant.getValue())))
if (failed(emitAttributeToStream(value.getLoc(), constant.getValue(), ss)))
return failure();

return success();
Expand Down Expand Up @@ -1572,7 +1581,7 @@ LogicalResult CppEmitter::emitOperand(Value value) {
if (expressionOp && shouldBeInlined(expressionOp))
return emitExpression(expressionOp);

os << getOrCreateName(value);
ss << getOrCreateName(value);
return success();
}

Expand Down

0 comments on commit 5981c2f

Please sign in to comment.