summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Parser
Commit message (Collapse)AuthorAgeFilesLines
...
* Verify string type token before attempting to get string value.Jacques Pienaar2019-03-291-0/+2
| | | | | | Add repro that would have resulted in crash previously. PiperOrigin-RevId: 228890749
* Support verbose parsing and printing of terminator operationsAlex Zinenko2019-03-291-0/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | Originally, terminators were special kinds of operation and could not be extended by dialects. Only builtin terminators were supported and they had custom parsers and printers. Currently, "terminator" is a property of an operation, making it possible for dialects to define custom terminators. However, verbose forms of operation syntax were not designed to support terminators that may have a list of successors (each successor contains a block name and an optional operand list). Calling printDefaultOp on a terminator drops all successor information. Dialects are thus required to provide custom parsers and printers for their terminators. Introduce the syntax for the list of successors in the verbose from of the operation. Add support for printing and parsing verbose operations with successors. Note that this does not yet add support for unregistered terminators since "terminator" is a property stored in AsbtractOperation and therefore is only available for registered operations that have an instance of AbstractOperation. Add tests for verbose parsing. It is currently impossible to test round-trip for verbose terminators because none of the known dialects use verbose syntax for printing terminators by default, however the printer was exercised on the LLVM IR dialect prototype. PiperOrigin-RevId: 228566453
* Add parser support for named type aliases.River Riddle2019-03-293-12/+67
| | | | | | | | | | | | | | | | | | | | Alias identifiers can be used in the place of the types that they alias, and are defined as: type-alias-def ::= '!' alias-name '=' 'type' type type-alias ::= '!' alias-name Example: !avx.m128 = type vector<4 x f32> ... "foo"(%x) : vector<4 x f32> -> () // becomes: "foo"(%x) : !avx.m128 -> () PiperOrigin-RevId: 228271372
* Misc readability and doc / code comment related improvements - NFCUday Bondhugula2019-03-291-1/+1
| | | | | | | | | | | | | | | | | | - when SSAValue/MLValue existed, code at several places was forced to create additional aggregate temporaries of SmallVector<SSAValue/MLValue> to handle the conversion; get rid of such redundant code - use filling ctors instead of explicit loops - for smallvectors, change insert(list.end(), ...) -> append(... - improve comments at various places - turn getMemRefAccess into MemRefAccess ctor and drop duplicated getMemRefAccess. In the next CL, provide getAccess() accessors for load, store, DMA op's to return a MemRefAccess. PiperOrigin-RevId: 228243638
* Add support for types belonging to unknown dialects. This allows for types ↵River Riddle2019-03-291-12/+20
| | | | | | to be round tripped even if the dialect that defines them is not linked in. These types will be represented by a new "UnknownType" that uniques them based upon the dialect namespace and raw string type data. PiperOrigin-RevId: 228184629
* Drop all uses of the ForInst induction variable before deleting ForInstAlex Zinenko2019-03-291-4/+2
| | | | | | | | | | | | | | | | The `for` instruction defines the loop induction variable it uses. In the well-formed IR, the induction variable can only be used by the body of the `for` loop. Existing implementation was explicitly cleaning the body of the for loop to remove all uses of the induction variable before removing its definition. However, in ill-formed IR that may appear in some stages of parsing, there may be (invalid) users of the loop induction variable outside the loop body. In case of unsuccessful parsing, destructor of the ForInst-defined Value would assert because there are remaining though invalid users of this Value. Explicitly drop all uses of the loop induction Value when destroying a ForInst. It is no longer necessary to explicitly clean the body of the loop, destructor of the block will take care of this. PiperOrigin-RevId: 228168880
* FunctionParser::~FunctionParser: avoid iterator invalidationAlex Zinenko2019-03-291-3/+4
| | | | | | | | | | | | When destroying a FunctionParser in case of parsing failure, we clean up all uses of undefined forward-declared references. This has been implemented as iteration over the list of uses. However, deleting one use from the list invalidates the iterator (`IROperand::drop` sets `nextUse` to `nullptr` while the iterator reads `nextUse` to advance; therefore only the first use was deleted from the list). Get a new iterator before calling drop to avoid invalidation. PiperOrigin-RevId: 228168849
* Rename getAffineBinaryExpr -> getAffineBinaryOpExpr, getBinaryAffineOpExpr ->Uday Bondhugula2019-03-291-9/+9
| | | | | | | | getAffineBinaryOpExpr for consistency (NFC) - this is consistent with the name of the class and getAffineDimExpr/ConstantExpr, etc. PiperOrigin-RevId: 228164959
* Handle parsing failure for splat elements attributeSmit Hinsu2019-03-291-0/+2
| | | | | | | | Currently, it emits the error but does not terminate parsing. TESTED with unit test PiperOrigin-RevId: 227886274
* Split the standard types from builtin types and move them into separate ↵River Riddle2019-03-291-6/+6
| | | | | | 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
* Implement initial support for dialect specific types.River Riddle2019-03-293-33/+62
| | | | | | | | | | | | | | | | | | | | | | | | | Dialect specific types are registered similarly to operations, i.e. registerType<...> within the dialect. Unlike operations, there is no notion of a "verbose" type, that is *all* types must be registered to a dialect. Casting support(isa/dyn_cast/etc.) is implemented by reserving a range of type kinds in the top level Type class as opposed to string comparison like operations. To support derived types a few hooks need to be implemented: In the concrete type class: - static char typeID; * A unique identifier for the type used during registration. In the Dialect: - typeParseHook and typePrintHook must be implemented to provide parser support. The syntax for dialect extended types is as follows: dialect-type: '!' dialect-namespace '<' '"' type-specific-data '"' '>' The 'type-specific-data' is information used to identify different types within the dialect, e.g: - !tf<"variant"> // Tensor Flow Variant Type - !tf<"string"> // Tensor Flow String Type TensorFlow/TensorFlowControl types are now implemented as dialect specific types as a proof of concept. PiperOrigin-RevId: 227580052
* Update the g3docs to reflect the merging of CFG and ML functions.Chris Lattner2019-03-291-1/+2
| | | | PiperOrigin-RevId: 227562943
* Eliminate extfunc/cfgfunc/mlfunc as a concept, and just use 'func' instead.Chris Lattner2019-03-292-36/+11
| | | | | | | | | | | | | The entire compiler now looks at structural properties of the function (e.g. does it have one block, does it contain an if/for stmt, etc) so the only thing holding up this difference is round tripping through the parser/printer syntax. Removing this shrinks the compile by ~140LOC. This is step 31/n towards merging instructions and statements. The last step is updating the docs, which I will do as a separate patch in order to split it from this mostly mechanical patch. PiperOrigin-RevId: 227540453
* Simplify FunctionPass to only have a runOnFunction hook, instead of having aChris Lattner2019-03-291-7/+1
| | | | | | | | | | runOnCFG/MLFunction override locations. Passes that care can handle this filtering if they choose. Also, eliminate one needless difference between CFG/ML functions in the parser. This is step 30/n towards merging instructions and statements. PiperOrigin-RevId: 227515912
* Clean up and improve the parser handling of basic block labels, now that weChris Lattner2019-03-292-39/+56
| | | | | | | | have a designator. This improves diagnostics and merges handling between CFG and ML functions more. This also eliminates hard coded parser knowledge of terminator keywords, allowing dialects to define their own terminators. PiperOrigin-RevId: 227239398
* Introduce ^ as a basic block sigil, eliminating an ambiguity on the MLIRChris Lattner2019-03-293-4/+13
| | | | | | syntax. PiperOrigin-RevId: 227234174
* Enhance parsing of CFG and Ext functions to optionally allow named arguments inChris Lattner2019-03-291-150/+91
| | | | | | | | | | | | | | | | | the function signature, giving them common functionality to ml functions. This is a strictly additive patch that adds new capability without changing behavior in a significant way (other than a few diagnostic cleanups). A subsequent patch will change the printer to use this behavior, which will require updating a ton of testcases. :) This exposes the fact that we need to make a grammar change for block arguments, as is tracked by b/122119779 This is step 23/n towards merging instructions and statements, and one of the first steps towards eliminating the "cfg vs ml" distinction at a syntax and semantic level. PiperOrigin-RevId: 227228342
* Tidy up references to "basic blocks" that should refer to blocks now. NFC.Chris Lattner2019-03-291-1/+1
| | | | PiperOrigin-RevId: 227196077
* Merge parser logic for CFG and ML functions, shrinking the codeChris Lattner2019-03-291-391/+316
| | | | | | | | | by ~80 lines. This causes a slight change to diagnostics, but is otherwise behavior preserving. This is step 22/n towards merging instructions and statements, MFC. PiperOrigin-RevId: 227187857
* Standardize naming of statements -> instructions, revisting the code base to beChris Lattner2019-03-291-45/+45
| | | | | | | | | 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-31/+31
| | | | | | | | | | | 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
* Eliminate the using decls for MLFunction and CFGFunction standardizing onChris Lattner2019-03-291-7/+7
| | | | | | | | Function. This is step 18/n towards merging instructions and statements, NFC. PiperOrigin-RevId: 227139399
* Rename BBArgument -> BlockArgument, Op::getOperation -> Op::getInst(),Chris Lattner2019-03-291-4/+4
| | | | | | | | 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-8/+10
| | | | | | | | OperationInst. This is a big mechanical patch. This is step 16/n towards merging instructions and statements, NFC. PiperOrigin-RevId: 227093712
* add a method to get FloatAttr value as doubleFeng Liu2019-03-291-2/+2
| | | | | | | | | | | | | | | | | Sometimes we have to get the raw value of the FloatAttr to invoke APIs from non-MLIR libraries (i.e. in the tpu_ops.inc and convert_tensor.cc files). Using `FloatAttr::getValue().convertToFloat()` and `FloatAttr::getValue().convertToDouble()` is not safe because interally they checke the semantics of the APFloat in the attribute, and the semantics is not always specified (the default value is f64 then convertToFloat will fail) or inferred incorrectly (for example, using 1.0 instead of 1.f for IEEEFloat). Calling these convert methods without knowing the semantics can usually crash the compiler. This new method converts the value of a FloatAttr to double even if it loses precision. Currently this method can be used to read in f32 data from arrays. PiperOrigin-RevId: 227076616
* Merge CFGFuncBuilder/MLFuncBuilder/FuncBuilder together into a single newChris Lattner2019-03-291-3/+3
| | | | | | | | FuncBuilder class. Also rename SSAValue.cpp to Value.cpp This is step 12/n towards merging instructions and statements, NFC. PiperOrigin-RevId: 227067644
* Merge SSAValue, CFGValue, and MLValue together into a single Value class, whichChris Lattner2019-03-291-38/+33
| | | | | | | | | 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-13/+15
| | | | | | | | | | | | 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
* Eliminate the MLFuncArgument class representing arguments to MLFunctions: ↵Chris Lattner2019-03-291-1/+1
| | | | | | | | | | | use the BlockArgument arguments of the entry block instead. This makes MLFunctions and CFGFunctions work more similarly. This is step 7/n towards merging instructions and statements, NFC. PiperOrigin-RevId: 226966975
* Refactor MLFunction to contain a StmtBlock for its body instead of inheritingChris Lattner2019-03-291-5/+5
| | | | | | | | | | 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
* Refactor ForStmt: having it contain a StmtBlock instead of subclassingChris Lattner2019-03-291-1/+1
| | | | | | | | | | | | | | StmtBlock. This is more consistent with IfStmt and also conceptually makes more sense - a forstmt "isn't" its body, it contains its body. This is step 1/N towards merging BasicBlock and StmtBlock. This is required because in the new regime StmtBlock will have a use list (just like BasicBlock does) of operands, and ForStmt already has a use list for its induction variable. This is a mechanical patch, NFC. PiperOrigin-RevId: 226684158
* Densify storage for f16, f32 and support f16 semantics in FloatAttrsAlex Zinenko2019-03-291-18/+18
| | | | | | | | | | | | | | | | | | Existing implementation always uses 64 bits to store floating point values in DenseElementsAttr. This was due to FloatAttrs always a `double` for storage independently of the actual type. Recent commits added support for FloatAttrs with the proper f32 type and floating semantics and changed the bitwidth reporting on FloatType. Use the existing infrastructure for densely storing 16 and 32-bit values in DenseElementsAttr storage to store f16 and f32 values. Move floating semantics definition to the FloatType level. Properly support f16 / IEEEhalf semantics at the FloatAttr level and in the builder. Note that bf16 is still stored as a 64-bit value with IEEEdouble semantics because APFloat does not have first-class support for bf16 types. PiperOrigin-RevId: 225981289
* Type system: replace Type::getBitWidth with getIntOrFloatBitWidthAlex Zinenko2019-03-291-9/+16
| | | | | | | | | | | | | | | | | | | | | | | As MLIR moves towards dialect-specific types, a generic Type::getBitWidth does not make sense for all of them. Even with the current type system, the bit width is not defined (and causes the method in question to abort) for all TensorFlow types. This commit restricts the bit width definition to primitive standard types that have a number of bits appearing verbatim in their type, i.e., integers and floats. As a side effect, it delegates the decision on the bit width of the `index` to the backends. Existing backends currently hardcode it to 64 bits. The Type::getBitWidth method is replaced by Type::getIntOrFloatBitWidth that only applies to integers and floats. The call sites are updated to use the new method, where applicable, or rewritten so as not rely on it. Incidentally, this fixes a utility method that did not account for memrefs being allowed to have vectors as element types in the size computation. As an observation, several places in the code use Type in places where a more specific type could be used instead. Some of those are fixed by this commit. PiperOrigin-RevId: 225844792
* Fix builder getFloatAttr of double to use F64 type and use fltSemantics in ↵Jacques Pienaar2019-03-291-12/+29
| | | | | | | | | | | | FloatAttr. Store FloatAttr using more appropriate fltSemantics (mostly fixing up F32/F64 storage, F16/BF16 pending). Previously F32 type was used incorrectly for double (the storage was double). Also add query method that returns fltSemantics for IEEE fp types and use that to verify that the APfloat given matches the type: * FloatAttr created using APFloat is verified that the semantics of the type and APFloat matches; * FloatAttr created using double has the APFloat created to match the semantics of the type; Change parsing of tensor negative splat element to pass in the element type expected. Misc other changes to account for the storage type matching the attribute. PiperOrigin-RevId: 225821834
* Return bool from all emitError methods similar to Operation::emitOpErrorSmit Hinsu2019-03-292-4/+3
| | | | | | | | | | | | | 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
* Strided DMA support for DmaStartOpUday Bondhugula2019-03-291-0/+13
| | | | | | | | - add optional stride arguments for DmaStartOp - add DmaStartOp::verify(), and missing test cases for DMA op's in test/IR/memory-ops.mlir. PiperOrigin-RevId: 224232466
* Add isIntOrIndex() and isIntOrIndexOrFloat() into TypeLei Zhang2019-03-291-2/+2
| | | | | | | | | 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
* Merge OperationInst functionality into Instruction.River Riddle2019-03-291-4/+4
| | | | | | 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
* Add Type to int/float attributes.Jacques Pienaar2019-03-291-14/+72
| | | | | | | | | | | | * Optionally attach the type of integer and floating point attributes to the attributes, this allows restricting a int/float to specific width. - Currently this allows suffixing int/float constant with type [this might be revised in future]. - Default to i64 and f32 if not specified. * For index types the APInt width used is 64. * Change callers to request a specific attribute type. * Store iN type with APInt of width N. * This change does not handle the folding of constants of different types (e.g., doing int type promotions to support constant folding i3 and i32), and instead restricts the constant folding to only operate on the same types. PiperOrigin-RevId: 221722699
* Replace TerminatorInst with builtin terminator operations.River Riddle2019-03-291-94/+15
| | | | | Note: Terminators will be merged into the operations list in a follow up patch. PiperOrigin-RevId: 221670037
* Add functionality for parsing/managing operation terminator successors.River Riddle2019-03-291-2/+47
| | | | | | Follow up patches will work to remove TerminatorInst. PiperOrigin-RevId: 221640621
* ConvertToCFG: properly remap nested function attributes.Alex Zinenko2019-03-291-79/+2
| | | | | | | | | | | | Array attributes can nested and function attributes can appear anywhere at that level. They should be remapped to point to the generated CFGFunction after ML-to-CFG conversion, similarly to plain function attributes. Extract the nested attribute remapping functionality from the Parser to Utils. Extract out the remapping function for individual Functions from the module remapping function. Use these new functions in the ML-to-CFG conversion pass and in the parser. PiperOrigin-RevId: 221510997
* Optionally emit errors from IntegerType factory functions.Alex Zinenko2019-03-291-5/+2
| | | | | | | | | | | | | | | Similarly to other types, introduce "get" and "getChecked" static member functions for IntegerType. The latter emits errors to the error handler registered with the MLIR context and returns a null type for the caller to handle errors gracefully. This deduplicates type consistency checks between the parser and the builder. Update the parser to call IntegerType::getChecked for error reporting instead of the builder that would simply assert. This CL completes the type system error emission refactoring: the parser now only emits syntax-related errors for types while type factory systems may emit type consistency errors. PiperOrigin-RevId: 221165207
* Homogenize branch instruction arguments.Alex Zinenko2019-03-291-21/+7
| | | | | | | | | | | | | | | | | | | | | | | | | Branch instruction arguments were defined and used inconsistently across different instructions, in both the spec and the implementation. In particular, conditional and unconditional branch instructions were using different syntax in the implementation. This led to the IR we produce not being accepted by the parser. Update the printer to use common syntax: `(` list-of-SSA-uses `:` list-of-types `)`. The motivation for choosing this syntax as opposed to the one in the spec, `(` list-of-SSA-uses `)` `:` list-of-types is double-fold. First, it is tricky to differentiate the label of the false branch from the type while parsing conditional branches (which is what apparently motivated the implementation to diverge from the spec in the first place). Second, the ongoing convergence between terminator instructions and other operations prompts for consistency between their operand list syntax. After this change, the only remaining difference between the two is the use of parentheses. Update the comment of the parser that did not correspond to the code. Remove the unused isParenthesized argument from parseSSAUseAndTypeList. Update the spec accordingly. Note that the examples in the spec were _not_ using the EBNF defined a couple of lines above them, but were using the current syntax. Add a supplementary example of a branch to a basic block with multiple arguments. PiperOrigin-RevId: 221162655
* Switch IntegerAttr to use APInt.Jacques Pienaar2019-03-291-5/+2
| | | | | | | | Change the storage type to APInt from int64_t for IntegerAttr (following the change to APFloat storage in FloatAttr). Effectively a direct change from int64_t to 64-bit APInt throughout (the bitwidth hardcoded). This change also adds a getInt convenience method to IntegerAttr and replaces previous getValue calls with getInt calls. While this changes updates the storage type, it does not update all constant folding calls. PiperOrigin-RevId: 221082788
* Handle VectorOrTensorType parse failure instead of crashingSmit Hinsu2019-03-291-1/+5
| | | | | | | | | | | This was unsafe after cr/219372163 and seems to be the only such case in the change. All other usage of dyn_cast are either handling the nullptr or are implicitly safe. For example, they are being extracted from operand or result SSAValue. TESTED with unit test PiperOrigin-RevId: 220905942
* Clean up TensorType construction.Alex Zinenko2019-03-291-6/+3
| | | | | | | | | | | | This CL introduces the following related changes: - move tensor element type validity checking to a static member function TensorType::isValidElementType - introduce get/getChecked similarly to MemRefType, where the checked function emits errors and returns nullptrs; - remove duplicate element type validity checking from the parser and rely on the type constructor to emit errors instead. PiperOrigin-RevId: 220694831
* Clean up VectorType construction.Alex Zinenko2019-03-291-5/+2
| | | | | | | | | | | | This CL introduces the following related changes: - factor out element type validity checking to a static member function VectorType::isValidElementType; - introduce get/getChecked similarly to MemRefType, where the checked function emits errors and returns nullptrs; - remove duplicate element type validity checking from the parser and rely on the type constructor to emit errors instead. PiperOrigin-RevId: 220693828
* Implement value type abstraction for locations.River Riddle2019-03-293-5/+5
| | | | | | 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
* Allow vector types to have index elements.Alex Zinenko2019-03-291-1/+2
| | | | | | | | | | It is unclear why vector types were not allowed to have "index" as element type. Index values are integers, although of unknown bit width, and should behave as such. Vectors of integers are allowed and so are tensors of indices (for indirection purposes), it is more consistent to also have vectors of indices. PiperOrigin-RevId: 220630123
OpenPOWER on IntegriCloud