Giter Site home page Giter Site logo

mlir's Introduction

301 - Moved

MLIR is now part of LLVM, more information on https://mlir.llvm.org

The code from this repository can now be found at https://github.com/llvm/llvm-project/tree/main/mlir/

Migration

If you have a local fork of this repository or pull-requests that need to be migrated to the LLVM monorepo, the following recipe may help you:

# From your local MLIR clone:
$ git clone [email protected]:newren/git-filter-repo.git /tmp/git-filter-repo
$ /tmp/git-filter-repo/git-filter-repo --path-rename :mlir/ --force  --message-callback 'return re.sub(b"(#[0-9]+)", b"tensorflow/mlir\\1", message)' --refs <branch name>

After this, all the commits from the previous upstream MLIR should match the ones in the monorepo now. If you don't provide the --refs option, this will rewrite all the branches in your repo.

From there you should be able to rebase any of your branch/commits on top of the LLVM monorepo:

$ git remote set-url origin [email protected]:llvm/llvm-project.git
$ git fetch origin
$ git rebase origin/main -i

Cherry-picking commits should also work, if you checkout the main branch from the monorepo you can git cherry-pick <sha1> from your (rewritten) branches.

You can also export patches with git format-patch <range> and re-apply it on the monorepo using git am <patch file>.

mlir's People

Contributors

aartbik avatar andydavis1 avatar antiagainst avatar benvanik avatar bondhugula avatar chsigg avatar dcaballe avatar denis0x0d avatar dimitriv avatar ftynse avatar gmngeoffrey avatar jingpu avatar joker-eph avatar jpienaar avatar kiszk avatar lattner avatar liufengdb avatar lucarfox avatar nmostafa avatar ombre5733 avatar pifon2a avatar pkanwar23 avatar river707 avatar rmlarsen avatar rsuderman avatar schweitzpgi avatar silvasean avatar smit-hinsu avatar tatianashp avatar thomasjoerg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mlir's Issues

Import MLIR to an external project

Hi! How do you generally suggest to add MLIR to a project using cmake? There is not any config cmake file, as it is for LLVM - LLVMConfig.cmake. And also MLIR libraries are not visible when adding only llvm dependencies in cmakelists. Also, I am not sure how to correctly import MLIR, so that I am able to inherit from the MLIR classes. For llvm I should enable rtti, does the same option work here?

[MLIR:ExecutionEngine] The change in the locking scheme for llvm:orc:ThreadSafeModule causes a build error.

Hello, recently the locking scheme for ThreadSafeModule was changed alongside with an API
https://reviews.llvm.org/rG809e9d1efa2f58b6333b1a0445e8574beedffc22
, so, at least it causes a build error with llvm on trunk:

llvm-project/llvm/projects/mlir/lib/ExecutionEngine/ExecutionEngine.cpp:186:44: error: ‘class llvm::orc::ThreadSafeModule’ has no member named ‘getModule’; did you mean ‘withModuleDo’?
       if (Error err = irTransformer(module.getModule()))

it seems like the workarond could be to wrap the code under #ifdef LLVM_VERSION, but, I might miss some context in it.
@ftynse I found that "makeIRTransformFunction" was implemented by you, can you please take a look?
Thanks.

Add spv.FuncOp to SPIR-V dialect

Currently SPIR-V dialect is using the FuncOp from StandardOps dialect. FuncOp do not allow implicit capture, whereas the SPIR-V specification requires that functions in SPIR-V dialect have access to global variables defined outside off the function. SPIR-V dialect needs to have its own FuncOp to allow such functionality.

Lots of warnings about move semantics when compile with clang-8

When I compile mlir with clang-8 I encountered many warnings seem relevant to move semantics like below. Is it ok keeping it?? (though they didn't appear when I compile it with gcc-8).
I'm expecting just add std::move to suppress these by following the suggestions.

486/1439] Building CXX object projects/mlir/lib/Dialect/...Ops/CMakeFiles/MLIRQuantOps.dir/Utils/QuantizeUtils.cpp.o
In file included from ../projects/mlir/lib/Dialect/QuantOps/Utils/QuantizeUtils.cpp:19:
../projects/mlir/include/mlir/Dialect/QuantOps/UniformSupport.h:97:12: warning: local variable 'result' will be copied despite being returned by name [-Wreturn-std-move]
    return result;
           ^~~~~~
../projects/mlir/include/mlir/Dialect/QuantOps/UniformSupport.h:97:12: note: call 'std::move' explicitly to avoid copying
    return result;
           ^~~~~~
           std::move(result)
1 warning generated.
[487/1439] Building CXX object projects/mlir/lib/Dialect/...ps/CMakeFiles/MLIRQuantOps.dir/Utils/UniformSupport.cpp.o
In file included from ../projects/mlir/lib/Dialect/QuantOps/Utils/UniformSupport.cpp:18:
../projects/mlir/include/mlir/Dialect/QuantOps/UniformSupport.h:97:12: warning: local variable 'result' will be copied despite being returned by name [-Wreturn-std-move]
    return result;
           ^~~~~~
../projects/mlir/include/mlir/Dialect/QuantOps/UniformSupport.h:97:12: note: call 'std::move' explicitly to avoid copying
    return result;
           ^~~~~~
           std::move(result)
1 warning generated.
[513/1439] Building CXX object projects/mlir/lib/Dialect/...CMakeFiles/MLIRQuantOps.dir/Transforms/ConvertConst.cpp.o
In file included from ../projects/mlir/lib/Dialect/QuantOps/Transforms/ConvertConst.cpp:21:
../projects/mlir/include/mlir/Dialect/QuantOps/UniformSupport.h:97:12: warning: local variable 'result' will be copied despite being returned by name [-Wreturn-std-move]
    return result;
           ^~~~~~
../projects/mlir/include/mlir/Dialect/QuantOps/UniformSupport.h:97:12: note: call 'std::move' explicitly to avoid copying
    return result;
           ^~~~~~
...

My configuration and build command.

cmake .. \
    -G Ninja \
    -DCMAKE_C_COMPILER=gcc-8 \
    -DCMAKE_CXX_COMPILER=g++-8 \
    -DLLVM_BUILD_EXAMPLES=OFF \
    -DLLVM_INCLUDE_EXAMPLES=OFF \
    -DLLVM_ENABLE_CXX1Y=Y \
    -DLLVM_TARGETS_TO_BUILD=host \
    -DLLVM_ENABLE_RTTI=ON \
    -DLLVM_ENABLE_ASSERTIONS=ON
cmake --build . --target check-mlir

Visual Studio compilation failure

Current master fails to compile with Visual Studio 2017 and 2019:

C:\Users\meinersbur\src\llvm\projects\mlir\include\mlir/IR/OpDefinition.h(740): error C2976: 'mlir::typelist_contains': too few template arguments
C:\Users\meinersbur\src\llvm\projects\mlir\include\mlir/IR/OpDefinition.h(44): note: see declaration of 'mlir::typelist_contains'
projects\mlir\include\mlir/StandardOps/Ops.h.inc(442): note: see reference to class template instantiation 'mlir::Op<mlir::ConstantOp,mlir::OpTrait::OneResult,mlir::OpTrait::HasNoSideEffect,mlir::OpTrait::NOperands<0>::Impl>' being compiled

This might be a compiler bug as it compiles with gcc and clang. Smaller reproducer:

template <typename ConcreteType>
class MyTrait {};

template<bool B>
class MyBool {};

class MyUsing {
public:
  template <typename ConcreteType>
  using Impl = MyTrait<ConcreteType>;
};

template <typename ConcreteType, template <typename T> class... Traits>
class Test {
  MyBool<typelist_contains<int, Traits<ConcreteType>...>::value> Y;
};

class MyTest : Test<MyTest, MyUsing::Impl> {
} T;

AffineApplyNormalizer::renumber returns invalid map

AffineApplyNormalizer::renumber isn't a publicly exposed method - it however generates invalid maps in some cases. Reproduce with two normalizers created with the maps below:

( )[s0] -> (s0) (%v1)
( )[s0] -> (s0) (%v2)

Calling renumber on the first with the second as argument yields:
( ) (s0) -> (s1) // invalid

The expressions it generates are correct, but the returned map's input dim/symbol count is incorrect (one instead of two here).

AffineMap renumber(const AffineApplyNormalizer &other);

How to understand "statically unpredictable data accesses or control flow"?

I am confused with this sentence.

The presence of statically unpredictable data accesses or control flow does not preclude representation in MLIR, but only limits to a certain extent the ability to reason about and apply transformations using the polyhedral abstraction

Locates in Rationale doc.

Does the unpredictable means that the value of some symbols are determined at runtime, so which branch to go is unpredictable?

Could you please give some detail examples? Thanks!

Top Level Operator will Cause Core Dump

Stack of Core Dump

mlir-opt: /u/qiangz/workspaces/llvm-project/llvm/include/llvm/ADT/SmallVector.h:167: llvm::SmallVectorTemplateCommon::reference llvm::Sma
llVectorTemplateCommon<llvm::StringSet<llvm::MallocAllocator>, void>::back() [T = llvm::StringSet<llvm::MallocAllocator>]: Assertion `!em
pty()' failed.
Stack dump:
0.      Program arguments: ../../../build/bin/mlir-opt a.mlir
1.      Program arguments: ../../../build/bin/mlir-opt a.mlir
 #0 0x00000000009e1319 llvm::sys::PrintStackTrace(llvm::raw_ostream&) /u/qiangz/workspaces/llvm-project/llvm/lib/Support/Unix/Signals.inc:532:11
 #1 0x00000000009e14c9 PrintStackTraceSignalHandler(void*) /u/qiangz/workspaces/llvm-project/llvm/lib/Support/Unix/Signals.inc:593:1
 #2 0x00000000009dfd36 llvm::sys::RunSignalHandlers() /u/qiangz/workspaces/llvm-project/llvm/lib/Support/Signals.cpp:67:5
 #3 0x00000000009e1c1b SignalHandler(int) /u/qiangz/workspaces/llvm-project/llvm/lib/Support/Unix/Signals.inc:384:1
 #4 0x00007f657309d390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
 #5 0x00007f6571bfc428 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x35428)
 #6 0x00007f6571bfe02a abort (/lib/x86_64-linux-gnu/libc.so.6+0x3702a)
 #7 0x00007f6571bf4bd7 (/lib/x86_64-linux-gnu/libc.so.6+0x2dbd7)
 #8 0x00007f6571bf4c82 (/lib/x86_64-linux-gnu/libc.so.6+0x2dc82)
 #9 0x000000000062845b llvm::SmallVectorTemplateCommon<llvm::StringSet<llvm::MallocAllocator>, void>::back() /u/qiangz/workspaces/llvm-project/llvm/include/llvm/ADT/SmallVector.h:168:12
#10 0x0000000000619557 (anonymous namespace)::OperationParser::recordDefinition(llvm::StringRef) /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/lib/Parser/Parser.cpp:2637:39
#11 0x0000000000603ff7 (anonymous namespace)::OperationParser::addDefinition((anonymous namespace)::OperationParser::SSAUseInfo, mlir::Value*) /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/lib/Parser/Parser.cpp:2773:10
#12 0x0000000000601c27 (anonymous namespace)::OperationParser::parseOperation() /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/lib/
Parser/Parser.cpp:3006:13
#13 0x000000000060077d (anonymous namespace)::ModuleParser::parseModule(mlir::ModuleOp) /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/lib/Parser/Parser.cpp:3992:20
#14 0x0000000000600550 mlir::parseSourceFile(llvm::SourceMgr const&, mlir::MLIRContext*) /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/lib/Parser/Parser.cpp:4057:27
#15 0x00000000005fc53a performActions(llvm::raw_ostream&, bool, bool, llvm::SourceMgr&, mlir::MLIRContext*, std::vector<mlir::PassRegistryEntry const*, std::allocator<mlir::PassRegistryEntry const*> > const&) /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/lib/Support/MlirOptMain.cpp:52:26
#16 0x00000000005fc452 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, bool, bool, std::vector<mlir::PassRegistryEntry const*, std::allocator<mlir::PassRegistryEntry const*> > const&) /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/lib/Support/MlirOptMain.cpp:90:12
#17 0x00000000005fbfa7 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, std::vector<mlir::PassRegistryEntry const*, std::allocator<mlir::PassRegistryEntry const*> > const&, bool, bool, bool) /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/lib/Support/MlirOptMain.cpp:153:10
#18 0x00000000008893fb main /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/tools/mlir-opt/mlir-opt.cpp:89:17
#19 0x00007f6571be7830 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x20830)
#20 0x000000000040e1a9 _start (../../../build/bin/mlir-opt+0x40e1a9)

Reproduce

The content of a.mlir is listed below.

%result = "foo.result_op"() : () -> i32

The reproduce command line:

mlir-opt a.mlir

Tips

If the operator is inside module(something like below), then the issue gone.

module {
  %result = "foo.result_op"() : () -> i32
}

Debug Clues

  1. The core dump is caused by below line of function OperationParser::recordDefinition.
    definitionsPerScope.back().insert(def);

    Because the definitionsPerScope is empty and the assert(!empty()); of its back method will cause the core dump.
  2. If the operator is inside module, the parser will meet module operator first, and when parser parse module, the function OperationParser::pushSSANameScope will be called, and the below line of it make the definitionsPerScope is not empty, so the core dump will not happen.
    definitionsPerScope.push_back({});

What is the Correct Way to Add Data Member in User Defined Dialect Type?

Hello,

I am trying to creating my own dialect with a new dialect type, say ToyArrayType, according to your toy example. My ToyArraytype contains an extra member data, a "string".

I want the "string" go along with me during the lowering to my Toy MLIR. However it seems that the ToyArrayType will be cast to mlir::Type during the lowering, and that makes me lost the "string" data because mlir::Type doesn't have that member.

For example, in Ch5/ToyDialect.cpp, function ReshapeOp::build(...), (around line 355), the statement:
state->types.push_back(ToyArrayType::get(builder->getContext()));

It seems that if the ToyArrayType has some member data, the "string", it will lose it when being pushed into the "state->types", which is a SmallVectormlir::Type.

If I am not on the correct path, could you please let me know the best way to add a data member in user dialect type? (without change/hacking codes for mlir::Type).

Thanks very much,
Rui

Parser bug - store op with no memref subscript

On the appended test case, the parser swallows the whole file - no error, no output.

$ mlir-opt bug.mlir
$

=========================================

func @foo(%C: memref<4096x4096xf32>) {
  %9 = constant 0.0 : f32
  affine.store %9, %C : memref<4096x4096xf32>
  return
}

replaceAllMemRefUsesWith leaves stray ops when it fails

When replaceAllMemRefUsesWith fails (when encountering non-deferencing uses of the memref), it returns failure after having processed some number of ops (the replacement ops for the processed ones will have already been introduced -- the IR is left inconsistent). This currently doesn't cause a problem because all use cases of this utility are checking a-priori whether all uses in the part of the IR being considered for replacement are deferencing ones. So, the utility is never expected to fail. However, this won't help future use cases.

This can be easily fixed by first iterating to check if all uses to be replaced are deferencing ones, and then do the replacement in a subsequent pass. While on this, replaceAllMemRefUsesWith can be refactored to introduce replaceMemRefUseWith and call the latter.

Build failure: LLVMIR/ModuleTranslation.cpp

I see build failures with the current LLVM tip: 159f621
and current MLIR 1c1e425

Build config:
CC=clang CXX=clang++ cmake -G Ninja ../llvm -DLLVM_BUILD_EXAMPLES=OFF -DLLVM_ENABLE_CXX1Y=Y -DLLVM_TARGETS_TO_BUILD="host"

/home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/Attributes.h:1142:9: error: call to implicitly-deleted copy constructor of 'mlir::detail::ElementsAttrIteratormlir::Attribute::Iterator'
it(rhs.process<Iterator, ConstructIter>(rhs.it)) {}
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/uday/llvm-project/llvm/projects/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp:98:17: note: in instantiation of member function 'mlir::detail::ElementsAttrIteratormlir::Attribute::ElementsAttrIterator' requested here
for (auto n : elementsAttr.getValues()) {
^
/home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/Attributes.h:1105:21: note: copy constructor of 'Iterator' is implicitly deleted because variant field 'sparseIt' has a non-trivial copy constructor
SparseIteratorT sparseIt;
^
/home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/Attributes.h:1115:14: error: call to implicitly-deleted copy constructor of 'mlir::detail::ElementsAttrIteratormlir::Attribute::Iterator'
return ProcessFn()(args...);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/Attributes.h:1142:16: note: in instantiation of function template specialization 'mlir::detail::ElementsAttrIteratormlir::Attribute::process<mlir::detail::ElementsAttrIteratormlir::Attribute::Iterator, ConstructIter, const mlir::detail::ElementsAttrIteratormlir::Attribute::Iterator>' requested here
it(rhs.process<Iterator, ConstructIter>(rhs.it)) {}
^
/home/uday/llvm-project/llvm/projects/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp:98:17: note: in instantiation of member function 'mlir::detail::ElementsAttrIteratormlir::Attribute::ElementsAttrIterator' requested here
for (auto n : elementsAttr.getValues()) {
^
/home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/Attributes.h:1105:21: note: copy constructor of 'Iterator' is implicitly deleted because variant field 'sparseIt' has a non-trivial copy constructor
SparseIteratorT sparseIt;
^
/home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/Attributes.h:1117:14: error: call to implicitly-deleted copy constructor of 'mlir::detail::ElementsAttrIteratormlir::Attribute::Iterator'
return ProcessFn()(args...);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/Attributes.h:1105:21: note: copy constructor of 'Iterator' is implicitly deleted because variant field 'sparseIt' has a non-trivial copy constructor
SparseIteratorT sparseIt;
^
/home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/Attributes.h:1136:49: error: call to implicitly-deleted copy constructor of 'mlir::detail::ElementsAttrIteratormlir::Attribute::Iterator'
Iterator operator()(const ItT &it) { return Iterator(it); }
^~~~~~~~~~~~
/home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/Attributes.h:1115:14: note: in instantiation of member function 'mlir::detail::ElementsAttrIteratormlir::Attribute::ConstructItermlir::DenseElementsAttr::AttributeElementIterator::operator()' requested here
return ProcessFn()(args...);
^
/home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/Attributes.h:1142:16: note: in instantiation of function template specialization 'mlir::detail::ElementsAttrIteratormlir::Attribute::process<mlir::detail::ElementsAttrIteratormlir::Attribute::Iterator, ConstructIter, const mlir::detail::ElementsAttrIteratormlir::Attribute::Iterator>' requested here
it(rhs.process<Iterator, ConstructIter>(rhs.it)) {}
^
/home/uday/llvm-project/llvm/projects/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp:98:17: note: in instantiation of member function 'mlir::detail::ElementsAttrIteratormlir::Attribute::ElementsAttrIterator' requested here
for (auto n : elementsAttr.getValues()) {
^
/home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/Attributes.h:1105:21: note: copy constructor of 'Iterator' is implicitly deleted because variant field 'sparseIt' has a non-trivial copy constructor
SparseIteratorT sparseIt;
^
/home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/Attributes.h:1136:49: error: call to implicitly-deleted copy constructor of 'mlir::detail::ElementsAttrIteratormlir::Attribute::Iterator'
Iterator operator()(const ItT &it) { return Iterator(it); }
^~~~~~~~~~~~
/home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/Attributes.h:1117:14: note: in instantiation of member function 'mlir::detail::ElementsAttrIteratormlir::Attribute::ConstructIter<llvm::mapped_iterator<llvm::detail::value_sequence_iterator, std::function<mlir::Attribute (long)>, mlir::Attribute> >::operator()' requested here
return ProcessFn()(args...);
^
/home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/Attributes.h:1142:16: note: in instantiation of function template specialization 'mlir::detail::ElementsAttrIteratormlir::Attribute::process<mlir::detail::ElementsAttrIteratormlir::Attribute::Iterator, ConstructIter, const mlir::detail::ElementsAttrIteratormlir::Attribute::Iterator>' requested here
it(rhs.process<Iterator, ConstructIter>(rhs.it)) {}
^
/home/uday/llvm-project/llvm/projects/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp:98:17: note: in instantiation of member function 'mlir::detail::ElementsAttrIteratormlir::Attribute::ElementsAttrIterator' requested here
for (auto n : elementsAttr.getValues()) {
^
/home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/Attributes.h:1105:21: note: copy constructor of 'Iterator' is implicitly deleted because variant field 'sparseIt' has a non-trivial copy constructor
SparseIteratorT sparseIt;
^
In file included from /home/uday/llvm-project/llvm/projects/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp:23:
In file included from /home/uday/llvm-project/llvm/projects/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h:26:
In file included from /home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/Block.h:25:
In file included from /home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/Value.h:25:
In file included from /home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/Types.h:21:
In file included from /home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/TypeSupport.h:26:
In file included from /home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/StorageUniquerSupport.h:26:
In file included from /home/uday/llvm-project/llvm/projects/mlir/include/mlir/Support/STLExtras.h:27:
In file included from /home/uday/llvm-project/llvm/include/llvm/ADT/iterator.h:12:
/home/uday/llvm-project/llvm/include/llvm/ADT/iterator_range.h:46:34: error: no matching constructor for initialization of 'mlir::detail::ElementsAttrIteratormlir::Attribute'
IteratorT end() const { return end_iterator; }
^~~~~~~~~~~~
/home/uday/llvm-project/llvm/projects/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp:98:17: note: in instantiation of member function 'llvm::iterator_range<mlir::detail::ElementsAttrIteratormlir::Attribute >::end' requested here
for (auto n : elementsAttr.getValues()) {
^
/home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/Attributes.h:1170:3: note: candidate constructor template not viable: requires 2 arguments, but 1 was provided
ElementsAttrIterator(unsigned attrKind, IteratorT it)
^
6 errors generated.

MLIR Regression test failures at HEAD (990677db)

Two of the unit tests fail on the current version. It has been independently reproduced by [email protected].

Test configuration

macOS Mojave
version: 10.14.3 (18D109)
MacBook Pro (13-inch, 2018, Four Thunderbolt 3 Ports)
processor 2.3 GHz Intel Core i5
memory 8 GB 2133 MHz LPDDR3
graphics Intel Iris Plus Graphics 655 1536 MB

Unit test summary

********************
Testing Time: 4.09s
********************
Failing Tests (2):
    MLIR :: mlir-cpu-runner/linalg_integration_test.mlir
    MLIR :: mlir-cpu-runner/simple.mlir

  Expected Passes    : 253
  Unsupported Tests  : 4
  Unexpected Failures: 2
FAILED: projects/mlir/test/CMakeFiles/check-mlir 

Full unit test output

[951/952] Running the MLIR regression tests
FAIL: MLIR :: mlir-cpu-runner/simple.mlir (255 of 259)
******************** TEST 'MLIR :: mlir-cpu-runner/simple.mlir' FAILED ********************
Script:
--
: 'RUN: at line 1';   mlir-cpu-runner /Users/ed/llvm-project/llvm/projects/mlir/test/mlir-cpu-runner/simple.mlir | /Users/ed/llvm-project/build/bin/FileCheck /Users/ed/llvm-project/llvm/projects/mlir/test/mlir-cpu-runner/simple.mlir
: 'RUN: at line 2';   mlir-cpu-runner -e foo -init-value 1000 /Users/ed/llvm-project/llvm/projects/mlir/test/mlir-cpu-runner/simple.mlir | /Users/ed/llvm-project/build/bin/FileCheck -check-prefix=NOMAIN /Users/ed/llvm-project/llvm/projects/mlir/test/mlir-cpu-runner/simple.mlir
: 'RUN: at line 3';   mlir-cpu-runner /Users/ed/llvm-project/llvm/projects/mlir/test/mlir-cpu-runner/simple.mlir -O3 | /Users/ed/llvm-project/build/bin/FileCheck /Users/ed/llvm-project/llvm/projects/mlir/test/mlir-cpu-runner/simple.mlir
: 'RUN: at line 4';   mlir-cpu-runner /Users/ed/llvm-project/llvm/projects/mlir/test/mlir-cpu-runner/simple.mlir -O3 -loop-distribute -loop-vectorize | /Users/ed/llvm-project/build/bin/FileCheck /Users/ed/llvm-project/llvm/projects/mlir/test/mlir-cpu-runner/simple.mlir
: 'RUN: at line 5';   mlir-cpu-runner /Users/ed/llvm-project/llvm/projects/mlir/test/mlir-cpu-runner/simple.mlir -loop-distribute -loop-vectorize | /Users/ed/llvm-project/build/bin/FileCheck /Users/ed/llvm-project/llvm/projects/mlir/test/mlir-cpu-runner/simple.mlir
--
Exit Code: 2

Command Output (stderr):
--
Program aborted due to an unhandled Error:
unsupported function typeStack dump:
0.	Program arguments: mlir-cpu-runner /Users/ed/llvm-project/llvm/projects/mlir/test/mlir-cpu-runner/simple.mlir 
0  mlir-cpu-runner          0x000000010c30226c llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 60
1  mlir-cpu-runner          0x000000010c302829 PrintStackTraceSignalHandler(void*) + 25
2  mlir-cpu-runner          0x000000010c300506 llvm::sys::RunSignalHandlers() + 118
3  mlir-cpu-runner          0x000000010c3064f2 SignalHandler(int) + 210
4  libsystem_platform.dylib 0x00007fff61786b3d _sigtramp + 29
5  mlir-cpu-runner          0x000000010f1bb008 llvm::remarks::CurrentRemarkVersion + 12744
6  libsystem_c.dylib        0x00007fff616441c9 abort + 127
7  mlir-cpu-runner          0x000000010c1d4c30 llvm::Error::getPtr() const + 0
8  mlir-cpu-runner          0x000000010c1d5c77 llvm::Error::assertIsChecked() + 87
9  mlir-cpu-runner          0x000000010c1d5bd0 llvm::Error::operator=(llvm::Error&&) + 32
10 mlir-cpu-runner          0x000000010bd0a341 mlir::JitRunnerMain(int, char**, llvm::function_ref<mlir::LogicalResult (mlir::ModuleOp)>) + 1793
11 mlir-cpu-runner          0x000000010badbffb main + 75
12 libdyld.dylib            0x00007fff6159bed9 start + 1
13 libdyld.dylib            0x0000000000000002 start + 18446603338882892074
FileCheck error: '-' is empty.
FileCheck command line:  /Users/ed/llvm-project/build/bin/FileCheck /Users/ed/llvm-project/llvm/projects/mlir/test/mlir-cpu-runner/simple.mlir

--

********************
FAIL: MLIR :: mlir-cpu-runner/linalg_integration_test.mlir (257 of 259)
******************** TEST 'MLIR :: mlir-cpu-runner/linalg_integration_test.mlir' FAILED ********************
Script:
--
: 'RUN: at line 1';   /Users/ed/llvm-project/build/bin/mlir-opt /Users/ed/llvm-project/llvm/projects/mlir/test/mlir-cpu-runner/linalg_integration_test.mlir -linalg-lower-to-llvm-dialect | mlir-cpu-runner -e dot -entry-point-result=f32 -shared-libs=/Users/ed/llvm-project/build/lib/libcblas.dylib,/Users/ed/llvm-project/build/lib/libcblas_interface.dylib | /Users/ed/llvm-project/build/bin/FileCheck /Users/ed/llvm-project/llvm/projects/mlir/test/mlir-cpu-runner/linalg_integration_test.mlir
: 'RUN: at line 2';   /Users/ed/llvm-project/build/bin/mlir-opt /Users/ed/llvm-project/llvm/projects/mlir/test/mlir-cpu-runner/linalg_integration_test.mlir -linalg-lower-to-loops -linalg-lower-to-llvm-dialect | mlir-cpu-runner -e dot -entry-point-result=f32 -shared-libs=/Users/ed/llvm-project/build/lib/libcblas.dylib,/Users/ed/llvm-project/build/lib/libcblas_interface.dylib | /Users/ed/llvm-project/build/bin/FileCheck /Users/ed/llvm-project/llvm/projects/mlir/test/mlir-cpu-runner/linalg_integration_test.mlir
: 'RUN: at line 3';   /Users/ed/llvm-project/build/bin/mlir-opt /Users/ed/llvm-project/llvm/projects/mlir/test/mlir-cpu-runner/linalg_integration_test.mlir -linalg-lower-to-llvm-dialect | mlir-cpu-runner -e matmul -entry-point-result=f32 -shared-libs=/Users/ed/llvm-project/build/lib/libcblas.dylib,/Users/ed/llvm-project/build/lib/libcblas_interface.dylib | /Users/ed/llvm-project/build/bin/FileCheck /Users/ed/llvm-project/llvm/projects/mlir/test/mlir-cpu-runner/linalg_integration_test.mlir
: 'RUN: at line 4';   /Users/ed/llvm-project/build/bin/mlir-opt /Users/ed/llvm-project/llvm/projects/mlir/test/mlir-cpu-runner/linalg_integration_test.mlir -linalg-lower-to-loops -linalg-lower-to-llvm-dialect | mlir-cpu-runner -e matmul -entry-point-result=f32 -shared-libs=/Users/ed/llvm-project/build/lib/libcblas.dylib,/Users/ed/llvm-project/build/lib/libcblas_interface.dylib | /Users/ed/llvm-project/build/bin/FileCheck /Users/ed/llvm-project/llvm/projects/mlir/test/mlir-cpu-runner/linalg_integration_test.mlir
--
Exit Code: 2

Command Output (stderr):
--
Program aborted due to an unhandled Error:
unsupported function typeStack dump:
0.	Program arguments: mlir-cpu-runner -e dot -entry-point-result=f32 -shared-libs=/Users/ed/llvm-project/build/lib/libcblas.dylib,/Users/ed/llvm-project/build/lib/libcblas_interface.dylib 
0  mlir-cpu-runner          0x000000010111026c llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 60
1  mlir-cpu-runner          0x0000000101110829 PrintStackTraceSignalHandler(void*) + 25
2  mlir-cpu-runner          0x000000010110e506 llvm::sys::RunSignalHandlers() + 118
3  mlir-cpu-runner          0x00000001011144f2 SignalHandler(int) + 210
4  libsystem_platform.dylib 0x00007fff61786b3d _sigtramp + 29
5  libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603338880881888
6  libsystem_c.dylib        0x00007fff616441c9 abort + 127
7  mlir-cpu-runner          0x0000000100fe2c30 llvm::Error::getPtr() const + 0
8  mlir-cpu-runner          0x0000000100fe3c77 llvm::Error::assertIsChecked() + 87
9  mlir-cpu-runner          0x0000000100fe3bd0 llvm::Error::operator=(llvm::Error&&) + 32
10 mlir-cpu-runner          0x0000000100b18269 mlir::JitRunnerMain(int, char**, llvm::function_ref<mlir::LogicalResult (mlir::ModuleOp)>) + 1577
11 mlir-cpu-runner          0x00000001008e9ffb main + 75
12 libdyld.dylib            0x00007fff6159bed9 start + 1
FileCheck error: '-' is empty.
FileCheck command line:  /Users/ed/llvm-project/build/bin/FileCheck /Users/ed/llvm-project/llvm/projects/mlir/test/mlir-cpu-runner/linalg_integration_test.mlir

AffineExpr::simplifyAdd bug + fix

Currently, the affine expr, d0 - (d0 + 1), for example, is simplified to 0 in AffineExpr::simplifyAdd. (Any d0 - c * (d0 c) is being simplified to d0 mod c due to a missing conditional.)

func @foo(%M : index) -> index {
%v = affine.apply (d0) -> (d0 -(d0 + 1)) (%M)
return %v : index
}

$ mlir-opt test.mlir
#map0 = (d0) -> (0)

module {
func @foo(%arg0: index) -> index {
%0 = affine.apply #map0(%arg0)
return %0 : index
}
}

This is fixed by changing the following:

if (!lrBinOpExpr)

to

if (!lrBinOpExpr || lrBinOpExpr.getKind() != AffineExprKind::FloorDiv)

Build failure: TestPatterns.inc and EnumsGenTest.cpp.inc

This is from a clean build (and the same cmake conf options as in README.md; gcc (GCC) 9.1.1 20190503 (Red Hat 9.1.1-1)). mlir commit id (latest as of now):
8d4fbbf

The log below is lengthy but here is the key diagnostic:

mlir::tblgen::EnumAttrCase::getValue() const: Assertion `isStrCase() && "cannot get value for EnumAttrCase"' failed.

$ cmake --build . --target check-mlir

[2/14] Building TestPatterns.inc...
FAILED: projects/mlir/test/lib/TestDialect/TestPatterns.inc
cd /home/uday/llvm-project/build && /home/uday/llvm-project/build/bin/mlir-tblgen -gen-rewriters -I/home/uday/llvm-project/llvm/projects/mlir/include -I/home/uday/llvm-project/build/projects/mlir/include -I /home/uday/llvm-project/llvm/projects/mlir/test/lib/TestDialect -I /home/uday/llvm-project/llvm/include /home/uday/llvm-project/llvm/projects/mlir/test/lib/TestDialect/TestOps.td -o projects/mlir/test/lib/TestDialect/TestPatterns.inc -d projects/mlir/test/lib/TestDialect/TestPatterns.inc.d
mlir-tblgen: /home/uday/llvm-project/llvm/projects/mlir/lib/TableGen/Attribute.cpp:152: int64_t mlir::tblgen::EnumAttrCase::getValue() const: Assertion isStrCase() && "cannot get value for EnumAttrCase"' failed. #0 0x00000000004cc29e llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/uday/llvm-project/llvm/lib/Support/Unix/Signals.inc:494:22 #1 0x00000000004cc331 PrintStackTraceSignalHandler(void*) /home/uday/llvm-project/llvm/lib/Support/Unix/Signals.inc:558:1 #2 0x00000000004ca601 llvm::sys::RunSignalHandlers() /home/uday/llvm-project/llvm/lib/Support/Signals.cpp:68:20 #3 0x00000000004cbd95 SignalHandler(int) /home/uday/llvm-project/llvm/lib/Support/Unix/Signals.inc:357:1 #4 0x00007f4e01be2e70 __restore_rt (/lib64/libpthread.so.0+0x12e70) #5 0x00007f4e0168deb5 __GI_raise (/lib64/libc.so.6+0x37eb5) #6 0x00007f4e01678895 __GI_abort (/lib64/libc.so.6+0x22895) #7 0x00007f4e01678769 _nl_load_domain.cold (/lib64/libc.so.6+0x22769) #8 0x00007f4e016865b6 (/lib64/libc.so.6+0x305b6) #9 0x0000000000445f18 mlir::tblgen::EnumAttrCase::getValue() const /home/uday/llvm-project/llvm/projects/mlir/lib/TableGen/Attribute.cpp:152:3 #10 0x0000000000433704 (anonymous namespace)::PatternEmitter::handleOpArgument(mlir::tblgen::DagLeaf, llvm::StringRef) /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/RewriterGen.cpp:635:57 #11 0x000000000043497c (anonymous namespace)::PatternEmitter::emitOpCreate(mlir::tblgen::DagNode, int, int) /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/RewriterGen.cpp:799:46 #12 0x0000000000433393 (anonymous namespace)::PatternEmitter::handleRewritePattern(mlir::tblgen::DagNode, int, int) /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/RewriterGen.cpp:595:1 #13 0x00000000004330a1 (anonymous namespace)::PatternEmitter::emitRewriteMethod() /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/RewriterGen.cpp:549:27 #14 0x0000000000432e28 (anonymous namespace)::PatternEmitter::emit(llvm::StringRef) /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/RewriterGen.cpp:522:3 #15 0x0000000000434ab3 (anonymous namespace)::PatternEmitter::emit(llvm::StringRef, llvm::Record*, llvm::DenseMap<llvm::Record const*, std::unique_ptr<mlir::tblgen::Operator, std::default_delete<mlir::tblgen::Operator> >, llvm::DenseMapInfo<llvm::Record const*>, llvm::detail::DenseMapPair<llvm::Record const*, std::unique_ptr<mlir::tblgen::Operator, std::default_delete<mlir::tblgen::Operator> > > >*, llvm::raw_ostream&) /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/RewriterGen.cpp:809:3 #16 0x0000000000434d6e emitRewriters(llvm::RecordKeeper const&, llvm::raw_ostream&) /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/RewriterGen.cpp:837:43 #17 0x0000000000434eff 'lambda'(llvm::RecordKeeper const&, llvm::raw_ostream&)::operator()(llvm::RecordKeeper const&, llvm::raw_ostream&) const /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/RewriterGen.cpp:854:27 #18 0x00000000004351ea _ZNSt17_Function_handlerIFbRKN4llvm12RecordKeeperERNS0_11raw_ostreamEEUlS3_S5_E_E9_M_invokeERKSt9_Any_dataS3_S5_ /usr/include/c++/9/bits/std_function.h:287:7 #19 0x0000000000413f6b std::function<bool (llvm::RecordKeeper const&, llvm::raw_ostream&)>::operator()(llvm::RecordKeeper const&, llvm::raw_ostream&) const /usr/include/c++/9/bits/std_function.h:691:5 #20 0x000000000041371b mlir::GenInfo::invoke(llvm::RecordKeeper const&, llvm::raw_ostream&) const /home/uday/llvm-project/llvm/projects/mlir/include/mlir/TableGen/GenInfo.h:48:3 #21 0x0000000000412fa3 MlirTableGenMain(llvm::raw_ostream&, llvm::RecordKeeper&) /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/mlir-tblgen.cpp:79:1 #22 0x00000000004fa83f llvm::TableGenMain(char*, bool (*)(llvm::raw_ostream&, llvm::RecordKeeper&)) /home/uday/llvm-project/llvm/lib/TableGen/Main.cpp:105:3 #23 0x00000000004130d2 main /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/mlir-tblgen.cpp:90:22 #24 0x00007f4e01679f33 __libc_start_main (/lib64/libc.so.6+0x23f33) #25 0x0000000000406e3e _start (/home/uday/llvm-project/build/bin/mlir-tblgen+0x406e3e) Stack dump: 0. Program arguments: /home/uday/llvm-project/build/bin/mlir-tblgen -gen-rewriters -I/home/uday/llvm-project/llvm/projects/mlir/include -I/home/uday/llvm-project/build/projects/mlir/include -I /home/uday/llvm-project/llvm/projects/mlir/test/lib/TestDialect -I /home/uday/llvm-project/llvm/include /home/uday/llvm-project/llvm/projects/mlir/test/lib/TestDialect/TestOps.td -o projects/mlir/test/lib/TestDialect/TestPatterns.inc -d projects/mlir/test/lib/TestDialect/TestPatterns.inc.d [2/14] Building TestPatterns.inc... FAILED: projects/mlir/test/lib/TestDialect/TestPatterns.inc cd /home/uday/llvm-project/build && /home/uday/llvm-project/build/bin/mlir-tblgen -gen-rewriters -I/home/uday/llvm-project/llvm/projects/mlir/include -I/home/uday/llvm-project/build/projects/mlir/include -I /home/uday/llvm-project/llvm/projects/mlir/test/lib/TestDialect -I /home/uday/llvm-project/llvm/include /home/uday/llvm-project/llvm/projects/mlir/test/lib/TestDialect/TestOps.td -o projects/mlir/test/lib/TestDialect/TestPatterns.inc -d projects/mlir/test/lib/TestDialect/TestPatterns.inc.d mlir-tblgen: /home/uday/llvm-project/llvm/projects/mlir/lib/TableGen/Attribute.cpp:152: int64_t mlir::tblgen::EnumAttrCase::getValue() const: Assertion isStrCase() && "cannot get value for EnumAttrCase"' failed.
#0 0x00000000004cc29e llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/uday/llvm-project/llvm/lib/Support/Unix/Signals.inc:494:22
#1 0x00000000004cc331 PrintStackTraceSignalHandler(void*) /home/uday/llvm-project/llvm/lib/Support/Unix/Signals.inc:558:1
#2 0x00000000004ca601 llvm::sys::RunSignalHandlers() /home/uday/llvm-project/llvm/lib/Support/Signals.cpp:68:20
#3 0x00000000004cbd95 SignalHandler(int) /home/uday/llvm-project/llvm/lib/Support/Unix/Signals.inc:357:1
#4 0x00007f4e01be2e70 __restore_rt (/lib64/libpthread.so.0+0x12e70)
#5 0x00007f4e0168deb5 __GI_raise (/lib64/libc.so.6+0x37eb5)
#6 0x00007f4e01678895 __GI_abort (/lib64/libc.so.6+0x22895)
#7 0x00007f4e01678769 _nl_load_domain.cold (/lib64/libc.so.6+0x22769)
#8 0x00007f4e016865b6 (/lib64/libc.so.6+0x305b6)
#9 0x0000000000445f18 mlir::tblgen::EnumAttrCase::getValue() const /home/uday/llvm-project/llvm/projects/mlir/lib/TableGen/Attribute.cpp:152:3
#10 0x0000000000433704 (anonymous namespace)::PatternEmitter::handleOpArgument(mlir::tblgen::DagLeaf, llvm::StringRef) /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/RewriterGen.cpp:635:57
#11 0x000000000043497c (anonymous namespace)::PatternEmitter::emitOpCreate(mlir::tblgen::DagNode, int, int) /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/RewriterGen.cpp:799:46
#12 0x0000000000433393 (anonymous namespace)::PatternEmitter::handleRewritePattern(mlir::tblgen::DagNode, int, int) /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/RewriterGen.cpp:595:1
#13 0x00000000004330a1 (anonymous namespace)::PatternEmitter::emitRewriteMethod() /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/RewriterGen.cpp:549:27
#14 0x0000000000432e28 (anonymous namespace)::PatternEmitter::emit(llvm::StringRef) /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/RewriterGen.cpp:522:3
#15 0x0000000000434ab3 (anonymous namespace)::PatternEmitter::emit(llvm::StringRef, llvm::Record*, llvm::DenseMap<llvm::Record const*, std::unique_ptr<mlir::tblgen::Operator, std::default_deletemlir::tblgen::Operator >, llvm::DenseMapInfo<llvm::Record const*>, llvm::detail::DenseMapPair<llvm::Record const*, std::unique_ptr<mlir::tblgen::Operator, std::default_deletemlir::tblgen::Operator > > >, llvm::raw_ostream&) /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/RewriterGen.cpp:809:3
#16 0x0000000000434d6e emitRewriters(llvm::RecordKeeper const&, llvm::raw_ostream&) /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/RewriterGen.cpp:837:43
#17 0x0000000000434eff 'lambda'(llvm::RecordKeeper const&, llvm::raw_ostream&)::operator()(llvm::RecordKeeper const&, llvm::raw_ostream&) const /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/RewriterGen.cpp:854:27
#18 0x00000000004351ea ZNSt17_Function_handlerIFbRKN4llvm12RecordKeeperERNS0_11raw_ostreamEEUlS3_S5_E_E9_M_invokeERKSt9_Any_dataS3_S5 /usr/include/c++/9/bits/std_function.h:287:7
#19 0x0000000000413f6b std::function<bool (llvm::RecordKeeper const&, llvm::raw_ostream&)>::operator()(llvm::RecordKeeper const&, llvm::raw_ostream&) const /usr/include/c++/9/bits/std_function.h:691:5
#20 0x000000000041371b mlir::GenInfo::invoke(llvm::RecordKeeper const&, llvm::raw_ostream&) const /home/uday/llvm-project/llvm/projects/mlir/include/mlir/TableGen/GenInfo.h:48:3
#21 0x0000000000412fa3 MlirTableGenMain(llvm::raw_ostream&, llvm::RecordKeeper&) /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/mlir-tblgen.cpp:79:1
#22 0x00000000004fa83f llvm::TableGenMain(char
, bool ()(llvm::raw_ostream&, llvm::RecordKeeper&)) /home/uday/llvm-project/llvm/lib/TableGen/Main.cpp:105:3
#23 0x00000000004130d2 main /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/mlir-tblgen.cpp:90:22
#24 0x00007f4e01679f33 __libc_start_main (/lib64/libc.so.6+0x23f33)
#25 0x0000000000406e3e _start (/home/uday/llvm-project/build/bin/mlir-tblgen+0x406e3e)
Stack dump:
0. Program arguments: /home/uday/llvm-project/build/bin/mlir-tblgen -gen-rewriters -I/home/uday/llvm-project/llvm/projects/mlir/include -I/home/uday/llvm-project/build/projects/mlir/include -I /home/uday/llvm-project/llvm/projects/mlir/test/lib/TestDialect -I /home/uday/llvm-project/llvm/include /home/uday/llvm-project/llvm/projects/mlir/test/lib/TestDialect/TestOps.td -o projects/mlir/test/lib/TestDialect/TestPatterns.inc -d projects/mlir/test/lib/TestDialect/TestPatterns.inc.d
[3/14] Building EnumsGenTest.h.inc...
FAILED: projects/mlir/unittests/TableGen/EnumsGenTest.h.inc
cd /home/uday/llvm-project/build && /home/uday/llvm-project/build/bin/mlir-tblgen -gen-enum-decls -I/home/uday/llvm-project/llvm/projects/mlir/include -I/home/uday/llvm-project/build/projects/mlir/include -I /home/uday/llvm-project/llvm/projects/mlir/unittests/TableGen -I /home/uday/llvm-project/llvm/include /home/uday/llvm-project/llvm/projects/mlir/unittests/TableGen/enums.td -o projects/mlir/unittests/TableGen/EnumsGenTest.h.inc -d projects/mlir/unittests/TableGen/EnumsGenTest.h.inc.d
mlir-tblgen: /home/uday/llvm-project/llvm/projects/mlir/lib/TableGen/Attribute.cpp:152: int64_t mlir::tblgen::EnumAttrCase::getValue() const: Assertion `isStrCase() && "cannot get value for EnumAttrCase"' failed.
#0 0x00000000004cc29e llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/uday/llvm-project/llvm/lib/Support/Unix/Signals.inc:494:22
#1 0x00000000004cc331 PrintStackTraceSignalHandler(void
) /home/uday/llvm-project/llvm/lib/Support/Unix/Signals.inc:558:1
#2 0x00000000004ca601 llvm::sys::RunSignalHandlers() /home/uday/llvm-project/llvm/lib/Support/Signals.cpp:68:20
#3 0x00000000004cbd95 SignalHandler(int) /home/uday/llvm-project/llvm/lib/Support/Unix/Signals.inc:357:1
#4 0x00007fc7c075ce70 __restore_rt (/lib64/libpthread.so.0+0x12e70)
#5 0x00007fc7c0207eb5 __GI_raise (/lib64/libc.so.6+0x37eb5)
#6 0x00007fc7c01f2895 __GI_abort (/lib64/libc.so.6+0x22895)
#7 0x00007fc7c01f2769 _nl_load_domain.cold (/lib64/libc.so.6+0x22769)
#8 0x00007fc7c02005b6 (/lib64/libc.so.6+0x305b6)
#9 0x0000000000445f18 mlir::tblgen::EnumAttrCase::getValue() const /home/uday/llvm-project/llvm/projects/mlir/lib/TableGen/Attribute.cpp:152:3
#10 0x00000000004071be emitEnumClass(llvm::Record const&, llvm::StringRef, llvm::StringRef, llvm::StringRef, std::vector<mlir::tblgen::EnumAttrCase, std::allocatormlir::tblgen::EnumAttrCase > const&, llvm::raw_ostream&) /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/EnumsGen.cpp:62:37
#11 0x00000000004080f3 emitEnumDecl(llvm::Record const&, llvm::raw_ostream&) /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/EnumsGen.cpp:211:16
#12 0x00000000004084e5 emitEnumDecls(llvm::RecordKeeper const&, llvm::raw_ostream&) /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/EnumsGen.cpp:238:26
#13 0x000000000040889f 'lambda'(llvm::RecordKeeper const&, llvm::raw_ostream&)::operator()(llvm::RecordKeeper const&, llvm::raw_ostream&) const /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/EnumsGen.cpp:278:18
#14 0x0000000000408b04 ZNSt17_Function_handlerIFbRKN4llvm12RecordKeeperERNS0_11raw_ostreamEEUlS3_S5_E_E9_M_invokeERKSt9_Any_dataS3_S5 /usr/include/c++/9/bits/std_function.h:287:7
#15 0x0000000000413f6b std::function<bool (llvm::RecordKeeper const&, llvm::raw_ostream&)>::operator()(llvm::RecordKeeper const&, llvm::raw_ostream&) const /usr/include/c++/9/bits/std_function.h:691:5
#16 0x000000000041371b mlir::GenInfo::invoke(llvm::RecordKeeper const&, llvm::raw_ostream&) const /home/uday/llvm-project/llvm/projects/mlir/include/mlir/TableGen/GenInfo.h:48:3
#17 0x0000000000412fa3 MlirTableGenMain(llvm::raw_ostream&, llvm::RecordKeeper&) /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/mlir-tblgen.cpp:79:1
#18 0x00000000004fa83f llvm::TableGenMain(char*, bool (*)(llvm::raw_ostream&, llvm::RecordKeeper&)) /home/uday/llvm-project/llvm/lib/TableGen/Main.cpp:105:3
#19 0x00000000004130d2 main /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-tblgen/mlir-tblgen.cpp:90:22
#20 0x00007fc7c01f3f33 __libc_start_main (/lib64/libc.so.6+0x23f33)
#21 0x0000000000406e3e _start (/home/uday/llvm-project/build/bin/mlir-tblgen+0x406e3e)
Stack dump:
0. Program arguments: /home/uday/llvm-project/build/bin/mlir-tblgen -gen-enum-decls -I/home/uday/llvm-project/llvm/projects/mlir/include -I/home/uday/llvm-project/build/projects/mlir/include -I /home/uday/llvm-project/llvm/projects/mlir/unittests/TableGen -I /home/uday/llvm-project/llvm/include /home/uday/llvm-project/llvm/projects/mlir/unittests/TableGen/enums.td -o projects/mlir/unittests/TableGen/EnumsGenTest.h.inc -d projects/mlir/unittests/TableGen/EnumsGenTest.h.inc.d
[5/14] Linking CXX executable bin/toyc-ch5
ninja: build stopped: subcommand failed.

[spirv] Add module level constants in SPIR-V dialect

Global variables in SPIR-V now use symbol names instead of returning a SSA values. The initializers of global variables also use these symbol names. Since constants can be used as initializers, module-level constants need to also have symbol names (instead of returning a symbol value).
Also need a mechanism to either materialize these global constant within a function scope so that there is an SSA value to use with other instructions.

Linking error on Debian testing

Linking error

cd "/home/sylvestre/dev/debian/pkg-llvm/llvm-toolchain/branches/llvm-toolchain-snapshot_9~svn357703/build-llvm/projects/mlir/tools/mlir-cpu-runner" && /usr/bin/cmake -E cmake_link_script CMakeFiles/mlir-cpu-runner.dir/link.txt --verbose=1
/usr/bin/g++-8  -g -O2 -fdebug-prefix-map=/home/sylvestre/dev/debian/pkg-llvm/llvm-toolchain/branches/llvm-toolchain-snapshot_9~svn357703=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O2 -DNDEBUG -g1  -Wl,-z,relro -Wl,-allow-shlib-undefined -Llib -Wl,--whole-archive,-lMLIRLLVMIR,-lMLIRStandardOps,-lMLIRTargetLLVMIR,-lMLIRTransforms,-lMLIRTranslation,--no-whole-archive CMakeFiles/mlir-cpu-runner.dir/mlir-cpu-runner.cpp.o  -o ../../../../bin/mlir-cpu-runner ../../../../lib/libMLIRIR.a ../../../../lib/libMLIRAffineOps.a ../../../../lib/libMLIRAnalysis.a ../../../../lib/libMLIREDSC.a ../../../../lib/libMLIRExecutionEngine.a ../../../../lib/libMLIRIR.a ../../../../lib/libMLIRParser.a ../../../../lib/libMLIRTransforms.a ../../../../lib/libMLIRSupport.a ../../../../lib/libLLVMCore.a ../../../../lib/libLLVMSupport.a ../../../../lib/libMLIRVectorOps.a ../../../../lib/libMLIRLLVMIR.a ../../../../lib/libMLIRPass.a ../../../../lib/libLLVMOrcJIT.a ../../../../lib/libLLVMExecutionEngine.a ../../../../lib/libLLVMRuntimeDyld.a ../../../../lib/libLLVMX86CodeGen.a ../../../../lib/libLLVMAsmPrinter.a ../../../../lib/libLLVMDebugInfoDWARF.a ../../../../lib/libLLVMGlobalISel.a ../../../../lib/libLLVMSelectionDAG.a ../../../../lib/libLLVMCodeGen.a ../../../../lib/libLLVMTarget.a ../../../../lib/libLLVMX86Desc.a ../../../../lib/libLLVMX86AsmPrinter.a ../../../../lib/libLLVMX86Utils.a ../../../../lib/libLLVMMCDisassembler.a ../../../../lib/libLLVMX86Info.a ../../../../lib/libLLVMipo.a ../../../../lib/libLLVMBitWriter.a ../../../../lib/libLLVMIRReader.a ../../../../lib/libLLVMAsmParser.a ../../../../lib/libLLVMInstrumentation.a ../../../../lib/libLLVMLinker.a ../../../../lib/libLLVMScalarOpts.a ../../../../lib/libLLVMAggressiveInstCombine.a ../../../../lib/libLLVMInstCombine.a ../../../../lib/libLLVMVectorize.a ../../../../lib/libLLVMTransformUtils.a ../../../../lib/libLLVMAnalysis.a ../../../../lib/libLLVMObject.a ../../../../lib/libLLVMBitReader.a ../../../../lib/libLLVMMCParser.a ../../../../lib/libLLVMMC.a ../../../../lib/libLLVMDebugInfoCodeView.a ../../../../lib/libLLVMDebugInfoMSF.a ../../../../lib/libLLVMProfileData.a ../../../../lib/libLLVMCore.a ../../../../lib/libLLVMBinaryFormat.a ../../../../lib/libMLIRAnalysis.a ../../../../lib/libMLIRAffineOps.a ../../../../lib/libMLIRIR.a ../../../../lib/libMLIRStandardOps.a ../../../../lib/libLLVMSupport.a -lz -lrt -ldl -ltinfo -lpthread -lm ../../../../lib/libLLVMDemangle.a 
/usr/bin/ld : ne peut trouver -lMLIRLLVMIR
/usr/bin/ld : ne peut trouver -lMLIRStandardOps
/usr/bin/ld : ne peut trouver -lMLIRTargetLLVMIR
/usr/bin/ld : ne peut trouver -lMLIRTransforms
/usr/bin/ld : ne peut trouver -lMLIRTranslation
collect2: error: ld returned 1 exit status

Built with:

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/lib/llvm-9 \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O2 -DNDEBUG -g1" \
-DBOOTSTRAP_CMAKE_CXX_FLAGS=' -fuse-ld=gold -fPIC -Wno-unused-command-line-argument -Wno-unknown-warning-option ' \
-DBOOTSTRAP_CMAKE_C_FLAGS=' -fuse-ld=gold -fPIC -Wno-unused-command-line-argument -Wno-unknown-warning-option ' \
-DLLVM_LINK_LLVM_DYLIB=ON \
-DLLVM_INSTALL_UTILS=ON \
-DLLVM_VERSION_SUFFIX= \
-DLLVM_ENABLE_SPHINX=ON \
-DSPHINX_WARNINGS_AS_ERRORS=OFF \
-DLLVM_BUILD_LLVM_DYLIB=ON \
-DLLVM_ENABLE_RTTI=ON \
-DLLVM_ENABLE_FFI=ON \
 -DLLVM_BINUTILS_INCDIR=/usr/include/ -DLLVM_USE_PERF=yes \
-DLIBCLANG_LIBRARY_VERSION=1 \
-DENABLE_LINKER_BUILD_ID=ON \
-DPOLLY_BUNDLED_JSONCPP=OFF \
-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly;AVR" \
-DCLANG_ENABLE_BOOTSTRAP=ON \
-DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON \
-DCLANG_VENDOR=Debian \
-DCLANG_BOOTSTRAP_PASSTHROUGH="CMAKE_INSTALL_PREFIX;CMAKE_VERBOSE_MAKEFILE;CMAKE_BUILD_TYPE;CMAKE_CXX_FLAGS_RELWITHDEBINFO;LLVM_LINK_LLVM_DYLIB;LLVM_INSTALL_UTILS;LLVM_VERSION_SUFFIX;LLVM_ENABLE_SPHINX;SPHINX_WARNINGS_AS_ERRORS;LLVM_BUILD_LLVM_DYLIB;LLVM_ENABLE_RTTI;LLVM_ENABLE_FFI;LIBCLANG_LIBRARY_VERSION;ENABLE_LINKER_BUILD_ID;POLLY_BUNDLED_JSONCPP;LLVM_EXPERIMENTAL_TARGETS_TO_BUILD;LLVM_USE_PERF;LLVM_ENABLE_ASSERTIONS;LLVM_BINUTILS_INCDIR;LLVM_HOST_TRIPLE;;LLVM_COMPILER_CHECKED;COMPILER_RT_BUILD_BUILTINS;LIBOMP_LIBFLAGS;CMAKE_SHARED_LINKER_FLAGS"

Running a pass from inside another pass

Trying to run a pass (via the pass manager as described in https://github.com/tensorflow/mlir/blob/master/g3doc/WritingAPass.md ) from inside another pass leads to all kinds of crashes and weird behavior, and this is expected since there are passes running concurrently on the same functions at the top level and then at an inner level. It does work when pass threading is disabled (at the top level via command-line).

Could such nesting be disallowed by design somehow? (via the context? - if there is a multi-threaded pass manager already running, new ones invoked could assert).

On another note, even if threading is disabled for the inner pass manager, this still creates problems since the 'run' on the pass manager processes all functions of the module, and so will race with the outer level pass manager that's running in parallel. Is there a reason for not exposing a way to run a pass on a function?

applyPatternsGreedily mutates IR even with empty pattern list

applyPatternsGreedily with an empty pattern list still mutates the IR (I wasn't expecting this). This forces users of the method to write tests that consider the compounded effect (even for parts of the IR that they aren't matching on). This also means passes performing pattern rewrites in addition to (and after) doing other transformations will have to check for unexpected effects. Reproduce it for example by running '-canonicalize' after commenting out

op->getCanonicalizationPatterns(patterns, context);

on this test case:

func @test(%arg0: index, %arg1: index, %arg2: index, %arg3: memref<100x200xf32>, %arg4: memref<100x200xf32>) {
  affine.for %arg5 = 0 to %arg0 {
    affine.for %arg6 = 0 to %arg1 {
      %0 = affine.apply (d0) -> (d0)(%arg5)
      %1 = affine.apply (d0) -> (d0)(%arg6)
      "foo"() : () -> ()
      "bar"() : () -> ()
      %2 = affine.load %arg3[%0, %1] : memref<100x200xf32>
    }
  }
  return
}

Bug cause Transforms/test-legalizer.mlir failed, it isn't caught by CI because of it's a assert.

The latest commits will cause test Transforms/test-legalizer.mlir failed when build project as debug mode.

The failure is caught by an assert of llvm assert(!NodePtr->isKnownSentinel());, I guess the CI are all release build, so this failure is not caught.

The root cause of this issue is below new added code of file test/TestDialect/TestPatterns.cpp added by commit: 1fc8140

    // Inline this region into the parent region.
    auto &parentRegion = *op->getContainingRegion();
    rewriter.inlineRegionBefore(op->getRegion(0), parentRegion.end());

parentRegion.end() give the end iterator, from below code we can found it is passed to before, but before need to be an iterator which point to available item, because it need to call the function getParent().

void PatternRewriter::inlineRegionBefore(Region &region,
                                         Region::iterator before) {
  before->getParent()->getBlocks().splice(before, region.getBlocks());
}

rewriter.inlineRegionBefore(op->getRegion(0), parentRegion.end());

before->getParent()->getBlocks().splice(before, region.getBlocks());

The Regression Test Failure Report:

[0/1] Running the MLIR regression tests
-- Testing: 208 tests, 8 threads --
Testing: 0 .. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 
FAIL: MLIR :: Transforms/test-legalizer.mlir (190 of 208)
******************** TEST 'MLIR :: Transforms/test-legalizer.mlir' FAILED ********************
Script:
--
: 'RUN: at line 1';   /u/qiangz/workspaces/llvm-project/build/bin/mlir-test-opt -test-legalize-patterns -split-input-file -verify-diagnostics /remote/ailab1/qiangz/workspaces/llvm-project/llvm/projects/mlir/test/Transforms/test-legalizer.mlir | /u/qiangz/workspaces/llvm-project/build/bin/FileCheck /remote/ailab1/qiangz/workspaces/llvm-project/llvm/projects/mlir/test/Transforms/test-legalizer.mlir --dump-input=fail
--
Exit Code: 2

Command Output (stderr):
--
mlir-test-opt: /u/qiangz/workspaces/llvm-project/llvm/include/llvm/ADT/ilist_iterator.h:139: llvm::ilist_iterator::reference llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Block, true, false, void>, false, false>::operator*() const [OptionsT = llvm::ilist_detail::node_options<mlir::Block, true, false, void>, IsReverse = false, IsConst = false]: Assertion `!NodePtr->isKnownSentinel()' failed.
Stack dump:
0.	Program arguments: /u/qiangz/workspaces/llvm-project/build/bin/mlir-test-opt -test-legalize-patterns -split-input-file -verify-diagnostics /remote/ailab1/qiangz/workspaces/llvm-project/llvm/projects/mlir/test/Transforms/test-legalizer.mlir 
1.	Program arguments: /u/qiangz/workspaces/llvm-project/build/bin/mlir-test-opt -test-legalize-patterns -split-input-file -verify-diagnostics /remote/ailab1/qiangz/workspaces/llvm-project/llvm/projects/mlir/test/Transforms/test-legalizer.mlir 
 #0 0x0000000000544e29 llvm::sys::PrintStackTrace(llvm::raw_ostream&) /u/qiangz/workspaces/llvm-project/llvm/lib/Support/Unix/Signals.inc:494:11
 #1 0x0000000000544fd9 PrintStackTraceSignalHandler(void*) /u/qiangz/workspaces/llvm-project/llvm/lib/Support/Unix/Signals.inc:558:1
 #2 0x00000000005438e6 llvm::sys::RunSignalHandlers() /u/qiangz/workspaces/llvm-project/llvm/lib/Support/Signals.cpp:67:5
 #3 0x000000000054565b SignalHandler(int) /u/qiangz/workspaces/llvm-project/llvm/lib/Support/Unix/Signals.inc:357:1
 #4 0x00007f30414795e0 __restore_rt (/lib64/libpthread.so.0+0xf5e0)
 #5 0x00007f303ffeb1f7 __GI_raise (/lib64/libc.so.6+0x351f7)
 #6 0x00007f303ffec8e8 __GI_abort (/lib64/libc.so.6+0x368e8)
 #7 0x00007f303ffe4266 __assert_fail_base (/lib64/libc.so.6+0x2e266)
 #8 0x00007f303ffe4312 (/lib64/libc.so.6+0x2e312)
 #9 0x000000000057acbb llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Block, true, false, void>, false, false>::operator*() const /u/qiangz/workspaces/llvm-project/llvm/include/llvm/ADT/ilist_iterator.h:140:33
#10 0x00000000006ac435 llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Block, true, false, void>, false, false>::operator->() const /u/qiangz/workspaces/llvm-project/llvm/include/llvm/ADT/ilist_iterator.h:142:32
#11 0x00000000006aa3fd mlir::PatternRewriter::inlineRegionBefore(mlir::Region&, llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Block, true, false, void>, false, false>) /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/lib/IR/PatternMatch.cpp:124:11
#12 0x0000000000590a0d (anonymous namespace)::DialectConversionRewriter::inlineRegionBefore(mlir::Region&, llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Block, true, false, void>, false, false>) /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:432:3
#13 0x00000000004a24d1 (anonymous namespace)::TestRegionRewriteBlockMovement::matchAndRewrite(mlir::Operation*, llvm::ArrayRef<mlir::Value*>, mlir::PatternRewriter&) const /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/test/TestDialect/TestPatterns.cpp:66:5
#14 0x000000000058d5ab mlir::ConversionPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:489:12
#15 0x00000000005924b5 (anonymous namespace)::OperationLegalizer::legalizePattern(mlir::Operation*, mlir::RewritePattern*, (anonymous namespace)::DialectConversionRewriter&) /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:636:8
#16 0x00000000005921f5 (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, (anonymous namespace)::DialectConversionRewriter&) /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:601:19
#17 0x0000000000591dbd (anonymous namespace)::FunctionConverter::convertBlock((anonymous namespace)::DialectConversionRewriter&, mlir::Block*, llvm::DenseSet<mlir::Block*, llvm::DenseMapInfo<mlir::Block*> >&) /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:853:23
#18 0x00000000005903b9 (anonymous namespace)::FunctionConverter::convertRegion((anonymous namespace)::DialectConversionRewriter&, mlir::Region&, bool) /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:890:14
#19 0x000000000058e9e3 (anonymous namespace)::FunctionConverter::convertFunction(mlir::Function*, mlir::TypeConverter::SignatureConversion*) /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:917:11
#20 0x000000000058e7f3 mlir::applyConversionPatterns(llvm::ArrayRef<mlir::Function*>, mlir::ConversionTarget&, mlir::TypeConverter&, std::vector<std::unique_ptr<mlir::RewritePattern, std::default_delete<mlir::RewritePattern> >, std::allocator<std::unique_ptr<mlir::RewritePattern, std::default_delete<mlir::RewritePattern> > > >&&) /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:1126:30
#21 0x000000000058e57b mlir::applyConversionPatterns(mlir::Module&, mlir::ConversionTarget&, mlir::TypeConverter&, std::vector<std::unique_ptr<mlir::RewritePattern, std::default_delete<mlir::RewritePattern> >, std::allocator<std::unique_ptr<mlir::RewritePattern, std::default_delete<mlir::RewritePattern> > > >&&) /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:1097:10
#22 0x00000000004a0cdb (anonymous namespace)::TestLegalizePatternDriver::runOnModule() /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/test/TestDialect/TestPatterns.cpp:113:16
#23 0x00000000005b8007 mlir::ModulePassBase::run(mlir::Module*, mlir::ModuleAnalysisManager&) /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/lib/Pass/Pass.cpp:92:3
#24 0x00000000005b83ea mlir::detail::ModulePassExecutor::run(mlir::Module*, mlir::ModuleAnalysisManager&) /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/lib/Pass/Pass.cpp:132:22
#25 0x00000000005b8c62 mlir::PassManager::run(mlir::Module*) /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/lib/Pass/Pass.cpp:267:15
#26 0x0000000000467235 performActions(llvm::SourceMgr&, mlir::MLIRContext*) /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/tools/mlir-opt/mlir-opt.cpp:96:17
#27 0x00000000004670c5 processFile(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >) /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/tools/mlir-opt/mlir-opt.cpp:138:34
#28 0x0000000000466f2f splitAndProcessFile(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >) /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/tools/mlir-opt/mlir-opt.cpp:166:9
#29 0x0000000000466bcd main /u/qiangz/workspaces/llvm-project/llvm/projects/mlir/tools/mlir-opt/mlir-opt.cpp:197:5
#30 0x00007f303ffd7c05 __libc_start_main (/lib64/libc.so.6+0x21c05)
#31 0x0000000000407a69 _start (/u/qiangz/workspaces/llvm-project/build/bin/mlir-test-opt+0x407a69)
FileCheck error: '-' is empty.
FileCheck command line:  /u/qiangz/workspaces/llvm-project/build/bin/FileCheck /remote/ailab1/qiangz/workspaces/llvm-project/llvm/projects/mlir/test/Transforms/test-legalizer.mlir --dump-input=fail

--

********************
Testing: 0 .. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
Testing Time: 3.02s
********************
Failing Tests (1):
    MLIR :: Transforms/test-legalizer.mlir

  Expected Passes    : 207
  Unexpected Failures: 1
FAILED: projects/mlir/test/CMakeFiles/check-mlir 
cd /u/qiangz/workspaces/llvm-project/build/projects/mlir/test && /usr/bin/python2.7 /u/qiangz/workspaces/llvm-project/build/./bin/llvm-lit -sv /u/qiangz/workspaces/llvm-project/build/projects/mlir/test
ninja: build stopped: subcommand failed.

Build failure: llvm::orc API mismatch?

With the latest versions (commit IDs below), I see the appended build failure.

cmake flags
$ cmake -G Ninja ../llvm -DLLVM_BUILD_EXAMPLES=ON -DLLVM_ENABLE_CXX1Y=Y -DLLVM_TARGETS_TO_BUILD="host" -DCMAKE_BUILD_TYPE=Release

LLVM commit ID:
commit 63db7e3 (HEAD -> master, origin/master, origin/HEAD)
Author: Craig Topper [email protected]
Date: Sun Apr 21 05:18:04 2019 +0000

[X86] Don't form masked vfpclass instruction from and+vfpclass unless the fpclass only has a single use.

llvm-svn: 358841

MLIR commit ID

commit 0f11538 (HEAD -> master, origin/master, origin/HEAD)
Author: Nicolas Vasilache [email protected]
Date: Thu Apr 18 08:25:54 2019 -0700

    Start a Linalg dialect

[13/111] Building CXX object projects/mlir/lib/ExecutionEngine/CMakeFiles/MLIRExecutionEngine.dir/ExecutionEngine.cpp.o
FAILED: projects/mlir/lib/ExecutionEngine/CMakeFiles/MLIRExecutionEngine.dir/ExecutionEngine.cpp.o
/usr/bin/c++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Iprojects/mlir/lib/ExecutionEngine -I/home/uday/git/llvm-project/llvm/projects/mlir/lib/ExecutionEngine -Iinclude -I/home/uday/git/llvm-project/llvm/include -I/home/uday/git/llvm-project/llvm/projects/mlir/include -Iprojects/mlir/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -fdiagnostics-color -ffunction-sections -fdata-sections -O2 -UNDEBUG -fno-exceptions -fno-rtti -std=c++11 -MD -MT projects/mlir/lib/ExecutionEngine/CMakeFiles/MLIRExecutionEngine.dir/ExecutionEngine.cpp.o -MF projects/mlir/lib/ExecutionEngine/CMakeFiles/MLIRExecutionEngine.dir/ExecutionEngine.cpp.o.d -o projects/mlir/lib/ExecutionEngine/CMakeFiles/MLIRExecutionEngine.dir/ExecutionEngine.cpp.o -c /home/uday/git/llvm-project/llvm/projects/mlir/lib/ExecutionEngine/ExecutionEngine.cpp
/home/uday/git/llvm-project/llvm/projects/mlir/lib/ExecutionEngine/ExecutionEngine.cpp: In constructor ‘mlir::impl::OrcJIT::OrcJIT(llvm::orc::JITTargetMachineBuilder, llvm::DataLayout, mlir::impl::OrcJIT::IRTransformer)’:
/home/uday/git/llvm-project/llvm/projects/mlir/lib/ExecutionEngine/ExecutionEngine.cpp:101:19: error: no matching function for call to ‘llvm::orc::DynamicLibrarySearchGenerator::GetForCurrentProcess(llvm::DataLayout&)’
layout)));
^
In file included from /home/uday/git/llvm-project/llvm/projects/mlir/lib/ExecutionEngine/ExecutionEngine.cpp:32:
/home/uday/git/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h:237:3: note: candidate: ‘static llvm::Expectedllvm::orc::DynamicLibrarySearchGenerator llvm::orc::DynamicLibrarySearchGenerator::GetForCurrentProcess(char, llvm::orc::DynamicLibrarySearchGenerator::SymbolPredicate)’
GetForCurrentProcess(char GlobalPrefix,
^~~~~~~~~~~~~~~~~~~~
/home/uday/git/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h:237:3: note: no known conversion for argument 1 from ‘llvm::DataLayout’ to ‘char’
/home/uday/git/llvm-project/llvm/projects/mlir/lib/ExecutionEngine/ExecutionEngine.cpp:100:9: error: ‘cantFail’ was not declared in this scope
cantFail(llvm::orc::DynamicLibrarySearchGenerator::GetForCurrentProcess(
^~~~~~~~
/home/uday/git/llvm-project/llvm/projects/mlir/lib/ExecutionEngine/ExecutionEngine.cpp:100:9: note: suggested alternative:
In file included from /home/uday/git/llvm-project/llvm/projects/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h:27,
from /home/uday/git/llvm-project/llvm/projects/mlir/lib/ExecutionEngine/ExecutionEngine.cpp:22:
/home/uday/git/llvm-project/llvm/include/llvm/Support/Error.h:749:4: note: ‘llvm::cantFail’
T& cantFail(Expected<T&> ValOrErr, const char *Msg = nullptr) {

Compilation fails with latest llvm (after revision 368707)

It seems llvm/llvm-project@52a34a7 (made yesterday, what timing!) breaks lib/ExecutionEngine/ExecutionEngine.cpp:

.../llvm-project/llvm/projects/mlir/lib/ExecutionEngine/ExecutionEngine.cpp: In constructor ‘mlir::impl::SearchGenerator::SearchGenerator(char)’:
.../llvm-project/llvm/projects/mlir/lib/ExecutionEngine/ExecutionEngine.cpp:87:31: error: no matching function for call to ‘llvm::orc::DynamicLibrarySearchGenerator::DynamicLibrarySearchGenerator(std::unique_ptr<llvm::orc::DynamicLibrarySearchGenerator>)’
                 GlobalPrefix))) {}
                               ^
In file included from .../llvm-project/llvm/projects/mlir/lib/ExecutionEngine/ExecutionEngine.cpp:28:0:
.../llvm-project/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h:253:3: note: candidate: llvm::orc::DynamicLibrarySearchGenerator::DynamicLibrarySearchGenerator(llvm::sys::DynamicLibrary, char, llvm::orc::DynamicLibrarySearchGenerator::SymbolPredicate)
   DynamicLibrarySearchGenerator(sys::DynamicLibrary Dylib, char GlobalPrefix,
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../llvm-project/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h:253:3: note:   candidate expects 3 arguments, 1 provided
.../llvm-project/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h:243:7: note: candidate: llvm::orc::DynamicLibrarySearchGenerator::DynamicLibrarySearchGenerator(const llvm::orc::DynamicLibrarySearchGenerator&)
 class DynamicLibrarySearchGenerator : public JITDylib::DefinitionGenerator {
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../llvm-project/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h:243:7: note:   no known conversion for argument 1 from ‘std::unique_ptr<llvm::orc::DynamicLibrarySearchGenerator>’ to ‘const llvm::orc::DynamicLibrarySearchGenerator&’
.../llvm-project/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h:243:7: note: candidate: llvm::orc::DynamicLibrarySearchGenerator::DynamicLibrarySearchGenerator(llvm::orc::DynamicLibrarySearchGenerator&&)
.../llvm-project/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h:243:7: note:   no known conversion for argument 1 from ‘std::unique_ptr<llvm::orc::DynamicLibrarySearchGenerator>’ to ‘llvm::orc::DynamicLibrarySearchGenerator&&’
.../llvm-project/llvm/projects/mlir/lib/ExecutionEngine/ExecutionEngine.cpp: In member function ‘llvm::Expected<llvm::DenseSet<llvm::orc::SymbolStringPtr> > mlir::impl::SearchGenerator::operator()(llvm::orc::JITDylib&, const SymbolNameSet&)’:
.../llvm-project/llvm/projects/mlir/lib/ExecutionEngine/ExecutionEngine.cpp:94:42: error: no match for call to ‘(llvm::orc::DynamicLibrarySearchGenerator) (llvm::orc::JITDylib&, const SymbolNameSet&)’
     auto res = defaultGenerator(JD, Names);
                                          ^
.../llvm-project/llvm/projects/mlir/lib/ExecutionEngine/ExecutionEngine.cpp: In constructor ‘mlir::impl::OrcJIT::OrcJIT(llvm::orc::JITTargetMachineBuilder, llvm::DataLayout, mlir::impl::OrcJIT::IRTransformer, llvm::ArrayRef<llvm::StringRef>)’:
.../llvm-project/llvm/projects/mlir/lib/ExecutionEngine/ExecutionEngine.cpp:142:31: error: ‘class llvm::orc::JITDylib’ has no member named ‘setGenerator’; did you mean ‘addGenerator’?
     session.getMainJITDylib().setGenerator(
                               ^~~~~~~~~~~~
                               addGenerator
.../llvm-project/llvm/projects/mlir/lib/ExecutionEngine/ExecutionEngine.cpp: In member function ‘void mlir::impl::OrcJIT::loadLibraries(llvm::ArrayRef<llvm::StringRef>)’:
.../llvm-project/llvm/projects/mlir/lib/ExecutionEngine/ExecutionEngine.cpp:226:8: error: ‘class llvm::orc::JITDylib’ has no member named ‘setGenerator’; did you mean ‘addGenerator’?
     JD.setGenerator(loaded.get());
        ^~~~~~~~~~~~
        addGenerator

In short:

  1. llvm::orc::JITDylib.setGenerator seems to have been replaced by .addGenerator
  2. SearchGenerator now has to extend llvm::orc::JITDylib::DefinitionGenerator
  3. Many of the generator-related APIs now take and return unique_ptrs

Add mlir-vulkan-runner

It would be nice to have a simple testing harness to exercise the SPIR-V blob generated and serialized from SPIR-V CodeGen on Vulkan-capable devices, similar to mlir-cuda-runner.

Ideally the runner should inspect the SPIR-V module to help building the resource interface for a Vulkan compute pipeline, run the compute pipeline by feeding in test data and then check the result data.

Missing documentation on setup ... need ninja

Congrats on the release. For fun, I tried to compile on my Mac and it has some issues if I follow the doc ... I have Xcode and I installed CMake via brew.

Must be a simple config issue. Happy to fix, if there is interest.

DEDUTTA:build dedutta$ cmake -G Ninja ../llvm -DLLVM_BUILD_EXAMPLES=ON
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_ASM_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
See also "/Users/dedutta/llvm-project/build/CMakeFiles/CMakeOutput.log".
DEDUTTA:build dedutta$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.10.44.4)
Target: x86_64-apple-darwin18.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

This is due to non install of Ninja .....

Add spv.CompositeExtract

The spec for this op is at https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#OpCompositeExtract.

We use Op Definition Spec (ODS) to describe the op, the doc for ODS is here: https://github.com/tensorflow/mlir/blob/master/g3doc/OpDefinitions.md

Useful SPIR-V ODS definitions:

def SPV_Composite: AnyTypeOf<[SPV_Vector, SPV_AnyArray]>;

It would be nice to define the custom assembly format to look like std.extract_element:

mlir/lib/StandardOps/Ops.cpp

Lines 1579 to 1594 in 34f7a2d

static ParseResult parseExtractElementOp(OpAsmParser *parser,
OperationState *result) {
OpAsmParser::OperandType aggregateInfo;
SmallVector<OpAsmParser::OperandType, 4> indexInfo;
ShapedType type;
auto affineIntTy = parser->getBuilder().getIndexType();
return failure(
parser->parseOperand(aggregateInfo) ||
parser->parseOperandList(indexInfo, OpAsmParser::Delimiter::Square) ||
parser->parseOptionalAttributeDict(result->attributes) ||
parser->parseColonType(type) ||
parser->resolveOperand(aggregateInfo, type, result->operands) ||
parser->resolveOperands(indexInfo, affineIntTy, result->operands) ||
parser->addTypeToList(type.getElementType(), result->types));
}

test:

mlir/test/IR/core-ops.mlir

Lines 357 to 368 in 34f7a2d

// CHECK-LABEL: func @extract_element(%arg0: tensor<*xi32>, %arg1: tensor<4x4xf32>) -> i32 {
func @extract_element(%arg0: tensor<*xi32>, %arg1 : tensor<4x4xf32>) -> i32 {
%c0 = "std.constant"() {value = 0: index} : () -> index
// CHECK: %0 = extract_element %arg0[%c0, %c0, %c0, %c0] : tensor<*xi32>
%0 = extract_element %arg0[%c0, %c0, %c0, %c0] : tensor<*xi32>
// CHECK: %1 = extract_element %arg1[%c0, %c0] : tensor<4x4xf32>
%1 = extract_element %arg1[%c0, %c0] : tensor<4x4xf32>
return %0 : i32
}

So for spv.CompositeExtract, we will have something like

spv.CompositeExtract %composite[%index0, %index1, ...] : <extracted-type>

It would be nice to implement the validation rules specified in the op description. You may want to use spv.struct, spv.array and other types for writing tests.

See the code for adding spv.Load/spv.Store as reference: 0c0217d

Use alloca instead of malloc for 0-d memref's? Getting scalar replacement working.

One way to hoist loop invariant memref load/store's and replace such subscripted accesses by scalars is by introducing 0-d memref's (load/store from the main memref to those 0-d memref's, then access the latter inside the loop), and rely on LLVM's mem2reg to eliminate the lowered counterparts of those 0-d memref's away, substituting (scalar) SSA values instead. However, currently, the lowering of MLIR's alloc to LLVM's malloc (in the -lower-to-llvm pass) gets in the way, but is trivially fixable as shown below.

Here's simple MLIR obtained after hoisting a loop invariant load (assume that the 0-d memref %s was automatically introduced by a pass/utility that performed the hosting for a loop invariant load on the original %A):

func @foo() {
  %c0 = constant 0 : index
  %cf0 = constant 0.0 : f32
  %A = alloc() : memref<1024xf32>
  %s = alloc() : memref<f32>
  %v = load %A[%c0] : memref<1024xf32>
  store %v, %s[]: memref<f32>

  affine.for %i = 0 to 1024 {
    %w = load %s[] : memref<f32>
    %r = addf %w, %cf0 : f32
  }
  return
}

The current lowering to LLVM yields:
(-lower-affine -lower-to-llvm | mlir-translate -mlir-to-llvmir)

; ModuleID = 'LLVMDialectModule'
source_filename = "LLVMDialectModule"

declare i8* @malloc(i64)

declare void @free(i8*)

define void @foo() {
  %1 = call i8* @malloc(i64 4096)
  %2 = bitcast i8* %1 to float*
  %3 = call i8* @malloc(i64 4)
  %4 = bitcast i8* %3 to float*
  %5 = getelementptr float, float* %2, i64 0
  %6 = load float, float* %5
  store float %6, float* %4
  br label %7

7:                                                ; preds = %10, %0
  %8 = phi i64 [ %13, %10 ], [ 0, %0 ]
  %9 = icmp slt i64 %8, 1024
  br i1 %9, label %10, label %14

10:                                               ; preds = %7
  %11 = load float, float* %4
  %12 = fadd float %11, 0.000000e+00
  %13 = add i64 %8, 1
  br label %7

14:                                               ; preds = %7
  ret void
}

'mem2reg' on this doesn't yield the desired replacement (expected?).

However, using an alloca for the single element memref makes the whole thing work:

$ opt -S /tmp/test4.mlir -mem2reg
; ModuleID = '/tmp/test4.mlir'
source_filename = "LLVMDialectModule"

declare i8* @malloc(i64)

declare void @free(i8*)

define void @foo() {
  %1 = call i8* @malloc(i64 4096)
  %2 = bitcast i8* %1 to float*
  %3 = call i8* @malloc(i64 4)
  %4 = getelementptr float, float* %2, i64 0
  %5 = load float, float* %4
  br label %6

6:                                                ; preds = %9, %0
  %7 = phi i64 [ %11, %9 ], [ 0, %0 ]
  %8 = icmp slt i64 %7, 1024
  br i1 %8, label %9, label %12

9:                                                ; preds = %6
  %10 = fadd float %5, 0.000000e+00
  %11 = add i64 %7, 1
  br label %6

12:                                               ; preds = %6
  ret void
}

One option here would be to have AllocOpLowering use 'alloca' for 0-d memrefs (they have a single element by definition) instead of a malloc + bitcast,

struct AllocOpLowering : public LLVMLegalizationPattern<AllocOp> {

but this would require the lowering to check for lifetimes - a concern that shouldn't be part of the lowering. Instead, one would want to have a pass/utility to replace alloc's with llvm.alloca when appropriate, but this isn't "lowering path neutral" and thus not reusable infra. Should one have a new standard op alloca for stack allocation so that a pass/utility could replace with when appropriate or in the first place generate such alloca's in place of alloc? The current alloc op doesn't say where memory gets allocated from.

(On a side note, another way to accomplish such scalar replacement of accesses is by leveraging support for loop live-out scalars when the IR supports it, but there are still good reasons for doing this via single element memref's and then relying on mem2reg, and also being able to go from one form to the other in MLIR itself.)

Problem when lower-to-llvm, when load/store a memref with its layout map

Hello,

I am trying to lower the following code to llvm:

func @load_store() {
^bb0:
// CHECK: %0 = alloc() : memref<1024x64xf32, 1>
%0 = alloc() : memref<1024x64xf32, (d0, d1) -> (d0, d1), 1>

%1 = constant 0 : index
%2 = constant 1 : index

// CHECK: %1 = load %0[%c0, %c1] : memref<1024x64xf32, 1>
%3 = load %0[%1, %2] : memref<1024x64xf32, (d0, d1) -> (d0, d1), 1>

// CHECK: store %1, %0[%c0, %c1] : memref<1024x64xf32, 1>
store %3, %0[%1, %2] : memref<1024x64xf32, (d0, d1) -> (d0, d1), 1>

return
}

I am using command: mlir-opt $INPUT_FILE --lower-affine --lower-to-llvm

But I got the following error message:

./mytmptest/memref_internal.mlir:10:8: error: 'llvm.getelementptr' op operand #0 must be LLVM dialect type
%3 = load %0[%1, %2] : memref<1024x64xf32, (d0, d1) -> (d0, d1), 1>
^

Could you please help to figure out the correct way for generating llvm code for the same or similar mlir code?

Thanks,
Rui

mlir-translate error + missing location pointing

On the appended MLIR, mlir-translate produces this error.

$ mlir-translate -mlir-to-llvmir /tmp/single.mlir
loc("/tmp/single.mlir":1:6): error: non-LLVM function argument type

I see two issues:

  1. On a minor note, the error message is missing reproduction and pinpointing to the source line being referred to.
  2. It's not clear what the error is about. It looks like it's pointing to the '@' sigil (the sixth character), but that's not a function argument. Is this due to something missing with memref type lowering? The doc at https://github.com/tensorflow/mlir/blob/master/g3doc/ConversionToLLVMDialect.md doesn't say so.

func @simple_func(%arg0: memref<8x8xvector<64xf32>>, %arg1: memref<8x8xvector<64xf32>>, %arg2: memref<8x8xvector<64xf32>>) -> memref<8x8xvector<64xf32>> {
affine.for %i = 0 to 256 {
affine.for %j = 0 to 256 {
affine.for %k = 0 to 250 {
%l = load %arg0[%i, %k] : memref<8x8xvector<64xf32>>
%r = load %arg1[%k, %j] : memref<8x8xvector<64xf32>>
%o = load %arg2[%i, %j] : memref<8x8xvector<64xf32>>
%m = mulf %l, %r : vector<64xf32>
%a = addf %o, %m : vector<64xf32>
store %a, %arg2[%i, %j] : memref<8x8xvector<64xf32>>
}
}
}
return %arg2 : memref<8x8xvector<64xf32>>
}

Build time errors

projects/mlir/include/mlir/LLVMIR/LLVMOps.h.inc:434:13: error: ‘mlir::LLVM::SubOp::SubOp(mlir::Operation*)’ is protected
   using Op::Op;
             ^
In file included from /home/y00469885/llvm-project/llvm/projects/mlir/include/mlir/IR/Function.h:29:0,
                 from /home/y00469885/llvm-project/llvm/projects/mlir/include/mlir/IR/Builders.h:21,
                 from /home/y00469885/llvm-project/llvm/projects/mlir/lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp:23:
/home/y00469885/llvm-project/llvm/projects/mlir/include/mlir/IR/Operation.h:396:24: error: within this context
     return OpClass(this);
                        ^
ninja: build stopped: subcommand failed.

Followed the steps:

git clone https://github.com/llvm/llvm-project.git
cd llvm-project/llvm/projects/
git clone https://github.com/tensorflow/mlir
cd ../..
mkdir build
cd build
cmake -G Ninja ../llvm -DLLVM_BUILD_EXAMPLES=ON
ninja check-mlir

Failing test with optimized build

With an optimized build

$ cmake -G Ninja ../llvm -DLLVM_BUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=Release

I see one failing test case.

$ ninja check-mlir
...
[ FAILED ] 1 test, listed below:
[ FAILED ] DialectDeathTest.MultipleDialectsWithSameNamespace

1 FAILED TEST


Testing Time: 0.81s


Failing Tests (1):
MLIR-Unit :: IR/./MLIRIRTests/DialectDeathTest.MultipleDialectsWithSameNamespace

Expected Passes : 98
Unexpected Failures: 1
FAILED: projects/mlir/test/CMakeFiles/check-mlir
cd /home/uday/git/llvm-project/build_opt/projects/mlir/test && /usr/bin/python2.7 /home/uday/git/llvm-project/build_opt/./bin/llvm-lit -sv /home/uday/git/llvm-project/build_opt/projects/mlir/test
ninja: build stopped: subcommand failed.
[uday@ukr-x1-laptop ~/git/llvm-project/build_opt]₹ ^C
[uday@ukr-x1-laptop ~/git/llvm-project/build_opt]₹ cmake -G Ninja ../llvm -DLLVM_BUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=Release^C
[uday@ukr-x1-laptop ~/git/llvm-project/build_opt]₹ ninja check-mlir
[0/1] Running the MLIR regression tests
FAIL: MLIR-Unit :: IR/./MLIRIRTests/DialectDeathTest.MultipleDialectsWithSameNamespace (10 of 99)
******************** TEST 'MLIR-Unit :: IR/./MLIRIRTests/DialectDeathTest.MultipleDialectsWithSameNamespace' FAILED ********************
Note: Google Test filter = DialectDeathTest.MultipleDialectsWithSameNamespace
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from DialectDeathTest
[ RUN ] DialectDeathTest.MultipleDialectsWithSameNamespace
/home/uday/git/llvm-project/llvm/projects/mlir/unittests/IR/DialectTest.cpp:35: Failure
Death test: new TestDialect(&context)
Result: failed to die.
Error msg:
[ DEATH ]
[ FAILED ] DialectDeathTest.MultipleDialectsWithSameNamespace (0 ms)
[----------] 1 test from DialectDeathTest (0 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (1 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] DialectDeathTest.MultipleDialectsWithSameNamespace

1 FAILED TEST


Testing Time: 0.81s


Failing Tests (1):
MLIR-Unit :: IR/./MLIRIRTests/DialectDeathTest.MultipleDialectsWithSameNamespace

Expected Passes : 98
Unexpected Failures: 1
FAILED: projects/mlir/test/CMakeFiles/check-mlir
cd /home/uday/git/llvm-project/build_opt/projects/mlir/test && /usr/bin/python2.7 /home/uday/git/llvm-project/build_opt/./bin/llvm-lit -sv /home/uday/git/llvm-project/build_opt/projects/mlir/test
ninja: build stopped: subcommand failed.

Bugs in examples/Linalg2 TensorOps.h ?

In the Linalg dialect example: examples/Linalg/Linalg2/include/linalg2/TensorOps.h why the 3 op classes are all defined with mlir::OpTrait::ZeroResult?

/// Implements c = A * B where c is a scalar and A and B are 1-D vectors.
class DotOp : public TensorContractionBase<DotOp>,
              public mlir::Op<DotOp, mlir::OpTrait::VariadicOperands,
                              mlir::OpTrait::ZeroResult> {


/// Implements C = A * B where A is a 2-D matrix and X and Y are 1-D vectors.
class MatvecOp : public TensorContractionBase<MatvecOp>,
                 public mlir::Op<MatvecOp, mlir::OpTrait::VariadicOperands,
                                 mlir::OpTrait::ZeroResult> {


/// Implements C = A * B on 2-D matrices.
class MatmulOp : public TensorContractionBase<MatmulOp>,
                 public mlir::Op<MatmulOp, mlir::OpTrait::VariadicOperands,
                                 mlir::OpTrait::ZeroResult> {

Why not mlir::OpTrait::OneResult? Thanks!

How to convert MLIR to SPIR-V?

Would you like to give me any information how to convert from MLIR to SPIR-V?
I tried to use mlir-translate with serialize-spirv option, but I couldn't realize how to use this option.

-lower-to-llvm minor bug / misleading error message

On the input:

func @foo(%0 : f32, %1 : vector<8xf32>) {
  %2 = "splat"(%0) : (f32) -> vector<8xf32>
  %3 = mulf %1, %2 : vector<8xf32>
  return
}

$ mlir-opt -lower-to-llvm /tmp/out.mlir

/tmp/out.mlir:5:8: error: 'llvm.fmul' op requires the same type for all operands and results
  %3 = mulf %1, %2 : vector<8xf32>
       ^

Both its operands are already vector<8xf32>! Also, since -lower-to-llvm is implemented as a partial conversion, one would expect it to just lower the mulf correctly and not worry about "splat" here?

Ignored failure when legalizing block ops

Hi!

We recently updated the version of MLIR that we are using for our nGraph dialect and noticed that the rewriter now has checks wrt legality of generated operations in the context of the destination dialect. This is great! It uncovered that we were generating an unsupported operation during the nGraph->affine lowering. However, root-causing the problem was a bit tricky since the applyConversionPatterns API didn’t return a failure and our compiler crashed far down the road. I found out that OperationLegalizer::legalize returned failure but this is ignored by the caller: https://github.com/tensorflow/mlir/blob/master/lib/Transforms/DialectConversion.cpp#L911

Is this an expected behavior? If so, would it make sense to have a stricter path/mode that propagates the failure to the caller instead?

Thanks!
Diego

Build failure - missing std::index_sequence - C++-14 flag missing?

With the current resp. tips of LLVM and MLIR, the build fails with messages below (with both clang and gcc). Looks like the -std=c++14 compile flag is missing from the conf?

In file included from /home/uday/llvm-project-bondhugula/llvm/projects/mlir/lib/TableGen/Argument.cpp:18:
In file included from /home/uday/llvm-project-bondhugula/llvm/projects/mlir/include/mlir/TableGen/Argument.h:33:
In file included from /home/uday/llvm-project-bondhugula/llvm/projects/mlir/include/mlir/TableGen/Attribute.h:27:
In file included from /home/uday/llvm-project-bondhugula/llvm/projects/mlir/include/mlir/TableGen/Constraint.h:28:
In file included from /home/uday/llvm-project-bondhugula/llvm/include/llvm/ADT/StringRef.h:12:
/home/uday/llvm-project-bondhugula/llvm/include/llvm/ADT/STLExtras.h:567:49: error: no template named 'index_sequence' in namespace 'std'
template <size_t... Ns> value_type deref(std::index_sequence<Ns...>) const {
~~~~~^
/home/uday/llvm-project-bondhugula/llvm/include/llvm/ADT/STLExtras.h:572:36: error: no template named 'index_sequence' in namespace 'std'
decltype(iterators) tup_inc(std::index_sequence<Ns...>) const {
~~~~~^
/home/uday/llvm-project-bondhugula/llvm/include/llvm/ADT/STLExtras.h:577:36: error: no template named 'index_sequence' in namespace 'std'
decltype(iterators) tup_dec

Build warnings

I noticed these two warnings while building out of the box (with gcc (GCC) 8.3.1).

[236/1306] Building CXX object lib/IR/CMakeFiles/LLVMCore.dir/Core.cpp.o
/home/uday/git/llvm-project/llvm/lib/IR/Core.cpp: In function ‘void LLVMContextSetDiagnosticHandler(LLVMContextRef, LLVMDiagnosticHandler, void*)’:
/home/uday/git/llvm-project/llvm/lib/IR/Core.cpp:89:18: warning: cast between incompatible function types from ‘LLVMDiagnosticHandler’ {aka ‘void ()(LLVMOpaqueDiagnosticInfo, void*)’} to ‘llvm::DiagnosticHandler::DiagnosticHandlerTy’ {aka ‘void ()(const llvm::DiagnosticInfo&, void)’} [-Wcast-function-type]
Handler),
^
/home/uday/git/llvm-project/llvm/lib/IR/Core.cpp: In function ‘void (* LLVMContextGetDiagnosticHandler(LLVMContextRef))(LLVMDiagnosticInfoRef, void*)’:
/home/uday/git/llvm-project/llvm/lib/IR/Core.cpp:95:48: warning: cast between incompatible function types from ‘llvm::DiagnosticHandler::DiagnosticHandlerTy’ {aka ‘void ()(const llvm::DiagnosticInfo&, void)’} to ‘LLVMDiagnosticHandler’ {aka ‘void ()(LLVMOpaqueDiagnosticInfo, void*)’} [-Wcast-function-type]
unwrap(C)->getDiagnosticHandlerCallBack());
^
[412/1306] Building CXX object lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/ScheduleDAGInstrs.cpp.o
/home/uday/git/llvm-project/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp:1473:14: warning: declaration of ‘llvm::raw_ostream& llvm::operator<<(llvm::raw_ostream&, const llvm::ILPValue&)’ with attribute ‘noinline’ follows inline declaration [-Wattributes]
raw_ostream &operator<<(raw_ostream &OS, const ILPValue &Val) {
^~~~~~~~
In file included from /home/uday/git/llvm-project/llvm/include/llvm/MC/MCDwarf.h:23,
from /home/uday/git/llvm-project/llvm/include/llvm/CodeGen/MachineFunction.h:36,
from /home/uday/git/llvm-project/llvm/include/llvm/CodeGen/SelectionDAG.h:34,
from /home/uday/git/llvm-project/llvm/include/llvm/CodeGen/TargetLowering.h:35,
from /home/uday/git/llvm-project/llvm/include/llvm/CodeGen/ScheduleDAG.h:24,
from /home/uday/git/llvm-project/llvm/include/llvm/CodeGen/ScheduleDAGInstrs.h:25,
from /home/uday/git/llvm-project/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp:14:
/home/uday/git/llvm-project/llvm/include/llvm/Support/Error.h:310:23: note: previous definition of ‘llvm::raw_ostream& llvm::operator<<(llvm::raw_ostream&, const llvm::Error&)’ was here
friend raw_ostream &operator<<(raw_ostream &OS, const Error &E) {

Build configuration with CC=clang CXX=clang fails

This is probably unrelated to the mlir part since clang can't find libstdc++ here.

CC=clang CXX=clang cmake -G Ninja ../llvm -DLLVM_BUILD_EXAMPLES=ON -DLLVM_ENABLE_CXX1Y=Y -DLLVM_TARGETS_TO_BUILD="host"

ends with this error:

-- Performing Test LLVM_LIBSTDCXX_MIN - Failed
CMake Error at cmake/modules/CheckCompilerVersion.cmake:80 (message):
libstdc++ version must be at least 4.8.
Call Stack (most recent call first):
cmake/config-ix.cmake:13 (include)
CMakeLists.txt:611 (include)

-- Configuring incomplete, errors occurred!
See also "/home/uday/llvm-project/build/CMakeFiles/CMakeOutput.log".
See also "/home/uday/llvm-project/build/CMakeFiles/CMakeError.log".

I do have a recent libstdc++

$ rpm -q libstdc++
libstdc++-9.1.1-1.fc30.x86_64

The error log has:

Performing C++ SOURCE FILE Test LLVM_LIBSTDCXX_MIN failed with the following output:
Change Dir: /home/uday/llvm-project/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/ninja-build cmTC_0cf6b
[1/2] Building CXX object CMakeFiles/cmTC_0cf6b.dir/src.cxx.o
[2/2] Linking CXX executable cmTC_0cf6b
FAILED: cmTC_0cf6b
: && /usr/lib64/ccache/clang -DLLVM_LIBSTDCXX_MIN -std=c++0x CMakeFiles/cmTC_0cf6b.dir/src.cxx.o -o cmTC_0cf6b && :
/usr/bin/ld: CMakeFiles/cmTC_0cf6b.dir/src.cxx.o:(.data+0x0): undefined reference to `std::bad_function_call::what() const'
clang-8: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

Source file was:

#include
#if defined(GLIBCXX)
#if GLIBCXX < 20130322
#error Unsupported libstdc++ version
#endif
#endif
#if defined(GLIBCXX)
extern const char _ZNKSt17bad_function_call4whatEv[];
const char *chk = _ZNKSt17bad_function_call4whatEv;
#else
const char *chk = "";
#endif
int main() { ++chk; return 0; }

$ clang --version
clang version 8.0.0 (Fedora 8.0.0-1.fc30)

Compilation failure in LowerToLLVMDialect.cpp

I recently started seeing this compilation failure when building the latest LLVM+MLIR tree.

llvm/projects/mlir/lib/Linalg/Transforms/LowerToLLVMDialect.cpp:649:70:   required from here
llvm/projects/mlir/include/mlir/IR/Builders.h:301:16: error: no matching function for call to mlir::LLVM::AllocaOp::build(mlir::OpBuilder*, mlir::OperationState*, mlir::LLVM::LLVMType&, mlir::edsc::intrinsics::ValueBuilder<mlir::LLVM::ConstantOp>&)
     OpTy::build(this, &state, args...);

I'm using g++ 8.3.0.

I can get past the compilation error by changing

    auto alloca =
      llvm_alloca(arg->getType().cast<LLVMType>().getPointerTo(), one)
            .getValue();

to

    auto alloca =
      llvm_alloca(arg->getType().cast<LLVMType>().getPointerTo(), ArrayRef<Value*>{one.getValue()}, ArrayRef<NamedAttribute>{})
            .getValue();

which may not be the proper fix.

[spirv] Support serialization for spv.struct.

Serialization for spv.struct must be added alongside with decoration with BufferBlock.

BufferBlock apply to a structure type to establish it is an SSBO-like shader-interface block.

OpDecorate %structType BufferBlock

Note: it is a blocker for #60

-lower-to-llvm crash: non-default memory space

$ mlir-opt -affine-dma-generate -lower-affine -lower-to-llvm nest_3d.mlir

yields the assertion below. I was expecting an error (emitError) if something wasn't supported. Input file appended below.

mlir-opt: /home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/Types.h:277: U mlir::Type::cast() const [with U = mlir::LLVM::LLVMType]: Assertion `isa()' failed.
Stack dump:
0. Program arguments: mlir-opt -affine-dma-generate -lower-affine -lower-to-llvm nest_3d.mlir

  1. Program arguments: mlir-opt -affine-dma-generate -lower-affine -lower-to-llvm nest_3d.mlir
    #0 0x00000000008dd8be llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/uday/llvm-project/llvm/lib/Support/Unix/Signals.inc:494:22
    #1 0x00000000008dd951 PrintStackTraceSignalHandler(void*) /home/uday/llvm-project/llvm/lib/Support/Unix/Signals.inc:558:1
    #2 0x00000000008dbc21 llvm::sys::RunSignalHandlers() /home/uday/llvm-project/llvm/lib/Support/Signals.cpp:68:20
    #3 0x00000000008dd3b5 SignalHandler(int) /home/uday/llvm-project/llvm/lib/Support/Unix/Signals.inc:357:1
    #4 0x00007ff7f108de80 __restore_rt (/lib64/libpthread.so.0+0x12e80)
    #5 0x00007ff7f0b52e75 __GI_raise (/lib64/libc.so.6+0x37e75)
    #6 0x00007ff7f0b3d895 __GI_abort (/lib64/libc.so.6+0x22895)
    #7 0x00007ff7f0b3d769 _nl_load_domain.cold (/lib64/libc.so.6+0x22769)
    #8 0x00007ff7f0b4b566 (/lib64/libc.so.6+0x30566)
    #9 0x000000000053f1a7 mlir::LLVM::LLVMType mlir::Type::castmlir::LLVM::LLVMType() const /home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/Types.h:278:12
    #10 0x0000000000697d3d (anonymous namespace)::DeallocOpLowering::matchAndRewrite(mlir::Operation*, llvm::ArrayRefmlir::Value*, mlir::PatternRewriter&) const /home/uday/llvm-project/llvm/projects/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp:515:64
    #11 0x00000000006cce3b mlir::ConversionPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const /home/uday/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:547:50
    #12 0x00000000006cd63d (anonymous namespace)::OperationLegalizer::legalizePattern(mlir::Operation*, mlir::RewritePattern*, (anonymous namespace)::DialectConversionRewriter&) /home/uday/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:694:45
    #13 0x00000000006cd37b (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, (anonymous namespace)::DialectConversionRewriter&) /home/uday/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:659:18
    #14 0x00000000006ce47a (anonymous namespace)::FunctionConverter::convertBlock((anonymous namespace)::DialectConversionRewriter&, mlir::Block*, llvm::DenseSet<mlir::Block*, llvm::DenseMapInfomlir::Block* >&) /home/uday/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:912:21
    #15 0x00000000006ce513 (anonymous namespace)::FunctionConverter::convertBlock((anonymous namespace)::DialectConversionRewriter&, mlir::Block*, llvm::DenseSet<mlir::Block*, llvm::DenseMapInfomlir::Block* >&) /home/uday/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:918:15
    #16 0x00000000006ce513 (anonymous namespace)::FunctionConverter::convertBlock((anonymous namespace)::DialectConversionRewriter&, mlir::Block*, llvm::DenseSet<mlir::Block*, llvm::DenseMapInfomlir::Block* >&) /home/uday/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:918:15
    #17 0x00000000006ce733 (anonymous namespace)::FunctionConverter::convertRegion((anonymous namespace)::DialectConversionRewriter&, mlir::Region&, bool) /home/uday/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:949:13
    #18 0x00000000006ce8e3 (anonymous namespace)::FunctionConverter::convertFunction(mlir::FuncOp, mlir::TypeConverter::SignatureConversion*) /home/uday/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:974:13
    #19 0x00000000006cf637 mlir::applyConversionPatterns(llvm::MutableArrayRefmlir::FuncOp, mlir::ConversionTarget&, mlir::TypeConverter&, std::vector<std::unique_ptr<mlir::RewritePattern, std::default_deletemlir::RewritePattern >, std::allocator<std::unique_ptr<mlir::RewritePattern, std::default_deletemlir::RewritePattern > > >&&) /home/uday/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:1166:15
    #20 0x00000000006cf3bd mlir::applyConversionPatterns(mlir::ModuleOp, mlir::ConversionTarget&, mlir::TypeConverter&, std::vector<std::unique_ptr<mlir::RewritePattern, std::default_deletemlir::RewritePattern >, std::allocator<std::unique_ptr<mlir::RewritePattern, std::default_deletemlir::RewritePattern > > >&&) /home/uday/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:1136:53
    #21 0x000000000069a224 (anonymous namespace)::LLVMLoweringPass::runOnModule() /home/uday/llvm-project/llvm/projects/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp:1045:15
    #22 0x00000000005cffb6 mlir::ModulePassBase::run(mlir::ModuleOp, mlir::ModuleAnalysisManager&) /home/uday/llvm-project/llvm/projects/mlir/lib/Pass/Pass.cpp:87:27
    #23 0x00000000005d0243 mlir::detail::ModulePassExecutor::run(mlir::ModuleOp, mlir::ModuleAnalysisManager&) /home/uday/llvm-project/llvm/projects/mlir/lib/Pass/Pass.cpp:127:15
    #24 0x00000000005d0a0b mlir::PassManager::run(mlir::ModuleOp) /home/uday/llvm-project/llvm/projects/mlir/lib/Pass/Pass.cpp:261:30
    #25 0x000000000059d8de performActions(llvm::raw_ostream&, bool, bool, llvm::SourceMgr&, mlir::MLIRContext*, std::vector<mlir::PassRegistryEntry const*, std::allocator<mlir::PassRegistryEntry const*> > const&) /home/uday/llvm-project/llvm/projects/mlir/lib/Support/MlirOptMain.cpp:65:13
    #26 0x000000000059da3e processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_deletellvm::MemoryBuffer >, bool, bool, std::vector<mlir::PassRegistryEntry const*, std::allocator<mlir::PassRegistryEntry const*> > const&) /home/uday/llvm-project/llvm/projects/mlir/lib/Support/MlirOptMain.cpp:91:45
    #27 0x000000000059def5 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_deletellvm::MemoryBuffer >, std::vector<mlir::PassRegistryEntry const*, std::allocator<mlir::PassRegistryEntry const*> > const&, bool, bool, bool) /home/uday/llvm-project/llvm/projects/mlir/lib/Support/MlirOptMain.cpp:154:32
    #28 0x00000000007ad0bf main /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-opt/mlir-opt.cpp:89:16
    #29 0x00007ff7f0b3ef33 __libc_start_main (/lib64/libc.so.6+0x23f33)
    #30 0x000000000040b5ce _start (/home/uday/llvm-project/build/bin/mlir-opt+0x40b5ce)
    Aborted (core dumped)

func @nest_3d(%A: memref<1024 x 1024 x vector<512 x f32>>, %B: memref<1024 x 1024 x vector<512 x f32>>, %C: memref<1024 x 1024 x vector<512 x f32>>) -> memref<1024 x 1024 x vector<512 x f32>> {
affine.for %i = 0 to 1024 {
affine.for %j = 0 to 1024 {
affine.for %k = 0 to 1024 {
%5 = affine.load %A[%i, %k] : memref<1024 x 1024 x vector<512 x f32>>
%6 = affine.load %B[%k, %j] : memref<1024 x 1024 x vector<512 x f32>>
%7 = affine.load %C[%i, %j] : memref<1024 x 1024 x vector<512 x f32>>
%8 = mulf %5, %6 : vector<512xf32>
%9 = addf %7, %8 : vector<512xf32>
affine.store %9, %C[%i, %j] : memref<1024 x 1024 x vector<512 x f32>>
}
}
}
return %C : memref<1024 x 1024 x vector<512 x f32>>
}

The semantics of AffineMap in MemRef

Here is an example:

#imapA = (d0, d1) [s0] -> (d0 + s0, d1)
%o = 1
%i = 0
%j = 0
%A = alloc()[%o] : memref<16x32xf32, #imapA, memspace0>
%v = load %A[%i, %j] : memref<16x32xf32, #imapA, memspace0>

It allocates a two dimension array, A[16][32].
The index of load is set to (0, 0).
Since there is an affinemap, %o is set to 1, the load operation will return A[1][0] actually.

Is my understanding correct? Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.