[BOLT][NFC] Refactor logging and error handling

Make core BOLT functionality more friendly to being used as a
library instead of in our standalone driver llvm-bolt. To accomplish
this, we augment BinaryContext with journaling streams that are to be
used by most BOLT code whenever something needs to be logged to the
screen. Users of the library can decide if logs should be printed to a
file, no file or to the screen, as before. To illustrate this, this
patch adds a new option --log-file that allows the user to redirect
BOLT logging to a file on disk or completely hide it by using
--log-file=/dev/null. Future BOLT code should now use
BinaryContext::outs() for printing important messages instead of
llvm::outs(). A new test log.test enforces this by verifying that no
strings are print to screen once the --log-file option is used.

We also refactor old error handling code that would directly call
exit(1) inside BOLT libraries whenever a serious problem occurred. To
overcome this, we add a new class BOLTError and auxiliary functions
createFatalBOLTError() and createNonFatalBOLTError() that allows BOLT
libs to bubble up the problem to the caller by using the Error class
as a return type (or Expected). To easily handle problems as before
(by quitting with exit(1)), callers can now use
BinaryContext::logBOLTErrorsAndQuitOnFatal(Error) whenever code needs
to deal with BOLT errors. To test this, we have fatal.s that checks
we are correctly quitting and printing a fatal error to the screen.

Because this is a significant change by itself, not all code was yet
ported. Code from Profiler libs (DataAggregator and friends) still
print errors directly to screen.
100 files changed
tree: 7ad6ba005f52a88f4670d30d28cfe2018a5f7593
  1. .ci/
  2. .github/
  3. bolt/
  4. clang/
  5. clang-tools-extra/
  6. cmake/
  7. compiler-rt/
  8. cross-project-tests/
  9. flang/
  10. libc/
  11. libclc/
  12. libcxx/
  13. libcxxabi/
  14. libunwind/
  15. lld/
  16. lldb/
  17. llvm/
  18. llvm-libgcc/
  19. mlir/
  20. openmp/
  21. polly/
  22. pstl/
  23. runtimes/
  24. third-party/
  25. utils/
  26. .arcconfig
  27. .arclint
  28. .clang-format
  29. .clang-tidy
  30. .git-blame-ignore-revs
  31. .gitattributes
  32. .gitignore
  33. .mailmap
  34. CODE_OF_CONDUCT.md
  35. CONTRIBUTING.md
  36. LICENSE.TXT
  37. README.md
  38. SECURITY.md
README.md

The LLVM Compiler Infrastructure

OpenSSF Scorecard OpenSSF Best Practices libc++

Welcome to the LLVM project!

This repository contains the source code for LLVM, a toolkit for the construction of highly optimized compilers, optimizers, and run-time environments.

The LLVM project has multiple components. The core of the project is itself called “LLVM”. This contains all of the tools, libraries, and header files needed to process intermediate representations and convert them into object files. Tools include an assembler, disassembler, bitcode analyzer, and bitcode optimizer.

C-like languages use the Clang frontend. This component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode -- and from there into object files, using LLVM.

Other components include: the libc++ C++ standard library, the LLD linker, and more.

Getting the Source Code and Building LLVM

Consult the Getting Started with LLVM page for information on building and running LLVM.

For information on how to contribute to the LLVM project, please take a look at the Contributing to LLVM guide.

Getting in touch

Join the LLVM Discourse forums, Discord chat, LLVM Office Hours or Regular sync-ups.

The LLVM project has adopted a code of conduct for participants to all modes of communication within the project.