Lei Zhang [Thu, 22 Aug 2019 01:04:56 +0000 (18:04 -0700)]
Remove the wrapping function in SPIR-V (de)serialization
Previously Module and Function are builtinn constructs in MLIR.
Due to the structural requirements we must wrap the SPIR-V
module inside a Function inside a Module. Now the requirement
is lifted and we can remove the wrapping function! :)
PiperOrigin-RevId:
264736051
MLIR Team [Thu, 22 Aug 2019 00:51:27 +0000 (17:51 -0700)]
NFC: Update in-code documentation for type.
PiperOrigin-RevId:
264734014
Chintan Kaur [Thu, 22 Aug 2019 00:45:06 +0000 (17:45 -0700)]
Fix minor typos in TestingGuide and OpDefinitions.
PiperOrigin-RevId:
264733092
MLIR Team [Wed, 21 Aug 2019 23:50:55 +0000 (16:50 -0700)]
NFC: Update in-code documentation for function-type.
PiperOrigin-RevId:
264723462
River Riddle [Wed, 21 Aug 2019 23:50:30 +0000 (16:50 -0700)]
Add a hook to the OpAsmDialectInterface to allow providing a special name for the operation result.
This generalizes the current special handling for constant operations(they get named 'cst'/'true'/'false'/etc.)
PiperOrigin-RevId:
264723379
MLIR Team [Wed, 21 Aug 2019 21:28:10 +0000 (14:28 -0700)]
[TableGen] Add a `StaticShapeMemRefOf` trait.
The trait specifies that the `MemRefOf` has to have a static shape.
PiperOrigin-RevId:
264692758
River Riddle [Wed, 21 Aug 2019 20:00:30 +0000 (13:00 -0700)]
Automated rollback of commit
b9dc2e481818315f2f0d87455349f497f6118a4c
PiperOrigin-RevId:
264672975
River Riddle [Wed, 21 Aug 2019 19:16:23 +0000 (12:16 -0700)]
NFC: Make the ModuleState field in the ModulePrinter optional.
The ModuleState is only used for printing aliases, which is only done when printing the top-level module.
PiperOrigin-RevId:
264664138
River Riddle [Wed, 21 Aug 2019 17:23:14 +0000 (10:23 -0700)]
Add iterator support to ElementsAttr and SparseElementsAttr.
This will allow iterating the values of a non-opaque ElementsAttr, with all of the types currently supported by DenseElementsAttr. This should help reduce the amount of specialization on DenseElementsAttr.
PiperOrigin-RevId:
264637293
River Riddle [Wed, 21 Aug 2019 16:41:37 +0000 (09:41 -0700)]
Move the parser extensions for aliases currently on Dialect to a new OpAsmDialectInterface.
This will allow for adding more hooks for controlling parser behavior without bloating Dialect in the common case. This cl also adds iteration support to the DialectInterfaceCollection.
PiperOrigin-RevId:
264627846
Lei Zhang [Wed, 21 Aug 2019 15:17:19 +0000 (08:17 -0700)]
[spirv] Support i1 as bool type
PiperOrigin-RevId:
264612014
Lei Zhang [Wed, 21 Aug 2019 12:35:07 +0000 (05:35 -0700)]
Support variadic ops in declarative rewrite rules
This CL extends declarative rewrite rules to support matching and
generating ops with variadic operands/results. For this, the
generated `matchAndRewrite()` method for each pattern now are
changed to
* Use "range" types for the local variables used to store captured
values (`operand_range` for operands, `ArrayRef<Value *>` for
values, *Op for results). This allows us to have a unified way
of handling both single values and value ranges.
* Create local variables for each operand for op creation. If the
operand is variadic, then a `SmallVector<Value*>` will be created
to collect all values for that operand; otherwise a `Value*` will
be created.
* Use a collective result type builder. All result types are
specified via a single parameter to the builder.
We can use one result pattern to replace multiple results of the
matched root op. When that happens, it will require specifying
types for multiple results. Add a new collective-type builder.
PiperOrigin-RevId:
264588559
Lei Zhang [Wed, 21 Aug 2019 11:45:23 +0000 (04:45 -0700)]
Materialize spv.constants at use sites
In SPIR-V binary format, constants are placed at the module level
and referenced by instructions inside functions using their result
<id>s. To model this natively (using SSA values for result <id>s),
it means we need to have implicit capturing functions. We will
lose the ability to have function passes if going down that path.
Instead, this CL changes to materialize constants at their use
sites in deserialization. It's cheap to copy constants in MLIR
given that attributes is uniqued to MLIRContext. By localizing
constants into functions, we can preserve isolated functions.
PiperOrigin-RevId:
264582532
River Riddle [Wed, 21 Aug 2019 02:58:35 +0000 (19:58 -0700)]
NFC: Keep the dialect list in the context sorted by namespace.
Most dialects are initialized statically, which does not have a guaranteed initialization order. By keeping the dialect list sorted, we can guarantee a deterministic iteration order of dialects.
PiperOrigin-RevId:
264522875
River Riddle [Wed, 21 Aug 2019 01:49:08 +0000 (18:49 -0700)]
NFC: Use a DenseSet instead of a DenseMap for DialectInterfaceCollection.
The interfaces are looked up by dialect, which can always be retrieved from an interface instance.
PiperOrigin-RevId:
264516023
River Riddle [Wed, 21 Aug 2019 01:41:38 +0000 (18:41 -0700)]
NFC: Move the LangRef documentation on StandardOps to a new document.
The LangRef should contain documentation about the core system, and standard ops is a dialect just like any other. This will also simplify the transition when StandardOps is eventually split apart.
PiperOrigin-RevId:
264514988
River Riddle [Tue, 20 Aug 2019 22:36:08 +0000 (15:36 -0700)]
NFC: Move AffineOps dialect to the Dialect sub-directory.
PiperOrigin-RevId:
264482571
Lei Zhang [Tue, 20 Aug 2019 20:33:41 +0000 (13:33 -0700)]
Add spv.specConstant and spv._reference_of
Similar to global variables, specialization constants also live
in the module scope and can be referenced by instructions in
functions in native SPIR-V. A direct modelling would be to allow
functions in the SPIR-V dialect to implicit capture, but it means
we are losing the ability to write passes for Functions. While
in SPIR-V normally we want to process the module as a whole,
it's not common to see multiple functions get used so we'd like
to leave the door open for those cases. Therefore, similar to
global variables, we introduce spv.specConstant to model three
SPIR-V instructions: OpSpecConstantTrue, OpSpecConstantFalse,
and OpSpecConstant. They do not return SSA value results;
instead they have symbols and can only be referenced by the
symbols. To use it in a function, we need to have another op
spv._reference_of to turn the symbol into an SSA value. This
breaks the tie and makes functions still explicit capture.
Previously specialization constants were handled similarly as
normal constants. That is incorrect given that specialization
constant actually acts more like variable (without need to
load and store). E.g., they cannot be de-duplicated like normal
constants.
This CL also refines various documents and comments.
PiperOrigin-RevId:
264455172
Denis Khalikov [Tue, 20 Aug 2019 18:02:57 +0000 (11:02 -0700)]
[spirv] Support (de)serialization of spv.struct
Support (de)serialization of spv.struct with offset decorations.
Closes tensorflow/mlir#94
PiperOrigin-RevId:
264421427
Diego Caballero [Tue, 20 Aug 2019 17:43:45 +0000 (10:43 -0700)]
Fix build of affine load/store with empty map
tensorflow/mlir#58 fixed and exercised
verification of load/store ops using empty affine maps. Unfortunately,
it didn't exercise the creation of them. This PR addresses that aspect.
It removes the assumption of AffineMap having at least one result and
stores a pointer to MLIRContext as member of AffineMap.
* Add empty map support to affine.store + test
* Move MLIRContext to AffineMapStorage
Closes tensorflow/mlir#74
PiperOrigin-RevId:
264416260
Andy Davis [Tue, 20 Aug 2019 17:38:27 +0000 (10:38 -0700)]
Update MLIR code examples in Passes.md doc to use new affine.load/store dma_start/wait operations.
PiperOrigin-RevId:
264415037
Zhang [Tue, 20 Aug 2019 15:53:02 +0000 (08:53 -0700)]
Update Ch-2.md
--
406f1e8211f8f5017f44f46af750dec061e707a2 by Zhang <
5205699+Naville@users.noreply.github.com>:
Update Ch-2.md
Closes tensorflow/mlir#93
PiperOrigin-RevId:
264392995
Alex Zinenko [Tue, 20 Aug 2019 14:51:32 +0000 (07:51 -0700)]
ConvertLaunchFuncToCudaCalls: use LLVM dialect globals
This conversion has been using a stack-allocated array of i8 to store the
null-terminated kernel name in order to pass it to the CUDA wrappers expecting
a C string because the LLVM dialect was missing support for globals. Now that
the suport is introduced, use a global instead.
Refactor global string construction from GenerateCubinAccessors into a common
utility function living in the LLVM namespace.
PiperOrigin-RevId:
264382489
Alex Zinenko [Tue, 20 Aug 2019 14:45:47 +0000 (07:45 -0700)]
JitRunner: support entry functions returning void
JitRunner can use as entry points functions that produce either a single
'!llvm.f32' value or a list of memrefs. Memref support is legacy and was
introduced before MLIR could lower memref allocation and deallocation to
malloc/free calls so as to allocate the memory externally, and is likely to be
dropped in the future since it unconditionally runs affine+standard-to-llvm
lowering on the module instead of accepting the LLVM dialect. CUDA runner
relies on memref-based flow in the runner without actually returning anything.
Introduce a runner flow to use functions that return void as entry points.
PiperOrigin-RevId:
264381686
Alex Zinenko [Tue, 20 Aug 2019 13:38:28 +0000 (06:38 -0700)]
LLVM dialect: prefix operations that correspond to intrinsics with "intr."
LLVM intrinsics have an open name space and their names can potentially overlap
with names of LLVM instructions (LLVM intrinsics are functions, not
instructions). In MLIR, LLVM intrinsics are modeled as operations, so it needs
to make sure their names cannot clash with the instructions. Use the "intr."
prefix for intrinsics in the LLVM dialect.
PiperOrigin-RevId:
264372173
Nicolas Vasilache [Tue, 20 Aug 2019 08:59:58 +0000 (01:59 -0700)]
Add support for LLVM lowering of binary ops on n-D vector types
This CL allows binary operations on n-D vector types to be lowered to LLVMIR by performing an (n-1)-D extractvalue, 1-D vector operation and an (n-1)-D insertvalue.
PiperOrigin-RevId:
264339118
Uday Bondhugula [Tue, 20 Aug 2019 08:52:39 +0000 (01:52 -0700)]
Fix AffineExpr::simplifyAdd bug
- fix missing check while simplifying an expression with floordiv to a
mod
- fixes issue tensorflow/mlir#82
Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>
Closes tensorflow/mlir#84
PiperOrigin-RevId:
264338353
Chintan Kaur [Tue, 20 Aug 2019 00:29:22 +0000 (17:29 -0700)]
Fix minor typos and add missing syntax in the documentation.
PiperOrigin-RevId:
264281501
Nicolas Vasilache [Tue, 20 Aug 2019 00:11:12 +0000 (17:11 -0700)]
Move Linalg and VectorOps dialects to the Dialect subdir - NFC
PiperOrigin-RevId:
264277760
River Riddle [Tue, 20 Aug 2019 00:01:13 +0000 (17:01 -0700)]
Add a DialectConversion document detailing the conversion infrastructure.
This is an important piece of the infrastructure that is missing proper high level documentation on usage.
PiperOrigin-RevId:
264275482
Rob Suderman [Mon, 19 Aug 2019 22:56:55 +0000 (15:56 -0700)]
Add DictionaryAttr to OpBase.td
PiperOrigin-RevId:
264262369
River Riddle [Mon, 19 Aug 2019 22:26:43 +0000 (15:26 -0700)]
Allow isolated regions to form isolated SSA name scopes in the printer.
This will allow for naming values the same as existing SSA values for regions attached to operations that are isolated from above. This fits in with how the system already allows separate name scopes for sibling regions. This name shadowing can be enabled in the custom parser of operations by setting the 'enableNameShadowing' flag to true when calling 'parseRegion'.
%arg = constant 10 : i32
foo.op {
%arg = constant 10 : i32
}
PiperOrigin-RevId:
264255999
Nicolas Vasilache [Mon, 19 Aug 2019 21:36:49 +0000 (14:36 -0700)]
Add alignment support to linalg.buffer_alloc
This CL adds an integer attribute to linalg.buffer_alloc and lowering to LLVM.
The alignment is constrained to be a positive power of 2.
Lowering to LLVM produces the pattern:
```
%[[alloc:.*]] = llvm.call @malloc(%[[s]]) : (!llvm.i64) -> !llvm<"i8*">
%[[cast:.*]] = llvm.bitcast %[[alloc]] : !llvm<"i8*"> to !llvm.i64
%[[rem:.*]] = llvm.urem %[[cast]], %[[c16]] : !llvm.i64
%[[drem:.*]] = llvm.sub %[[c16]], %[[rem]] : !llvm.i64
%[[off:.*]] = llvm.urem %[[drem]], %[[c16]] : !llvm.i64
llvm.getelementptr %{{.*}}[%[[off]]] : (!llvm<"i8*">, !llvm.i64) -> !llvm<"i8*">
```
where `ptr` is aligned on `align` by computing the address
`ptr + (align - ptr % align) % align`.
To allow dealloc op to still be able to free memory, additional information is needed in
the buffer type. The buffer type is thus extended with an extra i8* for the base allocation address.
PiperOrigin-RevId:
264244455
River Riddle [Mon, 19 Aug 2019 19:43:46 +0000 (12:43 -0700)]
Add support for Operation interfaces.
Operation interfaces, as the name suggests, are those registered at the
Operation level. These interfaces provide an opaque view into derived
operations, by providing a virtual interface that must be implemented. As an
example, the Linalg dialect implements an interface LinalgOp that provides
general queries about some of the dialects library operations. These queries may
provide things like: the number of parallel loops, the number of inputs and
outputs, etc.
Operation interfaces are defined by overriding the CRTP base class OpInterface.
This class takes as a template parameter, a `Traits` class that defines a
Concept and a Model class. These classes provide an implementation of
concept-based polymorphism, where the Concept defines a set of virtual methods
that are overridden by the Model that is templated on the concrete operation
type. It is important to note that these classes should be pure in that they
contain no non-static data members.
PiperOrigin-RevId:
264218741
River Riddle [Mon, 19 Aug 2019 19:12:50 +0000 (12:12 -0700)]
NFC: Don't assume that all operation traits are within the 'OpTrait::' namespace.
This places an unnecessary restriction that all traits are within this namespace.
PiperOrigin-RevId:
264212000
Mahesh Ravishankar [Mon, 19 Aug 2019 18:38:53 +0000 (11:38 -0700)]
Fix parsing/printing of spv.globalVariable and spv._address_of
Change the prining/parsing of spv.globalVariable to print the type of
the variable after the ':' to be consistent with MLIR convention.
The spv._address_of should print the variable type after the ':'. It was
mistakenly printing the address of the return value. Add a (missing)
test that should have caught that.
Also move spv.globalVariable and spv._address_of tests to
structure-ops.mlir.
PiperOrigin-RevId:
264204686
River Riddle [Mon, 19 Aug 2019 18:00:47 +0000 (11:00 -0700)]
NFC: Move LLVMIR, SDBM, and StandardOps to the Dialect/ directory.
PiperOrigin-RevId:
264193915
Lei Zhang [Mon, 19 Aug 2019 17:57:43 +0000 (10:57 -0700)]
[spirv] Add spv.ReturnValue
This CL adds the spv.ReturnValue op and its tests. Also adds a
InFunctionScope trait to make sure that the op stays inside
a function. To be consistent, ModuleOnly trait is changed to
InModuleScope.
PiperOrigin-RevId:
264193081
Nicolas Vasilache [Mon, 19 Aug 2019 17:21:15 +0000 (10:21 -0700)]
Refactor linalg lowering to LLVM
The linalg.view type used to be lowered to a struct containing a data pointer, offset, sizes/strides information. This was problematic when passing to external functions due to ABI, struct padding and alignment issues.
The linalg.view type is now lowered to LLVMIR as a *pointer* to a struct containing the data pointer, offset and sizes/strides. This simplifies the interfacing with external library functions and makes it trivial to add new functions without creating a shim that would go from a value type struct to a pointer type.
The consequences are that:
1. lowering explicitly uses llvm.alloca in lieu of llvm.undef and performs the proper llvm.load/llvm.store where relevant.
2. the shim creation function `getLLVMLibraryCallDefinition` disappears.
3. views are passed by pointer, scalars are passed by value. In the future, other structs will be passed by pointer (on a per-need basis).
PiperOrigin-RevId:
264183671
Nicolas Vasilache [Mon, 19 Aug 2019 01:54:50 +0000 (18:54 -0700)]
Add alignment support for llvm.alloca
Extend the LLVM dialect AllocaOp with an alignment attribute.
PiperOrigin-RevId:
264068306
Jacques Pienaar [Sun, 18 Aug 2019 18:32:26 +0000 (11:32 -0700)]
InitLLVM already initializes PrettyStackTraceProgram
Remove extra PrettyStackTraceProgram and use InitLLVM consistently.
PiperOrigin-RevId:
264041205
Jacques Pienaar [Sat, 17 Aug 2019 18:05:35 +0000 (11:05 -0700)]
Change from llvm::make_unique to std::make_unique
Switch to C++14 standard method as llvm::make_unique has been removed (
https://reviews.llvm.org/D66259). Also mark some targets as c++14 to ease next
integrates.
PiperOrigin-RevId:
263953918
River Riddle [Sat, 17 Aug 2019 17:22:19 +0000 (10:22 -0700)]
NFC: Add header blocks to improve readability.
PiperOrigin-RevId:
263951251
Mahesh Ravishankar [Sat, 17 Aug 2019 17:19:48 +0000 (10:19 -0700)]
Add spirv::GlobalVariableOp that allows module level definition of variables
FuncOps in MLIR use explicit capture. So global variables defined in
module scope need to have a symbol name and this should be used to
refer to the variable within the function. This deviates from SPIR-V
spec, which assigns an SSA value to variables at all scopes that can
be used to refer to the variable, which requires SPIR-V functions to
allow implicit capture. To handle this add a new op,
spirv::GlobalVariableOp that can be used to define module scope
variables.
Since instructions need an SSA value, an new spirv::AddressOfOp is
added to convert a symbol reference to an SSA value for use with other
instructions.
This also means the spirv::EntryPointOp instruction needs to change to
allow initializers to be specified using symbol reference instead of
SSA value
The current spirv::VariableOp which returns an SSA value (as defined
by SPIR-V spec) can still be used to define function-scope variables.
PiperOrigin-RevId:
263951109
River Riddle [Sat, 17 Aug 2019 02:21:50 +0000 (19:21 -0700)]
NFC: Modernize and cleanup standard ops.
PiperOrigin-RevId:
263891926
River Riddle [Sat, 17 Aug 2019 00:59:03 +0000 (17:59 -0700)]
NFC: Refactor the PassInstrumentation framework to operate on Operation instead of llvm::Any.
Now that functions and modules are operations, Operation makes more sense as the opaque object to refer to both.
PiperOrigin-RevId:
263883913
River Riddle [Fri, 16 Aug 2019 21:45:37 +0000 (14:45 -0700)]
NFC: Move the Type::is* predicates to StandardTypes.cpp
These methods are currently defined 'inline' in StandardTypes.h, but this may create linker errors if StandardTypes.h isn't included at the use site.
PiperOrigin-RevId:
263850328
MLIR Team [Fri, 16 Aug 2019 18:00:31 +0000 (11:00 -0700)]
Fix minor typos in the documentation
PiperOrigin-RevId:
263805025
Denis Khalikov [Fri, 16 Aug 2019 17:17:47 +0000 (10:17 -0700)]
[spirv] Extend spv.array with Layoutinfo
Extend spv.array with Layoutinfo to support (de)serialization.
Closes tensorflow/mlir#80
PiperOrigin-RevId:
263795304
River Riddle [Fri, 16 Aug 2019 17:16:09 +0000 (10:16 -0700)]
Refactor DialectConversion to convert the signatures of blocks when they are moved.
Often we want to ensure that block arguments are converted before operations that use them. This refactors the current implementation to be cleaner/less frequent by triggering conversion when a set of blocks are moved/inlined; or when legalization is successful.
PiperOrigin-RevId:
263795005
Jacques Pienaar [Fri, 16 Aug 2019 15:34:37 +0000 (08:34 -0700)]
C++14 is now default enabled in LLVM, remove obsolete CMake flag.
PiperOrigin-RevId:
263776602
Jacques Pienaar [Fri, 16 Aug 2019 15:08:11 +0000 (08:08 -0700)]
Remove C++11 requirement set in cmakelists
C++14 is now the required.
PiperOrigin-RevId:
263772579
Nicolas Vasilache [Fri, 16 Aug 2019 10:52:56 +0000 (03:52 -0700)]
Extend vector.outerproduct with an optional 3rd argument
This CL adds an optional third argument to the vector.outerproduct instruction.
When such a third argument is specified, it is added to the result of the outerproduct and is lowered to FMA intrinsic when the lowering supports it.
In the future, we can add an attribute on the `vector.outerproduct` instruction to modify the operations for which to emit code (e.g. "+/*", "max/+", "min/+", "log/exp" ...).
This CL additionally performs minor cleanups in the vector lowering and adds tests to improve coverage.
This has been independently verified to result in proper fma instructions for haswell as follows.
Input:
```
func @outerproduct_add(%arg0: vector<17xf32>, %arg1: vector<8xf32>, %arg2: vector<17x8xf32>) -> vector<17x8xf32> {
%2 = vector.outerproduct %arg0, %arg1, %arg2 : vector<17xf32>, vector<8xf32>
return %2 : vector<17x8xf32>
}
}
```
Command:
```
mlir-opt vector-to-llvm.mlir -vector-lower-to-llvm-dialect --disable-pass-threading | mlir-opt -lower-to-cfg -lower-to-llvm | mlir-translate --mlir-to-llvmir | opt -O3 | llc -O3 -march=x86-64 -mcpu=haswell -mattr=fma,avx2
```
Output:
```
outerproduct_add: # @outerproduct_add
# %bb.0:
...
vmovaps 112(%rbp), %ymm8
vbroadcastss %xmm0, %ymm0
...
vbroadcastss 64(%rbp), %ymm15
vfmadd213ps 144(%rbp), %ymm8, %ymm0 # ymm0 = (ymm8 * ymm0) + mem
...
vfmadd213ps 400(%rbp), %ymm8, %ymm9 # ymm9 = (ymm8 * ymm9) + mem
...
```
PiperOrigin-RevId:
263743359
Mahesh Ravishankar [Thu, 15 Aug 2019 17:54:22 +0000 (10:54 -0700)]
Simplify the classes that support SPIR-V conversion.
Modify the Type converters to have a SPIRVBasicTypeConverter which
only handles conversion from standard types to SPIRV types. Rename
SPIRVEntryFnConverter to SPIRVTypeConverter. This contains the
SPIRVBasicTypeConverter within it.
Remove SPIRVFnLowering class and have separate utility methods to
lower a function as entry function or a non-entry function. The
current setup could end with diamond inheritence that is not very
friendly to use. For example, you could define the following Op
conversion methods that lower from a dialect "Foo" which resuls in
diamond inheritance.
template<typename OpTy>
class FooDialect : public SPIRVOpLowering<OpTy> {...};
class FooFnLowering : public FooDialect, SPIRVFnLowering {...};
PiperOrigin-RevId:
263597101
Mahesh Ravishankar [Thu, 15 Aug 2019 17:52:24 +0000 (10:52 -0700)]
Add BuiltIn EnumAttr to SPIR-V dialect
Generate the EnumAttr to represent BuiltIns in SPIR-V dialect. The
builtIn can be specified as a StringAttr with value being the
name of the builtin. Extend Decoration (de)serialization to handle
BuiltIns.
Also fix an error in the SPIR-V dialect generator script.
PiperOrigin-RevId:
263596624
Alex Zinenko [Thu, 15 Aug 2019 11:50:51 +0000 (04:50 -0700)]
ExecutionEngine: fix after upstream LLVM ORC update
LLVM r368707 updated the APIs in llvm::orc::DynamicLibrarySearchGenerator to
use unique_ptr for holding the instance of the generator. Update our uses of
DynamicLibrarySearchGenerator in the ExecutionEngine to reflect that.
PiperOrigin-RevId:
263539855
River Riddle [Thu, 15 Aug 2019 03:48:35 +0000 (20:48 -0700)]
Add support for Dialect interfaces.
Dialect interfaces are virtual apis registered to a specific dialect instance. Dialect interfaces are generally useful for transformation passes, or analyses, that want to opaquely operate on operations within a given dialect. These interfaces generally involve wide coverage over the entire dialect.
A dialect interface can be defined by inheriting from the CRTP base class DialectInterfaceBase::Base. This class provides the necessary utilities for registering an interface with the dialect so that it can be looked up later. Dialects overriding an interface may register an instance via 'Dialect::addInterfaces'. This API works very similarly to the respective addOperations/addTypes/etc. This will allow for a transformation/utility to later query the interface from an opaque dialect instance via 'getInterface<T>'.
A utility class 'DialectInterfaceCollection' is also provided that will collect all of the dialects that implement a specific interface within a given module. This allows for simplifying the API of interface lookups.
PiperOrigin-RevId:
263489015
River Riddle [Wed, 14 Aug 2019 22:03:25 +0000 (15:03 -0700)]
Refactor ElementsAttr::getValue and DenseElementsAttr::getSplatValue.
All 'getValue' variants now require that the index is valid, queryable via 'isValidIndex'. 'getSplatValue' now requires that the attribute is a proper splat. This allows for querying these methods on DenseElementAttr with all possible value types; e.g. float, int, APInt, etc. This also allows for removing unnecessary conversions to Attribute that really want the underlying value.
PiperOrigin-RevId:
263437337
Nicolas Vasilache [Wed, 14 Aug 2019 21:40:22 +0000 (14:40 -0700)]
Move remaining linalg ops to ODS - NFC
This CL moves the linalg.load/range/store ops to ODS.
Minor cleanups are performed.
Additional invalid IR tests are added for coverage.
PiperOrigin-RevId:
263432110
Ben Vanik [Wed, 14 Aug 2019 17:30:30 +0000 (10:30 -0700)]
Allow the use of the $cppClass template variable in verifier code blocks.
PiperOrigin-RevId:
263378198
Nicolas Vasilache [Wed, 14 Aug 2019 14:01:04 +0000 (07:01 -0700)]
Refactor linalg.view lowering to LLVM - NFC
This CL fuses the emission of size and stride information and makes it clearer which indexings are stepped over when querying the positions. This refactor was motivated by an index calculation bug in the stride computation.
PiperOrigin-RevId:
263341610
Nicolas Vasilache [Wed, 14 Aug 2019 13:02:40 +0000 (06:02 -0700)]
Move linalg.slice to ODS
PiperOrigin-RevId:
263334168
River Riddle [Tue, 13 Aug 2019 23:42:41 +0000 (16:42 -0700)]
Add a utility script to auto-generate CHECK commands for mlir test cases.
This script is a utility to add FileCheck patterns to an mlir file. The script will heuristically insert CHECK/CHECK-LABEL commands for each line within the file. By default this script will also try to insert string substitution blocks for all SSA value names. The script is designed to make adding checks to a test case fast, it is *not* designed to be authoritative about what constitutes a good test!
Note: Some cases may not be handled well, e.g. operands to operations with regions, but this script is only intended to be a starting point.
Example usage:
$ generate-test-checks.py foo.mlir
$ mlir-opt foo.mlir -transformation | generate-test-checks.py
module {
func @fold_extract_element(%arg0: index) -> (f32, f16, f16, i32) {
%cst = constant 4.
500000e+00 : f32
%cst_0 = constant -2.
000000e+00 : f16
%cst_1 = constant 0.
000000e+00 : f16
%c64_i32 = constant 64 : i32
return %cst, %cst_0, %cst_1, %c64_i32 : f32, f16, f16, i32
}
}
// CHECK-LABEL: func @fold_extract_element(
// CHECK-SAME: [[VAL_0:%.*]]: index) -> (f32, f16, f16, i32) {
// CHECK: [[VAL_1:%.*]] = constant 4.
500000e+00 : f32
// CHECK: [[VAL_2:%.*]] = constant -2.
000000e+00 : f16
// CHECK: [[VAL_3:%.*]] = constant 0.
000000e+00 : f16
// CHECK: [[VAL_4:%.*]] = constant 64 : i32
// CHECK: return [[VAL_1]], [[VAL_2]], [[VAL_3]], [[VAL_4]] : f32, f16, f16, i32
// CHECK: }
PiperOrigin-RevId:
263242983
jpienaar [Tue, 13 Aug 2019 21:22:58 +0000 (14:22 -0700)]
Add unreachable to avoid GCC -Wreturn-type warning
GCC warns of control reaching end of non-void function (-Wreturn-type).
Closes tensorflow/mlir#75
PiperOrigin-RevId:
263214601
Nicolas Vasilache [Tue, 13 Aug 2019 16:20:06 +0000 (09:20 -0700)]
Fix indexing issue in lowering of linalg.slice
This CL fixes the stepping through operands when emitting the view sizes of linalg.slice to LLVMIR. This is now consistent with the strides emission.
A relevant test is added.
Fix suggested by Alex Zinenko, thanks!
PiperOrigin-RevId:
263150922
Alex Zinenko [Tue, 13 Aug 2019 10:40:20 +0000 (03:40 -0700)]
LLVM dialect: introduce fmuladd intrinsic as operation
This operation is important to achieve decent performance in computational
kernels. In LLVM, it is implemented as an intrinsic (through function
declaration and function call). Thanks to MLIR's extendable set of operations,
it does not have to differentiate between built-ins and intrinsics, so fmuladd
is introduced as a general type-polymorphic operation. Custom printing and
parsing will be added later.
PiperOrigin-RevId:
263106305
Alex Zinenko [Tue, 13 Aug 2019 08:38:54 +0000 (01:38 -0700)]
GenerateCubinAccessors: use LLVM dialect constants
The GenerateCubinAccessors was generating functions that fill
dynamically-allocated memory with the binary constant of a CUBIN attached as a
stirng attribute to the GPU kernel. This approach was taken to circumvent the
missing support for global constants in the LLVM dialect (and MLIR in general).
Global constants were recently added to the LLVM dialect. Change the
GenerateCubinAccessors pass to emit a global constant array of characters and a
function that returns a pointer to the first character in the array.
PiperOrigin-RevId:
263092052
Mehdi Amini [Tue, 13 Aug 2019 02:12:42 +0000 (19:12 -0700)]
Express ownership transfer in PassManager API through std::unique_ptr (NFC)
Since raw pointers are always passed around for IR construct without
implying any ownership transfer, it can be error prone to have implicit
ownership transferred the same way.
For example this code can seem harmless:
Pass *pass = ....
pm.addPass(pass);
pm.addPass(pass);
pm.run(module);
PiperOrigin-RevId:
263053082
Jacques Pienaar [Mon, 12 Aug 2019 19:52:44 +0000 (12:52 -0700)]
Add start of textmate language grammar.
Basic* grammar to start of with, this doesn't handle custom ops and doesn't
handle ops with regions. But useful enough to make reading the .mlir files
easier.
Followed the approach used for emacs & vim and placed in separate directory
under utils.
* I got a little bit carried away trying to handle attributes and tried to do some custom op printing handling, but finally abandoned it. Also first time writing a textmate grammar so I assume a lot can be improved :)
PiperOrigin-RevId:
262985490
Jacques Pienaar [Mon, 12 Aug 2019 16:02:07 +0000 (09:02 -0700)]
Use unreachable post switch rather than default case.
Prefer to enumerate all cases in the switch instead of using default to allow
compiler to flag missing cases. This also avoids -Wcovered-switch-default
warning.
PiperOrigin-RevId:
262935972
Jacques Pienaar [Mon, 12 Aug 2019 15:59:36 +0000 (08:59 -0700)]
Avoid passing in line/col for files not registered with SourceMgr.
This can result in index expression overflow in "Loc.getPointer() - ColumnNo"
in SourgeMgr.
loc could also be prefixed to the message additionally in this case.
PiperOrigin-RevId:
262935408
Jacques Pienaar [Mon, 12 Aug 2019 15:32:59 +0000 (08:32 -0700)]
Update typo
cond_br was accidentally typed as br_cond in a few examples.
PiperOrigin-RevId:
262929398
Alex Zinenko [Mon, 12 Aug 2019 13:10:29 +0000 (06:10 -0700)]
LLVM dialect: introduce llvm.addressof to access globals
This instruction is a local counterpart of llvm.global that takes a symbol
reference to a global and produces an SSA value containing the pointer to it.
Used in combination, these two operations allow one to use globals with other
operations expecting SSA values. At a cost of IR indirection, we make sure the
functions don't implicitly capture the surrounding SSA values and remain
suitable for parallel processing.
PiperOrigin-RevId:
262908622
Nicolas Vasilache [Mon, 12 Aug 2019 11:08:26 +0000 (04:08 -0700)]
Add lowering of vector dialect to LLVM dialect.
This CL is step 3/n towards building a simple, programmable and portable vector abstraction in MLIR that can go all the way down to generating assembly vector code via LLVM's opt and llc tools.
This CL adds support for converting MLIR n-D vector types to (n-1)-D arrays of 1-D LLVM vectors and a conversion VectorToLLVM that lowers the `vector.extractelement` and `vector.outerproduct` instructions to the proper mix of `llvm.vectorshuffle`, `llvm.extractelement` and `llvm.mulf`.
This has been independently verified to produce proper avx2 code.
Input:
```
func @vec_1d(%arg0: vector<4xf32>, %arg1: vector<8xf32>) -> vector<8xf32> {
%2 = vector.outerproduct %arg0, %arg1 : vector<4xf32>, vector<8xf32>
%3 = vector.extractelement %2[0 : i32]: vector<4x8xf32>
return %3 : vector<8xf32>
}
```
Command:
```
mlir-opt vector-to-llvm.mlir -vector-lower-to-llvm-dialect --disable-pass-threading | mlir-opt -lower-to-cfg -lower-to-llvm | mlir-translate --mlir-to-llvmir | opt -O3 | llc -O3 -march=x86-64 -mcpu=haswell -mattr=fma,avx2
```
Output:
```
vec_1d: # @vec_1d
# %bb.0:
vbroadcastss %xmm0, %ymm0
vmulps %ymm1, %ymm0, %ymm0
retq
```
PiperOrigin-RevId:
262895929
River Riddle [Mon, 12 Aug 2019 01:33:42 +0000 (18:33 -0700)]
NFC: Update pattern rewrite API to pass OwningRewritePatternList by const reference.
The pattern list is not modified by any of these APIs and should thus be passed with const.
PiperOrigin-RevId:
262844002
Chris Lattner [Mon, 12 Aug 2019 01:16:54 +0000 (18:16 -0700)]
ODS: Round out the definitions of the common integer attributes sizes, adding
1/8/16 bit attrs. NFC
PiperOrigin-RevId:
262843016
River Riddle [Sun, 11 Aug 2019 00:26:35 +0000 (17:26 -0700)]
Refactor DenseElementAttr::getValues methods to return full ranges for splats.
The current implementation only returns one element for the splat case, which often comes as a surprise; leading to subtle/confusing bugs. The new behavior will include an iterate over the full range of elements, as defined by the shaped type, by providing the splat value for each iterator index.
PiperOrigin-RevId:
262756780
River Riddle [Sat, 10 Aug 2019 03:07:25 +0000 (20:07 -0700)]
NFC: Standardize the terminology used for parent ops/regions/etc.
There are currently several different terms used to refer to a parent IR unit in 'get' methods: getParent/getEnclosing/getContaining. This cl standardizes all of these methods to use 'getParent*'.
PiperOrigin-RevId:
262680287
Lei Zhang [Sat, 10 Aug 2019 02:03:58 +0000 (19:03 -0700)]
NFC: Refactoring PatternSymbolResolver into SymbolInfoMap
In declarative rewrite rules, a symbol can be bound to op arguments or
results in the source pattern, and it can be bound to op results in the
result pattern. This means given a symbol in the pattern, it can stands
for different things: op operand, op attribute, single op result,
op result pack. We need a better way to model this complexity so that
we can handle according to the specific kind a symbol corresponds to.
Created SymbolInfo class for maintaining the information regarding a
symbol. Also created a companion SymbolInfoMap class for a map of
such symbols, providing insertion and querying depending on use cases.
PiperOrigin-RevId:
262675515
River Riddle [Sat, 10 Aug 2019 00:20:02 +0000 (17:20 -0700)]
NFC: Update usages of OwningRewritePatternList to pass by & instead of &&.
This will allow for reusing the same pattern list, which may be costly to continually reconstruct, on multiple invocations.
PiperOrigin-RevId:
262664599
Alex Zinenko [Fri, 9 Aug 2019 17:45:15 +0000 (10:45 -0700)]
Translation to LLVM IR: use LogicalResult instead of bool
The translation code predates the introduction of LogicalResult and was relying
on the obsolete LLVM convention of returning false on success. Change it to
use MLIR's LogicalResult abstraction instead. NFC.
PiperOrigin-RevId:
262589432
Alex Zinenko [Fri, 9 Aug 2019 15:59:45 +0000 (08:59 -0700)]
LLVM dialect and translation: support global strings
Unlike regular constant values, strings must be placed in some memory and
referred to through a pointer to that memory. Until now, they were not
supported in function-local constant declarations with `llvm.constant`.
Introduce support for global strings using `llvm.global`, which would translate
them into global arrays in LLVM IR and thus make sure they have some memory
allocated for storage.
PiperOrigin-RevId:
262569316
Alex Zinenko [Fri, 9 Aug 2019 15:30:13 +0000 (08:30 -0700)]
Translation to LLVM: support llvm.global
Add support for translating recently introduced llvm.global operations to
global variables in the LLVM IR proper.
PiperOrigin-RevId:
262564700
Nicolas Vasilache [Fri, 9 Aug 2019 14:33:34 +0000 (07:33 -0700)]
External library name mangling support for linalg.
This CL introduces the ability to generate the external library name for Linalg operations.
The problem is that neither mlir or C support overloading and we want a simplified form of name mangling that is still reasonable to read.
This CL creates the name of the external call that Linalg expects from the operation name and the type of its arguments.
The interface library names are updated and use new cases are added for FillOp.
PiperOrigin-RevId:
262556833
Nicolas Vasilache [Fri, 9 Aug 2019 14:28:51 +0000 (07:28 -0700)]
Allow linalg.view to change the underlying elemental type.
This CL adds the ability for linalg.view to act as a bitcast operation.
This will be used when promoting views into faster memory and casting to vector types.
In the process, linalg.view is moved to ODS.
PiperOrigin-RevId:
262556246
Nicolas Vasilache [Fri, 9 Aug 2019 13:55:10 +0000 (06:55 -0700)]
Add a higher-order vector.outerproduct operation in MLIR
This CL is step 2/n towards building a simple, programmable and portable vector abstraction in MLIR that can go all the way down to generating assembly vector code via LLVM's opt and llc tools.
This CL adds the vector.outerproduct operation to the MLIR vector dialect as well as the appropriate roundtrip test. Lowering to LLVM will occur in the following CL.
PiperOrigin-RevId:
262552027
Nicolas Vasilache [Fri, 9 Aug 2019 12:58:19 +0000 (05:58 -0700)]
Add a higher-order vector.extractelement operation in MLIR
This CL is step 2/n towards building a simple, programmable and portable vector abstraction in MLIR that can go all the way down to generating assembly vector code via LLVM's opt and llc tools.
This CL adds the vector.extractelement operation to the MLIR vector dialect as well as the appropriate roundtrip test. Lowering to LLVM will occur in the following CL.
PiperOrigin-RevId:
262545089
Nicolas Vasilache [Fri, 9 Aug 2019 12:24:47 +0000 (05:24 -0700)]
Add support for vector ops in the LLVM dialect
This CL is step 1/n towards building a simple, programmable and portable vector abstraction in MLIR that can go all the way down to generating assembly vector code via LLVM's opt and llc tools.
This CL adds the 3 instructions `llvm.extractelement`, `llvm.insertelement` and `llvm.shufflevector` as documented in the LLVM LangRef "Vector Instructions" section.
The "Experimental Vector Reduction Intrinsics" are left out for now and can be added in the future on a per-need basis.
Appropriate roundtrip and LLVM Target tests are added.
PiperOrigin-RevId:
262542095
Alex Zinenko [Fri, 9 Aug 2019 12:01:23 +0000 (05:01 -0700)]
LLVM Dialect: introduce llvm.global
Introduce an operation that defines global constants and variables in the LLVM
dialect, to reflect the corresponding LLVM IR capability. This operation is
expected to live in the top-level module and behaves similarly to
llvm.constant. It currently does not model many of the attributes supported by
the LLVM IR for global values (memory space, alignment, thread-local, linkage)
and will be extended as the relevant use cases appear.
PiperOrigin-RevId:
262539445
Nagy Mostafa [Fri, 9 Aug 2019 01:29:23 +0000 (18:29 -0700)]
Add support for floating-point comparison 'fcmp' to the LLVM dialect.
This adds support for fcmp to the LLVM dialect and adds any necessary lowerings, as well as support for EDSCs.
Closes tensorflow/mlir#69
PiperOrigin-RevId:
262475255
Diego Caballero [Thu, 8 Aug 2019 23:02:50 +0000 (16:02 -0700)]
Enable TTI for host TargetMachine in JitRunner
This commit improves JitRunner so that it creates a target machine
for the current CPU host which is used to properly initialize LLVM's
TargetTransformInfo for such a target. This will enable optimizations
such as vectorization in LLVM when using JitRunner. Please, note that,
as part of this work, JITTargetMachineBuilder::detectHost() has been
extended to include the host CPU name and sub-target features as part of
the host CPU detection (https://reviews.llvm.org/D65760).
Closes tensorflow/mlir#71
PiperOrigin-RevId:
262452525
Mahesh Ravishankar [Thu, 8 Aug 2019 21:40:03 +0000 (14:40 -0700)]
Build SymbolTable upfront in ModuleOp verification.
Building the symbol table upfront from module op allows for O(1)
lookup of the function while verifying duplicate EntryPointOp within
the module.
PiperOrigin-RevId:
262435697
Mahesh Ravishankar [Thu, 8 Aug 2019 21:18:39 +0000 (14:18 -0700)]
Add SymbolTable trait to spirv::ModuleOp.
Adding the SymbolTable trait allows looking up the name of the
functions using the symbol table while verifying EntryPointOps instead
of manually tracking the function names.
PiperOrigin-RevId:
262431220
Alex Zinenko [Thu, 8 Aug 2019 19:18:05 +0000 (12:18 -0700)]
Lexer: NFC: sort helper methods alphabetically
Lexer methods were added progressively as implementation advanced. The rest of
MLIR now tends to sort methods alphabetically for better discoverability in
absence of tooling. Sort the lexer methods as well.
PiperOrigin-RevId:
262406992
Alex Zinenko [Thu, 8 Aug 2019 19:11:27 +0000 (12:11 -0700)]
FunctionSupport: wrap around bool to have a more semantic callback type
This changes the type of the function type-building callback from
(ArrayRef<Type>, ArrayRef<Type>, bool, string &) to (ArrayRef<Type>,
ArrayRef<Type>, VariadicFlag, String &) to make the intended use clear from the
callback signature alone.
Also rearrange type definitions in Parser.cpp to make them more sorted
alphabetically.
PiperOrigin-RevId:
262405851
Alex Zinenko [Thu, 8 Aug 2019 16:41:48 +0000 (09:41 -0700)]
Introduce support for variadic function signatures for the LLVM dialect
LLVM function type has first-class support for variadic functions. In the
current lowering pipeline, it is emulated using an attribute on functions of
standard function type. In LLVMFuncOp that has LLVM function type, this can be
modeled directly. Introduce parsing support for variadic arguments to the
function and use it to support variadic function declarations in LLVMFuncOp.
Function definitions are currently not supported as that would require modeling
va_start/va_end LLVM intrinsics in the dialect and we don't yet have a
consistent story for LLVM intrinsics.
PiperOrigin-RevId:
262372651
Kan Chen [Thu, 8 Aug 2019 16:30:09 +0000 (09:30 -0700)]
Command toyc should be toyc-ch2 in this chapter
Closes tensorflow/mlir#70
PiperOrigin-RevId:
262370485
Alex Zinenko [Thu, 8 Aug 2019 16:14:24 +0000 (09:14 -0700)]
Parser: treat implicit top-level module as an SSA name scope
Now that modules are also operations, nothing prevents one from defining SSA
values in the module. Doing so in an implicit top-level module, i.e. outside
of a `module` operation, was leading to a crash because the implicit module was
not associated with an SSA name scope. Create a name scope before parsing the
top-level module to fix this.
PiperOrigin-RevId:
262366891
Nicolas Vasilache [Thu, 8 Aug 2019 16:09:29 +0000 (09:09 -0700)]
Add canonicalization pattern for linalg.dim
This CL introduces canonicalization patterns for linalg.dim.
This allows the dimenions of chains of view, slice and subview operations to simplify.
Down the line, when mixed with cse, this also allows better composition of linalg tiling and fusion by tracking operations that give the same result (not in this CL).
PiperOrigin-RevId:
262365865
Eric Schweitz [Thu, 8 Aug 2019 08:05:26 +0000 (01:05 -0700)]
Add the LLVM IR unreachable instruction to the LLVMIR dialect.
http://llvm.org/docs/LangRef.html#unreachable-instruction
Closes tensorflow/mlir#64
PiperOrigin-RevId:
262301557