[PATCH] D53424: Enable thread specific cl::opt values for multi-threaded support

Yevgeny Rouban via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 19 02:21:55 PDT 2018


yrouban created this revision.
yrouban added reviewers: chandlerc, espindola, sepavloff, skatkov, reames.
Herald added subscribers: kristina, jfb.

When several threads compile different modules the compiler options (instances of //cl::opt//) cannot be set individually for each thread. That is because the options are visible to all threads. In other words all options are global.

It would be convenient if the options were specific to LLVMContext and they were accessed through an instance of LLVMContext. This kind of change would need changes in all source files where options are used.

This patch proposes a solution that needs minimal changes in LLVM source base.
It is proposed to have a thread local set of re-defined option values mapped by pointers to options.

Specifically, every time a program gets/sets a value for an option it is checked if the //current thread local context// is set for the current thread and the option has its local copy in this context. If so the local copy of the option is accessed, otherwise the global option is accessed. For all programs that existed so far the context is not set and they work with the global options.
For new multi-threaded compilers (where every thread compiles its own module) every thread can be linked to its own context (see //ContextValues//) where any option can have its thread specific value that do not affect the other threads' option values. See the //thread_routine()// in the test //ContextSpecificValues2//.

This feature allows a configuration flexibility for multi-threaded compilers that can compile every compilation unit in its own thread with different command line options.


Repository:
  rL LLVM

https://reviews.llvm.org/D53424

Files:
  include/llvm/Support/CommandLine.h
  lib/Support/CommandLine.cpp
  unittests/Support/CommandLineTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53424.170161.patch
Type: text/x-patch
Size: 12575 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181019/a956fc3d/attachment.bin>


More information about the llvm-commits mailing list