Commit Graph

38 Commits

Author SHA1 Message Date
Stella Laurenzo 1a2ad06bae Fix lingering sign compare warnings in exposed by "ninja check-mlir".
--

PiperOrigin-RevId: 248050178
2019-05-20 13:41:11 -07:00
River Riddle d39a30626e Use the DialectSymbolRegistry to reserve space in the Attribute::Kind enum to allow for dialects to define attribute kinds. The currently defined attributes kinds have now been moved to StandardAttributes.
--

PiperOrigin-RevId: 247988373
2019-05-20 13:40:03 -07:00
River Riddle 6a6cb40f23 Refactor the includes of Function.h now that the dependency on Operation has been removed. The dependency was on the op casting methods, which have now moved out of Operation, used by the walker.
--

PiperOrigin-RevId: 247944666
2019-05-20 13:38:32 -07:00
River Riddle 53a3483cc8 Ensure that all attributes are registered with a dialect. This is one of the final steps towards allowing dialects to define their own attributes, but there are still several things missing before this is fully supported(e.g. parsing/printing ).
--

PiperOrigin-RevId: 247684322
2019-05-10 19:30:23 -07:00
River Riddle 334d57ef41 Add an AttrBase class to simplify defining derived Attributes. This class serves the same purpose as TypeBase, and thus the duplicated functionality has been split into a new support class 'StorageUserBase'.
--

PiperOrigin-RevId: 247358373
2019-05-10 19:24:46 -07:00
River Riddle 983e0eea95 Simplify several usages of attributes now that they always have a type and, transitively, access to the context.
This also fixes a bug where FunctionAttrs were not being remapped for function and function argument attributes.

--

PiperOrigin-RevId: 246876924
2019-05-10 19:22:41 -07:00
River Riddle 3f27c60688 Add a static utility to FloatAttr for converting an APFloat to double.
--

PiperOrigin-RevId: 246671765
2019-05-06 08:29:28 -07:00
Jacques Pienaar 2fe8ae4f6c Fix up some mixed sign warnings.
--

PiperOrigin-RevId: 246614498
2019-05-06 08:28:20 -07:00
River Riddle 777e7b4f4f Make the Twine parameter of the current diagnostic emit functions optional. This allows for the ability to exclusively use the new diagnostic interface without breaking all of the existing usages. Several diagnostics emitted in lib/IR have been updated to make use of this functionality.
--

PiperOrigin-RevId: 246546044
2019-05-06 08:27:13 -07:00
River Riddle b91aea1516 NFC: Move AttributeStorage and AttributeUniquer into a new header AttributeSupport.h in preparation for them to be used by dialect defined attributes.
--

PiperOrigin-RevId: 246385860
2019-05-06 08:25:37 -07:00
River Riddle 007a4acece Remove NumericAttr. Now that all attributes contain a type, this subclass is no longer necessary.
--

PiperOrigin-RevId: 246061024
2019-05-06 08:23:33 -07:00
River Riddle 17d3acf40c Ensure that every Attribute contains a Type. If an Attribute does not provide a type explicitly, the type is defaulted to NoneType.
--

PiperOrigin-RevId: 246021088
2019-05-06 08:23:14 -07:00
River Riddle 0f89ef30b7 Refactor Attribute uniquing to use StorageUniquer instead of being hard coded in the MLIRContext. This allows for attributes to be uniqued similarly to types. This is the second step towards allowing dialects to define attributes.
--

PiperOrigin-RevId: 245974705
2019-05-06 08:22:50 -07:00
River Riddle 67653d9881 Add iterator support to DenseIntElementsAttr and DenseFPElementsAttr. This avoids the need to load all of the values from a DenseElementsAttr inorder to process them.
--

PiperOrigin-RevId: 242212741
2019-04-07 18:20:40 -07:00
River Riddle f0b38058b1 Add support for building a DenseIntElementsAttr with ArrayRef<int64_t> values.
PiperOrigin-RevId: 239616595
2019-03-29 17:29:42 -07:00
River Riddle db1757f858 Add support for named function argument attributes. The attribute dictionary is printed after the argument type:
func @arg_attrs(i32 {arg_attr: 10})

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

PiperOrigin-RevId: 236136830
2019-03-29 16:50:15 -07:00
River Riddle 303b768579 Add a generic getValue to ElementsAttr for accessing a value at a given index.
PiperOrigin-RevId: 236013669
2019-03-29 16:48:59 -07:00
River Riddle 302fb03961 Add a new class NamedAttributeList to deduplicate named attribute handling between Function and Instruction.
PiperOrigin-RevId: 235830304
2019-03-29 16:45:40 -07:00
River Riddle f1f86eac60 Add support for constructing DenseIntElementsAttr with an array of APInt and
DenseFPElementsAttr with an array of APFloat.

PiperOrigin-RevId: 235581794
2019-03-29 16:41:50 -07:00
River Riddle a51d21538c Add constant folding for ExtractElementOp when the aggregate is an OpaqueElementsAttr.
PiperOrigin-RevId: 235533283
2019-03-29 16:40:20 -07:00
Tatiana Shpeisman 2e6cd60d3b Add dialect-specific decoding for opaque constants.
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
2019-03-29 16:24:38 -07:00
Lei Zhang 8b75cc5741 Define NumericAttr as the base class for BoolAttr, IntegerAttr, FloatAttr, and ElementsAttr
These attribute kinds are different from the rest in the sense that their types are defined
in MLIR's type hierarchy and we can build constant op out of them.

By defining this middle-level base class, we have a unified way to test and query the type
of these attributes, which will be useful when constructing constant ops of various dialects.

This CL also added asserts to reject non-NumericAttr in constant op's build() method.

PiperOrigin-RevId: 232188178
2019-03-29 16:08:43 -07:00
River Riddle 6859f33292 Migrate VectorOrTensorType/MemRefType shape api to use int64_t instead of int.
PiperOrigin-RevId: 230605756
2019-03-29 15:33:20 -07:00
River Riddle 512d87cefc Add a constant folding hook to ExtractElementOp to fold extracting the element of a constant. This also adds a 'getValue' function to DenseElementsAttr and SparseElementsAttr to get the element at a constant index.
PiperOrigin-RevId: 230098938
2019-03-29 15:28:28 -07:00
River Riddle 0e81d7c420 [MLIR] Add functionality for constructing a DenseElementAttr from an array 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
2019-03-29 15:25:45 -07:00
River Riddle 06b0bd9651 Emit unsupported error when parsing a DenseElementAttr with an integer type of greater than 64 bits.
DenseElementAttr currently does not support value bitwidths of > 64. This can result in asan failures and crashes when trying to invoke DenseElementsAttr::writeBits/DenseElementsAttr::readBits.

PiperOrigin-RevId: 229241125
2019-03-29 15:14:23 -07:00
River Riddle ba9a544615 Simplify Attribute constructor definitions.
PiperOrigin-RevId: 228926113
2019-03-29 15:11:41 -07:00
Feng Liu 9b20a4ccdf add a method to get FloatAttr value as double
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
2019-03-29 14:41:34 -07:00
Alex Zinenko 49c81ebcb0 Densify storage for f16, f32 and support f16 semantics in FloatAttrs
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
2019-03-29 14:32:14 -07:00
Jacques Pienaar 711047c0cd Add Type to int/float attributes.
* 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
2019-03-29 13:59:23 -07:00
Alex Zinenko d030433443 ConvertToCFG: properly remap nested function attributes.
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
2019-03-29 13:57:58 -07:00
Jacques Pienaar 25e6b541cd Switch IntegerAttr to use APInt.
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
2019-03-29 13:55:08 -07:00
River Riddle 4c465a181d Implement value type abstraction for types.
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
2019-03-29 13:45:54 -07:00
Uday Bondhugula ea65c695b9 Introduce integer set attribute
- add IntegerSetAttr to Attributes; add parsing and other support for it
  (builder, etc.).

PiperOrigin-RevId: 218804579
2019-03-29 13:40:50 -07:00
River Riddle 792d1c25e4 Implement value type abstraction for attributes.
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
2019-03-29 13:39:19 -07:00
MLIR Team f1e039617b Support for AffineMapAttr.
PiperOrigin-RevId: 205157390
2019-03-29 12:35:40 -07:00
Chris Lattner b0dabbd67f Add parsing for attributes and attibutes on operations. Add IR representation
for attributes on operations.  Split Operation out from OperationInst so it
can be shared with OperationStmt one day.

PiperOrigin-RevId: 203325366
2019-03-29 12:29:16 -07:00
Chris Lattner ccd8caee9e Implement IR support for attributes.
PiperOrigin-RevId: 203293376
2019-03-29 12:29:00 -07:00