platform/upstream/llvm.git
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

4 years agoAdd support for multi-level value mapping to DialectConversion.
River Riddle [Mon, 16 Sep 2019 17:37:48 +0000 (10:37 -0700)]
Add support for multi-level value mapping to DialectConversion.

When performing A->B->C conversion, an operation may still refer to an operand of A. This makes it necessary to unmap through multiple levels of replacement for a specific value.

PiperOrigin-RevId: 269367859

4 years ago[spirv] Add support for BitEnumAttr
Lei Zhang [Mon, 16 Sep 2019 16:22:43 +0000 (09:22 -0700)]
[spirv] Add support for BitEnumAttr

Certain enum classes in SPIR-V, like function/loop control and memory
access, are bitmasks. This CL introduces a BitEnumAttr to properly
model this and drive auto-generation of verification code and utility
functions. We still store the attribute using an 32-bit IntegerAttr
for minimal memory footprint and easy (de)serialization. But utility
conversion functions are adjusted to inspect each bit and generate
"|"-concatenated strings for the bits; vice versa.

Each such enum class has a "None" case that means no bit is set. We
need special handling for "None". Because of this, the logic is not
general anymore. So right now the definition is placed in the SPIR-V
dialect. If later this turns out to be useful for other dialects,
then we can see how to properly adjust it and move to OpBase.td.

Added tests for SPV_MemoryAccess to check and demonstrate.

PiperOrigin-RevId: 269350620

4 years agoOverhaul the SDBM expression kind hierarchy
Alex Zinenko [Mon, 16 Sep 2019 15:15:25 +0000 (08:15 -0700)]
Overhaul the SDBM expression kind hierarchy

Swap the allowed nesting of sum and diff expressions: now a diff expression can
contain a sum expression, but only on the left hand side.  A difference of two
expressions sum must be canonicalized by grouping their constant terms in a
single expression.  This change of sturcture became possible thanks to the
introduction of the "direct" super-kind.  It is necessary to enable support of
sum expressions on the left hand side of the stripe expression.

SDBM expressions are now grouped into the following structure
- expression
  - varying
    - direct
      - sum <- (term, constant)
      - term
        - symbol
        - dimension
        - stripe <- (term, constant)
    - negation <- (direct)
    - difference <- (direct, term)
  - constant
The notation <- (...) denotes the types of subexpressions a compound
expression can combine.

PiperOrigin-RevId: 269337222

4 years agoIntroduce SDBMDirect expression into the SDBM expression hierarchy
Alex Zinenko [Mon, 16 Sep 2019 15:08:22 +0000 (08:08 -0700)]
Introduce SDBMDirect expression into the SDBM expression hierarchy

Direct expressions are those that do not negate any of the variables they
involve.  They include input expressions (dimensions and symbols), stripe and
sum expressions, and combinations of those.  Reifying direct expressions as a
class is a precondition for enabling additions on the LHS of a stripe
expression.

PiperOrigin-RevId: 269336031

4 years agoUnify how errors are emitted in LaunchFuncOp verification.
MLIR Team [Mon, 16 Sep 2019 14:45:13 +0000 (07:45 -0700)]
Unify how errors are emitted in LaunchFuncOp verification.

PiperOrigin-RevId: 269331869

4 years agoError out when kernel function is not found while translating GPU calls.
MLIR Team [Mon, 16 Sep 2019 14:18:40 +0000 (07:18 -0700)]
Error out when kernel function is not found while translating GPU calls.

PiperOrigin-RevId: 269327909

4 years agoDrop makePositionAttr and the like in favor of Builder::getI64ArrayAttr
Alex Zinenko [Mon, 16 Sep 2019 10:30:33 +0000 (03:30 -0700)]
Drop makePositionAttr and the like in favor of Builder::getI64ArrayAttr

The helper functions makePositionAttr() and positionAttr() were originally
introduced in the lowering-to-LLVM-dialect pass to construct integer array
attributes that are used for static positions in extract/insertelement.
Constructing an integer array attribute being fairly common, a utility function
Builder::getI64ArrayAttr was later introduced into the Builder API.  Drop
makePositionAttr and similar homegrown functions and use that API instead.
PiperOrigin-RevId: 269295836

4 years agoAdd mechanism to specify extended instruction sets in SPIR-V.
Mahesh Ravishankar [Mon, 16 Sep 2019 02:39:28 +0000 (19:39 -0700)]
Add mechanism to specify extended instruction sets in SPIR-V.

Add support for specifying extended instructions sets. The operations
in SPIR-V dialect are named as 'spv.<extension-name>.<op-name>'. Use
this mechanism to define a 'Exp' operation from GLSL(450)
instructions.
Later CLs will add support for (de)serialization of these operations,
and update the dialect generation scripts to auto-generate the
specification using the spec directly.

Additional changes:
Add a Type Constraint to OpBase.td to check for vector of specified
lengths. This is used to check that the vector type used in SPIR-V
dialect are of lengths 2, 3 or 4.
Update SPIRVBase.td to use this Type constraints for vectors.

PiperOrigin-RevId: 269234377

4 years agoUpdate the pass registration section and add a sub-section on the textual pipeline...
River Riddle [Sun, 15 Sep 2019 21:00:31 +0000 (14:00 -0700)]
Update the pass registration section and add a sub-section on the textual pipeline specification.

Now that the pass manager is generalized, and nested/arbritrary pipelines are possible, it is important to document how to specify these types of pipelines from the command line.

PiperOrigin-RevId: 269207681

4 years agoFix typo in test/AffineOps/ops.mlir
Uday Bondhugula [Sun, 15 Sep 2019 16:05:54 +0000 (09:05 -0700)]
Fix typo in test/AffineOps/ops.mlir

Closes tensorflow/mlir#135

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/135 from bondhugula:patch-1 539a7f1b43d09ef539b2fd15875f8ac765600263
PiperOrigin-RevId: 269187507

4 years agoNFC: Update the PassInstrumentation section.
River Riddle [Sun, 15 Sep 2019 05:10:00 +0000 (22:10 -0700)]
NFC: Update the PassInstrumentation section.

This section has grown stale as the pass infrastructure has been generalized.

PiperOrigin-RevId: 269140863

4 years agoNFC: Update the expected outputs of pass-timing.
River Riddle [Sun, 15 Sep 2019 05:02:41 +0000 (22:02 -0700)]
NFC: Update the expected outputs of pass-timing.

The output of the pass timing instrumentation has been changed now that the pass hierarchy has been generalized.

PiperOrigin-RevId: 269140277

4 years agoUpdate the IRPrinter instrumentation to work on non function/module operations.
River Riddle [Sun, 15 Sep 2019 04:56:09 +0000 (21:56 -0700)]
Update the IRPrinter instrumentation to work on non function/module operations.

This is necessary now that the pass manager may work on different types of operations.

PiperOrigin-RevId: 269139669

4 years agoNFC: Pass PassInstrumentations by unique_ptr instead of raw pointer.
River Riddle [Sun, 15 Sep 2019 00:44:10 +0000 (17:44 -0700)]
NFC: Pass PassInstrumentations by unique_ptr instead of raw pointer.

This makes the ownership model explicit, and removes potential user errors.

PiperOrigin-RevId: 269122834

4 years agoNFC: Merge OpPass with OperationPass into just OperationPass.
River Riddle [Sun, 15 Sep 2019 00:37:03 +0000 (17:37 -0700)]
NFC: Merge OpPass with OperationPass into just OperationPass.

OperationPass' are defined exactly the same way as they are now:
   class DerivedPass :  public OperationPass<DerivedPass>;

OpPass' are now defined as OperationPass, but with an additional template parameter for the operation type:
   class DerivedPass :  public OperationPass<DerivedPass, FuncOp>;

PiperOrigin-RevId: 269122410

4 years agoAdd convenience methods to create i8 and i16 attributes in Builder.
Jing Pu [Sun, 15 Sep 2019 00:02:06 +0000 (17:02 -0700)]
Add convenience methods to create i8 and i16 attributes in Builder.

PiperOrigin-RevId: 269120226

4 years agoNFC - Move explicit copy/dma generation utility out of pass and into LoopUtils
Uday Bondhugula [Sat, 14 Sep 2019 20:23:18 +0000 (13:23 -0700)]
NFC - Move explicit copy/dma generation utility out of pass and into LoopUtils

- turn copy/dma generation method into a utility in LoopUtils, allowing
  it to be reused elsewhere.

- no functional/logic change to the pass/utility

- trim down header includes in files affected

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

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/124 from bondhugula:datacopy 9f346e62e5bd9dd1986720a30a35f302eb4d3252
PiperOrigin-RevId: 269106088

4 years agoupdate normalizeMemRef utility; handle missing failure check + add more tests
Uday Bondhugula [Sat, 14 Sep 2019 20:21:00 +0000 (13:21 -0700)]
update normalizeMemRef utility; handle missing failure check + add more tests

- take care of symbolic operands with alloc
- add missing check for compose map failure and a test case
- add test cases on strides
- drop incorrect check for one-to-one'ness

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

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/132 from bondhugula:normalize-memrefs 8aebf285fb0d7c19269d85255aed644657e327b7
PiperOrigin-RevId: 269105947

4 years agoClean up build trip count analysis method - avoid mutating IR
Uday Bondhugula [Sat, 14 Sep 2019 19:10:18 +0000 (12:10 -0700)]
Clean up build trip count analysis method - avoid mutating IR

- NFC - on any pass/utility logic/output.

- Resolve TODO; the method building loop trip count maps was
  creating and deleting affine.apply ops (transforming IR from under
  analysis!, strictly speaking). Introduce AffineValueMap::difference to
  do this correctly (without the need to create any IR).

- Move AffineApplyNormalizer out so that its methods are reusable from
  AffineStructures.cpp; add a helper method 'normalize' to it. Fix
  AffineApplyNormalize::renumberOneDim (Issue tensorflow/mlir#89).

- Trim includes on files touched.

- add test case on a scenario previously not covered

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

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/133 from bondhugula:trip-count-build 7fc34d857f7788f98b641792cafad6f5bd50e47b
PiperOrigin-RevId: 269101118

4 years agoNFC: Fix stray character in error message: 1 -> '
River Riddle [Sat, 14 Sep 2019 16:43:55 +0000 (09:43 -0700)]
NFC: Fix stray character in error message: 1 -> '
PiperOrigin-RevId: 269091468

4 years agoUpdate QuickstartRewrites.md regarding op definition and rewrites
Lei Zhang [Sat, 14 Sep 2019 15:36:53 +0000 (08:36 -0700)]
Update QuickstartRewrites.md regarding op definition and rewrites

This CL updates the doc with recent changes. It also adds a section
on registering and using the auto-generated patterns.

PiperOrigin-RevId: 269086830

4 years agoAdd pattern to canonicalize for loop bounds
Uday Bondhugula [Sat, 14 Sep 2019 05:11:23 +0000 (22:11 -0700)]
Add pattern to canonicalize for loop bounds

- add pattern to canonicalize affine.for loop bounds (using
  canonicalizeMapAndOperands)
- rename AffineForLoopBoundFolder -> AffineForLoopBoundFolder for
  consistency

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

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/111 from bondhugula:bound-canonicalize ee8fb7f43a7ffd45f6df3f53c95098d8b7e494c7
PiperOrigin-RevId: 269041220

4 years agoVerify that ModuleOps only contain dialect specific attributes.
River Riddle [Sat, 14 Sep 2019 01:18:22 +0000 (18:18 -0700)]
Verify that ModuleOps only contain dialect specific attributes.

ModuleOp has no expected operations, so only dialect-specific attributes are valid.

PiperOrigin-RevId: 269020062

4 years agoadd missing memref cast fold pattern for dim op
Uday Bondhugula [Sat, 14 Sep 2019 01:18:21 +0000 (18:18 -0700)]
add missing memref cast fold pattern for dim op

- add missing canonicalization pattern to fold memref_cast + dim to
  dim (needed to propagate constant when folding a dynamic shape to
  a static one)

- also fix an outdated/inconsistent comment in StandardOps/Ops.td

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

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/126 from bondhugula:quickfix 4566e75e49685c532faffff91d64c5d83d4da524
PiperOrigin-RevId: 269020058

4 years agoPublicly expose the functionality to parse a textual pass pipeline.
River Riddle [Sat, 14 Sep 2019 00:53:28 +0000 (17:53 -0700)]
Publicly expose the functionality to parse a textual pass pipeline.

This allows for users other than those on the command line to apply a textual description of a pipeline to a given pass manager.

PiperOrigin-RevId: 269017028

4 years agoAdd type constraints for shaped types with same rank and element count
Geoffrey Martin-Noble [Fri, 13 Sep 2019 23:05:06 +0000 (16:05 -0700)]
Add type constraints for shaped types with same rank and element count

PiperOrigin-RevId: 269000237

4 years agoUpdate SPIR-V symbols and use GLSL450 instead of VulkanKHR
Lei Zhang [Fri, 13 Sep 2019 22:25:56 +0000 (15:25 -0700)]
Update SPIR-V symbols and use GLSL450 instead of VulkanKHR

SPIR-V recently publishes v1.5, which brings a bunch of symbols
into core. So the suffix "KHR"/"EXT"/etc. is removed from the
symbols. We use a script to pull information from the spec
directly.

Also changed conversion and tests to use GLSL450 instead of
VulkanKHR memory model. GLSL450 is still the main memory model
supported by Vulkan shaders and it does not require extra
capability to enable.

PiperOrigin-RevId: 268992661

4 years agoNFC: Finish replacing FunctionPassBase/ModulePassBase with OpPassBase.
River Riddle [Fri, 13 Sep 2019 20:33:46 +0000 (13:33 -0700)]
NFC: Finish replacing FunctionPassBase/ModulePassBase with OpPassBase.

These directives were temporary during the generalization of FunctionPass/ModulePass to OpPass.

PiperOrigin-RevId: 268970259

4 years agoAdd tablegen class for memrefs with rank constraints
Geoffrey Martin-Noble [Fri, 13 Sep 2019 20:21:57 +0000 (13:21 -0700)]
Add tablegen class for memrefs with rank constraints

PiperOrigin-RevId: 268968004

4 years agoForward diagnostics from untracked threads in ParallelDiagnosticHandler.
River Riddle [Fri, 13 Sep 2019 20:18:44 +0000 (13:18 -0700)]
Forward diagnostics from untracked threads in ParallelDiagnosticHandler.

This allows for the use of multiple ParallelDiagnosticHandlers without having them conflict with each other.

PiperOrigin-RevId: 268967407

4 years agoImprove verifier error reporting on type mismatch (NFC)
MLIR Team [Fri, 13 Sep 2019 19:46:07 +0000 (12:46 -0700)]
Improve verifier error reporting on type mismatch (NFC)

Before this change, it only reports expected type but not exact type, so
it's hard to troubleshoot.

PiperOrigin-RevId: 268961078

4 years agoRefactor pass pipeline command line parsing to support explicit pipeline strings.
River Riddle [Fri, 13 Sep 2019 19:09:50 +0000 (12:09 -0700)]
Refactor pass pipeline command line parsing to support explicit pipeline strings.

This allows for explicitly specifying the pipeline to add to the pass manager. This includes the nesting structure, as well as the passes/pipelines to run. A textual pipeline string is defined as a series of names, each of which may in itself recursively contain a nested pipeline description. A name is either the name of a registered pass, or pass pipeline, (e.g. "cse") or the name of an operation type (e.g. "func").

For example, the following pipeline:
$ mlir-opt foo.mlir -cse -canonicalize -lower-to-llvm

Could now be specified as:
$ mlir-opt foo.mlir -pass-pipeline='func(cse, canonicalize), lower-to-llvm'

This will allow for running pipelines on nested operations, like say spirv modules. This does not remove any of the current functionality, and in fact can be used in unison. The new option is available via 'pass-pipeline'.

PiperOrigin-RevId: 268954279

4 years agoNFC: Update comments about rank constraints
Geoffrey Martin-Noble [Fri, 13 Sep 2019 17:28:53 +0000 (10:28 -0700)]
NFC: Update comments about rank constraints

These refer to ranked tensors, but are actually applicable to any shaped type

PiperOrigin-RevId: 268931789

4 years agoFixing typo in documentation.
MLIR Team [Fri, 13 Sep 2019 11:07:33 +0000 (04:07 -0700)]
Fixing typo in documentation.

PiperOrigin-RevId: 268877189

4 years agoLog name of the generated illegal operation name in DialectConversion debug mode
Smit Hinsu [Fri, 13 Sep 2019 08:37:07 +0000 (01:37 -0700)]
Log name of the generated illegal operation name in DialectConversion debug mode

PiperOrigin-RevId: 268859399

4 years agoCmpf constant folding for nan and inf
Geoffrey Martin-Noble [Thu, 12 Sep 2019 22:43:26 +0000 (15:43 -0700)]
Cmpf constant folding for nan and inf

PiperOrigin-RevId: 268783645

4 years agoNFC: Clean up constant fold tests
Geoffrey Martin-Noble [Thu, 12 Sep 2019 22:29:59 +0000 (15:29 -0700)]
NFC: Clean up constant fold tests

Use variable captures to make constant folding tests less sensitive to printer/parser implementation details.

See guidelines at https://github.com/tensorflow/mlir/blob/master/g3doc/TestingGuide.md

PiperOrigin-RevId: 268780812

4 years ago[spirv] Add support for spv.loop (de)serialization
Lei Zhang [Wed, 11 Sep 2019 21:02:23 +0000 (14:02 -0700)]
[spirv] Add support for spv.loop (de)serialization

This CL adds support for serializing and deserializing spv.loop ops.
This adds support for spv.Branch and spv.BranchConditional op
(de)serialization, too, because they are needed for spv.loop.

PiperOrigin-RevId: 268536962

4 years agoRename SDBMPositiveExpr to SDBMTermExpr
Alex Zinenko [Wed, 11 Sep 2019 17:18:01 +0000 (10:18 -0700)]
Rename SDBMPositiveExpr to SDBMTermExpr

This better reflects how this kind of expressions is used and avoids the
potential confusion since the expression can take negative values.  Term
expressions comprise dimensions, symbols and stripe expressions.  In an SDBM
domain, a stripe expression always corresponds to a variable, input or
temporary.  This expression can appear anywhere an input variable can,
including on the LHS of other stripe expressions.

PiperOrigin-RevId: 268486066

4 years agoFix typos in SDBMTest.cpp
Alex Zinenko [Wed, 11 Sep 2019 13:11:03 +0000 (06:11 -0700)]
Fix typos in SDBMTest.cpp

PiperOrigin-RevId: 268443146

4 years agoAdd logical groups to NVVM op definitions.
MLIR Team [Wed, 11 Sep 2019 12:09:23 +0000 (05:09 -0700)]
Add logical groups to NVVM op definitions.

PiperOrigin-RevId: 268436116

4 years agoFix a typo in comments. The Inequality and Equality explanations were apparently...
MLIR Team [Wed, 11 Sep 2019 06:53:58 +0000 (23:53 -0700)]
Fix a typo in comments. The Inequality and Equality explanations were apparently reversed.

PiperOrigin-RevId: 268395163

4 years agoDon't leak TargetMachine in ExecutionEngine::setupTargetTriple
MLIR Team [Wed, 11 Sep 2019 02:02:54 +0000 (19:02 -0700)]
Don't leak TargetMachine in ExecutionEngine::setupTargetTriple

PiperOrigin-RevId: 268361054

4 years agoAdd folding rule for spv.CompositeExtract
Lei Zhang [Wed, 11 Sep 2019 00:47:37 +0000 (17:47 -0700)]
Add folding rule for spv.CompositeExtract

If the composite is a constant, we can fold it away. This only
supports vector and array constants for now, given that struct
constant is not supported in spv.constant yet.

PiperOrigin-RevId: 268350340

4 years agoRemove the constraint that min / max should stride zero
Feng Liu [Tue, 10 Sep 2019 20:26:14 +0000 (13:26 -0700)]
Remove the constraint that min / max should stride zero

Since we apply nudging for the zero point to make sure the nudged zerop points
can be in the range of [qmin, qmax], the constraint that rmin / rmax should
stride zero isn't necessary.

This also matches the documentation of tensorflow's FakeQuantWithMinMaxArgs op,
where min and max don't need to stride zero:
https://www.tensorflow.org/api_docs/python/tf/quantization/fake_quant_with_min_max_args

PiperOrigin-RevId: 268296285

4 years agoConvert ConstFakeQuantPerAxis to qcast and dcast pair
Feng Liu [Tue, 10 Sep 2019 17:50:16 +0000 (10:50 -0700)]
Convert ConstFakeQuantPerAxis to qcast and dcast pair

This is also to add the test to the fakeQuantAttrsToType for per-channel fake quant.

PiperOrigin-RevId: 268260032

4 years agoRemove unused variable
Jacques Pienaar [Tue, 10 Sep 2019 08:30:34 +0000 (01:30 -0700)]
Remove unused variable

PiperOrigin-RevId: 268173638

4 years agoRemove redundant qualification
Jacques Pienaar [Tue, 10 Sep 2019 02:50:19 +0000 (19:50 -0700)]
Remove redundant qualification

Address GCC error: extra qualification not allowed [-fpermissive]

PiperOrigin-RevId: 268133737

4 years agoAvoid sign-compare warning
Jacques Pienaar [Tue, 10 Sep 2019 02:36:02 +0000 (19:36 -0700)]
Avoid sign-compare warning

PiperOrigin-RevId: 268132321

4 years agoAdd pass generate per block in a function a GraphViz Dot graph with ops as nodes
Jacques Pienaar [Tue, 10 Sep 2019 01:12:12 +0000 (18:12 -0700)]
Add pass generate per block in a function a GraphViz Dot graph with ops as nodes

* Add GraphTraits that treat a block as a graph, Operation* as node and use-relationship for edges;
  - Just basic graph output;
* Add use iterator to iterate over all uses of an Operation;
* Add testing pass to generate op graph;

This does not support arbitrary operations other than function nor nested regions yet.

PiperOrigin-RevId: 268121782

4 years agoAdd quant.const_fake_quant_per_axis op
Feng Liu [Mon, 9 Sep 2019 22:42:07 +0000 (15:42 -0700)]
Add quant.const_fake_quant_per_axis op

Comparing to the existing quant.const_fake_quant op, the min and max attributes
of this new op is for each channel of last dimension of the input.

PiperOrigin-RevId: 268093722

4 years ago[NFC] Rename ExpressedToUniformQuantizedType to ExpressedToQuantizedType
Feng Liu [Mon, 9 Sep 2019 22:29:30 +0000 (15:29 -0700)]
[NFC] Rename ExpressedToUniformQuantizedType to ExpressedToQuantizedType

PiperOrigin-RevId: 268090906

4 years agoConvert per channel fake quant attributes to type
Feng Liu [Mon, 9 Sep 2019 21:57:29 +0000 (14:57 -0700)]
Convert per channel fake quant attributes to type

For per channel fake quant attributes, the returned type should be
UniformQuantizedPerAxisType. Currently, this method isn't under test because we
haven't added the quant_ConstFakeQuantPerAxis op and the convert method.

PiperOrigin-RevId: 268084017

4 years agoExplicitly declare the OpPassManager move constructor to avoid undefined errors.
River Riddle [Mon, 9 Sep 2019 20:43:51 +0000 (13:43 -0700)]
Explicitly declare the OpPassManager move constructor to avoid undefined errors.

Some compilers will try to auto-generate the destructor, instead of using the user provided destructor, when creating a default move constructor.

PiperOrigin-RevId: 268067367

4 years agoOverload LLVM::TerminatorOp::build() for empty operands list.
MLIR Team [Mon, 9 Sep 2019 18:38:34 +0000 (11:38 -0700)]
Overload LLVM::TerminatorOp::build() for empty operands list.

PiperOrigin-RevId: 268041584

4 years agoAdd warpsize and laneid intrinsics to NVVM dialect.
MLIR Team [Mon, 9 Sep 2019 18:37:05 +0000 (11:37 -0700)]
Add warpsize and laneid intrinsics to NVVM dialect.

PiperOrigin-RevId: 268041263

4 years agoAdd support for coalescing adjacent nested pass pipelines.
River Riddle [Mon, 9 Sep 2019 16:51:59 +0000 (09:51 -0700)]
Add support for coalescing adjacent nested pass pipelines.

This allows for parallelizing across pipelines of multiple operation types. AdaptorPasses can now hold pass managers for multiple operation types and will dispatch based upon the operation being operated on.

PiperOrigin-RevId: 268017344

4 years agoAddressing some late review comments on kernel inlining.
Stephan Herhut [Mon, 9 Sep 2019 08:15:10 +0000 (01:15 -0700)]
Addressing some late review comments on kernel inlining.

Just formatting and better lit tests, no functional change.

PiperOrigin-RevId: 267942907

4 years agoAdd `parseGenericOperation()` to the OpAsmParser
Mehdi Amini [Mon, 9 Sep 2019 06:39:34 +0000 (23:39 -0700)]
Add `parseGenericOperation()` to the OpAsmParser

This method parses an operation in its generic form, from the current parser
state. This is the symmetric of OpAsmPrinter::printGenericOp(). An immediate
use case is illustrated in the test dialect, where an operation wraps another
one in its region and makes use of a single-line pretty-print form.

PiperOrigin-RevId: 267930869

4 years agoRefactor PassTiming to support nested pipelines.
River Riddle [Mon, 9 Sep 2019 02:57:25 +0000 (19:57 -0700)]
Refactor PassTiming to support nested pipelines.

This is done via a new set of instrumentation hooks runBeforePipeline/runAfterPipeline, that signal the lifetime of a pass pipeline on a specific operation type. These hooks also provide the parent thread of the pipeline, allowing for accurate merging of timers running on different threads.

PiperOrigin-RevId: 267909193

4 years agoUse "final" instead of marking method virtual in override (NFC)
Mehdi Amini [Sun, 8 Sep 2019 01:56:39 +0000 (18:56 -0700)]
Use "final" instead of marking method virtual in override (NFC)

This is the only example for overriding this interface in the repo, let's
try to make it right as it may be taken as a reference when implemented in
other dialects

PiperOrigin-RevId: 267811123

4 years agoRefactor getUsedValuesDefinedAbove to expose a variant taking a callback (NFC)
Mehdi Amini [Sun, 8 Sep 2019 00:02:07 +0000 (17:02 -0700)]
Refactor getUsedValuesDefinedAbove to expose a variant taking a callback (NFC)

This will allow clients to implement a different collection strategy on these
values, including collecting each uses within the region for example.

PiperOrigin-RevId: 267803978

4 years agoSet mlir-cpu-runner JIT codegen opt level correctly
Uday Bondhugula [Sat, 7 Sep 2019 16:59:47 +0000 (09:59 -0700)]
Set mlir-cpu-runner JIT codegen opt level correctly

- the JIT codegen was being run at the default -O0 level; instead,
  propagate the opt level from the cmd line.

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

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/123 from bondhugula:jit-runner 3b055e47f94c9a48bf487f6400787478738cda02
PiperOrigin-RevId: 267778586

4 years agoWrap debug dump in LLVM_DEBUG
Mehdi Amini [Sat, 7 Sep 2019 15:53:24 +0000 (08:53 -0700)]
Wrap debug dump in LLVM_DEBUG

PiperOrigin-RevId: 267774506

4 years agoAdd doc for declarative rewrite rules
Lei Zhang [Sat, 7 Sep 2019 12:25:39 +0000 (05:25 -0700)]
Add doc for declarative rewrite rules

This doc serves as a manual for table-driven declarative rewrite rules.
It lists all the details regarding supported mechanisms.

PiperOrigin-RevId: 267761702

4 years agoFix typo in the documentation for tensor_cast (NFC)
Mehdi Amini [Fri, 6 Sep 2019 19:30:06 +0000 (12:30 -0700)]
Fix typo in the documentation for tensor_cast (NFC)

PiperOrigin-RevId: 267650411

4 years agoRestrict affine inlining to just Function operations.
River Riddle [Fri, 6 Sep 2019 18:43:35 +0000 (11:43 -0700)]
Restrict affine inlining to just Function operations.

The current restrictions on dim/symbols require a top-level symbol for the conservative case of a non-affine region. This should be relaxed in the future.

PiperOrigin-RevId: 267641838

4 years agoAdd custom builder for AffineIfOp
Nagy Mostafa [Fri, 6 Sep 2019 18:02:31 +0000 (11:02 -0700)]
Add custom builder for AffineIfOp

Closes tensorflow/mlir#109

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/109 from nmostafa:nmostafa/AffineIfOp 7dbf2115f0092ffab26381ea8704aa05a0253971
PiperOrigin-RevId: 267633077

4 years agoSimplify Linalg ABI integration with external function calls.
Nicolas Vasilache [Fri, 6 Sep 2019 15:30:54 +0000 (08:30 -0700)]
Simplify Linalg ABI integration with external function calls.

View descriptors are converted to *pointer to* LLVM struct to avoid ABI issues related to C struct packing. This creates unnecessary complexity and hampers unification with memrefs.
Instead, this CL makes view descriptors convert to LLVM struct (as it was originally) and promotes all structs to pointers right before calling an external function.

PiperOrigin-RevId: 267602693

4 years agoFix typos in Interfaces.md
Alex Zinenko [Fri, 6 Sep 2019 08:22:24 +0000 (01:22 -0700)]
Fix typos in Interfaces.md

PiperOrigin-RevId: 267548530

4 years agoInteger set + operands / affine if op canonicalization
Uday Bondhugula [Fri, 6 Sep 2019 06:12:01 +0000 (23:12 -0700)]
Integer set + operands / affine if op canonicalization

- turn canonicalizeMapAndOperands into a template that works on both
  sets and maps, and use it to introduce a utility to canonicalize an
  affine integer set and its operands
- add pattern to canonicalize affine if op's.
- rename IntegerSet::getNumOperands -> IntegerSet::getNumInputs to be
  consistent with AffineMap
- add missing accessors for IntegerSet

Doesn't need extensive testing since canonicalizeSetAndOperands just
reuses canonicalizeMapAndOperands' logic, and the latter is tested on
affine.apply map + operands; the new method works the same way on an
integer set + operands of an affine if op for example.

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

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/112 from bondhugula:set-canonicalize eff72f23250b96fa7d9f5caff3877440f5de2cec
PiperOrigin-RevId: 267532876

4 years agoAdd support for conservatively inlining Affine operations.
River Riddle [Thu, 5 Sep 2019 22:19:55 +0000 (15:19 -0700)]
Add support for conservatively inlining Affine operations.

This commit defines an initial implementation of the DialectInlinerInterface for the AffineOps dialect. This change allows for affine operations to be inlined into any region that is not an affine region. Inlining into affine regions requires special handling for dimension/symbol identifiers that will be added in followups.

PiperOrigin-RevId: 267467078

4 years ago[spirv] Add spv.loop
Lei Zhang [Thu, 5 Sep 2019 19:45:08 +0000 (12:45 -0700)]
[spirv] Add spv.loop

SPIR-V can explicitly declare structured control-flow constructs using merge
instructions. These explicitly declare a header block before the control
flow diverges and a merge block where control flow subsequently converges.
These blocks delimit constructs that must nest, and can only be entered
and exited in structured ways.

Instead of having a `spv.LoopMerge` op to directly model loop merge
instruction for indicating the merge and continue target, we use regions
to delimit the boundary of the loop: the merge target is the next op
following the `spv.loop` op and the continue target is the block that
has a back-edge pointing to the entry block inside the `spv.loop`'s region.
This way it's easier to discover all blocks belonging to a construct and
it plays nicer with the MLIR system.

Updated the SPIR-V.md doc.

PiperOrigin-RevId: 267431010

4 years agoAdd the initial inlining infrastructure.
River Riddle [Thu, 5 Sep 2019 19:23:45 +0000 (12:23 -0700)]
Add the initial inlining infrastructure.

This defines a set of initial utilities for inlining a region(or a FuncOp), and defines a simple inliner pass for testing purposes.
A new dialect interface is defined, DialectInlinerInterface, that allows for dialects to override hooks controlling inlining legality. The interface currently provides the following hooks, but these are just premilinary and should be changed/added to/modified as necessary:

* isLegalToInline
  - Determine if a region can be inlined into one of this dialect, *or* if an operation of this dialect can be inlined into a given region.

* shouldAnalyzeRecursively
  - Determine if an operation with regions should be analyzed recursively for legality. This allows for child operations to be closed off from the legality checks for operations like lambdas.

* handleTerminator
  - Process a terminator that has been inlined.

This cl adds support for inlining StandardOps, but other dialects will be added in followups as necessary.

PiperOrigin-RevId: 267426759

4 years agoMake GPU kernel outlining test independent of value names.
Stephan Herhut [Thu, 5 Sep 2019 08:45:40 +0000 (01:45 -0700)]
Make GPU kernel outlining test independent of value names.

PiperOrigin-RevId: 267323604

4 years agoGeneralize I32ElementsAttr definition and introduce I64ElementsAttr
Smit Hinsu [Thu, 5 Sep 2019 06:15:33 +0000 (23:15 -0700)]
Generalize I32ElementsAttr definition and introduce I64ElementsAttr

Also, fix constBuilderCall to return attribute of the storage class DenseIntElementsAttr

PiperOrigin-RevId: 267305813

4 years agoUse transform function on llvm::Module in the ExecutionEngine
Nicolas Vasilache [Thu, 5 Sep 2019 02:16:32 +0000 (19:16 -0700)]
Use transform function on llvm::Module in the ExecutionEngine

The refactoring of ExecutionEngine dropped the usage of the irTransform function used to pass -O3 and other options to LLVM. As a consequence, the proper optimizations do not kick in in LLMV-land.

This CL makes use of the transform function and allows producing avx512 instructions, on an internal example, when using:
`mlir-cpu-runner -dump-object-file=1 -object-filename=foo.o` combined with `objdump -D foo.o`.

Assembly produced resembles:
```
    2b2e:       62 72 7d 48 18 04 0e    vbroadcastss (%rsi,%rcx,1),%zmm8
    2b35:       62 71 7c 48 28 ce       vmovaps %zmm6,%zmm9
    2b3b:       62 72 3d 48 a8 c9       vfmadd213ps %zmm1,%zmm8,%zmm9
    2b41:       62 f1 7c 48 28 cf       vmovaps %zmm7,%zmm1
    2b47:       62 f2 3d 48 a8 c8       vfmadd213ps %zmm0,%zmm8,%zmm1
    2b4d:       62 f2 7d 48 18 44 0e    vbroadcastss 0x4(%rsi,%rcx,1),%zmm0
    2b54:       01
    2b55:       62 71 7c 48 28 c6       vmovaps %zmm6,%zmm8
    2b5b:       62 72 7d 48 a8 c3       vfmadd213ps %zmm3,%zmm0,%zmm8
    2b61:       62 f1 7c 48 28 df       vmovaps %zmm7,%zmm3
    2b67:       62 f2 7d 48 a8 da       vfmadd213ps %zmm2,%zmm0,%zmm3
    2b6d:       62 f2 7d 48 18 44 0e    vbroadcastss 0x8(%rsi,%rcx,1),%zmm0
    2b74:       02
    2b75:       62 f2 7d 48 a8 f5       vfmadd213ps %zmm5,%zmm0,%zmm6
    2b7b:       62 f2 7d 48 a8 fc       vfmadd213ps %zmm4,%zmm0,%zmm7
```
etc.

Fixes tensorflow/mlir#120

PiperOrigin-RevId: 267281097

4 years agoUpdated StructAttr to use the struct name for StorageType and ReturnType.
Rob Suderman [Thu, 5 Sep 2019 00:24:04 +0000 (17:24 -0700)]
Updated StructAttr to use the struct name for StorageType and ReturnType.

PiperOrigin-RevId: 267266687

4 years agoRetain address space during MLIR > LLVM conversion.
MLIR Team [Wed, 4 Sep 2019 19:26:11 +0000 (12:26 -0700)]
Retain address space during MLIR > LLVM conversion.

PiperOrigin-RevId: 267206460

4 years agoMove LLVMIR dialect tests from test/LLVMIR to test/Dialect and test/Conversion
Alex Zinenko [Wed, 4 Sep 2019 15:37:39 +0000 (08:37 -0700)]
Move LLVMIR dialect tests from test/LLVMIR to test/Dialect and test/Conversion

This follows up on the recent restructuring that moved the dialects under
lib/Dialect and inter-dialect conversions to lib/Conversion. Originally, the
tests for both the LLVMIR dialect itself and the conversion from Standard to
LLVMIR dialect lived under test/LLVMIR.  This no longer reflects the code
structure.  Move the tests to either test/Dialect/LLVMIR or
test/Conversion/StandardToLLVM depending on the features they exercise.

PiperOrigin-RevId: 267159219

4 years agoMake isIsolatedAbove robuster to invalid IR
Jacques Pienaar [Wed, 4 Sep 2019 14:02:37 +0000 (07:02 -0700)]
Make isIsolatedAbove robuster to invalid IR

This function is only called from the verifier.

PiperOrigin-RevId: 267145495

4 years agopipeline-data-transfer: remove dead tag alloc's and improve test coverage for replace...
Uday Bondhugula [Wed, 4 Sep 2019 13:58:39 +0000 (06:58 -0700)]
pipeline-data-transfer: remove dead tag alloc's and improve test coverage for replaceMemRefUsesWith / pipeline-data-transfer

- address remaining comments from PR tensorflow/mlir#87 for better test coverage for
  pipeline-data-transfer/replaceAllMemRefUsesWith
- remove dead tag allocs the same way they are removed for the replaced buffers

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

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/106 from bondhugula:followup 9e868666d047e8d43e5f82f43e4093b838c710fa
PiperOrigin-RevId: 267144774

4 years agoMove Linalg dialect tests to test/Dialect/Linalg
Alex Zinenko [Wed, 4 Sep 2019 13:32:54 +0000 (06:32 -0700)]
Move Linalg dialect tests to test/Dialect/Linalg

This was missing from the commit that moved the Linalg dialect to lib/Dialect.

PiperOrigin-RevId: 267141176

4 years agoMake GPU kernel outlining inline constants.
Stephan Herhut [Wed, 4 Sep 2019 13:15:40 +0000 (06:15 -0700)]
Make GPU kernel outlining inline constants.

It is generally beneficial to pass less arguments to a kernel, so cloning constants
into the kernel is beneficial.

PiperOrigin-RevId: 267139084

4 years agoAdd support for array-typed constants.
MLIR Team [Wed, 4 Sep 2019 10:45:38 +0000 (03:45 -0700)]
Add support for array-typed constants.

PiperOrigin-RevId: 267121729

4 years agoUpdate the syntax of splat attribute in LLVM.md
Alex Zinenko [Wed, 4 Sep 2019 10:01:17 +0000 (03:01 -0700)]
Update the syntax of splat attribute in LLVM.md

The syntax for splat attributes changed, but was not updated in the description
of the LLVM dialect constant operations in LLVM.md.  Update the document to use
the correct syntax.  Also add a dialect roundtrip test for such attribute,
which was previously missing.

PiperOrigin-RevId: 267116305

4 years agoMention clang-format in the developer guide
Alex Zinenko [Wed, 4 Sep 2019 09:42:50 +0000 (02:42 -0700)]
Mention clang-format in the developer guide

PiperOrigin-RevId: 267114122

4 years agoProperly clone Linalg ops with regions
Nicolas Vasilache [Tue, 3 Sep 2019 22:27:49 +0000 (15:27 -0700)]
Properly clone Linalg ops with regions

This CL adds support for proper cloning of Linalg ops that have regions (i.e. the generic linalg op). This is used to properly implement tiling and fusion for such ops. Adequate tests are added.

PiperOrigin-RevId: 267027176

4 years agoUtility to normalize memrefs with non-identity layout maps
Uday Bondhugula [Tue, 3 Sep 2019 19:13:59 +0000 (12:13 -0700)]
Utility to normalize memrefs with non-identity layout maps

- introduce utility to convert memrefs with non-identity layout maps to
  ones with identity layout maps: convert the type and rewrite/remap all
  its uses

- add this utility to -simplify-affine-structures pass for testing
  purposes

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

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/104 from bondhugula:memref-normalize f2c914aa1890e8860326c9e33f9aa160b3d65e6d
PiperOrigin-RevId: 266985317

4 years agoAdd folding rule and dialect materialization hook for spv.constant
Lei Zhang [Tue, 3 Sep 2019 19:09:07 +0000 (12:09 -0700)]
Add folding rule and dialect materialization hook for spv.constant

This will allow us to use MLIR's folding infrastructure to deduplicate
SPIR-V constants.

This CL also changed isValidSPIRVType in SPIRVDialect to a static method.

PiperOrigin-RevId: 266984403

4 years agoFix affine data copy generation corner cases/bugs
Uday Bondhugula [Tue, 3 Sep 2019 18:52:39 +0000 (11:52 -0700)]
Fix affine data copy generation corner cases/bugs

- the [begin, end) range identified for copying could end in between the
  block, which makes hoisting invalid in some cases. Change the range
  identification to always end with end of block.

- add test case to exercise these (with fast mem capacity set to minimal so
  that single element memref buffers are generated at the innermost loop)

- the location of begin/end of the block range for data copying was
  being confused with the insert points for copy in and copy out code.
  In cases, where we choose to hoist transfers, these are separate.

- when copy loops are single iteration ones, promote their bodies at
  the end of the pass.

- change default fast mem space to 1 (setting it to zero made it
  generate DMA op's that won't verify in the default case - since the
  DMA ops have a check for src/dest memref spaces being different).

Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>
Co-Authored-By: Mehdi Amini <joker.eph@gmail.com>
Closes tensorflow/mlir#88

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/88 from bondhugula:datacopy 88697267c45e850c3ced87671e16e4a930c02a42
PiperOrigin-RevId: 266980911