[PATCH] D103958: [WIP] Support MustControl conditional control attribute

Marco Elver via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 9 05:39:25 PDT 2021


melver created this revision.
Herald added subscribers: dexonsmith, jfb, hiraditya.
Herald added a reviewer: aaron.ballman.
melver requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, jdoerfert.
Herald added projects: clang, LLVM.

[ WIP, only high-level comments for now ]

Introduce a new attribute, 'MustControl'/'mustcontrol', which denotes that a
conditional control statement must result in true control-flow and not
be optimized away. The attribute otherwise has no semantic relevance.

However, the existence of a true branch is of relevance when branch
execution has side-effects on machine state that the programmer is
interested in, for example in OS kernels.

The Linux kernel, for one, relies on the existence of true conditional
branches for the enforcement of memory orders, per Linux-kernel memory
consistency model (LKMM) [1]. With the 'mustcontrol' attribute, Clang
would provide a primitive required for the Linux kernel to ensure a true
branch is emitted without resorting to inline assembly (which often
results in poor codegen). The primitive is simple and low-level enough,
that the compiler can remain blissfully unaware of the LKMM and leave
the semantics of Linux's memory model to the kernel community.

[1] https://lkml.kernel.org/r/YLn8dzbNwvqrqqp5@hirez.programming.kicks-ass.net


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103958

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/test/CodeGenCXX/attr-mustcontrol.cpp
  llvm/include/llvm/IR/FixedMetadataKinds.def
  llvm/include/llvm/IR/IRBuilder.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/IR/MDBuilder.h
  llvm/lib/CodeGen/BranchFolding.cpp
  llvm/lib/IR/IRBuilder.cpp
  llvm/lib/IR/MDBuilder.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103958.350865.patch
Type: text/x-patch
Size: 15512 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210609/9ddd00ac/attachment.bin>


More information about the llvm-commits mailing list