diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 20:50:49 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 20:50:49 +0000 | 
| commit | 2298981669bf3bd63335a4be179bc0f96823a8f4 (patch) | |
| tree | 1cbe2eb27f030d2d70b80ee5ca3c86bee7326a9f /tools/driver/cc1_main.cpp | |
| parent | 9a83721404652cea39e9f02ae3e3b5c964602a5c (diff) | |
Diffstat (limited to 'tools/driver/cc1_main.cpp')
| -rw-r--r-- | tools/driver/cc1_main.cpp | 62 | 
1 files changed, 57 insertions, 5 deletions
| diff --git a/tools/driver/cc1_main.cpp b/tools/driver/cc1_main.cpp index 7d21c6a671d21..7315a1357089c 100644 --- a/tools/driver/cc1_main.cpp +++ b/tools/driver/cc1_main.cpp @@ -1,9 +1,8 @@  //===-- cc1_main.cpp - Clang CC1 Compiler Frontend ------------------------===//  // -//                     The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception  //  //===----------------------------------------------------------------------===//  // @@ -14,6 +13,7 @@  //===----------------------------------------------------------------------===//  #include "clang/Basic/Stack.h" +#include "clang/Basic/TargetOptions.h"  #include "clang/CodeGen/ObjectFilePCHContainerOperations.h"  #include "clang/Config/config.h"  #include "clang/Driver/DriverDiagnostic.h" @@ -35,10 +35,14 @@  #include "llvm/Support/Compiler.h"  #include "llvm/Support/ErrorHandling.h"  #include "llvm/Support/ManagedStatic.h" +#include "llvm/Support/Path.h"  #include "llvm/Support/Signals.h" +#include "llvm/Support/TargetRegistry.h"  #include "llvm/Support/TargetSelect.h" +#include "llvm/Support/TimeProfiler.h"  #include "llvm/Support/Timer.h"  #include "llvm/Support/raw_ostream.h" +#include "llvm/Target/TargetMachine.h"  #include <cstdio>  #ifdef CLANG_HAVE_RLIMITS @@ -165,6 +169,23 @@ static void ensureSufficientStack() {  static void ensureSufficientStack() {}  #endif +/// Print supported cpus of the given target. +static int PrintSupportedCPUs(std::string TargetStr) { +  std::string Error; +  const llvm::Target *TheTarget = +      llvm::TargetRegistry::lookupTarget(TargetStr, Error); +  if (!TheTarget) { +    llvm::errs() << Error; +    return 1; +  } + +  // the target machine will handle the mcpu printing +  llvm::TargetOptions Options; +  std::unique_ptr<llvm::TargetMachine> TheTargetMachine( +      TheTarget->createTargetMachine(TargetStr, "", "+cpuHelp", Options, None)); +  return 0; +} +  int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {    ensureSufficientStack(); @@ -195,6 +216,13 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {    bool Success = CompilerInvocation::CreateFromArgs(        Clang->getInvocation(), Argv.begin(), Argv.end(), Diags); +  if (Clang->getFrontendOpts().TimeTrace) +    llvm::timeTraceProfilerInitialize(); + +  // --print-supported-cpus takes priority over the actual compilation. +  if (Clang->getFrontendOpts().PrintSupportedCPUs) +    return PrintSupportedCPUs(Clang->getTargetOpts().Triple); +    // Infer the builtin include path if unspecified.    if (Clang->getHeaderSearchOpts().UseBuiltinIncludes &&        Clang->getHeaderSearchOpts().ResourceDir.empty()) @@ -216,12 +244,36 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {      return 1;    // Execute the frontend actions. -  Success = ExecuteCompilerInvocation(Clang.get()); +  { +    llvm::TimeTraceScope TimeScope("ExecuteCompiler", StringRef("")); +    Success = ExecuteCompilerInvocation(Clang.get()); +  }    // If any timers were active but haven't been destroyed yet, print their    // results now.  This happens in -disable-free mode.    llvm::TimerGroup::printAll(llvm::errs()); +  if (llvm::timeTraceProfilerEnabled()) { +    SmallString<128> Path(Clang->getFrontendOpts().OutputFile); +    llvm::sys::path::replace_extension(Path, "json"); +    auto profilerOutput = +        Clang->createOutputFile(Path.str(), +                                /*Binary=*/false, +                                /*RemoveFileOnSignal=*/false, "", +                                /*Extension=*/"json", +                                /*useTemporary=*/false); + +    llvm::timeTraceProfilerWrite(*profilerOutput); +    // FIXME(ibiryukov): make profilerOutput flush in destructor instead. +    profilerOutput->flush(); +    llvm::timeTraceProfilerCleanup(); + +    llvm::errs() << "Time trace json-file dumped to " << Path.str() << "\n"; +    llvm::errs() +        << "Use chrome://tracing or Speedscope App " +           "(https://www.speedscope.app) for flamegraph visualization\n"; +  } +    // Our error handler depends on the Diagnostics object, which we're    // potentially about to delete. Uninstall the handler now so that any    // later errors use the default handling behavior instead. | 
