This is an archive of the discontinued LLVM Phabricator instance.

[mlir][SideEffects] Enable specifying side effects directly on the arguments/results of an operation.
ClosedPublic

Authored by rriddle on Feb 11 2020, 1:13 PM.

Details

Summary

New classes are added to ODS to enable specifying additional information on the arguments and results of an operation. These classes, Arg and Res allow for adding a description and a set of 'decorators' along with the constraint. This enables specifying the side effects of an operation directly on the arguments and results themselves.

Example:

def LoadOp : Std_Op<"load"> {
  let arguments = (ins Arg<"The MemRef to load from.", AnyMemRef,
                           [MemRead]>:$memref,
                       Variadic<Index>:$indices);
}

Depends On D74439

Diff Detail

Event Timeline

rriddle created this revision.Feb 11 2020, 1:13 PM
jpienaar marked an inline comment as done.Feb 27 2020, 6:02 PM

Should Arg<"The MemRef to load from." be Arg<"the MemRef to load from" ? E.g., sentence fragment, not capitalized, could be added in generated docs as table entries?

mlir/include/mlir/IR/OpBase.td
1716

s/{}/;/ ?

mlir/include/mlir/TableGen/SideEffects.h
27

Nit: C++

mlir/lib/TableGen/Operator.cpp
309

Mmm, why are we referring to "constraint" a few times, could this be stored instead or queried in a different way? (same as being done for operands and attributes)

mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
1209

Does formatv read easier here?

1227

Comment?

rriddle updated this revision to Diff 247373.Feb 28 2020, 2:58 PM
rriddle marked 3 inline comments as done.

Resolve comments

jpienaar accepted this revision.Mar 3 2020, 4:40 PM

General structure looks good to me and we can iterate from here, thanks

mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
1056–1058

One last question about the ordering, what about switching the constraint and the text?

Then we have

AnyMemRef
Arg<AnyMemRef>
Arg<AnyMemRef, "the reference to load from">
Arg<AnyMemRef, "the reference to load from", [MemRead]>

and it just seems to extend more naturally (and one could have desc be empty to match what we have today implicitly).

Or is there a reason you prefer this ordering?

This revision is now accepted and ready to land.Mar 3 2020, 4:40 PM
rriddle updated this revision to Diff 248826.Mar 6 2020, 1:53 PM
rriddle marked an inline comment as done.

Resolve comments

This revision was automatically updated to reflect the committed changes.

This appears to break the VisualStudio build for MSVC++ 14.16

E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(58): error C2664: 'bool mlir::SideEffects::Effect::Base<mlir::MemoryEffects::Allocate,mlir::MemoryEffects::Effect>::classof(const mlir::MemoryEffects::Effect *)': cannot convert argument 1 from 'const From *' to 'const mlir::MemoryEffects::Effect *'
        with
        [
            From=mlir::SideEffects::Effect
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(58): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(57): note: while compiling class template member function 'bool llvm::isa_impl<To,From,void>::doit(const From &)'
        with
        [
            To=mlir::MemoryEffects::Allocate,
            From=mlir::SideEffects::Effect
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(105): note: see reference to function template instantiation 'bool llvm::isa_impl<To,From,void>::doit(const From &)' being compiled
        with
        [
            To=mlir::MemoryEffects::Allocate,
            From=mlir::SideEffects::Effect
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(105): note: see reference to class template instantiation 'llvm::isa_impl<To,From,void>' being compiled
        with
        [
            To=mlir::MemoryEffects::Allocate,
            From=mlir::SideEffects::Effect
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(103): note: while compiling class template member function 'bool llvm::isa_impl_cl<To,FromTy>::doit(const From *)'
        with
        [
            To=mlir::MemoryEffects::Allocate,
            FromTy=const mlir::SideEffects::Effect *,
            From=mlir::SideEffects::Effect
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(131): note: see reference to function template instantiation 'bool llvm::isa_impl_cl<To,FromTy>::doit(const From *)' being compiled
        with
        [
            To=mlir::MemoryEffects::Allocate,
            FromTy=const mlir::SideEffects::Effect *,
            From=mlir::SideEffects::Effect
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(131): note: see reference to class template instantiation 'llvm::isa_impl_cl<To,FromTy>' being compiled
        with
        [
            To=mlir::MemoryEffects::Allocate,
            FromTy=const mlir::SideEffects::Effect *
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(130): note: while compiling class template member function 'bool llvm::isa_impl_wrap<To,SimpleFrom,SimpleFrom>::doit(const FromTy &)'
        with
        [
            To=mlir::MemoryEffects::Allocate,
            SimpleFrom=const mlir::SideEffects::Effect *,
            FromTy=const mlir::SideEffects::Effect *
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(121): note: see reference to function template instantiation 'bool llvm::isa_impl_wrap<To,SimpleFrom,SimpleFrom>::doit(const FromTy &)' being compiled
        with
        [
            To=mlir::MemoryEffects::Allocate,
            SimpleFrom=const mlir::SideEffects::Effect *,
            FromTy=const mlir::SideEffects::Effect *
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(122): note: see reference to class template instantiation 'llvm::isa_impl_wrap<To,SimpleFrom,SimpleFrom>' being compiled
        with
        [
            To=mlir::MemoryEffects::Allocate,
            SimpleFrom=const mlir::SideEffects::Effect *
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(120): note: while compiling class template member function 'bool llvm::isa_impl_wrap<X,const Y,const mlir::SideEffects::Effect *>::doit(From &)'
        with
        [
            X=mlir::MemoryEffects::Allocate,
            Y=const mlir::SideEffects::Effect *,
            From=const mlir::SideEffects::Effect *
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(141): note: see reference to function template instantiation 'bool llvm::isa_impl_wrap<X,const Y,const mlir::SideEffects::Effect *>::doit(From &)' being compiled
        with
        [
            X=mlir::MemoryEffects::Allocate,
            Y=const mlir::SideEffects::Effect *,
            From=const mlir::SideEffects::Effect *
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(142): note: see reference to class template instantiation 'llvm::isa_impl_wrap<X,const Y,const mlir::SideEffects::Effect *>' being compiled
        with
        [
            X=mlir::MemoryEffects::Allocate,
            Y=const mlir::SideEffects::Effect *
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\mlir\lib\IR\Operation.cpp(967): note: see reference to function template instantiation 'bool llvm::isa<mlir::MemoryEffects::Allocate,const mlir::SideEffects::Effect*>(const Y &)' being compiled
        with
        [
            Y=const mlir::SideEffects::Effect *
        ]
ninja: build stopped: subcommand failed.

This appears to break the VisualStudio build for MSVC++ 14.16

E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(58): error C2664: 'bool mlir::SideEffects::Effect::Base<mlir::MemoryEffects::Allocate,mlir::MemoryEffects::Effect>::classof(const mlir::MemoryEffects::Effect *)': cannot convert argument 1 from 'const From *' to 'const mlir::MemoryEffects::Effect *'
        with
        [
            From=mlir::SideEffects::Effect
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(58): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(57): note: while compiling class template member function 'bool llvm::isa_impl<To,From,void>::doit(const From &)'
        with
        [
            To=mlir::MemoryEffects::Allocate,
            From=mlir::SideEffects::Effect
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(105): note: see reference to function template instantiation 'bool llvm::isa_impl<To,From,void>::doit(const From &)' being compiled
        with
        [
            To=mlir::MemoryEffects::Allocate,
            From=mlir::SideEffects::Effect
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(105): note: see reference to class template instantiation 'llvm::isa_impl<To,From,void>' being compiled
        with
        [
            To=mlir::MemoryEffects::Allocate,
            From=mlir::SideEffects::Effect
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(103): note: while compiling class template member function 'bool llvm::isa_impl_cl<To,FromTy>::doit(const From *)'
        with
        [
            To=mlir::MemoryEffects::Allocate,
            FromTy=const mlir::SideEffects::Effect *,
            From=mlir::SideEffects::Effect
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(131): note: see reference to function template instantiation 'bool llvm::isa_impl_cl<To,FromTy>::doit(const From *)' being compiled
        with
        [
            To=mlir::MemoryEffects::Allocate,
            FromTy=const mlir::SideEffects::Effect *,
            From=mlir::SideEffects::Effect
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(131): note: see reference to class template instantiation 'llvm::isa_impl_cl<To,FromTy>' being compiled
        with
        [
            To=mlir::MemoryEffects::Allocate,
            FromTy=const mlir::SideEffects::Effect *
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(130): note: while compiling class template member function 'bool llvm::isa_impl_wrap<To,SimpleFrom,SimpleFrom>::doit(const FromTy &)'
        with
        [
            To=mlir::MemoryEffects::Allocate,
            SimpleFrom=const mlir::SideEffects::Effect *,
            FromTy=const mlir::SideEffects::Effect *
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(121): note: see reference to function template instantiation 'bool llvm::isa_impl_wrap<To,SimpleFrom,SimpleFrom>::doit(const FromTy &)' being compiled
        with
        [
            To=mlir::MemoryEffects::Allocate,
            SimpleFrom=const mlir::SideEffects::Effect *,
            FromTy=const mlir::SideEffects::Effect *
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(122): note: see reference to class template instantiation 'llvm::isa_impl_wrap<To,SimpleFrom,SimpleFrom>' being compiled
        with
        [
            To=mlir::MemoryEffects::Allocate,
            SimpleFrom=const mlir::SideEffects::Effect *
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(120): note: while compiling class template member function 'bool llvm::isa_impl_wrap<X,const Y,const mlir::SideEffects::Effect *>::doit(From &)'
        with
        [
            X=mlir::MemoryEffects::Allocate,
            Y=const mlir::SideEffects::Effect *,
            From=const mlir::SideEffects::Effect *
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(141): note: see reference to function template instantiation 'bool llvm::isa_impl_wrap<X,const Y,const mlir::SideEffects::Effect *>::doit(From &)' being compiled
        with
        [
            X=mlir::MemoryEffects::Allocate,
            Y=const mlir::SideEffects::Effect *,
            From=const mlir::SideEffects::Effect *
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(142): note: see reference to class template instantiation 'llvm::isa_impl_wrap<X,const Y,const mlir::SideEffects::Effect *>' being compiled
        with
        [
            X=mlir::MemoryEffects::Allocate,
            Y=const mlir::SideEffects::Effect *
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\mlir\lib\IR\Operation.cpp(967): note: see reference to function template instantiation 'bool llvm::isa<mlir::MemoryEffects::Allocate,const mlir::SideEffects::Effect*>(const Y &)' being compiled
        with
        [
            Y=const mlir::SideEffects::Effect *
        ]
ninja: build stopped: subcommand failed.

Thanks for the report, looks like MSVC has some buggy symbol resolution for templates. I'll send fix-forward shortly.

This appears to break the VisualStudio build for MSVC++ 14.16

E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(58): error C2664: 'bool mlir::SideEffects::Effect::Base<mlir::MemoryEffects::Allocate,mlir::MemoryEffects::Effect>::classof(const mlir::MemoryEffects::Effect *)': cannot convert argument 1 from 'const From *' to 'const mlir::MemoryEffects::Effect *'
        with
        [
            From=mlir::SideEffects::Effect
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(58): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(57): note: while compiling class template member function 'bool llvm::isa_impl<To,From,void>::doit(const From &)'
        with
        [
            To=mlir::MemoryEffects::Allocate,
            From=mlir::SideEffects::Effect
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(105): note: see reference to function template instantiation 'bool llvm::isa_impl<To,From,void>::doit(const From &)' being compiled
        with
        [
            To=mlir::MemoryEffects::Allocate,
            From=mlir::SideEffects::Effect
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(105): note: see reference to class template instantiation 'llvm::isa_impl<To,From,void>' being compiled
        with
        [
            To=mlir::MemoryEffects::Allocate,
            From=mlir::SideEffects::Effect
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(103): note: while compiling class template member function 'bool llvm::isa_impl_cl<To,FromTy>::doit(const From *)'
        with
        [
            To=mlir::MemoryEffects::Allocate,
            FromTy=const mlir::SideEffects::Effect *,
            From=mlir::SideEffects::Effect
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(131): note: see reference to function template instantiation 'bool llvm::isa_impl_cl<To,FromTy>::doit(const From *)' being compiled
        with
        [
            To=mlir::MemoryEffects::Allocate,
            FromTy=const mlir::SideEffects::Effect *,
            From=mlir::SideEffects::Effect
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(131): note: see reference to class template instantiation 'llvm::isa_impl_cl<To,FromTy>' being compiled
        with
        [
            To=mlir::MemoryEffects::Allocate,
            FromTy=const mlir::SideEffects::Effect *
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(130): note: while compiling class template member function 'bool llvm::isa_impl_wrap<To,SimpleFrom,SimpleFrom>::doit(const FromTy &)'
        with
        [
            To=mlir::MemoryEffects::Allocate,
            SimpleFrom=const mlir::SideEffects::Effect *,
            FromTy=const mlir::SideEffects::Effect *
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(121): note: see reference to function template instantiation 'bool llvm::isa_impl_wrap<To,SimpleFrom,SimpleFrom>::doit(const FromTy &)' being compiled
        with
        [
            To=mlir::MemoryEffects::Allocate,
            SimpleFrom=const mlir::SideEffects::Effect *,
            FromTy=const mlir::SideEffects::Effect *
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(122): note: see reference to class template instantiation 'llvm::isa_impl_wrap<To,SimpleFrom,SimpleFrom>' being compiled
        with
        [
            To=mlir::MemoryEffects::Allocate,
            SimpleFrom=const mlir::SideEffects::Effect *
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(120): note: while compiling class template member function 'bool llvm::isa_impl_wrap<X,const Y,const mlir::SideEffects::Effect *>::doit(From &)'
        with
        [
            X=mlir::MemoryEffects::Allocate,
            Y=const mlir::SideEffects::Effect *,
            From=const mlir::SideEffects::Effect *
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(141): note: see reference to function template instantiation 'bool llvm::isa_impl_wrap<X,const Y,const mlir::SideEffects::Effect *>::doit(From &)' being compiled
        with
        [
            X=mlir::MemoryEffects::Allocate,
            Y=const mlir::SideEffects::Effect *,
            From=const mlir::SideEffects::Effect *
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\llvm\include\llvm/Support/Casting.h(142): note: see reference to class template instantiation 'llvm::isa_impl_wrap<X,const Y,const mlir::SideEffects::Effect *>' being compiled
        with
        [
            X=mlir::MemoryEffects::Allocate,
            Y=const mlir::SideEffects::Effect *
        ]
E:\build_slave\mlir-x64-windows-ninja\llvm-project\mlir\lib\IR\Operation.cpp(967): note: see reference to function template instantiation 'bool llvm::isa<mlir::MemoryEffects::Allocate,const mlir::SideEffects::Effect*>(const Y &)' being compiled
        with
        [
            Y=const mlir::SideEffects::Effect *
        ]
ninja: build stopped: subcommand failed.

Thanks for the report, looks like MSVC has some buggy symbol resolution for templates. I'll send fix-forward shortly.

I submitted: https://github.com/llvm/llvm-project/commit/f240d303c2edf69d6a53691c62da110877ac6bf5

Let me know if that fixes it for you.

Let me know if that fixes it for you.

It works. Thanks so much! My understanding is that some of these template related issues are fixed in VS19, but there is a different bug that's preventing us from using it until the next release.