Index: include/clang/Driver/CC1Options.td =================================================================== --- include/clang/Driver/CC1Options.td +++ include/clang/Driver/CC1Options.td @@ -218,6 +218,8 @@ HelpText<"Limit the number of registers available for integer arguments">; def mrelocation_model : Separate<["-"], "mrelocation-model">, HelpText<"The relocation model to use">; +def mthread_model : Separate<["-"], "mthread-model">, + HelpText<"The thread model to use">; def munwind_tables : Flag<["-"], "munwind-tables">, HelpText<"Generate unwinding tables for all functions">; def mconstructor_aliases : Flag<["-"], "mconstructor-aliases">, Index: include/clang/Driver/ToolChain.h =================================================================== --- include/clang/Driver/ToolChain.h +++ include/clang/Driver/ToolChain.h @@ -248,6 +248,9 @@ /// UseSjLjExceptions - Does this tool chain use SjLj exceptions. virtual bool UseSjLjExceptions() const { return false; } + /// getThreadModel() - Which thread model does this target use? + virtual std::string getThreadModel() const { return "POSIX"; } + /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking /// command line arguments into account. virtual std::string Index: include/clang/Frontend/CodeGenOptions.h =================================================================== --- include/clang/Frontend/CodeGenOptions.h +++ include/clang/Frontend/CodeGenOptions.h @@ -134,6 +134,9 @@ /// The name of the relocation model to use. std::string RelocationModel; + /// The thread model to use + std::string ThreadModel; + /// Path to blacklist file for sanitizers. std::string SanitizerBlacklistFile; Index: lib/CodeGen/BackendUtil.cpp =================================================================== --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -419,6 +419,16 @@ llvm::TargetOptions Options; + Options.ThreadModel = llvm::ThreadModel::POSIX; + if (CodeGenOpts.ThreadModel == "POSIX") { + Options.ThreadModel = llvm::ThreadModel::POSIX; + } else if (CodeGenOpts.ThreadModel == "Single") { + Options.ThreadModel = llvm::ThreadModel::Single; + } else { + assert(false && "Invalid Thread model!"); + Options.ThreadModel = llvm::ThreadModel::POSIX; + } + if (CodeGenOpts.DisableIntegratedAS) Options.DisableIntegratedAS = true; Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -2776,6 +2776,9 @@ } } + CmdArgs.push_back("-mthread-model"); + CmdArgs.push_back(Args.MakeArgString(getToolChain().getThreadModel())); + if (!Args.hasFlag(options::OPT_fmerge_all_constants, options::OPT_fno_merge_all_constants)) CmdArgs.push_back("-fno-merge-all-constants"); Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -437,6 +437,7 @@ Args.hasArg(OPT_cl_fast_relaxed_math); Opts.UnwindTables = Args.hasArg(OPT_munwind_tables); Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic"); + Opts.ThreadModel = Args.getLastArgValue(OPT_mthread_model, "POSIX"); Opts.TrapFuncName = Args.getLastArgValue(OPT_ftrap_function_EQ); Opts.UseInitArray = Args.hasArg(OPT_fuse_init_array);