@@ -378,10 +378,11 @@ static LogicalResult printOperation(CppEmitter &emitter,
378378}
379379
380380static LogicalResult printOperation (CppEmitter &emitter,
381- emitc::LValueToRValueOp lValueToRValueOp) {
382- // Add name to cache so that `hasValueInScope` works.
383- emitter.getOrCreateName (lValueToRValueOp.getResult ());
384- return success ();
381+ emitc::LValueLoadOp lValueLoadOp) {
382+ if (failed (emitter.emitAssignPrefix (*lValueLoadOp)))
383+ return failure ();
384+
385+ return emitter.emitOperand (lValueLoadOp.getOperand ());
385386}
386387
387388static LogicalResult printOperation (CppEmitter &emitter,
@@ -961,7 +962,7 @@ static LogicalResult printFunctionBody(CppEmitter &emitter,
961962 // regions.
962963 WalkResult result =
963964 functionOp->walk <WalkOrder::PreOrder>([&](Operation *op) -> WalkResult {
964- if (isa<emitc::LiteralOp, emitc::LValueToRValueOp >(op) ||
965+ if (isa<emitc::LiteralOp>(op) ||
965966 (isa<emitc::ApplyOp>(op) &&
966967 cast<emitc::ApplyOp>(op).getApplicableOperator () == " *" ) ||
967968 isa<emitc::ExpressionOp>(op->getParentOp ()) ||
@@ -1153,15 +1154,6 @@ std::string CppEmitter::getSubscriptName(emitc::SubscriptOp op) {
11531154StringRef CppEmitter::getOrCreateName (Value val) {
11541155 if (auto literal = dyn_cast_if_present<emitc::LiteralOp>(val.getDefiningOp ()))
11551156 return literal.getValue ();
1156- if (auto lValueToRValue =
1157- dyn_cast_if_present<emitc::LValueToRValueOp>(val.getDefiningOp ())) {
1158- Value operand = lValueToRValue.getOperand ();
1159- valueMapper.insert (val, " ***UNUSED***" );
1160-
1161- assert (hasValueInScope (operand));
1162-
1163- return getOrCreateName (operand);
1164- }
11651157 if (!valueMapper.count (val)) {
11661158 if (auto subscript =
11671159 dyn_cast_if_present<emitc::SubscriptOp>(val.getDefiningOp ())) {
@@ -1428,7 +1420,7 @@ LogicalResult CppEmitter::emitVariableAssignment(OpResult result) {
14281420
14291421LogicalResult CppEmitter::emitVariableDeclaration (OpResult result,
14301422 bool trailingSemicolon) {
1431- if (isa<emitc::SubscriptOp>(result.getDefiningOp ()))
1423+ if (isa<emitc::SubscriptOp, emitc::GetGlobalOp >(result.getDefiningOp ()))
14321424 return success ();
14331425 if (hasValueInScope (result)) {
14341426 return result.getDefiningOp ()->emitError (
@@ -1532,11 +1524,11 @@ LogicalResult CppEmitter::emitOperation(Operation &op, bool trailingSemicolon) {
15321524 emitc::ConditionalOp, emitc::ConstantOp, emitc::DeclareFuncOp,
15331525 emitc::DivOp, emitc::ExpressionOp, emitc::ForOp, emitc::FuncOp,
15341526 emitc::GlobalOp, emitc::GetGlobalOp, emitc::IfOp,
1535- emitc::IncludeOp, emitc::LogicalAndOp,
1536- emitc::LValueToRValueOp , emitc::LogicalNotOp , emitc::RemOp ,
1537- emitc::LogicalOrOp , emitc::MulOp , emitc::ReturnOp ,
1538- emitc::SubOp , emitc::SubscriptOp , emitc::UnaryMinusOp ,
1539- emitc::UnaryPlusOp, emitc::VariableOp, emitc:: VerbatimOp>(
1527+ emitc::IncludeOp, emitc::LogicalAndOp, emitc::LogicalNotOp,
1528+ emitc::LValueLoadOp , emitc::RemOp , emitc::LogicalOrOp ,
1529+ emitc::MulOp , emitc::ReturnOp , emitc::SubOp, emitc::SubscriptOp ,
1530+ emitc::UnaryMinusOp , emitc::UnaryPlusOp , emitc::VariableOp ,
1531+ emitc::VerbatimOp>(
15401532 [&](auto op) { return printOperation (*this , op); })
15411533 // Func ops.
15421534 .Case <func::CallOp, func::FuncOp, func::ReturnOp>(
@@ -1549,7 +1541,8 @@ LogicalResult CppEmitter::emitOperation(Operation &op, bool trailingSemicolon) {
15491541 if (failed (status))
15501542 return failure ();
15511543
1552- if (isa<emitc::LiteralOp, emitc::LValueToRValueOp, emitc::SubscriptOp, emitc::GetGlobalOp>(op))
1544+ if (isa<emitc::LiteralOp, emitc::SubscriptOp,
1545+ emitc::GetGlobalOp>(op))
15531546 return success ();
15541547
15551548 if (getEmittedExpression () ||
0 commit comments