CodeGen.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- llvm/Support/CodeGen.h - CodeGen Concepts ---------------*- 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 file define some types which define code generation concepts. For
  15. // example, relocation model.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_SUPPORT_CODEGEN_H
  19. #define LLVM_SUPPORT_CODEGEN_H
  20. #include <cstdint>
  21. #include <optional>
  22. namespace llvm {
  23. // Relocation model types.
  24. namespace Reloc {
  25. // Cannot be named PIC due to collision with -DPIC
  26. enum Model { Static, PIC_, DynamicNoPIC, ROPI, RWPI, ROPI_RWPI };
  27. }
  28. // Code model types.
  29. namespace CodeModel {
  30. // Sync changes with CodeGenCWrappers.h.
  31. enum Model { Tiny, Small, Kernel, Medium, Large };
  32. }
  33. namespace PICLevel {
  34. // This is used to map -fpic/-fPIC.
  35. enum Level { NotPIC=0, SmallPIC=1, BigPIC=2 };
  36. }
  37. namespace PIELevel {
  38. enum Level { Default=0, Small=1, Large=2 };
  39. }
  40. // TLS models.
  41. namespace TLSModel {
  42. enum Model {
  43. GeneralDynamic,
  44. LocalDynamic,
  45. InitialExec,
  46. LocalExec
  47. };
  48. }
  49. namespace CodeGenOpt {
  50. /// Type for the unique integer IDs of code generation optimization levels.
  51. using IDType = int;
  52. /// Code generation optimization level.
  53. enum Level : IDType {
  54. None = 0, ///< -O0
  55. Less = 1, ///< -O1
  56. Default = 2, ///< -O2, -Os
  57. Aggressive = 3 ///< -O3
  58. };
  59. /// Get the \c Level identified by the integer \p ID.
  60. ///
  61. /// Returns std::nullopt if \p ID is invalid.
  62. inline std::optional<Level> getLevel(IDType ID) {
  63. if (ID < 0 || ID > 3)
  64. return std::nullopt;
  65. return static_cast<Level>(ID);
  66. }
  67. /// Parse \p C as a single digit integer ID and get matching \c Level.
  68. ///
  69. /// Returns std::nullopt if the input is not a valid digit or not a valid ID.
  70. inline std::optional<Level> parseLevel(char C) {
  71. if (C < '0')
  72. return std::nullopt;
  73. return getLevel(static_cast<IDType>(C - '0'));
  74. }
  75. } // namespace CodeGenOpt
  76. /// These enums are meant to be passed into addPassesToEmitFile to indicate
  77. /// what type of file to emit, and returned by it to indicate what type of
  78. /// file could actually be made.
  79. enum CodeGenFileType {
  80. CGFT_AssemblyFile,
  81. CGFT_ObjectFile,
  82. CGFT_Null // Do not emit any output.
  83. };
  84. // Specify what functions should keep the frame pointer.
  85. enum class FramePointerKind { None, NonLeaf, All };
  86. // Specify what type of zeroing callee-used registers.
  87. namespace ZeroCallUsedRegs {
  88. const unsigned ONLY_USED = 1U << 1;
  89. const unsigned ONLY_GPR = 1U << 2;
  90. const unsigned ONLY_ARG = 1U << 3;
  91. enum class ZeroCallUsedRegsKind : unsigned int {
  92. // Don't zero any call-used regs.
  93. Skip = 1U << 0,
  94. // Only zeros call-used GPRs used in the fn and pass args.
  95. UsedGPRArg = ONLY_USED | ONLY_GPR | ONLY_ARG,
  96. // Only zeros call-used GPRs used in the fn.
  97. UsedGPR = ONLY_USED | ONLY_GPR,
  98. // Only zeros call-used regs used in the fn and pass args.
  99. UsedArg = ONLY_USED | ONLY_ARG,
  100. // Only zeros call-used regs used in the fn.
  101. Used = ONLY_USED,
  102. // Zeros all call-used GPRs that pass args.
  103. AllGPRArg = ONLY_GPR | ONLY_ARG,
  104. // Zeros all call-used GPRs.
  105. AllGPR = ONLY_GPR,
  106. // Zeros all call-used regs that pass args.
  107. AllArg = ONLY_ARG,
  108. // Zeros all call-used regs.
  109. All = 0,
  110. };
  111. } // namespace ZeroCallUsedRegs
  112. enum class UWTableKind {
  113. None = 0, ///< No unwind table requested
  114. Sync = 1, ///< "Synchronous" unwind tables
  115. Async = 2, ///< "Asynchronous" unwind tables (instr precise)
  116. Default = 2,
  117. };
  118. enum class FunctionReturnThunksKind : unsigned int {
  119. Keep = 0, ///< No function return thunk.
  120. Extern = 1, ///< Replace returns with jump to thunk, don't emit thunk.
  121. Invalid = 2, ///< Not used.
  122. };
  123. } // namespace llvm
  124. #endif
  125. #ifdef __GNUC__
  126. #pragma GCC diagnostic pop
  127. #endif