platform/upstream/llvm.git
5 years agoRefactor DialectConversion to support different conversion modes.
River Riddle [Tue, 16 Jul 2019 18:57:45 +0000 (11:57 -0700)]
Refactor DialectConversion to support different conversion modes.

Users generally want several different modes of conversion. This cl refactors DialectConversion to provide two:
* Partial (applyPartialConversion)
  - This mode allows for illegal operations to exist in the IR, and does not fail if an operation fails to be legalized.

* Full (applyFullConversion)
  - This mode fails if any operation is not properly legalized to the conversion target. This allows for ensuring that the IR after a conversion only contains operations legal for the target.

PiperOrigin-RevId: 258412243

5 years agoAdd a TypeIsPred.
Jacques Pienaar [Tue, 16 Jul 2019 18:54:54 +0000 (11:54 -0700)]
Add a TypeIsPred.

Mostly one would use the type specification directly on the operand, but for
cases where the type of the operand depends on other operand types, `TypeIs`
attribute can be used to construct verification methods.

PiperOrigin-RevId: 258411758

5 years agoSupport signed and unsigned quantization types
Feng Liu [Tue, 16 Jul 2019 16:32:18 +0000 (09:32 -0700)]
Support signed and unsigned quantization types

This patch added a new argument to the fakeQuantAttrsToType utility method, so
it can be used to convert min/max to quantized type with different signed
storage types.

PiperOrigin-RevId: 258382538

5 years agoFix build by making LoopOps depend on StandardOps
Alex Zinenko [Tue, 16 Jul 2019 13:27:11 +0000 (06:27 -0700)]
Fix build by making LoopOps depend on StandardOps

LoopOps needs the definition ConstantIndexOp in the verifier of loop::ForOp.

PiperOrigin-RevId: 258355329

5 years agoMove shared cpu runner library to Support/JitRunner.
Stephan Herhut [Tue, 16 Jul 2019 12:28:56 +0000 (05:28 -0700)]
Move shared cpu runner library to Support/JitRunner.

PiperOrigin-RevId: 258347825

5 years agoNFC: Move SPIR-V dialect to Dialect/ subdirectory
Lei Zhang [Tue, 16 Jul 2019 12:06:57 +0000 (05:06 -0700)]
NFC: Move SPIR-V dialect to Dialect/ subdirectory

PiperOrigin-RevId: 258345603

5 years agoBetter support for attribute wrapper classes when getting def name
Lei Zhang [Tue, 16 Jul 2019 11:33:54 +0000 (04:33 -0700)]
Better support for attribute wrapper classes when getting def name

Unless we explicitly name a template instantiation in .td file, its def
name will be "anonymous_<number>". We typically give base-level Attr
template instantiation a name by writing `def AnAttr : Attr<...>`. But
when `AnAttr` is further wrapped in classes like OptionalAttr, the name
is lost unless explicitly def'ed again. These implicit-named template
instantiation is fairly common when writing op definitions. Those wrapper
classes are just essentially attaching more information to the attribute.
Without a proper way to trace back to the original attribute def name
can cause problems for consumers wanting to handle attributes according
to their types.

Previously we handled OptionalAttr and DefaultValuedAttr specifically,
but Confined was not supported. And they can compose together to have
Confined<OptionalAttr<...>, [...]>. So this CL moves the baseAttr field
to main Attr class (like isOptional) and set it only on the innermost
wrapper class.

PiperOrigin-RevId: 258341646

5 years agoReplace linalg.for by loop.for
Nicolas Vasilache [Tue, 16 Jul 2019 08:46:23 +0000 (01:46 -0700)]
Replace linalg.for by loop.for

With the introduction of the Loop dialect, uses of the `linalg.for` operation can now be subsumed 1-to-1 by `loop.for`.
This CL performs the replacement and tests are updated accordingly.

PiperOrigin-RevId: 258322565

5 years agoForward-declare LogicalResult as struct rather than class
Alex Zinenko [Tue, 16 Jul 2019 08:27:08 +0000 (01:27 -0700)]
Forward-declare LogicalResult as struct rather than class

Windows builds are broken by a class/struct mismatch between a
forward-declaration of LogicalResult and its definition.

PiperOrigin-RevId: 258320420

5 years agoRemove lowerAffineConstructs and lowerControlFlow in favor of providing patterns.
River Riddle [Mon, 15 Jul 2019 19:52:44 +0000 (12:52 -0700)]
Remove lowerAffineConstructs and lowerControlFlow in favor of providing patterns.

These methods don't compose well with the rest of conversion framework, and create artificial breaks in conversion. Replace these methods with two(populateAffineToStdConversionPatterns and populateLoopToStdConversionPatterns respectively) that populate a list of patterns to perform the same behavior.

PiperOrigin-RevId: 258219277

5 years agoUpdate 'applyPatternsGreedily' to work on the regions of any operations.
River Riddle [Mon, 15 Jul 2019 16:52:52 +0000 (09:52 -0700)]
Update 'applyPatternsGreedily' to work on the regions of any operations.

'applyPatternsGreedily' is a useful utility outside of just function regions.

PiperOrigin-RevId: 258182937

5 years agoRefactor the traversal of operations to Convert in DialectConversion.
River Riddle [Mon, 15 Jul 2019 15:40:11 +0000 (08:40 -0700)]
Refactor the traversal of operations to Convert in DialectConversion.

This cl changes the way that operations/blocks to convert are collected/traversed so that parent region operations can be legalized before their bodies. Most RewritePatterns for region operations assume that the entry arguments to each region are yet to be converted. Given that the bodies are currently converted first, this makes it difficult to fit these patterns into the same run as one converting types.

The operations/blocks to convert are now collected before any legalization has run, which simplifies the conversion logic itself, as legalization may insert new operations, move blocks, etc.

PiperOrigin-RevId: 258170158

5 years agoFix opt build (unused variable in Linalg).
Andy Davis [Mon, 15 Jul 2019 15:29:47 +0000 (08:29 -0700)]
Fix opt build (unused variable in Linalg).

PiperOrigin-RevId: 258168108

5 years agoLinalg Utils: use Doxygen comments where appropriate
Alex Zinenko [Mon, 15 Jul 2019 14:50:11 +0000 (07:50 -0700)]
Linalg Utils: use Doxygen comments where appropriate

PiperOrigin-RevId: 258160982

5 years agoExtend linalg transformations to allow value operands that are not views
Alex Zinenko [Mon, 15 Jul 2019 14:42:37 +0000 (07:42 -0700)]
Extend linalg transformations to allow value operands that are not views

This CL extends the linalg ops that can be tiled and fused to operations that take either views, scalar or vector operands.

PiperOrigin-RevId: 258159734

5 years agoRefactor LowerAffine to use OpRewritePattern instead of ConversionPattern.
River Riddle [Mon, 15 Jul 2019 14:35:00 +0000 (07:35 -0700)]
Refactor LowerAffine to use OpRewritePattern instead of ConversionPattern.

ConversionPattern should ideally only be used when the types of the operands are changing, which in this case they aren't. Using OpRewritePattern also lends to much simpler code.

PiperOrigin-RevId: 258158474

5 years agoLLVMDialect: still depend on standard types.
Alex Zinenko [Mon, 15 Jul 2019 13:55:53 +0000 (06:55 -0700)]
LLVMDialect: still depend on standard types.

The dependecy on standard type is mandated by attribute verifiers on some
operations (e.g., llvm.constant) that use values of those types.

PiperOrigin-RevId: 258153134

5 years agoAutomated rollback of changelist 258149291.
MLIR Team [Mon, 15 Jul 2019 13:44:38 +0000 (06:44 -0700)]
Automated rollback of changelist 258149291.

PiperOrigin-RevId: 258151618

5 years agoStart moving AffineOps to ODS
Nicolas Vasilache [Mon, 15 Jul 2019 13:44:22 +0000 (06:44 -0700)]
Start moving AffineOps to ODS

This CL starts with the AffineTerminatorOp to ODS.

PiperOrigin-RevId: 258151579

5 years agoIntroduce loop coalescing utility and a simple pass
Alex Zinenko [Mon, 15 Jul 2019 13:40:07 +0000 (06:40 -0700)]
Introduce loop coalescing utility and a simple pass

Multiple (perfectly) nested loops with independent bounds can be combined into
a single loop and than subdivided into blocks of arbitrary size for load
balancing or more efficient parallelism exploitation.  However, MLIR wants to
preserve the multi-dimensional multi-loop structure at higher levels of
abstraction. Introduce a transformation that coalesces nested loops with
independent bounds so that they can be further subdivided by tiling.

PiperOrigin-RevId: 258151016

5 years agoExtend linalg transformations to allow value operands that are not views
Nicolas Vasilache [Mon, 15 Jul 2019 13:27:21 +0000 (06:27 -0700)]
Extend linalg transformations to allow value operands that are not views

This CL extends the linalg ops that can be tiled and fused to operations that take either views, scalar or vector operands.

PiperOrigin-RevId: 258149291

5 years agoDecouple LLVM dialect from Standard dialect
Alex Zinenko [Mon, 15 Jul 2019 13:19:39 +0000 (06:19 -0700)]
Decouple LLVM dialect from Standard dialect

Due to the absence of ODS support for enum attributes, the implementation of
the LLVM dialect `icmp` operation was reusing the comparison predicate from the
Standard dialect, creating an avoidable library dependency.  With ODS support
and ICmpPredicate attribute recently introduced, the dependency is no longer
justified.  Update the Standard to LLVM convresion to also convert the
CmpIPredicate into LLVM::ICmpPredicate and remove the unnecessary includes.

Note that the MLIRLLVMIR library did not explicitly depend on MLIRStandardOps,
requiring dependees of MLIRLLVMIR to also depend on MLIRStandardOps, which
should no longer be the case.

PiperOrigin-RevId: 258148456

5 years agoLLVM Dialect: define ICmpPredicate in ODS
Alex Zinenko [Mon, 15 Jul 2019 12:45:08 +0000 (05:45 -0700)]
LLVM Dialect: define ICmpPredicate in ODS

Use the recently introduced enum-gen functionality to define the predicate
attribute of the ICmp LLVM dialect operation directly in ODS.  This removes the
need for manually-coded string-to-integer conversion functions and contributes
to the overall homogenization of the operation definitions.

PiperOrigin-RevId: 258143923

5 years agoExtract std.for std.if and std.terminator in their own dialect
Nicolas Vasilache [Mon, 15 Jul 2019 09:50:09 +0000 (02:50 -0700)]
Extract std.for std.if and std.terminator in their own dialect

These ops should not belong to the std dialect.
This CL extracts them in their own dialect and updates the corresponding conversions and tests.

PiperOrigin-RevId: 258123853

5 years agoFix a bug in DialectConversion when using RewritePattern.
River Riddle [Sun, 14 Jul 2019 20:29:46 +0000 (13:29 -0700)]
Fix a bug in DialectConversion when using RewritePattern.

When using a RewritePattern and replacing an operation with an existing value, that value may have already been replaced by something else. This cl ensures that only the final value is used when applying rewrites.

PiperOrigin-RevId: 258058488

5 years agoFix typos
Masaki Kozuki [Sat, 13 Jul 2019 12:55:25 +0000 (05:55 -0700)]
Fix typos

Closes tensorflow/mlir#45

PiperOrigin-RevId: 257948893

5 years agoNFC: Add header blocks to DialectConversion.h to improve readability.
River Riddle [Sat, 13 Jul 2019 01:11:40 +0000 (18:11 -0700)]
NFC: Add header blocks to DialectConversion.h to improve readability.
PiperOrigin-RevId: 257903383

5 years agoNFC: Don't print the location of a diagnostic if it is unknown.
River Riddle [Fri, 12 Jul 2019 22:49:38 +0000 (15:49 -0700)]
NFC: Don't print the location of a diagnostic if it is unknown.

Printing 'loc(unknown)' just clutters the output with unhelpful information.

PiperOrigin-RevId: 257883717

5 years agoAdd serialization and deserialization of FuncOps. To support this the
Mahesh Ravishankar [Fri, 12 Jul 2019 21:32:20 +0000 (14:32 -0700)]
Add serialization and deserialization of FuncOps. To support this the
following SPIRV Instructions serializaiton/deserialization are added
as well

OpFunction
OpFunctionParameter
OpFunctionEnd
OpReturn

PiperOrigin-RevId: 257869806

5 years ago[spirv] Various small code improvements
Lei Zhang [Fri, 12 Jul 2019 20:53:57 +0000 (13:53 -0700)]
[spirv] Various small code improvements

* Changed SPIR-V types to all use unsigned for member type count and index
* Used the same method name for getting element type and count
* Improved spv.CompositeExtract verification a bit

PiperOrigin-RevId: 257862580

5 years agoUpdate the PatternRewriter constructor to take a context instead of a region.
River Riddle [Fri, 12 Jul 2019 19:11:24 +0000 (12:11 -0700)]
Update the PatternRewriter constructor to take a context instead of a region.

This will allow for cleanly using a rewriter for multiple different regions.

PiperOrigin-RevId: 257845371

5 years agoChange the IR printing pass instrumentation to ignore the verifier passes on non...
River Riddle [Fri, 12 Jul 2019 18:20:09 +0000 (11:20 -0700)]
Change the IR printing pass instrumentation to ignore the verifier passes on non-failure.

The verifier passes are NO-OP and are only useful to print after in the case of failure. This removes a lot of unnecessary clutter when printing after/before all passes.

PiperOrigin-RevId: 257836310

5 years agoRemove the 'region' field from OpBuilder.
River Riddle [Fri, 12 Jul 2019 17:43:11 +0000 (10:43 -0700)]
Remove the 'region' field from OpBuilder.

This field wasn't updated as the insertion point changed, making it potentially dangerous given the multi-level of MLIR(e.g. 'createBlock' would always insert the new block in 'region'). This also allows for building an OpBuilder with just a context.

PiperOrigin-RevId: 257829135

5 years agoHide some public API of QuantizedType inherited from Type.
Jing Pu [Fri, 12 Jul 2019 17:10:42 +0000 (10:10 -0700)]
Hide some public API of QuantizedType inherited from Type.

It is for preventing subtle bugs when writing predicates with wrong APIs. For example,

// BAD example for checking a quant type has an i8 or i16 storage type.
auto qtype = type.dyn_cast<mlir::quant::UniformQuantizedType>()
if (qtype.isSigned() && (qtype.isInteger(8) || qtype.isInteger(16)))

PiperOrigin-RevId: 257823263

5 years ago[spirv] Add script to auto-generate SPIR-V op template from spec
Lei Zhang [Fri, 12 Jul 2019 17:00:13 +0000 (10:00 -0700)]
[spirv] Add script to auto-generate SPIR-V op template from spec

SPIR-V has a JSON grammar file that defines the syntax of SPIR-V
instructions. However, its lacks fine-grained constraints on
instruction operands; those information is only available as
natural language sentences in the SPIR-V spec, which also contains
the detailed documentation for each SPIR-V instruction.

This CL pulls information from both the JSON grammar and HTML
spec. It right now uses the former to deduce the arguments and
results (with coarse-grained constraints) and the latter for
documentation. In the future we can add the functionality to
match certain natural language sentences for more fine-grained
constraints, but right now the developer is expected to update
the generated op definition. This should serve as a nice
bootstrap step to save efforts.

PiperOrigin-RevId: 257821205

5 years agoFix a bug in the canonicalizer when replacing constants via patterns.
River Riddle [Fri, 12 Jul 2019 16:38:55 +0000 (09:38 -0700)]
Fix a bug in the canonicalizer when replacing constants via patterns.

The GreedyPatternRewriteDriver currently does not notify the OperationFolder when constants are removed as part of a pattern match. This materializes in a nasty bug where a different operation may be allocated to the same address. This causes an assertion in the OperationFolder when it gets notified of the new operations removal.

PiperOrigin-RevId: 257817627

5 years agoLower affine control flow to std control flow to LLVM dialect
Nicolas Vasilache [Fri, 12 Jul 2019 13:48:45 +0000 (06:48 -0700)]
Lower affine control flow to std control flow to LLVM dialect

This CL splits the lowering of affine to LLVM into 2 parts:
1. affine -> std
2. std -> LLVM

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

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

PiperOrigin-RevId: 257794436

5 years ago[spirv] Add CompositeExtractOp operation.
Denis Khalikov [Fri, 12 Jul 2019 13:14:53 +0000 (06:14 -0700)]
[spirv] Add CompositeExtractOp operation.

CompositeExtractOp allows to extract a part of a composite object.

Closes tensorflow/mlir#44

PiperOrigin-RevId: 257790731

5 years agoLoopsToGPU: use PassRegistration with constructor
Alex Zinenko [Fri, 12 Jul 2019 12:36:55 +0000 (05:36 -0700)]
LoopsToGPU: use PassRegistration with constructor

PassRegistration with an optional constructor was introduced after the
LoopsToGPUPass, which resorted to deriving one pass from another as a means of
accepting options supplied as command-line arguments. Use PassRegistration with
constructor instead of defining a derived pass for LoopsToGPU.  Also rename the
pass to better reflect its current nature.

PiperOrigin-RevId: 257786923

5 years agoLinalgTilingPass: use PassRegistration with a pass constructor
Alex Zinenko [Fri, 12 Jul 2019 12:36:19 +0000 (05:36 -0700)]
LinalgTilingPass: use PassRegistration with a pass constructor

Linalg tiling pass was introduced before PassRegistration with an optional pass
constructor.  It resorted to deriving a helper class from the origial pass
class in order to provide a default constructor with values obtained from
command line flags.  Use PassRegistration with the optional pass constructor
instead, which avoids declaring an additional class.

PiperOrigin-RevId: 257786876

5 years agoNFC: Remove redundant call to registerPassManagerCLOptions from MLIR tutorial
Smit Hinsu [Fri, 12 Jul 2019 01:26:26 +0000 (18:26 -0700)]
NFC: Remove redundant call to registerPassManagerCLOptions from MLIR tutorial

main already calls registerPassManagerCLOptions.

TESTED = not (NFC)
PiperOrigin-RevId: 257722013

5 years agoUpdate the dialect attribute verifiers related to functions.
River Riddle [Thu, 11 Jul 2019 22:05:19 +0000 (15:05 -0700)]
Update the dialect attribute verifiers related to functions.

Remove the Function specific attribute verifier in favor of the general operation verifier. This also generalizes the function argument verifier to allow use for an argument attached to any region of any operation.

PiperOrigin-RevId: 257689962

5 years agoAdd support for serialization/deserialization of OpTypeVoid and
Mahesh Ravishankar [Thu, 11 Jul 2019 21:37:50 +0000 (14:37 -0700)]
Add support for serialization/deserialization of OpTypeVoid and
OpTypeFunction

PiperOrigin-RevId: 257684235

5 years agoRename FunctionAttr to SymbolRefAttr.
River Riddle [Thu, 11 Jul 2019 18:41:04 +0000 (11:41 -0700)]
Rename FunctionAttr to SymbolRefAttr.

This allows for the attribute to hold symbolic references to other operations than FuncOp. This also allows for removing the dependence on FuncOp from the base Builder.

PiperOrigin-RevId: 257650017

5 years agoFuncOp::eraseBody: drop all references before erasing blocks
Alex Zinenko [Thu, 11 Jul 2019 17:00:54 +0000 (10:00 -0700)]
FuncOp::eraseBody: drop all references before erasing blocks

Operations in a block can use a value defined in a dominating block.  When a
block, and therefore all its operations, is deleted, the operations are not
allowed to have any remaining uses.  Drop all uses of values in all blocks
before deleting them in FuncOp::eraseBody to avoid deleting an operation before
deleting the users of its results.

PiperOrigin-RevId: 257628002

5 years agoaffine.load/store: check for the right number of operands
Alex Zinenko [Thu, 11 Jul 2019 14:42:51 +0000 (07:42 -0700)]
affine.load/store: check for the right number of operands

Affine load and store operations take a variadic number of arguments, most of
which are interpreted as subscripts for the multi-dimensional memref they
access.  Add a verifier check that ensures the number of operands is equal to
the number affine remapping inputs if present and to the rank of the acessed
memref otherwise.  Although it is impossible to obtain such operations by
parsing the custom syntax, it is possible to construct them using the generic
syntax or programmatically.

PiperOrigin-RevId: 257605902

5 years agoPropagate linalg op attributes in transformations
Nicolas Vasilache [Thu, 11 Jul 2019 14:13:30 +0000 (07:13 -0700)]
Propagate linalg op attributes in transformations

Also fix the tile_conv test.

PiperOrigin-RevId: 257602321

5 years agomcuMemHostRegister: take into account sizeof(float)
Alex Zinenko [Thu, 11 Jul 2019 12:21:34 +0000 (05:21 -0700)]
mcuMemHostRegister: take into account sizeof(float)

cuMemHostRegister expects the size of registered memory in bytes whereas the
memref descriptor in memref_t contains the number of elements.  Get the actual
size in bytes instead.

PiperOrigin-RevId: 257589116

5 years agoUpdate the gen_spirv_dialect.py script to add opcodes from the SPIR-V
Mahesh Ravishankar [Thu, 11 Jul 2019 00:33:28 +0000 (17:33 -0700)]
Update the gen_spirv_dialect.py script to add opcodes from the SPIR-V
JSON spec into the SPIRBase.td file. This is done incrementally to
only import those opcodes that are needed, through use of the script
define_opcode.sh added.

PiperOrigin-RevId: 257517343

5 years agoNFC: Replace Module::getNamedFunction with lookupSymbol<FuncOp>.
River Riddle [Wed, 10 Jul 2019 22:49:27 +0000 (15:49 -0700)]
NFC: Replace Module::getNamedFunction with lookupSymbol<FuncOp>.

This allows for removing the last direct reference to FuncOp from ModuleOp.

PiperOrigin-RevId: 257498296

5 years agoRefactor the parsing/printing of the top-level module.
River Riddle [Wed, 10 Jul 2019 22:16:52 +0000 (15:16 -0700)]
Refactor the parsing/printing of the top-level module.

This changes the top-level module parser to handle the case where the top-level module is defined with the module operation syntax, i.e:
  module ... {
  }

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

PiperOrigin-RevId: 257492069

5 years agoFix BufferSizeOp type lowering to LLVM.
Nicolas Vasilache [Wed, 10 Jul 2019 18:42:56 +0000 (11:42 -0700)]
Fix BufferSizeOp type lowering to LLVM.

This fixes a bug where the result type was incorrect when lowering to LLVM.

PiperOrigin-RevId: 257449384

5 years agoPassRegistation: use overloads instead of a default argument
Alex Zinenko [Wed, 10 Jul 2019 18:39:09 +0000 (11:39 -0700)]
PassRegistation: use overloads instead of a default argument

Windows build is not happy trying to convert a lambda into a constant reference
to a function in default arguments of the PassRegistration constructor.  Define
two overloaded constructors instead and construct the lambda as a variable in
the constructor body.

PiperOrigin-RevId: 257448633

5 years agoDrop the trailing newline from the FuncOp syntax.
River Riddle [Wed, 10 Jul 2019 18:34:57 +0000 (11:34 -0700)]
Drop the trailing newline from the FuncOp syntax.

The ModulePrinter prints the newline now for children of the top-level module. This also fixes the location printing for functions as the location used to be printed on a different line.

PiperOrigin-RevId: 257447633

5 years agoEDSC: use affine.load/store instead of std.load/store
Alex Zinenko [Wed, 10 Jul 2019 18:16:40 +0000 (11:16 -0700)]
EDSC: use affine.load/store instead of std.load/store

Standard load and store operations are evolving to be separated from the Affine
constructs.  Special affine.load/store have been introduced to uphold the
restrictions of the Affine control flow constructs on their operands.
EDSC-produced loads and stores were originally intended to uphold those
restrictions as well so they should use affine.load/store instead of
std.load/store.

PiperOrigin-RevId: 257443307

5 years agoNFC: Remove Function::getModule.
River Riddle [Wed, 10 Jul 2019 18:12:27 +0000 (11:12 -0700)]
NFC: Remove Function::getModule.

There is already a more general 'getParentOfType' method, and 'getModule' is likely to be misused as functions get placed within different regions than ModuleOp.

PiperOrigin-RevId: 257442243

5 years agoDelete dead code
Nicolas Vasilache [Wed, 10 Jul 2019 18:02:56 +0000 (11:02 -0700)]
Delete dead code

AffineIfOp::build is not tested or exercised anywhere. It also perpetuates a questionable choice of encoding an optional region as an empty region which we would like to change in the future.
PiperOrigin-RevId: 257439832

5 years agoNFC: Rename Module to ModuleOp.
River Riddle [Wed, 10 Jul 2019 17:07:49 +0000 (10:07 -0700)]
NFC: Rename Module to ModuleOp.

Module is a legacy name that only exists as a typedef of ModuleOp.

PiperOrigin-RevId: 257427248

5 years agoUpdate ModuleOp::create(...) to take a Location instead of a context.
River Riddle [Wed, 10 Jul 2019 00:57:24 +0000 (17:57 -0700)]
Update ModuleOp::create(...) to take a Location instead of a context.

This allows for giving a Module a more interesting location than 'Unknown'.

PiperOrigin-RevId: 257310117

5 years agoNFC: Rename Function to FuncOp.
River Riddle [Tue, 9 Jul 2019 23:17:55 +0000 (16:17 -0700)]
NFC: Rename Function to FuncOp.
PiperOrigin-RevId: 257293379

5 years agoConstrain regex to avoid ordering issues.
Jacques Pienaar [Tue, 9 Jul 2019 20:17:30 +0000 (13:17 -0700)]
Constrain regex to avoid ordering issues.

PiperOrigin-RevId: 257257173

5 years agoRelax the restriction that Modules cannot contain operations producing results.
River Riddle [Tue, 9 Jul 2019 18:49:41 +0000 (11:49 -0700)]
Relax the restriction that Modules cannot contain operations producing results.

This was an arbitrary restriction caused by the way that modules were printed. Now that that has been fixed, this restriction can be removed.

PiperOrigin-RevId: 257240329

5 years agoStandardize the value numbering in the AsmPrinter.
River Riddle [Tue, 9 Jul 2019 17:40:29 +0000 (10:40 -0700)]
Standardize the value numbering in the AsmPrinter.

Change the AsmPrinter to number values breadth-first so that values in adjacent regions can have the same name. This allows for ModuleOp to contain operations that produce results. This also standardizes the special name of region entry arguments to "arg[0-9+]" now that Functions are also operations.

PiperOrigin-RevId: 257225069

5 years agoAdd parentheses around boolean operators in an assertion in
Alex Zinenko [Tue, 9 Jul 2019 14:51:17 +0000 (07:51 -0700)]
Add parentheses around boolean operators in an assertion in
Linalg/Transforms/Tiling.cpp.  This fixes a warning.

PiperOrigin-RevId: 257191302

5 years agoFix a test broken on some systems due to a mis-rebase.
Alex Zinenko [Tue, 9 Jul 2019 14:43:17 +0000 (07:43 -0700)]
Fix a test broken on some systems due to a mis-rebase.

PiperOrigin-RevId: 257190161

5 years agoImplement parametric tiling on standard for loops
Alex Zinenko [Tue, 9 Jul 2019 13:37:17 +0000 (06:37 -0700)]
Implement parametric tiling on standard for loops

Parametric tiling can be used to extract outer loops with fixed number of
iterations.  This in turn enables mapping to GPU kernels on a fixed grid
independently of the range of the original loops, which may be unknown
statically, making the kernel adaptable to different sizes.  Provide a utility
function that also computes the parametric tile size given the range of the
loop.  Exercise the utility function through a simple pass that applies it to
all top-level loop nests.  Permutability or parallelism checks must be
performed before calling this utility function in actual passes.

Note that parametric tiling cannot be implemented in a purely affine way,
although it can be encoded using semi-affine maps.  The choice to implement it
on standard loops is guided by them being the common representation between
Affine loops, Linalg and GPU kernels.

PiperOrigin-RevId: 257180251

5 years agoExtend AffineToGPU to support Linalg loops
Alex Zinenko [Tue, 9 Jul 2019 12:26:18 +0000 (05:26 -0700)]
Extend AffineToGPU to support Linalg loops

Extend the utility that converts affine loop nests to support other types of
loops by abstracting away common behavior through templates.  This also
slightly simplifies the existing Affine to GPU conversion by always passing in
the loop step as an additional kernel argument even though it is a known
constant.  If it is used, it will be propagated into the loop body by the
existing canonicalization pattern and can be further constant-folded, otherwise
it will be dropped by canonicalization.

This prepares for the common loop abstraction that will be used for converting
to GPU kernels, which is conceptually close to Linalg loops, while maintaining
the existing conversion operational.

PiperOrigin-RevId: 257172216

5 years agoNFC: Change a usage of StringLiteral to StringRef.
River Riddle [Tue, 9 Jul 2019 07:58:41 +0000 (00:58 -0700)]
NFC: Change a usage of StringLiteral to StringRef.

This matches the result type of other functions returning c-string, and fixes a build failure where some compilers fail to construct the StringLiteral.

PiperOrigin-RevId: 257139513

5 years agoGeneralize the symbol table functionality of ModuleOp into a trait 'OpTrait::SymbolTa...
River Riddle [Tue, 9 Jul 2019 05:31:25 +0000 (22:31 -0700)]
Generalize the symbol table functionality of ModuleOp into a trait 'OpTrait::SymbolTable'.

Operations must only contain a single region.  Once attached, all operations that contain a 'mlir::SymbolTable::getSymbolAttrName()' StringAttr attribute within the child region will be verified to ensure that the names are uniqued. Operations using this trait also gain access to the 'SymbolTable' class, which can be used to manage the symbol table of the operation. This class also provides constant-time lookup of symbols by name, and will automatically rename symbols on insertion.

PiperOrigin-RevId: 257123573

5 years agoNFC: Remove `Module::getFunctions` in favor of a general `getOps<T>`.
River Riddle [Tue, 9 Jul 2019 01:27:45 +0000 (18:27 -0700)]
NFC: Remove `Module::getFunctions` in favor of a general `getOps<T>`.

Modules can now contain more than just Functions, this just updates the iteration API to reflect that. The 'begin'/'end' methods have also been updated to iterate over opaque Operations.

PiperOrigin-RevId: 257099084

5 years agoNFC: Make the 'disable-pass-threading' flag a PassManagerOption.
River Riddle [Mon, 8 Jul 2019 21:05:37 +0000 (14:05 -0700)]
NFC: Make the 'disable-pass-threading' flag a PassManagerOption.

This also adds the ability to programmatically disable threading.

PiperOrigin-RevId: 257051809

5 years agoRemove dead code.
Jacques Pienaar [Mon, 8 Jul 2019 21:01:09 +0000 (14:01 -0700)]
Remove dead code.

PiperOrigin-RevId: 257050780

5 years agoAdd dependencies for standard ops to SPIR-V conversion
Lei Zhang [Mon, 8 Jul 2019 18:56:16 +0000 (11:56 -0700)]
Add dependencies for standard ops to SPIR-V conversion

PiperOrigin-RevId: 257026374

5 years agoAdd missing override.
Jacques Pienaar [Mon, 8 Jul 2019 18:45:05 +0000 (11:45 -0700)]
Add missing override.

PiperOrigin-RevId: 257024265

5 years agoNFC: Remove the various "::getFunction" methods.
River Riddle [Mon, 8 Jul 2019 18:20:26 +0000 (11:20 -0700)]
NFC: Remove the various "::getFunction" methods.

These methods assume that a function is a valid builtin top-level operation, and removing these methods allows for decoupling FuncOp and IR/. Utility "getParentOfType" methods have been added to Operation/OpState to allow for querying the first parent operation of a given type.

PiperOrigin-RevId: 257018913

5 years agoNFC: Add AbstractOperation as a friend of 'Op'.
River Riddle [Mon, 8 Jul 2019 18:17:40 +0000 (11:17 -0700)]
NFC: Add AbstractOperation as a friend of 'Op'.

This allows for accessing the hidden overload of 'Op::hasTrait'.

PiperOrigin-RevId: 257018255

5 years agoAdd Ops in SPIR-V Dialect corresponding to OpEntryPoint and OpExecutionMode
Mahesh Ravishankar [Mon, 8 Jul 2019 17:56:20 +0000 (10:56 -0700)]
Add Ops in SPIR-V Dialect corresponding to OpEntryPoint and OpExecutionMode

PiperOrigin-RevId: 257013183

5 years agoRemove dead code.
Jacques Pienaar [Mon, 8 Jul 2019 17:52:16 +0000 (10:52 -0700)]
Remove dead code.

PiperOrigin-RevId: 257012369

5 years agoAdd 'hasTrait' support to Operation.
River Riddle [Mon, 8 Jul 2019 17:30:20 +0000 (10:30 -0700)]
Add 'hasTrait' support to Operation.

This is accomplished by adding a new callback to AbstractOperation that takes a ClassID for a given trait type and compares that against the ClassIDs for the traits used when registering an operation. This allows for opaquely querying if an operation was registered with a given trait, e.g:

Operation *op = ...;
bool singleResult = op->hasTrait<OpTrait::OneResult>();

PiperOrigin-RevId: 257007710

5 years ago[spirv] NFC: Remove functions wrapping spv.module in tests
Lei Zhang [Mon, 8 Jul 2019 17:10:39 +0000 (10:10 -0700)]
[spirv] NFC: Remove functions wrapping spv.module in tests

Now both functions and modules are just general ops and we do not require
top-level entities in a module's block to be the old builtin functions
any more. Removing the wrapping functions to simplify the tests.

PiperOrigin-RevId: 257003572

5 years agoAdd missing overrides.
Jacques Pienaar [Mon, 8 Jul 2019 16:35:19 +0000 (09:35 -0700)]
Add missing overrides.

PiperOrigin-RevId: 256995548

5 years agoRemove std::move of trivially-copyable type.
Jacques Pienaar [Mon, 8 Jul 2019 15:19:19 +0000 (08:19 -0700)]
Remove std::move of trivially-copyable type.

Address ClangTidy finding:

* std::move of the expression of the trivially-copyable type 'mlir::Module' (aka 'mlir::ModuleOp') has no effect; remove std::move()

PiperOrigin-RevId: 256981849

5 years agoInclude missing header.
Jacques Pienaar [Mon, 8 Jul 2019 15:04:40 +0000 (08:04 -0700)]
Include missing header.

This target was failing to build with newer version of libc++.

PiperOrigin-RevId: 256979592

5 years agoLinalgOp::Model: add missing override specifiers
Alex Zinenko [Mon, 8 Jul 2019 11:17:45 +0000 (04:17 -0700)]
LinalgOp::Model: add missing override specifiers

All non-static functions in LinalgOp::Model override pure virtual functions
from LinalgOp::Concept, but only some of them have the `override` specifier.
This may lead one to erroneously believe the functions without the specified
are not overrides or virtual functions.  Add the specifier to all relevant
functions.

PiperOrigin-RevId: 256948453

5 years agoUse isa instead of dyn_cast as cast value isn't used.
Jacques Pienaar [Sun, 7 Jul 2019 21:04:46 +0000 (14:04 -0700)]
Use isa instead of dyn_cast as cast value isn't used.

Avoids unused variable warning.

PiperOrigin-RevId: 256874512

5 years agoMigrate NativeCodeCall and AllAttrConstraintsOf tests to use TestDialect
Lei Zhang [Fri, 5 Jul 2019 17:05:16 +0000 (10:05 -0700)]
Migrate NativeCodeCall and AllAttrConstraintsOf tests to use TestDialect

PiperOrigin-RevId: 256685260

5 years agoMigrate pattern attribute matching tests to use TestDialect
Lei Zhang [Fri, 5 Jul 2019 16:23:47 +0000 (09:23 -0700)]
Migrate pattern attribute matching tests to use TestDialect

This CL also reorders op definitions and tests a bit to make them
group more logically.

PiperOrigin-RevId: 256682105

5 years agoMove StdForOp to ODS ForOp
Nicolas Vasilache [Fri, 5 Jul 2019 12:04:53 +0000 (05:04 -0700)]
Move StdForOp to ODS ForOp

PiperOrigin-RevId: 256657155

5 years agoAdd a standard if op
Nicolas Vasilache [Fri, 5 Jul 2019 10:34:49 +0000 (03:34 -0700)]
Add a standard if op

This CL adds an "std.if" op to represent an if-then-else construct whose condition is an arbitrary value of type i1.
This is necessary to lower all the existing examples from affine and linalg to std.for + std.if.

This CL introduces the op and adds the relevant positive and negative unit test. Lowering will be done in a separate followup CL.

PiperOrigin-RevId: 256649138

5 years agoSimplify launch_func rewrite pattern in mlir-cuda-runner
Alex Zinenko [Fri, 5 Jul 2019 09:51:26 +0000 (02:51 -0700)]
Simplify launch_func rewrite pattern in mlir-cuda-runner

Use the bulk setOperands on the cloned operation, no need to cast or iterate
over the operand list.

PiperOrigin-RevId: 256643496

5 years agoODS: provide a flag to skip generation of default build methods
Alex Zinenko [Fri, 5 Jul 2019 09:27:39 +0000 (02:27 -0700)]
ODS: provide a flag to skip generation of default build methods

Some operations need to override the default behavior of builders, in
particular region-holding operations such as affine.for or tf.graph want to
inject default terminators into the region upon construction, which default
builders won't do.  Provide a flag that disables the generation of default
builders so that the custom builders could use the same function signatures.
This is an intentionally low-level and heavy-weight feature that requires the
entire builder to be implemented, and it should be used sparingly.  Injecting
code into the end of a default builder would depend on the naming scheme of the
default builder arguments that is not visible in the ODS.  Checking that the
signature of a custom builder conflicts with that of a default builder to
prevent emission would require teaching ODG to differentiate between types and
(optional) argument names in the generated C++ code.  If this flag ends up
being used a lot, we should consider adding traits that inject specific code
into the default builder.

PiperOrigin-RevId: 256640069

5 years agoAdd ODS accessors for named regions.
Nicolas Vasilache [Fri, 5 Jul 2019 09:20:38 +0000 (02:20 -0700)]
Add ODS accessors for named regions.

PiperOrigin-RevId: 256639471

5 years agoTrivial typo in comment fix.
Chris Lattner [Fri, 5 Jul 2019 05:17:42 +0000 (22:17 -0700)]
Trivial typo in comment fix.

PiperOrigin-RevId: 256616187

5 years agoNFC: Remove Region::getContainingFunction as Functions are now Operations.
River Riddle [Thu, 4 Jul 2019 20:22:42 +0000 (13:22 -0700)]
NFC: Remove Region::getContainingFunction as Functions are now Operations.

PiperOrigin-RevId: 256579717

5 years agoFix another incorrect forward declaration of LogicalResult
Alex Zinenko [Thu, 4 Jul 2019 20:05:28 +0000 (13:05 -0700)]
Fix another incorrect forward declaration of LogicalResult

LogicalResult is a struct and the Windows build is unhappy about it being
forward-declared as class.

PiperOrigin-RevId: 256578230

5 years agoForward-declare LogicalResult as struct
Alex Zinenko [Thu, 4 Jul 2019 17:16:39 +0000 (10:16 -0700)]
Forward-declare LogicalResult as struct

LogicalResult is a struct but some headers forward-declare it as a class, which
breaks Windows builds.  Forward-delcare as a struct instead.

PiperOrigin-RevId: 256565699

5 years agoMake TranslateFromMLIRFunction type return LogicalResult instead of bool
Alex Zinenko [Thu, 4 Jul 2019 15:18:45 +0000 (08:18 -0700)]
Make TranslateFromMLIRFunction type return LogicalResult instead of bool

This interface was created before MLIR introduced LogicalResult.

PiperOrigin-RevId: 256554557

5 years agoAdd an mlir-cuda-runner tool.
Stephan Herhut [Thu, 4 Jul 2019 14:49:52 +0000 (07:49 -0700)]
Add an mlir-cuda-runner tool.

This tool allows to execute MLIR IR snippets written in the GPU dialect
on a CUDA capable GPU. For this to work, a working CUDA install is required
and the build has to be configured with MLIR_CUDA_RUNNER_ENABLED set to 1.

PiperOrigin-RevId: 256551415

5 years agoAllocOp: drop redundant verifier check
Alex Zinenko [Thu, 4 Jul 2019 14:47:34 +0000 (07:47 -0700)]
AllocOp: drop redundant verifier check

The equality check between the rank of a memref and the input size of the
layout affine map in AllocOp::verify is subsumed by the well-formedness check
of the memref type itself.  Drop the redundant check from the verifier since it
is never exercised (the type builder does not allow one to construct a type
that would not pass the verifier check).

PiperOrigin-RevId: 256551247

5 years agoAdd missing mlir:: namespace in definition of createConvertToLLVMIRPass.
Stephan Herhut [Thu, 4 Jul 2019 14:02:25 +0000 (07:02 -0700)]
Add missing mlir:: namespace in definition of createConvertToLLVMIRPass.

PiperOrigin-RevId: 256546769