summaryrefslogtreecommitdiffstats
path: root/mlir/lib/IR/Builders.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Add dialect-specific decoding for opaque constants.Tatiana Shpeisman2019-03-291-2/+3
| | | | | | | | Associates opaque constants with a particular dialect. Adds general mechanism to register dialect-specific hooks defined in external components. Adds hooks to decode opaque tensor constant and extract an element of an opaque tensor constant. This CL does not change the existing mechanism for registering constant folding hook yet. One thing at a time. PiperOrigin-RevId: 233544757
* Remove remaining references to OperationInst in all directories except for ↵River Riddle2019-03-291-5/+5
| | | | | | lib/Transforms. PiperOrigin-RevId: 232322771
* Define the AffineForOp and replace ForInst with it. This patch is largely ↵River Riddle2019-03-291-16/+0
| | | | | | mechanical, i.e. changing usages of ForInst to OpPointer<AffineForOp>. An important difference is that upon construction an AffineForOp no longer automatically creates the body and induction variable. To generate the body/iv, 'createBody' can be called on an AffineForOp with no body. PiperOrigin-RevId: 232060516
* Define an detail::OperandStorage class to handle managing instruction ↵River Riddle2019-03-291-3/+4
| | | | | | operands. This class stores operands in a similar way to SmallVector except for two key differences. The first is the inline storage, which is a trailing objects array. The second is that being able to dynamically resize the operand list is optional. This means that we can enable the cases where operations need to change the number of operands after construction without losing the spatial locality benefits of the common case (operation instructions / non-control flow instructions with a lifetime fixed number of operands). PiperOrigin-RevId: 231910497
* Recommit: Define a AffineOps dialect as well as an AffineIfOp operation. ↵River Riddle2019-03-291-7/+0
| | | | | | Replace all instances of IfInst with AffineIfOp and delete IfInst. PiperOrigin-RevId: 231342063
* Automated rollback of changelist 231318632.Nicolas Vasilache2019-03-291-0/+7
| | | | PiperOrigin-RevId: 231327161
* Define a AffineOps dialect as well as an AffineIfOp operation. Replace all ↵River Riddle2019-03-291-7/+0
| | | | | | instances of IfInst with AffineIfOp and delete IfInst. PiperOrigin-RevId: 231318632
* Allow operations to hold a blocklist and add support for parsing/printing a ↵River Riddle2019-03-291-3/+3
| | | | | | block list for verbose printing. PiperOrigin-RevId: 230951462
* Migrate VectorOrTensorType/MemRefType shape api to use int64_t instead of int.River Riddle2019-03-291-3/+4
| | | | PiperOrigin-RevId: 230605756
* [MLIR] Add functionality for constructing a DenseElementAttr from an array ↵River Riddle2019-03-291-0/+5
| | | | | | of attributes and rerwite DenseElementsAttr::writeBits/readBits to handle non uniform bitwidths. This fixes asan failures that happen when using non uniform bitwidths. PiperOrigin-RevId: 229815107
* Const fold splat vectors/tensors in standard add, sub, and mul opsLei Zhang2019-03-291-0/+26
| | | | | | | | | | | | | The const folding logic is structurally similar, so use a template to abstract the common part. Moved mul(x, 0) to a legalization pattern to be consistent with mul(x, 1). Also promoted getZeroAttr() to be a method on Builder since it is expected to be frequently used. PiperOrigin-RevId: 228891989
* Split the standard types from builtin types and move them into separate ↵River Riddle2019-03-291-1/+1
| | | | | | 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-291-18/+0
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* Tidy up references to "basic blocks" that should refer to blocks now. NFC.Chris Lattner2019-03-291-2/+2
| | | | PiperOrigin-RevId: 227196077
* Standardize naming of statements -> instructions, revisting the code base to beChris Lattner2019-03-291-11/+11
| | | | | | | | | 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-5/+5
| | | | | | | | | | | 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
* Merge Operation into OperationInst and standardize nomenclature aroundChris Lattner2019-03-291-1/+1
| | | | | | | | OperationInst. This is a big mechanical patch. This is step 16/n towards merging instructions and statements, NFC. PiperOrigin-RevId: 227093712
* Merge CFGFuncBuilder/MLFuncBuilder/FuncBuilder together into a single newChris Lattner2019-03-291-26/+12
| | | | | | | | 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-24/+11
| | | | | | | | | 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-6/+6
| | | | | | | | | | | | 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 convenience methods to make type explicit.Jacques Pienaar2019-03-291-3/+7
| | | | PiperOrigin-RevId: 226939383
* Per review on the previous CL, drop MLFuncBuilder::createOperation, changingChris Lattner2019-03-291-12/+0
| | | | | | | | clients to use OperationState instead. This makes MLFuncBuilder more similiar to CFGFuncBuilder. This whole area will get tidied up more when cfg and ml worlds get unified. This patch is just gardening, NFC. PiperOrigin-RevId: 226701959
* Give StmtBlocks a use-def list, and give OperationStmt's the ability to haveChris Lattner2019-03-291-3/+4
| | | | | | | | | optional successor operands when they are terminator operations. This isn't used yet, but is part 2/n towards merging BasicBlock into StmtBlock and Instruction into OperationStmt. PiperOrigin-RevId: 226684636
* Type system: replace Type::getBitWidth with getIntOrFloatBitWidthAlex Zinenko2019-03-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | 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-1/+5
| | | | | | | | | | | | 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
* Verify CmpIOp's result type to be bool-likeLei Zhang2019-03-291-0/+2
| | | | | | | | | 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
* [MLIR] Rename OperationInst to Instruction.River Riddle2019-03-291-3/+3
| | | | PiperOrigin-RevId: 221795407
* Add Type to int/float attributes.Jacques Pienaar2019-03-291-4/+18
| | | | | | | | | | | | * 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
* [MLIR] Merge terminator and uses into BasicBlock operations list handling.River Riddle2019-03-291-10/+1
| | | | PiperOrigin-RevId: 221700132
* Replace TerminatorInst with builtin terminator operations.River Riddle2019-03-291-1/+10
| | | | | 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-3/+6
| | | | | | Follow up patches will work to remove TerminatorInst. PiperOrigin-RevId: 221640621
* - Add support for fused locations.River Riddle2019-03-291-0/+4
| | | | | | | | | | | | | | | | | | | | | | These are locations that form a collection of other source locations with an optional metadata attribute. - Add initial support for print/dump for locations. Location Printing Examples: * Unknown : [unknown-location] * FileLineColLoc : third_party/llvm/llvm/projects/google-mlir/test/TensorFlowLite/legalize.mlir:6:8 * FusedLoc : <"tfl-legalize">[third_party/llvm/llvm/projects/google-mlir/test/TensorFlowLite/legalize.mlir:6:8, third_party/llvm/llvm/projects/google-mlir/test/TensorFlowLite/legalize.mlir:7:8] - Add diagnostic support for fused locs. * Prints the first location as the main location and the remaining as "fused from here" notes: e.g. third_party/llvm/llvm/projects/google-mlir/test/TensorFlowLite/legalize.mlir:6:8: error: This is an error. %1 = "tf.add"(%arg0, %0) : (i32, i32) -> i32 ^ third_party/llvm/llvm/projects/google-mlir/test/TensorFlowLite/legalize.mlir:7:8: error: Fused from here. %2 = "tf.relu"(%1) : (i32) -> i32 ^ PiperOrigin-RevId: 220835552
* Implement value type abstraction for locations.River Riddle2019-03-291-8/+8
| | | | | | 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
* Materialize IndexType in the API.Alex Zinenko2019-03-291-1/+1
| | | | | | | | | | | | | | | Previously, index (aka affint) type was hidden under OtherType in the type API. We will need to identify and operate on values of index types in the upcoming MLFunc->CFGFunc(->LLVM) lowering passes. Materialize index type into a separate class and make it visible to LLVM RTTI hierarchy directly. Practically, index is an integer type of unknown bit width and is accetable in most places where regular integer types are. This is purely an API change that does not affect the IR. After IndexType is separated out from OtherType, the remaining "other types" are, in fact, TF-specific types only. Further renaming may be of interest. PiperOrigin-RevId: 220614026
* Implement value type abstraction for types.River Riddle2019-03-291-28/+27
| | | | | | 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
* Introduce integer set attributeUday Bondhugula2019-03-291-0/+4
| | | | | | | - add IntegerSetAttr to Attributes; add parsing and other support for it (builder, etc.). PiperOrigin-RevId: 218804579
* Implement value type abstraction for attributes.River Riddle2019-03-291-18/+18
| | | | | | 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
* Introduce Fourier-Motzkin variable elimination + other cleanup/supportUday Bondhugula2019-03-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Introduce Fourier-Motzkin variable elimination to eliminate a dimension from a system of linear equalities/inequalities. Update isEmpty to use this. Since FM is only exact on rational/real spaces, an emptiness check based on this is guaranteed to be exact whenever it says the underlying set is empty; if it says, it's not empty, there may still be no integer points in it. Also, supports a version that computes "dark shadows". - Test this by checking for "always false" conditionals in if statements. - Unique IntegerSet's that are small (few constraints, few variables). This basically means the canonical empty set and other small sets that are likely commonly used get uniqued; allows checking for the canonical empty set by pointer. IntegerSet::kUniquingThreshold gives the threshold constraint size for uniqui'ing. - rename simplify-affine-expr -> simplify-affine-structures Other cleanup - IntegerSet::numConstraints, AffineMap::numResults are no longer needed; remove them. - add copy assignment operators for AffineMap, IntegerSet. - rename Invalid() -> Null() on AffineExpr, AffineMap, IntegerSet - Misc cleanup for FlatAffineConstraints API PiperOrigin-RevId: 218690456
* Add support to opaque elements attributesFeng Liu2019-03-291-2/+7
| | | | | | | | | | | | | For some of the constant vector / tesor, if the compiler doesn't need to interpret their elements content, they can be stored in this class to save the serialize / deserialize cost. syntax: `opaque<` tensor-type `,` opaque-string `>` opaque-string ::= `0x` [0-9a-fA-F]* PiperOrigin-RevId: 218399426
* Use APFloat for FloatAttributeFeng Liu2019-03-291-0/+4
| | | | | | | | | | | | We should be able to represent arbitrary precision Float-point values inside the IR, so compiler optimizations, such as constant folding can be done independently on the compiling platform. This CL also added a new field, AttrValueGetter, to the Attr class definition for TableGen. This field is used to customize which mlir::Attr getter method to get the defined PrimitiveType. PiperOrigin-RevId: 218034983
* Add support to constant sparse tensor / vector attributeFeng Liu2019-03-291-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | The SparseElementsAttr uses (COO) Coordinate List encoding to represents a sparse tensor / vector. Specifically, the coordinates and values are stored as two dense elements attributes. The first dense elements attribute is a 2-D attribute with shape [N, ndims], which contains the indices of the elements with nonzero values in the constant vector/tensor. The second elements attribute is a 1-D attribute list with shape [N], which supplies the values for each element in the first elements attribute. ndims is the rank of the vector/tensor and N is the total nonzero elements. The syntax is: `sparse<` (tensor-type | vector-type)`, ` indices-attribute-list, values-attribute-list `>` Example: a sparse tensor sparse<vector<3x4xi32>, [[0, 0], [1, 2]], [1, 2]> represents the dense tensor [[1, 0, 0, 0] [0, 0, 2, 0] [0, 0, 0, 0]] PiperOrigin-RevId: 217764319
* Add support to constant dense vector/tensor attribute.Feng Liu2019-03-291-0/+5
| | | | | | | | | | | | | | | | | | | The syntax of dense vecor/tensor attribute value is `dense<` (tensor-type | vector-type)`,` attribute-list`>` and attribute-list ::= `[` attribute-list (`, ` attribute-list)* `]`. The construction of the dense vector/tensor attribute takes a vector/tensor type and a character array as arguments. The size of the input array should be larger than the size specified by the type argument. It also assumes the elements of the vector or tensor have been trunked to the data type sizes in the input character array, so it extends the trunked data to 64 bits when it is retrieved. PiperOrigin-RevId: 217762811
* [MLIR] IntegerSet value typeNicolas Vasilache2019-03-291-4/+4
| | | | | | | | | | | | | | | This CL applies the same pattern as AffineMap to IntegerSet: a simple struct that acts as the storage is allocated in the bump pointer. The IntegerSet is immutable and accessed everywhere by value. Note that unlike AffineMap, it is not possible to remove the MLIRContext parameter when constructing an IntegerSet for now. One possible way to achieve this would be to add an enum to distinguish between the mathematically empty set, the universe set and other sets. This is left for future discussion. PiperOrigin-RevId: 216545361
* Add support to constant splat vector/tensor attribute.Feng Liu2019-03-291-0/+5
| | | | | | | | | This attribute represents a reference to a splat vector or tensor, where all the elements have the same value. The syntax of the attribute is: `splat<` (tensor-type | vector-type)`,` attribute-value `>` PiperOrigin-RevId: 216537997
* Change the representation of an operation name to be either anChris Lattner2019-03-291-1/+1
| | | | | | | | | 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
* Support `getShape`, `hasStaticShape` and `getDimSize` methods for all the ↵Feng Liu2019-03-291-2/+1
| | | | | | Vector and Tensor Types. PiperOrigin-RevId: 216447553
* [MLIR] AffineMap value typeNicolas Vasilache2019-03-291-22/+22
| | | | | | | | This CL applies the same pattern as AffineExpr to AffineMap: a simple struct that acts as the storage is allocated in the bump pointer. The AffineMap is immutable and accessed everywhere by value. PiperOrigin-RevId: 216445930
* [MLIR] Sketch AffineExpr value typeNicolas Vasilache2019-03-291-53/+1
| | | | | | | | | | | | | | | | This CL sketches what it takes for AffineExpr to fully have by-value semantics and not be a not-so-smart pointer anymore. This essentially makes the underyling class a simple storage struct and implements the operations on the value type directly. Since there is no forwarding of operations anymore, we can full isolate the storage class and make a hard visibility barrier by moving detail::AffineExpr into AffineExprDetail.h. AffineExprDetail.h is only included where storage-related information is needed. PiperOrigin-RevId: 216385459
* Address comments from previous CL/216216446MLIR Team2019-03-291-1/+1
| | | | PiperOrigin-RevId: 216298139
* [MLIR] AffineExpr final cleanupsNicolas Vasilache2019-03-291-28/+27
| | | | | | | | | | | This CL: 1. performs the global codemod AffineXExpr->AffineXExprClass and AffineXExprRef -> AffineXExpr; 2. simplifies function calls by removing the redundant MLIRContext parameter; 3. adds missing binary operator versions of scalar op AffineExpr where it makes sense. PiperOrigin-RevId: 216242674
OpenPOWER on IntegriCloud