This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Use thread_local stack in LLVM dialect type parsing and printing
ClosedPublic

Authored by ftynse on Dec 22 2020, 9:15 AM.

Details

Summary

LLVM dialect type parsing and printing have been using a local stack object
forwarded between recursive functions responsible for parsing or printing
specific types. This stack is necessary to intercept (mutually) recursive
structure types and avoid inifinite recursion. This approach works only thanks
to the closedness of the LLVM dialect type system: types that don't belong to
the dialect are not allowed. Switch the approach to using a thread_local
stack inside the functions parsing the structure types. This makes the code
slightly cleaner by avoiding the need to pass the stack object around and, more
importantly, makes it possible to reconsider the closedness of the LLVM dialect
type system. As a nice side effect of this change, container LLVM dialect types
now support type aliases in their body (although it is currently impossible to
also use the alises when printing).

Depends On D93713

Diff Detail

Event Timeline

ftynse created this revision.Dec 22 2020, 9:15 AM
ftynse requested review of this revision.Dec 22 2020, 9:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 22 2020, 9:15 AM
mehdi_amini added inline comments.Dec 22 2020, 9:34 AM
mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp
60

I really don't like mutable global state in general.

If we really can't avoid it, please document extremely carefully the invariant around it.

Ideally we should also be able to check the invariants with assertions.

ftynse updated this revision to Diff 314618.Jan 5 2021, 8:03 AM

Address review

ftynse added inline comments.Jan 5 2021, 8:04 AM
mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp
60

Added more documentation and an assertion. We may want to move this into DialectAsmPrinter/Parser since at least SPIR-V has a similar need, but I haven't put enough thinking into how to do that, yet.

mehdi_amini accepted this revision.Jan 5 2021, 10:08 AM
mehdi_amini added inline comments.
mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp
336

Assert looks great :)

This revision is now accepted and ready to land.Jan 5 2021, 10:08 AM