platform/upstream/llvm.git
5 years agoAdd documentation for the new pass infrastructure.
River Riddle [Thu, 7 Mar 2019 01:34:42 +0000 (17:34 -0800)]
Add documentation for the new pass infrastructure.

PiperOrigin-RevId: 237153501

5 years agoAdds offset argument to specified range of ids know to be aligned when calling mergeA...
MLIR Team [Thu, 7 Mar 2019 00:41:32 +0000 (16:41 -0800)]
Adds offset argument to specified range of ids know to be aligned when calling mergeAndAlignIds (used by FlatAffineConstraints).
Supports use case where FlatAffineConstraints::composeMap adds dim identifiers with no SSA values (because the identifiers are the result of an AffineValueMap which is not materialized in the IR and thus has no SSA Value results).

PiperOrigin-RevId: 237145506

5 years agoFix opt build.
MLIR Team [Thu, 7 Mar 2019 00:18:56 +0000 (16:18 -0800)]
Fix opt build.

PiperOrigin-RevId: 237141751

5 years agoAdd FlatAffineConstraints::containsId to avoid using findId when position isn't
Uday Bondhugula [Thu, 7 Mar 2019 00:18:27 +0000 (16:18 -0800)]
Add FlatAffineConstraints::containsId to avoid using findId when position isn't
needed + other cleanup
- clean up unionBoundingBox (hoist SmallVector allocations out of loop).

PiperOrigin-RevId: 237141668

5 years agoFix an incorrect comment in builder-api-test.
Nicolas Vasilache [Wed, 6 Mar 2019 22:34:26 +0000 (14:34 -0800)]
Fix an incorrect comment in builder-api-test.

Also address post commit cleanups that were missed.

PiperOrigin-RevId: 237122077

5 years agoAdd helper classes to declarative builders to help write end-to-end custom ops.
Nicolas Vasilache [Wed, 6 Mar 2019 21:54:41 +0000 (13:54 -0800)]
Add helper classes to declarative builders to help write end-to-end custom ops.

This CL adds the same helper classes that exist in the AST form of EDSCs to support a basic indexing notation and emit the proper load and store operations and capture MemRefViews as function arguments.

This CL also adds a wrapper class LoopNestBuilder to allow generic rank-agnostic loops over indices.

PiperOrigin-RevId: 237113755

5 years ago[TableGen] Emit verification code for op results
Lei Zhang [Wed, 6 Mar 2019 20:50:01 +0000 (12:50 -0800)]
[TableGen] Emit verification code for op results

They can be verified using the same logic as operands.

PiperOrigin-RevId: 237101461

5 years agoNFC: Remove 'Result' from the analysis manager api to better reflect the implementati...
River Riddle [Wed, 6 Mar 2019 20:03:14 +0000 (12:03 -0800)]
NFC: Remove 'Result' from the analysis manager api to better reflect the implementation. There is no distinction between analysis computation and result.

PiperOrigin-RevId: 237093101

5 years agoMore graceful failure when verifying llvm.noalias.
Dimitrios Vytiniotis [Wed, 6 Mar 2019 19:05:43 +0000 (11:05 -0800)]
More graceful failure when verifying llvm.noalias.

PiperOrigin-RevId: 237081778

5 years agoAdd support for preserving specific analyses in the analysis manager. Passes can...
River Riddle [Wed, 6 Mar 2019 19:04:22 +0000 (11:04 -0800)]
Add support for preserving specific analyses in the analysis manager. Passes can now preserve specific analyses via 'markAnalysesPreserved'.

Example:

markAnalysesPreserved<DominanceInfo>();
markAnalysesPreserved<DominanceInfo, PostDominanceInfo>();

PiperOrigin-RevId: 237081454

5 years agoHotfix for unused variable in opt mode
Nicolas Vasilache [Wed, 6 Mar 2019 18:28:31 +0000 (10:28 -0800)]
Hotfix for unused variable in opt mode

PiperOrigin-RevId: 237073601

5 years agoUsing llvm.noalias attribute when generating LLVMIR.
Dimitrios Vytiniotis [Wed, 6 Mar 2019 17:34:53 +0000 (09:34 -0800)]
Using llvm.noalias attribute when generating LLVMIR.

PiperOrigin-RevId: 237063104

5 years ago[EDSC] Hotfix: Avoid implicit OpPointer -> OpType* conversion
Nicolas Vasilache [Wed, 6 Mar 2019 16:39:27 +0000 (08:39 -0800)]
[EDSC] Hotfix: Avoid implicit OpPointer -> OpType* conversion

An implicit OpPointer -> OpType* conversion results in AddressSanitizer triggering a stack-use-after-scope error (which may be a false positive).
Avoid using such patterns to make life good again.

PiperOrigin-RevId: 237053863

5 years agoPython bindinds: support functions with attributes and argument attributes
Alex Zinenko [Wed, 6 Mar 2019 15:58:18 +0000 (07:58 -0800)]
Python bindinds: support functions with attributes and argument attributes

Currently, Python bindings provide support for declarting and defining MLIR
functions given a list of argument and result types.  Extend the support for
both function declaration and function definition to handle optional function
attributes and function argument attributes.  Function attributes are exposed
as keyword arguments on function declaration and definition calls.  Function
argument attributes are exposed through a special object that combines the
argument type and its list of attributes.  Such objects can be passed instead
of bare types into the type declaration and definition calls.  They can be
constructed from bare types and reused in different declarations.

Note that, from the beginning, Python bindings did not pass through C bindings
to declare and define functions.  This commit keeps the direct interaction
between Python and C++.

PiperOrigin-RevId: 237047561

5 years agoAdd an eager API version for BR and COND_BR
Nicolas Vasilache [Wed, 6 Mar 2019 15:46:36 +0000 (07:46 -0800)]
Add an eager API version for BR and COND_BR

When building unstructured control-flow there is a need to construct mlir::Block* before being able to fill them. This invites goto-style programming.

This CL introduces an alternative eager API for BR and COND_BR in which blocks are created eagerly and captured on the fly.

This allows reducing the number of calls to `BlockBuilder` from 4 to 2 in the `builder_blocks_eager` test and from 3 to 2 in the `builder_cond_branch_eager` test.

PiperOrigin-RevId: 237046114

5 years agoAdd support for Branches in edsc::Builder
Nicolas Vasilache [Wed, 6 Mar 2019 14:12:39 +0000 (06:12 -0800)]
Add support for Branches in edsc::Builder

This CL adds support for BranchHandle and BranchBuilder that require a slightly different
abstraction since an mlir::Block is not an mlir::Value.

This CL also adds support for the BR and COND_BR instructions and the relevant tests.

PiperOrigin-RevId: 237034312

5 years agoStart a new implementation for edsc::Builder
Nicolas Vasilache [Wed, 6 Mar 2019 13:46:09 +0000 (05:46 -0800)]
Start a new implementation for edsc::Builder

This CL reworks the design of EDSCs from first principles.
It introduces a ValueHandle which can hold either:
1. an eagerly typed, delayed Value*
2. a precomputed Value*

A ValueHandle can be manipulated with intrinsic operations a nested within a NestedBuilder. These NestedBuilder are a more idiomatic nested builder abstraction that should feel intuitive to program in C++.

Notably, this abstraction does not require an AST to stage the construction of MLIR snippets from C++. Instead, the abstraction makes use of orderings between definition and declaration of ValueHandles and provides a NestedBuilder and a LoopBuilder helper classes to handle those orderings.

All instruction creations are meant to use the templated ValueHandle::create<> which directly calls mlir::Builder.create<>.

For now the EDSC AST and the builders live side-by-side until the C API is ported.

PiperOrigin-RevId: 237030945

5 years agoTableGen: allow mixing attributes and operands in the Arguments DAG of Op definition
Alex Zinenko [Wed, 6 Mar 2019 09:23:41 +0000 (01:23 -0800)]
TableGen: allow mixing attributes and operands in the Arguments DAG of Op definition

The existing implementation of the Op definition generator assumes and relies
on the fact that native Op Attributes appear after its value-based operands in
the Arguments list.  Furthermore, the same order is used in the generated
`build` function for the operation.  This is not desirable for some operations
with mandatory attributes that would want the attribute to appear upfront for
better consistency with their textual representation, for example `cmpi` would
prefer the `predicate` attribute to be foremost in the argument list.

Introduce support for using attributes and operands in the Arguments DAG in no
particular order.  This is achieved by maintaining a list of Arguments that
point to either the value or the attribute and are used to generate the `build`
method.

PiperOrigin-RevId: 237002921

5 years agoUse FlatAffineConstraints::unionBoundingBox to perform slice bounds union for loop...
MLIR Team [Wed, 6 Mar 2019 04:33:30 +0000 (20:33 -0800)]
Use FlatAffineConstraints::unionBoundingBox to perform slice bounds union for loop fusion pass (WIP).
Adds utility to convert slice bounds to a FlatAffineConstraints representation.
Adds utility to FlatAffineConstraints to promote loop IV symbol identifiers to dim identifiers.

PiperOrigin-RevId: 236973261

5 years agoDMA generation CL flag update
Uday Bondhugula [Wed, 6 Mar 2019 01:19:47 +0000 (17:19 -0800)]
DMA generation CL flag update

- allow mem capacity to be overridden by command-line flag
- change default fast mem space to 2

PiperOrigin-RevId: 236951598

5 years agoAdd missing run command to fusion test cases - follow up to cl/236882988
Uday Bondhugula [Wed, 6 Mar 2019 00:54:34 +0000 (16:54 -0800)]
Add missing run command to fusion test cases - follow up to cl/236882988

PiperOrigin-RevId: 236947383

5 years agoChange Pass:getFunction() to return pointer instead of ref - NFC
Uday Bondhugula [Tue, 5 Mar 2019 23:05:34 +0000 (15:05 -0800)]
Change Pass:getFunction() to return pointer instead of ref - NFC

- change this for consistency - everything else similar takes/returns a
  Function pointer - the FuncBuilder ctor,
  Block/Value/Instruction::getFunction(), etc.
- saves a whole bunch of &s everywhere

PiperOrigin-RevId: 236928761

5 years agoChange the TensorFlow attribute prefix from "tf$" to "tf." to match the specification...
River Riddle [Tue, 5 Mar 2019 22:42:55 +0000 (14:42 -0800)]
Change the TensorFlow attribute prefix from "tf$" to "tf." to match the specification of dialect attributes. This also fixes tblgen generation of dialect attributes that used the sugared name "tf$attr" as c++ identifiers.

PiperOrigin-RevId: 236924392

5 years agoAdd a unittests directory for MLIR and start adding tests for OperandStorage from...
River Riddle [Tue, 5 Mar 2019 21:37:48 +0000 (13:37 -0800)]
Add a unittests directory for MLIR and start adding tests for OperandStorage from InstructionSupport.h.

PiperOrigin-RevId: 236911640

5 years agoNFC: Move OperandStorage into a new header file for instruction support utilities...
River Riddle [Tue, 5 Mar 2019 19:56:57 +0000 (11:56 -0800)]
NFC: Move OperandStorage into a new header file for instruction support utilities, InstructionSupport.h.

PiperOrigin-RevId: 236892857

5 years agoFix and improve detectAsMod
Uday Bondhugula [Tue, 5 Mar 2019 19:08:41 +0000 (11:08 -0800)]
Fix and improve detectAsMod
- fix for the mod detection
- simplify/avoid the mod at construction (if the dividend is already known to be less
  than the divisor), since the information is available at hand there

PiperOrigin-RevId: 236882988

5 years agoFix lower/upper bound mismatch in stripmineSink
Nicolas Vasilache [Tue, 5 Mar 2019 18:50:50 +0000 (10:50 -0800)]
Fix lower/upper bound mismatch in stripmineSink

Also beef up the corresponding test case.

PiperOrigin-RevId: 236878818

5 years agoFix dialect attribute hooks so that they accept a NamedAttribute instead of an Attribute.
River Riddle [Tue, 5 Mar 2019 18:05:53 +0000 (10:05 -0800)]
Fix dialect attribute hooks so that they accept a NamedAttribute instead of an Attribute.

PiperOrigin-RevId: 236869321

5 years agoTableGen: fix builder generation for optional attributes
Alex Zinenko [Tue, 5 Mar 2019 13:48:24 +0000 (05:48 -0800)]
TableGen: fix builder generation for optional attributes

The recently introduced support for generating MLIR Operations with optional
attributes did not handle the formatted string emission properly, in particular
it did not escape `{` and `}` in calls to `formatv` leading to assertions
during TableGen op definition generation.  Fix this by splitting out the
unncessary braces from the format string.  Additionally, fix the emission of
the builder argument comment to correctly indicate which attributes are indeed
optional and which are not.

PiperOrigin-RevId: 236832230

5 years agoMake sure that fusion test cases don't have out of bounds accesses
Uday Bondhugula [Tue, 5 Mar 2019 01:26:46 +0000 (17:26 -0800)]
Make sure that fusion test cases don't have out of bounds accesses

- fix out of bounds test case
- -memref-bound-check on the test/Transforms/loop-fusion.mlir no longer reports any
  errors, before or after -loop-fusion is run

PiperOrigin-RevId: 236757658

5 years agoAdds loop attribute as a temporary work around to prevent slice fusion of loop nests...
MLIR Team [Mon, 4 Mar 2019 23:14:12 +0000 (15:14 -0800)]
Adds loop attribute as a temporary work around to prevent slice fusion of loop nests containing instructions with side effects (the proper solution will be do use memref read/write regions in the future).

PiperOrigin-RevId: 236733739

5 years agoBug fix for getConstantBoundOnDimSize
Uday Bondhugula [Mon, 4 Mar 2019 22:58:59 +0000 (14:58 -0800)]
Bug fix for getConstantBoundOnDimSize

- this was detected when memref-bound-check was run on the output of the
  loop-fusion pass
- the addition (to represent ceildiv as a floordiv) had to be performed only
  for the constant term of the constraint
- update test cases
- memref-bound-check no longer returns an error on the output of this test case

PiperOrigin-RevId: 236731137

5 years agoSupporting conversion of argument attributes along their types.
Dimitrios Vytiniotis [Mon, 4 Mar 2019 21:04:59 +0000 (13:04 -0800)]
Supporting conversion of argument attributes along their types.

This fixes a bug: previously, during conversion function argument
attributes were neither beings passed through nor converted. This fix
extends DialectConversion to allow for simultaneous conversion of the
function type and the argument attributes.

This was important when lowering MLIR to LLVM where attribute
information (e.g. noalias) needs to be preserved in MLIR(LLVMDialect).

Longer run it seems reasonable that we want to convert both the
function attribute and its type and the argument attributes, but that
requires a small refactoring in Function.h to aggregate these three
fields in an inner struct, which will require some discussion.

PiperOrigin-RevId: 236709409

5 years agoAdd a 'verifyPasses' flag to the PassManager that specifies if the IR should be verif...
River Riddle [Mon, 4 Mar 2019 20:33:13 +0000 (12:33 -0800)]
Add a 'verifyPasses' flag to the PassManager that specifies if the IR should be verified after each pass. This also adds a "verify-each" flag to mlir-opt to optionally disable running the verifier after each pass.

PiperOrigin-RevId: 236703760

5 years agoHandle MemRefRegion::compute return value in loop fusion pass (NFC).
MLIR Team [Mon, 4 Mar 2019 19:01:25 +0000 (11:01 -0800)]
Handle MemRefRegion::compute return value in loop fusion pass (NFC).

PiperOrigin-RevId: 236685849

5 years agoIntroduce the notion of dialect attributes and dependent attributes. A dialect attrib...
River Riddle [Sun, 3 Mar 2019 06:34:18 +0000 (22:34 -0800)]
Introduce the notion of dialect attributes and dependent attributes. A dialect attribute derives its context from a specific dialect, whereas a dependent attribute derives context from what it is attached to. Following this, we now enforce that functions and function arguments may only contain dialect specific attributes. These are generic entities and cannot provide any specific context for a dependent attribute.

Dialect attributes are defined as:

        dialect-namespace `.` attr-name `:` attribute-value

Dialects can override any of the following hooks to verify the validity of a given attribute:
  * verifyFunctionAttribute
  * verifyFunctionArgAttribute
  * verifyInstructionAttribute

PiperOrigin-RevId: 236507970

5 years agoImplement the initial AnalysisManagement infrastructure, with the introduction of...
River Riddle [Sun, 3 Mar 2019 05:46:58 +0000 (21:46 -0800)]
Implement the initial AnalysisManagement infrastructure, with the introduction of the FunctionAnalysisManager and ModuleAnalysisManager classes. These classes provide analysis computation, caching, and invalidation for a specific IR unit. The invalidation is currently limited to either all or none, i.e. you cannot yet preserve specific analyses.

An analysis can be any class, but it must provide the following:
* A constructor for a given IR unit.

struct MyAnalysis {
  // Compute this analysis with the provided module.
  MyAnalysis(Module *module);
};

Analyses can be accessed from a Pass by calling either the 'getAnalysisResult<AnalysisT>' or 'getCachedAnalysisResult<AnalysisT>' methods. A FunctionPass may query for a cached analysis on the parent module with 'getCachedModuleAnalysisResult'. Similary, a ModulePass may query an analysis, it doesn't need to be cached, on a child function with 'getFunctionAnalysisResult'.

By default, when running a pass all cached analyses are set to be invalidated. If no transformation was performed, a pass can use the method 'markAllAnalysesPreserved' to preserve all analysis results. As noted above, preserving specific analyses is not yet supported.

PiperOrigin-RevId: 236505642

5 years agoAdd an assertion on the builder to ensure that a block is set before creating an...
Mehdi Amini [Sun, 3 Mar 2019 05:18:19 +0000 (21:18 -0800)]
Add an assertion on the builder to ensure that a block is set before creating an operation

This is more friendly for the user than a raw segfault

PiperOrigin-RevId: 236504102

5 years agoSet the namespace of the StandardOps dialect to "std", but add a special case to...
River Riddle [Sun, 3 Mar 2019 02:03:03 +0000 (18:03 -0800)]
Set the namespace of the StandardOps dialect to "std", but add a special case to the parser to allow parsing standard operations without the "std" prefix. This will now allow for the standard dialect to be looked up dynamically by name.

PiperOrigin-RevId: 236493865

5 years agoRemove hidden flag from fusion CL options
Uday Bondhugula [Sat, 2 Mar 2019 01:42:13 +0000 (17:42 -0800)]
Remove hidden flag from fusion CL options

PiperOrigin-RevId: 236409185

5 years agoUpdate addSliceBounds to deal with loops with floor's/mod's.
Uday Bondhugula [Sat, 2 Mar 2019 01:06:25 +0000 (17:06 -0800)]
Update addSliceBounds to deal with loops with floor's/mod's.

- This change only impacts the cost model for fusion, given the way
  addSliceBounds was being used. It so happens that the output in spite of this
  CL's fix is the same; however, the assertions added no longer fail. (an
  invalid/inconsistent memref region was being used earlier).

PiperOrigin-RevId: 236405030

5 years agoNFC. Move all of the remaining operations left in BuiltinOps to StandardOps. The...
River Riddle [Sat, 2 Mar 2019 00:58:00 +0000 (16:58 -0800)]
NFC. Move all of the remaining operations left in BuiltinOps to StandardOps. The only thing left in BuiltinOps are the core MLIR types. The standard types can't be moved because they are referenced within the IR directory, e.g. in things like Builder.

PiperOrigin-RevId: 236403665

5 years agoUse consistent names for dialect op source files
Lei Zhang [Fri, 1 Mar 2019 21:48:24 +0000 (13:48 -0800)]
Use consistent names for dialect op source files

This CL changes dialect op source files (.h, .cpp, .td) to follow the following
convention:

  <full-dialect-name>/<dialect-namespace>Ops.{h|cpp|td}

Builtin and standard dialects are specially treated, though. Both of them do
not have dialect namespace; the former is still named as BuiltinOps.* and the
latter is named as Ops.*.

Purely mechanical. NFC.

PiperOrigin-RevId: 236371358

5 years agoA simple pass to detect and mark all parallel loops
Uday Bondhugula [Fri, 1 Mar 2019 21:27:06 +0000 (13:27 -0800)]
A simple pass to detect and mark all parallel loops
- detect all parallel loops based on dep information and mark them with a
  "parallel" attribute
- add mlir::isLoopParallel(OpPointer<AffineForOp> ...), and refactor an existing method
  to use that (reuse some code from @andydavis (cl/236007073) for this)
- a simple/meaningful way to test memref dep test as well

Ex:

$ mlir-opt -detect-parallel test/Transforms/parallelism-detection.mlir
#map1 = ()[s0] -> (s0)
func @foo(%arg0: index) {
  %0 = alloc() : memref<1024x1024xvector<64xf32>>
  %1 = alloc() : memref<1024x1024xvector<64xf32>>
  %2 = alloc() : memref<1024x1024xvector<64xf32>>
  for %i0 = 0 to %arg0 {
    for %i1 = 0 to %arg0 {
      for %i2 = 0 to %arg0 {
        %3 = load %0[%i0, %i2] : memref<1024x1024xvector<64xf32>>
        %4 = load %1[%i2, %i1] : memref<1024x1024xvector<64xf32>>
        %5 = load %2[%i0, %i1] : memref<1024x1024xvector<64xf32>>
        %6 = mulf %3, %4 : vector<64xf32>
        %7 = addf %5, %6 : vector<64xf32>
        store %7, %2[%i0, %i1] : memref<1024x1024xvector<64xf32>>
      } {parallel: false}
    } {parallel: true}
  } {parallel: true}
  return
}

PiperOrigin-RevId: 236367368

5 years agoLoop fusion for input reuse.
MLIR Team [Fri, 1 Mar 2019 19:50:25 +0000 (11:50 -0800)]
Loop fusion for input reuse.
*) Breaks fusion pass into multiple sub passes over nodes in data dependence graph:
- first pass fuses single-use producers into their unique consumer.
- second pass enables fusing for input-reuse by fusing sibling nodes which read from the same memref, but which do not share dependence edges.
- third pass fuses remaining producers into their consumers (Note that the sibling fusion pass may have transformed a producer with multiple uses into a single-use producer).
*) Fusion for input reuse is enabled by computing a sibling node slice using the load/load accesses to the same memref, and fusion safety is guaranteed by checking that the sibling node memref write region (to a different memref) is preserved.
*) Enables output vector and output matrix computations from KFAC patches-second-moment operation to fuse into a single loop nest and reuse input from the image patches operation.
*) Adds a generic loop utilitiy for finding all sequential loops in a loop nest.
*) Adds and updates unit tests.

PiperOrigin-RevId: 236350987

5 years agoAdd support for parsing and printing affine.if and affine.for attributes. The attribu...
River Riddle [Fri, 1 Mar 2019 19:29:01 +0000 (11:29 -0800)]
Add support for parsing and printing affine.if and affine.for attributes. The attribute dictionaries are printed after the final block list for both operations:

  for %i = 0 to 10 {
     ...
  } {some_attr: true}

  if () : () () {
    ...
  } {some_attr: true}

  if () : () () {
    ...
  } else {
    ...
  } {some_attr: true}

PiperOrigin-RevId: 236346983

5 years agoAnalysis support for floordiv/mod's in loop bounds/
Uday Bondhugula [Fri, 1 Mar 2019 17:48:22 +0000 (09:48 -0800)]
Analysis support for floordiv/mod's in loop bounds/

- handle floordiv/mod's in loop bounds for all analysis purposes
- allows fusion slicing to be more powerful
- add simple test cases based on -memref-bound-check
- fusion based test cases in follow up CLs

PiperOrigin-RevId: 236328551

5 years agoMethod to align/merge dimensional/symbolic identifiers between two FlatAffineConstraints
Uday Bondhugula [Fri, 1 Mar 2019 16:49:20 +0000 (08:49 -0800)]
Method to align/merge dimensional/symbolic identifiers between two FlatAffineConstraints

- add a method to merge and align the spaces (identifiers) of two
  FlatAffineConstraints (both get dimension-wise and symbol-wise unique
  columns)
- this completes several TODOs, gets rid of previous assumptions/restrictions
  in composeMap, unionBoundingBox, and reuses common code
- remove previous workarounds / duplicated funcitonality in
  FlatAffineConstraints::composeMap and unionBoundingBox, use mergeAlignIds
  from both

PiperOrigin-RevId: 236320581

5 years agoEDSC bindings: expose generic Op construction interface
Alex Zinenko [Fri, 1 Mar 2019 14:39:05 +0000 (06:39 -0800)]
EDSC bindings: expose generic Op construction interface

EDSC Expressions can now be used to build arbitrary MLIR operations identified
by their canonical name, i.e. the name obtained from
`OpClass::getOperationName()` for registered operations.  Expose this
functionality to the C API and Python bindings.  This exposes builder-level
interface to Python and avoids the need for experimental Python code to
implement EDSC free function calls for constructing each op type.

This modification required exposing mlir::Attribute to the C API and Python
bindings, which only supports integer attributes for now.

This is step 4/n to making EDSCs more generalizable.

PiperOrigin-RevId: 236306776

5 years agoUse Instruction::isBeforeInBlock instead of a linear scan
Uday Bondhugula [Fri, 1 Mar 2019 02:16:52 +0000 (18:16 -0800)]
Use Instruction::isBeforeInBlock instead of a linear scan

- use Instruction::isBeforeInBlock instead of a linear scan in
  AffineAnalysis.cpp

PiperOrigin-RevId: 236235824

5 years agoProvide a Builder::getNamedAttr and (Instruction|Function)::setAttr(StringRef, Attrib...
River Riddle [Fri, 1 Mar 2019 00:45:30 +0000 (16:45 -0800)]
Provide a Builder::getNamedAttr and (Instruction|Function)::setAttr(StringRef, Attribute) to simplify attribute manipulation.

PiperOrigin-RevId: 236222504

5 years agoRemove PassResult and have the runOnFunction/runOnModule functions return void instea...
River Riddle [Thu, 28 Feb 2019 22:50:42 +0000 (14:50 -0800)]
Remove PassResult and have the runOnFunction/runOnModule functions return void instead. To signal a pass failure, passes should now invoke the 'signalPassFailure' method. This provides the equivalent functionality when needed, but isn't an intrusive part of the API like PassResult.

PiperOrigin-RevId: 236202029

5 years agoChange some of the debug messages to use emitError / emitWarning / emitNote - NFC
Uday Bondhugula [Thu, 28 Feb 2019 20:07:12 +0000 (12:07 -0800)]
Change some of the debug messages to use emitError / emitWarning / emitNote - NFC

PiperOrigin-RevId: 236169676

5 years agoAdd support for named function argument attributes. The attribute dictionary is print...
River Riddle [Thu, 28 Feb 2019 17:30:52 +0000 (09:30 -0800)]
Add support for named function argument attributes. The attribute dictionary is printed after the argument type:

func @arg_attrs(i32 {arg_attr: 10})

func @arg_attrs(%arg0: i32 {arg_attr: 10})

PiperOrigin-RevId: 236136830

5 years agoLLVM IR Dialect: unify call and call0 operations
Alex Zinenko [Thu, 28 Feb 2019 15:36:17 +0000 (07:36 -0800)]
LLVM IR Dialect: unify call and call0 operations

When the LLVM IR dialect was implemented, TableGen operation definition scheme
did not support operations with variadic results.  Therefore, the `call`
instruction was split into `call` and `call0` for the single- and zero-result
calls (LLVM does not support multi-result operations).  Unify `call` and
`call0` using the recently added TableGen support for operations with Variadic
results.  Explicitly verify that the new operation has 0 or 1 results.  As a
side effect, this change enables clean-ups in the conversion to the LLVM IR
dialect that no longer needs to rely on wrapped LLVM IR void types when
constructing zero-result calls.

PiperOrigin-RevId: 236119197

5 years agoExecutionEngine OptUtils: support -On flags in string-based initialization
Alex Zinenko [Thu, 28 Feb 2019 14:01:02 +0000 (06:01 -0800)]
ExecutionEngine OptUtils: support -On flags in string-based initialization

Original implementation of OutUtils provided two different LLVM IR module
transformers to be used with the MLIR ExecutionEngine: OptimizingTransformer
parameterized by the optimization levels (similar to -O3 flags) and
LLVMPassesTransformer parameterized by the string formatted similarly to
command line options of LLVM's "opt" tool without support for -O* flags.
Introduce such support by declaring the flags inside the parser and by
populating the pass managers similarly to what "opt" does.  Remove the
additional flags from mlir-cpu-runner as they can now be wrapped into
`-llvm-opts` together with other LLVM-related flags.

PiperOrigin-RevId: 236107292

5 years agoWhen parsing, check that a region operation is not referencing any of the entry argum...
River Riddle [Thu, 28 Feb 2019 01:58:09 +0000 (17:58 -0800)]
When parsing, check that a region operation is not referencing any of the entry arguments to its block lists.

PiperOrigin-RevId: 236030438

5 years agoMove the PassExecutor and ModuleToFunctionPassAdaptor classes from PassManager.h...
River Riddle [Thu, 28 Feb 2019 01:49:51 +0000 (17:49 -0800)]
Move the PassExecutor and ModuleToFunctionPassAdaptor classes from PassManager.h to Pass.cpp. This allows for us to remove a dependency on Pass.h from PassManager.h.

PiperOrigin-RevId: 236029339

5 years agoAdd a generic getValue to ElementsAttr for accessing a value at a given index.
River Riddle [Thu, 28 Feb 2019 00:15:16 +0000 (16:15 -0800)]
Add a generic getValue to ElementsAttr for accessing a value at a given index.

PiperOrigin-RevId: 236013669

5 years agoRemove the stubs for getValue from DenseIntElementsAttr and DenseFPElementsAttr as...
River Riddle [Thu, 28 Feb 2019 00:00:19 +0000 (16:00 -0800)]
Remove the stubs for getValue from DenseIntElementsAttr and DenseFPElementsAttr as they aren't implemented. The type for the index is also wrong.

PiperOrigin-RevId: 236010720

5 years agoAdd support for registering pass pipelines to the PassRegistry. This is done by provi...
River Riddle [Wed, 27 Feb 2019 22:45:36 +0000 (14:45 -0800)]
Add support for registering pass pipelines to the PassRegistry. This is done by providing a static registration facility PassPipelineRegistration that works similarly to PassRegistration except for it also takes a function that will add necessary passes to a provided PassManager.

  void pipelineBuilder(PassManager &pm) {
      pm.addPass(new MyPass());
      pm.addPass(new MyOtherPass());
  }

  static PassPipelineRegistration Unused("unused", "Unused pass", pipelineBuilder);

This is also useful for registering specializations of existing passes:

  Pass *createFooPass10() { return new FooPass(10); }

  static PassPipelineRegistration Unused("unused", "Unused pass", createFooPass10);

PiperOrigin-RevId: 235996282

5 years agoFix incorrect line split in header guard.
Jacques Pienaar [Wed, 27 Feb 2019 22:37:51 +0000 (14:37 -0800)]
Fix incorrect line split in header guard.

PiperOrigin-RevId: 235994785

5 years agoDetect more trivially redundant constraints better
Uday Bondhugula [Wed, 27 Feb 2019 21:43:08 +0000 (13:43 -0800)]
Detect more trivially redundant constraints better

- detect more trivially redundant constraints in
  FlatAffineConstraints::removeTrivialRedundantConstraints. Redundancy due to
  constraints that only differ in the constant part (eg., 32i + 64j - 3 >= 0, 32 +
  64j - 8 >= 0) is now detected.  The method is still linear-time and does
  a single scan over the FlatAffineConstraints buffer. This detection is useful
  and needed to eliminate redundant constraints generated after FM elimination.

- update GCDTightenInequalities so that we also normalize by the GCD while at
  it. This way more constraints will show up as redundant (232i - 203 >= 0
  becomes i - 1 >= 0 instead of 232i - 232 >= 0) without having to call
  normalizeConstraintsByGCD.

- In FourierMotzkinEliminate, call GCDTightenInequalities and
  normalizeConstraintsByGCD before calling removeTrivialRedundantConstraints()
  - so that more redundant constraints are detected. As a result, redundancy
    due to constraints like i - 5 >= 0, i - 7 >= 0, 2i - 5 >= 0, 232i - 203 >=
    0 is now detected (here only i >= 7 is non-redundant).

As a result of these, a -memref-bound-check on the added test case runs in 16ms
instead of 1.35s (opt build) and no longer returns a conservative result.

PiperOrigin-RevId: 235983550

5 years agoFix bug in memref region computation with slice loop bounds. Adds loop IV values...
MLIR Team [Wed, 27 Feb 2019 19:01:49 +0000 (11:01 -0800)]
Fix bug in memref region computation with slice loop bounds. Adds loop IV values to ComputationSliceState which are used in FlatAffineConstraints::addSliceBounds, to ensure that constraints are only added for loop IV values which are present in the constraint system.

PiperOrigin-RevId: 235952912

5 years agoPort all of the existing passes over to the new pass manager infrastructure. This...
River Riddle [Wed, 27 Feb 2019 18:59:29 +0000 (10:59 -0800)]
Port all of the existing passes over to the new pass manager infrastructure. This is largely NFC.

PiperOrigin-RevId: 235952357

5 years agoImplement the initial pass management functionality.
River Riddle [Wed, 27 Feb 2019 18:57:59 +0000 (10:57 -0800)]
Implement the initial pass management functionality.
The definitions of derived passes have now changed and passes must adhere to the following:

* Inherit from a CRTP base class FunctionPass/ModulePass.
   - This class provides several necessary utilities for the transformation:
       . Access to the IR unit being transformed (getFunction/getModule)
       . Various utilities for pass identification and registration.

* Provide a 'PassResult runOn(Function|Module)()' method to transform the IR.
   - This replaces the runOn* functions from before.

This patch also introduces the notion of the PassManager. This allows for simplified construction of pass pipelines and acts as the sole interface for executing passes. This is important as FunctionPass will no longer have a 'runOnModule' method.

PiperOrigin-RevId: 235952008

5 years ago[TableGen] Use result names in build() methods if possible
Lei Zhang [Wed, 27 Feb 2019 16:40:07 +0000 (08:40 -0800)]
[TableGen] Use result names in build() methods if possible

This will make it clear which result's type we are expecting in the build() signature.

PiperOrigin-RevId: 235925706

5 years ago[TableGen] Add more scalar integer and floating-point types
Lei Zhang [Wed, 27 Feb 2019 15:51:50 +0000 (07:51 -0800)]
[TableGen] Add more scalar integer and floating-point types

PiperOrigin-RevId: 235918286

5 years agoEDSC: move FileCheck tests into the source file
Alex Zinenko [Wed, 27 Feb 2019 11:03:20 +0000 (03:03 -0800)]
EDSC: move FileCheck tests into the source file

EDSC provide APIs for constructing and modifying the IR.  These APIs are
currently tested by a "test" module pass that reads the dummy IR (empty
functions), recognizes certain function names and injects the IR into those
functions based on their name.  This situation is unsatisfactory because the
expected outcome of the test lives in a different file than the input to the
test, i.e. the API calls.

Create a new binary for tests that constructs the IR from scratch using EDSC
APIs and prints it.  Put FileCheck comments next to the printing.  This removes
the need to have a file with dummy inputs and assert on its contents in the
test driver.  The test source includes a simplistic test harness that runs all
functions marked as TEST_FUNC but intentionally does not include any
value-testing functionality.

PiperOrigin-RevId: 235886629

5 years agoAdding an IREE type kind range definition.
Ben Vanik [Wed, 27 Feb 2019 05:14:21 +0000 (21:14 -0800)]
Adding an IREE type kind range definition.

PiperOrigin-RevId: 235849609

5 years agoAdd a new class NamedAttributeList to deduplicate named attribute handling between...
River Riddle [Wed, 27 Feb 2019 02:01:46 +0000 (18:01 -0800)]
Add a new class NamedAttributeList to deduplicate named attribute handling between Function and Instruction.

PiperOrigin-RevId: 235830304

5 years agoTemp change in FlatAffineConstraints::getSliceBounds() to deal with TODO in
Uday Bondhugula [Wed, 27 Feb 2019 01:32:47 +0000 (17:32 -0800)]
Temp change in FlatAffineConstraints::getSliceBounds() to deal with TODO in
LoopFusion

- getConstDifference in LoopFusion is pending a refactoring to handle bounds
  with min's and max's; it currently asserts on some useful test cases that we
  want to experiment with. This CL changes getSliceBounds to be more
  conservative so as to not trigger the assertion. Filed b/126426796 to track this.

PiperOrigin-RevId: 235826538

5 years agoAllow function names to have a leading underscore. This matches what is already defin...
River Riddle [Wed, 27 Feb 2019 01:11:24 +0000 (17:11 -0800)]
Allow function names to have a leading underscore. This matches what is already defined in the spec, but not supported in the implementation.

PiperOrigin-RevId: 235823663

5 years agoValidate the names of attribute, dialect, and functions during verification. This...
River Riddle [Wed, 27 Feb 2019 00:43:12 +0000 (16:43 -0800)]
Validate the names of attribute, dialect, and functions during verification. This essentially enforces the parsing rules upon their names.

PiperOrigin-RevId: 235818842

5 years agoLoop fusion comand line options cleanup
Uday Bondhugula [Wed, 27 Feb 2019 00:10:19 +0000 (16:10 -0800)]
Loop fusion comand line options cleanup

- clean up loop fusion CL options for promoting local buffers to fast memory
  space
- add parameters to loop fusion pass instantiation

PiperOrigin-RevId: 235813419

5 years agoAdd parser support for internal named attributes. These are attributes with names...
River Riddle [Tue, 26 Feb 2019 20:52:51 +0000 (12:52 -0800)]
Add parser support for internal named attributes. These are attributes with names starting with ':'.

PiperOrigin-RevId: 235774810

5 years ago[TableGen] Fix using rewrite()'s qualified name for a bound argument in match()
Lei Zhang [Tue, 26 Feb 2019 20:09:22 +0000 (12:09 -0800)]
[TableGen] Fix using rewrite()'s qualified name for a bound argument in match()

PiperOrigin-RevId: 235767304

5 years agoAdd a Function::isExternal utility to simplify checks for external functions.
River Riddle [Tue, 26 Feb 2019 18:27:09 +0000 (10:27 -0800)]
Add a Function::isExternal utility to simplify checks for external functions.

PiperOrigin-RevId: 235746553

5 years agoRewrite the dominance info classes to allow for operating on arbitrary control flow...
River Riddle [Tue, 26 Feb 2019 18:07:27 +0000 (10:07 -0800)]
Rewrite the dominance info classes to allow for operating on arbitrary control flow within operation regions. The CSE pass is also updated to properly handle nested dominance.

PiperOrigin-RevId: 235742627

5 years agoUnboxing for static memrefs.
Dimitrios Vytiniotis [Tue, 26 Feb 2019 13:48:41 +0000 (05:48 -0800)]
Unboxing for static memrefs.

When lowering to MLIR(LLVMDialect) we unbox the structs that result
from converting static memrefs, that is, singleton structs
that just contain a raw pointer. This allows us to get rid of all
"extractvalue" instructions in the common case where shapes are fully
known.

PiperOrigin-RevId: 235706021

5 years agoLLVM IR dialect and translation: support conditional branches with arguments
Alex Zinenko [Tue, 26 Feb 2019 10:02:26 +0000 (02:02 -0800)]
LLVM IR dialect and translation: support conditional branches with arguments

Since the goal of the LLVM IR dialect is to reflect LLVM IR in MLIR, the
dialect and the conversion procedure must account for the differences betweeen
block arguments and LLVM IR PHI nodes. In particular, LLVM IR disallows PHI
nodes with different values coming from the same source. Therefore, the LLVM IR
dialect now disallows `cond_br` operations that have identical successors
accepting arguments, which would lead to invalid PHI nodes. The conversion
process resolves the potential PHI source ambiguity by injecting dummy blocks
if the same block is used more than once as a successor in an instruction.
These dummy blocks branch unconditionally to the original successors, pass them
the original operands (available in the dummy block because it is dominated by
the original block) and are used instead of them in the original terminator
operation.

PiperOrigin-RevId: 235682798

5 years agoUpdate LLVM Dialect documentation
Alex Zinenko [Tue, 26 Feb 2019 09:27:27 +0000 (01:27 -0800)]
Update LLVM Dialect documentation

Addressing post-submit comments.  The `getelementptr` operation now supports
non-constant indexes, similarly to LLVM, and this functionality is exercised by
the lowering to the dialect.  Update the documentation accordingly.

List the values of integer comparison predicates, which currently correspond to
those of CmpIOp in MLIR.  Ideally, we would use strings instead, but it
requires additional support for argument conversion in both the dialect
lowering pass and the LLVM translator.

PiperOrigin-RevId: 235678877

5 years agoVerify IR produced by TranslateToMLIR functions
Smit Hinsu [Tue, 26 Feb 2019 00:23:08 +0000 (16:23 -0800)]
Verify IR produced by TranslateToMLIR functions

TESTED with existing unit tests

PiperOrigin-RevId: 235623059

5 years agoCleanup post cl/235283610 - NFC
Uday Bondhugula [Tue, 26 Feb 2019 00:11:30 +0000 (16:11 -0800)]
Cleanup post cl/235283610 - NFC

- remove stale comments + cleanup
- drop MLIRContext * field from expr flattener

PiperOrigin-RevId: 235621178

5 years agoConvert the dialect type parse/print hooks into virtual functions on the Dialect...
River Riddle [Mon, 25 Feb 2019 21:16:24 +0000 (13:16 -0800)]
Convert the dialect type parse/print hooks into virtual functions on the Dialect class.

PiperOrigin-RevId: 235589945

5 years agoAdd support for constructing DenseIntElementsAttr with an array of APInt and
River Riddle [Mon, 25 Feb 2019 20:32:43 +0000 (12:32 -0800)]
Add support for constructing DenseIntElementsAttr with an array of APInt and
DenseFPElementsAttr with an array of APFloat.

PiperOrigin-RevId: 235581794

5 years ago[TableGen] Use ArrayRef instead of SmallVectorImpl for suitable method
Lei Zhang [Mon, 25 Feb 2019 20:10:40 +0000 (12:10 -0800)]
[TableGen] Use ArrayRef instead of SmallVectorImpl for suitable method

PiperOrigin-RevId: 235577399

5 years agoAdd a stripmineSink and imperfectly nested tiling primitives.
Nicolas Vasilache [Mon, 25 Feb 2019 17:53:05 +0000 (09:53 -0800)]
Add a stripmineSink and imperfectly nested tiling primitives.

This CL adds a primitive to perform stripmining of a loop by a given factor and
sinking it under multiple target loops.
In turn this is used to implement imperfectly nested loop tiling (with interchange) by repeatedly calling the stripmineSink primitive.

The API returns the point loops and allows repeated invocations of tiling to achieve declarative, multi-level, imperfectly-nested tiling.

Note that this CL is only concerned with the mechanical aspects and does not worry about analysis and legality.

The API is demonstrated in an example which creates an EDSC block, emits the corresponding MLIR and applies imperfectly-nested tiling:

```cpp
    auto block = edsc::block({
      For(ArrayRef<edsc::Expr>{i, j}, {zero, zero}, {M, N}, {one, one}, {
        For(k1, zero, O, one, {
          C({i, j, k1}) = A({i, j, k1}) + B({i, j, k1})
        }),
        For(k2, zero, O, one, {
          C({i, j, k2}) = A({i, j, k2}) + B({i, j, k2})
        }),
      }),
    });
    // clang-format on
    emitter.emitStmts(block.getBody());

    auto l_i = emitter.getAffineForOp(i), l_j = emitter.getAffineForOp(j),
         l_k1 = emitter.getAffineForOp(k1), l_k2 = emitter.getAffineForOp(k2);
    auto indicesL1 = mlir::tile({l_i, l_j}, {512, 1024}, {l_k1, l_k2});
    auto l_ii1 = indicesL1[0][0], l_jj1 = indicesL1[1][0];
    mlir::tile({l_jj1, l_ii1}, {32, 16}, l_jj1);
```

The edsc::Expr for the induction variables (i, j, k_1, k_2) provide the programmatic hooks from which tiling can be applied declaratively.

PiperOrigin-RevId: 235548228

5 years agoEDSC: support conditional branch instructions
Alex Zinenko [Mon, 25 Feb 2019 17:22:04 +0000 (09:22 -0800)]
EDSC: support conditional branch instructions

Leverage the recently introduced support for multiple argument groups and
multiple destination blocks in EDSC Expressions to implement conditional
branches in EDSC.  Conditional branches have two successors and three argument
groups.  The first group contains a single expression of i1 type that
corresponds to the condition of the branch.  The two following groups contain
arguments of the two successors of the conditional branch instruction, in the
same order as the successors.  Expose this instruction to the C API and Python
bindings.

PiperOrigin-RevId: 235542768

5 years agoEDSC: support branch instructions
Alex Zinenko [Mon, 25 Feb 2019 17:16:30 +0000 (09:16 -0800)]
EDSC: support branch instructions

The new implementation of blocks was designed to support blocks with arguments.
More specifically, StmtBlock can be constructed with a list of Bindables that
will be bound to block aguments upon construction.  Leverage this functionality
to implement branch instructions with arguments.

This additionally requires the statement storage to have a list of successors,
similarly to core IR operations.

Becauase successor chains can form loops, we need a possibility to decouple
block declaration, after which it becomes usable by branch instructions, from
block body definition.  This is achieved by creating an empty block and by
resetting its body with a new list of instructions.  Note that assigning a
block from another block will not affect any instructions that may have
designated this block as their successor (this behavior is necessary to make
value-type semantics of EDSC types consistent).  Combined, one can now write
generators like

    EDSCContext context;
    Type indexType = ...;
    Bindable i(indexType), ii(indexType), zero(indexType), one(indexType);
    StmtBlock loopBlock({i}, {});
    loopBlock.set({ii = i + one,
                   Branch(loopBlock, {ii})});
    MLIREmitter(&builder)
        .bindConstant<ConstantIndexOp>(zero, 0)
        .bindConstant<ConstantIndexOp>(one, 1)
.emitStmt(Branch(loopBlock, {zero}));

where the emitter will emit the statement and its successors, if present.

PiperOrigin-RevId: 235541892

5 years agoUse dialect hook registration for constant folding hook.
Tatiana Shpeisman [Mon, 25 Feb 2019 16:37:28 +0000 (08:37 -0800)]
Use dialect hook registration for constant folding hook.

Deletes specialized mechanism for registering constant folding hook and uses dialect hooks registration mechanism instead.

PiperOrigin-RevId: 235535410

5 years agoAdd constant folding for ExtractElementOp when the aggregate is an OpaqueElementsAttr.
River Riddle [Mon, 25 Feb 2019 16:21:41 +0000 (08:21 -0800)]
Add constant folding for ExtractElementOp when the aggregate is an OpaqueElementsAttr.

PiperOrigin-RevId: 235533283

5 years agoEDSC printing: handle integer attributes with bitwidth > 64
Alex Zinenko [Mon, 25 Feb 2019 16:09:34 +0000 (08:09 -0800)]
EDSC printing: handle integer attributes with bitwidth > 64

This came up in post-submit review.  Use LLVM's support for outputting APInt
values directly instead of obtaining a 64-bit integer value from APInt, which
will not work for wider integers.

PiperOrigin-RevId: 235531574

5 years ago[TableGen] Fix infinite loop in SubstLeaves substitution
Lei Zhang [Mon, 25 Feb 2019 12:03:02 +0000 (04:03 -0800)]
[TableGen] Fix infinite loop in SubstLeaves substitution

Previously we have `auto pos = std::string::find(...) != std::string::npos` as
if condition to control substring substitution. Instead of the position for the
found substring, `pos` will be a boolean value indicating found nor not. Then
used as the replace start position, we were always replacing starting from 0 or
1. If the replaced substring also has the pattern to be matched, we'll see
an infinite loop.

PiperOrigin-RevId: 235504681

5 years agoRefactor AffineExprFlattener and move FlatAffineConstraints out of IR into
Uday Bondhugula [Sat, 23 Feb 2019 00:51:08 +0000 (16:51 -0800)]
Refactor AffineExprFlattener and move FlatAffineConstraints out of IR into
Analysis - NFC

- refactor AffineExprFlattener (-> SimpleAffineExprFlattener) so that it
  doesn't depend on FlatAffineConstraints, and so that FlatAffineConstraints
  could be moved out of IR/; the simplification that the IR needs for
  AffineExpr's doesn't depend on FlatAffineConstraints
- have AffineExprFlattener derive from SimpleAffineExprFlattener to use for
  all Analysis/Transforms purposes; override addLocalFloorDivId in the derived
  class

- turn addAffineForOpDomain into a method on FlatAffineConstraints
- turn AffineForOp::getAsValueMap into an AffineValueMap ctor

PiperOrigin-RevId: 235283610

5 years agoSpike to define real math ops and lowering of one variant of add to corresponding...
Stella Laurenzo [Fri, 22 Feb 2019 23:11:00 +0000 (15:11 -0800)]
Spike to define real math ops and lowering of one variant of add to corresponding integer ops.

The only reason in starting with a fixedpoint add is that it is the absolute simplest variant and illustrates the level of abstraction I'm aiming for.

The overall flow would be:
  1. Determine quantization parameters (out of scope of this cl).
  2. Source dialect rules to lower supported math ops to the quantization dialect (out of scope of this cl).
  3. Quantization passes: [-quant-convert-const, -quant-lower-uniform-real-math, -quant-lower-unsupported-to-float] (the last one not implemented yet)
  4. Target specific lowering of the integral arithmetic ops (roughly at the level of gemmlowp) to more fundamental operations (i.e. calls to gemmlowp, simd instructions, DSP instructions, etc).

How I'm doing this should facilitate implementation of just about any kind of backend except TFLite, which has a very course, adhoc surface area for its quantized kernels. Options there include (I'm not taking an opinion on this - just trying to provide options):
  a) Not using any of this: just match q/dbarrier + tf math ops to the supported TFLite quantized op set.
  b) Implement the more fundamental integer math ops on TFLite and convert to those instead of the current op set.

Note that I've hand-waved over the process of choosing appropriate quantization parameters. Getting to that next. As you can see, different implementations will likely have different magic combinations of specific math support, and we will need the target system that has been discussed for some of the esoteric cases (i.e. many DSPs only support POT fixedpoint).

Two unrelated changes to the overall goal of this CL and can be broken out of desired:
  - Adding optional attribute support to TabelGen
  - Allowing TableGen native rewrite hooks to return nullptr, signalling that no rewrite has been done.

PiperOrigin-RevId: 235267229

5 years agoNFC: Make DialectConversion not directly inherit from ModulePass. It is now just...
River Riddle [Fri, 22 Feb 2019 16:10:29 +0000 (08:10 -0800)]
NFC: Make DialectConversion not directly inherit from ModulePass. It is now just a utility class that performs dialect conversion on a provided module.

PiperOrigin-RevId: 235194067

5 years agoRewrite MLPatternLoweringPass to no longer inherit from FunctionPass and just provide...
River Riddle [Fri, 22 Feb 2019 16:10:10 +0000 (08:10 -0800)]
Rewrite MLPatternLoweringPass to no longer inherit from FunctionPass and just provide a utility function that applies ML patterns.

PiperOrigin-RevId: 235194034

5 years agoInternal change
MLIR Team [Fri, 22 Feb 2019 15:48:59 +0000 (07:48 -0800)]
Internal change

PiperOrigin-RevId: 235191129

5 years agoDocument the conversion into the LLVM IR dialect
Alex Zinenko [Fri, 22 Feb 2019 15:45:55 +0000 (07:45 -0800)]
Document the conversion into the LLVM IR dialect

Add a documentation page on the key points of the conversion to LLVM IR.  This
focuses on the aspects of conversion that are relevant for integration of the
LLVM IR dialect (and produced LLVM IR that is mostly a one-to-one translation)
into other projects.  In particular, it describes the type conversion rules and
the memref model supporting dynamic sizes.

PiperOrigin-RevId: 235190772