Commit Graph

2172 Commits

Author SHA1 Message Date
River Riddle fec20e590f NFC: Rename Module to ModuleOp.
Module is a legacy name that only exists as a typedef of ModuleOp.

PiperOrigin-RevId: 257427248
2019-07-10 10:11:21 -07:00
River Riddle 6b6dc59f30 Update ModuleOp::create(...) to take a Location instead of a context.
This allows for giving a Module a more interesting location than 'Unknown'.

PiperOrigin-RevId: 257310117
2019-07-10 10:11:00 -07:00
River Riddle 8c44367891 NFC: Rename Function to FuncOp.
PiperOrigin-RevId: 257293379
2019-07-10 10:10:53 -07:00
Jacques Pienaar 847c2355fd Constrain regex to avoid ordering issues.
PiperOrigin-RevId: 257257173
2019-07-09 13:17:57 -07:00
River Riddle e0dd5f98c4 Relax the restriction that Modules cannot contain operations producing results.
This was an arbitrary restriction caused by the way that modules were printed. Now that that has been fixed, this restriction can be removed.

PiperOrigin-RevId: 257240329
2019-07-09 11:50:13 -07:00
River Riddle 89bc449cee Standardize the value numbering in the AsmPrinter.
Change the AsmPrinter to number values breadth-first so that values in adjacent regions can have the same name. This allows for ModuleOp to contain operations that produce results. This also standardizes the special name of region entry arguments to "arg[0-9+]" now that Functions are also operations.

PiperOrigin-RevId: 257225069
2019-07-09 10:41:00 -07:00
Alex Zinenko 4cabebf04d Add parentheses around boolean operators in an assertion in
Linalg/Transforms/Tiling.cpp.  This fixes a warning.

PiperOrigin-RevId: 257191302
2019-07-09 07:51:45 -07:00
Alex Zinenko 7a2e8726e8 Fix a test broken on some systems due to a mis-rebase.
PiperOrigin-RevId: 257190161
2019-07-09 07:43:42 -07:00
Alex Zinenko 9d03f5674f Implement parametric tiling on standard for loops
Parametric tiling can be used to extract outer loops with fixed number of
iterations.  This in turn enables mapping to GPU kernels on a fixed grid
independently of the range of the original loops, which may be unknown
statically, making the kernel adaptable to different sizes.  Provide a utility
function that also computes the parametric tile size given the range of the
loop.  Exercise the utility function through a simple pass that applies it to
all top-level loop nests.  Permutability or parallelism checks must be
performed before calling this utility function in actual passes.

Note that parametric tiling cannot be implemented in a purely affine way,
although it can be encoded using semi-affine maps.  The choice to implement it
on standard loops is guided by them being the common representation between
Affine loops, Linalg and GPU kernels.

PiperOrigin-RevId: 257180251
2019-07-09 06:37:41 -07:00
Alex Zinenko 80e2871087 Extend AffineToGPU to support Linalg loops
Extend the utility that converts affine loop nests to support other types of
loops by abstracting away common behavior through templates.  This also
slightly simplifies the existing Affine to GPU conversion by always passing in
the loop step as an additional kernel argument even though it is a known
constant.  If it is used, it will be propagated into the loop body by the
existing canonicalization pattern and can be further constant-folded, otherwise
it will be dropped by canonicalization.

This prepares for the common loop abstraction that will be used for converting
to GPU kernels, which is conceptually close to Linalg loops, while maintaining
the existing conversion operational.

PiperOrigin-RevId: 257172216
2019-07-09 05:26:50 -07:00
River Riddle 2002087f1a NFC: Change a usage of StringLiteral to StringRef.
This matches the result type of other functions returning c-string, and fixes a build failure where some compilers fail to construct the StringLiteral.

PiperOrigin-RevId: 257139513
2019-07-09 00:59:08 -07:00
River Riddle ee8e8b5539 Generalize the symbol table functionality of ModuleOp into a trait 'OpTrait::SymbolTable'.
Operations must only contain a single region.  Once attached, all operations that contain a 'mlir::SymbolTable::getSymbolAttrName()' StringAttr attribute within the child region will be verified to ensure that the names are uniqued. Operations using this trait also gain access to the 'SymbolTable' class, which can be used to manage the symbol table of the operation. This class also provides constant-time lookup of symbols by name, and will automatically rename symbols on insertion.

PiperOrigin-RevId: 257123573
2019-07-08 22:31:56 -07:00
River Riddle 626b8b6a5d NFC: Remove `Module::getFunctions` in favor of a general `getOps<T>`.
Modules can now contain more than just Functions, this just updates the iteration API to reflect that. The 'begin'/'end' methods have also been updated to iterate over opaque Operations.

PiperOrigin-RevId: 257099084
2019-07-08 18:28:17 -07:00
River Riddle 5e4f8b7e7b NFC: Make the 'disable-pass-threading' flag a PassManagerOption.
This also adds the ability to programmatically disable threading.

PiperOrigin-RevId: 257051809
2019-07-08 14:16:08 -07:00
Jacques Pienaar 86580e71d2 Remove dead code.
PiperOrigin-RevId: 257050780
2019-07-08 14:15:20 -07:00
Lei Zhang 891a7911c2 Add dependencies for standard ops to SPIR-V conversion
PiperOrigin-RevId: 257026374
2019-07-08 12:40:21 -07:00
Jacques Pienaar 504d58affe Add missing override.
PiperOrigin-RevId: 257024265
2019-07-08 12:40:15 -07:00
River Riddle ce502af9cd NFC: Remove the various "::getFunction" methods.
These methods assume that a function is a valid builtin top-level operation, and removing these methods allows for decoupling FuncOp and IR/. Utility "getParentOfType" methods have been added to Operation/OpState to allow for querying the first parent operation of a given type.

PiperOrigin-RevId: 257018913
2019-07-08 12:40:08 -07:00
River Riddle d3a85cc77d NFC: Add AbstractOperation as a friend of 'Op'.
This allows for accessing the hidden overload of 'Op::hasTrait'.

PiperOrigin-RevId: 257018255
2019-07-08 12:40:02 -07:00
Mahesh Ravishankar f2fb3d1909 Add Ops in SPIR-V Dialect corresponding to OpEntryPoint and OpExecutionMode
PiperOrigin-RevId: 257013183
2019-07-08 12:39:55 -07:00
Jacques Pienaar ea2117e567 Remove dead code.
PiperOrigin-RevId: 257012369
2019-07-08 12:39:48 -07:00
River Riddle 02975d7033 Add 'hasTrait' support to Operation.
This is accomplished by adding a new callback to AbstractOperation that takes a ClassID for a given trait type and compares that against the ClassIDs for the traits used when registering an operation. This allows for opaquely querying if an operation was registered with a given trait, e.g:

Operation *op = ...;
bool singleResult = op->hasTrait<OpTrait::OneResult>();

PiperOrigin-RevId: 257007710
2019-07-08 12:39:42 -07:00
Lei Zhang 50a4c89e8f [spirv] NFC: Remove functions wrapping spv.module in tests
Now both functions and modules are just general ops and we do not require
top-level entities in a module's block to be the old builtin functions
any more. Removing the wrapping functions to simplify the tests.

PiperOrigin-RevId: 257003572
2019-07-08 12:39:35 -07:00
Jacques Pienaar b3e7bb0498 Add missing overrides.
PiperOrigin-RevId: 256995548
2019-07-08 12:39:28 -07:00
Jacques Pienaar 01d042a123 Remove std::move of trivially-copyable type.
Address ClangTidy finding:

* std::move of the expression of the trivially-copyable type 'mlir::Module' (aka 'mlir::ModuleOp') has no effect; remove std::move()

PiperOrigin-RevId: 256981849
2019-07-08 12:39:21 -07:00
Jacques Pienaar 3898e100c8 Include missing header.
This target was failing to build with newer version of libc++.

PiperOrigin-RevId: 256979592
2019-07-08 08:05:09 -07:00
Alex Zinenko a89b8aecca LinalgOp::Model: add missing override specifiers
All non-static functions in LinalgOp::Model override pure virtual functions
from LinalgOp::Concept, but only some of them have the `override` specifier.
This may lead one to erroneously believe the functions without the specified
are not overrides or virtual functions.  Add the specifier to all relevant
functions.

PiperOrigin-RevId: 256948453
2019-07-08 04:18:14 -07:00
Jacques Pienaar 7e74ee8ff7 Use isa instead of dyn_cast as cast value isn't used.
Avoids unused variable warning.

PiperOrigin-RevId: 256874512
2019-07-07 14:05:16 -07:00
Lei Zhang 7bf65a0086 Migrate NativeCodeCall and AllAttrConstraintsOf tests to use TestDialect
PiperOrigin-RevId: 256685260
2019-07-05 10:05:43 -07:00
Lei Zhang 80381abfd0 Migrate pattern attribute matching tests to use TestDialect
This CL also reorders op definitions and tests a bit to make them
group more logically.

PiperOrigin-RevId: 256682105
2019-07-05 09:24:15 -07:00
Nicolas Vasilache afadfebe9c Move StdForOp to ODS ForOp
PiperOrigin-RevId: 256657155
2019-07-05 05:05:19 -07:00
Nicolas Vasilache 991040478b Add a standard if op
This CL adds an "std.if" op to represent an if-then-else construct whose condition is an arbitrary value of type i1.
This is necessary to lower all the existing examples from affine and linalg to std.for + std.if.

This CL introduces the op and adds the relevant positive and negative unit test. Lowering will be done in a separate followup CL.

PiperOrigin-RevId: 256649138
2019-07-05 03:35:18 -07:00
Alex Zinenko 471da08e4e Simplify launch_func rewrite pattern in mlir-cuda-runner
Use the bulk setOperands on the cloned operation, no need to cast or iterate
over the operand list.

PiperOrigin-RevId: 256643496
2019-07-05 02:51:53 -07:00
Alex Zinenko ead1acaef2 ODS: provide a flag to skip generation of default build methods
Some operations need to override the default behavior of builders, in
particular region-holding operations such as affine.for or tf.graph want to
inject default terminators into the region upon construction, which default
builders won't do.  Provide a flag that disables the generation of default
builders so that the custom builders could use the same function signatures.
This is an intentionally low-level and heavy-weight feature that requires the
entire builder to be implemented, and it should be used sparingly.  Injecting
code into the end of a default builder would depend on the naming scheme of the
default builder arguments that is not visible in the ODS.  Checking that the
signature of a custom builder conflicts with that of a default builder to
prevent emission would require teaching ODG to differentiate between types and
(optional) argument names in the generated C++ code.  If this flag ends up
being used a lot, we should consider adding traits that inject specific code
into the default builder.

PiperOrigin-RevId: 256640069
2019-07-05 02:28:05 -07:00
Nicolas Vasilache 8c6a3ace16 Add ODS accessors for named regions.
PiperOrigin-RevId: 256639471
2019-07-05 02:21:06 -07:00
Chris Lattner 75ae06acf3 Trivial typo in comment fix.
PiperOrigin-RevId: 256616187
2019-07-04 22:18:12 -07:00
River Riddle 474e354179 NFC: Remove Region::getContainingFunction as Functions are now Operations.
PiperOrigin-RevId: 256579717
2019-07-04 13:23:10 -07:00
Alex Zinenko fa6b49b095 Fix another incorrect forward declaration of LogicalResult
LogicalResult is a struct and the Windows build is unhappy about it being
forward-declared as class.

PiperOrigin-RevId: 256578230
2019-07-04 13:05:54 -07:00
Alex Zinenko abc722a582 Forward-declare LogicalResult as struct
LogicalResult is a struct but some headers forward-declare it as a class, which
breaks Windows builds.  Forward-delcare as a struct instead.

PiperOrigin-RevId: 256565699
2019-07-04 10:17:11 -07:00
Alex Zinenko 6f7f2bced8 Make TranslateFromMLIRFunction type return LogicalResult instead of bool
This interface was created before MLIR introduced LogicalResult.

PiperOrigin-RevId: 256554557
2019-07-04 08:19:14 -07:00
Stephan Herhut e8b21a75f8 Add an mlir-cuda-runner tool.
This tool allows to execute MLIR IR snippets written in the GPU dialect
on a CUDA capable GPU. For this to work, a working CUDA install is required
and the build has to be configured with MLIR_CUDA_RUNNER_ENABLED set to 1.

PiperOrigin-RevId: 256551415
2019-07-04 07:53:54 -07:00
Alex Zinenko bd17bd299f AllocOp: drop redundant verifier check
The equality check between the rank of a memref and the input size of the
layout affine map in AllocOp::verify is subsumed by the well-formedness check
of the memref type itself.  Drop the redundant check from the verifier since it
is never exercised (the type builder does not allow one to construct a type
that would not pass the verifier check).

PiperOrigin-RevId: 256551247
2019-07-04 07:53:42 -07:00
Stephan Herhut 1bcaa3185d Add missing mlir:: namespace in definition of createConvertToLLVMIRPass.
PiperOrigin-RevId: 256546769
2019-07-04 07:53:31 -07:00
Alex Zinenko 9a1b6fec79 Make ConvertStandardToLLVMPass extendable with other patterns
Extend the LLVM lowering pass to accept callbacks that construct an instance of
(a subclass of) LLVMTypeConverter and populate a list of conversion patterns.
These callbacks will be called when the pass processes a module and their
results will be used to set up the dialect conversion infrastructure.  Clients
can now provide additional conversion patterns to avoid the need of
materializing type conversions between LLVM and other types.

PiperOrigin-RevId: 256532415
2019-07-04 07:53:19 -07:00
Mahesh Ravishankar 82679d4718 NFC: Refactoring to remove code bloat in SPIRV due to handling of Enum
Class Attribute parsing

PiperOrigin-RevId: 256471248
2019-07-03 18:18:01 -07:00
Lei Zhang 9cde4be7a5 [TableGen] Support creating multi-result ops in result patterns
This CL introduces a new syntax for creating multi-result ops and access their
results in result patterns. Specifically, if a multi-result op is unbound or
bound to a name without a trailing `__N` suffix, it will act as a value pack
and expand to all its values. If a multi-result op is bound to a symbol with
`__N` suffix, only the N-th result will be extracted and used.

PiperOrigin-RevId: 256465208
2019-07-03 18:17:49 -07:00
River Riddle e7d594bb1c Replace the implementation of Function and Module with FuncOp and ModuleOp.
This is an important step in allowing for the top-level of the IR to be extensible. FuncOp and ModuleOp contain all of the necessary functionality, while using the existing operation infrastructure. As an interim step, many of the usages of Function and Module, including the name, will remain the same. In the future, many of these will be relaxed to allow for many different types of top-level operations to co-exist.

PiperOrigin-RevId: 256427100
2019-07-03 14:37:18 -07:00
Andy Davis 2e1187dd25 Globally change load/store/dma_start/dma_wait operations over to affine.load/store/dma_start/dma_wait.
In most places, this is just a name change (with the exception of affine.dma_start swapping the operand positions of its tag memref and num_elements operands).
Significant code changes occur here:
*) Vectorization: LoopAnalysis.cpp, Vectorize.cpp
*) Affine Transforms: Transforms/Utils/Utils.cpp

PiperOrigin-RevId: 256395088
2019-07-03 14:37:06 -07:00
Nicolas Vasilache 28fb743798 More general subview calculation in tiling
This CL refactors tiling to enable tiling of views that are not just specified by a simple permutation. This allows the tiling of convolutions for which a new example is added.

PiperOrigin-RevId: 256346028
2019-07-03 14:36:42 -07:00
Nicolas Vasilache 0024ddc4ae Add a generic loop abstraction to the std dialect
This CL is the first step of a refactoring unification of the control flow abstraction used in different dialects. The `std.for` loop accepts unrestricted indices to encode min, max and step and will be used as a common abstraction on the way to lower level dialects.

PiperOrigin-RevId: 256331795
2019-07-03 14:36:30 -07:00