Commit Graph

2144 Commits

Author SHA1 Message Date
River Riddle 60a2983779 Fix a bug in the canonicalizer when replacing constants via patterns.
The GreedyPatternRewriteDriver currently does not notify the OperationFolder when constants are removed as part of a pattern match. This materializes in a nasty bug where a different operation may be allocated to the same address. This causes an assertion in the OperationFolder when it gets notified of the new operations removal.

PiperOrigin-RevId: 257817627
2019-07-12 17:42:24 -07:00
Nicolas Vasilache cab671d166 Lower affine control flow to std control flow to LLVM dialect
This CL splits the lowering of affine to LLVM into 2 parts:
1. affine -> std
2. std -> LLVM

The conversions mostly consists of splitting concerns between the affine and non-affine worlds from existing conversions.
Short-circuiting of affine `if` conditions was never tested or exercised and is removed in the process, it can be reintroduced later if needed.

LoopParametricTiling.cpp is updated to reflect the newly added ForOp::build.

PiperOrigin-RevId: 257794436
2019-07-12 08:44:28 -07:00
Denis Khalikov 884b94e038 [spirv] Add CompositeExtractOp operation.
CompositeExtractOp allows to extract a part of a composite object.

Closes tensorflow/mlir#44

PiperOrigin-RevId: 257790731
2019-07-12 08:44:21 -07:00
Alex Zinenko 2178467dca LoopsToGPU: use PassRegistration with constructor
PassRegistration with an optional constructor was introduced after the
LoopsToGPUPass, which resorted to deriving one pass from another as a means of
accepting options supplied as command-line arguments. Use PassRegistration with
constructor instead of defining a derived pass for LoopsToGPU.  Also rename the
pass to better reflect its current nature.

PiperOrigin-RevId: 257786923
2019-07-12 08:44:14 -07:00
Alex Zinenko f20f347fdb LinalgTilingPass: use PassRegistration with a pass constructor
Linalg tiling pass was introduced before PassRegistration with an optional pass
constructor.  It resorted to deriving a helper class from the origial pass
class in order to provide a default constructor with values obtained from
command line flags.  Use PassRegistration with the optional pass constructor
instead, which avoids declaring an additional class.

PiperOrigin-RevId: 257786876
2019-07-12 08:44:08 -07:00
Smit Hinsu e50da9efe8 NFC: Remove redundant call to registerPassManagerCLOptions from MLIR tutorial
main already calls registerPassManagerCLOptions.

TESTED = not (NFC)
PiperOrigin-RevId: 257722013
2019-07-12 08:44:02 -07:00
River Riddle 136ccd4948 Update the dialect attribute verifiers related to functions.
Remove the Function specific attribute verifier in favor of the general operation verifier. This also generalizes the function argument verifier to allow use for an argument attached to any region of any operation.

PiperOrigin-RevId: 257689962
2019-07-12 08:43:55 -07:00
Mahesh Ravishankar f93e95ed5f Add support for serialization/deserialization of OpTypeVoid and
OpTypeFunction

PiperOrigin-RevId: 257684235
2019-07-12 08:43:48 -07:00
River Riddle 9dbef0bf96 Rename FunctionAttr to SymbolRefAttr.
This allows for the attribute to hold symbolic references to other operations than FuncOp. This also allows for removing the dependence on FuncOp from the base Builder.

PiperOrigin-RevId: 257650017
2019-07-12 08:43:42 -07:00
Alex Zinenko 4dfe6d457b FuncOp::eraseBody: drop all references before erasing blocks
Operations in a block can use a value defined in a dominating block.  When a
block, and therefore all its operations, is deleted, the operations are not
allowed to have any remaining uses.  Drop all uses of values in all blocks
before deleting them in FuncOp::eraseBody to avoid deleting an operation before
deleting the users of its results.

PiperOrigin-RevId: 257628002
2019-07-12 08:43:35 -07:00
Alex Zinenko 65da460c79 affine.load/store: check for the right number of operands
Affine load and store operations take a variadic number of arguments, most of
which are interpreted as subscripts for the multi-dimensional memref they
access.  Add a verifier check that ensures the number of operands is equal to
the number affine remapping inputs if present and to the rank of the acessed
memref otherwise.  Although it is impossible to obtain such operations by
parsing the custom syntax, it is possible to construct them using the generic
syntax or programmatically.

PiperOrigin-RevId: 257605902
2019-07-12 08:43:29 -07:00
Nicolas Vasilache 4bbfb749bb Propagate linalg op attributes in transformations
Also fix the tile_conv test.

PiperOrigin-RevId: 257602321
2019-07-12 08:43:22 -07:00
Alex Zinenko 7ef559e0f2 mcuMemHostRegister: take into account sizeof(float)
cuMemHostRegister expects the size of registered memory in bytes whereas the
memref descriptor in memref_t contains the number of elements.  Get the actual
size in bytes instead.

PiperOrigin-RevId: 257589116
2019-07-12 08:43:15 -07:00
Mahesh Ravishankar 801efec9e6 Update the gen_spirv_dialect.py script to add opcodes from the SPIR-V
JSON spec into the SPIRBase.td file. This is done incrementally to
only import those opcodes that are needed, through use of the script
define_opcode.sh added.

PiperOrigin-RevId: 257517343
2019-07-12 08:43:09 -07:00
River Riddle 6da343ecfc NFC: Replace Module::getNamedFunction with lookupSymbol<FuncOp>.
This allows for removing the last direct reference to FuncOp from ModuleOp.

PiperOrigin-RevId: 257498296
2019-07-12 08:43:03 -07:00
River Riddle 122cab6770 Refactor the parsing/printing of the top-level module.
This changes the top-level module parser to handle the case where the top-level module is defined with the module operation syntax, i.e:
  module ... {
  }

The printer is also updated to always print the top-level module in this form. This allows for cleanly round-tripping the location and attributes of the top-level module.

PiperOrigin-RevId: 257492069
2019-07-12 08:42:56 -07:00
Nicolas Vasilache cb3f0d6f9b Fix BufferSizeOp type lowering to LLVM.
This fixes a bug where the result type was incorrect when lowering to LLVM.

PiperOrigin-RevId: 257449384
2019-07-12 08:42:49 -07:00
Alex Zinenko 7b530a88d5 PassRegistation: use overloads instead of a default argument
Windows build is not happy trying to convert a lambda into a constant reference
to a function in default arguments of the PassRegistration constructor.  Define
two overloaded constructors instead and construct the lambda as a variable in
the constructor body.

PiperOrigin-RevId: 257448633
2019-07-12 08:42:42 -07:00
River Riddle 1b247a1247 Drop the trailing newline from the FuncOp syntax.
The ModulePrinter prints the newline now for children of the top-level module. This also fixes the location printing for functions as the location used to be printed on a different line.

PiperOrigin-RevId: 257447633
2019-07-12 08:42:35 -07:00
Alex Zinenko 054e25c079 EDSC: use affine.load/store instead of std.load/store
Standard load and store operations are evolving to be separated from the Affine
constructs.  Special affine.load/store have been introduced to uphold the
restrictions of the Affine control flow constructs on their operands.
EDSC-produced loads and stores were originally intended to uphold those
restrictions as well so they should use affine.load/store instead of
std.load/store.

PiperOrigin-RevId: 257443307
2019-07-12 08:42:28 -07:00
River Riddle b3e28fca53 NFC: Remove Function::getModule.
There is already a more general 'getParentOfType' method, and 'getModule' is likely to be misused as functions get placed within different regions than ModuleOp.

PiperOrigin-RevId: 257442243
2019-07-12 08:42:21 -07:00
Nicolas Vasilache 68edb3ba75 Delete dead code
AffineIfOp::build is not tested or exercised anywhere. It also perpetuates a questionable choice of encoding an optional region as an empty region which we would like to change in the future.
PiperOrigin-RevId: 257439832
2019-07-12 08:42:13 -07:00
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