LinkAllCodegenComponents.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/Codegen/LinkAllCodegenComponents.h ------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This header file pulls in all codegen related passes for tools like lli and
  15. // llc that need this functionality.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_CODEGEN_LINKALLCODEGENCOMPONENTS_H
  19. #define LLVM_CODEGEN_LINKALLCODEGENCOMPONENTS_H
  20. #include "llvm/IR/BuiltinGCs.h"
  21. #include "llvm/CodeGen/Passes.h"
  22. #include "llvm/CodeGen/SchedulerRegistry.h"
  23. #include "llvm/Target/TargetMachine.h"
  24. #include <cstdlib>
  25. namespace {
  26. struct ForceCodegenLinking {
  27. ForceCodegenLinking() {
  28. // We must reference the passes in such a way that compilers will not
  29. // delete it all as dead code, even with whole program optimization,
  30. // yet is effectively a NO-OP. As the compiler isn't smart enough
  31. // to know that getenv() never returns -1, this will do the job.
  32. // This is so that globals in the translation units where these functions
  33. // are defined are forced to be initialized, populating various
  34. // registries.
  35. if (std::getenv("bar") != (char*) -1)
  36. return;
  37. (void) llvm::createFastRegisterAllocator();
  38. (void) llvm::createBasicRegisterAllocator();
  39. (void) llvm::createGreedyRegisterAllocator();
  40. (void) llvm::createDefaultPBQPRegisterAllocator();
  41. llvm::linkAllBuiltinGCs();
  42. (void) llvm::createBURRListDAGScheduler(nullptr,
  43. llvm::CodeGenOpt::Default);
  44. (void) llvm::createSourceListDAGScheduler(nullptr,
  45. llvm::CodeGenOpt::Default);
  46. (void) llvm::createHybridListDAGScheduler(nullptr,
  47. llvm::CodeGenOpt::Default);
  48. (void) llvm::createFastDAGScheduler(nullptr, llvm::CodeGenOpt::Default);
  49. (void) llvm::createDefaultScheduler(nullptr, llvm::CodeGenOpt::Default);
  50. (void) llvm::createVLIWDAGScheduler(nullptr, llvm::CodeGenOpt::Default);
  51. }
  52. } ForceCodegenLinking; // Force link by creating a global definition.
  53. }
  54. #endif
  55. #ifdef __GNUC__
  56. #pragma GCC diagnostic pop
  57. #endif