| author | |
| committer | |
| log | 05454123d45ca9a5fc4578d4ebffec9b158cf089 |
| tree | f389bb16cdb6e8770d1dc7aa3daa6433f2e6b3a4 |
| parent | 70e05c67ce6f044b5b99e01a5d972bbe92c38344 |
| signature |
upstream commit 1931d3cb20a00da732c5210b123656632982fde03 files changed, 89 insertions(+), 28 deletions(-)
src/zig_clang_cc1_main.cpp+57-6| ... | ... | @@ -1,9 +1,8 @@ |
| 1 | 1 | //===-- cc1_main.cpp - Clang CC1 Compiler Frontend ------------------------===// |
| 2 | 2 | // |
| 3 | // The LLVM Compiler Infrastructure | |
| 4 | // | |
| 5 | // This file is distributed under the University of Illinois Open Source | |
| 6 | // License. See LICENSE.TXT for details. | |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | |
| 4 | // See https://llvm.org/LICENSE.txt for license information. | |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |
| 7 | 6 | // |
| 8 | 7 | //===----------------------------------------------------------------------===// |
| 9 | 8 | // |
| ... | ... | @@ -14,6 +13,7 @@ |
| 14 | 13 | //===----------------------------------------------------------------------===// |
| 15 | 14 | |
| 16 | 15 | #include "clang/Basic/Stack.h" |
| 16 | #include "clang/Basic/TargetOptions.h" | |
| 17 | 17 | #include "clang/CodeGen/ObjectFilePCHContainerOperations.h" |
| 18 | 18 | #include "clang/Config/config.h" |
| 19 | 19 | #include "clang/Driver/DriverDiagnostic.h" |
| ... | ... | @@ -35,10 +35,14 @@ |
| 35 | 35 | #include "llvm/Support/Compiler.h" |
| 36 | 36 | #include "llvm/Support/ErrorHandling.h" |
| 37 | 37 | #include "llvm/Support/ManagedStatic.h" |
| 38 | #include "llvm/Support/Path.h" | |
| 38 | 39 | #include "llvm/Support/Signals.h" |
| 40 | #include "llvm/Support/TargetRegistry.h" | |
| 39 | 41 | #include "llvm/Support/TargetSelect.h" |
| 42 | #include "llvm/Support/TimeProfiler.h" | |
| 40 | 43 | #include "llvm/Support/Timer.h" |
| 41 | 44 | #include "llvm/Support/raw_ostream.h" |
| 45 | #include "llvm/Target/TargetMachine.h" | |
| 42 | 46 | #include <cstdio> |
| 43 | 47 | |
| 44 | 48 | #ifdef CLANG_HAVE_RLIMITS |
| ... | ... | @@ -159,6 +163,23 @@ static void ensureSufficientStack() { |
| 159 | 163 | static void ensureSufficientStack() {} |
| 160 | 164 | #endif |
| 161 | 165 | |
| 166 | /// Print supported cpus of the given target. | |
| 167 | static int PrintSupportedCPUs(std::string TargetStr) { | |
| 168 | std::string Error; | |
| 169 | const llvm::Target *TheTarget = | |
| 170 | llvm::TargetRegistry::lookupTarget(TargetStr, Error); | |
| 171 | if (!TheTarget) { | |
| 172 | llvm::errs() << Error; | |
| 173 | return 1; | |
| 174 | } | |
| 175 | ||
| 176 | // the target machine will handle the mcpu printing | |
| 177 | llvm::TargetOptions Options; | |
| 178 | std::unique_ptr<llvm::TargetMachine> TheTargetMachine( | |
| 179 | TheTarget->createTargetMachine(TargetStr, "", "+cpuHelp", Options, None)); | |
| 180 | return 0; | |
| 181 | } | |
| 182 | ||
| 162 | 183 | int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { |
| 163 | 184 | ensureSufficientStack(); |
| 164 | 185 | |
| ... | ... | @@ -184,6 +205,13 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { |
| 184 | 205 | bool Success = CompilerInvocation::CreateFromArgs( |
| 185 | 206 | Clang->getInvocation(), Argv.begin(), Argv.end(), Diags); |
| 186 | 207 | |
| 208 | if (Clang->getFrontendOpts().TimeTrace) | |
| 209 | llvm::timeTraceProfilerInitialize(); | |
| 210 | ||
| 211 | // --print-supported-cpus takes priority over the actual compilation. | |
| 212 | if (Clang->getFrontendOpts().PrintSupportedCPUs) | |
| 213 | return PrintSupportedCPUs(Clang->getTargetOpts().Triple); | |
| 214 | ||
| 187 | 215 | // Infer the builtin include path if unspecified. |
| 188 | 216 | if (Clang->getHeaderSearchOpts().UseBuiltinIncludes && |
| 189 | 217 | Clang->getHeaderSearchOpts().ResourceDir.empty()) |
| ... | ... | @@ -205,12 +233,36 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { |
| 205 | 233 | return 1; |
| 206 | 234 | |
| 207 | 235 | // Execute the frontend actions. |
| 208 | Success = ExecuteCompilerInvocation(Clang.get()); | |
| 236 | { | |
| 237 | llvm::TimeTraceScope TimeScope("ExecuteCompiler", StringRef("")); | |
| 238 | Success = ExecuteCompilerInvocation(Clang.get()); | |
| 239 | } | |
| 209 | 240 | |
| 210 | 241 | // If any timers were active but haven't been destroyed yet, print their |
| 211 | 242 | // results now. This happens in -disable-free mode. |
| 212 | 243 | llvm::TimerGroup::printAll(llvm::errs()); |
| 213 | 244 | |
| 245 | if (llvm::timeTraceProfilerEnabled()) { | |
| 246 | SmallString<128> Path(Clang->getFrontendOpts().OutputFile); | |
| 247 | llvm::sys::path::replace_extension(Path, "json"); | |
| 248 | auto profilerOutput = | |
| 249 | Clang->createOutputFile(Path.str(), | |
| 250 | /*Binary=*/false, | |
| 251 | /*RemoveFileOnSignal=*/false, "", | |
| 252 | /*Extension=*/"json", | |
| 253 | /*useTemporary=*/false); | |
| 254 | ||
| 255 | llvm::timeTraceProfilerWrite(*profilerOutput); | |
| 256 | // FIXME(ibiryukov): make profilerOutput flush in destructor instead. | |
| 257 | profilerOutput->flush(); | |
| 258 | llvm::timeTraceProfilerCleanup(); | |
| 259 | ||
| 260 | llvm::errs() << "Time trace json-file dumped to " << Path.str() << "\n"; | |
| 261 | llvm::errs() | |
| 262 | << "Use chrome://tracing or Speedscope App " | |
| 263 | "(https://www.speedscope.app) for flamegraph visualization\n"; | |
| 264 | } | |
| 265 | ||
| 214 | 266 | // Our error handler depends on the Diagnostics object, which we're |
| 215 | 267 | // potentially about to delete. Uninstall the handler now so that any |
| 216 | 268 | // later errors use the default handling behavior instead. |
| ... | ... | @@ -224,4 +276,3 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { |
| 224 | 276 | |
| 225 | 277 | return !Success; |
| 226 | 278 | } |
| 227 |
src/zig_clang_cc1as_main.cpp+28-16| ... | ... | @@ -1,9 +1,8 @@ |
| 1 | 1 | //===-- cc1as_main.cpp - Clang Assembler ---------------------------------===// |
| 2 | 2 | // |
| 3 | // The LLVM Compiler Infrastructure | |
| 4 | // | |
| 5 | // This file is distributed under the University of Illinois Open Source | |
| 6 | // License. See LICENSE.TXT for details. | |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | |
| 4 | // See https://llvm.org/LICENSE.txt for license information. | |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |
| 7 | 6 | // |
| 8 | 7 | //===----------------------------------------------------------------------===// |
| 9 | 8 | // |
| ... | ... | @@ -99,7 +98,7 @@ struct AssemblerInvocation { |
| 99 | 98 | llvm::DebugCompressionType CompressDebugSections = |
| 100 | 99 | llvm::DebugCompressionType::None; |
| 101 | 100 | std::string MainFileName; |
| 102 | std::string SplitDwarfFile; | |
| 101 | std::string SplitDwarfOutput; | |
| 103 | 102 | |
| 104 | 103 | /// @} |
| 105 | 104 | /// @name Frontend Options |
| ... | ... | @@ -138,6 +137,10 @@ struct AssemblerInvocation { |
| 138 | 137 | /// The name of the relocation model to use. |
| 139 | 138 | std::string RelocationModel; |
| 140 | 139 | |
| 140 | /// The ABI targeted by the backend. Specified using -target-abi. Empty | |
| 141 | /// otherwise. | |
| 142 | std::string TargetABI; | |
| 143 | ||
| 141 | 144 | /// @} |
| 142 | 145 | |
| 143 | 146 | public: |
| ... | ... | @@ -255,7 +258,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, |
| 255 | 258 | } |
| 256 | 259 | Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm); |
| 257 | 260 | Opts.OutputPath = Args.getLastArgValue(OPT_o); |
| 258 | Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file); | |
| 261 | Opts.SplitDwarfOutput = Args.getLastArgValue(OPT_split_dwarf_output); | |
| 259 | 262 | if (Arg *A = Args.getLastArg(OPT_filetype)) { |
| 260 | 263 | StringRef Name = A->getValue(); |
| 261 | 264 | unsigned OutputType = StringSwitch<unsigned>(Name) |
| ... | ... | @@ -283,6 +286,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, |
| 283 | 286 | Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack); |
| 284 | 287 | Opts.FatalWarnings = Args.hasArg(OPT_massembler_fatal_warnings); |
| 285 | 288 | Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic"); |
| 289 | Opts.TargetABI = Args.getLastArgValue(OPT_target_abi); | |
| 286 | 290 | Opts.IncrementalLinkerCompatible = |
| 287 | 291 | Args.hasArg(OPT_mincremental_linker_compatible); |
| 288 | 292 | Opts.SymbolDefs = Args.getAllArgValues(OPT_defsym); |
| ... | ... | @@ -337,7 +341,7 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, |
| 337 | 341 | SourceMgr SrcMgr; |
| 338 | 342 | |
| 339 | 343 | // Tell SrcMgr about this buffer, which is what the parser will pick up. |
| 340 | SrcMgr.AddNewSourceBuffer(std::move(*Buffer), SMLoc()); | |
| 344 | unsigned BufferIndex = SrcMgr.AddNewSourceBuffer(std::move(*Buffer), SMLoc()); | |
| 341 | 345 | |
| 342 | 346 | // Record the location of the include directories so that the lexer can find |
| 343 | 347 | // it later. |
| ... | ... | @@ -363,8 +367,8 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, |
| 363 | 367 | if (!FDOS) |
| 364 | 368 | return true; |
| 365 | 369 | std::unique_ptr<raw_fd_ostream> DwoOS; |
| 366 | if (!Opts.SplitDwarfFile.empty()) | |
| 367 | DwoOS = getOutputStream(Opts.SplitDwarfFile, Diags, IsBinary); | |
| 370 | if (!Opts.SplitDwarfOutput.empty()) | |
| 371 | DwoOS = getOutputStream(Opts.SplitDwarfOutput, Diags, IsBinary); | |
| 368 | 372 | |
| 369 | 373 | // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and |
| 370 | 374 | // MCObjectFileInfo needs a MCContext reference in order to initialize itself. |
| ... | ... | @@ -394,12 +398,21 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, |
| 394 | 398 | Ctx.setDwarfDebugProducer(StringRef(Opts.DwarfDebugProducer)); |
| 395 | 399 | if (!Opts.DebugCompilationDir.empty()) |
| 396 | 400 | Ctx.setCompilationDir(Opts.DebugCompilationDir); |
| 401 | else { | |
| 402 | // If no compilation dir is set, try to use the current directory. | |
| 403 | SmallString<128> CWD; | |
| 404 | if (!sys::fs::current_path(CWD)) | |
| 405 | Ctx.setCompilationDir(CWD); | |
| 406 | } | |
| 397 | 407 | if (!Opts.DebugPrefixMap.empty()) |
| 398 | 408 | for (const auto &KV : Opts.DebugPrefixMap) |
| 399 | 409 | Ctx.addDebugPrefixMapEntry(KV.first, KV.second); |
| 400 | 410 | if (!Opts.MainFileName.empty()) |
| 401 | 411 | Ctx.setMainFileName(StringRef(Opts.MainFileName)); |
| 402 | 412 | Ctx.setDwarfVersion(Opts.DwarfVersion); |
| 413 | if (Opts.GenDwarfForAssembly) | |
| 414 | Ctx.setGenDwarfRootFile(Opts.InputFile, | |
| 415 | SrcMgr.getMemoryBuffer(BufferIndex)->getBuffer()); | |
| 403 | 416 | |
| 404 | 417 | // Build up the feature string from the target feature list. |
| 405 | 418 | std::string FS; |
| ... | ... | @@ -418,6 +431,9 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, |
| 418 | 431 | raw_pwrite_stream *Out = FDOS.get(); |
| 419 | 432 | std::unique_ptr<buffer_ostream> BOS; |
| 420 | 433 | |
| 434 | MCTargetOptions MCOptions; | |
| 435 | MCOptions.ABIName = Opts.TargetABI; | |
| 436 | ||
| 421 | 437 | // FIXME: There is a bit of code duplication with addPassesToEmitFile. |
| 422 | 438 | if (Opts.OutputType == AssemblerInvocation::FT_Asm) { |
| 423 | 439 | MCInstPrinter *IP = TheTarget->createMCInstPrinter( |
| ... | ... | @@ -426,7 +442,6 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, |
| 426 | 442 | std::unique_ptr<MCCodeEmitter> CE; |
| 427 | 443 | if (Opts.ShowEncoding) |
| 428 | 444 | CE.reset(TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx)); |
| 429 | MCTargetOptions MCOptions; | |
| 430 | 445 | std::unique_ptr<MCAsmBackend> MAB( |
| 431 | 446 | TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions)); |
| 432 | 447 | |
| ... | ... | @@ -447,7 +462,6 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, |
| 447 | 462 | |
| 448 | 463 | std::unique_ptr<MCCodeEmitter> CE( |
| 449 | 464 | TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx)); |
| 450 | MCTargetOptions MCOptions; | |
| 451 | 465 | std::unique_ptr<MCAsmBackend> MAB( |
| 452 | 466 | TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions)); |
| 453 | 467 | std::unique_ptr<MCObjectWriter> OW = |
| ... | ... | @@ -481,9 +495,8 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, |
| 481 | 495 | createMCAsmParser(SrcMgr, Ctx, *Str.get(), *MAI)); |
| 482 | 496 | |
| 483 | 497 | // FIXME: init MCTargetOptions from sanitizer flags here. |
| 484 | MCTargetOptions Options; | |
| 485 | 498 | std::unique_ptr<MCTargetAsmParser> TAP( |
| 486 | TheTarget->createMCAsmParser(*STI, *Parser, *MCII, Options)); | |
| 499 | TheTarget->createMCAsmParser(*STI, *Parser, *MCII, MCOptions)); | |
| 487 | 500 | if (!TAP) |
| 488 | 501 | Failed = Diags.Report(diag::err_target_unknown_triple) << Opts.Triple; |
| 489 | 502 | |
| ... | ... | @@ -514,8 +527,8 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, |
| 514 | 527 | if (Failed) { |
| 515 | 528 | if (Opts.OutputPath != "-") |
| 516 | 529 | sys::fs::remove(Opts.OutputPath); |
| 517 | if (!Opts.SplitDwarfFile.empty() && Opts.SplitDwarfFile != "-") | |
| 518 | sys::fs::remove(Opts.SplitDwarfFile); | |
| 530 | if (!Opts.SplitDwarfOutput.empty() && Opts.SplitDwarfOutput != "-") | |
| 531 | sys::fs::remove(Opts.SplitDwarfOutput); | |
| 519 | 532 | } |
| 520 | 533 | |
| 521 | 534 | return Failed; |
| ... | ... | @@ -594,4 +607,3 @@ int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { |
| 594 | 607 | |
| 595 | 608 | return !!Failed; |
| 596 | 609 | } |
| 597 |
src/zig_clang_driver.cpp+4-6| ... | ... | @@ -1,9 +1,8 @@ |
| 1 | 1 | //===-- driver.cpp - Clang GCC-Compatible Driver --------------------------===// |
| 2 | 2 | // |
| 3 | // The LLVM Compiler Infrastructure | |
| 4 | // | |
| 5 | // This file is distributed under the University of Illinois Open Source | |
| 6 | // License. See LICENSE.TXT for details. | |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | |
| 4 | // See https://llvm.org/LICENSE.txt for license information. | |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |
| 7 | 6 | // |
| 8 | 7 | //===----------------------------------------------------------------------===// |
| 9 | 8 | // |
| ... | ... | @@ -339,7 +338,7 @@ int ZigClang_main(int argc_, const char **argv_) { |
| 339 | 338 | // response files written by clang will tokenize the same way in either mode. |
| 340 | 339 | bool ClangCLMode = false; |
| 341 | 340 | if (StringRef(TargetAndMode.DriverMode).equals("--driver-mode=cl") || |
| 342 | std::find_if(argv.begin(), argv.end(), [](const char *F) { | |
| 341 | llvm::find_if(argv, [](const char *F) { | |
| 343 | 342 | return F && strcmp(F, "--driver-mode=cl") == 0; |
| 344 | 343 | }) != argv.end()) { |
| 345 | 344 | ClangCLMode = true; |
| ... | ... | @@ -510,4 +509,3 @@ int ZigClang_main(int argc_, const char **argv_) { |
| 510 | 509 | // failing command. |
| 511 | 510 | return Res; |
| 512 | 511 | } |
| 513 |