Alex Zinenko [Fri, 6 Dec 2019 22:18:05 +0000 (14:18 -0800)]
Use named traits in the ODS definition of LLVMFuncOp
The "FunctionLike" and "IsIsolatedFromAbove" op traits are now defined as named
records in base ODS file. Use those instead of NativeOpTrait referring to the
C++ class name in the ODS definition of LLVMFuncOp. NFC.
PiperOrigin-RevId:
284260891
Aart Bik [Fri, 6 Dec 2019 20:38:52 +0000 (12:38 -0800)]
[VecOps] Rename vector.[insert|extract]element to just vector.[insert|extract]
Since these operations lower to [insert|extract][element|value] at LLVM
dialect level, neither element nor value would correctly reflect the meaning.
PiperOrigin-RevId:
284240727
Alex Zinenko [Fri, 6 Dec 2019 20:00:01 +0000 (12:00 -0800)]
LLVM::GlobalOp: take address space as builder argument
Accept the address space of the global as a builder argument when constructing
an LLVM::GlobalOp instance. This decreases the reliance of LLVM::GlobalOp users
on the internal name of the attribute used for this purpose. Update several
uses of the address space in GPU to NVVM conversion.
PiperOrigin-RevId:
284233254
Alex Zinenko [Fri, 6 Dec 2019 19:59:59 +0000 (11:59 -0800)]
Move GPU::FuncOp definition to ODS - NFC
Move the definition of the GPU function opreation from hand-rolled C++ code to
ODS framework. This only does the moves, a follow-up is necessary to clean up
users of custom functions that could be auto-generated by ODS.
PiperOrigin-RevId:
284233245
MLIR Team [Fri, 6 Dec 2019 19:06:38 +0000 (11:06 -0800)]
Provide a way to get the type of a ValueHandle.
PiperOrigin-RevId:
284221337
Aart Bik [Fri, 6 Dec 2019 19:01:54 +0000 (11:01 -0800)]
[VectorOps] Add lowering of vector.broadcast to LLVM IR
For example, a scalar broadcast
%0 = vector.broadcast %x : f32 to vector<2xf32>
return %0 : vector<2xf32>
which expands scalar x into vector [x,x] by lowering
to the following LLVM IR dialect to implement the
duplication over the leading dimension.
%0 = llvm.mlir.undef : !llvm<"<2 x float>">
%1 = llvm.mlir.constant(0 : index) : !llvm.i64
%2 = llvm.insertelement %x, %0[%1 : !llvm.i64] : !llvm<"<2 x float>">
%3 = llvm.shufflevector %2, %0 [0 : i32, 0 : i32] : !llvm<"<2 x float>">, !llvm<"<2 x float>">
return %3 : vector<2xf32>
In the trailing dimensions, the operand is simply
"passed through", unless a more elaborate "stretch"
is required.
For example
%0 = vector.broadcast %arg0 : vector<1xf32> to vector<4xf32>
return %0 : vector<4xf32>
becomes
%0 = llvm.mlir.undef : !llvm<"<4 x float>">
%1 = llvm.mlir.constant(0 : index) : !llvm.i64
%2 = llvm.extractelement %arg0[%1 : !llvm.i64] : !llvm<"<1 x float>">
%3 = llvm.mlir.constant(0 : index) : !llvm.i64
%4 = llvm.insertelement %2, %0[%3 : !llvm.i64] : !llvm<"<4 x float>">
%5 = llvm.shufflevector %4, %0 [0 : i32, 0 : i32, 0 : i32, 0 : i32] : !llvm<"<4 x float>">, !llvm<"<4 x float>">
llvm.return %5 : !llvm<"<4 x float>">
PiperOrigin-RevId:
284219926
Jacques Pienaar [Fri, 6 Dec 2019 18:52:38 +0000 (10:52 -0800)]
Generate builder for ops that use InferTypeOpInterface trait in ODS
For ops with infer type op interface defined, generate version that calls the inferal method on build. This is intermediate step to removing special casing of SameOperandsAndResultType & FirstAttrDereivedResultType. After that would be generating the inference code, with the initial focus on shaped container types. In between I plan to refactor these a bit to reuse generated paths. The intention would not be to add the type inference trait in multiple places, but rather to take advantage of the current modelling in ODS where possible to emit it instead.
Switch the `inferReturnTypes` method to be static.
Skipping ops with regions here as I don't like the Region vs unique_ptr<Region> difference at the moment, and I want the infer return type trait to be useful for verification too. So instead, just skip it for now to avoid churn.
PiperOrigin-RevId:
284217913
Alex Zinenko [Fri, 6 Dec 2019 18:08:15 +0000 (10:08 -0800)]
Add conversions of GPU func with memory attributions to LLVM/NVVM
GPU functions use memory attributions, a combination of Op attributes and
region arguments, to specify function-wide buffers placed in workgroup or
private memory spaces. Introduce a lowering pattern for GPU functions to be
converted to LLVM functions taking into account memory attributions. Workgroup
attributions get transformed into module-level globals with unique names
derived from function names. Private attributions get converted into
llvm.allocas inside the function body. In both cases, we inject at the
beginning of the function the IR that obtains the raw pointer to the data and
populates a MemRef descriptor based on the MemRef type of buffer, making
attributions compose with the rest of the MemRef lowering and transparent for
use with std.load and std.store. While using raw pointers instead of
descriptors might have been more efficient, it is better implemented as a
canonicalization or a separate transformation so that non-attribution memrefs
could also benefit from it.
PiperOrigin-RevId:
284208396
Alexandre E. Eichenberger [Fri, 6 Dec 2019 17:40:12 +0000 (09:40 -0800)]
fix examples in comments
Closes tensorflow/mlir#301
COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/301 from AlexandreEichenberger:vect-doc-update
7e5418a9101a4bdad2357882fe660b02bba8bd01
PiperOrigin-RevId:
284202462
River Riddle [Fri, 6 Dec 2019 17:28:48 +0000 (09:28 -0800)]
Use regex to fix failure when stats are disabled.
It would be nice if we could detect if stats were enabled or not and use 'Requires', but this isn't possible to do at configure time.
Fixes tensorflow/mlir#296
PiperOrigin-RevId:
284200271
Andy Davis [Fri, 6 Dec 2019 15:36:55 +0000 (07:36 -0800)]
Unroll vector masks along with their associated vector arguments.
Updates vector ContractionOp to use proper vector masks (produced by CreateMaskOp/ConstantMaskOp).
Leverages the following canonicalizations in unrolling unit test: CreateMaskOp -> ConstantMaskOp, StridedSliceOp(ConstantMaskOp) -> ConstantMaskOp
Removes IndexTupleOp (no longer needed now that we have vector mask ops).
Updates all unit tests.
PiperOrigin-RevId:
284182168
Denis Khalikov [Fri, 6 Dec 2019 14:26:24 +0000 (06:26 -0800)]
[spirv] Reorder `erase` and `emplace` to avoid "invalid iterator access".
The iterator should be erased before adding a new entry
into blockMergeInfo to avoid iterator invalidation.
Closes tensorflow/mlir#299
COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/299 from denis0x0D:sandbox/reoder_erase
983be565809aa0aadfc7e92962e4d4b282f63c66
PiperOrigin-RevId:
284173235
Uday Bondhugula [Fri, 6 Dec 2019 13:59:06 +0000 (05:59 -0800)]
DimOp folding for alloc/view dynamic dimensions
Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>
Closes tensorflow/mlir#253
COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/253 from bondhugula:dimop
a4b464f24ae63fd259114558d87e11b8ee4dae86
PiperOrigin-RevId:
284169689
Kazuaki Ishizaki [Fri, 6 Dec 2019 13:58:59 +0000 (05:58 -0800)]
minor spelling tweaks
Closes tensorflow/mlir#290
COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/290 from kiszk:spelling_tweaks_201912
9d9afd16a723dd65754a04698b3976f150a6054a
PiperOrigin-RevId:
284169681
Alex Zinenko [Fri, 6 Dec 2019 09:08:40 +0000 (01:08 -0800)]
LLVM::AddressOfOp: properly take into account the address space
The AddressOf operation in the LLVM dialect return a pointer to a global
variable. The latter may be in a non-default address space as indicated by the
"addr_space" attribute. Check that the address space of the pointer returned by
AddressOfOp matches that of the referenced GlobalOp. Update the AddressOfOp
builder to respect this constraint.
PiperOrigin-RevId:
284138860
River Riddle [Fri, 6 Dec 2019 01:46:37 +0000 (17:46 -0800)]
NFC: Add documentation for `-mlir-print-op-on-diagnostic` and `-mlir-print-stacktrace-on-diagnostic`.
This change adds proper documentation in Diagnostics.md, allowing for users to more easily find them.
PiperOrigin-RevId:
284092336
River Riddle [Thu, 5 Dec 2019 23:32:59 +0000 (15:32 -0800)]
Add include path to the TestDialect to fix broken build.
PiperOrigin-RevId:
284067891
Jose Ignacio Gomez [Thu, 5 Dec 2019 23:14:22 +0000 (15:14 -0800)]
[Linalg] Add permutation information to tiling
This patch closes issue tensorflow/mlir#271.
It adds an optional permutation map to declarative tiling transformations.
The map is expressed as a list of integers.
Closes tensorflow/mlir#288
COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/288 from tetuante:issue271
2df2938d6a1f01b3bc404ded08dea2dd1e10b588
PiperOrigin-RevId:
284064151
River Riddle [Thu, 5 Dec 2019 22:52:28 +0000 (14:52 -0800)]
Refactor the IRPrinting instrumentation to take a derivable config.
This allows for more interesting behavior from users, e.g. enabling the ability to dump the IR to a separate file for each pass invocation.
PiperOrigin-RevId:
284059447
nmostafa [Thu, 5 Dec 2019 21:12:50 +0000 (13:12 -0800)]
Add UnrankedMemRef Type
Closes tensorflow/mlir#261
COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/261 from nmostafa:nmostafa/unranked
96b6e918f6ed64496f7573b2db33c0b02658ca45
PiperOrigin-RevId:
284037040
Denis Khalikov [Thu, 5 Dec 2019 21:10:10 +0000 (13:10 -0800)]
[spirv] Add CompositeInsertOp operation
A CompositeInsertOp operation make a copy of a composite object,
while modifying one part of it.
Closes tensorflow/mlir#292
COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/292 from denis0x0D:sandbox/composite_insert
2200962b9057bda53cd2f2866b461e2797196380
PiperOrigin-RevId:
284036551
River Riddle [Thu, 5 Dec 2019 19:52:58 +0000 (11:52 -0800)]
Add support for instance specific pass statistics.
Statistics are a way to keep track of what the compiler is doing and how effective various optimizations are. It is useful to see what optimizations are contributing to making a particular program run faster. Pass-instance specific statistics take this even further as you can see the effect of placing a particular pass at specific places within the pass pipeline, e.g. they could help answer questions like "what happens if I run CSE again here".
Statistics can be added to a pass by simply adding members of type 'Pass::Statistics'. This class takes as a constructor arguments: the parent pass pointer, a name, and a description. Statistics can be dumped by the pass manager in a similar manner to how pass timing information is dumped, i.e. via PassManager::enableStatistics programmatically; or -pass-statistics and -pass-statistics-display via the command line pass manager options.
Below is an example:
struct MyPass : public OperationPass<MyPass> {
Statistic testStat{this, "testStat", "A test statistic"};
void runOnOperation() {
...
++testStat;
...
}
};
$ mlir-opt -pass-pipeline='func(my-pass,my-pass)' foo.mlir -pass-statistics
Pipeline Display:
===-------------------------------------------------------------------------===
... Pass statistics report ...
===-------------------------------------------------------------------------===
'func' Pipeline
MyPass
(S) 15 testStat - A test statistic
MyPass
(S) 6 testStat - A test statistic
List Display:
===-------------------------------------------------------------------------===
... Pass statistics report ...
===-------------------------------------------------------------------------===
MyPass
(S) 21 testStat - A test statistic
PiperOrigin-RevId:
284022014
Mahesh Ravishankar [Thu, 5 Dec 2019 19:31:28 +0000 (11:31 -0800)]
Allow specification of the workgroup size for GPUToSPIRV lowering.
SPIR-V/Vulkan spec requires the workgroups size to be specified with
the spv.ExecutionMode operation. This was hard-wired to be set to a
particular value. It is now changed to be configurable by clients of
the pass or of the patterns that implement the lowering from GPU to
SPIRV.
PiperOrigin-RevId:
284017482
Lei Zhang [Thu, 5 Dec 2019 18:05:54 +0000 (10:05 -0800)]
Add spv.AtomicCompareExchangeWeak
PiperOrigin-RevId:
283997917
River Riddle [Thu, 5 Dec 2019 17:59:52 +0000 (09:59 -0800)]
Add a flag to dump the current stack trace when emitting a diagnostic.
It is often desirable to know where within the program that a diagnostic was emitted, without reverting to assert/unreachable which crash the program. This change adds a flag `mlir-print-stacktrace-on-diagnostic` that attaches the current stack trace as a note to every diagnostic that gets emitted.
PiperOrigin-RevId:
283996373
Lei Zhang [Thu, 5 Dec 2019 12:39:06 +0000 (04:39 -0800)]
[spirv] Fix nested loop (de)serialization
For serialization, when we have nested ops, the inner loop will create multiple
SPIR-V blocks. If the outer loop has block arguments (which corresponds to
OpPhi instructions), we defer the handling of OpPhi's parent block handling
until we serialized all blocks and then fix it up with the result <id>. These two
cases happening together was generating invalid SPIR-V blob because we
previously assume the parent block to be the block containing the terminator.
That is not true anymore when the block contains structured control flow ops.
If that happens, it should be fixed to use the structured control flow op's
merge block.
For deserialization, we record a map from header blocks to their corresponding
merge and continue blocks during the initial deserialization and then use the
info to construct spv.selection/spv.loop. The existing implementation will also
fall apart when we have nested loops. If so, we clone all blocks for the outer
loop, including the ones for the inner loop, to the spv.loop's region. So the map
for header blocks' merge info need to be updated; otherwise we are operating
on already deleted blocks.
PiperOrigin-RevId:
283949230
Mehdi Amini [Thu, 5 Dec 2019 12:32:13 +0000 (04:32 -0800)]
Fix MLIR Build after LLVM upstream JIT changes (getMainJITDylib removed)
The getMainJITDylib() method was removed in
4fc68b9b7f, replace it by creating a JITDylib on the fly.
PiperOrigin-RevId:
283948595
Tres Popp [Thu, 5 Dec 2019 11:56:18 +0000 (03:56 -0800)]
Move ModuleManager functionality into mlir::SymbolTable.
Note for broken code, the following transformations occurred:
ModuleManager::insert(Block::iterator, Operation*) - > SymbolTable::insert(Operation*, Block::iterator)
ModuleManager::lookupSymbol -> SymbolTable::lookup
ModuleManager::getModule() -> SymbolTable::getOp()
ModuleManager::getContext() -> SymbolTable::getOp()->getContext()
ModuleManager::* -> SymbolTable::*
PiperOrigin-RevId:
283944635
Lei Zhang [Thu, 5 Dec 2019 07:45:01 +0000 (23:45 -0800)]
Add MLIRIR as a dependency to LLVM and related dialects
Fixes tensorflow/mlir#289
PiperOrigin-RevId:
283914472
River Riddle [Thu, 5 Dec 2019 00:09:41 +0000 (16:09 -0800)]
Optimize operation ordering to support non-congruent indices.
This change adds support for non-congruent indices in the operation ordering within a basic block. This effect of this is that insertions are less likely to cause an invalidation of the ordering within a block. This has a big effect on modules that have very large basic blocks.
PiperOrigin-RevId:
283858136
River Riddle [Wed, 4 Dec 2019 23:49:09 +0000 (15:49 -0800)]
Add emitOptional(Error|Warning|Remark) functions to simplify emission with an optional location.
In some situations a diagnostic may optionally be emitted by the presence of a location, e.g. attribute and type verification. These situations currently require extra 'if(loc) emitError(...); return failure()' wrappers that make verification clunky. These new overloads take an optional location and a list of arguments to the diagnostic, and return a LogicalResult. We take the arguments directly and return LogicalResult instead of returning InFlightDiagnostic because we cannot create a valid diagnostic with a null location. This creates an awkward situation where a user may try to treat the, potentially null, diagnostic as a valid one and encounter crashes when attaching notes/etc. Below is an example of how these methods simplify some existing usages:
Before:
if (loc)
emitError(*loc, "this is my diagnostic with argument: ") << 5;
return failure();
After:
return emitOptionalError(loc, "this is my diagnostic with argument: ", 5);
PiperOrigin-RevId:
283853599
Nicolas Vasilache [Wed, 4 Dec 2019 22:15:24 +0000 (14:15 -0800)]
Add a CL option to Standard to LLVM lowering to use alloca instead of malloc/free.
In the future, a more configurable malloc and free interface should be used and exposed via
extra parameters to the `createLowerToLLVMPass`. Until requirements are gathered, a simple CL flag allows generating code that runs successfully on hardware that cannot use the stdlib.
PiperOrigin-RevId:
283833424
Andy Davis [Wed, 4 Dec 2019 21:00:14 +0000 (13:00 -0800)]
Add canonicalization patterns for vector CreateMaskOp and StridedSliceOp to be used in the unroll vector op transformation.
Adds a ConstantMaskOp to the vector ops dialect.
Adds the following canonicalization patterns:
CreateMaskOp -> ConstantMaskOp
StridedSliceOp(ConstantMaskOp) -> ConstantMaskOp
PiperOrigin-RevId:
283816752
River Riddle [Wed, 4 Dec 2019 20:31:36 +0000 (12:31 -0800)]
[CSE] NFC: Hash the attribute dictionary pointer instead of the list of attributes.
PiperOrigin-RevId:
283810829
Nicolas Vasilache [Wed, 4 Dec 2019 20:11:08 +0000 (12:11 -0800)]
Drop MaterializeVectorTransfers in favor of simpler declarative unrolling
Now that we have unrolling as a declarative pattern, we can drop a full pass that has gone stale. In the future we may want to add specific unrolling patterns for VectorTransferReadOp.
PiperOrigin-RevId:
283806880
River Riddle [Wed, 4 Dec 2019 20:05:52 +0000 (12:05 -0800)]
NFC: Fix mismatches between LangRef.md and actual parser implementation.
PiperOrigin-RevId:
283805832
Lei Zhang [Wed, 4 Dec 2019 19:34:01 +0000 (11:34 -0800)]
[spirv] Define a few more extensions in SPIRVBase.td
PiperOrigin-RevId:
283798496
Sean Silva [Wed, 4 Dec 2019 18:19:20 +0000 (10:19 -0800)]
Print out large elementsattr's such that they are parseable.
I found that when running crash reproducers, the elided elementsattr's
would prevent parsing the IR repro. I found myself manually going and
replacing the "..." with some valid IR.
With this change, we now print elided attrs as `opaque<"", "0xDEADBEEF">`
to clearly delineate them as being elided while still being parseable.
PiperOrigin-RevId:
283781806
Uday Bondhugula [Wed, 4 Dec 2019 17:29:51 +0000 (09:29 -0800)]
NFC - fix name / comments - isAccessInvariant
- the name was misleading; this is really checking if a Value being used
to index was loop IV invariant. Update comment.
- the method is only used locally; what can be exposed in the future is
isAccessInvariant(LoadOrStoreOp op, Value *iv)
Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>
Closes tensorflow/mlir#285
COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/285 from bondhugula:quickfix
fe5837abe987980c4ab469a9aa7de8e4f0007d9f
PiperOrigin-RevId:
283771923
Scott Todd [Wed, 4 Dec 2019 17:15:49 +0000 (09:15 -0800)]
[spirv] Adding sqrt op in the GLSL extension.
PiperOrigin-RevId:
283769736
Alex Zinenko [Wed, 4 Dec 2019 15:41:55 +0000 (07:41 -0800)]
Loop coalescing: fix pointer chainsing in use-chain traversal
In the replaceAllUsesExcept utility function called from loop coalescing the
iteration over the use-chain is incorrect. The use list nodes (IROperands) have
next/prev links, and bluntly resetting the use would make the loop to continue
on uses of the value that was replaced instead of the original one. As a
result, it could miss the existing uses and update the wrong ones. Make sure we
increment the iterator before updating the use in the loop body.
Reported-by: Uday Bondhugula <uday@polymagelabs.com>
Closes tensorflow/mlir#291.
PiperOrigin-RevId:
283754195
Julian Gross [Wed, 4 Dec 2019 15:17:01 +0000 (07:17 -0800)]
Added new FAbs, FCeil, Cos, Neg, Sign, Tanh operations.
Closes tensorflow/mlir#251
COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/251 from dfki-jugr:new_ops
0398997bf9953016898f873068e22916a062eb2b
PiperOrigin-RevId:
283750699
Andy Davis [Wed, 4 Dec 2019 14:53:07 +0000 (06:53 -0800)]
Adds support for unrolling single-result vector operations with iterator type lists and indexing maps to a target vector size.
Adds unit tests for unrolling the vector ContractionOp with different iteration orders.
PiperOrigin-RevId:
283747503
Kazuaki Ishizaki [Wed, 4 Dec 2019 12:58:12 +0000 (04:58 -0800)]
minor spelling tweaks
Closes tensorflow/mlir#250
COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/250 from kiszk:spelling_tweaks_201911
50fc04443723190b764e824b6fcd2469fecb56e6
PiperOrigin-RevId:
283733032
Smit Hinsu [Wed, 4 Dec 2019 05:25:02 +0000 (21:25 -0800)]
Avoid variable name conflict in MLIR tutorial code snippet
PiperOrigin-RevId:
283682865
Nicolas Vasilache [Wed, 4 Dec 2019 01:51:34 +0000 (17:51 -0800)]
Refactor dependencies to expose Vector transformations as patterns - NFC
This CL refactors some of the MLIR vector dependencies to allow decoupling VectorOps, vector analysis, vector transformations and vector conversions from each other.
This makes the system more modular and allows extracting VectorToVector into VectorTransforms that do not depend on vector conversions.
This refactoring exhibited a bunch of cyclic library dependencies that have been cleaned up.
PiperOrigin-RevId:
283660308
Lei Zhang [Wed, 4 Dec 2019 00:43:40 +0000 (16:43 -0800)]
[spirv] Add spv.GroupNonUniformBallot
This CL also did the following cleanup:
- Moved the test for spv.SubgroupBallotKHR to its own file
- Wrapped generated canonicalization patterns in anonymous namespace
- Updated header comments in SPVOps.td
PiperOrigin-RevId:
283650091
Mahesh Ravishankar [Wed, 4 Dec 2019 00:05:46 +0000 (16:05 -0800)]
Add a pass to legalize operations before lowering to SPIR-V.
Not all StandardOps can be lowered to SPIR-V. For example, subview op
implementation requires use of pointer bitcasts which is not valid
according to SPIR-V spec (or at least is ambiguous about it). Such ops
need to be removed/transformed before lowering to SPIR-V. The
SPIRVLegalizationPass is added a place where such legalizations can be
added. Current implementation folds the subview ops with load/stores
so that the lowering itself does not have to convert a subview op.
PiperOrigin-RevId:
283642981
Sean Silva [Tue, 3 Dec 2019 22:00:36 +0000 (14:00 -0800)]
Make diagnostic a bit clearer.
This prints out in case of any pass failure. Not just a crash.
PiperOrigin-RevId:
283616719
Andy Davis [Tue, 3 Dec 2019 19:55:09 +0000 (11:55 -0800)]
Add CreateMaskOp to the VectorOps dialect.
PiperOrigin-RevId:
283591888
Sean Silva [Tue, 3 Dec 2019 19:23:48 +0000 (11:23 -0800)]
Verifier: Better error message in case of successor operand mismatch.
In particular, print the successor number in the diagnostic.
PiperOrigin-RevId:
283585084
River Riddle [Tue, 3 Dec 2019 19:13:39 +0000 (11:13 -0800)]
Allow analyses to provide a hook 'isInvalidated' to determine if they are truly invalidated.
The hook has the following form:
* `bool isInvalidated(const AnalysisManager::PreservedAnalyses &)`
Given a preserved analysis set, the analysis returns true if it should truly be
invalidated. This allows for more fine-tuned invalidation in cases where an
analysis wasn't explicitly marked preserved, but may be preserved(or
invalidated) based upon other properties; such as analyses sets.
PiperOrigin-RevId:
283582889
Mahesh Ravishankar [Tue, 3 Dec 2019 18:20:37 +0000 (10:20 -0800)]
Convert MemRefType to a linearized array in SPIR-V lowering.
The SPIR-V lowering used nested !spv.arrays to represented
multi-dimensional arrays, with the hope that in-conjunction with the
layout annotations, the shape and layout of memref can be represented
directly. It is unclear though how portable this representation will
end up being. It will rely on driver compilers implementing complex
index computations faithfully. A more portable approach is to use
linearized arrays to represent memrefs and explicitly instantiate all
the index computation in SPIR-V. This gives added benefit that we can
further optimize the generated code in MLIR before generating the
SPIR-V binary.
PiperOrigin-RevId:
283571167
MLIR Team [Tue, 3 Dec 2019 18:11:40 +0000 (10:11 -0800)]
Add Python bindings for affine expressions with binary operators.
PiperOrigin-RevId:
283569325
MLIR Team [Tue, 3 Dec 2019 17:32:16 +0000 (09:32 -0800)]
Add python bindings for ArrayAttr, AffineMapAttr.
PiperOrigin-RevId:
283561252
Alex Zinenko [Tue, 3 Dec 2019 14:22:31 +0000 (06:22 -0800)]
Fix ViewOp to have at most one offset operand
As described in the documentation, ViewOp is expected to take an optional
dynamic offset followed by a list of dynamic sizes. However, the ViewOp parser
did not include a check for the offset being a single value and accepeted a
list of values instead.
Furthermore, several tests have been exercising the wrong syntax of a ViewOp,
passing multiple values to the dyanmic stride list, which was not caught by the
parser. The trailing values could have been erronously interpreted as dynamic
sizes. This is likely due to resyntaxing of the ViewOp, with the previous
syntax taking the list of sizes before the offset. Update the tests to use the
syntax with the offset preceding the sizes.
Worse, the conversion of ViewOp to the LLVM dialect assumed the wrong order of
operands with offset in the trailing position, and erronously relied on the
permissive parsing that interpreted trailing dynamic offset values as leading
dynamic sizes. Fix the lowering to use the correct order of operands.
PiperOrigin-RevId:
283532506
Diego Caballero [Tue, 3 Dec 2019 14:09:21 +0000 (06:09 -0800)]
AffineLoopFusion: Prevent fusion of multi-out-edge producer loops
tensorflow/mlir#162 introduced a bug that
incorrectly allowed fusion of producer loops with multiple outgoing
edges. This commit fixes that problem. It also introduces a new flag to
disable sibling loop fusion so that we can test producer-consumer fusion
in isolation.
Closes tensorflow/mlir#259
COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/259 from dcaballe:dcaballe/fix_multi_out_edge_producer_fusion
578d5661705fd5c56c555832d5e0528df88c5282
PiperOrigin-RevId:
283531105
Stephan Herhut [Tue, 3 Dec 2019 13:11:20 +0000 (05:11 -0800)]
Extend conversion of SubViewOp to llvm to also support cases where size and stride
are constant (i.e., there are no size and stride operands).
We recently added canonicalization that rewrites constant size and stride operands to
SubViewOp into static information in the type, so these patterns now occur during code
generation.
PiperOrigin-RevId:
283524688
Lei Zhang [Tue, 3 Dec 2019 12:49:20 +0000 (04:49 -0800)]
[spirv] Add spv.SubgroupBallotKHROp
PiperOrigin-RevId:
283522284
Alexander Belyaev [Tue, 3 Dec 2019 09:55:18 +0000 (01:55 -0800)]
[Linalg] Update/fix documentation for linalg.indexed_generic.
PiperOrigin-RevId:
283503642
Alex Zinenko [Tue, 3 Dec 2019 08:26:13 +0000 (00:26 -0800)]
Add linkage support to LLVMFuncOp
A recent commit introduced the Linkage attribute to the LLVM dialect and used
it in the Global Op. Also use it in LLVMFuncOp. As per LLVM Language Reference,
if the linkage attribute is omitted, the function is assumed to have external
linkage.
PiperOrigin-RevId:
283493299
Lei Zhang [Mon, 2 Dec 2019 22:21:42 +0000 (14:21 -0800)]
[spirv] NFC: reorder sections in SPIRVBase.td
Put extensions and capabilities at the very beginning because
they will be referenced later by other definitions.
PiperOrigin-RevId:
283416972
Lei Zhang [Mon, 2 Dec 2019 20:26:34 +0000 (12:26 -0800)]
NFC: use `&&` instead of `and`
PiperOrigin-RevId:
283392575
Aart Bik [Mon, 2 Dec 2019 17:56:58 +0000 (09:56 -0800)]
[VectorOps] Add legality rules to broadcast
PiperOrigin-RevId:
283360101
Lei Zhang [Mon, 2 Dec 2019 17:33:24 +0000 (09:33 -0800)]
[ODS] Generate builders taking unwrapped value and defaults for attributes
Existing builders generated by ODS require attributes to be passed
in as mlir::Attribute or its subclasses. This is okay foraggregate-
parameter builders, which is primarily to be used by programmatic
C++ code generation; it is inconvenient for separate-parameter
builders meant to be called in manually written C++ code because
it requires developers to wrap raw values into mlir::Attribute by
themselves.
This CL extends to generate additional builder methods that
take raw values for attributes and handles the wrapping in the
builder implementation. Additionally, if an attribute appears
late in the arguments list and has a default value, the default
value is supplied in the declaration if possible.
PiperOrigin-RevId:
283355919
Mehdi Amini [Mon, 2 Dec 2019 17:17:51 +0000 (09:17 -0800)]
Generate dialect documentations in the doc folder for every dialect
Also add a mlir-doc build target to general all the docs
PiperOrigin-RevId:
283353529
brett koonce [Mon, 2 Dec 2019 17:12:48 +0000 (09:12 -0800)]
docs: minor spelling tweaks
Closes tensorflow/mlir#262
COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/262 from brettkoonce:docs-sp
6833fc8aa41edd02d8bc7c3cbb84211cb8b0334c
PiperOrigin-RevId:
283352765
Denis Khalikov [Mon, 2 Dec 2019 15:58:38 +0000 (07:58 -0800)]
Add missing `>` to the description of std.view.
Closes tensorflow/mlir#266
COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/266 from denis0x0D:sandbox/miss_char
a5f662e1bf103b5009da67d045ee2fcebf822ab0
PiperOrigin-RevId:
283340486
Lei Zhang [Mon, 2 Dec 2019 15:54:23 +0000 (07:54 -0800)]
[DRR] Introduce `$_` to ignore op argument match
Right now op argument matching in DRR is position-based, meaning we need to
specify N arguments for an op with N ODS-declared argument. This can be annoying
when we don't want to capture all the arguments. `$_` is to remedy the situation.
PiperOrigin-RevId:
283339992
Lei Zhang [Mon, 2 Dec 2019 15:51:27 +0000 (07:51 -0800)]
NFC: Update std.subview op to use AttrSizedOperandSegments
This turns a few manually written helper methods into auto-generated ones.
PiperOrigin-RevId:
283339617
JKIsaacLee [Mon, 2 Dec 2019 15:08:31 +0000 (07:08 -0800)]
add missing '>' in Ch-2
add missing '>' in Ch-2
(tensor<2x3xf64)->(tensor<2x3xf64>)
Closes tensorflow/mlir#283
COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/283 from JKIsaacLee:patch-1
b69fe8d51e2a540f7efaded159d35b88778ad159
PiperOrigin-RevId:
283333807
Alexander Belyaev [Mon, 2 Dec 2019 14:30:19 +0000 (06:30 -0800)]
Lower linalg.indexed_generic with libcall to LLVM.
PiperOrigin-RevId:
283328994
Alex Zinenko [Mon, 2 Dec 2019 11:27:38 +0000 (03:27 -0800)]
Introduce Linkage attribute to the LLVM dialect
LLVM IR supports linkage on global objects such as global variables and
functions. Introduce the Linkage attribute into the LLVM dialect, backed by an
integer storage. Use this attribute on LLVM::GlobalOp and make it mandatory.
Implement parsing/printing of the attribute and conversion to LLVM IR.
See tensorflow/mlir#277.
PiperOrigin-RevId:
283309328
Jacques Pienaar [Fri, 29 Nov 2019 18:43:24 +0000 (10:43 -0800)]
mlir-tblgen: Dump input records when no generator is set
Follow LLVM's tblgen convention when no generator is set instead of asserting.
PiperOrigin-RevId:
283073690
Jacques Pienaar [Fri, 29 Nov 2019 18:26:23 +0000 (10:26 -0800)]
Fix redundant convert and use NamedAttributeList as value
* Had leftover call that would result in converting to dictionary attr before
being implicitedly converted back to NamedAttributeList;
* NamedAttributeList is value typed, so don't use const reference;
PiperOrigin-RevId:
283072576
JKIsaacLee [Fri, 29 Nov 2019 16:48:22 +0000 (08:48 -0800)]
Fixed typo in Ch-1 of Toy tutorial
Closes tensorflow/mlir#282
PiperOrigin-RevId:
283064785
Denis Khalikov [Thu, 28 Nov 2019 21:27:26 +0000 (13:27 -0800)]
[spirv] Check that operand of `spirv::CompositeExtractOp` is constant while folding.
Closes tensorflow/mlir#281
COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/281 from denis0x0D:sandbox/composite_ex_fold
d02d73658bd1b9eaa515eb4e0aee34bc41d4252b
PiperOrigin-RevId:
282971563
Alex Zinenko [Thu, 28 Nov 2019 19:50:47 +0000 (11:50 -0800)]
Split out FunctionLike printing/parsing into FunctionImplementation.{h,cpp}
Helper utilies for parsing and printing FunctionLike Ops are only relevant to
the implementation of the Op, not its definition. They depend on
OpImplementation.h and increase the inclusion footprint of FunctionSupport.h,
and do so only to provide some utilities in the "impl" namespace. Move them to
a separate files, similarly to OpDefinition/OpImplementation distinction, and
make only Op implementations use them while keeping headers cleaner. NFC.
PiperOrigin-RevId:
282964556
Jose Ignacio Gomez [Thu, 28 Nov 2019 09:59:22 +0000 (01:59 -0800)]
[Linalg] Change attribute n_loop_types to iterator
This addresses issue tensorflow/mlir#270. Linalg is updated to take the same form
of iterator_types than vector contraction.
Closes tensorflow/mlir#280
COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/280 from tetuante:PRissue270
d26d88d090d3765d3b9884bfabdd023143f27287
PiperOrigin-RevId:
282905396
Lei Zhang [Wed, 27 Nov 2019 23:55:07 +0000 (15:55 -0800)]
NFC: A few cleanups for SPIRVLowering
Updated comments and used static instead of anonymous namspace
to hide functions to be consistent with the existing codebase.
PiperOrigin-RevId:
282847784
Lei Zhang [Wed, 27 Nov 2019 22:12:32 +0000 (14:12 -0800)]
[spirv] NFC: Add getZero() and getOne() static method to ConstantOp
Getting constant zero or one is very common so it merits a special handy
method on spirv::ConstantOp itself.
PiperOrigin-RevId:
282832572
Lei Zhang [Wed, 27 Nov 2019 21:46:20 +0000 (13:46 -0800)]
[spirv] Add folders for spv.IAdd and spv.IMul
Adding zero and multiplying one can be common when generating code
for index calculation.
This CL also sorted canonicalize.mlir to alphabetical order.
PiperOrigin-RevId:
282828055
Aart Bik [Wed, 27 Nov 2019 19:58:08 +0000 (11:58 -0800)]
Fixed typo in Toy tutorial (second var e -> var f)
PiperOrigin-RevId:
282810649
Nicolas Vasilache [Wed, 27 Nov 2019 15:31:41 +0000 (07:31 -0800)]
Implement Linalg to loops lowering as a pattern
This CL rewrites the linalg ops to loops transformations as patterns that can be targeted directly from Tablegen. Reliance on OpFolder is removed and to cope with it we introduce local folding patterns that are applied greedily.
PiperOrigin-RevId:
282765550
Aart Bik [Wed, 27 Nov 2019 03:52:02 +0000 (19:52 -0800)]
[VectorOps] Refine BroadcastOp in VectorOps dialect
Since second argument is always fully overwritten and
shape is define in "to" clause, it is not needed.
Also renamed "into" to "to" now that arg is dropped.
PiperOrigin-RevId:
282686475
Jacques Pienaar [Tue, 26 Nov 2019 23:30:04 +0000 (15:30 -0800)]
Add create method that takes equivalent of OperationState with NamedAttributeList
This method is close to creating an OperationState first and then unpacking it
but avoids creating the OperationState and takes a NamedAttributeList for
attributes rather than array of NamedAttribute (to enable reusing an already
created NamedAttributeList).
Reuse this new method via create that takes OperationState. I'll update inferReturnTypes in follow up to also take NamedAttributeList and so a build method that uses both inferReturnTypes and create can reuse the same list.
PiperOrigin-RevId:
282651642
Aart Bik [Tue, 26 Nov 2019 22:43:03 +0000 (14:43 -0800)]
[VectorOps] Add a BroadcastOp to the VectorOps dialect
PiperOrigin-RevId:
282643305
David Truby [Tue, 26 Nov 2019 19:37:46 +0000 (11:37 -0800)]
Add OpenMP dialect to the dialect registry
Closes tensorflow/mlir#244
COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/244 from DavidTruby:openmp
30e2638ee678188575dd5aeb3f7fa51d93369f5f
PiperOrigin-RevId:
282607397
Mahesh Ravishankar [Tue, 26 Nov 2019 18:10:59 +0000 (10:10 -0800)]
Misc changes to lowering to SPIR-V.
These changes to SPIR-V lowering while adding support for lowering
SUbViewOp, but are not directly related.
- Change the lowering of MemRefType to
!spv.ptr<!spv.struct<!spv.array<...>[offset]>, ..>
This is consistent with the Vulkan spec.
- To enable testing a simple pattern of lowering functions is added to
ConvertStandardToSPIRVPass. This is just used to convert the type of
the arguments of the function. The added function lowering itself is
not meant to be the way functions are eventually lowered into SPIR-V
dialect.
PiperOrigin-RevId:
282589644
Nicolas Vasilache [Tue, 26 Nov 2019 16:47:14 +0000 (08:47 -0800)]
Automated rollback of commit
d60133f89bb08341718bb3132b19bc891f7d4f4d
PiperOrigin-RevId:
282574110
Nicolas Vasilache [Tue, 26 Nov 2019 15:38:33 +0000 (07:38 -0800)]
Relax restriction on affine_apply dim and symbol operands
The affine_apply operation is currently "doubly" affine and conflates two things:
1. it applies an affine map to a list of values of type `index` that are defined as either dim or symbol
2. it restricts (and propagates constraints on) the provenance of dims and symbols to a small subset of ops for which more restrictive polyhedral constraints apply.
Point 2. is related to the ability to form so-called static control parts and is related to dependence analysis and legality of transformations.
Point 1. however is completely independent, the only local implication of dims and symbol for affine_apply is that dims compose while symbols concatenate as well as the structural constraint that dims may not be multiplied.
The properties of composition and canonicalization in affine_apply are more generally useful. This CL relaxes the verifier on affine_apply so it can be used more generally.
The relevant affine.for/if/load/store op verifiers already implement the dim and symbol checking.
See this thread for the related discussion: https://groups.google.com/a/tensorflow.org/g/mlir/c/HkwCbV8D9N0/m/8srUNrX6CAAJ
PiperOrigin-RevId:
282562517
Andrew Anderson [Tue, 26 Nov 2019 01:53:20 +0000 (17:53 -0800)]
Some minor corrections and improvements to LangRef
Some productions in the LangRef were using undefined terminals and non-terminals, which have been added to the EBNF.
The dialect type and dialect attribute productions matched precisely the same structure and have been deduplicated.
The production for ssa-id was ambiguous but the fix is trivial (merging the leading '%') and has been applied.
Closes tensorflow/mlir#265
PiperOrigin-RevId:
282470892
Lei Zhang [Tue, 26 Nov 2019 01:26:16 +0000 (17:26 -0800)]
Add support for AttrSizedOperandSegments/AttrSizedResultSegments
Certain operations can have multiple variadic operands and their size
relationship is not always known statically. For such cases, we need
a per-op-instance specification to divide the operands into logical
groups or segments. This can be modeled by attributes.
This CL introduces C++ trait AttrSizedOperandSegments for operands and
AttrSizedResultSegments for results. The C++ trait just guarantees
such size attribute has the correct type (1D vector) and values
(non-negative), etc. It serves as the basis for ODS sugaring that
with ODS argument declarations we can further verify the number of
elements match the number of ODS-declared operands and we can generate
handy getter methods.
PiperOrigin-RevId:
282467075
Nicolas Vasilache [Mon, 25 Nov 2019 23:56:06 +0000 (15:56 -0800)]
Use vector.InsertStridedSlice in Vector -> Vector unrolling
This CL uses the recently added op to finish the implementation of Vector -> Vector unrolling by replacing the "fake join op" by a series of InsertStridedSliceOp.
Test is updated accordingly
PiperOrigin-RevId:
282451126
Nicolas Vasilache [Mon, 25 Nov 2019 23:36:45 +0000 (15:36 -0800)]
Add a vector.InsertStridedSliceOp
This new op is the counterpart of vector.StridedSliceOp and will be used for in the pattern rewrites for vector unrolling.
PiperOrigin-RevId:
282447414
MLIR Team [Mon, 25 Nov 2019 22:44:20 +0000 (14:44 -0800)]
Allow LLVM::ExtractElementOp to have non-i32 indices.
Also change the text format a bit, so that indices are braced by squares.
PiperOrigin-RevId:
282437095
Ben Vanik [Mon, 25 Nov 2019 22:31:12 +0000 (14:31 -0800)]
Make std.divis and std.diviu support ElementsAttr folding.
PiperOrigin-RevId:
282434465
Mahesh Ravishankar [Mon, 25 Nov 2019 21:19:19 +0000 (13:19 -0800)]
NFC: Actually expose the implementation of createGPUToSPIRVLoweringPass.
A mismatch in the function declaration and function definition,
prevented the implementation of the createGPUToSPIRVLoweringPass from
being exposed.
PiperOrigin-RevId:
282419815
Mahesh Ravishankar [Mon, 25 Nov 2019 20:56:46 +0000 (12:56 -0800)]
Add missing rule to generate SPIR-V ABI Attribute using tblgen to CMake.
PiperOrigin-RevId:
282415592
Andy Davis [Mon, 25 Nov 2019 20:39:30 +0000 (12:39 -0800)]
Update VectorContractionOp to take iterator types and index mapping attributes compatible with linalg ops.
PiperOrigin-RevId:
282412311