Commit Graph

2512 Commits

Author SHA1 Message Date
Lei Zhang 9da6e90e1c Replace bitwiseCast with llvm::bit_cast
PiperOrigin-RevId: 258986485
2019-07-19 11:41:41 -07:00
Lei Zhang e239f9647e Suppress compiler warnings regarding unused variables
Not all ops have operands or results, so it ends up there may be no
use of wordIndex or the generated op's results.

PiperOrigin-RevId: 258984485
2019-07-19 11:41:34 -07:00
Lei Zhang 1331c84fe3 Wrap op (de)serialization methods in anonymous namespace
It's a known bug that older GCC is not happy with method specialization in
the enclosing (global) namespace:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480

This CL wraps the generated specialization methods in the anonymous namespace
to make sure the specialization is in the same namespace as the class.

PiperOrigin-RevId: 258983181
2019-07-19 11:41:27 -07:00
Jacques Pienaar c253c6eb2f Switch C++14 std::equal usage to for-loop.
Version of std::equal used required C++14, switching to for-loop for now. Just a direct change from std::equal to the equivalent using for loop.

PiperOrigin-RevId: 258970366
2019-07-19 11:41:20 -07:00
Alex Zinenko 6fe99662aa Move loop dialect tests into separate files - NFC
This was overlooked when moving out loop operations from Standard to a separate
dialect.

PiperOrigin-RevId: 258970115
2019-07-19 11:41:12 -07:00
Lei Zhang 89a10b73fb Add missing MLIRDialect dependency for MLIRDialect
Tests for the Broadcastable trait was added in a previous CL, which
makes MLIRDialect depend on MLIRDialect now.

PiperOrigin-RevId: 258967332
2019-07-19 11:41:06 -07:00
Mahesh Ravishankar 03c8303a12 Make SPIR-V spv.EntryPoint and spv.ExecutionMode consistent with SPIR-V spec
This CL changes the Op definition of spirv::EntryPointOp and
spirv::ExecutionModeOp to be consistent with the SPIR-V spec.
1) The EntryPointOp doesn't return a value
2) The ExecutionModeOp takes as argument, the SymbolRefAttr to refer
to the function, instead of the result of the EntryPointOp.

Following this, the spirv::EntryPointType is no longer necessary, and
is removed.

PiperOrigin-RevId: 258964027
2019-07-19 11:40:58 -07:00
Alex Zinenko 287d111023 Generalize implicit terminator into an OpTrait
Several groups of operations in different dialects (e.g. AffineForOp,
AffineIfOp; loop::ForOp, loop::IfOp) share the requirement for their regions to
contain 0 or 1 block, and for blocks to always have a specific terminator type.
Furthermore, this terminator may be omitted from the custom syntax.  Generalize
this behavior into OpTrait::SingleBlockImplicitTerminator, parameterized by the
terminator operation type.  This trait provides the verifier that checks the
presence of the terminator, and utility functions adding the terminator in case
of absence.

PiperOrigin-RevId: 258957180
2019-07-19 11:40:51 -07:00
Nicolas Vasilache 6204acacc7 Uniformize test name - NFC
PiperOrigin-RevId: 258956693
2019-07-19 11:40:43 -07:00
Nicolas Vasilache d2a872922f Refactor stripmineSink for AffineForOp - NFC
More moving less cloning.

PiperOrigin-RevId: 258947575
2019-07-19 11:40:37 -07:00
Nicolas Vasilache db4cd1c8dc Utility function to map a loop on a parametric grid of virtual processors
This CL introduces a simple loop utility function which rewrites the bounds and step of a loop so as to become mappable on a regular grid of processors whose identifiers are given by SSA values.

A corresponding unit test is added.

For example, using CUDA terminology, and assuming a 2-d grid with processorIds = [blockIdx.x, threadIdx.x] and numProcessors = [gridDim.x, blockDim.x], the loop:
```
   loop.for %i = %lb to %ub step %step {
     ...
   }
```
is rewritten into a version resembling the following pseudo-IR:
```
   loop.for %i = %lb + threadIdx.x + blockIdx.x * blockDim.x to %ub
      step %gridDim.x * blockDim.x {
     ...
   }
```

PiperOrigin-RevId: 258945942
2019-07-19 11:40:31 -07:00
Nicolas Vasilache 5bc344743c Uniformize the API for the mlir::tile functions on AffineForOp and loop::ForOp
This CL adapts the recently introduced parametric tiling to have an API matching the tiling
of AffineForOp. The transformation using stripmineSink is more general and produces  imperfectly nested loops.

Perfect nesting invariants of the tiled version are obtained by selectively applying hoisting of ops to isolate perfectly nested bands. Such hoisting may fail to produce a perfect loop nest in cases where ForOp transitively depend on enclosing induction variables. In such cases, the API provides a LogicalResult return but the SimpleParametricLoopTilingPass does not currently use this result.

A new unit test is added with a triangular loop for which the perfect nesting property does not hold. For this example, the old behavior was to produce IR that did not verify (some use was not dominated by its def).

PiperOrigin-RevId: 258928309
2019-07-19 11:40:25 -07:00
River Riddle 28057ff3da Add support for providing a legality callback for dynamic legality in DialectConversion.
This allows for providing specific handling for dynamically legal operations/dialects without overriding the general 'isDynamicallyLegal' hook. This also means that a derived ConversionTarget class need not always be defined when some operations are dynamically legal.

Example usage:

ConversionTarget target(...);
target.addDynamicallyLegalOp<ReturnOp>([](ReturnOp op) {
  return ...
};
target.addDynamicallyLegalDialect<StandardOpsDialect>([](Operation *op) {
  return ...
};

PiperOrigin-RevId: 258884753
2019-07-19 11:40:19 -07:00
Lei Zhang 36a26e0033 [spirv] group methods better and improve comments
This CL groups (de)serialization methods logically and improves comments
at various places. It also sorted method implementations to follow the
order of their declarations. There is NFC.

PiperOrigin-RevId: 258843490
2019-07-19 11:40:12 -07:00
Lei Zhang 9291868960 Place generated StandardOps to SPIR-V patterns in anonymous namespace
This avoids polluting the mlir namespace.

PiperOrigin-RevId: 258826497
2019-07-19 11:40:06 -07:00
River Riddle 8b447b6cad NFC: Expose a ConversionPatternRewriter for use with ConversionPatterns.
This specific PatternRewriter will allow for exposing hooks in the future that are only useful for the conversion framework, e.g. type conversions.

PiperOrigin-RevId: 258818122
2019-07-19 11:40:00 -07:00
Feng Liu 701266c47a Add an "is_signed" attribute to the quant_ConstFakeQuant op
Some TensorFlow simulated quantize ops such as QuantizeAndDequantizeV2Op have
attribute for the sign of the quantization, so quant_ConstFakeQuant should be
able to represent it with the new attribute is added.

The method for converting these attributes to an QuantizedType is updated to
handle this new argument.

PiperOrigin-RevId: 258810290
2019-07-19 11:39:54 -07:00
Mehdi Amini 90b5a381ce Minor cleanup to LangRef, MLIR stands for "Multi-Level IR"
PiperOrigin-RevId: 258798577
2019-07-19 11:39:47 -07:00
Lei Zhang e9c42e3552 Fix script relative path after moving SPIR-V dialect
PiperOrigin-RevId: 258786729
2019-07-19 11:39:41 -07:00
Lei Zhang 9f498f921b Print boolean values in ElementsAttr as "true"/"false"
We already parse boolean "true"/"false" as ElementsAttr elements.
This CL makes it round-trippable that we are printing the same way.

PiperOrigin-RevId: 258784962
2019-07-19 11:39:35 -07:00
Jing Pu e558c040aa Add UnitAttr in OpBase.td.
Note that UnitAttr cannot be used for op definition yet.

PiperOrigin-RevId: 258693338
2019-07-19 11:39:29 -07:00
Mahesh Ravishankar c6cfebf1af Automatically generate (de)serialization methods for SPIR-V ops
For ops in SPIR-V dialect that are a direct mirror of SPIR-V
operations, the serialization/deserialization methods can be
automatically generated from the Op specification. To enable this an
'autogenSerialization' field is added to SPV_Ops. When set to
non-zero, this will enable the automatic (de)serialization function
generation

Also adding tests that verify the spv.Load, spv.Store and spv.Variable
ops are serialized and deserialized correctly. To fully support these
tests also add serialization and deserialization of float types and
spv.ptr types

PiperOrigin-RevId: 258684764
2019-07-19 11:39:22 -07:00
Geoffrey Martin-Noble ec66bc57a8 Add helper to get flattened tuple types
The API on TupleType::getFlattenedTypes follows our normal conventions by accepting an output parameter, but requires callers to allocate their own storage and lends itself to use in an imperative style. This makes it difficult to use in tablegen. The current solution is to define a lambda that is immediately called, but it's cleaner to extract that into a helper.

PiperOrigin-RevId: 258672046
2019-07-19 11:39:16 -07:00
Smit Hinsu 68c409238e Simplify broadcastable traits
We only verify broadcastable trait verifier and don't care about mutations so removed all CHECK statements and FileCheck invocation.

PiperOrigin-RevId: 258662882
2019-07-19 11:39:10 -07:00
River Riddle d097cc6119 Add support for parsing/printing the trailing type of a dialect attribute.
This cl standardizes the printing of the type of dialect attributes to work the same as other attribute kinds. The type of dialect attributes will trail the dialect specific portion:

`#` dialect-namespace `<` attr-data `>` `:` type

The attribute parsing hooks on Dialect have been updated to take an optionally null expected type for the attribute. This matches the respective parseAttribute hooks in the OpAsmParser.

PiperOrigin-RevId: 258661298
2019-07-19 11:39:04 -07:00
Mehdi Amini 775daf7c1f Update Contributing.md doc to refer to the developer guide
This intends to reduce duplication and ensure that new informations added
to the developer guide (like the recent testing good practice) are not
missed by new contributors.

PiperOrigin-RevId: 258650672
2019-07-19 11:38:57 -07:00
Smit Hinsu cce2f4c4ed Relax Broadcastable trait to only reject instances that are statically incompatible
Currently, Broadcastable trait also rejects instances when the op result has shape other than what can be statically inferred based on the operand shapes even if the result shape is compatible with the inferred broadcasted shape.

For example,
(tensor<3x2xi32>, tensor<*xi32>) -> tensor<4x3x2xi32>
(tensor<2xi32>, tensor<2xi32>) -> tensor<*xi32>

PiperOrigin-RevId: 258647493
2019-07-19 11:38:51 -07:00
River Riddle 9e3c2650d2 Refactor the conversion of block argument types in DialectConversion.
This cl begins a large refactoring over how signature types are converted in the DialectConversion infrastructure. The signatures of blocks are now converted on-demand when an operation held by that block is being converted. This allows for handling the case where a region is created as part of a pattern, something that wasn't possible previously.

This cl also generalizes the region signature conversion used by FuncOp to work on any region of any operation. This generalization allows for removing the 'apply*Conversion' functions that were specific to FuncOp/ModuleOp. The implementation currently uses a new hook on TypeConverter, 'convertRegionSignature', but this should ideally be removed in favor of using Patterns. That depends on adding support to the PatternRewriter used by ConversionPattern to allow applying signature conversions to regions, which should be coming in a followup.

PiperOrigin-RevId: 258645733
2019-07-19 11:38:45 -07:00
Smit Hinsu ee21bb9944 Add tests for broadcastable trait
PiperOrigin-RevId: 258637509
2019-07-19 11:38:38 -07:00
River Riddle d81e2376f7 Add an initial TestingGuide document to describe testing in MLIR.
As the number of contributors begins to scale, and the number of tests rise, it is important to detail the testing strategy in MLIR and best practices for writing those tests.

PiperOrigin-RevId: 258612585
2019-07-19 11:38:31 -07:00
River Riddle 491ef84dc4 Add support for explicitly marking dialects and operations as illegal.
This explicit tag is useful is several ways:
*) This simplifies how to mark sub sections of a dialect as explicitly unsupported, e.g. my target supports all operations in the foo dialect except for these select few. This is useful for partial lowerings between dialects.
*) Partial conversions will now verify that operations that were explicitly marked as illegal must be converted. This provides some guarantee that the operations that need to be lowered by a specific pass will be.

PiperOrigin-RevId: 258582879
2019-07-19 11:38:25 -07:00
River Riddle a4cbe4ebe1 Verify that ReturnOp only appears within the region of a FuncOp.
The invariants of ReturnOp are directly tied to FuncOp, making ReturnOp invalid in any other context.

PiperOrigin-RevId: 258421200
2019-07-16 13:45:54 -07:00
Nicolas Vasilache 0002e2964d Move affine.for and affine.if to ODS
As the move to ODS is made, body and region names across affine and loop dialects are uniformized.

PiperOrigin-RevId: 258416590
2019-07-16 13:45:47 -07:00
River Riddle 2b9855b5b4 Refactor DialectConversion to support different conversion modes.
Users generally want several different modes of conversion. This cl refactors DialectConversion to provide two:
* Partial (applyPartialConversion)
  - This mode allows for illegal operations to exist in the IR, and does not fail if an operation fails to be legalized.

* Full (applyFullConversion)
  - This mode fails if any operation is not properly legalized to the conversion target. This allows for ensuring that the IR after a conversion only contains operations legal for the target.

PiperOrigin-RevId: 258412243
2019-07-16 13:45:41 -07:00
Jacques Pienaar ffc0217bc7 Add a TypeIsPred.
Mostly one would use the type specification directly on the operand, but for
cases where the type of the operand depends on other operand types, `TypeIs`
attribute can be used to construct verification methods.

PiperOrigin-RevId: 258411758
2019-07-16 13:45:35 -07:00
Feng Liu a6d2223584 Support signed and unsigned quantization types
This patch added a new argument to the fakeQuantAttrsToType utility method, so
it can be used to convert min/max to quantized type with different signed
storage types.

PiperOrigin-RevId: 258382538
2019-07-16 13:45:29 -07:00
Alex Zinenko 0ede23010f Fix build by making LoopOps depend on StandardOps
LoopOps needs the definition ConstantIndexOp in the verifier of loop::ForOp.

PiperOrigin-RevId: 258355329
2019-07-16 13:45:22 -07:00
Stephan Herhut 6760ea5338 Move shared cpu runner library to Support/JitRunner.
PiperOrigin-RevId: 258347825
2019-07-16 13:45:16 -07:00
Lei Zhang d36dd94c75 NFC: Move SPIR-V dialect to Dialect/ subdirectory
PiperOrigin-RevId: 258345603
2019-07-16 13:45:09 -07:00
Lei Zhang 765b77cc70 Better support for attribute wrapper classes when getting def name
Unless we explicitly name a template instantiation in .td file, its def
name will be "anonymous_<number>". We typically give base-level Attr
template instantiation a name by writing `def AnAttr : Attr<...>`. But
when `AnAttr` is further wrapped in classes like OptionalAttr, the name
is lost unless explicitly def'ed again. These implicit-named template
instantiation is fairly common when writing op definitions. Those wrapper
classes are just essentially attaching more information to the attribute.
Without a proper way to trace back to the original attribute def name
can cause problems for consumers wanting to handle attributes according
to their types.

Previously we handled OptionalAttr and DefaultValuedAttr specifically,
but Confined was not supported. And they can compose together to have
Confined<OptionalAttr<...>, [...]>. So this CL moves the baseAttr field
to main Attr class (like isOptional) and set it only on the innermost
wrapper class.

PiperOrigin-RevId: 258341646
2019-07-16 13:45:03 -07:00
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