[all-commits] [llvm/llvm-project] 639890: Extend the `uwtable` attribute with unwind table kind

Momchil Velikov via All-commits all-commits at lists.llvm.org
Mon Feb 14 06:35:38 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 6398903ac8c141820a84f3063b7956abe1742500
      https://github.com/llvm/llvm-project/commit/6398903ac8c141820a84f3063b7956abe1742500
  Author: Momchil Velikov <momchil.velikov at arm.com>
  Date:   2022-02-14 (Mon, 14 Feb 2022)

  Changed paths:
    M clang/lib/CodeGen/CGExpr.cpp
    M clang/lib/CodeGen/CodeGenModule.cpp
    M clang/test/CodeGen/asan-globals.cpp
    A clang/test/CodeGen/uwtable-attr.c
    M llvm/bindings/go/llvm/ir_test.go
    M llvm/docs/LangRef.rst
    M llvm/include/llvm/AsmParser/LLParser.h
    M llvm/include/llvm/AsmParser/LLToken.h
    M llvm/include/llvm/IR/Attributes.h
    M llvm/include/llvm/IR/Attributes.td
    M llvm/include/llvm/IR/Function.h
    M llvm/include/llvm/IR/Module.h
    M llvm/include/llvm/Support/CodeGen.h
    M llvm/lib/AsmParser/LLLexer.cpp
    M llvm/lib/AsmParser/LLParser.cpp
    M llvm/lib/Bitcode/Reader/BitcodeReader.cpp
    M llvm/lib/CodeGen/MachineOutliner.cpp
    M llvm/lib/IR/AttributeImpl.h
    M llvm/lib/IR/Attributes.cpp
    M llvm/lib/IR/Function.cpp
    M llvm/lib/IR/Module.cpp
    A llvm/test/Assembler/uwtable-1.ll
    A llvm/test/Assembler/uwtable-2.ll
    M llvm/test/Bitcode/attributes.ll
    M llvm/test/CodeGen/Thumb2/pacbti-m-outliner-1.ll
    M llvm/test/CodeGen/Thumb2/pacbti-m-outliner-3.ll
    M llvm/test/Instrumentation/AddressSanitizer/module-flags.ll
    M llvm/test/Transforms/Attributor/ArgumentPromotion/X86/attributes.ll
    M llvm/test/Transforms/Attributor/ArgumentPromotion/X86/min-legal-vector-width.ll
    M llvm/test/Transforms/Attributor/align.ll
    M llvm/test/Transforms/Attributor/allow_list.ll
    M llvm/test/Transforms/Attributor/cb_liveness_disabled.ll
    M llvm/test/Transforms/Attributor/cb_liveness_enabled.ll
    M llvm/test/Transforms/Attributor/internal-noalias.ll
    M llvm/test/Transforms/Attributor/liveness.ll
    M llvm/test/Transforms/Attributor/nocapture-2.ll
    M llvm/test/Transforms/Attributor/nofree.ll
    M llvm/test/Transforms/Attributor/noreturn.ll
    M llvm/test/Transforms/Attributor/nosync.ll
    M llvm/test/Transforms/Attributor/returned.ll
    M llvm/test/Transforms/Attributor/value-simplify-pointer-info.ll
    M llvm/test/Transforms/Attributor/willreturn.ll
    M llvm/test/Transforms/FunctionAttrs/atomic.ll
    M llvm/test/Transforms/FunctionAttrs/nofree-attributor.ll
    M llvm/test/Transforms/FunctionAttrs/nofree.ll
    M llvm/test/Transforms/FunctionAttrs/nosync.ll
    M llvm/test/Transforms/GCOVProfiling/module-flags.ll
    M llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/check_attrs.ll.funcattrs.expected
    M llvm/unittests/IR/VerifierTest.cpp

  Log Message:
  -----------
  Extend the `uwtable` attribute with unwind table kind

We have the `clang -cc1` command-line option `-funwind-tables=1|2` and
the codegen option `VALUE_CODEGENOPT(UnwindTables, 2, 0) ///< Unwind
tables (1) or asynchronous unwind tables (2)`. However, this is
encoded in LLVM IR by the presence or the absence of the `uwtable`
attribute, i.e.  we lose the information whether to generate want just
some unwind tables or asynchronous unwind tables.

Asynchronous unwind tables take more space in the runtime image, I'd
estimate something like 80-90% more, as the difference is adding
roughly the same number of CFI directives as for prologues, only a bit
simpler (e.g. `.cfi_offset reg, off` vs. `.cfi_restore reg`). Or even
more, if you consider tail duplication of epilogue blocks.
Asynchronous unwind tables could also restrict code generation to
having only a finite number of frame pointer adjustments (an example
of *not* having a finite number of `SP` adjustments is on AArch64 when
untagging the stack (MTE) in some cases the compiler can modify `SP`
in a loop).
Having the CFI precise up to an instruction generally also means one
cannot bundle together CFI instructions once the prologue is done,
they need to be interspersed with ordinary instructions, which means
extra `DW_CFA_advance_loc` commands, further increasing the unwind
tables size.

That is to say, async unwind tables impose a non-negligible overhead,
yet for the most common use cases (like C++ exceptions), they are not
even needed.

This patch extends the `uwtable` attribute with an optional
value:
      -  `uwtable` (default to `async`)
      -  `uwtable(sync)`, synchronous unwind tables
      -  `uwtable(async)`, asynchronous (instruction precise) unwind tables

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D114543




More information about the All-commits mailing list