[llvm-branch-commits] [mlir] release/18.x: [mlir] Skip invalid test on big endian platform (s390x) (#80246) (PR #81373)

2024-02-12 Thread Jacques Pienaar via llvm-branch-commits

https://github.com/jpienaar approved this pull request.


https://github.com/llvm/llvm-project/pull/81373
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Simplify `ArgConverter` state (PR #81462)

2024-02-20 Thread Jacques Pienaar via llvm-branch-commits

https://github.com/jpienaar approved this pull request.

Nice, thanks!

https://github.com/llvm/llvm-project/pull/81462
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Decouple `ConversionPatternRewriterImpl` from `ConversionPatternRewriter` (PR #82333)

2024-02-20 Thread Jacques Pienaar via llvm-branch-commits

https://github.com/jpienaar approved this pull request.


https://github.com/llvm/llvm-project/pull/82333
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Turn block type conversion into `IRRewrite` (PR #81756)

2024-02-21 Thread Jacques Pienaar via llvm-branch-commits

https://github.com/jpienaar approved this pull request.

Nice, just small nits. Thanks

https://github.com/llvm/llvm-project/pull/81756
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Turn block type conversion into `IRRewrite` (PR #81756)

2024-02-21 Thread Jacques Pienaar via llvm-branch-commits


@@ -1173,29 +936,110 @@ struct ConversionPatternRewriterImpl : public 
RewriterBase::Listener {
 } // namespace detail
 } // namespace mlir
 
+void IRRewrite::eraseOp(Operation *op) {
+  rewriterImpl.eraseRewriter.eraseOp(op);
+}
+
+void IRRewrite::eraseBlock(Block *block) {
+  rewriterImpl.eraseRewriter.eraseBlock(block);
+}
+
+void BlockTypeConversionRewrite::commit() {
+  // Process the remapping for each of the original arguments.
+  for (unsigned i = 0, e = origBlock->getNumArguments(); i != e; ++i) {
+std::optional &info = argInfo[i];
+BlockArgument origArg = origBlock->getArgument(i);
+
+// Handle the case of a 1->0 value mapping.
+if (!info) {
+  if (Value newArg =
+  rewriterImpl.mapping.lookupOrNull(origArg, origArg.getType()))
+origArg.replaceAllUsesWith(newArg);
+  continue;
+}
+
+// Otherwise this is a 1->1+ value mapping.
+Value castValue = info->castValue;
+assert(info->newArgSize >= 1 && castValue && "expected 1->1+ mapping");
+
+// If the argument is still used, replace it with the generated cast.
+if (!origArg.use_empty()) {
+  origArg.replaceAllUsesWith(
+  rewriterImpl.mapping.lookupOrDefault(castValue, origArg.getType()));
+}
+  }
+
+  delete origBlock;
+  origBlock = nullptr;
+}
+
 void BlockTypeConversionRewrite::rollback() {
-  // Undo the type conversion.
-  rewriterImpl.argConverter.discardRewrites(block);
-}
-
-/// Detach any operations nested in the given operation from their parent
-/// blocks, and erase the given operation. This can be used when the nested
-/// operations are scheduled for erasure themselves, so deleting the regions of
-/// the given operation together with their content would result in 
double-free.
-/// This happens, for example, when rolling back op creation in the reverse
-/// order and if the nested ops were created before the parent op. This 
function
-/// does not need to collect nested ops recursively because it is expected to
-/// also be called for each nested op when it is about to be deleted.
-static void detachNestedAndErase(Operation *op) {
+  // Drop all uses of the new block arguments and replace uses of the new 
block.
+  for (int i = block->getNumArguments() - 1; i >= 0; --i)
+block->getArgument(i).dropAllUses();
+  block->replaceAllUsesWith(origBlock);
+
+  // Move the operations back the original block, move the original block back
+  // into its original location and the delete the new block.
+  origBlock->getOperations().splice(origBlock->end(), block->getOperations());
+  block->getParent()->getBlocks().insert(Region::iterator(block), origBlock);
+  eraseBlock(block);
+}
+
+LogicalResult BlockTypeConversionRewrite::materializeLiveConversions(
+function_ref findLiveUser) {
+  // Process the remapping for each of the original arguments.
+  for (unsigned i = 0, e = origBlock->getNumArguments(); i != e; ++i) {

jpienaar wrote:

llvm::enumerate ?

https://github.com/llvm/llvm-project/pull/81756
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Turn block type conversion into `IRRewrite` (PR #81756)

2024-02-21 Thread Jacques Pienaar via llvm-branch-commits


@@ -1173,29 +936,110 @@ struct ConversionPatternRewriterImpl : public 
RewriterBase::Listener {
 } // namespace detail
 } // namespace mlir
 
+void IRRewrite::eraseOp(Operation *op) {
+  rewriterImpl.eraseRewriter.eraseOp(op);
+}
+
+void IRRewrite::eraseBlock(Block *block) {
+  rewriterImpl.eraseRewriter.eraseBlock(block);
+}
+
+void BlockTypeConversionRewrite::commit() {
+  // Process the remapping for each of the original arguments.
+  for (unsigned i = 0, e = origBlock->getNumArguments(); i != e; ++i) {

jpienaar wrote:

Would llvm::zip work here to enable a range based loop?

https://github.com/llvm/llvm-project/pull/81756
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Turn block type conversion into `IRRewrite` (PR #81756)

2024-02-21 Thread Jacques Pienaar via llvm-branch-commits

https://github.com/jpienaar edited 
https://github.com/llvm/llvm-project/pull/81756
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Turn op creation into `IRRewrite` (PR #81759)

2024-02-21 Thread Jacques Pienaar via llvm-branch-commits

https://github.com/jpienaar edited 
https://github.com/llvm/llvm-project/pull/81759
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Turn op creation into `IRRewrite` (PR #81759)

2024-02-21 Thread Jacques Pienaar via llvm-branch-commits

https://github.com/jpienaar approved this pull request.

Thanks!

https://github.com/llvm/llvm-project/pull/81759
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Turn op creation into `IRRewrite` (PR #81759)

2024-02-21 Thread Jacques Pienaar via llvm-branch-commits


@@ -299,7 +294,8 @@ class IRRewrite {
 ReplaceBlockArg,
 MoveOperation,
 ModifyOperation,
-ReplaceOperation

jpienaar wrote:

Mmm, come to think of it: would it make sense to have "marker" types here so 
that you wouldn't need to change below if you add types & also where one adds 
entries here is self-documented due to markers?

https://github.com/llvm/llvm-project/pull/81759
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Turn op creation into `IRRewrite` (PR #81759)

2024-02-21 Thread Jacques Pienaar via llvm-branch-commits


@@ -372,7 +368,11 @@ class CreateBlockRewrite : public BlockRewrite {
 auto &blockOps = block->getOperations();
 while (!blockOps.empty())
   blockOps.remove(blockOps.begin());
-eraseBlock(block);
+if (block->getParent()) {

jpienaar wrote:

Nit: eliding braces for simple conditionals is style here.

https://github.com/llvm/llvm-project/pull/81759
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Turn op creation into `IRRewrite` (PR #81759)

2024-02-21 Thread Jacques Pienaar via llvm-branch-commits


@@ -2549,10 +2572,15 @@ LogicalResult 
OperationConverter::legalizeConvertedArgumentTypes(
 });
 return liveUserIt == val.user_end() ? nullptr : *liveUserIt;
   };
-  for (auto &r : rewriterImpl.rewrites)
-if (auto *rewrite = dyn_cast(r.get()))
-  if (failed(rewrite->materializeLiveConversions(findLiveUser)))
+  // Note: `rewrites` may be reallocated as the loop is running.
+  for (int64_t i = 0; i < rewriterImpl.rewrites.size(); ++i) {

jpienaar wrote:

Range based? (yeah seems I'm focussed on loops this morning :))

https://github.com/llvm/llvm-project/pull/81759
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Turn op creation into `IRRewrite` (PR #81759)

2024-02-21 Thread Jacques Pienaar via llvm-branch-commits


@@ -1110,7 +1120,18 @@ void ReplaceOperationRewrite::rollback() {
 
 void ReplaceOperationRewrite::cleanup() { eraseOp(op); }
 
+void CreateOperationRewrite::rollback() {
+  for (Region ®ion : op->getRegions()) {
+while (!region.getBlocks().empty())
+  region.getBlocks().remove(region.getBlocks().begin());
+  }
+  op->dropAllUses();
+  eraseOp(op);
+}
+
 void ConversionPatternRewriterImpl::detachNestedAndErase(Operation *op) {
+  // if (erasedIR.erasedOps.contains(op)) return;

jpienaar wrote:

rm ?

https://github.com/llvm/llvm-project/pull/81759
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [mlir] [mlir][Transforms] Make `ConversionPatternRewriter` constructor private (PR #82244)

2024-02-21 Thread Jacques Pienaar via llvm-branch-commits

https://github.com/jpienaar approved this pull request.


https://github.com/llvm/llvm-project/pull/82244
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Turn unresolved materializations into `IRRewrite`s (PR #81761)

2024-02-22 Thread Jacques Pienaar via llvm-branch-commits

https://github.com/jpienaar approved this pull request.


https://github.com/llvm/llvm-project/pull/81761
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms] Encapsulate dialect conversion options in `ConversionConfig` (PR #82250)

2024-02-22 Thread Jacques Pienaar via llvm-branch-commits

https://github.com/jpienaar edited 
https://github.com/llvm/llvm-project/pull/82250
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms] Encapsulate dialect conversion options in `ConversionConfig` (PR #82250)

2024-02-22 Thread Jacques Pienaar via llvm-branch-commits

https://github.com/jpienaar approved this pull request.


https://github.com/llvm/llvm-project/pull/82250
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms] Encapsulate dialect conversion options in `ConversionConfig` (PR #82250)

2024-02-22 Thread Jacques Pienaar via llvm-branch-commits


@@ -1070,6 +1072,30 @@ class PDLConversionConfig final {
 
 #endif // MLIR_ENABLE_PDL_IN_PATTERNMATCH
 
+//===--===//
+// ConversionConfig
+//===--===//
+
+/// Dialect conversion configuration.
+struct ConversionConfig {
+  /// An optional callback used to notify about match failure diagnostics 
during
+  /// the conversion. Diagnostics are only reported to this callback may only 
be

jpienaar wrote:

"Diagnostics are only reported to this callback may only be available in debug 
mode" - this reads a bit weird.

https://github.com/llvm/llvm-project/pull/82250
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Simplify `BlockTypeConversionRewrite` (PR #83286)

2024-02-29 Thread Jacques Pienaar via llvm-branch-commits

https://github.com/jpienaar approved this pull request.


https://github.com/llvm/llvm-project/pull/83286
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Simplify handling of erased IR (PR #83423)

2024-02-29 Thread Jacques Pienaar via llvm-branch-commits

https://github.com/jpienaar approved this pull request.


https://github.com/llvm/llvm-project/pull/83423
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms] Add listener support to dialect conversion (PR #83425)

2024-03-03 Thread Jacques Pienaar via llvm-branch-commits

https://github.com/jpienaar approved this pull request.



> *[Reviewable](https://reviewable.io/reviews/llvm/llvm-project/83425)* status: 
> 0 of 4 files reviewed, 1 unresolved discussion (waiting on @ftynse, 
> @joker-eph, and @matthias-springer)

___
*[`mlir/lib/Transforms/Utils/DialectConversion.cpp` line 363 at 
r1](https://reviewable.io/reviews/llvm/llvm-project/83425#-Ns3aO9h2L3R0Ul-IX4T:-Ns3aO9h2L3R0Ul-IX4U:blphauh)
 ([raw 
file](https://github.com/llvm/llvm-project/blob/22e8d5ea80b74d687c3e792c512f50b9de81f489/mlir/lib/Transforms/Utils/DialectConversion.cpp#L363)):*
> ```cpp
>   // notification and iterators into past IR state cannot be represented.
>   listener->notifyBlockInserted(block, /*previous=*/region,
> /*previousIt=*/{});
> ```

And this is expected in the consumer that it may get not previousIt?





https://github.com/llvm/llvm-project/pull/83425
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Interfaces][WIP] `Variable` abstraction for `ValueBoundsOpInterface` (PR #87980)

2024-04-10 Thread Jacques Pienaar via llvm-branch-commits

https://github.com/jpienaar edited 
https://github.com/llvm/llvm-project/pull/87980
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Interfaces][WIP] `Variable` abstraction for `ValueBoundsOpInterface` (PR #87980)

2024-04-10 Thread Jacques Pienaar via llvm-branch-commits


@@ -67,6 +73,83 @@ static std::optional 
getConstantIntValue(OpFoldResult ofr) {
   return std::nullopt;
 }
 
+ValueBoundsConstraintSet::Variable::Variable(OpFoldResult ofr)
+: Variable(ofr, std::nullopt) {}
+
+ValueBoundsConstraintSet::Variable::Variable(Value indexValue)
+: Variable(static_cast(indexValue)) {}
+
+ValueBoundsConstraintSet::Variable::Variable(Value shapedValue, int64_t dim)
+: Variable(static_cast(shapedValue), std::optional(dim)) {}
+
+ValueBoundsConstraintSet::Variable::Variable(OpFoldResult ofr,
+ std::optional dim) {
+  Builder b(ofr.getContext());
+  if (auto constInt = ::getConstantIntValue(ofr)) {
+assert(!dim && "expected no dim for index-typed values");
+map = AffineMap::get(/*dimCount=*/0, /*symbolCount=*/0,
+ b.getAffineConstantExpr(*constInt));
+return;
+  }
+  Value value = cast(ofr);
+#ifndef NDEBUG
+  if (dim) {
+assert(isa(value.getType()) && "expected shaped type");
+  } else {
+assert(value.getType().isIndex() && "expected index type");
+  }
+#endif // NDEBUG
+  map = AffineMap::get(/*dimCount=*/0, /*symbolCount=*/1,
+   b.getAffineSymbolExpr(0));
+  mapOperands.emplace_back(value, dim);
+}
+
+ValueBoundsConstraintSet::Variable::Variable(AffineMap map,
+ ArrayRef mapOperands) {
+  assert(map.getNumResults() == 1 && "expected single result");
+
+  // Turn all dims into symbols.
+  Builder b(map.getContext());
+  SmallVector dimReplacements, symReplacements;
+  for (int64_t i = 0; i < map.getNumDims(); ++i)

jpienaar wrote:

Nit: LLVM style is to avoid checking end condition by querying end state unless 
where the iteration space could change during iteration.

https://github.com/llvm/llvm-project/pull/87980
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Interfaces][WIP] `Variable` abstraction for `ValueBoundsOpInterface` (PR #87980)

2024-04-10 Thread Jacques Pienaar via llvm-branch-commits

https://github.com/jpienaar approved this pull request.

Nice refactor, I think easier to read 

https://github.com/llvm/llvm-project/pull/87980
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] cad16e4 - Avoid unused variable warning in opt mode

2021-01-20 Thread Jacques Pienaar via llvm-branch-commits

Author: Jacques Pienaar
Date: 2021-01-20T09:45:22-08:00
New Revision: cad16e4a9267f08229c59e473db6dedd730a5d93

URL: 
https://github.com/llvm/llvm-project/commit/cad16e4a9267f08229c59e473db6dedd730a5d93
DIFF: 
https://github.com/llvm/llvm-project/commit/cad16e4a9267f08229c59e473db6dedd730a5d93.diff

LOG: Avoid unused variable warning in opt mode

Added: 


Modified: 
mlir/lib/Transforms/LoopFusion.cpp

Removed: 




diff  --git a/mlir/lib/Transforms/LoopFusion.cpp 
b/mlir/lib/Transforms/LoopFusion.cpp
index 2bee9cb33405..6c56368ca6e1 100644
--- a/mlir/lib/Transforms/LoopFusion.cpp
+++ b/mlir/lib/Transforms/LoopFusion.cpp
@@ -763,9 +763,11 @@ bool MemRefDependenceGraph::init(FuncOp f) {
 }
   }
 
+#ifndef NDEBUG
   for (auto &idAndNode : nodes)
 LLVM_DEBUG(llvm::dbgs() << "Create node " << idAndNode.first << " for:\n"
 << *(idAndNode.second.op) << "\n");
+#endif
 
   // Add dependence edges between nodes which produce SSA values and their
   // users.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] aee622f - [mlir] Enable passing crash reproducer stream factory method

2021-01-21 Thread Jacques Pienaar via llvm-branch-commits

Author: Jacques Pienaar
Date: 2021-01-21T20:03:15-08:00
New Revision: aee622fa200de9ad28334cf74416f2fd5391e2ee

URL: 
https://github.com/llvm/llvm-project/commit/aee622fa200de9ad28334cf74416f2fd5391e2ee
DIFF: 
https://github.com/llvm/llvm-project/commit/aee622fa200de9ad28334cf74416f2fd5391e2ee.diff

LOG: [mlir] Enable passing crash reproducer stream factory method

Add factory to create streams for logging the reproducer. Allows for more 
general logging (beyond file) and logging the configuration/module separately 
(logged in order, configuration before module).

Also enable querying filename of ToolOutputFile.

Differential Revision: https://reviews.llvm.org/D94868

Added: 


Modified: 
llvm/include/llvm/Support/ToolOutputFile.h
mlir/docs/PassManagement.md
mlir/include/mlir/Pass/PassManager.h
mlir/lib/Pass/Pass.cpp

Removed: 




diff  --git a/llvm/include/llvm/Support/ToolOutputFile.h 
b/llvm/include/llvm/Support/ToolOutputFile.h
index cf01b9ecefc5..ec1d6ae52268 100644
--- a/llvm/include/llvm/Support/ToolOutputFile.h
+++ b/llvm/include/llvm/Support/ToolOutputFile.h
@@ -35,6 +35,7 @@ class ToolOutputFile {
 /// The flag which indicates whether we should not delete the file.
 bool Keep;
 
+StringRef getFilename() { return Filename; }
 explicit CleanupInstaller(StringRef Filename);
 ~CleanupInstaller();
   } Installer;
@@ -57,6 +58,9 @@ class ToolOutputFile {
   /// Return the contained raw_fd_ostream.
   raw_fd_ostream &os() { return *OS; }
 
+  /// Return the filename initialized with.
+  StringRef getFilename() { return Installer.getFilename(); }
+
   /// Indicate that the tool's job wrt this output file has been successful and
   /// the file should not be deleted.
   void keep() { Installer.Keep = true; }

diff  --git a/mlir/docs/PassManagement.md b/mlir/docs/PassManagement.md
index 558d5f6d315f..9b24e721da08 100644
--- a/mlir/docs/PassManagement.md
+++ b/mlir/docs/PassManagement.md
@@ -1145,8 +1145,7 @@ was executing, as well as the initial IR before any 
passes were run. A potential
 reproducible may have the form:
 
 ```mlir
-// configuration: -pass-pipeline='func(cse,canonicalize),inline'
-// note: verifyPasses=false
+// configuration: -pass-pipeline='func(cse,canonicalize),inline' -verify-each
 
 module {
   func @foo() {
@@ -1159,6 +1158,10 @@ The configuration dumped can be passed to `mlir-opt` by 
specifying
 `-run-reproducer` flag. This will result in parsing the first line 
configuration
 of the reproducer and adding those to the command line options.
 
+Beyond specifying a filename, one can also register a `ReproducerStreamFactory`
+function that would be invoked in the case of a crash and the reproducer 
written
+to its stream.
+
 ### Local Reproducer Generation
 
 An additional flag may be passed to

diff  --git a/mlir/include/mlir/Pass/PassManager.h 
b/mlir/include/mlir/Pass/PassManager.h
index 9fc81b5e421d..beb6bc99a18e 100644
--- a/mlir/include/mlir/Pass/PassManager.h
+++ b/mlir/include/mlir/Pass/PassManager.h
@@ -192,6 +192,29 @@ class PassManager : public OpPassManager {
   void enableCrashReproducerGeneration(StringRef outputFile,
bool genLocalReproducer = false);
 
+  /// Streams on which to output crash reproducer.
+  struct ReproducerStream {
+virtual ~ReproducerStream() = default;
+
+/// Description of the reproducer stream.
+virtual StringRef description() = 0;
+
+/// Stream on which to output reproducer.
+virtual raw_ostream &os() = 0;
+  };
+
+  /// Method type for constructing ReproducerStream.
+  using ReproducerStreamFactory =
+  std::function(std::string &error)>;
+
+  /// Enable support for the pass manager to generate a reproducer on the event
+  /// of a crash or a pass failure. `factory` is used to construct the streams
+  /// to write the generated reproducer to. If `genLocalReproducer` is true, 
the
+  /// pass manager will attempt to generate a local reproducer that contains 
the
+  /// smallest pipeline.
+  void enableCrashReproducerGeneration(ReproducerStreamFactory factory,
+   bool genLocalReproducer = false);
+
   /// Runs the verifier after each individual pass.
   void enableVerifier(bool enabled = true);
 
@@ -349,8 +372,8 @@ class PassManager : public OpPassManager {
   /// A manager for pass instrumentations.
   std::unique_ptr instrumentor;
 
-  /// An optional filename to use when generating a crash reproducer if valid.
-  Optional crashReproducerFileName;
+  /// An optional factory to use when generating a crash reproducer if valid.
+  ReproducerStreamFactory crashReproducerStreamFactory;
 
   /// Flag that specifies if pass timing is enabled.
   bool passTiming : 1;

diff  --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp
index d8a59bc83661..0828941d0267 100644
--- a/mlir/lib/Pass/Pass.cpp
+++ b/mlir/lib/Pass/Pass.cpp
@@ -64

[llvm-branch-commits] [mlir] 73de3df - Add more explicit assert for failures

2021-01-22 Thread Jacques Pienaar via llvm-branch-commits

Author: Jacques Pienaar
Date: 2021-01-22T11:45:25-08:00
New Revision: 73de3df1d28523dbd67dd54594480d126e27b559

URL: 
https://github.com/llvm/llvm-project/commit/73de3df1d28523dbd67dd54594480d126e27b559
DIFF: 
https://github.com/llvm/llvm-project/commit/73de3df1d28523dbd67dd54594480d126e27b559.diff

LOG: Add more explicit assert for failures

Differential Revision: https://reviews.llvm.org/D95201

Added: 


Modified: 
mlir/lib/IR/BuiltinTypes.cpp

Removed: 




diff  --git a/mlir/lib/IR/BuiltinTypes.cpp b/mlir/lib/IR/BuiltinTypes.cpp
index 34283e95b8f5..23553a8483de 100644
--- a/mlir/lib/IR/BuiltinTypes.cpp
+++ b/mlir/lib/IR/BuiltinTypes.cpp
@@ -214,7 +214,10 @@ int64_t ShapedType::getNumElements() const {
   return num;
 }
 
-int64_t ShapedType::getRank() const { return getShape().size(); }
+int64_t ShapedType::getRank() const {
+  assert(hasRank() && "cannot query rank of unranked shaped type");
+  return getShape().size();
+}
 
 bool ShapedType::hasRank() const {
   return !isa();



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] e032669 - [mlir] Skip empty op-pipelines in inliner textual opt parsing

2020-12-29 Thread Jacques Pienaar via llvm-branch-commits

Author: Jacques Pienaar
Date: 2020-12-29T13:59:53-08:00
New Revision: e03266994af898efcde7b27936250e85f774f39f

URL: 
https://github.com/llvm/llvm-project/commit/e03266994af898efcde7b27936250e85f774f39f
DIFF: 
https://github.com/llvm/llvm-project/commit/e03266994af898efcde7b27936250e85f774f39f.diff

LOG: [mlir] Skip empty op-pipelines in inliner textual opt parsing

Avoids failing on cases like

inline{default-pipeline=canonicalize max-iterations=4 op-pipelines=},

as produced by crash reproducer.

Added: 


Modified: 
mlir/lib/Transforms/Inliner.cpp

Removed: 




diff  --git a/mlir/lib/Transforms/Inliner.cpp b/mlir/lib/Transforms/Inliner.cpp
index 364af20c0695..42ab8f0ce4df 100644
--- a/mlir/lib/Transforms/Inliner.cpp
+++ b/mlir/lib/Transforms/Inliner.cpp
@@ -764,6 +764,10 @@ LogicalResult InlinerPass::initializeOptions(StringRef 
options) {
   // Initialize the op specific pass pipelines.
   llvm::StringMap pipelines;
   for (StringRef pipeline : opPipelineStrs) {
+// Skip empty pipelines.
+if (pipeline.empty())
+  continue;
+
 // Pipelines are expected to be of the form `()`.
 size_t pipelineStart = pipeline.find_first_of('(');
 if (pipelineStart == StringRef::npos || !pipeline.consume_back(")"))



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] 5fd2b3a - [mlir] Add error message when failing to add pass

2020-12-29 Thread Jacques Pienaar via llvm-branch-commits

Author: Jacques Pienaar
Date: 2020-12-29T14:20:19-08:00
New Revision: 5fd2b3a1246fee0ce1613931fcf1ed51412a6b3f

URL: 
https://github.com/llvm/llvm-project/commit/5fd2b3a1246fee0ce1613931fcf1ed51412a6b3f
DIFF: 
https://github.com/llvm/llvm-project/commit/5fd2b3a1246fee0ce1613931fcf1ed51412a6b3f.diff

LOG: [mlir] Add error message when failing to add pass

Ran into failure without any error message previously here.

Differential Revision: https://reviews.llvm.org/D93910

Added: 
mlir/test/Pass/invalid-pass.mlir

Modified: 
mlir/lib/Pass/PassRegistry.cpp

Removed: 




diff  --git a/mlir/lib/Pass/PassRegistry.cpp b/mlir/lib/Pass/PassRegistry.cpp
index f41ca72d7838..091fee5fcd9b 100644
--- a/mlir/lib/Pass/PassRegistry.cpp
+++ b/mlir/lib/Pass/PassRegistry.cpp
@@ -452,12 +452,15 @@ LogicalResult TextualPipeline::addToPipeline(
 function_ref errorHandler) const {
   for (auto &elt : elements) {
 if (elt.registryEntry) {
-  if (failed(
-  elt.registryEntry->addToPipeline(pm, elt.options, errorHandler)))
-return failure();
+  if (failed(elt.registryEntry->addToPipeline(pm, elt.options,
+  errorHandler))) {
+return errorHandler("failed to add `" + elt.name + "` with options `" +
+elt.options + "`");
+  }
 } else if (failed(addToPipeline(elt.innerPipeline, pm.nest(elt.name),
 errorHandler))) {
-  return failure();
+  return errorHandler("failed to add `" + elt.name + "` with options `" +
+  elt.options + "` to inner pipeline");
 }
   }
   return success();

diff  --git a/mlir/test/Pass/invalid-pass.mlir 
b/mlir/test/Pass/invalid-pass.mlir
new file mode 100644
index ..2453b8d99ec9
--- /dev/null
+++ b/mlir/test/Pass/invalid-pass.mlir
@@ -0,0 +1,6 @@
+// RUN: not mlir-opt %s 
-pass-pipeline='module(test-module-pass{test-option=a})' 2>&1 | FileCheck %s
+
+// CHECK: : no such option test-option
+// CHECK: failed to add `test-module-pass` with options `test-option=a`
+// CHECK: failed to add `module` with options `` to inner pipeline
+module {}



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 2016f2c - Fixes warning 'enumeration value not handled in switch'.

2020-12-30 Thread Jacques Pienaar via llvm-branch-commits

Author: Bogdan Graur
Date: 2020-12-30T06:56:29-08:00
New Revision: 2016f2c8a76d67d8cd4771796b6cd19fd66e3f37

URL: 
https://github.com/llvm/llvm-project/commit/2016f2c8a76d67d8cd4771796b6cd19fd66e3f37
DIFF: 
https://github.com/llvm/llvm-project/commit/2016f2c8a76d67d8cd4771796b6cd19fd66e3f37.diff

LOG: Fixes warning 'enumeration value not handled in switch'.

This was introduced in commit: 981a0bd85811fe49379fdbef35528e2c2f3511a3.

Differential Revision: https://reviews.llvm.org/D93944

Added: 


Modified: 
llvm/tools/llvm-c-test/echo.cpp

Removed: 




diff  --git a/llvm/tools/llvm-c-test/echo.cpp b/llvm/tools/llvm-c-test/echo.cpp
index e2262c2d575d..a29f360d1fdf 100644
--- a/llvm/tools/llvm-c-test/echo.cpp
+++ b/llvm/tools/llvm-c-test/echo.cpp
@@ -149,6 +149,8 @@ struct TypeCloner {
   LLVMGetVectorSize(Src));
   case LLVMMetadataTypeKind:
 return LLVMMetadataTypeInContext(Ctx);
+  case LLVMX86_AMXTypeKind:
+return LLVMX86AMXTypeInContext(Ctx);
   case LLVMX86_MMXTypeKind:
 return LLVMX86MMXTypeInContext(Ctx);
   case LLVMTokenTypeKind:



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] 453b6aa - [mlir] Add option to read reproducer options from file

2020-12-30 Thread Jacques Pienaar via llvm-branch-commits

Author: Jacques Pienaar
Date: 2020-12-30T10:46:01-08:00
New Revision: 453b6aadcef9625599d6099011bede710d4524f1

URL: 
https://github.com/llvm/llvm-project/commit/453b6aadcef9625599d6099011bede710d4524f1
DIFF: 
https://github.com/llvm/llvm-project/commit/453b6aadcef9625599d6099011bede710d4524f1.diff

LOG: [mlir] Add option to read reproducer options from file

Add command line option to read the configuration dumped by the MLIR crash
reproducer and adds those to the other command line options parsed by mlir-opt.

Simple convenience that enables `mlir-opt --run-reproducer /tmp/repro.mlir`
instead of needing to copy&paste the configuration.

Differential Revision: https://reviews.llvm.org/D93924

Added: 
mlir/test/Pass/run-reproducer.mlir

Modified: 
mlir/docs/PassManagement.md
mlir/lib/Support/MlirOptMain.cpp

Removed: 




diff  --git a/mlir/docs/PassManagement.md b/mlir/docs/PassManagement.md
index a3a5a49444a9..b71859f7d974 100644
--- a/mlir/docs/PassManagement.md
+++ b/mlir/docs/PassManagement.md
@@ -1138,6 +1138,10 @@ module {
 }
 ```
 
+The configuration dumped can be passed to `mlir-opt` by specifying
+`-run-reproducer` flag. This will result in parsing the first line 
configuration
+of the reproducer and adding those to the command line options.
+
 ### Local Reproducer Generation
 
 An additional flag may be passed to

diff  --git a/mlir/lib/Support/MlirOptMain.cpp 
b/mlir/lib/Support/MlirOptMain.cpp
index 5d852292fd06..f7d837259f65 100644
--- a/mlir/lib/Support/MlirOptMain.cpp
+++ b/mlir/lib/Support/MlirOptMain.cpp
@@ -29,6 +29,7 @@
 #include "llvm/Support/InitLLVM.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/SourceMgr.h"
+#include "llvm/Support/StringSaver.h"
 #include "llvm/Support/ToolOutputFile.h"
 
 using namespace mlir;
@@ -182,6 +183,11 @@ LogicalResult mlir::MlirOptMain(int argc, char **argv, 
llvm::StringRef toolName,
   "show-dialects", cl::desc("Print the list of registered dialects"),
   cl::init(false));
 
+  static cl::opt runRepro(
+  "run-reproducer",
+  cl::desc("Append the command line options of the reproducer"),
+  cl::init(false));
+
   InitLLVM y(argc, argv);
 
   // Register any command line options.
@@ -219,6 +225,23 @@ LogicalResult mlir::MlirOptMain(int argc, char **argv, 
llvm::StringRef toolName,
 return failure();
   }
 
+  // Parse reproducer options.
+  BumpPtrAllocator a;
+  StringSaver saver(a);
+  if (runRepro) {
+auto pair = file->getBuffer().split('\n');
+if (!pair.first.consume_front("// configuration:")) {
+  llvm::errs() << "Failed to find repro configuration, expect file to "
+  "begin with '// configuration:'\n";
+  return failure();
+}
+// Tokenize & parse the first line.
+SmallVector newArgv;
+newArgv.push_back(argv[0]);
+llvm::cl::TokenizeGNUCommandLine(pair.first, saver, newArgv);
+cl::ParseCommandLineOptions(newArgv.size(), &newArgv[0], helpHeader);
+  }
+
   auto output = openOutputFile(outputFilename, &errorMessage);
   if (!output) {
 llvm::errs() << errorMessage << "\n";

diff  --git a/mlir/test/Pass/run-reproducer.mlir 
b/mlir/test/Pass/run-reproducer.mlir
new file mode 100644
index ..9caa3f68abef
--- /dev/null
+++ b/mlir/test/Pass/run-reproducer.mlir
@@ -0,0 +1,22 @@
+// configuration: -mlir-disable-threading=true 
-pass-pipeline='func(cse,canonicalize)' -print-ir-before=cse -o /dev/null
+
+// Test of the reproducer run option. The first line has to be the
+// configuration (matching what is produced by reproducer).
+
+// RUN: mlir-opt %s -run-reproducer 2>&1 | FileCheck -check-prefix=BEFORE %s
+
+func @foo() {
+  %0 = constant 0 : i32
+  return
+}
+
+func @bar() {
+  return
+}
+
+// BEFORE: *** IR Dump Before{{.*}}CSE ***
+// BEFORE-NEXT: func @foo()
+// BEFORE: *** IR Dump Before{{.*}}CSE ***
+// BEFORE-NEXT: func @bar()
+// BEFORE-NOT: *** IR Dump Before{{.*}}Canonicalizer ***
+// BEFORE-NOT: *** IR Dump After



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] 8c1f553 - Avoid using /dev/null in test

2020-12-30 Thread Jacques Pienaar via llvm-branch-commits

Author: Jacques Pienaar
Date: 2020-12-30T14:16:13-08:00
New Revision: 8c1f55384450a26f6ca391dd25905c32f9ed5644

URL: 
https://github.com/llvm/llvm-project/commit/8c1f55384450a26f6ca391dd25905c32f9ed5644
DIFF: 
https://github.com/llvm/llvm-project/commit/8c1f55384450a26f6ca391dd25905c32f9ed5644.diff

LOG: Avoid using /dev/null in test

Windows build bot was not happy with this
(http://lab.llvm.org:8011/#/builders/13/builds/3327/steps/7/logs/FAIL__MLIR__run-reproducer_mlir)

Added: 


Modified: 
mlir/test/Pass/run-reproducer.mlir

Removed: 




diff  --git a/mlir/test/Pass/run-reproducer.mlir 
b/mlir/test/Pass/run-reproducer.mlir
index 9caa3f68abef..af36c5bb65f2 100644
--- a/mlir/test/Pass/run-reproducer.mlir
+++ b/mlir/test/Pass/run-reproducer.mlir
@@ -1,4 +1,4 @@
-// configuration: -mlir-disable-threading=true 
-pass-pipeline='func(cse,canonicalize)' -print-ir-before=cse -o /dev/null
+// configuration: -mlir-disable-threading=true 
-pass-pipeline='func(cse,canonicalize)' -print-ir-before=cse
 
 // Test of the reproducer run option. The first line has to be the
 // configuration (matching what is produced by reproducer).



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] 8d541a1 - [mlir][shape] Add shape.lib attribute

2020-12-31 Thread Jacques Pienaar via llvm-branch-commits

Author: Jacques Pienaar
Date: 2020-12-31T14:46:08-08:00
New Revision: 8d541a1fbe6d92a3fadf6d7d8e8209ed6c76e092

URL: 
https://github.com/llvm/llvm-project/commit/8d541a1fbe6d92a3fadf6d7d8e8209ed6c76e092
DIFF: 
https://github.com/llvm/llvm-project/commit/8d541a1fbe6d92a3fadf6d7d8e8209ed6c76e092.diff

LOG: [mlir][shape] Add shape.lib attribute

Enable querying shape function library ops from the module. Currently
supports singular or array of them (as long as array has all unique ops
in mappings). The preferred canonical form would have one library, but
given the invariant on the mapping, this can easily be achieved by a
simple merging pass.

Preferred the attribute approach vs naming convention as these could be
added in multiple different ways.

Added: 


Modified: 
mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td
mlir/lib/Dialect/Shape/IR/Shape.cpp
mlir/test/Analysis/test-shape-fn-report.mlir
mlir/test/Dialect/Shape/invalid.mlir
mlir/test/lib/Dialect/Shape/TestShapeFunctions.cpp

Removed: 




diff  --git a/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td 
b/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td
index a7868e74c65f..1cccb59dfbb9 100644
--- a/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td
+++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td
@@ -37,6 +37,7 @@ def ShapeDialect : Dialect {
   let cppNamespace = "::mlir::shape";
 
   let hasConstantMaterializer = 1;
+  let hasOperationAttrVerify = 1;
 }
 
 def Shape_ShapeType : DialectTypehasTrait())
+  return op->emitError(
+  "shape.lib attribute may only be on op implementing SymbolTable");
+
+if (auto symbolRef = attribute.second.dyn_cast()) {
+  auto *symbol = SymbolTable::lookupSymbolIn(op, symbolRef);
+  if (!symbol)
+return op->emitError("shape function library ")
+   << symbolRef << " not found";
+  return isa(symbol)
+ ? success()
+ : op->emitError()
+   << symbolRef << " required to be shape function 
library";
+}
+
+if (auto arr = attribute.second.dyn_cast()) {
+  // Verify all entries are function libraries and mappings in libraries
+  // refer to unique ops.
+  DenseSet key;
+  for (auto it : arr) {
+if (!it.isa())
+  return op->emitError(
+  "only SymbolRefAttr allowed in shape.lib attribute array");
+
+auto shapeFnLib = dyn_cast(
+SymbolTable::lookupSymbolIn(op, it.cast()));
+if (!shapeFnLib)
+  return op->emitError()
+ << it << " does not refer to FunctionLibraryOp";
+for (auto mapping : shapeFnLib.mapping()) {
+  if (!key.insert(mapping.first).second) {
+return op->emitError("only one op to shape mapping allowed, found "
+ "multiple for `")
+   << mapping.first << "`";
+  }
+}
+  }
+  return success();
+}
+
+return op->emitError("only SymbolRefAttr or array of SymbolRefAttrs "
+ "allowed as shape.lib attribute");
+  }
+  return success();
+}
+
 
//===--===//
 // AnyOp
 
//===--===//

diff  --git a/mlir/test/Analysis/test-shape-fn-report.mlir 
b/mlir/test/Analysis/test-shape-fn-report.mlir
index ad5c8e64a1b7..b01593531502 100644
--- a/mlir/test/Analysis/test-shape-fn-report.mlir
+++ b/mlir/test/Analysis/test-shape-fn-report.mlir
@@ -1,5 +1,7 @@
 // RUN: mlir-opt %s --test-shape-function-report -verify-diagnostics
 
+module attributes {shape.lib = [@shape_lib]} {
+
 // expected-remark@+1 {{associated shape function: same_result_shape}}
 func @tanh(%arg: tensor<10x20xf32>) -> tensor<10x20xf32>
 attributes {shape.function = @shape_lib::@same_result_shape} {
@@ -20,3 +22,5 @@ shape.function_library @shape_lib {
 } mapping {
   test.same_operand_result_type = @same_result_shape
 }
+
+}

diff  --git a/mlir/test/Dialect/Shape/invalid.mlir 
b/mlir/test/Dialect/Shape/invalid.mlir
index eb0ae5ae05a9..d2f5af2f7b30 100644
--- a/mlir/test/Dialect/Shape/invalid.mlir
+++ b/mlir/test/Dialect/Shape/invalid.mlir
@@ -154,3 +154,95 @@ func @broadcast(%arg0 : !shape.shape, %arg1 : 
tensor) -> tensor -> tensor
   return %result : tensor
 }
+
+// -
+
+// Test using an unsupported shape.lib attribute type.
+
+// expected-error@+1 {{only SymbolRefAttr allowed in shape.lib attribute 
array}}
+module attributes {shape.lib = [@shape_lib, "shape_lib"]} {
+
+shape.function_library @shape_lib {
+  // Test shape function that returns the shape of input arg as result shape.
+  func @same_result_shape(%arg: !shape.value_shape) -> !shape.shape {
+%0 = shape.shape_of %arg : !shape.value_shape -> !shape.shape
+return %0 : !shape.shape
+  }
+} mapping {
+  test.same_operand_result_type 

[llvm-branch-commits] [llvm] 44f399c - [FileCheck] Add a literal check directive modifier

2020-12-18 Thread Jacques Pienaar via llvm-branch-commits

Author: Jacques Pienaar
Date: 2020-12-18T17:26:15-08:00
New Revision: 44f399ccc12e27d20bae1ea7e712ef7f71e2ff3a

URL: 
https://github.com/llvm/llvm-project/commit/44f399ccc12e27d20bae1ea7e712ef7f71e2ff3a
DIFF: 
https://github.com/llvm/llvm-project/commit/44f399ccc12e27d20bae1ea7e712ef7f71e2ff3a.diff

LOG: [FileCheck] Add a literal check directive modifier

Introduce CHECK modifiers that change the behavior of the CHECK
directive. Also add a LITERAL modifier for cases where matching could
end requiring escaping strings interpreted as regex where only
literal/fixed string matching is desired (making the CHECK's more
difficult to write/fragile and difficult to interpret).

Added: 
llvm/test/FileCheck/check-literal.txt

Modified: 
llvm/docs/CommandGuide/FileCheck.rst
llvm/include/llvm/FileCheck/FileCheck.h
llvm/lib/FileCheck/FileCheck.cpp

Removed: 




diff  --git a/llvm/docs/CommandGuide/FileCheck.rst 
b/llvm/docs/CommandGuide/FileCheck.rst
index bf8147abf0a3..398cce1f8a8c 100644
--- a/llvm/docs/CommandGuide/FileCheck.rst
+++ b/llvm/docs/CommandGuide/FileCheck.rst
@@ -660,6 +660,30 @@ simply uniquely match a single line in the file being 
verified.
 
 ``CHECK-LABEL:`` directives cannot contain variable definitions or uses.
 
+Directive modifiers
+~~~
+
+A directive modifier can be append to a directive by following the directive
+with ``{}`` where the only supported value for  is
+``LITERAL``.
+
+The ``LITERAL`` directive modifier can be used to perform a literal match. The
+modifier results in the directive not recognizing any syntax to perform regex
+matching, variable capture or any substitutions. This is useful when the text
+to match would require excessive escaping otherwise. For example, the
+following will perform literal matches rather than considering these as
+regular expressions:
+
+.. code-block:: text
+
+   Input: [[[10, 20]], [[30, 40]]]
+   Output %r10: [[10, 20]]
+   Output %r10: [[30, 40]]
+
+   ; CHECK{LITERAL}: [[[10, 20]], [[30, 40]]]
+   ; CHECK-DAG{LITERAL}: [[30, 40]]
+   ; CHECK-DAG{LITERAL}: [[10, 20]]
+
 FileCheck Regex Matching Syntax
 ~~~
 

diff  --git a/llvm/include/llvm/FileCheck/FileCheck.h 
b/llvm/include/llvm/FileCheck/FileCheck.h
index b10db710ef38..b44ab025694b 100644
--- a/llvm/include/llvm/FileCheck/FileCheck.h
+++ b/llvm/include/llvm/FileCheck/FileCheck.h
@@ -17,6 +17,7 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/SourceMgr.h"
+#include 
 #include 
 #include 
 
@@ -64,12 +65,23 @@ enum FileCheckKind {
   CheckBadCount
 };
 
+enum FileCheckKindModifier {
+  /// Modifies directive to perform literal match.
+  ModifierLiteral = 0,
+
+  // The number of modifier.
+  Size
+};
+
 class FileCheckType {
   FileCheckKind Kind;
   int Count; ///< optional Count for some checks
+  /// Modifers for the check directive.
+  std::bitset Modifiers;
 
 public:
-  FileCheckType(FileCheckKind Kind = CheckNone) : Kind(Kind), Count(1) {}
+  FileCheckType(FileCheckKind Kind = CheckNone)
+  : Kind(Kind), Count(1), Modifiers() {}
   FileCheckType(const FileCheckType &) = default;
   FileCheckType &operator=(const FileCheckType &) = default;
 
@@ -78,8 +90,19 @@ class FileCheckType {
   int getCount() const { return Count; }
   FileCheckType &setCount(int C);
 
+  bool isLiteralMatch() const {
+return Modifiers[FileCheckKindModifier::ModifierLiteral];
+  }
+  FileCheckType &setLiteralMatch(bool Literal = true) {
+Modifiers.set(FileCheckKindModifier::ModifierLiteral, Literal);
+return *this;
+  }
+
   // \returns a description of \p Prefix.
   std::string getDescription(StringRef Prefix) const;
+
+  // \returns a description of \p Modifiers.
+  std::string getModifiersDescription() const;
 };
 } // namespace Check
 

diff  --git a/llvm/lib/FileCheck/FileCheck.cpp 
b/llvm/lib/FileCheck/FileCheck.cpp
index d6fda5b36e69..c6a5b69e2055 100644
--- a/llvm/lib/FileCheck/FileCheck.cpp
+++ b/llvm/lib/FileCheck/FileCheck.cpp
@@ -917,6 +917,12 @@ bool Pattern::parsePattern(StringRef PatternStr, StringRef 
Prefix,
 return false;
   }
 
+  // If literal check, set fixed string.
+  if (CheckTy.isLiteralMatch()) {
+FixedStr = PatternStr;
+return false;
+  }
+
   // Check to see if this is a fixed string, or if it has regex pieces.
   if (!MatchFullLinesHere &&
   (PatternStr.size() < 2 || (PatternStr.find("{{") == StringRef::npos &&
@@ -1588,26 +1594,43 @@ Check::FileCheckType 
&Check::FileCheckType::setCount(int C) {
   return *this;
 }
 
+std::string Check::FileCheckType::getModifiersDescription() const {
+  if (Modifiers.none())
+return "";
+  std::string Ret;
+  raw_string_ostream OS(Ret);
+  OS << '{';
+  if (isLiteralMatch())
+OS << "LITERAL";
+  OS << '}';
+  return OS.str();
+}
+
 std::string Check::FileCheckType::getDescription(StringRef Prefix) const {
+  // App

[llvm-branch-commits] [mlir] ca1ab0c - [mlir] Add tensor passes to passes.md

2020-12-23 Thread Jacques Pienaar via llvm-branch-commits

Author: Jacques Pienaar
Date: 2020-12-23T16:13:03-08:00
New Revision: ca1ab0c66d1c499d4ddcf723dcba692792d531a7

URL: 
https://github.com/llvm/llvm-project/commit/ca1ab0c66d1c499d4ddcf723dcba692792d531a7
DIFF: 
https://github.com/llvm/llvm-project/commit/ca1ab0c66d1c499d4ddcf723dcba692792d531a7.diff

LOG: [mlir] Add tensor passes to passes.md

Added: 


Modified: 
mlir/docs/Passes.md

Removed: 




diff  --git a/mlir/docs/Passes.md b/mlir/docs/Passes.md
index c7ac56f84ea9..fdf2893e880a 100644
--- a/mlir/docs/Passes.md
+++ b/mlir/docs/Passes.md
@@ -56,6 +56,10 @@ This document describes the available MLIR passes and their 
contracts.
 
 [include "StandardPasses.md"]
 
+## `tensor` Dialect Passes
+
+[include "TensorPasses.md"]
+
 ## TOSA Dialect Passes
 
 [include "TosaPasses.md"]



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] 6dd9596 - [mlir] Add a shape function library op

2020-11-28 Thread Jacques Pienaar via llvm-branch-commits

Author: Jacques Pienaar
Date: 2020-11-28T15:53:59-08:00
New Revision: 6dd9596b19d7679c562f8e866be6d0c3d7c21994

URL: 
https://github.com/llvm/llvm-project/commit/6dd9596b19d7679c562f8e866be6d0c3d7c21994
DIFF: 
https://github.com/llvm/llvm-project/commit/6dd9596b19d7679c562f8e866be6d0c3d7c21994.diff

LOG: [mlir] Add a shape function library op

Op with mapping from ops to corresponding shape functions for those op
in the library and mechanism to associate shape functions to functions.
The mapping of operand to shape function is kept separate from the shape
functions themselves as the operation is associated to the shape
function and not vice versa, and one could have a common library of
shape functions that can be used in different contexts.

Use fully qualified names and require a name for shape fn lib ops for
now and an explicit print/parse (based around the generated one & GPU
module op ones).

Differential Revision: https://reviews.llvm.org/D91672

Added: 
mlir/test/Analysis/test-shape-fn-report.mlir
mlir/test/lib/Dialect/Shape/CMakeLists.txt
mlir/test/lib/Dialect/Shape/TestShapeFunctions.cpp

Modified: 
mlir/include/mlir/Dialect/Shape/IR/Shape.h
mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
mlir/lib/Dialect/Shape/IR/Shape.cpp
mlir/test/lib/Dialect/CMakeLists.txt
mlir/test/lib/Dialect/Test/TestOps.td
mlir/tools/mlir-opt/CMakeLists.txt
mlir/tools/mlir-opt/mlir-opt.cpp

Removed: 




diff  --git a/mlir/include/mlir/Dialect/Shape/IR/Shape.h 
b/mlir/include/mlir/Dialect/Shape/IR/Shape.h
index f40d6154544a..cb5ed56e16a2 100644
--- a/mlir/include/mlir/Dialect/Shape/IR/Shape.h
+++ b/mlir/include/mlir/Dialect/Shape/IR/Shape.h
@@ -14,6 +14,7 @@
 #ifndef MLIR_SHAPE_IR_SHAPE_H
 #define MLIR_SHAPE_IR_SHAPE_H
 
+#include "mlir/IR/BuiltinDialect.h"
 #include "mlir/IR/Dialect.h"
 #include "mlir/IR/OpDefinition.h"
 #include "mlir/IR/OpImplementation.h"

diff  --git a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td 
b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
index a852d900cf69..52768e49001d 100644
--- a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
+++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
@@ -18,6 +18,7 @@ include "mlir/Interfaces/ControlFlowInterfaces.td"
 include "mlir/Interfaces/InferTypeOpInterface.td"
 include "mlir/Interfaces/SideEffectInterfaces.td"
 include "mlir/IR/OpAsmInterface.td"
+include "mlir/IR/SymbolInterfaces.td"
 
 
//===--===//
 // Shape op definitions
@@ -492,7 +493,7 @@ def Shape_WithOp : Shape_Op<"with_shape", [NoSideEffect]> {
 }
 
 def Shape_YieldOp : Shape_Op<"yield",
-[HasParent<"ReduceOp">,
+[HasParent<"ReduceOp, FunctionLibraryOp">,
  NoSideEffect,
  ReturnLike,
  Terminator]> {
@@ -780,4 +781,62 @@ def Shape_CstrRequireOp : Shape_Op<"cstr_require", []> {
   let hasFolder = 1;
 }
 
+//===--===//
+// Shape collection ops.
+//===--===//
+
+def Shape_FunctionLibraryOp : Shape_Op<"function_library",
+[AffineScope, IsolatedFromAbove, NoRegionArguments, SymbolTable, Symbol,
+ SingleBlockImplicitTerminator<"ShapeFunctionLibraryTerminatorOp">]> {
+  let summary = "Represents shape functions and corresponding ops";
+  let description = [{
+Represents a list of shape functions and the ops whose shape transfer
+functions they represent.
+
+Example:
+
+```mlir
+shape.function_library {
+  func @same_result_shape(%arg: !shape.value_shape) -> !shape.shape {
+%0 = shape.shape_of %arg : !shape.value_shape -> !shape.shape
+return %0 : !shape.shape
+  }
+} mapping {
+  std.atan = @same_result_shape
+}
+```
+  }];
+
+  let arguments = (ins SymbolNameAttr:$sym_name,
+   OptionalAttr:$sym_visibility);
+  let arguments = (ins DictionaryAttr:$mapping);
+  let regions = (region AnyRegion:$body);
+
+  let extraClassDeclaration = [{
+/// Returns an associated shape function for an operation if defined.
+FuncOp getShapeFunction(Operation *op);
+  }];
+
+  let builders = [OpBuilderDAG<(ins "StringRef":$name)>];
+  let skipDefaultBuilders = 1;
+
+  let printer = [{ ::print(p, *this); }];
+  let parser = [{ return ::parse$cppClass(parser, result); }];
+}
+
+//===--===//
+// ShapeFunctionLibraryTerminatorOp
+//===--===//
+
+def ShapeFunctionLibraryTerminatorOp : Shape_Op<"fn_lib_terminator",
+[Terminator, HasParent<"FunctionLibraryOp">]> {
+  let summary = "A pseudo op that marks the end of a shape function library";
+  let description = [{
+`shape_fn_lib_terminator` is a special pseudo terminator operation for the
+shape

[llvm-branch-commits] [mlir] e534cee - [mlir] Add a shape function library op

2020-11-29 Thread Jacques Pienaar via llvm-branch-commits

Author: Jacques Pienaar
Date: 2020-11-29T11:15:30-08:00
New Revision: e534cee26ae3626ced20438ea82e11291cc768e8

URL: 
https://github.com/llvm/llvm-project/commit/e534cee26ae3626ced20438ea82e11291cc768e8
DIFF: 
https://github.com/llvm/llvm-project/commit/e534cee26ae3626ced20438ea82e11291cc768e8.diff

LOG: [mlir] Add a shape function library op

Op with mapping from ops to corresponding shape functions for those op
in the library and mechanism to associate shape functions to functions.
The mapping of operand to shape function is kept separate from the shape
functions themselves as the operation is associated to the shape
function and not vice versa, and one could have a common library of
shape functions that can be used in different contexts.

Use fully qualified names and require a name for shape fn lib ops for
now and an explicit print/parse (based around the generated one & GPU
module op ones).

This commit reverts d9da4c3e73720badfcac5c0dc63c0285bb690770. Fixes
missing headers (don't know how that was working locally).

Differential Revision: https://reviews.llvm.org/D91672

Added: 
mlir/test/Analysis/test-shape-fn-report.mlir
mlir/test/lib/Dialect/Shape/CMakeLists.txt
mlir/test/lib/Dialect/Shape/TestShapeFunctions.cpp

Modified: 
mlir/include/mlir/Dialect/Shape/IR/Shape.h
mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
mlir/lib/Dialect/Shape/IR/Shape.cpp
mlir/test/lib/Dialect/CMakeLists.txt
mlir/test/lib/Dialect/Test/TestOps.td
mlir/tools/mlir-opt/CMakeLists.txt
mlir/tools/mlir-opt/mlir-opt.cpp

Removed: 




diff  --git a/mlir/include/mlir/Dialect/Shape/IR/Shape.h 
b/mlir/include/mlir/Dialect/Shape/IR/Shape.h
index f40d6154544a..eab3c6f67ca0 100644
--- a/mlir/include/mlir/Dialect/Shape/IR/Shape.h
+++ b/mlir/include/mlir/Dialect/Shape/IR/Shape.h
@@ -14,9 +14,11 @@
 #ifndef MLIR_SHAPE_IR_SHAPE_H
 #define MLIR_SHAPE_IR_SHAPE_H
 
+#include "mlir/IR/BuiltinOps.h"
 #include "mlir/IR/Dialect.h"
 #include "mlir/IR/OpDefinition.h"
 #include "mlir/IR/OpImplementation.h"
+#include "mlir/IR/SymbolTable.h"
 #include "mlir/Interfaces/ControlFlowInterfaces.h"
 #include "mlir/Interfaces/InferTypeOpInterface.h"
 #include "mlir/Interfaces/SideEffectInterfaces.h"

diff  --git a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td 
b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
index a852d900cf69..52768e49001d 100644
--- a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
+++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
@@ -18,6 +18,7 @@ include "mlir/Interfaces/ControlFlowInterfaces.td"
 include "mlir/Interfaces/InferTypeOpInterface.td"
 include "mlir/Interfaces/SideEffectInterfaces.td"
 include "mlir/IR/OpAsmInterface.td"
+include "mlir/IR/SymbolInterfaces.td"
 
 
//===--===//
 // Shape op definitions
@@ -492,7 +493,7 @@ def Shape_WithOp : Shape_Op<"with_shape", [NoSideEffect]> {
 }
 
 def Shape_YieldOp : Shape_Op<"yield",
-[HasParent<"ReduceOp">,
+[HasParent<"ReduceOp, FunctionLibraryOp">,
  NoSideEffect,
  ReturnLike,
  Terminator]> {
@@ -780,4 +781,62 @@ def Shape_CstrRequireOp : Shape_Op<"cstr_require", []> {
   let hasFolder = 1;
 }
 
+//===--===//
+// Shape collection ops.
+//===--===//
+
+def Shape_FunctionLibraryOp : Shape_Op<"function_library",
+[AffineScope, IsolatedFromAbove, NoRegionArguments, SymbolTable, Symbol,
+ SingleBlockImplicitTerminator<"ShapeFunctionLibraryTerminatorOp">]> {
+  let summary = "Represents shape functions and corresponding ops";
+  let description = [{
+Represents a list of shape functions and the ops whose shape transfer
+functions they represent.
+
+Example:
+
+```mlir
+shape.function_library {
+  func @same_result_shape(%arg: !shape.value_shape) -> !shape.shape {
+%0 = shape.shape_of %arg : !shape.value_shape -> !shape.shape
+return %0 : !shape.shape
+  }
+} mapping {
+  std.atan = @same_result_shape
+}
+```
+  }];
+
+  let arguments = (ins SymbolNameAttr:$sym_name,
+   OptionalAttr:$sym_visibility);
+  let arguments = (ins DictionaryAttr:$mapping);
+  let regions = (region AnyRegion:$body);
+
+  let extraClassDeclaration = [{
+/// Returns an associated shape function for an operation if defined.
+FuncOp getShapeFunction(Operation *op);
+  }];
+
+  let builders = [OpBuilderDAG<(ins "StringRef":$name)>];
+  let skipDefaultBuilders = 1;
+
+  let printer = [{ ::print(p, *this); }];
+  let parser = [{ return ::parse$cppClass(parser, result); }];
+}
+
+//===--===//
+// ShapeFunctionLibraryTerminatorOp
+//===--===//
+
+de

[llvm-branch-commits] [mlir] 9c3fa3d - Don't emit on op diagnostic in reproducer emission

2020-12-13 Thread Jacques Pienaar via llvm-branch-commits

Author: Jacques Pienaar
Date: 2020-12-13T07:21:32-08:00
New Revision: 9c3fa3d84d5cdcdcdb5b6961f2c587f84e7caa39

URL: 
https://github.com/llvm/llvm-project/commit/9c3fa3d84d5cdcdcdb5b6961f2c587f84e7caa39
DIFF: 
https://github.com/llvm/llvm-project/commit/9c3fa3d84d5cdcdcdb5b6961f2c587f84e7caa39.diff

LOG: Don't emit on op diagnostic in reproducer emission

This avoids dumping the module post emitting a reproducer, which results in
many MB logs where a reproducer has already been neatly generated.

Differential Revision: https://reviews.llvm.org/D93165

Added: 


Modified: 
mlir/lib/Pass/Pass.cpp

Removed: 




diff  --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp
index 056da035a5b5..f53a087fac47 100644
--- a/mlir/lib/Pass/Pass.cpp
+++ b/mlir/lib/Pass/Pass.cpp
@@ -765,10 +765,14 @@ 
PassManager::runWithCrashRecovery(MutableArrayRef> passes,
   std::string error;
   if (failed(context.generate(error)))
 return op->emitError(": ") << error;
-  return op->emitError()
- << "A failure has been detected while processing the MLIR module, a "
-"reproducer has been generated in '"
- << *crashReproducerFileName << "'";
+  bool shouldPrintOnOp = op->getContext()->shouldPrintOpOnDiagnostic();
+  op->getContext()->printOpOnDiagnostic(false);
+  op->emitError()
+  << "A failure has been detected while processing the MLIR module, a "
+ "reproducer has been generated in '"
+  << *crashReproducerFileName << "'";
+  op->getContext()->printOpOnDiagnostic(shouldPrintOnOp);
+  return failure();
 }
 
 
//===--===//



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] 7e3b047 - [mlir] Change include image to be toplevel

2020-03-22 Thread Jacques Pienaar via llvm-branch-commits

Author: Jacques Pienaar
Date: 2020-03-22T12:56:57-07:00
New Revision: 7e3b0471715383330c0ea819041497de68051f2d

URL: 
https://github.com/llvm/llvm-project/commit/7e3b0471715383330c0ea819041497de68051f2d
DIFF: 
https://github.com/llvm/llvm-project/commit/7e3b0471715383330c0ea819041497de68051f2d.diff

LOG: [mlir] Change include image to be toplevel

This will match the changes mlir.llvm.org side.

Added: 


Modified: 
mlir/docs/LangRef.md

Removed: 




diff  --git a/mlir/docs/LangRef.md b/mlir/docs/LangRef.md
index a3e5738b49b5..f180075c0d73 100644
--- a/mlir/docs/LangRef.md
+++ b/mlir/docs/LangRef.md
@@ -944,7 +944,7 @@ multidimensional index from one index space to another. For 
example, the
 following figure shows an index map which maps a 2-dimensional index from a 2x2
 index space to a 3x3 index space, using symbols `S0` and `S1` as offsets.
 
-![Index Map Example](includes/img/index-map.svg)
+![Index Map Example](/includes/img/index-map.svg)
 
 The number of domain dimensions and range dimensions of an index map can be
 
diff erent, but must match the number of dimensions of the input and output 
index



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms] Dialect conversion: Add flag to disable rollback (PR #136490)

2025-04-21 Thread Jacques Pienaar via llvm-branch-commits

https://github.com/jpienaar edited 
https://github.com/llvm/llvm-project/pull/136490
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms] Dialect conversion: Add flag to disable rollback (PR #136490)

2025-04-21 Thread Jacques Pienaar via llvm-branch-commits


@@ -861,8 +861,10 @@ struct ConversionPatternRewriterImpl : public 
RewriterBase::Listener {
   /// conversion process succeeds.
   void applyRewrites();
 
-  /// Reset the state of the rewriter to a previously saved point.
-  void resetState(RewriterState state);
+  /// Reset the state of the rewriter to a previously saved point. Optionally,
+  /// the name of the pattern that triggered the rollback can specified for
+  /// debugging purposes.
+  void resetState(RewriterState state, StringRef patternName = "");

jpienaar wrote:

Are patternName params intended to stay post?

https://github.com/llvm/llvm-project/pull/136490
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][Transforms] Dialect conversion: Add flag to disable rollback (PR #136490)

2025-04-21 Thread Jacques Pienaar via llvm-branch-commits

https://github.com/jpienaar approved this pull request.

So this would also allow folks to prefetch the future state? E.g., used to test 
for failures when rollback no longer supported?

https://github.com/llvm/llvm-project/pull/136490
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits