This is an archive of the discontinued LLVM Phabricator instance.

[mlir] LLVM import: handle constant data and array/vector aggregates
ClosedPublic

Authored by ftynse on Jan 16 2020, 4:26 AM.

Details

Summary

Implement the handling of llvm::ConstantDataSequential and
llvm::ConstantAggregate for (nested) array and vector types when imporitng LLVM
IR to MLIR. In all cases, the result is a DenseElementsAttr that can be used in
either a llvm.mlir.global or a llvm.mlir.constant. Nested aggregates are
unpacked recursively until an element or a constant data is found. Nested
arrays with innermost scalar type are represented as DenseElementsAttr of
tensor type. Nested arrays with innermost vector type are represented as
DenseElementsAttr with (multidimensional) vector type.

Constant aggregates of struct type are not yet supported as the LLVM dialect
does not have a well-defined way of modeling struct-type constants.

Diff Detail

Event Timeline

ftynse created this revision.Jan 16 2020, 4:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 16 2020, 4:26 AM

Unit tests: pass. 61913 tests passed, 0 failed and 783 were skipped.

clang-tidy: unknown.

clang-format: pass.

Build artifacts: diff.json, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
254

How about LLVM struct?

ftynse marked an inline comment as done.Jan 16 2020, 7:27 AM
ftynse added inline comments.
mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
254

We don't have a well-defined way of representing constants of struct type in the dialect. Since this code asserts (or even crashes) on unsupported inputs, I added an assert as well. The follow up (D72839) will replace all asserts including this one by graceful error handling.

I could just report an error and return nullptr here, but it would crash two steps up in the call stack...

nicolasvasilache accepted this revision.Jan 27 2020, 6:49 AM
This revision is now accepted and ready to land.Jan 27 2020, 6:49 AM
This revision was automatically updated to reflect the committed changes.