Skip to content

Commit 6976ca6

Browse files
Address comments from final review of @ftynse.
1 parent 2f5a296 commit 6976ca6

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

mlir/include/mlir/Dialect/Transform/IR/TransformDialect.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ def Transform_Dialect : Dialect {
4343
constexpr const static ::llvm::StringLiteral kArgReadOnlyAttrName =
4444
"transform.readonly";
4545

46-
/// Above attribute names as `StringAttr`.
46+
/// Names of the attributes indicating whether an argument of an external
47+
/// transform dialect symbol is consumed or only read.
4748
StringAttr getConsumedAttrName() const {
4849
return StringAttr::get(getContext(), kArgConsumedAttrName);
4950
}

mlir/lib/Dialect/Transform/Transforms/TransformInterpreterPassBase.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ constexpr static llvm::StringLiteral kTransformDialectTagPayloadRootValue =
5050
constexpr static llvm::StringLiteral
5151
kTransformDialectTagTransformContainerValue = "transform_container";
5252

53-
namespace {
54-
5553
/// Utility to parse the content of a `transformFileName` MLIR file containing
5654
/// a transform dialect specification.
5755
static LogicalResult
@@ -180,8 +178,9 @@ printReproCall(llvm::raw_ostream &os, StringRef rootOpName, StringRef passName,
180178

181179
/// Prints the module rooted at `root` to `os` and appends
182180
/// `transformContainer` if it is not nested in `root`.
183-
llvm::raw_ostream &printModuleForRepro(llvm::raw_ostream &os, Operation *root,
184-
Operation *transform) {
181+
static llvm::raw_ostream &printModuleForRepro(llvm::raw_ostream &os,
182+
Operation *root,
183+
Operation *transform) {
185184
root->print(os);
186185
if (!root->isAncestor(transform))
187186
transform->print(os);
@@ -190,12 +189,13 @@ llvm::raw_ostream &printModuleForRepro(llvm::raw_ostream &os, Operation *root,
190189

191190
/// Saves the payload and the transform IR into a temporary file and reports
192191
/// the file name to `os`.
193-
void saveReproToTempFile(
194-
llvm::raw_ostream &os, Operation *target, Operation *transform,
195-
StringRef passName, const Pass::Option<std::string> &debugPayloadRootTag,
196-
const Pass::Option<std::string> &debugTransformRootTag,
197-
const Pass::Option<std::string> &transformLibraryFileName,
198-
StringRef binaryName) {
192+
static void
193+
saveReproToTempFile(llvm::raw_ostream &os, Operation *target,
194+
Operation *transform, StringRef passName,
195+
const Pass::Option<std::string> &debugPayloadRootTag,
196+
const Pass::Option<std::string> &debugTransformRootTag,
197+
const Pass::Option<std::string> &transformLibraryFileName,
198+
StringRef binaryName) {
199199
using llvm::sys::fs::TempFile;
200200
Operation *root = getRootOperation(target);
201201

@@ -298,14 +298,15 @@ static void performOptionalDebugActions(
298298
/// has to be a declaration (aka has to be external) and `func2` either has to
299299
/// be a declaration as well, or it has to be public (otherwise, it wouldn't
300300
/// be visible by `func1`).
301-
bool canMergeInto(FunctionOpInterface func1, FunctionOpInterface func2) {
301+
static bool canMergeInto(FunctionOpInterface func1, FunctionOpInterface func2) {
302302
return func1.isExternal() && (func2.isPublic() || func2.isExternal());
303303
}
304304

305305
/// Merge `func1` into `func2`. The two ops must be inside the same parent op
306306
/// and mergable according to `canMergeInto`. The function erases `func1` such
307307
/// that only `func2` exists when the function returns.
308-
LogicalResult mergeInto(FunctionOpInterface func1, FunctionOpInterface func2) {
308+
static LogicalResult mergeInto(FunctionOpInterface func1,
309+
FunctionOpInterface func2) {
309310
assert(canMergeInto(func1, func2));
310311
assert(func1->getParentOp() == func2->getParentOp() &&
311312
"expected func1 and func2 to be in the same parent op");
@@ -319,7 +320,7 @@ LogicalResult mergeInto(FunctionOpInterface func1, FunctionOpInterface func2) {
319320

320321
// Check and merge argument attributes.
321322
MLIRContext *context = func1->getContext();
322-
auto td = context->getLoadedDialect<transform::TransformDialect>();
323+
auto *td = context->getLoadedDialect<transform::TransformDialect>();
323324
StringAttr consumedName = td->getConsumedAttrName();
324325
StringAttr readOnlyName = td->getReadOnlyAttrName();
325326
for (unsigned i = 0, e = func1.getNumArguments(); i < e; ++i) {
@@ -359,6 +360,10 @@ LogicalResult mergeInto(FunctionOpInterface func1, FunctionOpInterface func2) {
359360
/// instances of `SymbolOpInterface`, where collisions are allowed if at least
360361
/// one of the two is external, in which case the other op preserved (or any one
361362
/// of the two if both are external).
363+
// TODO: Reconsider cloning individual ops rather than forcing users of the
364+
// function to clone (or move) `other` in order to improve efficiency.
365+
// This might primarily make sense if we can also prune the symbols that
366+
// are merged to a subset (such as those that are actually used).
362367
static LogicalResult mergeSymbolsInto(Operation *target,
363368
OwningOpRef<Operation *> other) {
364369
assert(target->hasTrait<OpTrait::SymbolTable>() &&
@@ -374,6 +379,7 @@ static LogicalResult mergeSymbolsInto(Operation *target,
374379
// Rename private symbols in both ops in order to resolve conflicts that can
375380
// be resolved that way.
376381
LLVM_DEBUG(DBGS() << "renaming private symbols to resolve conflicts:\n");
382+
// TODO: Do we *actually* need to test in both directions?
377383
for (auto &&[symbolTable, otherSymbolTable] : llvm::zip(
378384
SmallVector<SymbolTable *, 2>{&targetSymbolTable, &otherSymbolTable},
379385
SmallVector<SymbolTable *, 2>{&otherSymbolTable,
@@ -519,8 +525,6 @@ static LogicalResult mergeSymbolsInto(Operation *target,
519525
return success();
520526
}
521527

522-
} // namespace
523-
524528
LogicalResult transform::detail::interpreterBaseRunOnOperationImpl(
525529
Operation *target, StringRef passName,
526530
const std::shared_ptr<OwningOpRef<ModuleOp>> &sharedTransformModule,

0 commit comments

Comments
 (0)