summaryrefslogtreecommitdiffstats
path: root/mlir/lib/IR/Operation.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Change impl::printBinaryOp() to consider operand and result typeLei Zhang2019-03-291-0/+13
| | | | | | | | | | The operand and result types of binary ops are not necessarily the same. For those binary ops, we cannot print in the short-form assembly. Enhance impl:::printBinaryOp to consider operand and result types to select which assembly form to use. PiperOrigin-RevId: 229608142
* Split the standard types from builtin types and move them into separate ↵River Riddle2019-03-291-2/+2
| | | | | | source files(StandardTypes.cpp/h). After this cl only FunctionType and IndexType are builtin types, but IndexType will likely become a standard type when the ml/cfgfunc merger is done. Mechanical NFC. PiperOrigin-RevId: 227750918
* Merge the verifier logic for all functions into a unified framework, thisChris Lattner2019-03-291-10/+7
| | | | | | | | | | requires enhancing DominanceInfo to handle the structure of an ML function, which is required anyway. Along the way, this also fixes a const correctness problem with Instruction::getBlock(). This is step 24/n towards merging instructions and statements. PiperOrigin-RevId: 227228900
* Tidy up references to "basic blocks" that should refer to blocks now. NFC.Chris Lattner2019-03-291-1/+1
| | | | PiperOrigin-RevId: 227196077
* Standardize naming of statements -> instructions, revisting the code base to beChris Lattner2019-03-291-2/+2
| | | | | | | | | consistent and moving the using declarations over. Hopefully this is the last truly massive patch in this refactoring. This is step 21/n towards merging instructions and statements, NFC. PiperOrigin-RevId: 227178245
* Rename BasicBlock and StmtBlock to Block, and make a pass cleaning it up. I ↵Chris Lattner2019-03-291-4/+4
| | | | | | | | | | | did not make an effort to rename all of the 'bb' names in the codebase, since they are still correct and any specific missed once can be fixed up on demand. The last major renaming is Statement -> Instruction, which is why Statement and Stmt still appears in various places. This is step 19/n towards merging instructions and statements, NFC. PiperOrigin-RevId: 227163082
* Rename BBArgument -> BlockArgument, Op::getOperation -> Op::getInst(),Chris Lattner2019-03-291-5/+5
| | | | | | | | StmtResult -> InstResult, StmtOperand -> InstOperand, and remove the old names. This is step 17/n towards merging instructions and statements, NFC. PiperOrigin-RevId: 227121537
* Merge Operation into OperationInst and standardize nomenclature aroundChris Lattner2019-03-291-226/+30
| | | | | | | | OperationInst. This is a big mechanical patch. This is step 16/n towards merging instructions and statements, NFC. PiperOrigin-RevId: 227093712
* Rework inherentance hierarchy: Operation now derives from Statement, andChris Lattner2019-03-291-62/+4
| | | | | | | | | | | | | OperationInst derives from it. This allows eliminating some forwarding functions, other complex code handling multiple paths, and the 'isStatement' bit tracked by Operation. This is the last patch I think I can make before the big mechanical change merging Operation into OperationInst, coming next. This is step 15/n towards merging instructions and statements, NFC. PiperOrigin-RevId: 227077411
* Merge SSAValue, CFGValue, and MLValue together into a single Value class, whichChris Lattner2019-03-291-9/+8
| | | | | | | | | is the new base of the SSA value hierarchy. This CL also standardizes all the nomenclature and comments to use 'Value' where appropriate. This also eliminates a large number of cast<MLValue>(x)'s, which is very soothing. This is step 11/n towards merging instructions and statements, NFC. PiperOrigin-RevId: 227064624
* Eliminate the Instruction, BasicBlock, CFGFunction, MLFunction, and ↵Chris Lattner2019-03-291-68/+19
| | | | | | | | | | | | ExtFunction classes, using the Statement/StmtBlock hierarchy and Function instead. This *only* changes the internal data structures, it does not affect the user visible syntax or structure of MLIR code. Function gets new "isCFG()" sorts of predicates as a transitional measure. This patch is gross in a number of ways, largely in an effort to reduce the amount of mechanical churn in one go. It introduces a bunch of using decls to keep the old names alive for now, and a bunch of stuff needs to be renamed. This is step 10/n towards merging instructions and statements, NFC. PiperOrigin-RevId: 227044402
* Rename findFunction from the ML side of the house to be named getFunction(),Chris Lattner2019-03-291-1/+1
| | | | | | | | | | | | making it more similar to the CFG side of things. It is true that in a deeply nested case that this is not a guaranteed O(1) time operation, and that 'get' could lead compiler hackers to think this is cheap, but we need to merge these and we can look into solutions for this in the future if it becomes a problem in practice. This is step 9/n towards merging instructions and statements, NFC. PiperOrigin-RevId: 226983931
* Refactor MLFunction to contain a StmtBlock for its body instead of inheritingChris Lattner2019-03-291-1/+1
| | | | | | | | | | from it. This is necessary progress to squaring away the parent relationship that a StmtBlock has with its enclosing if/for/fn, and makes room for functions to have more than one block in the future. This also removes IfClause and ForStmtBody. This is step 5/n towards merging instructions and statements, NFC. PiperOrigin-RevId: 226936541
* Eliminate the ability to add operands to an instruction, used in a narrow caseChris Lattner2019-03-291-14/+9
| | | | | | | | | | | | | | | for SSA values in terminators, but easily worked around. At the same time, move the StmtOperand list in a OperationStmt to the end of its trailing objects list so we can *reduce* the number of operands, without affecting offsets to the other stuff in the allocation. This is important because we want OperationStmts to be consequtive, including their operands - we don't want to use an std::vector of operands like Instructions have. This is patch 4/n towards merging instructions and statements, NFC. PiperOrigin-RevId: 226865727
* Return bool from all emitError methods similar to Operation::emitOpErrorSmit Hinsu2019-03-291-24/+16
| | | | | | | | | | | | | This simplifies call-sites returning true after emitting an error. After the conversion, dropped braces around single statement blocks as that seems more common. Also, switched to emitError method instead of emitting Error kind using the emitDiagnostic method. TESTED with existing unit tests PiperOrigin-RevId: 224527868
* Add isIntOrIndex() and isIntOrIndexOrFloat() into TypeLei Zhang2019-03-291-12/+4
| | | | | | | | | The checks for `isa<IndexType>() || isa<IntegerType>()` and `isa<IndexType>() || isa<IntegerType>() || isa<FloatType>()` are frequently used, so it's useful to have some helper methods for them. PiperOrigin-RevId: 224133596
* Verify CmpIOp's result type to be bool-likeLei Zhang2019-03-291-1/+57
| | | | | | | | | This CL added two new traits, SameOperandsAndResultShape and ResultsAreBoolLike, and changed CmpIOp to embody these two traits. As a consequence, CmpIOp's result type now is verified to be bool-like. PiperOrigin-RevId: 223208438
* Add support for setting the location of an IROperandOwner.River Riddle2019-03-291-0/+8
| | | | PiperOrigin-RevId: 222995814
* Adds ConstantFoldHook registry in MLIRContextFeng Liu2019-03-291-2/+9
| | | | | | | | | | | | | | This reverts the previous method which needs to create a new dialect with the constant fold hook from TensorFlow. This new method uses a function object in dialect to store the constant fold hook. Once a hook is registered to the dialect, this function object will be assigned when the dialect is added to the MLIRContext. For the operations which are not registered, a new method getRegisteredDialects is added to the MLIRContext to query the dialects which matches their op name prefixes. PiperOrigin-RevId: 222310149
* Add functionality for erasing terminator successor operands and basic block ↵River Riddle2019-03-291-0/+6
| | | | | | arguments. PiperOrigin-RevId: 222303233
* Add support for Operation::moveBefore(Operation *).River Riddle2019-03-291-0/+7
| | | | PiperOrigin-RevId: 222252521
* Merge OperationInst functionality into Instruction.River Riddle2019-03-291-35/+28
| | | | | | We do some limited renaming here but define an alias for OperationInst so that a follow up cl can solely perform the large scale renaming. PiperOrigin-RevId: 221726963
* [MLIR] Merge terminator and uses into BasicBlock operations list handling.River Riddle2019-03-291-4/+1
| | | | PiperOrigin-RevId: 221700132
* Replace TerminatorInst with builtin terminator operations.River Riddle2019-03-291-1/+4
| | | | | Note: Terminators will be merged into the operations list in a follow up patch. PiperOrigin-RevId: 221670037
* Fix variables only used in assertions.River Riddle2019-03-291-2/+2
| | | | PiperOrigin-RevId: 221660580
* Add functionality for parsing/managing operation terminator successors.River Riddle2019-03-291-1/+99
| | | | | | Follow up patches will work to remove TerminatorInst. PiperOrigin-RevId: 221640621
* Start the plumbing for removing TerminatorInst.River Riddle2019-03-291-0/+18
| | | | | | | | | | * Add skeleton br/cond_br builtin ops. * Add a terminator trait for operations. * Mark ReturnOp as a Terminator. The functionality for managing/parsing/verifying successors will be added in a follow up cl. PiperOrigin-RevId: 221283000
* Falls back to dialect constant folding hookFeng Liu2019-03-291-4/+9
| | | | PiperOrigin-RevId: 220861133
* Implement value type abstraction for locations.River Riddle2019-03-291-1/+1
| | | | | | Value type abstraction for locations differ from others in that a Location can NOT be null. NOTE: dyn_cast returns an Optional<T>. PiperOrigin-RevId: 220682078
* Enable arithmetics for index types.Alex Zinenko2019-03-291-4/+12
| | | | | | | | | | | | | | | | | | | | | | | Arithmetic and comparison instructions are necessary to implement, e.g., control flow when lowering MLFunctions to CFGFunctions. (While it is possible to replace some of the arithmetics by affine_apply instructions for loop bounds, it is still necessary for loop bounds checking, steps, if-conditions, non-trivial memref subscripts, etc.) Furthermore, working with indirect accesses in, e.g., lookup tables for large embeddings, may require operating on tensors of indexes. For example, the equivalents to C code "LUT[Index[i]]" or "ResultIndex[i] = i + j" where i, j are loop induction variables require the arithmetics on indices as well as the possibility to operate on tensors thereof. Allow arithmetic and comparison operations to apply to index types by declaring them integer-like. Allow tensors whose element type is index for indirection purposes. The absence of vectors with "index" element type is explicitly tested, but the only justification for this restriction in the CL introducing the test is "because we don't need them". Do NOT enable vectors of index types, although it makes vector and tensor types inconsistent with respect to allowed element types. PiperOrigin-RevId: 220614055
* Add OpTraits for operand types: IntegerLike and SameType.Alex Zinenko2019-03-291-12/+34
| | | | | | | | | | | | | | Introduce new OpTraits verifying relation between operands of an Operation, similarly to its results. Arithmetic operations are defined separately for integer and floating point types. While we are currently leveraging the equality of result and operand types to make sure the right arithmetic operations are used for the right types, we may eventually want to verify operand types directly. Furthermore, for upcoming comparison operations, the type of the result differs from those of the operands so we need to verify the operand types directly. Similarly, we will want to restrict comparisons (and potentially binary arithmetic operations) to operands of the same type. PiperOrigin-RevId: 220365629
* Implement value type abstraction for types.River Riddle2019-03-291-13/+13
| | | | | | This is done by changing Type to be a POD interface around an underlying pointer storage and adding in-class support for isa/dyn_cast/cast. PiperOrigin-RevId: 219372163
* Add support for walking the use list of an SSAValue and converting owners toChris Lattner2019-03-291-0/+32
| | | | | | | | Operation*'s, simplifying some code in GreedyPatternRewriteDriver.cpp. Also add print/dump methods on Operation. PiperOrigin-RevId: 219045764
* Implement value type abstraction for attributes.River Riddle2019-03-291-3/+3
| | | | | | This is done by changing Attribute to be a POD interface around an underlying pointer storage and adding in-class support for isa/dyn_cast/cast. PiperOrigin-RevId: 218764173
* Add a pattern (x+0) -> x, generalize Canonicalize to CFGFunc's, address a ↵Chris Lattner2019-03-291-0/+8
| | | | | | | | few TODOs, and add some casting support to Operation. PiperOrigin-RevId: 218219340
* introduce a memref_cast operation, refactoring common code between it andChris Lattner2019-03-291-1/+25
| | | | | | shape_cast into a common CastOp class. PiperOrigin-RevId: 218175818
* Introduce a new Operation::erase helper to generalize some code inChris Lattner2019-03-291-0/+7
| | | | | | | the pattern matcher / canonicalizer, and rename existing eraseFromBlock methods to align with it. PiperOrigin-RevId: 218104455
* Replace the "OperationSet" abstraction with a new Dialect abstraction. This isChris Lattner2019-03-291-2/+13
| | | | | | | | | a step forward because now every AbstractOperation knows which Dialect it is associated with, enabling things in the future like "constant folding hooks" which will be important for layering. This is also a bit nicer on the registration side of things. PiperOrigin-RevId: 218104230
* Rename Operation::getAs to Operation::dyn_castFeng Liu2019-03-291-18/+18
| | | | | | | | | Also rename Operation::is to Operation::isa Introduce Operation::cast All of these are for consistency with global dyn_cast/cast/isa operators. PiperOrigin-RevId: 217878786
* Add constant folding and binary operator reassociation to the canonicalizeChris Lattner2019-03-291-0/+8
| | | | | | | pass, build up the worklist infra in anticipation of improving the pattern matcher to match more than one node. PiperOrigin-RevId: 217330579
* Change the representation of an operation name to be either anChris Lattner2019-03-291-2/+31
| | | | | | | | | AbstractOperation* or an Identifier. This makes it possible to get to stuff in AbstractOperation faster than going through a hash table lookup. This makes constant folding a bit faster now, but will become more important with subsequent changes. PiperOrigin-RevId: 216476772
* Add target independent standard DMA ops: dma.start, dma.waitUday Bondhugula2019-03-291-2/+5
| | | | | | | | | | | Add target independent standard DMA ops: dma.start, dma.wait. Update pipeline data transfer to use these to detect DMA ops. While on this - return failure from mlir-opt::performActions if a pass generates invalid output - improve error message for verify 'n' operand traits PiperOrigin-RevId: 216429885
* Fix b/116749799, an issue where the ZeroResult trait's verifier hook left in ↵Chris Lattner2019-03-291-0/+52
| | | | | | | | | an old form. Upgrade it, and move all the trait verifier implementations consistently out of line to reduce template bloat. PiperOrigin-RevId: 214718242
* Rename OpBase -> Op.Chris Lattner2019-03-291-5/+5
| | | | PiperOrigin-RevId: 214676460
* Introduce a new BinaryOp to commonize simple binary ops, introduce traits forChris Lattner2019-03-291-0/+80
| | | | | | | | | ResultIsFloatLike/ResultIsIntegerLike, move some code out of templates into shared code, keep the ops in StandardOps.cpp/h sorted. This significantly reduces the boilerplate for Add/Mul sorts of ops. In a subsequent patch, I plan to rename OpBase to Op, but didn't want to clutter this diff. PiperOrigin-RevId: 214622871
* Implement support for constant folding operations and a simple constant foldingChris Lattner2019-03-291-0/+16
| | | | | | | | | | | | | | | | | | optimization pass: - Give the ability for operations to implement a constantFold hook (a simple one for single-result ops as well as general support for multi-result ops). - Implement folding support for constant and addf. - Implement support in AbstractOperation and Operation to make this usable by clients. - Implement a very simple constant folding pass that does top down folding on CFG and ML functions, with a testcase that exercises all the above stuff. Random cleanups: - Improve the build APIs for ConstantOp. - Stop passing "-o -" to mlir-opt in the testsuite, since that is the default. PiperOrigin-RevId: 213749809
* rework the custom op verifier hooks to use the diagnostic emissionChris Lattner2019-03-291-0/+38
| | | | | | | | | | infrastructure, instead of returning a const char*. This allows custom formatting and more interesting diagnostics. This patch regresses the error message quality from the control flow lowering pass, I'll address this in a subsequent patch. PiperOrigin-RevId: 212210681
* Introduce a new Location abstraction to represent location data in a structuredChris Lattner2019-03-291-1/+1
| | | | | | | | (and more useful) way rather than hacking up a pile of attributes for it. In the future this will grow to represent inlined locations, fusion cases etc, but for now we start with simple Unknown and File/Line/Col locations. NFC. PiperOrigin-RevId: 210485775
* Push location information more tightly into the IR, providing space for everyChris Lattner2019-03-291-4/+12
| | | | | | | | | | | | | | operation and statement to have a location, and make it so a location is required to be specified whenever you make one (though a null location is still allowed). This is to encourage compiler authors to propagate loc info properly, allowing our failability story to work well. This is still a WIP - it isn't clear if we want to continue abusing Attribute for location information, or whether we should introduce a new class heirarchy to do so. This is good step along the way, and unblocks some of the tf/xla work that builds upon it. PiperOrigin-RevId: 210001406
* Finish support for function attributes, and improve lots of things:Chris Lattner2019-03-291-19/+21
| | | | | | | | | | | | | | | | | | | | | | | - Have the parser rewrite forward references to their resolved values at the end of parsing. - Implement verifier support for detecting malformed function attrs. - Add efficient query for (in general, recursive) attributes to tell if they contain a function. As part of this, improve other general infrastructure: - Implement support for verifying OperationStmt's in ml functions, refactoring and generalizing support for operations in the verifier. - Refactor location handling code in mlir-opt to have the non-error expecting form of mlir-opt invocations to report error locations precisely. - Fix parser to detect verifier failures and report them through errorReporter instead of printing the error and crashing. This regresses the location info for verifier errors in the parser that were previously ascribed to the function. This will get resolved in future patches by adding support for function attributes, which we can use to manage location information. PiperOrigin-RevId: 209600980
OpenPOWER on IntegriCloud