Skip to content

Commit f4d0c63

Browse files
committed
rename constants when used in an initial instruction
1 parent 89218e9 commit f4d0c63

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

mlir/lib/Conversion/Normalize/Normalize.cpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ struct NormalizePass : public impl::NormalizeBase<NormalizePass> {
5656
SmallPtrSet<const mlir::Operation *, 32> &visited);
5757

5858
bool isInitialOperation(mlir::Operation *const op) const noexcept;
59-
void nameAsInitialOperation(mlir::Operation *op);
59+
void nameAsInitialOperation(
60+
mlir::Operation *op,
61+
llvm::SmallPtrSet<const mlir::Operation *, 32> &visited);
6062
void nameAsRegularOperation(
6163
mlir::Operation *op,
6264
llvm::SmallPtrSet<const mlir::Operation *, 32> &visited);
@@ -101,7 +103,7 @@ void NormalizePass::RenameOperation(
101103
visited.insert(op);
102104

103105
if (isInitialOperation(op)) {
104-
nameAsInitialOperation(op);
106+
nameAsInitialOperation(op, visited);
105107
} else {
106108
nameAsRegularOperation(op, visited);
107109
}
@@ -158,7 +160,9 @@ std::string inline split(std::string_view str, const char &delimiter,
158160
return nullptr;
159161
}
160162

161-
void NormalizePass::nameAsInitialOperation(mlir::Operation *op) {
163+
void NormalizePass::nameAsInitialOperation(
164+
mlir::Operation *op,
165+
llvm::SmallPtrSet<const mlir::Operation *, 32> &visited) {
162166
SmallVector<SmallString<64>, 4> Operands;
163167

164168
if (op->getNumOperands() == 0) {
@@ -175,23 +179,28 @@ void NormalizePass::nameAsInitialOperation(mlir::Operation *op) {
175179
} else {
176180
for (mlir::Value operand : op->getOperands()) {
177181
if (mlir::Operation *defOp = operand.getDefiningOp()) {
182+
RenameOperation(defOp, visited);
183+
178184
std::string TextRepresentation;
179185
mlir::AsmState state(defOp, flags);
180186
llvm::raw_string_ostream Stream(TextRepresentation);
181187
defOp->print(Stream, state);
182-
std::string hash = to_string(strHash(split(Stream.str(), '=', 1)));
183-
Operands.push_back(StringRef(hash));
188+
Operands.push_back(StringRef(split(Stream.str(), '=', 0)));
184189
} else if (auto ba = dyn_cast<mlir::BlockArgument>(operand)) {
185190
mlir::Block *ownerBlock = ba.getOwner();
186191
unsigned argIndex = ba.getArgNumber();
187-
if (auto func = dyn_cast<mlir::func::FuncOp>(ownerBlock->getParentOp())) {
192+
if (auto func =
193+
dyn_cast<mlir::func::FuncOp>(ownerBlock->getParentOp())) {
188194
if (&func.front() == ownerBlock) {
189-
Operands.push_back(StringRef(std::string("funcArg" + std::to_string(argIndex))));
195+
Operands.push_back(
196+
StringRef(std::string("funcArg" + std::to_string(argIndex))));
190197
} else {
191-
Operands.push_back(StringRef(std::string("blockArg" + std::to_string(argIndex))));
198+
Operands.push_back(
199+
StringRef(std::string("blockArg" + std::to_string(argIndex))));
192200
}
193201
} else {
194-
Operands.push_back(StringRef(std::string("blockArg" + std::to_string(argIndex))));
202+
Operands.push_back(
203+
StringRef(std::string("blockArg" + std::to_string(argIndex))));
195204
}
196205
}
197206
}
@@ -252,12 +261,15 @@ void NormalizePass::nameAsRegularOperation(
252261
unsigned argIndex = ba.getArgNumber();
253262
if (auto func = dyn_cast<mlir::func::FuncOp>(ownerBlock->getParentOp())) {
254263
if (&func.front() == ownerBlock) {
255-
Operands.push_back(StringRef(std::string("funcArg" + std::to_string(argIndex))));
264+
Operands.push_back(
265+
StringRef(std::string("funcArg" + std::to_string(argIndex))));
256266
} else {
257-
Operands.push_back(StringRef(std::string("blockArg" + std::to_string(argIndex))));
267+
Operands.push_back(
268+
StringRef(std::string("blockArg" + std::to_string(argIndex))));
258269
}
259270
} else {
260-
Operands.push_back(StringRef(std::string("blockArg" + std::to_string(argIndex))));
271+
Operands.push_back(
272+
StringRef(std::string("blockArg" + std::to_string(argIndex))));
261273
}
262274
}
263275
}

0 commit comments

Comments
 (0)