Commit Graph

201 Commits

Author SHA1 Message Date
Rasmus Munk Larsen 1df5f3159e Fix typo in Toy tutorial documentation
PiperOrigin-RevId: 255054639
2019-06-25 15:00:08 -07:00
Lei Zhang 8f77d2afed [spirv] Basic serializer and deserializer
This CL adds the basic SPIR-V serializer and deserializer for converting
SPIR-V module into the binary format and back. Right now only an empty
module with addressing model and memory model is supported; (de)serialize
other components will be added gradually with subsequent CLs.

The purpose of this library is to enable importing SPIR-V binary modules
to run transformations on them and exporting SPIR-V modules to be consumed
by execution environments. The focus is transformations, which inevitably
means changes to the binary module; so it is not designed to be a general
tool for investigating the SPIR-V binary module and does not guarantee
roundtrip equivalence (at least for now).

PiperOrigin-RevId: 254473019
2019-06-22 09:17:21 -07:00
Nicolas Vasilache 0804750c9b Uniformize usage of OpBuilder& (NFC)
Historically the pointer-based version of builders was used.
This CL uniformizes to OpBuilder &

PiperOrigin-RevId: 254280885
2019-06-22 09:14:49 -07:00
Mahesh Ravishankar d7ba69e811 Add SPIRV Image Type according to the spec described here :
https://www.khronos.org/registry/spir-v/specs/1.0/SPIRV.html#OpTypeImage.

Add new enums to describe Image dimensionality, Image Depth, Arrayed
information, Sampling, Sampler User information, and Image format.
Doesn's support the Optional Access qualifier at this stage

Fix Enum generator for tblgen to add "_" at the beginning if the enum
starts with a number.

PiperOrigin-RevId: 254091423
2019-06-19 23:09:01 -07:00
Geoffrey Martin-Noble d7d69569e7 Rename -verify mlir-opt flag to -verify-expected-diagnostics
This name has caused some confusion because it suggests that it's running op verification (and that this verification isn't getting run by default).

PiperOrigin-RevId: 254035268
2019-06-19 23:08:03 -07:00
Lei Zhang 23962b0d63 [spirv] Add spv.Variable
This is a direct modelling of SPIR-V's OpVariable. The custom assembly format
parsers/prints descriptor in a nicer way if presents. There are other common
decorations that can appear on variables like builtin, which can be supported
later.

This CL additionally deduplicates the parser/printer/verifier declaration
in op definitions by adding defaults to SPV_Op base.
by adding

PiperOrigin-RevId: 253828254
2019-06-19 23:06:55 -07:00
Lei Zhang 980bf61b4b [spirv] Add spv.constant
This CL defines a single `spv.constant` op to represent various
flavors of SPIR-V constant instructions.

PiperOrigin-RevId: 253665716
2019-06-19 23:04:48 -07:00
Lei Zhang 2091ed5e30 [spirv] Add doc regarding the SPIR-V dialect
* Add basic design philosophy
* Add type syntax to both the doc and type parser comments

PiperOrigin-RevId: 253625782
2019-06-19 23:04:10 -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
Lei Zhang 1be9fc6611 [TableGen] Generating enum definitions and utility functions
Enum attributes can be defined using `EnumAttr`, which requires all its cases
to be defined with `EnumAttrCase`. To facilitate the interaction between
`EnumAttr`s and their C++ consumers, add a new EnumsGen TableGen backend
to generate a few common utilities, including an enum class, `llvm::DenseMapInfo`
for the enum class, conversion functions from/to strings.

This is controlled via the `-gen-enum-decls` and `-gen-enum-defs` command-line
options of `mlir-tblgen`.

PiperOrigin-RevId: 252209623
2019-06-09 16:24:08 -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 ecfd5f8cad Make it explicit that the IR printing instrumentation should not be used when multi-threading is enabled.
PiperOrigin-RevId: 251478399
2019-06-09 16:16:47 -07:00
Alex Zinenko 252de8eca0 Introduce OpOperandAdaptors and emit them from ODS
When manipulating generic operations, such as in dialect conversion /
rewriting, it is often necessary to view a list of Values as operands to an
operation without creating the operation itself.  The absence of such view
makes dialect conversion patterns, among others, to use magic numbers to obtain
specific operands from a list of rewritten values when converting an operation.
Introduce XOpOperandAdaptor classes that wrap an ArrayRef<Value *> and provide
accessor functions identical to those available in XOp.  This makes it possible
for conversions to use these adaptors to address the operands with names rather
than rely on their position in the list.  The adaptors are generated from ODS
together with the actual operation definitions.

This is another step towards making dialect conversion patterns specific for a
given operation.

Illustrate the approach on conversion patterns in the standard to LLVM dialect
conversion.

PiperOrigin-RevId: 251232899
2019-06-03 19:26:12 -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
MLIR Team 5a91b9896c Remove "size" property of affine maps.
--

PiperOrigin-RevId: 250572818
2019-06-01 20:09:02 -07:00
River Riddle c455ecef22 Add an example of accessing the impl storage to the 'DefiningAttributesAndTypes' document.
--

PiperOrigin-RevId: 250553898
2019-06-01 20:07:51 -07:00
River Riddle ae1651368f NFC: Rename DialectConversionPattern to ConversionPattern.
--

PiperOrigin-RevId: 249857277
2019-06-01 20:00:13 -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
Thomas Joerg 6a31f9a7e3 Automated rollback of changelist 247713812.
PiperOrigin-RevId: 249605627
2019-06-01 19:57:44 -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
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
Geoffrey Martin-Noble da37b0a536 Clean up container type names in OpBase
Establish the following convention:
    1. Container class types end in "Of" (e.g. TensorOf) and take a list of allowed types.
    2. An X container where only a single type is allowed is called TypeX (e.g. I32Tensor).
    3. An X container where any type is allowed is called AnyX (e.g. AnyTensor).

--

PiperOrigin-RevId: 249281018
2019-06-01 19:55:03 -07:00
Nicolas Vasilache fdbbb3c274 Use lambdas for nesting edsc constructs.
Using ArrayRef introduces issues with the order of evaluation between a constructor and
    the arguments of the subsequent calls to the `operator()`.
    As a consequence the order of captures is not well-defined can go wrong with certain compilers (e.g. gcc-6.4).
    This CL fixes the issue by using lambdas in lieu of ArrayRef.

--

PiperOrigin-RevId: 249114775
2019-05-20 13:50:28 -07:00
Geoffrey Martin-Noble 3be4346cdf Rename "AnyOf" and "AllOf" combined predicates to "Or" and "And", respectively.
This reduces conflict between these and other type names, where we're moving towards "Of" indicating a container type containing certain types. It also better matches the "Neg" predicate modifier and generally is pretty understandable/readable for predicates.

--

PiperOrigin-RevId: 249076508
2019-05-20 13:49:44 -07:00
Lei Zhang 20e0cedfbd [ODS] Allow dialect to specify C++ namespaces
Previously we force the C++ namespaces to be `NS` if `SomeOp` is defined as
    `NS_SomeOp`. This is too rigid as it does not support nested namespaces
    well. This CL adds a "namespace" field into the Dialect class to allow
    flexible namespaces.

--

PiperOrigin-RevId: 249064981
2019-05-20 13:49:27 -07:00
River Riddle 68250edbfa NFC: Tidy up DialectConversion.cpp and rename DialectOpConversion to DialectConversionPattern.
--

PiperOrigin-RevId: 248980810
2019-05-20 13:48:19 -07:00
River Riddle 1966d34da4 Move the ConversionListBuilder utility to PatternMatch.h and rename it to RewriteListBuilder. It has no specific functionality for DialectOpConversion patterns and can be useful for RewritePatterns in general.
--

PiperOrigin-RevId: 248884466
2019-05-20 13:47:28 -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
River Riddle 742863b497 Add a new tutorial document that details how to define Dialect Attributes and Types.
--

PiperOrigin-RevId: 248417063
2019-05-20 13:43:40 -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
River Riddle 636b7f6f54 Add a new document detailing the diagnostics infrastructure.
--

PiperOrigin-RevId: 248275851
2019-05-20 13:42:38 -07:00
Lei Zhang 635bebaac9 Update "Table-driven Op Definition Specification" doc
This CL turns the previous "Op Definition" doc into a manual for table-driven
    op definition specification by fleshing out more details of existing mechanisms.

--

PiperOrigin-RevId: 248013274
2019-05-20 13:40:43 -07:00
Andy Davis 59100a0177 Move Affine Expressions and Affine Structures documentation from LangRef to Affine Dialect doc.
--

PiperOrigin-RevId: 247971222
2019-05-20 13:39:13 -07:00
Alex Zinenko 3d62ef8018 Update region documentation
Restructure the Regions section in LangRef to avoid having a wall of text and
    reflect a recent evolution of the design.  Unspecify region types, that are put
    on hold until use cases arise.

    Update the Rationale doc with a list of design decisions related to regions.
    Separately list the design alternatives that were considered and discarded due
    to the lack of existing use cases.

--

PiperOrigin-RevId: 247943144
2019-05-20 13:38:22 -07:00
River Riddle d7c467ded1 Remove the explicit "friend Operation" statement from each of the derived operations now that op casting is no longer inside of Operation.
--

PiperOrigin-RevId: 247791672
2019-05-20 13:38:02 -07:00
Mehdi Amini ecd4c7d67a Revert "Pass for outlining gpu.launch operation bodies into kernel functions called by gpu.launch_func operations"
OSS build was broken (missing CMakeLists.txt changes and compilation failures on Ubuntu)

Automated rollback of changelist 247564213.

PiperOrigin-RevId: 247713812
2019-05-10 21:26:30 -07:00
Thomas Joerg 0a21ab70fa Pass for outlining gpu.launch operation bodies into kernel functions called by gpu.launch_func operations.
--

PiperOrigin-RevId: 247564213
2019-05-10 19:27:40 -07:00
Thomas Joerg cffed537a1 Fix a few typos in the Toy tutorial documentation
--

PiperOrigin-RevId: 247047009
2019-05-10 19:23:40 -07:00
Thomas Joerg b28bafd74f Add operations to produce block/index ids and dimensions to the gpu dialect.
--

PiperOrigin-RevId: 246976227
2019-05-10 19:23:32 -07:00
MLIR Team 465df0d916 Add the "gpu.launch_func" op to the GPU dialect.
The idea is to lower `gpu.launch` operations into `gpu.launch_func` operations by outlining the kernel body into a function, which is closer to the NVVM model.

--

PiperOrigin-RevId: 246806890
2019-05-06 08:30:07 -07:00
Alex Zinenko b7b75cf74c GPU dialect: introduce custom syntax for gpu.launch
This syntax removes boilerplate and verbose list of region arguments in the
    header of the entry block.  It groups operands into segments related to GPU
    blocks, GPU threads as well as the operands that are forwarded to the kernel.
    The two former segments are also used to give names to the region arguments
    that are used for GPU blocks and threads inside the kernel body region.

--

PiperOrigin-RevId: 246792329
2019-05-06 08:29:57 -07:00
Alex Zinenko d3380a504f Change syntax of regions in the generic form of operations
The generic form of operations currently supports optional regions to be
    located after the operation type.  As we are going to add a type to each
    region in a leading position in the region syntax, similarly to functions, it
    becomes ambiguous to have regions immediately after the operation type.  Put
    regions between operands the optional list of successors in the generic
    operation syntax and wrap them in parentheses.  The effect on the exisitng IR
    syntax is minimal since only three operations (`affine.for`, `affine.if` and
    `gpu.kernel`) currently use regions.

--

PiperOrigin-RevId: 246787087
2019-05-06 08:29:48 -07:00
Mehdi Amini e2e89f5c83 Specify Regions in LangRef
Region is the generalization of a function body (a list of blocks forming a CFG) to be allowed to be enclosed inside any operation. This nesting of IR is already leveraged in the affine dialect to support `affine.for`, `affine.if`, and `gpu.launch` operations.

--

PiperOrigin-RevId: 246766830
2019-05-06 08:29:38 -07:00
Mehdi Amini cad369b667 Minor fixes (formatting/typos) to the DeveloperGuide
--

PiperOrigin-RevId: 246621047
2019-05-06 08:28:30 -07:00
Mehdi Amini 4db06d84d8 Automated rollback of changelist 246610168.
PiperOrigin-RevId: 246610394
2019-05-06 08:28:11 -07:00
Mehdi Amini 00dea78fdc Add a section in the DeveloperGuide about avoiding unsigned integer
--

PiperOrigin-RevId: 246610168
2019-05-06 08:28:01 -07:00
Mehdi Amini 1a2f2d1216 Add a section in the DeveloperGuide for the naming convention of command line options
--

PiperOrigin-RevId: 246610123
2019-05-06 08:27:51 -07:00
Nicolas Vasilache 258e8d9ce2 Prepend an "affine-" prefix to Affine pass option names - NFC
Trying to activate both LLVM and MLIR passes in mlir-cpu-runner showed name collisions when registering pass names.
    One possible way of disambiguating that should also work across dialects is to prepend the dialect name to the passes that specifically operate on that dialect.

    With this CL, mlir-cpu-runner tests still run when both LLVM and MLIR passes are registered

--

PiperOrigin-RevId: 246539917
2019-05-06 08:26:44 -07:00
Jacques Pienaar 1e217ccacd Start developer guide doc.
This is just a bare skeleton to start populating developer policies and
    guidelines. LLVM side this would be multiple separate documents (coding
    standard & programmer's manual) but starting with one and we can break it out
    into multiple if the content so dictates.

--

PiperOrigin-RevId: 246433346
2019-05-06 08:26:06 -07:00
MLIR Team e3be54cd4a Fix a minor formatting issue.
--

PiperOrigin-RevId: 246307329
2019-05-06 08:24:31 -07:00