platform/upstream/llvm.git
4 years agoAdd support for Logical Ops in SPIR-V dialect
Mahesh Ravishankar [Mon, 30 Sep 2019 17:40:07 +0000 (10:40 -0700)]
Add support for Logical Ops in SPIR-V dialect

Add operations corresponding to OpLogicalAnd, OpLogicalNot,
OpLogicalEqual, OpLogicalNotEqual and OpLogicalOr instructions in
SPIR-V dialect. This needs changes to class hierarchy in SPIR-V
TableGen files to split SPIRVLogicalOp into SPIRVLogicalUnaryOp and
SPIRVLogicalBinaryOp. All derived classes of SPIRVLogicalOp are
updated accordingly.

Update the spirv dialect generation script to
1) Allow specifying base class to use for instruction spec generation
and file name to generate the specification in separately.
2) Use the existing descriptions for operations.
3) Update define_inst.sh to also invoke define_opcode.sh to also
define the corresponding SPIR-V instruction opcode enum.

PiperOrigin-RevId: 272014876

4 years agoUse MaybeAlign when setting alignment
Jacques Pienaar [Mon, 30 Sep 2019 16:36:26 +0000 (09:36 -0700)]
Use MaybeAlign when setting alignment

PiperOrigin-RevId: 272000548

4 years agoFix MemRefType::getStrides corner case
Nicolas Vasilache [Mon, 30 Sep 2019 14:15:54 +0000 (07:15 -0700)]
Fix MemRefType::getStrides corner case

MemRefType::getStrides uses AffineExpr::walk which operates in post-order from the leaves. In order to compute strides properly, it needs to escape on terminal nodes and analyze binary ops only. This did not work for AffineExpr that consist of a single term (i.e. without a binary op).

This CL fixes the corner case and adds relevant tests.

PiperOrigin-RevId: 271975746

4 years agoSwitch comments from GPU dialect terms to CUDA terms (NFC).
Christian Sigg [Mon, 30 Sep 2019 10:19:09 +0000 (03:19 -0700)]
Switch comments from GPU dialect terms to CUDA terms (NFC).

local workgroup -> block, subgroup -> warp, invocation -> thread.

PiperOrigin-RevId: 271946342

4 years agoAdd InferTypeOpTrait & enable generating its member function definition
Jacques Pienaar [Mon, 30 Sep 2019 00:28:29 +0000 (17:28 -0700)]
Add InferTypeOpTrait & enable generating its member function definition

Use OpInterfaces to add an interface for ops defining a return type function.

This change does not use this trait in any meaningful way, I'll use it in a
follow up to generalize and unify some of the op type traits/constraints. Also,
currently the infer type function can only be manually specified in C++, that should rather be the fallback in future.

PiperOrigin-RevId: 271883746

4 years agoupdate Rationale.md - remove outdated info
Uday Bondhugula [Sun, 29 Sep 2019 22:53:24 +0000 (15:53 -0700)]
update Rationale.md - remove outdated info

- removing outdated/confusing info
- the affine dialect is missing documentation on
  affine.load/affine.store; the references herein have to be updated
  once that's updated.

Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>
Closes tensorflow/mlir#159

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/159 from bondhugula:doc 86dd794f2d0d7fd097dde5764c62eb406ed4f910
PiperOrigin-RevId: 271876525

4 years agoFix a typo in Toy Chapter 2 tutorial documentation
Roberto Rosmaninho [Sun, 29 Sep 2019 22:53:21 +0000 (15:53 -0700)]
Fix a typo in Toy Chapter 2 tutorial documentation

Closes tensorflow/mlir#155

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/155 from Robertorosmaninho:patch-1 232ac4e1253948c7f3150515e93abe50fcec2f96
PiperOrigin-RevId: 271876515

4 years agoFix syntax of 'call' and 'splat' ops
Uday Bondhugula [Sun, 29 Sep 2019 22:52:52 +0000 (15:52 -0700)]
Fix syntax of 'call' and 'splat' ops

- fix missing return value syntax on call / splat ops
- reflow cond_br / store op syntax

Closes tensorflow/mlir#161

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/161 from bondhugula:patch-1 2beb5bdcb387a5e7c52438985f79e2987d3b3ebe
PiperOrigin-RevId: 271876453

4 years agoSwitch explicit create methods to match generated build's order
Jacques Pienaar [Sat, 28 Sep 2019 16:35:23 +0000 (09:35 -0700)]
Switch explicit create methods to match generated build's order

The generated build methods have result type before the arguments (operands and attributes, which are also now adjacent in the explicit create method). This also results in changing the create method's ordering to match most build method's ordering.

PiperOrigin-RevId: 271755054

4 years agoTablegen helpers for accessing properties of shaped types
Geoffrey Martin-Noble [Sat, 28 Sep 2019 00:34:56 +0000 (17:34 -0700)]
Tablegen helpers for accessing properties of shaped types

Tablegen's lack of functions continues to be annoying

PiperOrigin-RevId: 271680947

4 years agoAppend a newline when dumping a Value.
Yanan Cao [Fri, 27 Sep 2019 23:20:04 +0000 (16:20 -0700)]
Append a newline when dumping a Value.

This is more consistent with other dump methods. Otherwise successive Value dumps are concatenated in same line, hurting readability.

PiperOrigin-RevId: 271669846

4 years agoRemove spurious debug spew in tests
Nicolas Vasilache [Fri, 27 Sep 2019 19:31:12 +0000 (12:31 -0700)]
Remove spurious debug spew in tests

PiperOrigin-RevId: 271624731

4 years agoAdd TODO to revisit coupling of CallOp to MemRefType lowering
Nicolas Vasilache [Fri, 27 Sep 2019 19:02:09 +0000 (12:02 -0700)]
Add TODO to revisit coupling of CallOp to MemRefType lowering

PiperOrigin-RevId: 271619132

4 years agoNFC - clean up op accessor usage, std.load/store op verify, other stale info
Uday Bondhugula [Fri, 27 Sep 2019 18:57:52 +0000 (11:57 -0700)]
NFC - clean up op accessor usage, std.load/store op verify, other stale info

- also remove stale terminology/references in docs

Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>
Closes tensorflow/mlir#148

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/148 from bondhugula:cleanup e846b641a3c2936e874138aff480a23cdbf66591
PiperOrigin-RevId: 271618279

4 years agoPromote MemRefDescriptor to a pointer to struct when passing function boundaries...
Nicolas Vasilache [Fri, 27 Sep 2019 16:55:38 +0000 (09:55 -0700)]
Promote MemRefDescriptor to a pointer to struct when passing function boundaries in LLVMLowering.

The strided MemRef RFC discusses a normalized descriptor and interaction with library calls (https://groups.google.com/a/tensorflow.org/forum/#!topic/mlir/MaL8m2nXuio).
Lowering of nested LLVM structs as value types does not play nicely with externally compiled C/C++ functions due to ABI issues.
Solving the ABI problem generally is a very complex problem and most likely involves taking
a dependence on clang that we do not want atm.

A simple workaround is to pass pointers to memref descriptors at function boundaries, which this CL implement.

PiperOrigin-RevId: 271591708

4 years agoFix JitRunner.cpp Error creation pattern and reactivate tests.
Nicolas Vasilache [Fri, 27 Sep 2019 16:44:54 +0000 (09:44 -0700)]
Fix JitRunner.cpp Error creation pattern and reactivate tests.

linalg_integration_test.mlir and simple.mlir were temporarily disabled due to an OSS-only failure.

The issue is that, once created, an llvm::Error must be explicitly checked before it can be discarded or overwritten.

This CL fixes the issue and reenable the test.

PiperOrigin-RevId: 271589651

4 years agoFix Documentation OpDefinitions.md
Denis Khalikov [Fri, 27 Sep 2019 14:46:40 +0000 (07:46 -0700)]
Fix Documentation OpDefinitions.md

Add missing semicolon for the builders example.

Closes tensorflow/mlir#150

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/150 from denis0x0D:sandbox/doc_fix 07e3680e678bf141a70af7747136e9fde7b4cc0a
PiperOrigin-RevId: 271568527

4 years agoFix missing links in the documentation
Kazuaki Ishizaki [Fri, 27 Sep 2019 14:44:52 +0000 (07:44 -0700)]
Fix missing links in the documentation

Closes tensorflow/mlir#149

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/149 from kiszk:missing_links_g3doc 5f98bc279649d54ea3dcf9fe0e17be6ad6d6cb8f
PiperOrigin-RevId: 271568274

4 years ago[ROCm] Adding ROCDL Dialect.
Deven Desai [Fri, 27 Sep 2019 06:49:51 +0000 (23:49 -0700)]
[ROCm] Adding ROCDL Dialect.

This commit introduces the ROCDL Dialect (i.e. the ROCDL ops + the code to lower those ROCDL ops to LLWM intrinsics/functions). Think of ROCDL Dialect as analogous to the NVVM Dialect, but for AMD GPUs. This patch contains just the essentials needed to get a simple example up and running. We expect to make further additions to the ROCDL Dialect.

This is the first of 3 commits, the follow-up will be:
 * add a pass that lowers GPU Dialect to ROCDL Dialect
 * add a "mlir-rocm-runner" utility

Closes tensorflow/mlir#146

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/146 from deven-amd:deven-rocdl-dialect e78e8005c75a78912631116c78dc844fcc4b0de9
PiperOrigin-RevId: 271511259

4 years agoDisable failing tests
Jacques Pienaar [Thu, 26 Sep 2019 23:41:57 +0000 (16:41 -0700)]
Disable failing tests

PiperOrigin-RevId: 271460509

4 years agoMake result ops generated output deterministic
Jacques Pienaar [Thu, 26 Sep 2019 21:00:22 +0000 (14:00 -0700)]
Make result ops generated output deterministic

Sort the result ops reported in lexographical order.

PiperOrigin-RevId: 271426258

4 years agoDecouple tiling from fusion in Linalg.
Nicolas Vasilache [Thu, 26 Sep 2019 15:43:58 +0000 (08:43 -0700)]
Decouple tiling from fusion in Linalg.

This CL modifies the linalg-fusion pass such that it does not tile anymore as part of the pass. Tiling is a separate concern that enables linalg fusion but should happen before.
This makes fusion more composable with other decisions.
In particular the fusion pass now becomes greedy and only applies the transformation on a best-effort basis.

This should also let fusion work in a multi-hop fashion with chains of producer/consumers.

Since the fusion pass does not perform tiling anymore, tests are rewritten to be in pretiled form and make the intent of the test clearer (albeit more verbose).

PiperOrigin-RevId: 271357741

4 years agoDrop support for memrefs from JitRunner
Alex Zinenko [Thu, 26 Sep 2019 12:41:26 +0000 (05:41 -0700)]
Drop support for memrefs from JitRunner

The support for functions taking and returning memrefs of floats was introduced
in the first version of the runner, created before MLIR had reliable lowering
of allocation/deallocation to library calls.  It forcibly runs MLIR
transformation convering affine, loop and standard dialects into the LLVM
dialect, unlike the other runner flows that accept the LLVM dialect directly.
Memref support leads to more complex layering and is generally fragile.  Drop
it in favor of functions returning a scalar, or library-based function calls to
print memrefs and other data structures.

PiperOrigin-RevId: 271330839

4 years agoAdd AllReduceOp to GPU dialect with lowering to NVVM.
Christian Sigg [Thu, 26 Sep 2019 07:17:13 +0000 (00:17 -0700)]
Add AllReduceOp to GPU dialect with lowering to NVVM.

The reduction operation is currently fixed to "add", and the scope is fixed to "workgroup".

The implementation is currently limited to sizes that are multiple 32 (warp size) and no larger than 1024.

PiperOrigin-RevId: 271290265

4 years agoRemove unused variables and methods to address compiler warnings
Lei Zhang [Thu, 26 Sep 2019 02:04:59 +0000 (19:04 -0700)]
Remove unused variables and methods to address compiler warnings

PiperOrigin-RevId: 271256784

4 years agoAdd spv.Bitcast operation to SPIR-V dialect
Mahesh Ravishankar [Thu, 26 Sep 2019 02:01:18 +0000 (19:01 -0700)]
Add spv.Bitcast operation to SPIR-V dialect

Support the OpBitcast instruction of SPIR-V using the spv.Bitcast
operation. The semantics implemented in the dialect differ from the
SPIR-V spec in that the dialect does not allow conversion to/from
pointer types from/to non-pointer types.

PiperOrigin-RevId: 271255957

4 years agoChange the return type of createPrintCFGGraphPass to match other passes.
Jing Pu [Thu, 26 Sep 2019 01:33:09 +0000 (18:33 -0700)]
Change the return type of createPrintCFGGraphPass to match other passes.

PiperOrigin-RevId: 271252404

4 years ago[spirv] Add SPV_UnaryOp and spv.FNegate
Lei Zhang [Wed, 25 Sep 2019 23:34:37 +0000 (16:34 -0700)]
[spirv] Add SPV_UnaryOp and spv.FNegate

This CL also moves common parsers and printers to the
same section in SPIRVOps.cpp.

PiperOrigin-RevId: 271233546

4 years agoMinor spelling tweaks
Kazuaki Ishizaki [Wed, 25 Sep 2019 18:57:13 +0000 (11:57 -0700)]
Minor spelling tweaks

Closes tensorflow/mlir#145

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/145 from kiszk:spelling_tweaks_g3doc ae9140aab5b797441e880d43e557903585815e40
PiperOrigin-RevId: 271173907

4 years agoEmit function name being tested in TestMemRefStrideCalculation
Jacques Pienaar [Wed, 25 Sep 2019 18:23:15 +0000 (11:23 -0700)]
Emit function name being tested in TestMemRefStrideCalculation

Bring back CHECK-LABEL post

PiperOrigin-RevId: 271166428

4 years agoAdd tablegen verification traits for comparing different properties
Geoffrey Martin-Noble [Wed, 25 Sep 2019 17:16:39 +0000 (10:16 -0700)]
Add tablegen verification traits for comparing different properties

This allows things like comparing the rank of one operand to the size of another that specifies indices into it.

PiperOrigin-RevId: 271150439

4 years agoFix memref-stride-calculation on Windows
Lei Zhang [Wed, 25 Sep 2019 15:41:11 +0000 (08:41 -0700)]
Fix memref-stride-calculation on Windows

Call llvm::outs().flush() to make sure we don't mix streams.
Remove CHECK-LABEL to avoid assuming the relative order
between the additional info and the output IR.

PiperOrigin-RevId: 271131100

4 years agoForward declare LogicalResult as a struct to be consistent
Lei Zhang [Wed, 25 Sep 2019 15:14:48 +0000 (08:14 -0700)]
Forward declare LogicalResult as a struct to be consistent

This addresses a MSVC linker error saying splitAndProcessBuffer
was unresolved.

PiperOrigin-RevId: 271126570

4 years agoMiscellaneous fixes to SPIR-V Deserializer (details below).
Mahesh Ravishankar [Wed, 25 Sep 2019 05:50:16 +0000 (22:50 -0700)]
Miscellaneous fixes to SPIR-V Deserializer (details below).

1) Process and ignore the following debug instructions: OpSource,
OpSourceContinued, OpSourceExtension, OpString, OpModuleProcessed.
2) While processing OpTypeInt instruction, ignore the signedness
specification. Currently MLIR doesnt make a distinction between signed
and unsigned integer types.
3) Process and ignore BufferBlock decoration (similar to Buffer
decoration). StructType needs to be enhanced to track this attribute
since its needed for proper validation checks.
4) Report better error for unhandled instruction during
deserialization.

PiperOrigin-RevId: 271057060

4 years agoNFC: Add 'const' dereference method to OperandTypeIterator.
River Riddle [Wed, 25 Sep 2019 04:54:25 +0000 (21:54 -0700)]
NFC: Add 'const' dereference method to OperandTypeIterator.

The deference provided by mapped_iterator is non-const.

PiperOrigin-RevId: 271051375

4 years agoAdd support for GLSL Binary ops, and use it to implement GLSL FMax.
Mahesh Ravishankar [Wed, 25 Sep 2019 02:41:31 +0000 (19:41 -0700)]
Add support for GLSL Binary ops, and use it to implement GLSL FMax.

A base class is added to implement all GLSL Binary operations and is
used to implement the FMax operation. The existing framework already
generates all the necessary (de)serialization code.

PiperOrigin-RevId: 271037166

4 years ago[spirv] Replace bitwiseCast with llvm::bit_cast
Lei Zhang [Wed, 25 Sep 2019 02:24:33 +0000 (19:24 -0700)]
[spirv] Replace bitwiseCast with llvm::bit_cast

PiperOrigin-RevId: 271035618

4 years agoNFC: Add a description to the ODS interface example.
River Riddle [Tue, 24 Sep 2019 20:51:56 +0000 (13:51 -0700)]
NFC: Add a description to the ODS interface example.
PiperOrigin-RevId: 270978748

4 years agoAllow attaching descriptions to OpInterfaces and InterfaceMethods.
River Riddle [Tue, 24 Sep 2019 19:45:11 +0000 (12:45 -0700)]
Allow attaching descriptions to OpInterfaces and InterfaceMethods.

This change adds support for documenting interfaces and their methods. A tablegen generator for the interface documentation is also added(gen-op-interface-doc).

Documentation is added to an OpInterface via the `description` field:
def MyOpInterface : OpInterface<"MyOpInterface"> {
  let description = [{
    My interface is very interesting.
  }];
}

Documentation is added to an InterfaceMethod via a new `description` field that comes right before the optional body:

InterfaceMethod<"void", "foo", (ins), [{
  This is the foo method.
}]>,

PiperOrigin-RevId: 270965485

4 years agoIntroduce splat op + provide its LLVM lowering
Uday Bondhugula [Tue, 24 Sep 2019 19:44:11 +0000 (12:44 -0700)]
Introduce splat op + provide its LLVM lowering

- introduce splat op in standard dialect (currently for int/float/index input
  type, output type can be vector or statically shaped tensor)
- implement LLVM lowering (when result type is 1-d vector)
- add constant folding hook for it
- while on Ops.cpp, fix some stale names

Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>
Closes tensorflow/mlir#141

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/141 from bondhugula:splat 48976a6aa0a75be6d91187db6418de989e03eb51
PiperOrigin-RevId: 270965304

4 years agoNormalize lowering of MemRef types
Nicolas Vasilache [Tue, 24 Sep 2019 18:21:04 +0000 (11:21 -0700)]
Normalize lowering of MemRef types

The RFC for unifying Linalg and Affine compilation passes into an end-to-end flow with a predictable ABI and linkage to external function calls raised the question of why we have variable sized descriptors for memrefs depending on whether they have static or dynamic dimensions  (https://groups.google.com/a/tensorflow.org/forum/#!topic/mlir/MaL8m2nXuio).

This CL standardizes the ABI on the rank of the memrefs.
The LLVM struct for a memref becomes equivalent to:
```
template <typename Elem, size_t Rank>
struct {
  Elem *ptr;
  int64_t sizes[Rank];
};
```

PiperOrigin-RevId: 270947276

4 years agoClone called functions into nested GPU module.
Christian Sigg [Tue, 24 Sep 2019 13:29:25 +0000 (06:29 -0700)]
Clone called functions into nested GPU module.

PiperOrigin-RevId: 270891190

4 years agoAllow null Attribute for value when building GlobalOp.
Christian Sigg [Tue, 24 Sep 2019 08:19:21 +0000 (01:19 -0700)]
Allow null Attribute for value when building GlobalOp.

PiperOrigin-RevId: 270853596

4 years ago[spirv] NFC: clean up (de)serialization tests
Lei Zhang [Tue, 24 Sep 2019 02:56:49 +0000 (19:56 -0700)]
[spirv] NFC: clean up (de)serialization tests

This CL uses the newly added -split-input-file CLI option to
mlir-translate to combine certain (de)serialization tests.
It also renames certain test filenames.

PiperOrigin-RevId: 270816324

4 years agoMake spirv::RuntimeArrayType part of spirv::CompositeType.
Mahesh Ravishankar [Tue, 24 Sep 2019 01:50:17 +0000 (18:50 -0700)]
Make spirv::RuntimeArrayType part of spirv::CompositeType.

According to SPIR-V spec, spirv::CompositeType includes
spirv::RuntimeArrayType. This allows using objects of
spirv::RuntimeArrayType with spirv::AccessChainOp.
PiperOrigin-RevId: 270809492

4 years agoLet mlir-translate support -split-input-file
Lei Zhang [Tue, 24 Sep 2019 01:17:52 +0000 (18:17 -0700)]
Let mlir-translate support -split-input-file

Similar to mlir-opt, having a -split-input-file mode is quite useful
in mlir-translate. It allows to put logically related tests in the
same test file for better organization.

PiperOrigin-RevId: 270805467

4 years agoHandle OpMemberName instruction in SPIR-V deserializer.
Mahesh Ravishankar [Tue, 24 Sep 2019 00:10:49 +0000 (17:10 -0700)]
Handle OpMemberName instruction in SPIR-V deserializer.

Sdd support in deserializer for OpMemberName instruction. For now
the name is just processed and not associated with the
spirv::StructType being built. That needs an enhancement to
spirv::StructTypes itself.
Add tests to check for errors reported during deserialization with
some refactoring to common out some utility functions.
PiperOrigin-RevId: 270794524

4 years agoUse constant's location for reporting errors in parsing of hex constant
Jacques Pienaar [Mon, 23 Sep 2019 22:51:11 +0000 (15:51 -0700)]
Use constant's location for reporting errors in parsing of hex constant

Before this the line following the error would be reported in some cases.

PiperOrigin-RevId: 270778722

4 years agoSimplify the way spirv::StructTypes are parsed.
Mahesh Ravishankar [Mon, 23 Sep 2019 19:52:28 +0000 (12:52 -0700)]
Simplify the way spirv::StructTypes are parsed.

The existing logic to parse spirv::StructTypes is very brittle. This
change simplifies the parsing logic a lot. The simplification also
allows for memberdecorations to be separated by commas instead of
spaces (which was an artifact of the existing parsing logic). The
change also needs a modification to mlir::parseType to return the
number of chars parsed. Adding a new parseType method to do so.

Also allow specification of spirv::StructType with no members.

PiperOrigin-RevId: 270739672

4 years agoAdd convenience methods to set an OpBuilder insertion point after an Operation (NFC)
Mehdi Amini [Mon, 23 Sep 2019 18:54:24 +0000 (11:54 -0700)]
Add convenience methods to set an OpBuilder insertion point after an Operation (NFC)

PiperOrigin-RevId: 270727180

4 years agoAdd initial callgraph support.
River Riddle [Mon, 23 Sep 2019 18:43:43 +0000 (11:43 -0700)]
Add initial callgraph support.

Using the two call interfaces, CallOpInterface and CallableOpInterface, this change adds support for an initial multi-level CallGraph. This call graph builds a set of nodes for each callable region, and connects them via edges. An edge may be any of the following types:
* Abstract
  - An edge not produced by a call operation, used for connecting to internal nodes from external nodes.
* Call
  - A call edge is an edge defined via a call-like operation.
* Child
  - This is an artificial edge connecting nested callgraph nodes.

This callgraph will be used, and improved upon, to begin supporting more interesting interprocedural analyses and transformation. In a followup, this callgraph will be used to support more complex inlining support.

PiperOrigin-RevId: 270724968

4 years agoAdd interfaces for call-like/callable operations.
River Riddle [Mon, 23 Sep 2019 18:36:37 +0000 (11:36 -0700)]
Add interfaces for call-like/callable operations.

These two operation interfaces will be used in a followup to support building a callgraph:
* CallOpInterface
  - Operations providing this interface are call-like, and have a "call" target. A call target may be a symbol reference, via SymbolRefAttr, or a SSA value.

* CallableOpInterface
  - Operations providing this interfaces define destinations to call-like operations, e.g. FuncOp. These operations may define any number of callable regions.

PiperOrigin-RevId: 270723300

4 years agoRefactor DiagnosticEngine to support multiple registered diagnostic handlers.
River Riddle [Mon, 23 Sep 2019 18:24:28 +0000 (11:24 -0700)]
Refactor DiagnosticEngine to support multiple registered diagnostic handlers.

This fixes a problem with current save-restore pattern of diagnostics handlers, as there may be a thread race between when the previous handler is destroyed. For example, this occurs when using multiple ParallelDiagnosticHandlers asynchronously:

Handler A
Handler B | - LifeTime - |    Restore A here.
Handler C | --- LifeTime ---| Restore B after it has been destroyed.

The new design allows for multiple handlers to be registered in a stack like fashion. Handlers can return success() to signal that they have fully processed a diagnostic, or failure to propagate otherwise.

PiperOrigin-RevId: 270720625

4 years agoUpdate the Pass, Analysis, and PassManager sections of WritingAPass.md.
River Riddle [Mon, 23 Sep 2019 18:17:55 +0000 (11:17 -0700)]
Update the Pass, Analysis, and PassManager sections of WritingAPass.md.

These have become out-of-date with the pass manager generalization.

PiperOrigin-RevId: 270719105

4 years agoNFC: Fix warning for uninitialized field.
River Riddle [Mon, 23 Sep 2019 17:19:45 +0000 (10:19 -0700)]
NFC: Fix warning for uninitialized field.
PiperOrigin-RevId: 270704572

4 years agoAdd variants of interleave that take separator
Jacques Pienaar [Mon, 23 Sep 2019 16:49:43 +0000 (09:49 -0700)]
Add variants of interleave that take separator

Make the common case of string separator easier to specify.

PiperOrigin-RevId: 270697581

4 years agoOutline GPU kernel function into a nested module.
Christian Sigg [Mon, 23 Sep 2019 10:16:23 +0000 (03:16 -0700)]
Outline GPU kernel function into a nested module.

Roll forward of commit 5684a12.

When outlining GPU kernels, put the kernel function inside a nested module. Then use a nested pipeline to generate the cubins, independently per kernel. In a final pass, move the cubins back to the parent module.

PiperOrigin-RevId: 270639748

4 years agoFix a number of Clang-Tidy warnings.
Christian Sigg [Mon, 23 Sep 2019 09:33:51 +0000 (02:33 -0700)]
Fix a number of Clang-Tidy warnings.

PiperOrigin-RevId: 270632324

4 years ago[NFC] Replace std::clamp with inline implementation.
Jing Pu [Mon, 23 Sep 2019 06:00:29 +0000 (23:00 -0700)]
[NFC] Replace std::clamp with inline implementation.

std::clamp is not in C++14, thus replace it with std::min and std::max.
PiperOrigin-RevId: 270604708

4 years agoSpecalize f32->i8/u8 Quanitization with C++ native arithmetic to optimize performance.
Jing Pu [Mon, 23 Sep 2019 05:07:08 +0000 (22:07 -0700)]
Specalize f32->i8/u8 Quanitization with C++ native arithmetic to optimize performance.

The CL adds a rounding mode flag to the class and changes the default to rmNearestTiesToAway from rmNearestTiesToEven because 1) Tensorflow QuantizeV2 ops uses rmNearestTiesToAway; 2) the specialization only implements rmNearestTiesToAway.

PiperOrigin-RevId: 270600739

4 years agoUpdate TruncateIOp builder to pass OperationState by reference.
MLIR Team [Sun, 22 Sep 2019 20:14:56 +0000 (13:14 -0700)]
Update TruncateIOp builder to pass OperationState by reference.

PiperOrigin-RevId: 270560295

4 years agoupdate layout map examples in doc, drop stale ones
Uday Bondhugula [Sun, 22 Sep 2019 17:14:11 +0000 (10:14 -0700)]
update layout map examples in doc, drop stale ones

- add more examples for affine layout maps showing various use
  cases

- affine map range sizes were removed from code, but examples in
  LangRef weren't updated

Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>
Closes tensorflow/mlir#142

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/142 from bondhugula:doc 3291a8784bc69883f7a7cead21445fc8118aaad2
PiperOrigin-RevId: 270548991

4 years agoFix undefined reference to mlir::getElementTypeOrSelf(mlir::Type)
Denis Khalikov [Sun, 22 Sep 2019 16:08:06 +0000 (09:08 -0700)]
Fix undefined reference to mlir::getElementTypeOrSelf(mlir::Type)

Fix undefined reference:
mlir/lib/Dialect/StandardOps/Ops.cpp:2029:
undefined reference to `mlir::getElementTypeOrSelf(mlir::Type)'

Closes tensorflow/mlir#144

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/144 from denis0x0D:sandbox/fix_undef 494d4f7fa2e98ba21954d2b2f7ec1776b9397e08
PiperOrigin-RevId: 270545190

4 years agoAdd integer sign- and zero-extension and truncation to standard.
Manuel Freiberger [Sat, 21 Sep 2019 23:14:07 +0000 (16:14 -0700)]
Add integer sign- and zero-extension and truncation to standard.

This adds sign- and zero-extension and truncation of integer types to the
standard dialects. This allows to perform integer type conversions without
having to go to the LLVM dialect and introduce custom type casts (between
standard and LLVM integer types).

Closes tensorflow/mlir#134

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/134 from ombre5733:sext-zext-trunc-in-std c7657bc84c0ca66b304e53ec03797e09152e4d31
PiperOrigin-RevId: 270479722

4 years agominor spelling tweaks
brett koonce [Sat, 21 Sep 2019 18:38:41 +0000 (11:38 -0700)]
minor spelling tweaks

Closes tensorflow/mlir#143

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/143 from brettkoonce:minor_sp_demo 76bdf7c121a824417969627fc15e50259356a2fa
PiperOrigin-RevId: 270462293

4 years ago[spirv] Add OpControlBarrier and OpMemoryBarrier.
Denis Khalikov [Sat, 21 Sep 2019 17:18:00 +0000 (10:18 -0700)]
[spirv] Add OpControlBarrier and OpMemoryBarrier.

Add OpControlBarrier and OpMemoryBarrier (de)serialization.

Closes tensorflow/mlir#130

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/130 from denis0x0D:sandbox/memory_barrier 2e3fff16bca44904dc1039592cb9a65d526faea8
PiperOrigin-RevId: 270457478

4 years agoUpgrade/fix/simplify store to load forwarding
Uday Bondhugula [Sat, 21 Sep 2019 17:08:32 +0000 (10:08 -0700)]
Upgrade/fix/simplify store to load forwarding

- fix store to load forwarding for a certain set of cases (where
  forwarding shouldn't have happened); use AffineValueMap difference
  based MemRefAccess equality checking; utility logic is also greatly
  simplified

- add missing equality/inequality operators for AffineExpr ==/!= ints

- add == != operators on MemRefAccess

Closes tensorflow/mlir#136

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/136 from bondhugula:store-load-forwarding d79fd1add8bcfbd9fa71d841a6a9905340dcd792
PiperOrigin-RevId: 270457011

4 years agoAdd a note about the use of recursion in the developer guide
Mehdi Amini [Sat, 21 Sep 2019 16:44:58 +0000 (09:44 -0700)]
Add a note about the use of recursion in the developer guide

PiperOrigin-RevId: 270455509

4 years ago[ODS] Add support for FloatElementsAttr
Lei Zhang [Sat, 21 Sep 2019 16:44:38 +0000 (09:44 -0700)]
[ODS] Add support for FloatElementsAttr

This CL adds a new FloatElementsAttr definition to ODS for float
elements attributes of a certain type.

Tests are added to show both verification and how to use it in patterns.

PiperOrigin-RevId: 270455487

4 years agoMake GlobalOp's value attribute optional.
Christian Sigg [Sat, 21 Sep 2019 08:19:43 +0000 (01:19 -0700)]
Make GlobalOp's value attribute optional.

Make GlobalOp's value attribute an OptionalAttr. Change code that uses the value to handle 'nullopt'. Translate an unitialized value attribute to llvm::UndefValue.

PiperOrigin-RevId: 270423646

4 years agoNFC: Pass OpAsmPrinter by reference instead of by pointer.
River Riddle [Sat, 21 Sep 2019 03:43:02 +0000 (20:43 -0700)]
NFC: Pass OpAsmPrinter by reference instead of by pointer.

MLIR follows the LLVM style of pass-by-reference.

PiperOrigin-RevId: 270401378

4 years agoNFC: Pass OperationState by reference instead of by pointer.
River Riddle [Sat, 21 Sep 2019 02:47:05 +0000 (19:47 -0700)]
NFC: Pass OperationState by reference instead of by pointer.

MLIR follows the LLVM convention of passing by reference instead of by pointer.

PiperOrigin-RevId: 270396945

4 years agoAvoid iterator invalidation when recursively computing pattern depth.
River Riddle [Fri, 20 Sep 2019 23:29:44 +0000 (16:29 -0700)]
Avoid iterator invalidation when recursively computing pattern depth.

computeDepth calls itself recursively, which may insert into minPatternDepth. minPatternDepth is a DenseMap, which invalidates iterators on insertion, so this may lead to asan failures.

PiperOrigin-RevId: 270374203

4 years agoNFC: Pass OpAsmParser by reference instead of by pointer.
River Riddle [Fri, 20 Sep 2019 18:36:49 +0000 (11:36 -0700)]
NFC: Pass OpAsmParser by reference instead of by pointer.

MLIR follows the LLVM style of pass-by-reference.

PiperOrigin-RevId: 270315612

4 years agoUse SmallVectorImpl in getStrides
Nicolas Vasilache [Fri, 20 Sep 2019 18:13:24 +0000 (11:13 -0700)]
Use SmallVectorImpl in getStrides

No need to force a particular size on the user of the API.

PiperOrigin-RevId: 270310570

4 years agoFix public build
Nicolas Vasilache [Fri, 20 Sep 2019 17:49:38 +0000 (10:49 -0700)]
Fix public build

TestMemRefStrideCalculation.cpp was missing

PiperOrigin-RevId: 270304543

4 years agoAdd utility to extract strides from layout map in MemRefType.
Nicolas Vasilache [Fri, 20 Sep 2019 16:25:52 +0000 (09:25 -0700)]
Add utility to extract strides from layout map in MemRefType.

The RFC for unifying Linalg and Affine compilation passes into an end-to-end flow discusses the notion of a strided MemRef (https://groups.google.com/a/tensorflow.org/forum/#!topic/mlir/MaL8m2nXuio).

This CL adds helper functions to extract strides from the layout map which in turn will allow converting between a strided form of the type and a layout map.

For now strides are only computed on a single affine map with a single result (i.e. the closed subset of linearization maps that are compatible with striding semantics). This restriction will be reevaluated / lifted in the future based on concrete use cases.

PiperOrigin-RevId: 270284686

4 years agoRemove unused import and two import forms
Jacques Pienaar [Fri, 20 Sep 2019 00:45:02 +0000 (17:45 -0700)]
Remove unused import and two import forms

argparse was imported with both 'import' and 'import from' and string import was unused,

PiperOrigin-RevId: 270164488

4 years agoAllow specification of decorators on SPIR-V StructType members.
Mahesh Ravishankar [Thu, 19 Sep 2019 21:49:29 +0000 (14:49 -0700)]
Allow specification of decorators on SPIR-V StructType members.

Allow specification of decorators on SPIR-V StructType members. If the
struct has layout information, these decorations are to be specified
after the offset specification of the member. These decorations are
emitted as OpMemberDecorate instructions on the struct <id>. Update
(de)serialization to handle these decorations.

PiperOrigin-RevId: 270130136

4 years agoAutomated rollback of commit 5684a12434f923d03b6870f2aa16226bfb0b38b6
George Karpenkov [Thu, 19 Sep 2019 21:33:54 +0000 (14:33 -0700)]
Automated rollback of commit 5684a12434f923d03b6870f2aa16226bfb0b38b6

PiperOrigin-RevId: 270126672

4 years agoQuantize attribute values by per axis quantization parameters
Feng Liu [Thu, 19 Sep 2019 21:11:35 +0000 (14:11 -0700)]
Quantize attribute values by per axis quantization parameters

A new converter with per axis quantization parameters is added to quantize a
dense elements attribute. For each slice along the quantization axis, it
creates an uniform quantized value converter, with different scale and zero
point, and quantizes the values in the slice.

The current implementation doesn't handle sparse elements attributes.

PiperOrigin-RevId: 270121986

4 years agoNFC: Fix return indentation in generated op definitions.
Prakalp Srivastava [Thu, 19 Sep 2019 17:23:32 +0000 (10:23 -0700)]
NFC: Fix return indentation in generated op definitions.
PiperOrigin-RevId: 270070670

4 years agoAdd address space attribute to LLVMIR's GlobalOp.
MLIR Team [Thu, 19 Sep 2019 11:50:17 +0000 (04:50 -0700)]
Add address space attribute to LLVMIR's GlobalOp.

PiperOrigin-RevId: 270012505

4 years agoOutline GPU kernel function into a nested module.
MLIR Team [Thu, 19 Sep 2019 08:51:00 +0000 (01:51 -0700)]
Outline GPU kernel function into a nested module.

When outlining GPU kernels, put the kernel function inside a nested module. Then use a nested pipeline to generate the cubins, independently per kernel. In a final pass, move the cubins back to the parent module.

PiperOrigin-RevId: 269987720

4 years agoNFC: Remove stray logging from ~Block().
River Riddle [Thu, 19 Sep 2019 02:20:36 +0000 (19:20 -0700)]
NFC: Remove stray logging from ~Block().
PiperOrigin-RevId: 269941815

4 years agoFix nested dominance relationship between parent results and child operations.
River Riddle [Thu, 19 Sep 2019 01:23:12 +0000 (18:23 -0700)]
Fix nested dominance relationship between parent results and child operations.

This modifies DominanceInfo::properlyDominates(Value *value, Operation *op) to return false if the value is defined by a parent operation of 'op'. This prevents using values defined by the parent operation from within any child regions.

PiperOrigin-RevId: 269934920

4 years agoSupport symbolic operands for memref replacement; fix memrefNormalize
Uday Bondhugula [Wed, 18 Sep 2019 18:25:33 +0000 (11:25 -0700)]
Support symbolic operands for memref replacement; fix memrefNormalize

- allow symbols in index remapping provided for memref replacement
- fix memref normalize crash on cases with layout maps with symbols

Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>
Reported by: Alex Zinenko

Closes tensorflow/mlir#139

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/139 from bondhugula:memref-rep-symbols 2f48c1fdb5d4c58915bbddbd9f07b18541819233
PiperOrigin-RevId: 269851182

4 years agoUnify error messages to start with lower-case.
MLIR Team [Wed, 18 Sep 2019 14:44:39 +0000 (07:44 -0700)]
Unify error messages to start with lower-case.

PiperOrigin-RevId: 269803466

4 years agoSDBM: support sum expressions on the LHS of stripe expressions
Alex Zinenko [Wed, 18 Sep 2019 09:16:59 +0000 (02:16 -0700)]
SDBM: support sum expressions on the LHS of stripe expressions

Introduce support for applying the stripe operator to sum expressions, as in
  (x + A) # B = x + A - (x + A) mod B.
This is required to represent a combination of tiling and padding in the SDBM
framework, and is a valid SDBM construct that was not originally supported.

PiperOrigin-RevId: 269758807

4 years agoSimplify SDBM expressions more aggressively in operators and conversions
Alex Zinenko [Wed, 18 Sep 2019 09:08:19 +0000 (02:08 -0700)]
Simplify SDBM expressions more aggressively in operators and conversions

Extend SDBM simplification patterns to support more cases where the addition of
two expressions each involving one or two variables would result in a sum
expression that only contains one variable and thus remains in the SDBM domain.
This is made possible by the new canonical structure of SDBM where the constant
term appears once.  This simplification will be necessary to support
round-tripping of stripe expressions containing constant terms on the LHS
through affine expressions.

PiperOrigin-RevId: 269757732

4 years agoAdd support to OpAsmParser for parsing unknown keywords.
River Riddle [Wed, 18 Sep 2019 00:54:54 +0000 (17:54 -0700)]
Add support to OpAsmParser for parsing unknown keywords.

This is useful in several cases, for example a user may want to sugar the syntax of a string(as we do with custom operation syntax), or avoid many nested ifs for  parsing a set of known keywords.

PiperOrigin-RevId: 269695451

4 years agoAdd (de)serialization support for OpRuntimeArray.
Mahesh Ravishankar [Tue, 17 Sep 2019 22:21:20 +0000 (15:21 -0700)]
Add (de)serialization support for OpRuntimeArray.

Update the SPIR-V (de)serialization to handle RuntimeArrayType.

PiperOrigin-RevId: 269667196

4 years agoRegister a -test-spirv-roundtrip hook to mlir-translate
Lei Zhang [Tue, 17 Sep 2019 21:47:55 +0000 (14:47 -0700)]
Register a -test-spirv-roundtrip hook to mlir-translate

This CL registers a new mlir-translate hook, -test-spirv-roundtrip,
for testing SPIR-V serialization and deserialization round-trip.

This CL also moves the existing -serialize-spirv and
-deserialize-spirv hooks to one source file.

PiperOrigin-RevId: 269659528

4 years agoAdd a preprocess pass to remove sequences that are problematic with FileCheck
River Riddle [Tue, 17 Sep 2019 20:59:12 +0000 (13:59 -0700)]
Add a preprocess pass to remove sequences that are problematic with FileCheck

Add a preprocess phase to rewrite parts of the input line that may be problematic with filecheck. This change adds preprocessing to escape '[[' bracket sequences, as these are used by FileCheck for variables.

PiperOrigin-RevId: 269648490

4 years agoSupport file-to-file translation in mlir-translate
Lei Zhang [Tue, 17 Sep 2019 20:03:48 +0000 (13:03 -0700)]
Support file-to-file translation in mlir-translate

Existing translations are either from MLIR or to MLIR. To support
cases like round-tripping some external format via MLIR, one must
chain two mlir-translate invocations together using pipes. This
can be problematic to support -split-input-file in mlir-translate
given that it won't work across pipes.

Motivated by the above, this CL adds another translation category
that allows file to file. This gives users more freedom.

PiperOrigin-RevId: 269636438

4 years agoChange MLIR translation functions signature
Lei Zhang [Tue, 17 Sep 2019 19:16:05 +0000 (12:16 -0700)]
Change MLIR translation functions signature

This CL changes translation functions to take MemoryBuffer
as input and raw_ostream as output. It is generally better to
avoid handling files directly in a library (unless the library
is specifically for file manipulation) and we can unify all
file handling to the mlir-translate binary itself.

PiperOrigin-RevId: 269625911

4 years agoAdd rewrite pattern to compose maps into affine load/stores
Uday Bondhugula [Tue, 17 Sep 2019 18:49:14 +0000 (11:49 -0700)]
Add rewrite pattern to compose maps into affine load/stores

- add canonicalization pattern to compose maps into affine loads/stores;
  templatize the pattern and reuse it for affine.apply as well

- rename getIndices -> getMapOperands() (getIndices is confusing since
  these are no longer the indices themselves but operands to the map
  whose results are the indices). This also makes the accessor uniform
  across affine.apply/load/store. Change arg names on the affine
  load/store builder to avoid confusion. Drop an unused confusing build
  method on AffineStoreOp.

- update incomplete doc comment for canonicalizeMapAndOperands (this was
  missed from a previous update).

Addresses issue tensorflow/mlir#121

Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>
Closes tensorflow/mlir#122

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/122 from bondhugula:compose-load-store e71de1771e56a85c4282c10cb43f30cef0701c4f
PiperOrigin-RevId: 269619540

4 years agoAdd missing CMake dependency from libAnalysis to the Vector dialect
Mehdi Amini [Tue, 17 Sep 2019 07:38:28 +0000 (00:38 -0700)]
Add missing CMake dependency from libAnalysis to the Vector dialect

Fixes tensorflow/mlir#138

PiperOrigin-RevId: 269509668

4 years agoAutogenerate (de)serialization for Extended Instruction Sets
Mahesh Ravishankar [Tue, 17 Sep 2019 00:11:50 +0000 (17:11 -0700)]
Autogenerate (de)serialization for Extended Instruction Sets

A generic mechanism for (de)serialization of extended instruction sets
is added with this CL. To facilitate this, a new class
"SPV_ExtendedInstSetOp" is added which is a base class for all
operations corresponding to extended instruction sets. The methods to
(de)serialization such ops as well as its dispatch is generated
automatically.

The behavior controlled by autogenSerialization and hasOpcode is also
slightly modified to enable this. They are now decoupled.
1) Setting hasOpcode=1 means the operation has a corresponding
   opcode in SPIR-V binary format, and its dispatch for
   (de)serialization is automatically generated.
2) Setting autogenSerialization=1 generates the function for
   (de)serialization automatically.
So now it is possible to have hasOpcode=0 and autogenSerialization=1
(for example SPV_ExtendedInstSetOp).

Since the dispatch functions is also auto-generated, the input file
needs to contain all operations. To this effect, SPIRVGLSLOps.td is
included into SPIRVOps.td. This makes the previously added
SPIRVGLSLOps.h and SPIRVGLSLOps.cpp unnecessary, and are deleted.

The SPIRVUtilsGen.cpp is also changed to make better use of
formatv,making the code more readable.

PiperOrigin-RevId: 269456263

4 years ago[spirv] Add support for function calls.
Denis Khalikov [Mon, 16 Sep 2019 22:39:16 +0000 (15:39 -0700)]
[spirv] Add support for function calls.

Add spv.FunctionCall operation and (de)serialization.

Closes tensorflow/mlir#137

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/137 from denis0x0D:sandbox/function_call_op e2e6f07d21e7f23e8b44c7df8a8ab784f3356ce4
PiperOrigin-RevId: 269437167