summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [mlir] NFC: Remove Value::operator* and Value::operator-> now that Value is ↵River Riddle2020-01-111-23/+23
| | | | | | | | | | properly value-typed. Summary: These were temporary methods used to simplify the transition. Reviewed By: antiagainst Differential Revision: https://reviews.llvm.org/D72548
* [mlir] Fix the wrong computation of dynamic strides for lowering AllocOp to LLVMTung Le Duc2019-12-281-4/+5
| | | | | Leftover change from before the MLIR merge, reviewed at accepted at https://github.com/tensorflow/mlir/pull/338.
* NFC: Replace ValuePtr with Value and remove it now that Value is value-typed.River Riddle2019-12-231-154/+146
| | | | | | ValuePtr was a temporary typedef during the transition to a value-typed Value. PiperOrigin-RevId: 286945714
* Adjust License.txt file to use the LLVM licenseMehdi Amini2019-12-231-13/+4
| | | | PiperOrigin-RevId: 286906740
* NFC: Introduce new ValuePtr/ValueRef typedefs to simplify the transition to ↵River Riddle2019-12-221-149/+152
| | | | | | | | | | Value being value-typed. This is an initial step to refactoring the representation of OpResult as proposed in: https://groups.google.com/a/tensorflow.org/g/mlir/c/XXzzKhqqF_0/m/v6bKb08WCgAJ This change will make it much simpler to incrementally transition all of the existing code to use value-typed semantics. PiperOrigin-RevId: 286844725
* Add integer bit-shift operations to the standard dialect.Manuel Freiberger2019-12-221-8/+27
| | | | | | | | | | | | | | | | | | | Rename the 'shlis' operation in the standard dialect to 'shift_left'. Add tests for this operation (these have been missing so far) and add a lowering to the 'shl' operation in the LLVM dialect. Add also 'shift_right_signed' (lowered to LLVM's 'ashr') and 'shift_right_unsigned' (lowered to 'lshr'). The original plan was to name these operations 'shift.left', 'shift.right.signed' and 'shift.right.unsigned'. This works if the operations are prefixed with 'std.' in MLIR assembly. Unfortunately during import the short form is ambigous with operations from a hypothetical 'shift' dialect. The best solution seems to omit dots in standard operations for now. Closes tensorflow/mlir#226 PiperOrigin-RevId: 286803388
* Added LLVM ops and lowering phases from standard dialect for FAbs, FCeil, ↵Marcel Koester2019-12-181-0/+21
| | | | | | | | | | | Cos, FNeg, CopySign. Added test cases for the newly added LLVM operations and lowering features. Closes tensorflow/mlir#300 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/300 from dfki-jugr:std_to_llvm da6168bbc1a369ae2e99ad3881fdddd82f075dd4 PiperOrigin-RevId: 286231169
* Introduce prefetch op: affine -> std -> llvm intrinsicUday Bondhugula2019-12-181-0/+34
| | | | | | | | | | | | | | | | | | | Introduce affine.prefetch: op to prefetch using a multi-dimensional subscript on a memref; similar to affine.load but has no effect on semantics, but only on performance. Provide lowering through std.prefetch, llvm.prefetch and map to llvm's prefetch instrinsic. All attributes reflected through the lowering - locality hint, rw, and instr/data cache. affine.prefetch %0[%i, %j + 5], false, 3, true : memref<400x400xi32> Signed-off-by: Uday Bondhugula <uday@polymagelabs.com> Closes tensorflow/mlir#225 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/225 from bondhugula:prefetch 4c3b4e93bc64d9a5719504e6d6e1657818a2ead0 PiperOrigin-RevId: 286212997
* NFC: Remove unnecessary 'llvm::' prefix from uses of llvm symbols declared ↵River Riddle2019-12-181-9/+7
| | | | | | | | in `mlir` namespace. Aside from being cleaner, this also makes the codebase more consistent. PiperOrigin-RevId: 286206974
* NFC: Use TypeSwitch to simplify existing code.River Riddle2019-12-171-19/+14
| | | | PiperOrigin-RevId: 286066371
* Make it possible to override the lowering of MemRef to the LLVM dialect. NFC.Alex Zinenko2019-12-171-12/+25
| | | | | | | | | | | | | The lowering of MemRef types to the LLVM dialect is connected to the underlying runtime representation of structured memory buffers. It has changed several times in the past and reached the current state of a LLVM structured-typed descriptor containing two pointers and all sizes. In several reported use cases, a different, often simpler, lowering scheme is required. For example, lowering statically-shaped memrefs to bare LLVM pointers to simplify aliasing annotation. Split the pattern population functions into those include memref-related operations and the remaining ones. Users are expected to extend TypeConverter::convertType to handle the memref types differently. PiperOrigin-RevId: 286030610
* StdToLLVM conversion: drop getMemRefElementType utility functionAlex Zinenko2019-12-171-12/+1
| | | | | | | | This function has become redundant with MemRefDescriptor::getElementType and is no longer necessary. Use the MemRefDescriptor pervasively to concentrate descriptor-related logic in one place and drop the utility function. PiperOrigin-RevId: 286024168
* Make memref promotion during std->LLVM lowering the default calling conventionAlex Zinenko2019-12-161-29/+17
| | | | | | | | | | | | | | | During the conversion from the standard dialect to the LLVM dialect, memref-typed arguments are promoted from registers to memory and passed into functions by pointer. This had been introduced into the lowering to work around the abesnce of calling convention modeling in MLIR to enable better interoperability with LLVM IR generated from C, and has been exerciced for several months. Make this promotion the default calling covention when converting to the LLVM dialect. This adds the documentation, simplifies the code and makes the conversion consistent across function operations and function types used in other places, e.g. in high-order functions or attributes, which would not follow the same rule previously. PiperOrigin-RevId: 285751280
* Added lowering of `std.tanh` to llvm function call to `tanh` and `tanhf`.Ehsan Toosi2019-12-121-0/+51
| | | | | | | Closes tensorflow/mlir#312 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/312 from dfki-ehna:tanh 9e89b072ff91ff390ad739501745114feb3ac856 PiperOrigin-RevId: 285205674
* Add std.log* and llvm.intr.log* that correspond to the LLVMIR intrinsicsNicolas Vasilache2019-12-111-0/+12
| | | | PiperOrigin-RevId: 285073483
* Minor spelling tweaksKazuaki Ishizaki2019-12-091-3/+3
| | | | | | Closes tensorflow/mlir#304 PiperOrigin-RevId: 284568358
* Replace spurious SmallVector constructions with ValueRangeUday Bondhugula2019-12-091-5/+5
| | | | | | | | | Signed-off-by: Uday Bondhugula <uday@polymagelabs.com> Closes tensorflow/mlir#305 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/305 from bondhugula:value_range 21d1fae73f549e3c8e72b60876eff1b864cea39c PiperOrigin-RevId: 284541027
* Update the builder API to take ValueRange instead of ArrayRef<Value *>River Riddle2019-12-071-1/+2
| | | | | | This allows for users to provide operand_range and result_range in builder.create<> calls, instead of requiring an explicit copy into a separate data structure like SmallVector/std::vector. PiperOrigin-RevId: 284360710
* Add a new ValueRange class.River Riddle2019-12-061-2/+1
| | | | | | | | This class represents a generic abstraction over the different ways to represent a range of Values: ArrayRef<Value *>, operand_range, result_range. This class will allow for removing the many instances of explicit SmallVector<Value *, N> construction. It has the same memory cost as ArrayRef, and only suffers cost from indexing(if+elsing the different underlying representations). This change only updates a few of the existing usages, with more to be changed in followups; e.g. 'build' API. PiperOrigin-RevId: 284307996
* Add conversions of GPU func with memory attributions to LLVM/NVVMAlex Zinenko2019-12-061-2/+60
| | | | | | | | | | | | | | | | | | | GPU functions use memory attributions, a combination of Op attributes and region arguments, to specify function-wide buffers placed in workgroup or private memory spaces. Introduce a lowering pattern for GPU functions to be converted to LLVM functions taking into account memory attributions. Workgroup attributions get transformed into module-level globals with unique names derived from function names. Private attributions get converted into llvm.allocas inside the function body. In both cases, we inject at the beginning of the function the IR that obtains the raw pointer to the data and populates a MemRef descriptor based on the MemRef type of buffer, making attributions compose with the rest of the MemRef lowering and transparent for use with std.load and std.store. While using raw pointers instead of descriptors might have been more efficient, it is better implemented as a canonicalization or a separate transformation so that non-attribution memrefs could also benefit from it. PiperOrigin-RevId: 284208396
* minor spelling tweaksKazuaki Ishizaki2019-12-061-1/+1
| | | | | | | Closes tensorflow/mlir#290 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/290 from kiszk:spelling_tweaks_201912 9d9afd16a723dd65754a04698b3976f150a6054a PiperOrigin-RevId: 284169681
* Add UnrankedMemRef Typenmostafa2019-12-051-31/+164
| | | | | | | Closes tensorflow/mlir#261 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/261 from nmostafa:nmostafa/unranked 96b6e918f6ed64496f7573b2db33c0b02658ca45 PiperOrigin-RevId: 284037040
* Add a CL option to Standard to LLVM lowering to use alloca instead of ↵Nicolas Vasilache2019-12-041-35/+89
| | | | | | | | | malloc/free. In the future, a more configurable malloc and free interface should be used and exposed via extra parameters to the `createLowerToLLVMPass`. Until requirements are gathered, a simple CL flag allows generating code that runs successfully on hardware that cannot use the stdlib. PiperOrigin-RevId: 283833424
* Fix ViewOp to have at most one offset operandAlex Zinenko2019-12-031-6/+11
| | | | | | | | | | | | | | | | | | | | | As described in the documentation, ViewOp is expected to take an optional dynamic offset followed by a list of dynamic sizes. However, the ViewOp parser did not include a check for the offset being a single value and accepeted a list of values instead. Furthermore, several tests have been exercising the wrong syntax of a ViewOp, passing multiple values to the dyanmic stride list, which was not caught by the parser. The trailing values could have been erronously interpreted as dynamic sizes. This is likely due to resyntaxing of the ViewOp, with the previous syntax taking the list of sizes before the offset. Update the tests to use the syntax with the offset preceding the sizes. Worse, the conversion of ViewOp to the LLVM dialect assumed the wrong order of operands with offset in the trailing position, and erronously relied on the permissive parsing that interpreted trailing dynamic offset values as leading dynamic sizes. Fix the lowering to use the correct order of operands. PiperOrigin-RevId: 283532506
* Extend conversion of SubViewOp to llvm to also support cases where size and ↵Stephan Herhut2019-12-031-6/+24
| | | | | | | | | | | | stride are constant (i.e., there are no size and stride operands). We recently added canonicalization that rewrites constant size and stride operands to SubViewOp into static information in the type, so these patterns now occur during code generation. PiperOrigin-RevId: 283524688
* Add linkage support to LLVMFuncOpAlex Zinenko2019-12-031-2/+4
| | | | | | | | | A recent commit introduced the Linkage attribute to the LLVM dialect and used it in the Global Op. Also use it in LLVMFuncOp. As per LLVM Language Reference, if the linkage attribute is omitted, the function is assumed to have external linkage. PiperOrigin-RevId: 283493299
* NFC: Update std.subview op to use AttrSizedOperandSegmentsLei Zhang2019-12-021-2/+1
| | | | | | This turns a few manually written helper methods into auto-generated ones. PiperOrigin-RevId: 283339617
* Changes to SubViewOp to make it more amenable to canonicalization.Mahesh Ravishankar2019-11-201-5/+20
| | | | | | | | | | | | | | The current SubViewOp specification allows for either all offsets, shape and stride to be dynamic or all of them to be static. There are opportunities for more fine-grained canonicalization based on which of these are static. For example, if the sizes are static, the result memref is of static shape. The specification of SubViewOp is modified to allow on or more of offsets, shapes and strides to be statically specified. The verification is updated to ensure that the result type of the subview op is consistent with which of these are static and which are dynamic. PiperOrigin-RevId: 281560457
* Change conversion CLI flag from -lower-to-llvm to -convert-std-to-llvmAlex Zinenko2019-11-191-1/+2
| | | | | | | | | | | | The command-line flag name `lower-to-llvm` for the pass performing dialect conversion from the Standard dialect to the LLVM dialect is misleading and inconsistent with most of the conversion passses. It leads the user to believe that there are no restrictions on what can be converted, while in fact only a subset of the Standard dialect can be converted (with operations from other dialects converted by separate passes). Use `convert-std-to-llvm` that better reflects what the pass does and is consistent with most other conversions. PiperOrigin-RevId: 281238797
* ConvertStandardToLLVM: replace assertion with graceful failureAlex Zinenko2019-11-181-2/+2
| | | | | | | | | | | | | The assertion was introduced in the early days of dialect conversion infrastructure when we had the matching function separate from the rewriting function. The infrastructure evolved to have a common matchAndRewrite function and the separate matching function was dropped without chaning the rewriting that became matchAndRewrite. This has led to assertion being triggered. Return a matchFailure instead of failing an assertion on unsupported types. Closes tensorflow/mlir#230 PiperOrigin-RevId: 281113741
* Make positions of elements in MemRef descriptor privateAlex Zinenko2019-11-141-25/+17
| | | | | | | | Previous commits removed all uses of LLVMTypeConverter::k*PosInMemRefDescriptor outside of the MemRefDescriptor class. These numbers are an implementation detail and can be hidden under a layer of more semantic APIs. PiperOrigin-RevId: 280442444
* Use MemRefDescriptor in Vector-to-LLVM convresionAlex Zinenko2019-11-141-0/+5
| | | | | | | | | | Following up on the consolidation of MemRef descriptor conversion, update Vector-to-LLVM conversion to use the helper class that abstracts away the implementation details of the MemRef descriptor. This also makes the types of the attributes in emitted llvm.insert/extractelement operations consistently i64 instead of a mix of index and i64. PiperOrigin-RevId: 280441451
* Use MemRefDescriptor in Linalg-to-LLVM conversionAlex Zinenko2019-11-141-105/+96
| | | | | | | | | | | Following up on the consolidation of MemRef descriptor conversion, update Linalg-to-LLVM conversion to use the helper class that abstracts away the implementation details of the MemRef descriptor. This required MemRefDescriptor to become publicly visible. Since this conversion is heavily EDSC-based, introduce locally an additional wrapper that uses builder and location pointed to by the EDSC context while emitting descriptor manipulation operations. PiperOrigin-RevId: 280429228
* Concentrate memref descriptor manipulation logic in one placeAlex Zinenko2019-11-141-165/+174
| | | | | | | | | | | Memref descriptor is becoming increasingly complex. Memrefs are manipulated by multiple standard instructions, each of which has a non-trivial lowering to the LLVM dialect. This leads to verbose code that manipulates the descriptors exposing the internals of insert/extractelement opreations. Implement a wrapper class that contains a memref descriptor and provides semantically named methods that build the primitive IR operations instead. PiperOrigin-RevId: 280371225
* Add LLVM lowering of std.subviewNicolas Vasilache2019-11-121-0/+113
| | | | | | A followup CL will replace usage of linalg.subview by std.subview. PiperOrigin-RevId: 279961981
* Add support for alignment attribute in std.alloc.Nicolas Vasilache2019-11-121-63/+123
| | | | | | | | | | | | This CL adds an extra pointer to the memref descriptor to allow specifying alignment. In a previous implementation, we used 2 types: `linalg.buffer` and `view` where the buffer type was the unit of allocation/deallocation/alignment and `view` was the unit of indexing. After multiple discussions it was decided to use a single type, which conflates both, so the memref descriptor now needs to carry both pointers. This is consistent with the [RFC-Proposed Changes to MemRef and Tensor MLIR Types](https://groups.google.com/a/tensorflow.org/forum/#!searchin/mlir/std.view%7Csort:date/mlir/-wKHANzDNTg/4K6nUAp8AAAJ). PiperOrigin-RevId: 279959463
* Update Linalg to use std.viewNicolas Vasilache2019-11-071-4/+8
| | | | | | Now that a view op has graduated to the std dialect, we can update Linalg to use it and remove ops that have become obsolete. As a byproduct, the linalg buffer and associated ops can also disappear. PiperOrigin-RevId: 279073591
* Add lowering of std.view to LLVMNicolas Vasilache2019-11-061-0/+126
| | | | | | | | | | | | | This CL ports the lowering of linalg.view to the newly introduced std.view. Differences in implementation relate to std.view having slightly different semantics: 1. a static or dynamic offset can be specified. 2. the size of the (contiguous) shape is passed instead of a range. 3. static size and stride information is extracted from the memref type rather than the range. Besides these differences, lowering behaves the same. A future CL will update Linalg to use this unified infrastructure. PiperOrigin-RevId: 278948853
* Implement lowering of VectorTypeCastOp to LLVMNicolas Vasilache2019-10-181-13/+22
| | | | | | | | | | A VectorTypeCastOp can only be used to lower between statically sized contiguous memrefs of scalar and matching vector type. The sizes and strides are thus fully static and easy to determine. A relevant test is added. This is a step towards solving tensorflow/mlir#189. PiperOrigin-RevId: 275538981
* Add support for PatternRewriter::eraseOp.River Riddle2019-10-161-2/+2
| | | | | | This hook is useful when an operation is known to be dead, and no replacement values make sense. PiperOrigin-RevId: 275052756
* Add conversion for splat of vectors of 2+DNicolas Vasilache2019-10-151-48/+142
| | | | | | | This CL adds a missing lowering for splat of multi-dimensional vectors. Additional support is also added to the runtime utils library to allow printing memrefs with such vectors. PiperOrigin-RevId: 274794723
* Emit LLVM IR equivalent of sizeof when lowering alloc operationsAlex Zinenko2019-10-111-12/+15
| | | | | | | | | | | | | | | | | Originally, the lowering of `alloc` operations has been computing the number of bytes to allocate when lowering based on the properties of MLIR type. This does not take into account type legalization that happens when compiling LLVM IR down to target assembly. This legalization can widen the type, potentially leading to out-of-bounds accesses to `alloc`ed data due to mismatches between address computation that takes the widening into account and allocation that does not. Use the LLVM IR's equivalent of `sizeof` to compute the number of bytes to be allocated: %0 = getelementptr %type* null, %indexType 0 %1 = ptrtoint %type* %0 to %indexType adapted from http://nondot.org/sabre/LLVMNotes/SizeOf-OffsetOf-VariableSizedStructs.txt PiperOrigin-RevId: 274159900
* Drop obsolete code from std to llvm memref loweringUday Bondhugula2019-10-111-22/+11
| | | | | | | | | | | | - dropping what looks like outdated code post some of the previous updates Signed-off-by: Uday Bondhugula <uday@polymagelabs.com> Closes tensorflow/mlir#179 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/179 from bondhugula:llfix 2a72ea441fe1b3924802273ffbe9870afeb90f91 PiperOrigin-RevId: 274158273
* Rename LLVM::exp and LLVM::fmuladd to LLVM::ExpOP and LLVM::FMulAddOp.Alexander Belyaev2019-10-111-1/+1
| | | | PiperOrigin-RevId: 274154655
* Add unary ops and ExpOp to Standard Dialect.Alexander Belyaev2019-10-111-25/+79
| | | | PiperOrigin-RevId: 274152154
* Standard-to-LLVM conversion: check that operands have LLVM typesAlex Zinenko2019-10-101-0/+6
| | | | | | | | | | | | In Standard to LLVM dialect conversion, the binary op conversion pattern implicitly assumed some operands were of LLVM IR dialect type. This is not necessarily true, for example if the Ops that produce those operands did not match the existing convresion patterns. Check if all operands are of LLVM IR dialect type and if not, fail to patch the binary op pattern. Closes tensorflow/mlir#168 PiperOrigin-RevId: 274063207
* Use llvm.func to define functions with wrapped LLVM IR function typeAlex Zinenko2019-10-101-38/+65
| | | | | | | | | | | | | | This function-like operation allows one to define functions that have wrapped LLVM IR function type, in particular variadic functions. The operation was added in parallel to the existing lowering flow, this commit only switches the flow to use it. Using a custom function type makes the LLVM IR dialect type system more consistent and avoids complex conversion rules for functions that previously had to use the built-in function type instead of a wrapped LLVM IR dialect type and perform conversions during the analysis. PiperOrigin-RevId: 273910855
* Replace constexpr MemRefType::kDynamicStrideOrOffset by a ↵Nicolas Vasilache2019-10-041-5/+5
| | | | | | | | | | MemRefType:;getDynamicStrideOrOffset() method - NFC This fixes global ODR-use issues, some of which manifest in Parser.cpp. Fixes tensorflow/mlir#167. PiperOrigin-RevId: 272886347
* Fix typos, NFC.Christian Sigg2019-10-041-2/+2
| | | | PiperOrigin-RevId: 272851237
* Add fpext and fptrunc to the Standard dialect and includes conversion to LLVMMLIR Team2019-10-031-3/+13
| | | | PiperOrigin-RevId: 272768027
OpenPOWER on IntegriCloud