Page MenuHomePhabricator

[mlir] speed up construction of LLVM IR constants when possible
ClosedPublic

Authored by ftynse on Sep 2 2021, 6:01 AM.

Details

Summary

The translation to LLVM IR used to construct sequential constants by recurring
down to individual elements, creating constant values for them, and wrapping
them into aggregate constants in post-order. This is highly inefficient for
large constants with known data such as DenseElementsAttr. Use LLVM's
ConstantData for the innermost dimension instead. LLVM does seem to support
data constants for nested sequential constants so the outer dimensions are
still handled recursively. Nevertheless, this speeds up the translation of
large constants with equal dimensions by up to 30x.

Users are advised to rewrite large constants to use flat types before
translating to LLVM IR if more efficiency in translation is necessary. This is
not done automatically as the translation is not aware of the expectations of
the overall compilation flow about type changes and indexing, in particular for
global constants with external linkage.

Diff Detail

Event Timeline

ftynse created this revision.Sep 2 2021, 6:01 AM
ftynse requested review of this revision.Sep 2 2021, 6:01 AM
silvas accepted this revision.Sep 2 2021, 11:23 AM

Awesome! Thanks!!!

This revision is now accepted and ready to land.Sep 2 2021, 11:23 AM