Commit Graph

1853 Commits

Author SHA1 Message Date
River Riddle 0840ecfd46 NFC: Rename FunctionParser to OperationParser. There is nothing specific to functions about this parser and provides general parser support for operations, and regions of operations.
PiperOrigin-RevId: 251749622
2019-06-09 16:20:24 -07:00
MLIR Team 952196f374 Minor change to Linalg Tablegen file to not include OpBase.td if already included by another include
PiperOrigin-RevId: 251725376
2019-06-09 16:20:13 -07:00
River Riddle e9d212c6aa NFC: Cleanup the definitions of OpAsmParser and CustomOpAsmParser by adding comments, grouping similar functionality, and adding header blocks.
PiperOrigin-RevId: 251723883
2019-06-09 16:20:02 -07:00
River Riddle 0560f153b8 Add utility 'create' methods to OperationFolder that will create an operation with a given OpBuilder and automatically try to fold it, similarly to OpBuilder::createOrFold. The difference here is that these methods enable folding to constants in addition to existing values. This functionality is then used to replace linalg::FunctionConstants.
PiperOrigin-RevId: 251716247
2019-06-09 16:19:51 -07:00
River Riddle d23435d554 NFC: Rename FunctionParser::builder to opBuilder. This allows for removing the clang specific pragmas for ignoring field shadowing warnings.
PiperOrigin-RevId: 251712823
2019-06-09 16:19:40 -07:00
River Riddle cc06860394 Fix a warning for missing parentheses around '||' inside of an assert.
PiperOrigin-RevId: 251712106
2019-06-09 16:19:28 -07:00
River Riddle d956010027 NFC: Cleanup FunctionParser by removing dead methods, adding header blocks, and grouping related pieces of functionality.
PiperOrigin-RevId: 251688578
2019-06-09 16:19:17 -07:00
MLIR Team bb475a27e2 Fix a typo in error message.
PiperOrigin-RevId: 251681475
2019-06-09 16:19:06 -07:00
River Riddle 6f5f5a9178 Add new 'createOrFold' methods to FuncBuilder to immediately try to fold an operation after creating it. This can be used to remove operations that are likely to be trivially folded later. Note, these functions only fold operations if all of the folded results are existing values.
PiperOrigin-RevId: 251674299
2019-06-09 16:18:55 -07:00
River Riddle 9fc00cf840 Always remap results when replacing an operation. This prevents a crash when lowering identity(passthrough) operations to the same resultant type as the original operation.
PiperOrigin-RevId: 251665492
2019-06-09 16:18:44 -07:00
River Riddle 0d2492eb2e When cleaning up after a failed legalization pattern, make sure to remove any newly created value mappings.
PiperOrigin-RevId: 251658984
2019-06-09 16:18:32 -07:00
River Riddle 08d407f243 Add a few utility overloads for OpAsmParser methods:
* Add a getCurrentLocation that returns the location directly.
* Add parseOperandList/parseTrailingOperandList overloads without the required operand count.

PiperOrigin-RevId: 251585488
2019-06-09 16:18:21 -07:00
Jacques Pienaar 7438dcb71f ODG: Always deference operand/result when using named arg/result.
Considered adding more placeholders to designate types in the replacement pattern, but convinced for now sticking to simpler approach. This should at least enable specifying constraints across operands/results/attributes and we can start getting rid of the special cases.

PiperOrigin-RevId: 251564893
2019-06-09 16:18:10 -07:00
River Riddle f1b848e470 NFC: Rename FuncBuilder to OpBuilder and refactor to take a top level region instead of a function.
PiperOrigin-RevId: 251563898
2019-06-09 16:17:59 -07:00
River Riddle f59f64e838 Add support to AffineApplyOp::fold for folding dim and symbol expression results.
PiperOrigin-RevId: 251512700
2019-06-09 16:17:46 -07:00
Lei Zhang 23cf3b39e0 [spirv] Basic validity of SPV_ModuleOp
This CL adds SPV_ModuleEndOp for terminating the only block inside a
SPV_ModuleOp's only region. Verification now enforces a spv.module only
contains func or spv.* ops and no external or nested functions are
present. Because of the structural requirement of a block, spv.Return
is also added in this CL.

PiperOrigin-RevId: 251510706
2019-06-09 16:17:34 -07:00
River Riddle 11d18a4a5e Add a utility function to Op that allows for checking if an operation has a specific trait.
PiperOrigin-RevId: 251489498
2019-06-09 16:17:23 -07:00
River Riddle 9b4a02c1e9 NFC: Rename FoldHelper to OperationFolder and split a large function in two.
PiperOrigin-RevId: 251485843
2019-06-09 16:17:11 -07:00
Ben Vanik 9fc4193eea Adding additional dialect parsing utilities, conversion wrappers, and traversal helpers.
- added a typed walk to Block (matching the equivalent on Function)
- added token parsers (incl optional variants) for : and (
- added applyConversionPatterns that takes a list of functions to apply patterns to

PiperOrigin-RevId: 251481608
2019-06-09 16:16:59 -07:00
River Riddle ecfd5f8cad Make it explicit that the IR printing instrumentation should not be used when multi-threading is enabled.
PiperOrigin-RevId: 251478399
2019-06-09 16:16:47 -07:00
River Riddle 70db033190 Add support to FuncOp for managing argument attributes. The syntax for argument attributes is the same as Function:
func @foo(i1 {dialect.attr: 10 : i64})

  func @foo(%arg0: i1 {dialect.attr: 10 : i64}) {
    return
  }

PiperOrigin-RevId: 251473338
2019-06-09 16:16:36 -07:00
Lei Zhang 3f517af9ad [ODG] Add iterators for results in Operator
PiperOrigin-RevId: 251417085
2019-06-09 16:16:24 -07:00
Stephan Herhut f7b9ac8245 Align NVVM operation names with names from GPU dialect.
Currently, we use different names for block and grid dimensions in the GPU vs. NVVM dialect, which is confusing. With this change, the NVVM names match the ones from the GPU dialect. The NVVM intrinsics use different names anyway, so it does not add new confusion.

PiperOrigin-RevId: 251389281
2019-06-09 16:16:12 -07:00
River Riddle 42c19e8272 Add a utility function to OperationName for extracting the dialect name.
PiperOrigin-RevId: 251333376
2019-06-03 19:27:35 -07:00
Lei Zhang 2cef9f07d2 [ODS] Add support for TypeArrayAttr
PiperOrigin-RevId: 251314203
2019-06-03 19:27:27 -07:00
Geoffrey Martin-Noble e2032c7d4e Replace comments referring to "vector or tensor" with "shaped" where appropriate
PiperOrigin-RevId: 251306752
2019-06-03 19:27:19 -07:00
Geoffrey Martin-Noble 93d522c696 Make MemRefOf tablegen type subclass ShapedContainerType
Possible now because MemRef subclasses ShapedType

PiperOrigin-RevId: 251292951
2019-06-03 19:27:10 -07:00
River Riddle 95eaca3e0f Refactor the dialect conversion framework to support multi-level conversions. Multi-level conversions are those that require multiple patterns to be applied before an operation is completely legalized. This essentially means that conversion patterns do not have to directly generate legal operations, and may be chained together to produce legal code.
To accomplish this, moving forward users will need to provide a legalization target that defines what operations are legal for the conversion. A target can mark an operation as legal by providing a specific legalization action. The initial actions are:
* Legal
  - This action signals that every instance of the given operation is legal,
    i.e. any combination of attributes, operands, types, etc. is valid.
* Dynamic
  - This action signals that only some instances of a given operation are legal. This
    allows for defining fine-tune constraints, like say std.add is only legal when
    operating on 32-bit integers.

An example target is shown below:
struct MyTarget : public ConversionTarget {
  MyTarget(MLIRContext &ctx) : ConversionTarget(ctx) {
    // All operations in the LLVM dialect are legal.
    addLegalDialect<LLVMDialect>();

    // std.constant op is always legal on this target.
    addLegalOp<ConstantOp>();

    // std.return op has dynamic legality constraints.
    addDynamicallyLegalOp<ReturnOp>();
  }

  /// Implement the custom legalization handler to handle
  /// std.return.
  bool isLegal(Operation *op) override {
    // Process the dynamic handling for a std.return op (and any others that were
    // marked "dynamic").
    ...
  }
};

PiperOrigin-RevId: 251289374
2019-06-03 19:27:02 -07:00
Lei Zhang 11fcecf15d Support type casting Type to itself
PiperOrigin-RevId: 251287045
2019-06-03 19:26:54 -07:00
River Riddle 62cbdd51fa Start defining a new operation 'FuncOp' that replicates all of the functionality of 'Function', but with an operation. The pretty syntax for the operation is exactly the same as that of Function. This operation is currently builtin, but should hopefully be moved to a different dialect when it has been completely decoupled from IR/. This is the first patch in a large series that refactors Functions to be represented as operations.
PiperOrigin-RevId: 251281612
2019-06-03 19:26:46 -07:00
Jacques Pienaar c014f5699f Add Windows build instructions.
PiperOrigin-RevId: 251269521
2019-06-03 19:26:37 -07:00
Alex Zinenko f5e736c448 SDBM: fix the order of variables in the stripe-induced inequalities
The initial implementation of SDBM mistakenly swapped the order of variables in
the inequalities induced by a stripe equality: y = x # B actually implies
y - x <= 0 and x - y <= B - 1 rather than x - y <= 0 and y - x <= B - 1 as
implemented.  Textual comments in the test files were correct but did not
correspond to the emitted IR.  Round-tripping between SDBM and expression lists
was not affected because the wrong order was used in both directions of the
conversion.  Use the correct order.

PiperOrigin-RevId: 251252980
2019-06-03 19:26:29 -07:00
River Riddle c263ae9104 Restructure the parser to support nested name scopes. This allows for regions at the same level of nesting to have values with the same SSA name. This is a necessary step for representing functions as operations.
The following is now valid IR:
  foo.op ... {
    %val = ...
  }, {
    %val = ...
  }

PiperOrigin-RevId: 251249875
2019-06-03 19:26:20 -07:00
Alex Zinenko 252de8eca0 Introduce OpOperandAdaptors and emit them from ODS
When manipulating generic operations, such as in dialect conversion /
rewriting, it is often necessary to view a list of Values as operands to an
operation without creating the operation itself.  The absence of such view
makes dialect conversion patterns, among others, to use magic numbers to obtain
specific operands from a list of rewritten values when converting an operation.
Introduce XOpOperandAdaptor classes that wrap an ArrayRef<Value *> and provide
accessor functions identical to those available in XOp.  This makes it possible
for conversions to use these adaptors to address the operands with names rather
than rely on their position in the list.  The adaptors are generated from ODS
together with the actual operation definitions.

This is another step towards making dialect conversion patterns specific for a
given operation.

Illustrate the approach on conversion patterns in the standard to LLVM dialect
conversion.

PiperOrigin-RevId: 251232899
2019-06-03 19:26:12 -07:00
River Riddle 3ea8575058 Cleanup the Linalg trait ViewRanks.
* Fix a miscompile on older clang versions when initializing an ArrayRef with an unsigned variadic template argument.
* Update the errors to use the streaming interface instead of Twine.

PiperOrigin-RevId: 251223929
2019-06-03 19:26:04 -07:00
River Riddle b1393c2cd0 NFC: Split up Parser::parseAttribute into multiple smaller functions to improve readability.
PiperOrigin-RevId: 251158192
2019-06-03 19:25:55 -07:00
Jacques Pienaar c914976c72 Allow constant of unit type.
--

PiperOrigin-RevId: 251053682
2019-06-01 20:14:48 -07:00
Jacques Pienaar 482d39eb98 Avoid failure due to incomplete type specification.
--

PiperOrigin-RevId: 251048081
2019-06-01 20:14:39 -07:00
Lei Zhang af98d82476 [spirv] Add a script to update SPIRVBase.td with new enum attributes
This script parses the SPIR-V JSON grammar to extract operand kinds that
    are enums and generate TableGen definitions for them.

    Also added a shell script to point to the correct relative file location
    to simplify command invocation.

--

PiperOrigin-RevId: 251041084
2019-06-01 20:14:28 -07:00
Mehdi Amini 05b0527ab7 Move NamedAttributeList::get() method out-of-line (fix CMake build due to missing include)
--

PiperOrigin-RevId: 251000296
2019-06-01 20:14:19 -07:00
Geoffrey Martin-Noble 8c4ae76b27 Use size_t for tuple type size
This is more consistent with standard containers.

--

PiperOrigin-RevId: 250985851
2019-06-01 20:14:09 -07:00
Geoffrey Martin-Noble daefaded4a Consistently use int64_t for shape-related values in shaped types
We want to support 64-bit shapes (even when the compiler is on a 32-bit architecture). Using int64_t consistently allows us to sidestep the bugginess of unsigned arithmetic.

    Still unsigned: kind, memory space, and bit width. The first two are basically enums. We could have a discussion about the last one, but it's basically just a very large enum as well and we're not doing any math on it, I think.

--

PiperOrigin-RevId: 250985791
2019-06-01 20:13:58 -07:00
Geoffrey Martin-Noble c912981bbd Static cast size_t -> int64_t instead of vice versa for equals comparisons
These were just introduced by a previous CL moving MemRef getRank to return int64_t. size_t could be smaller than 64 bits and in equals comparisons, signed vs unsigned doesn't matter. In these cases, we know right now that the particular int64_t is not larger than max size_t (because it currently comes directly from a size() call), the alternative cast plus equals comparison is always safe, so we might as well do it that way and no longer require reasoning deeper into the callstack.

    We are already assuming that size() calls fit into int64_t in a number of other cases like the aforementioned getRank() (since exabytes of RAM are rare). If we want to avoid this assumption we will have to come up with a principled way to do it throughout.

--

PiperOrigin-RevId: 250980297
2019-06-01 20:13:49 -07:00
River Riddle e7b337acf8 Add support for providing an output stream to the SourceMgrDiagnosticHandlers.
--

PiperOrigin-RevId: 250974331
2019-06-01 20:13:39 -07:00
Amit Sabne 7a43da6060 Loop invariant code motion - remove reliance on getForwardSlice. Add more tests.
--

PiperOrigin-RevId: 250950703
2019-06-01 20:13:30 -07:00
River Riddle 05bb27fac2 NFC: Cleanup method definitions within Parser and add header blocks to improve readability.
--

PiperOrigin-RevId: 250949195
2019-06-01 20:13:19 -07:00
Mehdi Amini 1e104f22eb Fix CMake builds: sources not used in every targets must be marked with LLVM_OPTIONAL_SOURCES
--

PiperOrigin-RevId: 250948796
2019-06-01 20:13:10 -07:00
Geoffrey Martin-Noble 65eae3f75f Get rid of separate getRank() on MemRef now that it subclasses ShapedType
We are moving towards int64_t for these shape/dimension -related values to avoid buginess with unsigned arithmetic

--

PiperOrigin-RevId: 250945322
2019-06-01 20:13:00 -07:00
Geoffrey Martin-Noble ac4b0a1e7b Some cleanup of ShapedType now that MemRef subclasses it.
Extract common methods into ShapedType.
    Simplify methods.
    Remove some extraneous asserts.
    Replace sentinel value with a helper method to check the same.

--

PiperOrigin-RevId: 250945261
2019-06-01 20:12:51 -07:00
Geoffrey Martin-Noble 32de860a09 Make MemRefType subclass ShapedType
MemRefs have the same notion of shape, rank, and fixed element type. This allows us to reuse utilities based on shape for memref.

    All dyn_cast and isa calls for ShapedType have been checked and either modified to explicitly check for vector or tensor, or confirmed to not depend on the result being a vector or tensor.

    Discussion in https://groups.google.com/a/tensorflow.org/forum/#!topic/mlir/cHLoyfGu8y8

--

PiperOrigin-RevId: 250945184
2019-06-01 20:12:40 -07:00