Skip to content

Commit 303d7fa

Browse files
authored
[MLIR][Interfaces] Make LoopLikeOpInterface inheritable outside of MLIR (#128743)
Many interface methods did not prefix the `mlir` namespace, which prevented inheriting from this interface from an interface defined outside the `mlir` namespace. Prefix namespaces everywhere to enable this.
1 parent c79e867 commit 303d7fa

File tree

1 file changed

+40
-35
lines changed

1 file changed

+40
-35
lines changed

mlir/include/mlir/Interfaces/LoopLikeInterface.td

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,12 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
180180
For loop operations that dont yield a value, this should return
181181
std::nullopt.
182182
}],
183-
/*retTy=*/"std::optional<::llvm::MutableArrayRef<::mlir::OpOperand>>",
183+
/*retTy=*/"::std::optional<::llvm::MutableArrayRef<::mlir::OpOperand>>",
184184
/*methodName=*/"getYieldedValuesMutable",
185185
/*args=*/(ins),
186186
/*methodBody=*/"",
187187
/*defaultImplementation=*/[{
188-
return std::nullopt;
188+
return ::std::nullopt;
189189
}]
190190
>,
191191
InterfaceMethod<[{
@@ -239,7 +239,7 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
239239
/// Returns if a block is inside a loop (within the current function). This
240240
/// can either be because the block is nested inside a LoopLikeInterface, or
241241
/// because the control flow graph is cyclic
242-
static bool blockIsInLoop(Block *block);
242+
static bool blockIsInLoop(::mlir::Block *block);
243243
}];
244244

245245
let extraSharedClassDeclaration = [{
@@ -249,31 +249,31 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
249249
auto inductionVars = $_op.getLoopInductionVars();
250250
if (inductionVars.has_value() && (*inductionVars).size() == 1)
251251
return (*inductionVars)[0];
252-
return std::nullopt;
252+
return ::std::nullopt;
253253
}
254254
/// Return the single lower bound value or attribute if it exists, otherwise
255255
/// return std::nullopt.
256256
::std::optional<::mlir::OpFoldResult> getSingleLowerBound() {
257257
auto lowerBounds = $_op.getLoopLowerBounds();
258258
if (lowerBounds.has_value() && (*lowerBounds).size() == 1)
259259
return (*lowerBounds)[0];
260-
return std::nullopt;
260+
return ::std::nullopt;
261261
}
262262
/// Return the single step value or attribute if it exists, otherwise
263263
/// return std::nullopt.
264264
::std::optional<::mlir::OpFoldResult> getSingleStep() {
265265
auto steps = $_op.getLoopSteps();
266266
if (steps.has_value() && (*steps).size() == 1)
267267
return (*steps)[0];
268-
return std::nullopt;
268+
return ::std::nullopt;
269269
}
270270
/// Return the single upper bound value or attribute if it exists, otherwise
271271
/// return std::nullopt.
272272
::std::optional<::mlir::OpFoldResult> getSingleUpperBound() {
273273
auto upperBounds = $_op.getLoopUpperBounds();
274274
if (upperBounds.has_value() && (*upperBounds).size() == 1)
275275
return (*upperBounds)[0];
276-
return std::nullopt;
276+
return ::std::nullopt;
277277
}
278278

279279
/// Append the specified additional "init" operands: replace this loop with
@@ -287,8 +287,9 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
287287
bool replaceInitOperandUsesInLoop) {
288288
return $_op.replaceWithAdditionalYields(
289289
rewriter, newInitOperands, replaceInitOperandUsesInLoop,
290-
[](OpBuilder &b, Location loc, ArrayRef<BlockArgument> newBBArgs) {
291-
return SmallVector<Value>(newBBArgs);
290+
[](::mlir::OpBuilder &b, ::mlir::Location loc,
291+
::mlir::ArrayRef<::mlir::BlockArgument> newBBArgs) {
292+
return ::mlir::SmallVector<::mlir::Value>(newBBArgs);
292293
});
293294
}
294295

@@ -298,9 +299,9 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
298299
auto mutableValues = $_op.getYieldedValuesMutable();
299300
if (!mutableValues || mutableValues->empty())
300301
return {};
301-
Operation *yieldOp = mutableValues->begin()->getOwner();
302+
::mlir::Operation *yieldOp = mutableValues->begin()->getOwner();
302303
unsigned firstOperandIndex = mutableValues->begin()->getOperandNumber();
303-
return OperandRange(
304+
return ::mlir::OperandRange(
304305
yieldOp->operand_begin() + firstOperandIndex,
305306
yieldOp->operand_begin() + firstOperandIndex + mutableValues->size());
306307
}
@@ -312,107 +313,111 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
312313
if (initsMutable.empty())
313314
return ::mlir::OperandRange($_op->operand_end(), $_op->operand_end());
314315
unsigned firstOperandIndex = initsMutable.begin()->getOperandNumber();
315-
return OperandRange(
316+
return ::mlir::OperandRange(
316317
$_op->operand_begin() + firstOperandIndex,
317318
$_op->operand_begin() + firstOperandIndex + initsMutable.size());
318319
}
319320

320321
/// Return the region iter_arg that corresponds to the given init operand.
321322
/// Return an "empty" block argument if the given operand is not an init
322323
/// operand of this loop op.
323-
BlockArgument getTiedLoopRegionIterArg(OpOperand *opOperand) {
324+
::mlir::BlockArgument getTiedLoopRegionIterArg(
325+
::mlir::OpOperand *opOperand) {
324326
auto initsMutable = $_op.getInitsMutable();
325-
auto it = llvm::find(initsMutable, *opOperand);
327+
auto it = ::llvm::find(initsMutable, *opOperand);
326328
if (it == initsMutable.end())
327329
return {};
328-
return $_op.getRegionIterArgs()[std::distance(initsMutable.begin(), it)];
330+
return $_op.getRegionIterArgs()[
331+
::std::distance(initsMutable.begin(), it)];
329332
}
330333

331334
/// Return the region iter_arg that corresponds to the given loop result.
332335
/// Return an "empty" block argument if the given OpResult is not a loop
333336
/// result or if this op does not expose any loop results.
334-
BlockArgument getTiedLoopRegionIterArg(OpResult opResult) {
337+
::mlir::BlockArgument getTiedLoopRegionIterArg(::mlir::OpResult opResult) {
335338
auto loopResults = $_op.getLoopResults();
336339
if (!loopResults)
337340
return {};
338-
auto it = llvm::find(*loopResults, opResult);
341+
auto it = ::llvm::find(*loopResults, opResult);
339342
if (it == loopResults->end())
340343
return {};
341-
return $_op.getRegionIterArgs()[std::distance(loopResults->begin(), it)];
344+
return $_op.getRegionIterArgs()[
345+
::std::distance(loopResults->begin(), it)];
342346
}
343347

344348
/// Return the init operand that corresponds to the given region iter_arg.
345349
/// Return "nullptr" if the given block argument is not a region iter_arg
346350
/// of this loop op.
347-
OpOperand *getTiedLoopInit(BlockArgument bbArg) {
351+
::mlir::OpOperand *getTiedLoopInit(::mlir::BlockArgument bbArg) {
348352
auto iterArgs = $_op.getRegionIterArgs();
349-
auto it = llvm::find(iterArgs, bbArg);
353+
auto it = ::llvm::find(iterArgs, bbArg);
350354
if (it == iterArgs.end())
351355
return {};
352-
return &$_op.getInitsMutable()[std::distance(iterArgs.begin(), it)];
356+
return &$_op.getInitsMutable()[::std::distance(iterArgs.begin(), it)];
353357
}
354358

355359
/// Return the init operand that corresponds to the given loop result.
356360
/// Return "nullptr" if the given OpResult is not a loop result or if this
357361
/// op does not expose any loop results.
358-
OpOperand *getTiedLoopInit(OpResult opResult) {
362+
::mlir::OpOperand *getTiedLoopInit(::mlir::OpResult opResult) {
359363
auto loopResults = $_op.getLoopResults();
360364
if (!loopResults)
361365
return nullptr;
362-
auto it = llvm::find(*loopResults, opResult);
366+
auto it = ::llvm::find(*loopResults, opResult);
363367
if (it == loopResults->end())
364368
return nullptr;
365-
return &$_op.getInitsMutable()[std::distance(loopResults->begin(), it)];
369+
return &$_op.getInitsMutable()[::std::distance(
370+
loopResults->begin(), it)];
366371
}
367372

368373
/// Return the yielded value that corresponds to the given region iter_arg.
369374
/// Return "nullptr" if the given block argument is not a region iter_arg
370375
/// of this loop op or if there is no yield corresponding to this `bbArg`.
371-
OpOperand *getTiedLoopYieldedValue(BlockArgument bbArg) {
376+
::mlir::OpOperand *getTiedLoopYieldedValue(::mlir::BlockArgument bbArg) {
372377
auto iterArgs = $_op.getRegionIterArgs();
373-
auto it = llvm::find(iterArgs, bbArg);
378+
auto it = ::llvm::find(iterArgs, bbArg);
374379
if (it == iterArgs.end())
375380
return {};
376-
std::optional<llvm::MutableArrayRef<::mlir::OpOperand>> yieldValues =
381+
::std::optional<::llvm::MutableArrayRef<::mlir::OpOperand>> yieldValues =
377382
$_op.getYieldedValuesMutable();
378383
if (!yieldValues)
379384
return {};
380-
return &yieldValues.value()[std::distance(iterArgs.begin(), it)];
385+
return &yieldValues.value()[::std::distance(iterArgs.begin(), it)];
381386
}
382387

383388
/// Return the loop result that corresponds to the given init operand.
384389
/// Return an "empty" OpResult if the given operand is not an init operand
385390
/// of this loop op or if this op does not expose any loop results.
386-
OpResult getTiedLoopResult(OpOperand *opOperand) {
391+
::mlir::OpResult getTiedLoopResult(::mlir::OpOperand *opOperand) {
387392
auto loopResults = $_op.getLoopResults();
388393
if (!loopResults)
389394
return {};
390395
auto initsMutable = $_op.getInitsMutable();
391-
auto it = llvm::find(initsMutable, *opOperand);
396+
auto it = ::llvm::find(initsMutable, *opOperand);
392397
if (it == initsMutable.end())
393398
return {};
394-
return (*loopResults)[std::distance(initsMutable.begin(), it)];
399+
return (*loopResults)[::std::distance(initsMutable.begin(), it)];
395400
}
396401

397402
/// Return the loop result that corresponds to the given region iter_arg.
398403
/// Return an "empty" OpResult if the given block argument is not a region
399404
/// iter_arg of this loop op or if this op does not expose any loop results.
400-
OpResult getTiedLoopResult(BlockArgument bbArg) {
405+
::mlir::OpResult getTiedLoopResult(::mlir::BlockArgument bbArg) {
401406
auto loopResults = $_op.getLoopResults();
402407
if (!loopResults)
403408
return {};
404409
auto iterArgs = $_op.getRegionIterArgs();
405-
auto it = llvm::find(iterArgs, bbArg);
410+
auto it = ::llvm::find(iterArgs, bbArg);
406411
if (it == iterArgs.end())
407412
return {};
408-
return (*loopResults)[std::distance(iterArgs.begin(), it)];
413+
return (*loopResults)[::std::distance(iterArgs.begin(), it)];
409414
}
410415
}];
411416

412417
let verifyWithRegions = 1;
413418

414419
let verify = [{
415-
return detail::verifyLoopLikeOpInterface($_op);
420+
return ::mlir::detail::verifyLoopLikeOpInterface($_op);
416421
}];
417422
}
418423

0 commit comments

Comments
 (0)