Commit Graph

793 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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 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
Jacques Pienaar b3e7bb0498 Add missing overrides.
PiperOrigin-RevId: 256995548
2019-07-08 12:39:28 -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
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
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
Mahesh Ravishankar c73edeec13 Add support for SPIR-V Struct Types. Current support is limited to
supporting only Offset decorations

PiperOrigin-RevId: 256216704
2019-07-02 16:43:36 -07:00
River Riddle 206e55cc16 NFC: Refactor Module to be value typed.
As with Functions, Module will soon become an operation, which are value-typed. This eases the transition from Module to ModuleOp. A new class, OwningModuleRef is provided to allow for owning a reference to a Module, and will auto-delete the held module on destruction.

PiperOrigin-RevId: 256196193
2019-07-02 16:43:36 -07:00
River Riddle 25f29e1b15 NFC: Update the Operation 'walk' methods to use llvm::function_ref instead of std::function.
PiperOrigin-RevId: 256099638
2019-07-02 10:28:12 -07:00
Alex Zinenko 0b468b0101 gpu::LaunchOp: canonicalize away constant kernel arguments
The GPU Launch operation may take constants as arguments, in particular
affine-to-GPU mapping pass automatically forwards potentially constant lower
bounds of loops into the kernel.  Define a canonicalization pattern for
LaunchOp that recreates the constants inside the kernel region instead of
accepting them as kernel arguments.  This is currently restricted to standard
constants but may be extended to other constant operations.

Also fix an off-by-one indexing bug in OperandStorage::eraseOperand.

PiperOrigin-RevId: 256035437
2019-07-01 17:03:03 -07:00
River Riddle 694975ddbc Standardize the definition and usage of getAllArgAttrs between FuncOp and Function.
PiperOrigin-RevId: 255988352
2019-07-01 11:39:12 -07:00
River Riddle 54cd6a7e97 NFC: Refactor Function to be value typed.
Move the data members out of Function and into a new impl storage class 'FunctionStorage'. This allows for Function to become value typed, which will greatly simplify the transition of Function to FuncOp(given that FuncOp is also value typed).

PiperOrigin-RevId: 255983022
2019-07-01 11:39:00 -07:00
River Riddle 8c47e2ed5c Extract the automatic function renaming and symbol table out of Module.
This functionality is now moved to a new class, ModuleManager. This class allows for inserting functions into a module, and will auto-rename them on insert to ensure a unique name. This now means that users adding new functions to a module must ensure that the function name is unique, as the Module will no longer do it automatically. This also means that Module::getNamedFunction now operates in O(N) instead of the O(c) time it did before. This simplifies the move of Modules to Operations as the ModuleOp will not be able to have this functionality.

PiperOrigin-RevId: 255846088
2019-07-01 09:55:13 -07:00
River Riddle 929466b5c9 Cleanup the 'clone' methods and remove the need to explicitly pass in the context.
This also adds a new 'Region::cloneInto' method that accepts an insertion position.

PiperOrigin-RevId: 255504640
2019-06-27 16:43:18 -07:00
River Riddle bda669beea Allow attaching a type to StringAttr.
Some dialects allow for string types, and this allows for reusing StringAttr for constants of these types.

PiperOrigin-RevId: 255413948
2019-06-27 09:13:44 -07:00
River Riddle 6ebd6df69f Add a new AttributeElementIterator to DenseElementsAttr.
This allows for iterating over the internal elements via an iterator_range of Attribute, and also allows for removing the final SmallVectorImpl based 'getValues' method.

PiperOrigin-RevId: 255309555
2019-06-26 18:50:18 -07:00
River Riddle 260d3e39ad Standardize and refactor Attribute type printing.
Remove the ability to print an attribute without a type, but allow for attributes to elide the type under certain circumstances. This fixes a bug where attributes within ArrayAttr, and other collection attributes, would never print the type.

PiperOrigin-RevId: 255306974
2019-06-26 18:29:54 -07:00
River Riddle a4c3a6455c Move the emitError/Warning/Remark utility methods out of MLIRContext and into the mlir namespace.
Now that Locations are attributes, they have direct access to the MLIR context. This allows for simplifying error emission by removing unnecessary context lookups.

PiperOrigin-RevId: 255112791
2019-06-25 21:32:23 -07:00
River Riddle 679a3b4191 Change the attribute dictionary syntax to separate name and value with '='.
The current syntax separates the name and value with ':', but ':' is already overloaded by several other things(e.g. trailing types). This makes the syntax difficult to parse in some situtations:

Old:
  "foo: 10 : i32"

New:
  "foo = 10 : i32"
PiperOrigin-RevId: 255097928
2019-06-25 19:06:34 -07:00
River Riddle 49162524d8 NFC: Uniformize the return of the LocationAttr 'get' methods to 'Location'.
PiperOrigin-RevId: 255078768
2019-06-25 16:57:56 -07:00
River Riddle 4842b2d42e Modify the syntax of the the ElementsAttrs to print the type as a colon type.
This is the standard syntax for types on operations, and is also already used by IntegerAttr and FloatAttr.

Example:
  dense<5> : tensor<i32>
  dense<[3]> : tensor<1xi32>
PiperOrigin-RevId: 255069157
2019-06-25 16:06:58 -07:00
River Riddle 3ca33a5c62 Move the IndexedAccessorIterator to STLExtras to allow for reuse.
This iterator is useful for implementing random access iterators based upon an index and an object pointer. Moving it to STLExtras allows for reuse elsewhere throughout the codebase, e.g. simplifying the DenseElementsAttr iterators.

PiperOrigin-RevId: 255020377
2019-06-25 12:11:14 -07:00
Andy Davis 91f27d025b Support printing SSA ids in affine.load/store which do not have special names.
PiperOrigin-RevId: 254997746
2019-06-25 10:30:26 -07:00
River Riddle 52ba785758 NFC: Simplify Operation::getContext to use the context within the location.
PiperOrigin-RevId: 254771979
2019-06-24 13:49:38 -07:00
Andy Davis 3df510bf42 Add parsing/printing for new affine.load and affine.store operations.
The new operations affine.load and affine.store will take composed affine maps by construction.
These operations will eventually replace load and store operations currently used in affine regions and operated on by affine transformation and analysis passes.

PiperOrigin-RevId: 254754048
2019-06-24 13:45:09 -07:00
River Riddle 650dc4bb65 Allow converting Diagnostic to LogicalResult::Failure. This matches the behavior of InFlightDiagnostic and enables notes to be converted to failure.
PiperOrigin-RevId: 254579098
2019-06-24 13:44:22 -07:00
River Riddle 48d6cf1ced NFC: Remove the 'context' parameter from OperationState.
Now that Locations are Attributes they contain a direct reference to the MLIRContext, i.e. the context can be directly accessed from the given location instead of being explicitly passed in.

PiperOrigin-RevId: 254568329
2019-06-22 13:05:10 -07:00
River Riddle 25734596e4 Define a ModuleOp that represents a Module as an Operation.
The ModuleOp contains a single region that must contain a single block. This block must be terminated by a new pseudo operation 'module_terminator'. The syntax for this operations is as follows:

  `module` (`attributes` attr-dict)? region

Example:

  module {
    ...
  }

  module attributes { ... } {
    ...
  }

PiperOrigin-RevId: 254513752
2019-06-22 09:18:36 -07:00
Nicolas Vasilache 4a1df48f44 Add a Linalg convolution op.
This CL adds a conv op that corresponds to the TF description along with its lowering to loops (https://www.tensorflow.org/api_docs/python/tf/nn/convolution).

The dimension of the convolution is inferred from the rank of the views. The other logical
dimensions correspond to the TF description.

The computation of tiled views need to be updated to work for the input tensor. This is left for a future CL.

PiperOrigin-RevId: 254505644
2019-06-22 09:18:06 -07:00
River Riddle 36b7c2da1d Refactor the location classes to be attributes instead of separate IR classes.
This will allow for locations to be used in the same contexts as attributes. Given that attributes are nullable types, the 'Location' class now represents a non-nullable wrapper around a 'LocationAttr'. This preserves the desired semantics we have for non-optional locations.

PiperOrigin-RevId: 254505278
2019-06-22 09:17:51 -07:00
River Riddle e4f8f3bc35 Simplify PredecessorIterator by using mapped_iterator.
PiperOrigin-RevId: 254495164
2019-06-22 09:17:36 -07:00
River Riddle d080efefe0 Cache instances of several common attributes(e.g. BoolAttr, UnitAttr) and types(I1/I16/I32/etc.) when creating the MLIRContext. This allows for these symbols to be accessed without the need to perform any lookups/locking.
PiperOrigin-RevId: 254410080
2019-06-22 09:15:51 -07:00
Nicolas Vasilache 235e2fe030 Support for 0-D case in Linalg ops
This CL adds support for O-D ops in Linalg ops by:
1. making the CopyOp maps optional instead of default valued
2. allowing certain map operations to accept and return empty maps
3. making linalg::LowerToLoops aware of these changes
4. providing a proper 0-D impl for CopyOp and FillOp
5. adding the relevant tests

PiperOrigin-RevId: 254381908
2019-06-22 09:15:36 -07:00
River Riddle 3e99d99553 Add an overload to 'PatternRewriter::inlineRegionBefore' that accepts a parent region for the insertion position. This allows for inlining the given region into the end of another region.
PiperOrigin-RevId: 254367375
2019-06-22 09:15:21 -07:00
River Riddle 9764ae3f24 Refactor the TypeConverter to support more robust type conversions:
* Support for 1->0 type mappings, i.e. when the argument is being removed.
* Reordering types when converting a type signature.
* Adding new inputs when converting a type signature.

This cl also lays down the initial foundation for supporting 1->N type mappings, but full support will come in a followup.

Moving forward, function signature changes will be driven by populating a SignatureConversion instance. This class contains all of the necessary information for adding/removing/remapping function signatures; e.g. addInputs, addResults, remapInputs, etc.

PiperOrigin-RevId: 254064665
2019-06-19 23:08:33 -07:00
River Riddle 927b7074a8 Extract the function symbol table functionality, i.e. mapping and name uniquing, out of Module and into a new class SymbolTable. As modules become operations it is necessary to extract out this functionality that cannot be represented with a generic operation.
PiperOrigin-RevId: 254041734
2019-06-19 23:08:22 -07:00
River Riddle 30bbd91056 Simplify usages of SplatElementsAttr now that it inherits from DenseElementsAttr.
PiperOrigin-RevId: 253910543
2019-06-19 23:07:34 -07:00
River Riddle 18743a33ac NFC: Reorder the attribute classes alphabetically to improve readability.
PiperOrigin-RevId: 253894445
2019-06-19 23:07:24 -07:00
River Riddle 34cb51743d NFC: Append 'Location' to the end of each the location kinds. This is in preparation for making the location classes attributes instead of separate IR types.
PiperOrigin-RevId: 253860058
2019-06-19 23:07:15 -07:00
River Riddle dee282c7da Replace usages of 'UniquedFilename' with 'Identifier' and remove it. Identifier already contains all of the necessary functionality/verification, so having a separate class for filenames is unnecessary.
PiperOrigin-RevId: 253855505
2019-06-19 23:07:05 -07:00
River Riddle 2b67821b90 Fix the detection of boolean splat values in DenseElementsAttr for arrays with <=15 values.
PiperOrigin-RevId: 253711372
2019-06-19 23:05:19 -07:00
Mehdi Amini 74df13fdda Refactor generic op printing: extract a public printFunctionalType() on OpAsmPrinter (NFC)
PiperOrigin-RevId: 253674584
2019-06-19 23:04:59 -07:00
Lei Zhang 31e2a6efe5 Also consider attributes when getting context for Operation
This CL also updates to use containing region as a fallback way to find
context since functions will eventually become ops with regions.

PiperOrigin-RevId: 253627322
2019-06-19 23:04:19 -07:00
Alex Zinenko 4291ae7431 Factor Region::getUsedValuesDefinedAbove into Transforms/RegionUtils
Arguably, this function is only useful for transformations and should not
pollute the main IR.  Also make sure it accepts a the resulting container
by-reference instead of returning it.

PiperOrigin-RevId: 253622981
2019-06-19 23:03:51 -07:00
Chris Lattner 05cf32162e Move the Region type out to its own .h/.cpp file instead of putting it into
Block.h/cpp.

This doesn't change much but makes it easier to find.

PiperOrigin-RevId: 253423041
2019-06-19 23:03:20 -07:00
Nicolas Vasilache e7e03cee1f Add Linalg CopyOp
This CL adds a generic CopyOp to Linalg and its lowering to loops.
The CopyOp supports input and output permutation maps.
When combined with tiling and allocating a new local buffer, this should provide basic support for implementing simple memory transfers with coalescing.

At the moment, lowering copies to a library call is not supported.

PiperOrigin-RevId: 253250497
2019-06-19 23:02:31 -07:00
Alex Zinenko ee6f84aebd Convert a nest affine loops to a GPU kernel
This converts entire loops into threads/blocks.  No check on the size of the
block or grid, or on the validity of parallelization is performed, it is under
the responsibility of the caller to strip-mine the loops and to perform the
dependence analysis before calling the conversion.

PiperOrigin-RevId: 253189268
2019-06-19 23:02:02 -07:00
River Riddle 6a0555a875 Refactor SplatElementsAttr to inherit from DenseElementsAttr as opposed to being a separate Attribute type. DenseElementsAttr provides a better internal representation for splat values as well as better API for accessing elements.
PiperOrigin-RevId: 253138287
2019-06-19 23:01:52 -07:00
River Riddle a0037a0473 NFC: Fix a warning for casting away const qualifiers.
PiperOrigin-RevId: 253124057
2019-06-19 23:01:31 -07:00
River Riddle 13461f5c33 Add several utility 'getValues<T>' functions to DenseElementsAttr that return ranges as opposed to filling a SmallVector. This is much more efficient for the general case and allows for avoiding constructing APInt/APFloat/Attribute when possible.
PiperOrigin-RevId: 253092550
2019-06-19 23:01:03 -07:00
River Riddle b5a34406a8 Update the Parser to support parsing/printing DenseElementAttrs with a splat value. The syntax for this is the same as 0-D tensors:
dense<tensor<100x100x100xi32>, 10>
  dense<tensor<1x1x1xi64>, -5>

PiperOrigin-RevId: 252907880
2019-06-19 23:00:24 -07:00
Alex Zinenko 867867a44d Fix static assertion in AttributeDetail.h
llvm::maskTrailingOnes<char> runs into a static assertion on the type not being
unsigned.  Use `unsigned char` instead of `char`.
PiperOrigin-RevId: 252827214
2019-06-19 22:59:45 -07:00
River Riddle d8cd96bc8b Refactor DenseElementsAttr to support auto-splatting the dense data on construction. This essentially means that we always auto-detect splat data and only store the minimum amount of data necessary. Support for parsing dense splats, and removing SplatElementsAttr(now that it is redundant) will come in followup cls
PiperOrigin-RevId: 252720561
2019-06-19 22:59:15 -07:00
River Riddle 420c1f383a Add a utility to OpAsmPrinter for printing an optional trailing arrow type list. This is useful for any operation that wants to print a set of types in the same format as a FunctionType/Operation signature.
PiperOrigin-RevId: 252647152
2019-06-19 22:58:16 -07:00
Alex Zinenko 8ad35b90ec Use DialectConversion to lower the Affine dialect to the Standard dialect
This introduces the support for region-containing operations to the dialect
conversion framework in order to support the conversion of affine control-flow
operations into the standard control flow with branches.  Regions that belong
to an operation are converted before the operation itself.  The
DialectConversionPattern can therefore access the converted regions of the
original operation and process them further if necessary.  In particular, the
conversion is allowed to move the blocks from the original region to other
regions and to split blocks into multiple blocks.  All block manipulations must
be performed through the PatternRewriter to ensure they will be undone if the
conversion fails.

Port the pass converting from the affine dialect (loops and ifs with bodies as
regions) to the standard dialect (branch-based cfg) to use DialectConversion in
order to exercise this new functionality.  The modification to the lowering
functions are minor and are focused on using the PatterRewriter instead of
directly modifying the IR.

PiperOrigin-RevId: 252625169
2019-06-11 10:14:27 -07:00
River Riddle 61c3b5df38 NFC: Cleanup the grouping of DenseElementsAttr 'get' methods, and move the bit write/read functions to static functions in Attributes.cpp.
PiperOrigin-RevId: 252094145
2019-06-09 16:23:45 -07:00
River Riddle 0cadec8ae6 Remove the ability to directly construct a DenseElementsAttr with a raw character buffer. This made assumptions about how DenseElementsAttr structured its internal storage, which may change in the future. To replace the existing use cases, a few utility methods have been added:
* 'get' methods that allow constructing from an ArrayRef of integer or floating point values.
* A 'reshape' method to allow for changing the shape without changing the underlying data.

PiperOrigin-RevId: 252067898
2019-06-09 16:23:34 -07:00
River Riddle b790a2f396 Remove the explicit attribute kinds for DenseIntElementsAttr and DenseFPElementsAttr in favor of just one DenseElementsAttr. Now that attribute has the ability to define 'classof(Attribute attr)' methods, these derived classes can just be specializations of the main attribute class.
PiperOrigin-RevId: 251948820
2019-06-09 16:22:05 -07:00
River Riddle e6872ce7b7 Simplify DenseElementsAttr by rounding up the storage of odd bit widths to 8-bits. This removes the requirement that the underlying buffer be aligned to 64 bits which opens the door for several optimizations in the future, e.g. detecting splat.
PiperOrigin-RevId: 251944922
2019-06-09 16:21:43 -07:00
River Riddle 3ab5c0bfaf Add a general operation property 'IsolatedFromAbove' that guarantees that all regions of a given operation are explicit capture only and will not reference values defined above the enclosing operation. This trait will be useful for applying some of the properties currently attached to Functions to operations, e.g. verifying dominance within a specific operation, enabling multi-threading of certain transformations between different instances, etc.
PiperOrigin-RevId: 251927466
2019-06-09 16:21:08 -07:00
MLIR Team f55f7dc769 Support FP16 in getZeroAttr.
PiperOrigin-RevId: 251783931
2019-06-09 16:20:47 -07:00
River Riddle 82f9be83a3 Add a verify method to FuncOp and check that the type signature matches the signature of the entry block.
PiperOrigin-RevId: 251759848
2019-06-09 16:20:35 -07:00
River Riddle cc06860394 Fix a warning for missing parentheses around '||' inside of an assert.
PiperOrigin-RevId: 251712106
2019-06-09 16:19:28 -07:00
River Riddle 6f5f5a9178 Add new 'createOrFold' methods to FuncBuilder to immediately try to fold an operation after creating it. This can be used to remove operations that are likely to be trivially folded later. Note, these functions only fold operations if all of the folded results are existing values.
PiperOrigin-RevId: 251674299
2019-06-09 16:18:55 -07:00
River Riddle 08d407f243 Add a few utility overloads for OpAsmParser methods:
* Add a getCurrentLocation that returns the location directly.
* Add parseOperandList/parseTrailingOperandList overloads without the required operand count.

PiperOrigin-RevId: 251585488
2019-06-09 16:18:21 -07:00
River Riddle f1b848e470 NFC: Rename FuncBuilder to OpBuilder and refactor to take a top level region instead of a function.
PiperOrigin-RevId: 251563898
2019-06-09 16:17:59 -07:00
River Riddle 70db033190 Add support to FuncOp for managing argument attributes. The syntax for argument attributes is the same as Function:
func @foo(i1 {dialect.attr: 10 : i64})

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

PiperOrigin-RevId: 251473338
2019-06-09 16:16:36 -07:00
River Riddle 42c19e8272 Add a utility function to OperationName for extracting the dialect name.
PiperOrigin-RevId: 251333376
2019-06-03 19:27:35 -07:00
Geoffrey Martin-Noble e2032c7d4e Replace comments referring to "vector or tensor" with "shaped" where appropriate
PiperOrigin-RevId: 251306752
2019-06-03 19:27:19 -07:00
River Riddle 62cbdd51fa Start defining a new operation 'FuncOp' that replicates all of the functionality of 'Function', but with an operation. The pretty syntax for the operation is exactly the same as that of Function. This operation is currently builtin, but should hopefully be moved to a different dialect when it has been completely decoupled from IR/. This is the first patch in a large series that refactors Functions to be represented as operations.
PiperOrigin-RevId: 251281612
2019-06-03 19:26:46 -07:00
Jacques Pienaar 482d39eb98 Avoid failure due to incomplete type specification.
--

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

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

--

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

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

--

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

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

--

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

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

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

--

PiperOrigin-RevId: 250945184
2019-06-01 20:12:40 -07:00
River Riddle 94541563dc Abstract the internal storage of the NamedAttributeList into a new attribute, DictionaryAttr. This attribute maintains a sorted list of NamedAttributes. This will allow for operations/functions to maintain sub dictionaries of attributes.
The syntax is the same as top level attribute dictionaries:
       {sub_dictionary: {fn: @someFn, boolAttr: true}}

--

PiperOrigin-RevId: 250898950
2019-06-01 20:12:01 -07:00
Geoffrey Martin-Noble 97505013c6 Make getRank abort for unranked type
This better matches the other methods in ShapedType which only make sense for ranked types. There's now an explicit hasRank for checking the rank. Actual call sites rarely used the "-1" sentinel to combine checking for rankedness and checking that rank is a certain value. And in most cases they should actually be checking for rankedness at a higher level using type predicates. Using an explicit method is clearer than a sentinel anyway.

--

PiperOrigin-RevId: 250720853
2019-06-01 20:11:12 -07:00
Geoffrey Martin-Noble 1c681a7caf Exclude all ShapedType subclasses other than TensorType subclasses from having non-scalar elements.
The current logic assumes that ShapedType indicates a vector or tensor, which will not be true soon when MemRef subclasses ShapedType

--

PiperOrigin-RevId: 250586364
2019-06-01 20:09:42 -07:00
Geoffrey Martin-Noble 66e84bf88c Make it clear that ElementsAttr is only for static shaped vectors or tensors.
This is in preparation for making MemRef a subclass of ShapedType, but also UnrankedTensor should already be excluded.

--

PiperOrigin-RevId: 250580197
2019-06-01 20:09:12 -07:00
MLIR Team 5a91b9896c Remove "size" property of affine maps.
--

PiperOrigin-RevId: 250572818
2019-06-01 20:09:02 -07:00
River Riddle 1fd1c7a8bb Replace the Function reference methods from the OpAsmParser/OpAsmPrinter with usages of FunctionAttr.
--

PiperOrigin-RevId: 250555680
2019-06-01 20:08:03 -07:00
Alex Zinenko c2d105811a Do not assume Blocks belong to Functions
Fix Block::splitBlock and Block::eraseFromFunction that erronously assume
    blocks belong to functions.  They now belong to regions.  When splitting, new
    blocks should be created in the same region as the existing block.  When
    erasing a block, it should be removed from the region rather than from the
    function body that transitively contains the region.

    Also rename Block::eraseFromFunction to Block::erase for consistency with other
    IR containers.

--

PiperOrigin-RevId: 250278272
2019-06-01 20:05:21 -07:00
River Riddle 647f8cabb9 Add support to RewritePattern for specifying the potential operations that can be generated during a rewrite. This will enable analyses to start understanding the possible effects of applying a rewrite pattern.
--

PiperOrigin-RevId: 249936309
2019-06-01 20:02:42 -07:00
River Riddle 9cb3ea8fe4 Update the type printer for Diagnostic to automatically wrap the type with ''.
--

PiperOrigin-RevId: 249935489
2019-06-01 20:02:22 -07:00
River Riddle ca885b3c81 Move the definitions of CmpIOp, CmpFOp, and SelectOp to the ODG framework.
--

PiperOrigin-RevId: 249928953
2019-06-01 20:01:42 -07:00
Geoffrey Martin-Noble 15075d5a22 Replace checks for rank -1 with direct calls to hasRank
Also removed a redundant check for rank after already checking for static shape (which implies rank)

--

PiperOrigin-RevId: 249927636
2019-06-01 20:01:33 -07:00
Geoffrey Martin-Noble 58a766705b Limit the number of places where shaped type has to explicitly reference its base classes.
Introduces a hasRank() method to make checking for rank a bit easier.

    This is partially to make it easier to make MemRef subclass ShapedType

--

PiperOrigin-RevId: 249927442
2019-06-01 20:01:22 -07:00
Geoffrey Martin-Noble 9f1f91e770 Add a type-constrained nested tuple type.
This is useful for dialects that use tuples but only support a subset of types.

--

PiperOrigin-RevId: 249910133
2019-06-01 20:01:03 -07:00
River Riddle 06734badbc Add operand type iterators to Operation and cleanup usages of operand->getType. This also simplifies some lingering usages of result->getType.
--

PiperOrigin-RevId: 249889174
2019-06-01 20:00:43 -07:00
River Riddle 5185acca0d Introduce a new common diagnostic handler ScopedDiagnosticHandler to simplify saving and restoring the currently registered handler.
--

PiperOrigin-RevId: 249735912
2019-06-01 19:59:33 -07:00
Rob Suderman e2b715fe41 Added the ability to run a mapping function across the values of an elements
attr. This supports both the SplatElementsAttr and DenseElementsAttr for both
    float and integer inputs / outputs.

--

PiperOrigin-RevId: 249681056
2019-06-01 19:58:24 -07:00
Stephan Herhut b52112275d Add LLVM::IntToPtrOp and LLVM::PtrToIntOp to LLVM dialect.
--

PiperOrigin-RevId: 249604199
2019-06-01 19:57:34 -07:00
Rob Suderman 51feed5518 Automated rollback of changelist 249538085.
PiperOrigin-RevId: 249550805
2019-06-01 19:57:23 -07:00
Rob Suderman ca9bd9d3af Added the ability to run a mapping function across the values of an elements
attr. This supports both the SplatElementsAttr and DenseElementsAttr for both
    float and integer inputs / outputs.

--

PiperOrigin-RevId: 249538085
2019-06-01 19:57:13 -07:00
River Riddle c33862b0ed Refactor FunctionAttr to hold the internal function reference by name instead of pointer. The one downside to this is that the function reference held by a FunctionAttr needs to be explicitly looked up from the parent module. This provides several benefits though:
* There is no longer a need to explicitly remap function attrs.
      - This removes a potentially expensive call from the destructor of Function.
      - This will enable some interprocedural transformations to now run intraprocedurally.
      - This wasn't scalable and forces dialect defined attributes to override
        a virtual function.
    * Replacing a function is now a trivial operation.
    * This is a necessary first step to representing functions as operations.

--

PiperOrigin-RevId: 249510802
2019-06-01 19:56:54 -07:00
Mehdi Amini d5397f4efe Return nullptr on Region::getContainingOperation()/getContainingFunction() instead of asserting
This avoids crashing when trying to dump an operation nested in a region that isn't yet attached to an operation, which is quite useful when debugging.

    This alone won't be enough to print an unlink Operation, it'll display `<<UNLINKED INSTRUCTION>>`.

--

PiperOrigin-RevId: 249496388
2019-06-01 19:56:43 -07:00
River Riddle d16b470809 Update Attribute::getDialect/Type::getDialect to return a non-const dialect reference.
--

PiperOrigin-RevId: 249467245
2019-06-01 19:56:13 -07:00
River Riddle cf8f1ea918 NFC: Fix the name of a comment header block in Diagnostics.cpp.
--

PiperOrigin-RevId: 249466645
2019-06-01 19:56:03 -07:00
River Riddle 3902cef954 Make the ParallelDiagnosticHandler used by the pass manager publicly available in Diagnostics.h. This provides a common utility for deterministically handling diagnostics in a multi-threaded environment.
--

PiperOrigin-RevId: 249325937
2019-06-01 19:55:24 -07:00
Alex Zinenko 3b500c694d Move SDBM uniquer into the SDBM dialect
MLIRContext does not have to be aware of the SDBM unique data structures
    directly.  Move the SDBM storage uniquer from MLIRContext to the SDBM dialect
    instance.  Expressions that previously required a context to be constructed now
    require an instance of the dialect in order to access the uniquer.  While they
    could look up the dialect in the context, it would have introduced a rather
    expensive lookup into each construction.  Instead, the caller is expected to
    obtain the dialect instance and cache it.

--

PiperOrigin-RevId: 249245199
2019-06-01 19:54:43 -07:00
Alex Zinenko 6804cf2429 Move SDBM infrastructure into a new SDBM dialect
We now have sufficient extensibility in dialects to move attribute components
    such as SDBM out of the core IR into a dedicated dialect and make them
    optional.  Introduce an SDBM dialect and move the code.  This is a mostly
    non-functional change.

--

PiperOrigin-RevId: 249244802
2019-06-01 19:54:33 -07:00
Alex Zinenko e62a12316e SDBMExpr: factor uniqu'ing out of MLIRContext.cpp
SDBM expressions are designed as components of an attribute, similarly to
    affine expressions.  As such, they need to be unique'd in the MLIRContext.
    When SDBM expressions were implemented, uniqu'ing objects in a context required
    to modify MLIRContext implementation.  This is no longer the case as generic
    StorageUniquer has been introduced.  Port the SDBMExpr uniqu'ing to use a newly
    introduced uniquer and remove SDBM construction from MLIRContext.cpp.

--

PiperOrigin-RevId: 249244739
2019-06-01 19:54:22 -07:00
Alex Zinenko c74996d199 AffineExpr: factor uniqu'ing out of MLIRContext.cpp
Affine expressions are designed as components of an attribute and are unique'd
    in the MLIRContext.  When affine expressions were implemented, uniqu'ing
    objects in a context required to modify MLIRContext implementation.  This is no
    longer the case as generic StorageUniquer has been introduced.  Port the
    AffineExpr construction to use the new infrastructure by introducing an
    affineUniquer into the MLIRContext.

--

PiperOrigin-RevId: 249207539
2019-06-01 19:53:43 -07:00
River Riddle d48ff10f01 When changing the type of a Function, also update the type of the respective FunctionAttr.
--

PiperOrigin-RevId: 249137558
2019-06-01 19:53:02 -07:00
River Riddle 039800bfb6 Add support for streaming an OperationName into a Diagnostic.
--

PiperOrigin-RevId: 248987646
2019-05-20 13:48:28 -07:00
River Riddle a23b728034 Allow a function to take the name of another existing function.
--

PiperOrigin-RevId: 248968285
2019-05-20 13:48:02 -07:00
River Riddle 7ffdf2cddd Add support for streaming Operations into Diagnostics.
--

PiperOrigin-RevId: 248967563
2019-05-20 13:47:53 -07:00
River Riddle 1e2d2f5d66 Add a utility function 'Operation::replaceUsesOfWith' to replace uses of a value within a single operation.
--

PiperOrigin-RevId: 248961779
2019-05-20 13:47:36 -07:00
Geoffrey Martin-Noble 22a8bc6ec3 Make shape matching work for any shaped type.
The current implementation makes some assumptions about what can be a shaped type, which aren't really necessary. It also has strange behavior for types that aren't in the limited set it handles (e.g. dialect-defined types)

    Updated the comment to match the implementation.

    This is partially motivated by the desire to make MemRef a subclass of ShapedType

--

PiperOrigin-RevId: 248859674
2019-05-20 13:47:09 -07:00
River Riddle 3de0c7696b Rewrite the DialectOpConversion patterns to inherit from RewritePattern instead of Pattern. This simplifies the infrastructure a bit by being able to reuse PatternRewriter and the RewritePatternMatcher, but also starts to lay the groundwork for a more generalized legalization framework that can operate on DialectOpConversions as well as normal RewritePatterns.
--

PiperOrigin-RevId: 248836492
2019-05-20 13:47:01 -07:00
River Riddle eb5ec03960 Refactor PatternRewriter to inherit from FuncBuilder instead of Builder. This is necessary for allowing more complicated rewrites in the future that may do things like update the insertion point (e.g. for rewrites involving regions).
--

PiperOrigin-RevId: 248803153
2019-05-20 13:46:26 -07:00
Geoffrey Martin-Noble e095f9e72a Also visit memref element type in AsmPrinter
--

PiperOrigin-RevId: 248797935
2019-05-20 13:46:17 -07:00
MLIR Team 7e11eb1f87 Fix use of variables only used in asserts.
This otherwise triggers "unused variable" errors in optimized build mode.

--

PiperOrigin-RevId: 248706350
2019-05-20 13:45:43 -07:00
Alex Zinenko 69ef8642df Overload arithmetic operators for SDBM expressions
Provide an "unsafe" version of the overloaded arithmetic operators for SDBM
    expressions.  These operators expect the operands to be of the right SDBM
    expression subtype and assert if they are not.  They also perform simple
    folding operations as well as some semantically correct operations that
    construct an SDBM expression of a different subtype, e.g., a difference
    expression if the RHS of an operator+ is a negated variable.  These operators
    are scoped in a namespace to allow for a future "safe" version of the operators
    that propagates null expressions to denote the error state when expressions
    have wrong subtypes.

--

PiperOrigin-RevId: 248704153
2019-05-20 13:45:34 -07:00
Alex Zinenko f06ab26acf Implement SDBM and conversion between SDBM and lists of SDBMExpr
Implement the storage class for striped difference-bound matrices (SDBM) as a
    container with a difference bounds matrix and a list of stripe expressions.  An
    SDBM defines an integer set.  Provide conversion mechanisms between lists of
    SDBM expressions treated as equalities with zero or less-than-or-equal
    inequalities with zero.

--

PiperOrigin-RevId: 248702871
2019-05-20 13:45:26 -07:00
Jacques Pienaar e489e59246 Don't fail verifying unranked shapes as being the same as this could be valid at runtime.
tensor<*xf32> could be a tensor<1xf32> at runtime but this verifyShapeMatch would return failure and say function is invalid.

--

PiperOrigin-RevId: 248583038
2019-05-20 13:44:33 -07:00
River Riddle 1982afb145 Unify the 'constantFold' and 'fold' hooks on an operation into just 'fold'. This new unified fold hook will take constant attributes as operands, and may return an existing 'Value *' or a constant 'Attribute' when folding. This removes the awkward situation where a simple canonicalization like "sub(x,x)->0" had to be written as a canonicalization pattern as opposed to a fold.
--

PiperOrigin-RevId: 248582024
2019-05-20 13:44:24 -07:00
Geoffrey Martin-Noble 090662c5f3 Rename VectorOrTensorType to ShapedType
This is in preparation for making it also support/be a parent class of MemRefType. MemRefs have similar shape/rank/element semantics and it would be useful to be able to use these same utilities for them.

    This CL should not change any semantics and only change variables, types, string literals, and comments. In follow-up CLs I will prepare all callers to handle MemRef types or remove their dependence on ShapedType.

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

--

PiperOrigin-RevId: 248476449
2019-05-20 13:43:58 -07:00
River Riddle 8d5bd823b0 Add support for parsing/printing dialect defined attributes. This also adds support for a pretty syntax for dialects attributes that is synonymous with the pretty syntax for dialect types. This cl also adds a new attribute 'OpaqueAttr' that allows for roundtripping attributes attached to unregistered dialects.
Dialect attributes have the following syntax:
       dialect-attribute  ::= `#` dialect-namespace `<` `"` attr-data `"` `>`
       dialect-attribute  ::= `#` alias-name pretty-dialect-sym-body?

--

PiperOrigin-RevId: 248344416
2019-05-20 13:43:05 -07:00
Chris Lattner 9ec6b5b749 Remove some extraneous const qualifiers on Type, and 0b1 -> 1 in tblgen files. (NFC)
--

PiperOrigin-RevId: 248332674
2019-05-20 13:42:56 -07:00
Nicolas Vasilache 8eb32a9051 Add an AffineExpr matcher
This CL gives a pattern-matching-y look and feel to AffineExpr.
    For now this uses a shared_ptr instead of unique'ing into a bumpPtrAllocator.
    SDBM gives a simple use case with more idiomatic syntax for matchers.

--

PiperOrigin-RevId: 248188075
2019-05-20 13:42:04 -07:00
River Riddle 6264fccd3a When converting a location to an SMLoc, advance to the first non-whitespace if the column is unknown(zero). This also fixes a small bug with call stack printing.
Example:
    /tmp/file_C.py:21:5: error: 'foo.bar' op attribute 'something'
        raise app.UsageError('Too many command-line arguments.')
        ^
    /tmp/file_D.py:20:3: note: called from
      if len(argv) > 1:
      ^
    /tmp/file_E.py:19:1: note: called from
    def main(argv):
    ^
    /tmp/file_F.py:24:3: note: called from
      app.run(main)
      ^

--

PiperOrigin-RevId: 248151212
2019-05-20 13:41:46 -07:00
River Riddle 30356de1db Add initial support to the SourceMgrDiagnosticHandler for printing call stacks.
Example:

    /tmp/file_C.py:17:1: error: 'foo.bar' op attribute 'something' ...
      app.run(main)
    ^
    /tmp/file_D.py:14:1: note: called from
        raise app.UsageError('Too many command-line arguments.')
    ^
    /tmp/file_E.py:12:1: note: called from
    def main(argv):
    ^
    /tmp/file_F.py:13:1: note: called from
      if len(argv) > 1:
    ^

--

PiperOrigin-RevId: 248074804
2019-05-20 13:41:20 -07:00
Stella Laurenzo 1a2ad06bae Fix lingering sign compare warnings in exposed by "ninja check-mlir".
--

PiperOrigin-RevId: 248050178
2019-05-20 13:41:11 -07:00
River Riddle cad382406f Refactor NameLoc so that it also holds a child location. This removes the awkward use of CallSiteLoc as a variable usage location.
--

PiperOrigin-RevId: 248014642
2019-05-20 13:40:52 -07:00
River Riddle d39a30626e Use the DialectSymbolRegistry to reserve space in the Attribute::Kind enum to allow for dialects to define attribute kinds. The currently defined attributes kinds have now been moved to StandardAttributes.
--

PiperOrigin-RevId: 247988373
2019-05-20 13:40:03 -07:00
River Riddle e18a55f142 NFC: Cleanup the definitions of the Location classes.
--

PiperOrigin-RevId: 247979132
2019-05-20 13:39:32 -07:00
River Riddle 6a6cb40f23 Refactor the includes of Function.h now that the dependency on Operation has been removed. The dependency was on the op casting methods, which have now moved out of Operation, used by the walker.
--

PiperOrigin-RevId: 247944666
2019-05-20 13:38:32 -07:00
River Riddle e686a11523 Remove several heavy includes from Diagnostics.h by a moving a couple of fields/methods to the .cpp file.
--

PiperOrigin-RevId: 247768443
2019-05-20 13:36:48 -07:00
River Riddle 85bf79851e Change the diagnostic handler to accept Diagnostic instead of location/message/kind. This opens the door for many more powerful use cases: fixits, colors, etc.
--

PiperOrigin-RevId: 247705673
2019-05-10 19:30:56 -07:00
River Riddle 53a3483cc8 Ensure that all attributes are registered with a dialect. This is one of the final steps towards allowing dialects to define their own attributes, but there are still several things missing before this is fully supported(e.g. parsing/printing ).
--

PiperOrigin-RevId: 247684322
2019-05-10 19:30:23 -07:00
River Riddle aa99db1809 Add support to the SourceMgrDiagnosticHandlers to auto-load new source files seen in diagnostics.
--

PiperOrigin-RevId: 247681779
2019-05-10 19:30:15 -07:00
Mehdi Amini ff5d021c39 Add llvm_unreachable in unreachable path to silence GCC warning (NFC)
The switch is supposed to be fully covered, but GCC warns that:
     "control reaches end of non-void function"

--

PiperOrigin-RevId: 247672430
2019-05-10 19:30:06 -07:00
River Riddle 9e363a1f3f Refactor the SourceMgrDiagnosticHandlers to support more locations than FileLineColLoc.
--

PiperOrigin-RevId: 247662828
2019-05-10 19:29:10 -07:00
River Riddle 685f948481 Add support to SourceMgrDiagnosticHandler for handling the case where the llvm::SourceMgr has no main file.
--

PiperOrigin-RevId: 247605584
2019-05-10 19:28:13 -07:00
Mehdi Amini 211ceb9fd5 Add override keyword on overidden virtual method (NFC)
Fix clang warnings

--

PiperOrigin-RevId: 247556495
2019-05-10 19:26:59 -07:00
River Riddle 5fd4ec1b78 Move the diagnostic verification functionality out of mlir-opt and into a new llvm::SourceMgr diagnostic handler 'SourceMgrDiagnosticVerifierHandler'. This will allow for other tools to reuse the 'expected-*' functionality.
--

PiperOrigin-RevId: 247514684
2019-05-10 19:26:51 -07:00