This is an archive of the discontinued LLVM Phabricator instance.

[mlir] take LLVMContext in MLIR-to-LLVM-IR translation
ClosedPublic

Authored by ftynse on Aug 6 2020, 9:30 AM.

Details

Summary

Due to the original type system implementation, LLVMDialect in MLIR contains an
LLVMContext in which the relevant objects (types, metadata) are created. When
an MLIR module using the LLVM dialect (and related intrinsic-based dialects
NVVM, ROCDL, AVX512) is converted to LLVM IR, it could only live in the
LLVMContext owned by the dialect. The type system no longer relies on the
LLVMContext, so this limitation can be removed. Instead, translation functions
now take a reference to an LLVMContext in which the LLVM IR module should be
constructed. The caller of the translation functions is responsible for
ensuring the same LLVMContext is not used concurrently as the translation no
longer uses a dialect-wide context lock.

As an additional bonus, this change removes the need to recreate the LLVM IR
module in a different LLVMContext through printing and parsing back, decreasing
the compilation overhead in JIT and GPU-kernel-to-blob passes.

Diff Detail

Event Timeline

ftynse created this revision.Aug 6 2020, 9:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 6 2020, 9:30 AM
ftynse requested review of this revision.Aug 6 2020, 9:30 AM
mehdi_amini accepted this revision.Aug 6 2020, 9:42 AM

Nice! I'm so glad to see this change :)

What state is still present in the dialect after this?

This revision is now accepted and ready to land.Aug 6 2020, 9:42 AM
ftynse added a comment.Aug 6 2020, 9:45 AM

What state is still present in the dialect after this?

A follow-up commit removes the context and the module, and only keeps an llvm::DataLayout. We need a proper model for that in MLIR before we can remove it completely, but we can move it from dialect to module as an intermediate step after a minor refactoring in LLVM.

rriddle accepted this revision.Aug 6 2020, 11:24 AM
rriddle added inline comments.
mlir/include/mlir/Target/ROCDLIR.h
18

Can we trim the context include here?

ftynse updated this revision to Diff 283874.Aug 7 2020, 5:14 AM

Address review

This revision was landed with ongoing or failed builds.Aug 7 2020, 5:22 AM
This revision was automatically updated to reflect the committed changes.