Commit Graph

2172 Commits

Author SHA1 Message Date
Nicolas Vasilache e78ea03b24 Replace linalg.for by loop.for
With the introduction of the Loop dialect, uses of the `linalg.for` operation can now be subsumed 1-to-1 by `loop.for`.
This CL performs the replacement and tests are updated accordingly.

PiperOrigin-RevId: 258322565
2019-07-16 13:44:57 -07:00
Alex Zinenko dec1942cdf Forward-declare LogicalResult as struct rather than class
Windows builds are broken by a class/struct mismatch between a
forward-declaration of LogicalResult and its definition.

PiperOrigin-RevId: 258320420
2019-07-16 13:44:51 -07:00
River Riddle 2087bf6386 Remove lowerAffineConstructs and lowerControlFlow in favor of providing patterns.
These methods don't compose well with the rest of conversion framework, and create artificial breaks in conversion. Replace these methods with two(populateAffineToStdConversionPatterns and populateLoopToStdConversionPatterns respectively) that populate a list of patterns to perform the same behavior.

PiperOrigin-RevId: 258219277
2019-07-16 13:44:45 -07:00
River Riddle e7a2ef21f9 Update 'applyPatternsGreedily' to work on the regions of any operations.
'applyPatternsGreedily' is a useful utility outside of just function regions.

PiperOrigin-RevId: 258182937
2019-07-16 13:44:39 -07:00
River Riddle 7d1e1e6721 Refactor the traversal of operations to Convert in DialectConversion.
This cl changes the way that operations/blocks to convert are collected/traversed so that parent region operations can be legalized before their bodies. Most RewritePatterns for region operations assume that the entry arguments to each region are yet to be converted. Given that the bodies are currently converted first, this makes it difficult to fit these patterns into the same run as one converting types.

The operations/blocks to convert are now collected before any legalization has run, which simplifies the conversion logic itself, as legalization may insert new operations, move blocks, etc.

PiperOrigin-RevId: 258170158
2019-07-16 13:44:33 -07:00
Andy Davis d2f1ed5137 Fix opt build (unused variable in Linalg).
PiperOrigin-RevId: 258168108
2019-07-16 13:44:27 -07:00
Alex Zinenko d52b6c94e1 Linalg Utils: use Doxygen comments where appropriate
PiperOrigin-RevId: 258160982
2019-07-16 13:44:21 -07:00
Alex Zinenko d2246182f0 Extend linalg transformations to allow value operands that are not views
This CL extends the linalg ops that can be tiled and fused to operations that take either views, scalar or vector operands.

PiperOrigin-RevId: 258159734
2019-07-16 13:44:15 -07:00
River Riddle 40715789f8 Refactor LowerAffine to use OpRewritePattern instead of ConversionPattern.
ConversionPattern should ideally only be used when the types of the operands are changing, which in this case they aren't. Using OpRewritePattern also lends to much simpler code.

PiperOrigin-RevId: 258158474
2019-07-16 13:44:09 -07:00
Alex Zinenko 5f01902ac1 LLVMDialect: still depend on standard types.
The dependecy on standard type is mandated by attribute verifiers on some
operations (e.g., llvm.constant) that use values of those types.

PiperOrigin-RevId: 258153134
2019-07-16 13:44:03 -07:00
MLIR Team 69457bc971 Automated rollback of changelist 258149291.
PiperOrigin-RevId: 258151618
2019-07-16 13:43:57 -07:00
Nicolas Vasilache f743f5bf32 Start moving AffineOps to ODS
This CL starts with the AffineTerminatorOp to ODS.

PiperOrigin-RevId: 258151579
2019-07-16 13:43:50 -07:00
Alex Zinenko fc044e8929 Introduce loop coalescing utility and a simple pass
Multiple (perfectly) nested loops with independent bounds can be combined into
a single loop and than subdivided into blocks of arbitrary size for load
balancing or more efficient parallelism exploitation.  However, MLIR wants to
preserve the multi-dimensional multi-loop structure at higher levels of
abstraction. Introduce a transformation that coalesces nested loops with
independent bounds so that they can be further subdivided by tiling.

PiperOrigin-RevId: 258151016
2019-07-16 13:43:44 -07:00
Nicolas Vasilache 4de019901b Extend linalg transformations to allow value operands that are not views
This CL extends the linalg ops that can be tiled and fused to operations that take either views, scalar or vector operands.

PiperOrigin-RevId: 258149291
2019-07-16 13:43:38 -07:00
Alex Zinenko ec82e1c907 Decouple LLVM dialect from Standard dialect
Due to the absence of ODS support for enum attributes, the implementation of
the LLVM dialect `icmp` operation was reusing the comparison predicate from the
Standard dialect, creating an avoidable library dependency.  With ODS support
and ICmpPredicate attribute recently introduced, the dependency is no longer
justified.  Update the Standard to LLVM convresion to also convert the
CmpIPredicate into LLVM::ICmpPredicate and remove the unnecessary includes.

Note that the MLIRLLVMIR library did not explicitly depend on MLIRStandardOps,
requiring dependees of MLIRLLVMIR to also depend on MLIRStandardOps, which
should no longer be the case.

PiperOrigin-RevId: 258148456
2019-07-16 13:43:31 -07:00
Alex Zinenko c3d166c532 LLVM Dialect: define ICmpPredicate in ODS
Use the recently introduced enum-gen functionality to define the predicate
attribute of the ICmp LLVM dialect operation directly in ODS.  This removes the
need for manually-coded string-to-integer conversion functions and contributes
to the overall homogenization of the operation definitions.

PiperOrigin-RevId: 258143923
2019-07-16 13:43:25 -07:00
Nicolas Vasilache cca53e8527 Extract std.for std.if and std.terminator in their own dialect
These ops should not belong to the std dialect.
This CL extracts them in their own dialect and updates the corresponding conversions and tests.

PiperOrigin-RevId: 258123853
2019-07-16 13:43:18 -07:00
River Riddle a764c19d17 Fix a bug in DialectConversion when using RewritePattern.
When using a RewritePattern and replacing an operation with an existing value, that value may have already been replaced by something else. This cl ensures that only the final value is used when applying rewrites.

PiperOrigin-RevId: 258058488
2019-07-16 13:43:12 -07:00
Masaki Kozuki 8819b722ca Fix typos
Closes tensorflow/mlir#45

PiperOrigin-RevId: 257948893
2019-07-13 05:56:05 -07:00
River Riddle e50a8bd19c NFC: Add header blocks to DialectConversion.h to improve readability.
PiperOrigin-RevId: 257903383
2019-07-13 05:55:50 -07:00
River Riddle fdc2b3f75f NFC: Don't print the location of a diagnostic if it is unknown.
Printing 'loc(unknown)' just clutters the output with unhelpful information.

PiperOrigin-RevId: 257883717
2019-07-12 17:43:08 -07:00
Mahesh Ravishankar 9af156757d Add serialization and deserialization of FuncOps. To support this the
following SPIRV Instructions serializaiton/deserialization are added
as well

OpFunction
OpFunctionParameter
OpFunctionEnd
OpReturn

PiperOrigin-RevId: 257869806
2019-07-12 17:43:03 -07:00
Lei Zhang 63bc37c9c0 [spirv] Various small code improvements
* Changed SPIR-V types to all use unsigned for member type count and index
* Used the same method name for getting element type and count
* Improved spv.CompositeExtract verification a bit

PiperOrigin-RevId: 257862580
2019-07-12 17:42:57 -07:00
River Riddle 2566a72a21 Update the PatternRewriter constructor to take a context instead of a region.
This will allow for cleanly using a rewriter for multiple different regions.

PiperOrigin-RevId: 257845371
2019-07-12 17:42:52 -07:00
River Riddle 0e3260bc73 Change the IR printing pass instrumentation to ignore the verifier passes on non-failure.
The verifier passes are NO-OP and are only useful to print after in the case of failure. This removes a lot of unnecessary clutter when printing after/before all passes.

PiperOrigin-RevId: 257836310
2019-07-12 17:42:46 -07:00
River Riddle 8e349a48b6 Remove the 'region' field from OpBuilder.
This field wasn't updated as the insertion point changed, making it potentially dangerous given the multi-level of MLIR(e.g. 'createBlock' would always insert the new block in 'region'). This also allows for building an OpBuilder with just a context.

PiperOrigin-RevId: 257829135
2019-07-12 17:42:41 -07:00
Jing Pu 8956838930 Hide some public API of QuantizedType inherited from Type.
It is for preventing subtle bugs when writing predicates with wrong APIs. For example,

// BAD example for checking a quant type has an i8 or i16 storage type.
auto qtype = type.dyn_cast<mlir::quant::UniformQuantizedType>()
if (qtype.isSigned() && (qtype.isInteger(8) || qtype.isInteger(16)))

PiperOrigin-RevId: 257823263
2019-07-12 17:42:35 -07:00
Lei Zhang bd484f17a0 [spirv] Add script to auto-generate SPIR-V op template from spec
SPIR-V has a JSON grammar file that defines the syntax of SPIR-V
instructions. However, its lacks fine-grained constraints on
instruction operands; those information is only available as
natural language sentences in the SPIR-V spec, which also contains
the detailed documentation for each SPIR-V instruction.

This CL pulls information from both the JSON grammar and HTML
spec. It right now uses the former to deduce the arguments and
results (with coarse-grained constraints) and the latter for
documentation. In the future we can add the functionality to
match certain natural language sentences for more fine-grained
constraints, but right now the developer is expected to update
the generated op definition. This should serve as a nice
bootstrap step to save efforts.

PiperOrigin-RevId: 257821205
2019-07-12 17:42:30 -07:00
River Riddle 60a2983779 Fix a bug in the canonicalizer when replacing constants via patterns.
The GreedyPatternRewriteDriver currently does not notify the OperationFolder when constants are removed as part of a pattern match. This materializes in a nasty bug where a different operation may be allocated to the same address. This causes an assertion in the OperationFolder when it gets notified of the new operations removal.

PiperOrigin-RevId: 257817627
2019-07-12 17:42:24 -07:00
Nicolas Vasilache cab671d166 Lower affine control flow to std control flow to LLVM dialect
This CL splits the lowering of affine to LLVM into 2 parts:
1. affine -> std
2. std -> LLVM

The conversions mostly consists of splitting concerns between the affine and non-affine worlds from existing conversions.
Short-circuiting of affine `if` conditions was never tested or exercised and is removed in the process, it can be reintroduced later if needed.

LoopParametricTiling.cpp is updated to reflect the newly added ForOp::build.

PiperOrigin-RevId: 257794436
2019-07-12 08:44:28 -07:00
Denis Khalikov 884b94e038 [spirv] Add CompositeExtractOp operation.
CompositeExtractOp allows to extract a part of a composite object.

Closes tensorflow/mlir#44

PiperOrigin-RevId: 257790731
2019-07-12 08:44:21 -07:00
Alex Zinenko 2178467dca LoopsToGPU: use PassRegistration with constructor
PassRegistration with an optional constructor was introduced after the
LoopsToGPUPass, which resorted to deriving one pass from another as a means of
accepting options supplied as command-line arguments. Use PassRegistration with
constructor instead of defining a derived pass for LoopsToGPU.  Also rename the
pass to better reflect its current nature.

PiperOrigin-RevId: 257786923
2019-07-12 08:44:14 -07:00
Alex Zinenko f20f347fdb LinalgTilingPass: use PassRegistration with a pass constructor
Linalg tiling pass was introduced before PassRegistration with an optional pass
constructor.  It resorted to deriving a helper class from the origial pass
class in order to provide a default constructor with values obtained from
command line flags.  Use PassRegistration with the optional pass constructor
instead, which avoids declaring an additional class.

PiperOrigin-RevId: 257786876
2019-07-12 08:44:08 -07:00
Smit Hinsu e50da9efe8 NFC: Remove redundant call to registerPassManagerCLOptions from MLIR tutorial
main already calls registerPassManagerCLOptions.

TESTED = not (NFC)
PiperOrigin-RevId: 257722013
2019-07-12 08:44:02 -07:00
River Riddle 136ccd4948 Update the dialect attribute verifiers related to functions.
Remove the Function specific attribute verifier in favor of the general operation verifier. This also generalizes the function argument verifier to allow use for an argument attached to any region of any operation.

PiperOrigin-RevId: 257689962
2019-07-12 08:43:55 -07:00
Mahesh Ravishankar f93e95ed5f Add support for serialization/deserialization of OpTypeVoid and
OpTypeFunction

PiperOrigin-RevId: 257684235
2019-07-12 08:43:48 -07:00
River Riddle 9dbef0bf96 Rename FunctionAttr to SymbolRefAttr.
This allows for the attribute to hold symbolic references to other operations than FuncOp. This also allows for removing the dependence on FuncOp from the base Builder.

PiperOrigin-RevId: 257650017
2019-07-12 08:43:42 -07:00
Alex Zinenko 4dfe6d457b FuncOp::eraseBody: drop all references before erasing blocks
Operations in a block can use a value defined in a dominating block.  When a
block, and therefore all its operations, is deleted, the operations are not
allowed to have any remaining uses.  Drop all uses of values in all blocks
before deleting them in FuncOp::eraseBody to avoid deleting an operation before
deleting the users of its results.

PiperOrigin-RevId: 257628002
2019-07-12 08:43:35 -07:00
Alex Zinenko 65da460c79 affine.load/store: check for the right number of operands
Affine load and store operations take a variadic number of arguments, most of
which are interpreted as subscripts for the multi-dimensional memref they
access.  Add a verifier check that ensures the number of operands is equal to
the number affine remapping inputs if present and to the rank of the acessed
memref otherwise.  Although it is impossible to obtain such operations by
parsing the custom syntax, it is possible to construct them using the generic
syntax or programmatically.

PiperOrigin-RevId: 257605902
2019-07-12 08:43:29 -07:00
Nicolas Vasilache 4bbfb749bb Propagate linalg op attributes in transformations
Also fix the tile_conv test.

PiperOrigin-RevId: 257602321
2019-07-12 08:43:22 -07:00
Alex Zinenko 7ef559e0f2 mcuMemHostRegister: take into account sizeof(float)
cuMemHostRegister expects the size of registered memory in bytes whereas the
memref descriptor in memref_t contains the number of elements.  Get the actual
size in bytes instead.

PiperOrigin-RevId: 257589116
2019-07-12 08:43:15 -07:00
Mahesh Ravishankar 801efec9e6 Update the gen_spirv_dialect.py script to add opcodes from the SPIR-V
JSON spec into the SPIRBase.td file. This is done incrementally to
only import those opcodes that are needed, through use of the script
define_opcode.sh added.

PiperOrigin-RevId: 257517343
2019-07-12 08:43:09 -07:00
River Riddle 6da343ecfc NFC: Replace Module::getNamedFunction with lookupSymbol<FuncOp>.
This allows for removing the last direct reference to FuncOp from ModuleOp.

PiperOrigin-RevId: 257498296
2019-07-12 08:43:03 -07:00
River Riddle 122cab6770 Refactor the parsing/printing of the top-level module.
This changes the top-level module parser to handle the case where the top-level module is defined with the module operation syntax, i.e:
  module ... {
  }

The printer is also updated to always print the top-level module in this form. This allows for cleanly round-tripping the location and attributes of the top-level module.

PiperOrigin-RevId: 257492069
2019-07-12 08:42:56 -07:00
Nicolas Vasilache cb3f0d6f9b Fix BufferSizeOp type lowering to LLVM.
This fixes a bug where the result type was incorrect when lowering to LLVM.

PiperOrigin-RevId: 257449384
2019-07-12 08:42:49 -07:00
Alex Zinenko 7b530a88d5 PassRegistation: use overloads instead of a default argument
Windows build is not happy trying to convert a lambda into a constant reference
to a function in default arguments of the PassRegistration constructor.  Define
two overloaded constructors instead and construct the lambda as a variable in
the constructor body.

PiperOrigin-RevId: 257448633
2019-07-12 08:42:42 -07:00
River Riddle 1b247a1247 Drop the trailing newline from the FuncOp syntax.
The ModulePrinter prints the newline now for children of the top-level module. This also fixes the location printing for functions as the location used to be printed on a different line.

PiperOrigin-RevId: 257447633
2019-07-12 08:42:35 -07:00
Alex Zinenko 054e25c079 EDSC: use affine.load/store instead of std.load/store
Standard load and store operations are evolving to be separated from the Affine
constructs.  Special affine.load/store have been introduced to uphold the
restrictions of the Affine control flow constructs on their operands.
EDSC-produced loads and stores were originally intended to uphold those
restrictions as well so they should use affine.load/store instead of
std.load/store.

PiperOrigin-RevId: 257443307
2019-07-12 08:42:28 -07:00
River Riddle b3e28fca53 NFC: Remove Function::getModule.
There is already a more general 'getParentOfType' method, and 'getModule' is likely to be misused as functions get placed within different regions than ModuleOp.

PiperOrigin-RevId: 257442243
2019-07-12 08:42:21 -07:00
Nicolas Vasilache 68edb3ba75 Delete dead code
AffineIfOp::build is not tested or exercised anywhere. It also perpetuates a questionable choice of encoding an optional region as an empty region which we would like to change in the future.
PiperOrigin-RevId: 257439832
2019-07-12 08:42:13 -07:00