Skip to content

Commit b139e8d

Browse files
committed
Replaced value stack by counter
1 parent 8b588c0 commit b139e8d

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

mlir/lib/Target/Cpp/TranslateToCpp.cpp

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,9 @@ struct CppEmitter {
211211
blockMapperScope(emitter.blockMapper),
212212
inductionVarMapperScope(emitter.loopInductionVarMapper),
213213
emitter(emitter) {
214-
emitter.valueInScopeCount.push(emitter.valueInScopeCount.top());
215214
emitter.labelInScopeCount.push(emitter.labelInScopeCount.top());
216215
}
217-
~Scope() { emitter.popStacksAndUpdate(); }
216+
~Scope() { emitter.labelInScopeCount.pop(); }
218217

219218
private:
220219
llvm::ScopedHashTableScope<Value, std::string> valueMapperScope;
@@ -305,7 +304,6 @@ struct CppEmitter {
305304
/// Map from block to name of C++ label.
306305
BlockMapper blockMapper;
307306

308-
std::stack<int64_t> valueInScopeCount;
309307
std::stack<int64_t> labelInScopeCount;
310308

311309
uint64_t loopNestingLevel{0};
@@ -1338,7 +1336,6 @@ CppEmitter::CppEmitter(raw_ostream &os, bool declareVariablesAtTop,
13381336
StringRef onlyTu, bool constantsAsVariables)
13391337
: os(os), declareVariablesAtTop(declareVariablesAtTop),
13401338
onlyTu(onlyTu.str()), constantsAsVariables(constantsAsVariables) {
1341-
valueInScopeCount.push(0);
13421339
labelInScopeCount.push(0);
13431340
}
13441341

@@ -1386,8 +1383,7 @@ StringRef CppEmitter::getOrCreateName(Value val) {
13861383
"cacheDeferredOpResult should have been called on this value, "
13871384
"update the emitOperation function.");
13881385

1389-
valueMapper.insert(val,
1390-
formatv("v{0}", ++valueInScopeCount.top() + valueCount));
1386+
valueMapper.insert(val, formatv("v{0}", ++valueCount));
13911387
}
13921388
return *valueMapper.begin(val);
13931389
}
@@ -1404,13 +1400,11 @@ StringRef CppEmitter::getOrCreateName(emitc::ForOp forOp) {
14041400
char range = 'z' - 'i';
14051401
if (identifier >= 0 && identifier <= range) {
14061402
loopInductionVarMapper.insert(
1407-
val, formatv("{0}_{1}", (char)(identifier + 'i'),
1408-
++valueInScopeCount.top() + valueCount));
1403+
val, formatv("{0}_{1}", (char)(identifier + 'i'), ++valueCount));
14091404
} else {
14101405
// If running out of letters, continue with zX
14111406
loopInductionVarMapper.insert(
1412-
val, formatv("z{0}_{1}", identifier - range - 1,
1413-
++valueInScopeCount.top() + valueCount));
1407+
val, formatv("z{0}_{1}", identifier - range - 1, ++valueCount));
14141408
}
14151409
}
14161410
return *loopInductionVarMapper.begin(val);
@@ -2005,16 +1999,6 @@ LogicalResult CppEmitter::emitTupleType(Location loc, ArrayRef<Type> types) {
20051999
return success();
20062000
}
20072001

2008-
void CppEmitter::popStacksAndUpdate() {
2009-
uint64_t newValues = valueInScopeCount.top();
2010-
2011-
valueInScopeCount.pop();
2012-
labelInScopeCount.pop();
2013-
2014-
newValues -= valueInScopeCount.top();
2015-
valueCount += newValues;
2016-
}
2017-
20182002
void CppEmitter::resetValueCounter() { valueCount = 0; }
20192003

20202004
void CppEmitter::decreaseLoopNestingLevel() { loopNestingLevel--; }

0 commit comments

Comments
 (0)