summaryrefslogtreecommitdiffstats
path: root/mlir/lib
Commit message (Collapse)AuthorAgeFilesLines
...
* Add support for instance specific pass statistics.River Riddle2019-12-056-23/+331
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Allow specification of the workgroup size for GPUToSPIRV lowering.Mahesh Ravishankar2019-12-053-11/+48
| | | | | | | | | | 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
* Add spv.AtomicCompareExchangeWeakLei Zhang2019-12-051-0/+77
| | | | PiperOrigin-RevId: 283997917
* Add a flag to dump the current stack trace when emitting a diagnostic.River Riddle2019-12-051-0/+19
| | | | | | 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
* [spirv] Fix nested loop (de)serializationLei Zhang2019-12-052-45/+108
| | | | | | | | | | | | | | | | | | | | | | 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
* Fix MLIR Build after LLVM upstream JIT changes (getMainJITDylib removed)Mehdi Amini2019-12-051-1/+4
| | | | | | The getMainJITDylib() method was removed in 4fc68b9b7f, replace it by creating a JITDylib on the fly. PiperOrigin-RevId: 283948595
* Move ModuleManager functionality into mlir::SymbolTable.Tres Popp2019-12-052-30/+49
| | | | | | | | | | 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
* Add MLIRIR as a dependency to LLVM and related dialectsLei Zhang2019-12-041-3/+3
| | | | | | Fixes tensorflow/mlir#289 PiperOrigin-RevId: 283914472
* Optimize operation ordering to support non-congruent indices.River Riddle2019-12-042-9/+76
| | | | | | 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
* Add emitOptional(Error|Warning|Remark) functions to simplify emission with ↵River Riddle2019-12-044-153/+85
| | | | | | | | | | | | | | | | | | 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
* Add a CL option to Standard to LLVM lowering to use alloca instead of ↵Nicolas Vasilache2019-12-041-35/+89
| | | | | | | | | 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
* Add canonicalization patterns for vector CreateMaskOp and StridedSliceOp to ↵Andy Davis2019-12-041-4/+158
| | | | | | | | | | | 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
* [CSE] NFC: Hash the attribute dictionary pointer instead of the list of ↵River Riddle2019-12-041-2/+2
| | | | | | attributes. PiperOrigin-RevId: 283810829
* Drop MaterializeVectorTransfers in favor of simpler declarative unrollingNicolas Vasilache2019-12-043-792/+14
| | | | | | 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
* NFC: Fix mismatches between LangRef.md and actual parser implementation.River Riddle2019-12-042-6/+10
| | | | PiperOrigin-RevId: 283805832
* Print out large elementsattr's such that they are parseable.Sean Silva2019-12-041-15/+27
| | | | | | | | | | | 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
* NFC - fix name / comments - isAccessInvariantUday Bondhugula2019-12-041-3/+18
| | | | | | | | | | | | | | | - 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
* Loop coalescing: fix pointer chainsing in use-chain traversalAlex Zinenko2019-12-041-1/+1
| | | | | | | | | | | | | | | 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
* Adds support for unrolling single-result vector operations with iterator ↵Andy Davis2019-12-042-21/+287
| | | | | | | | 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
* Refactor dependencies to expose Vector transformations as patterns - NFCNicolas Vasilache2019-12-0315-46/+64
| | | | | | | | | 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
* [spirv] Add spv.GroupNonUniformBallotLei Zhang2019-12-031-0/+40
| | | | | | | | | 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
* Add a pass to legalize operations before lowering to SPIR-V.Mahesh Ravishankar2019-12-034-1/+230
| | | | | | | | | | | | 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
* Make diagnostic a bit clearer.Sean Silva2019-12-031-1/+1
| | | | | | This prints out in case of any pass failure. Not just a crash. PiperOrigin-RevId: 283616719
* Add CreateMaskOp to the VectorOps dialect.Andy Davis2019-12-031-0/+31
| | | | PiperOrigin-RevId: 283591888
* Verifier: Better error message in case of successor operand mismatch.Sean Silva2019-12-031-6/+9
| | | | | | In particular, print the successor number in the diagnostic. PiperOrigin-RevId: 283585084
* Convert MemRefType to a linearized array in SPIR-V lowering.Mahesh Ravishankar2019-12-032-70/+98
| | | | | | | | | | | | | | | 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
* Fix ViewOp to have at most one offset operandAlex Zinenko2019-12-032-8/+19
| | | | | | | | | | | | | | | | | | | | | 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
* AffineLoopFusion: Prevent fusion of multi-out-edge producer loopsDiego Caballero2019-12-031-3/+5
| | | | | | | | | | | | | 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
* Extend conversion of SubViewOp to llvm to also support cases where size and ↵Stephan Herhut2019-12-031-6/+24
| | | | | | | | | | | | 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
* [spirv] Add spv.SubgroupBallotKHROpLei Zhang2019-12-031-3/+24
| | | | PiperOrigin-RevId: 283522284
* Add linkage support to LLVMFuncOpAlex Zinenko2019-12-034-45/+132
| | | | | | | | | 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
* [VectorOps] Add legality rules to broadcastAart Bik2019-12-021-3/+10
| | | | PiperOrigin-RevId: 283360101
* [ODS] Generate builders taking unwrapped value and defaults for attributesLei Zhang2019-12-021-2/+2
| | | | | | | | | | | | | | | | | | 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
* [DRR] Introduce `$_` to ignore op argument matchLei Zhang2019-12-021-1/+2
| | | | | | | | 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
* NFC: Update std.subview op to use AttrSizedOperandSegmentsLei Zhang2019-12-023-79/+55
| | | | | | This turns a few manually written helper methods into auto-generated ones. PiperOrigin-RevId: 283339617
* Lower linalg.indexed_generic with libcall to LLVM.Alexander Belyaev2019-12-021-1/+57
| | | | PiperOrigin-RevId: 283328994
* Introduce Linkage attribute to the LLVM dialectAlex Zinenko2019-12-025-17/+163
| | | | | | | | | | | 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
* Fix redundant convert and use NamedAttributeList as valueJacques Pienaar2019-11-291-6/+6
| | | | | | | | * 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
* [spirv] Check that operand of `spirv::CompositeExtractOp` is constant while ↵Denis Khalikov2019-11-281-0/+3
| | | | | | | | | 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
* Split out FunctionLike printing/parsing into FunctionImplementation.{h,cpp}Alex Zinenko2019-11-284-3/+6
| | | | | | | | | | | 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
* NFC: A few cleanups for SPIRVLoweringLei Zhang2019-11-271-51/+53
| | | | | | | Updated comments and used static instead of anonymous namspace to hide functions to be consistent with the existing codebase. PiperOrigin-RevId: 282847784
* [spirv] NFC: Add getZero() and getOne() static method to ConstantOpLei Zhang2019-11-273-4/+32
| | | | | | | Getting constant zero or one is very common so it merits a special handy method on spirv::ConstantOp itself. PiperOrigin-RevId: 282832572
* [spirv] Add folders for spv.IAdd and spv.IMulLei Zhang2019-11-271-0/+30
| | | | | | | | | 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
* Implement Linalg to loops lowering as a patternNicolas Vasilache2019-11-272-111/+205
| | | | | | 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
* [VectorOps] Refine BroadcastOp in VectorOps dialectAart Bik2019-11-261-10/+8
| | | | | | | | 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
* Add create method that takes equivalent of OperationState with ↵Jacques Pienaar2019-11-261-6/+19
| | | | | | | | | | | | | 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
* [VectorOps] Add a BroadcastOp to the VectorOps dialectAart Bik2019-11-261-0/+41
| | | | PiperOrigin-RevId: 282643305
* Misc changes to lowering to SPIR-V.Mahesh Ravishankar2019-11-264-38/+141
| | | | | | | | | | | | | | | 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
* Relax restriction on affine_apply dim and symbol operandsNicolas Vasilache2019-11-261-5/+0
| | | | | | | | | | | | | | | | | | 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
* Add support for AttrSizedOperandSegments/AttrSizedResultSegmentsLei Zhang2019-11-252-6/+47
| | | | | | | | | | | | | | | | | 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
OpenPOWER on IntegriCloud