[PATCH] D132352: Introduce noread_thread_id to address the thread identification problem in coroutines

Chuanqi Xu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 22 01:12:06 PDT 2022


ChuanqiXu created this revision.
ChuanqiXu added reviewers: nhaehnle, jyknight, nikic, rjmccall, efriedma, fhahn, ychen.
ChuanqiXu added a project: LLVM.
Herald added subscribers: jeroen.dobbelaere, wenlei, okura, jdoerfert, kuter, hiraditya, arichardson.
Herald added a project: All.
ChuanqiXu requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: sstefan1.
Herald added subscribers: llvm-commits, cfe-commits, sstefan1.
Herald added a project: clang.

This implements the suggested solution from @nhaehnle, @jyknight and @fhahn (who prefer this than D127383 <https://reviews.llvm.org/D127383>). The suggested solution is described in: https://discourse.llvm.org/t/address-thread-identification-problems-with-coroutine/62015/48. Here is the referenced solutions:

1. Introduce new attribute noread_thread_id
2. Emit noread_thread_id in addition to readnone in the frontend for functions that are known to not read the thread ID implicitly or explicitly.
3. Mark the TLS intrinsic as only as readnone.
4. Many checks for hasAttribute(ReadNone) (e.g. to guard CSE) have to become hasAttribute(ReadNone) && (!isCoroutine(CurrentFn) || !hasAttribute(NoReadThreadID). Though, note that this isn’t the first time that happens. For example, we have a bunch of places that need to check hasAttribute(ReadNone) && !hasAttribute(Convergent). So there’s precedent.

And the patch doesn't implement the 2ed and 4th solutions completely, I think we could complete them step by step since we lack enough tests now. The decision may be a little bit painful but I think it would be more stable.

Test Plans: check-all, https://godbolt.org/z/TGcPPP57K, https://godbolt.org/z/TGcPPP57K, folly and out internal projects.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132352

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/asm-attrs.c
  clang/test/CodeGen/builtin-sqrt.c
  clang/test/CodeGen/libcalls.c
  llvm/docs/LangRef.rst
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/Attributes.td
  llvm/include/llvm/IR/InstrTypes.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/Transforms/Scalar/EarlyCSE.cpp
  llvm/lib/Transforms/Scalar/GVN.cpp
  llvm/lib/Transforms/Scalar/NewGVN.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/test/Analysis/BasicAA/cs-cs.ll
  llvm/test/Analysis/BasicAA/intrinsics.ll
  llvm/test/Analysis/TypeBasedAliasAnalysis/functionattrs.ll
  llvm/test/Analysis/TypeBasedAliasAnalysis/intrinsics.ll
  llvm/test/Assembler/aarch64-intrinsics-attributes.ll
  llvm/test/Bindings/llvm-c/debug_info.ll
  llvm/test/Bitcode/compatibility-3.6.ll
  llvm/test/Bitcode/compatibility-3.7.ll
  llvm/test/Bitcode/compatibility-3.8.ll
  llvm/test/Bitcode/compatibility-3.9.ll
  llvm/test/Bitcode/compatibility-4.0.ll
  llvm/test/Bitcode/compatibility-5.0.ll
  llvm/test/Bitcode/compatibility-6.0.ll
  llvm/test/Bitcode/compatibility.ll
  llvm/test/Bitcode/upgrade-invariant-group-barrier.ll
  llvm/test/Feature/intrinsics.ll
  llvm/test/Instrumentation/MemorySanitizer/attributes.ll
  llvm/test/Other/invariant.group.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/X86/attributes.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/X86/min-legal-vector-width.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/X86/thiscall.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/pr33641_remove_arg_dbgvalue.ll
  llvm/test/Transforms/Attributor/dereferenceable-1.ll
  llvm/test/Transforms/Attributor/heap_to_stack.ll
  llvm/test/Transforms/Attributor/heap_to_stack_gpu.ll
  llvm/test/Transforms/Attributor/liveness.ll
  llvm/test/Transforms/Attributor/lowerheap.ll
  llvm/test/Transforms/Attributor/lvi-after-jumpthreading.ll
  llvm/test/Transforms/Attributor/memory_locations.ll
  llvm/test/Transforms/Attributor/noalias.ll
  llvm/test/Transforms/Attributor/nocapture-1.ll
  llvm/test/Transforms/Attributor/nofree.ll
  llvm/test/Transforms/Attributor/nonnull.ll
  llvm/test/Transforms/Attributor/norecurse.ll
  llvm/test/Transforms/Attributor/nosync.ll
  llvm/test/Transforms/Attributor/openmp_parallel.ll
  llvm/test/Transforms/Attributor/readattrs.ll
  llvm/test/Transforms/Attributor/value-simplify-assume.ll
  llvm/test/Transforms/Attributor/value-simplify-pointer-info.ll
  llvm/test/Transforms/Attributor/value-simplify.ll
  llvm/test/Transforms/Attributor/willreturn.ll
  llvm/test/Transforms/Coroutines/coro-readnone-01.ll
  llvm/test/Transforms/Coroutines/coro-readnone-02.ll
  llvm/test/Transforms/Coroutines/coro-readnone-03.ll
  llvm/test/Transforms/DeadArgElim/2010-04-30-DbgInfo.ll
  llvm/test/Transforms/DeadArgElim/keepalive.ll
  llvm/test/Transforms/GlobalOpt/ctor-memset.ll
  llvm/test/Transforms/GlobalOpt/pr54572.ll
  llvm/test/Transforms/Inline/inline_invoke.ll
  llvm/test/Transforms/InstCombine/AArch64/2012-04-23-Neon-Intrinsics.ll
  llvm/test/Transforms/LowerMatrixIntrinsics/strided-store-double.ll
  llvm/test/Transforms/ObjCARC/basic.ll
  llvm/test/Transforms/ObjCARC/ensure-that-exception-unwind-path-is-visited.ll
  llvm/test/Transforms/ObjCARC/nested.ll
  llvm/test/Transforms/OpenMP/replace_globalization.ll
  llvm/test/Transforms/OpenMP/spmdization.ll
  llvm/test/Transforms/OpenMP/spmdization_guarding.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
  llvm/test/Transforms/SimplifyCFG/X86/merge-compatible-invokes-of-landingpad-debuginfo.ll
  llvm/test/Verifier/fp-intrinsics.ll
  llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.globals.expected
  llvm/test/tools/llvm-reduce/remove-attributes-from-intrinsics.ll
  llvm/utils/TableGen/CodeGenIntrinsics.h
  llvm/utils/TableGen/CodeGenTarget.cpp
  llvm/utils/TableGen/IntrinsicEmitter.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132352.454398.patch
Type: text/x-patch
Size: 120652 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220822/a15d7db3/attachment-0001.bin>


More information about the cfe-commits mailing list