347 Commits

Author SHA1 Message Date
Tung D. Le
095e6ac9fd [mlir] Fix memory explosion when converting global variable bodies in ModuleTranslation
There is memory explosion when converting the body or initializer region of a large global variable, e.g. a constant array.

For example, when translating a constant array of 100000 strings:
```
llvm.mlir.global internal constant @cats_strings() {addr_space = 0 : i32, alignment = 16 : i64} : !llvm.array<100000 x ptr<i8>> {
    %0 = llvm.mlir.undef : !llvm.array<100000 x ptr<i8>>
    %1 = llvm.mlir.addressof @om_1 : !llvm.ptr<array<1 x i8>>
    %2 = llvm.getelementptr %1[0, 0] : (!llvm.ptr<array<1 x i8>>) -> !llvm.ptr<i8>
    %3 = llvm.insertvalue %2, %0[0] : !llvm.array<100000 x ptr<i8>>
    %4 = llvm.mlir.addressof @om_2 : !llvm.ptr<array<1 x i8>>
    %5 = llvm.getelementptr %4[0, 0] : (!llvm.ptr<array<1 x i8>>) -> !llvm.ptr<i8>
    %6 = llvm.insertvalue %5, %3[1] : !llvm.array<100000 x ptr<i8>>
    %7 = llvm.mlir.addressof @om_3 : !llvm.ptr<array<1 x i8>>
    %8 = llvm.getelementptr %7[0, 0] : (!llvm.ptr<array<1 x i8>>) -> !llvm.ptr<i8>
    %9 = llvm.insertvalue %8, %6[2] : !llvm.array<100000 x ptr<i8>>
    %10 = llvm.mlir.addressof @om_4 : !llvm.ptr<array<1 x i8>>
    %11 = llvm.getelementptr %10[0, 0] : (!llvm.ptr<array<1 x i8>>) -> !llvm.ptr<i8>
    %12 = llvm.insertvalue %11, %9[3] : !llvm.array<100000 x ptr<i8>>

    ... (ignore the remaining part)
}
```

where `@om_1`, `@om_2`, ... are string global constants.

Each time an operation is converted to LLVM, a new constant is created.
When it comes to `llvm.insertvalue`, a new constant array of 100000 elements is created and the old constant array (input) is not destroyed.
This causes memory explosion. We observed that, on a system with 128 GB memory, the translation of 100000 elements got killed due to using up all the memory.
On a system with 64 GB, 65536 elements was enough to cause the translation killed.

This patch fixes the issue by checking generated constants and destroyed them if there is no use.
By the fix, the translation of 100000 elements only takes about 1.6 GB memory, and finishes without any error.

Reviewed By: ftynse, kiranchandramohan

Differential Revision: https://reviews.llvm.org/D148487
2023-05-16 10:37:33 +00:00
Christian Ulmann
794b58b467 [IR] Drop const in DILocation::getMergedLocation
This commit removes constness from DILocation::getMergedLocation and
fixes all its users accordingly.

Having constness on the parameters forced the return type to be const
as well, which does force usage of `const_cast` when the location needs
to be used in metadata nodes.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D149942
2023-05-15 07:21:43 +00:00
Tres Popp
5550c82189 [mlir] Move casting calls from methods to function calls
The MLIR classes Type/Attribute/Operation/Op/Value support
cast/dyn_cast/isa/dyn_cast_or_null functionality through llvm's doCast
functionality in addition to defining methods with the same name.
This change begins the migration of uses of the method to the
corresponding function call as has been decided as more consistent.

Note that there still exist classes that only define methods directly,
such as AffineExpr, and this does not include work currently to support
a functional cast/isa call.

Caveats include:
- This clang-tidy script probably has more problems.
- This only touches C++ code, so nothing that is being generated.

Context:
- https://mlir.llvm.org/deprecation/ at "Use the free function variants
  for dyn_cast/cast/isa/…"
- Original discussion at https://discourse.llvm.org/t/preferred-casting-style-going-forward/68443

Implementation:
This first patch was created with the following steps. The intention is
to only do automated changes at first, so I waste less time if it's
reverted, and so the first mass change is more clear as an example to
other teams that will need to follow similar steps.

Steps are described per line, as comments are removed by git:
0. Retrieve the change from the following to build clang-tidy with an
   additional check:
   https://github.com/llvm/llvm-project/compare/main...tpopp:llvm-project:tidy-cast-check
1. Build clang-tidy
2. Run clang-tidy over your entire codebase while disabling all checks
   and enabling the one relevant one. Run on all header files also.
3. Delete .inc files that were also modified, so the next build rebuilds
   them to a pure state.
4. Some changes have been deleted for the following reasons:
   - Some files had a variable also named cast
   - Some files had not included a header file that defines the cast
     functions
   - Some files are definitions of the classes that have the casting
     methods, so the code still refers to the method instead of the
     function without adding a prefix or removing the method declaration
     at the same time.

```
ninja -C $BUILD_DIR clang-tidy

run-clang-tidy -clang-tidy-binary=$BUILD_DIR/bin/clang-tidy -checks='-*,misc-cast-functions'\
               -header-filter=mlir/ mlir/* -fix

rm -rf $BUILD_DIR/tools/mlir/**/*.inc

git restore mlir/lib/IR mlir/lib/Dialect/DLTI/DLTI.cpp\
            mlir/lib/Dialect/Complex/IR/ComplexDialect.cpp\
            mlir/lib/**/IR/\
            mlir/lib/Dialect/SparseTensor/Transforms/SparseVectorization.cpp\
            mlir/lib/Dialect/Vector/Transforms/LowerVectorMultiReduction.cpp\
            mlir/test/lib/Dialect/Test/TestTypes.cpp\
            mlir/test/lib/Dialect/Transform/TestTransformDialectExtension.cpp\
            mlir/test/lib/Dialect/Test/TestAttributes.cpp\
            mlir/unittests/TableGen/EnumsGenTest.cpp\
            mlir/test/python/lib/PythonTestCAPI.cpp\
            mlir/include/mlir/IR/
```

Differential Revision: https://reviews.llvm.org/D150123
2023-05-12 11:21:25 +02:00
Christian Ulmann
62d7d94c2e [mlir][LLVM] Support locations in loop annotation
This commit introduces support for locations as part of the loop
annotation attribute. These locations indicate the start and the end of
the loop.

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D149858
2023-05-05 07:54:22 +00:00
Andrew Gozillon
f478721231 [MLIR][LLVM] Add accessor for LLVMModule and invoke convertDialectAttributes on GlobalOps
This patch seeks to do two things add an accessor method to
retrieve the ModuleTranslations contained LLVM Module for direct
usage by dialects that are being lowered to LLVM-IR. One particular
use case for this is in the OpenMP Dialect, when interfacing
with the OMPIRBuilder in certain cases it is useful to be able
to access the LLVM Module directly.

The second is invoking convertDialectAttributes on GlobalOp's
so as to be able to lower dialect specific attributes that are
applied or lowered onto GlobalOp's.

Reviewers: ftynse

Differential Revision: https://reviews.llvm.org/D149279
2023-04-27 14:51:54 -05:00
Jan Sjodin
d3f9388ffb [OpenMP][Flang][MLIR] Add lowering of TargetOp for host codegen to LLVM-IR
This patch adds lowering of TargetOps for the host. The lowering outlines the
target region function and uses the OpenMPIRBuilder support functions to emit
the function and call. Code generation for offloading will be done in later
patches.

Reviewed By: kiranchandramohan, jdoerfert, agozillon

Differential Revision: https://reviews.llvm.org/D147172
2023-04-26 12:51:31 -04:00
Rahul Kayaith
8db947da0b [mlir] Make ElementsAttr inherit from TypedAttr
This allows implicit conversion from `ElementsAttr` to `TypedAttr`, but
required renaming the `ElementsAttr::getType()` interface method to
`getShapedType`.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D148492
2023-04-20 16:31:53 -04:00
Tobias Gysi
9d69bca187 [mlir] Add stack alignment to the data layout dialect.
The revision adds the stack alignment to the
data layout dialect and it extends the LLVM dialect
import and export to support the new data layout
entry.

One possible use case for the flag is the LLVM dialect
inliner. The LLVM inliner queries the flag to
determine if it is safe to update the alignment of an
existing alloca. We may want to perform the same
optimization inside of MLIR.

Reviewed By: Dinistro

Differential Revision: https://reviews.llvm.org/D147332
2023-04-03 06:58:37 +00:00
Tobias Gysi
56d94a90db [mlir][llvm] Add experimental alias scope decl intrinsic.
The revision adds the llvm.experimental.noalias.scope.decl intrinsic
to the LLVM dialect and updates the import and export accordingly.

Reviewed By: Dinistro

Differential Revision: https://reviews.llvm.org/D146504
2023-03-22 10:21:09 +01:00
Jan Sjodin
382eb7c2c7 [mlir] Add alloca address space handling to the data layout subsystem
This patch adds alloca address space information to the data layout interface
and implementation in the DLTI dialect. This is needed for targets that use
separate address spaces for local/stack data.

Reviewed By: ftynse, krzysz00

Differential Revision: https://reviews.llvm.org/D144657
2023-03-21 09:37:08 -04:00
Sergio Afonso
0e9523efda [mlir] Support lowering of dialect attributes attached to top-level modules
This patch supports the processing of dialect attributes attached to top-level
module-type operations during MLIR-to-LLVMIR lowering.

This approach modifies the `mlir::translateModuleToLLVMIR()` function to call
`ModuleTranslation::convertOperation()` on the top-level operation, after its
body has been lowered. This, in turn, will get the
`LLVMTranslationDialectInterface` object associated to that operation's dialect
before trying to use it for lowering prior to processing dialect attributes
attached to the operation.

Since there are no `LLVMTranslationDialectInterface`s for the builtin and GPU
dialects, which define their own module-type operations, this patch also adds
and registers them. The requirement for always calling
`mlir::registerBuiltinDialectTranslation()` before any translation of MLIR to
LLVM IR where builtin module operations are present is introduced. The purpose
of these new translation interfaces is to succeed when processing module-type
operations, allowing the lowering process to continue and to prevent the
introduction of failures related to not finding such interfaces.

Differential Revision: https://reviews.llvm.org/D145932
2023-03-21 12:54:26 +00:00
Jakub Kuderski
8c258fda1f [ADT][mlir][NFCI] Do not use non-const lvalue-refs with enumerate
Replace references to enumerate results with either result_pairs
(reference wrapper type) or structured bindings. I did not use
structured bindings everywhere as it wasn't clear to me it would
improve readability.

This is in preparation to the switch to zip semantics which won't
support non-const lvalue reference to elements:
https://reviews.llvm.org/D144503.

I chose to use values instead of const lvalue-refs because MLIR is
biased towards avoiding `const` local variables. This won't degrade
performance because currently `result_pair` is cheap to copy (size_t
+ iterator), and in the future, the enumerator iterator dereference
will return temporaries anyway.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D146006
2023-03-15 10:43:56 -04:00
Christian Ulmann
6628767e47 [mlir][llvm] Add visibility attribute
This commit introduces the LLVM's visibility attribute and adds it to
both globals and functions.

Furthermore, this commit ensures that "thread_local" is printed in the
correct place and adds a test for that.

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D145790
2023-03-12 10:31:29 +01:00
Tobias Gysi
2ea6bb645e [mlir][llvm] Use interfaces in the translation to LLVMIR.
The revision consistently uses the AliasAnalysisOp and AccessGroupOp
interfaces in the translation from MLIR to LLVMIR. It thus drops the
last string based lookups of alias scope and access group attributes.

Depends on D144851

Reviewed By: Dinistro

Differential Revision: https://reviews.llvm.org/D145037
2023-03-02 13:00:57 +01:00
Tobias Gysi
edfefd7fc5 [mlir][llvm] Add AliasAnalysis and AccessGroup interfaces.
The revision introduces two interfaces that provide access to
the alias analysis and access group metadata attributes. The
AliasAnalysis interface combines all alias analysis related
attributes (alias, noalias, and tbaa) similar to LLVM's getAAMetadata
method, while the AccessGroup interface is dedicated to the
access group metadata.

Previously, only the load and store operations supported alias analysis
and access group metadata. This revision extends this support to the
atomic operations. A follow up revision will also add support for the
memcopy, memset, and memove intrinsics. The interfaces then provide
convenient access to the metadata attributes and eliminate the need
of TypeSwitch or string based attribute access.

The revision still relies on string based attribute access for
the translation to LLVM IR (except for tbaa metadata). Only once
the the memory access intrinsics also implement the new interfaces,
the translation to LLVM IR can be fully switched to use interface
based attribute accesses.

Depends on D144875

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D144851
2023-03-01 09:27:06 +01:00
Christian Ulmann
87a0479538 [mlir][llvm] Fuse access_group & loop export (NFC)
This commit moves the access group translation into the
LoopAnnotationTranslation class as these two metadata kinds only appear
together.

Drops the access group cleanup from `ModuleTranslation::forgetMapping`
as this is only used on function regions. Access groups only appear in the
region of a global metadata operation and will thus not be cleaned here.

Analogous to https://reviews.llvm.org/D143577

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D144253
2023-02-17 15:31:21 +01:00
Christian Ulmann
d94399c641 [mlir][llvm] Make LoopAnnotations non-discardable
This commit adds the loop annotation attribute to LLVM::Br and
LLVM::CondBr to ensure it is non-discardable. Furthermore, the name is
changed from "llvm.loop" to "loop-annotation".

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D143986
2023-02-14 15:16:05 +01:00
Alex Zinenko
8c7cfa3572 [mlir] fix LLVM IR translation of vector<... x index>
When the translation was written, `vector<... x index>` was not allowed
at all. After it was added later, the translation was never adapted. It
kept working in the most common case of index-typed attributes using
64-bit storage and being converted to 64-bit integers in LLVM IR, but
not in the other cases that require truncation or extension, producing
wrong results when using the raw data storage of the dense attrbute to
construct the LLVM IR constant. When the storage size doesn't match,
fall back to the per-element constant construction, which is slower but
handles bitwidth differences correctly.

Fixes #60614.

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D143993
2023-02-14 10:42:56 +00:00
Tobias Gysi
bfea837676 [mlir][llvm] Reintroduce string based attribute setting.
Reintroduce string based attribute setting in the
translation from LLVM dialect to LLVM IR. The TypeSwitch
based implementation introduced in
https://reviews.llvm.org/D143654  does not work for
intrinsics that set the requiresAccessGroup or
requiresAliasScope flag.

Reviewed By: hgreving

Differential Revision: https://reviews.llvm.org/D143936
2023-02-14 08:09:58 +01:00
Tobias Gysi
fef08da4b7 [mlir][llvm] Store memory op metadata using op attributes.
The revision introduces operation attributes to store tbaa metadata on
load and store operations rather than relying using dialect attributes.
At the same time, the change also ensures the provided getters and
setters instead are used instead of a string based lookup. The latter
is done for the tbaa, access groups, and alias scope attributes.

The goal of this change is to ensure the metadata attributes are only
placed on operations that have the corresponding operation attributes.
This is imported since only these operations later on translate these
attributes to LLVM IR. Dialect attributes placed on other operations
are lost during the translation.

Reviewed By: vzakhari, Dinistro

Differential Revision: https://reviews.llvm.org/D143654
2023-02-10 15:27:25 +01:00
Christian Ulmann
889a11783e [mlir][llvm] Add structured loop metadata
This commit introduces a structured representation of loop metadata to
the LLVM dialect. This attribute explicitly models all known `!llvm.loop`
metadata fields and groups them by introducing nested attributes for each
namespace.

The new attribute replaces the LoopOptionAttr that could only model a
limited subset of loop metadata.

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D143064
2023-02-03 08:57:30 +01:00
Christian Ulmann
5212058405 Reland "[mlir][LLVM] Add all LLVM parameter attributes"
This change was reverted because it introduced a linking issue due to
duplicated symbols. Making sure that the detail helper only has a static
header implementation fixes this issue.

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D142635
2023-01-31 09:11:02 +01:00
Christian Ulmann
bd0c809209 Revert "[mlir][LLVM] Add all LLVM parameter attributes"
This reverts commit 54941942c82f3a1640d50c0e354d29a3cf5535f6.

The commit introduced a linking error in flang.
2023-01-30 09:38:00 +01:00
Christian Ulmann
54941942c8 [mlir][LLVM] Add all LLVM parameter attributes
This commit adds name accessors and verifiers for all LLVM parameter
attributes excluding the swift specific ones to the LLVM dialect.
Additionally, these attributes are now also imported and exported.

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D142635
2023-01-30 08:51:03 +01:00
Christian Ulmann
be4b87353e [mlir][LLVM] Add param attr verifiers
This commit introduces unified parameter attribute verifiers to the LLVM
dialect and removes according checks in the export. As LLVM does not
verify the validity of certain attributes on return values, this commit
unifies the handling of argument and result attributes wherever possible.

Depends on D142212

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D142372
2023-01-25 15:04:45 +01:00
Christian Ulmann
9b9cfe77a5 [mlir][LLVM] Replace readnone with memory effects
This commit introduces LLVM's `MemoryEffects` attribute and replaces the
deprecated usage of `llvm.readnone` in the LLVM dialect.
The absence of the attribute on a `LLVMFuncOp` implies that it might
access all kinds of memory. This semantic corresponds to `llvm::Function`'s
behaviour.

Depends on D142002

Differential Revision: https://reviews.llvm.org/D142013
2023-01-19 11:50:04 +01:00
Slava Zakharin
406800cbfe [mlir] Fixed memory leak after D141726.
Reported in https://lab.llvm.org/buildbot/#/builders/5/builds/30788

Differential Revision: https://reviews.llvm.org/D141985
2023-01-17 21:34:46 -08:00
Slava Zakharin
b3d8639f35 [mlir][llvmir] Fixed MDNode uniquing during TBAA translation.
In the process of creating the MDNodes for the TBAA tag operations
we used to produce incomplete MDNodes like:
```
  @__tbaa::@tbaa_tag_4 => !{!null, !null, i64 0}
  @__tbaa::@tbaa_tag_7 => !{!null, !null, i64 0}
```
This caused the two tags to map to the same incomplete MDNode due to uniquing.
To prevent this, we have to use temporary MDNodes instead of !null's.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D141726
2023-01-16 12:38:31 -08:00
Hendrik Greving
37c750a5fd [mlir:LLVM] Fix minor bug, missing cconv translation
Fixes translating the calling convention to LLVM-IR, possibly missed
by https://reviews.llvm.org/D126161, and adds a test.
2023-01-16 12:18:28 -08:00
Kazu Hirata
0a81ace004 [mlir] Use std::optional instead of llvm::Optional (NFC)
This patch replaces (llvm::|)Optional< with std::optional<.  I'll post
a separate patch to remove #include "llvm/ADT/Optional.h".

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-14 01:25:58 -08:00
Kazu Hirata
a1fe1f5f77 [mlir] Add #include <optional> (NFC)
This patch adds #include <optional> to those files containing
llvm::Optional<...> or Optional<...>.

I'll post a separate patch to actually replace llvm::Optional with
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-13 21:05:06 -08:00
Slava Zakharin
2f66c89130 [mlir] Support TBAA metadata in LLVMIR dialect.
This change introduces new LLVMIR dialect operations to represent
TBAA root, type descriptor and access tag metadata nodes.

For the purpose of importing TBAA metadata from LLVM IR it only
supports the current version of TBAA format described in
https://llvm.org/docs/LangRef.html#tbaa-metadata (i.e. size-aware
representation introduced in D41501 is not supported).

TBAA attribute support is only added for LLVM::LoadOp and LLVM::StoreOp.
Support for intrinsics operations (e.g. LLVM::MemcpyOp) may be added later.

The TBAA attribute is represented as an array of access tags, though,
LLVM IR supports only single access tag per memory accessing instruction.
I implemented it as an array anticipating similar support in LLVM IR
to combine TBAA graphs with different roots for Flang - one of the options
described in https://docs.google.com/document/d/16kKZVmI585wth01VSaJAqZMZpoX68rcdBmgfj0kNAt0/edit#heading=h.jzzheaz9vqac

It should be easy to restrict MLIR operation to a single access tag,
if we end up using a different approach for Flang.

Differential Revision: https://reviews.llvm.org/D140768
2023-01-06 11:16:31 -08:00
Christian Ulmann
b72dd6f775 [mlir] Add function_entry_count to LLVMFuncOp
This commit introduces the function_entry_count metadata field to the
LLVMFuncOp and adds both the corresponding import and export
funtionalities.
The import of the function metadata uses the same infrastructure as the
instruction metadata, i.e., it dispatches through a dialect interface.

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D141001
2023-01-05 13:40:56 +01:00
Ramkumar Ramachandra
22426110c5 mlir/tblgen: use std::optional in generation
This is part of an effort to migrate from llvm::Optional to
std::optional. This patch changes the way mlir-tblgen generates .inc
files, and modifies tests and documentation appropriately. It is a "no
compromises" patch, and doesn't leave the user with an unpleasant mix of
llvm::Optional and std::optional.

A non-trivial change has been made to ControlFlowInterfaces to split one
constructor into two, relating to a build failure on Windows.

See also: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Signed-off-by: Ramkumar Ramachandra <r@artagnon.com>

Differential Revision: https://reviews.llvm.org/D138934
2022-12-17 11:13:26 +01:00
Guray Ozen
359c064da7 [mlir] Support llvm.readonly attribute on llvm pointers
The attribute is translated into LLVM's function attribute 'readonly'. The attribute can be only used for pointers.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D139641
2022-12-09 10:36:59 +01:00
Kazu Hirata
1a36588ec6 [mlir] Use std::nullopt instead of None (NFC)
This patch mechanically replaces None with std::nullopt where the
compiler would warn if None were deprecated.  The intent is to reduce
the amount of manual work required in migrating from Optional to
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-03 18:50:27 -08:00
Slava Zakharin
29016d2830 [mlir][llvmir] Translate function result attributes to LLVM IR.
Translate align, noalias, noundef, signext and zeroext result
attributes from llvm.func to LLVM IR.

This is needed for https://github.com/llvm/llvm-project/issues/58579

Differential Revision: https://reviews.llvm.org/D137049
2022-11-18 12:03:42 -08:00
Slava Zakharin
6f04011f15 [mlir][llvmir] Add support for llvm.signext/zeroext function attributes.
This change-set adds basic support for llvm.signext and llvm.zeroext
attributes, and makes sure that the attributes are translated to LLVM IR
when attached to arguments.

This is needed for https://github.com/llvm/llvm-project/issues/58579

Differential Revision: https://reviews.llvm.org/D137048
2022-11-03 09:19:02 -07:00
Slava Zakharin
473d001152 [mlir][llvmir] Convert attributes for functions without bodies.
So far the function argument attributes were only translated
for functions with bodies. This change makes sure that this
happens for functions without bodies (declarations) as well.

This is needed for https://github.com/llvm/llvm-project/issues/58579

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D137047
2022-11-03 08:52:19 -07:00
River Riddle
9af92ed8a0 [mlir:LLVM] Rewrite the LLVMIR export to use the debug info attributes
This has been a long standing TODO, and actually enables users to generate
debug information for LLVM using the LLVM dialect; as opposed to our
dummy placeholder that generated just enough for line table information.

Differential Revision: https://reviews.llvm.org/D136543
2022-10-24 22:31:41 -07:00
rkayaith
ed90f8026e [mlir-translate] Support parsing operations other than 'builtin.module' as top-level
This adds a '--no-implicit-module' option, which disables the insertion
of a top-level 'builtin.module' during parsing.

The translation APIs are also updated to take/return 'Operation*'
instead of 'ModuleOp', to allow other operation types to be used. To
simplify translations which are restricted to specific operation types,
'TranslateFromMLIRRegistration' has an overload which performs the
necessary cast and error checking.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D134237
2022-10-21 15:54:06 -04:00
Nikita Popov
87549e61da [LLVMIR] Use helper methods to set/check readnone attribute (NFC)
This makes the code forward-compatible to the memory attribute.
2022-10-21 16:23:52 +02:00
Victor Perez
70e3f0e10e [mlir][llvm] Handle llvm.noundef attribute when converting to LLVM IR
Translate LLVMIR llvm.noundef attribute to its equivalent in LLVM IR.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D136324
2022-10-20 12:59:47 +01:00
rkayaith
aa00e3e6c1 [mlir][llvm] Support pointer entries in data layout translation
This adds support for pointer DLTI entries in LLVMIR export, e.g.
```
// translated to: p0:32:64:128
#dlti.dl_entry<!llvm.ptr, dense<[32,64,128]> : vector<3xi32>>
// translated to: p1:32:32:32:64
#dlti.dl_entry<!llvm.ptr<1>, dense<[32,32,32,64]> : vector<4xi32>>
```

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D133434
2022-09-21 11:16:15 -04:00
Alexander Batashev
79c2094881 [mlir][LLVMIR] Parse some type attributes for LLVM function parameters
With the transition to opaque pointers, type information has been
transferred to function parameter attributes. This patch adds correct
parsing for some of those arguments and fixes some tests, that
previously used UnitAttr for those.

Differential Revision: https://reviews.llvm.org/D132366
2022-08-25 11:06:51 +03:00
Slava Zakharin
13cb085ca1 [mlir] Support llvm.readnone attribute for all FunctionOpInterface ops.
The attribute is translated into LLVM's function attribute 'readnone'.
There is no explicit verification regarding conflicting 'readnone'
and function attributes from 'passthrough', though, LLVM would assert
if they are incompatible during LLVM IR creation.

Differential Revision: https://reviews.llvm.org/D131457
2022-08-24 10:12:37 -07:00
Mehdi Amini
d04c2b2fd9 Revert "[MLIR] Generic 'malloc', 'aligned_alloc' and 'free' functions"
This reverts commit 3e21fb616d9a1b29bf9d1a1ba484add633d6d5b3.

A lot of integration tests are failing on the bot.
2022-07-18 18:07:36 +00:00
Michele Scuttari
3e21fb616d [MLIR] Generic 'malloc', 'aligned_alloc' and 'free' functions
When converted to the LLVM dialect, the memref.alloc and memref.free operations were generating calls to hardcoded 'malloc' and 'free' functions. This didn't leave any freedom to users to provide their custom implementation. Those operations now convert into calls to '_mlir_alloc' and '_mlir_free' functions, which have also been implemented into the runtime support library as wrappers to 'malloc' and 'free'. The same has been done for the 'aligned_alloc' function.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D128791
2022-07-18 17:58:58 +02:00
Kazu Hirata
5605a1eedd Use drop_begin (NFC) 2022-07-15 23:58:11 -07:00
Kazu Hirata
c27d815249 [mlir] Use value instead of getValue (NFC) 2022-07-14 00:19:59 -07:00