TargetOptions.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. //===-- llvm/Target/TargetOptions.h - Target Options ------------*- C++ -*-===//
  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.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines command line option flags that are shared across various
  11. // targets.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_TARGET_TARGETOPTIONS_H
  15. #define LLVM_TARGET_TARGETOPTIONS_H
  16. #include "llvm/Target/TargetRecip.h"
  17. #include "llvm/MC/MCTargetOptions.h"
  18. #include <string>
  19. namespace llvm {
  20. class MachineFunction;
  21. class Module;
  22. class StringRef;
  23. namespace FloatABI {
  24. enum ABIType {
  25. Default, // Target-specific (either soft or hard depending on triple, etc).
  26. Soft, // Soft float.
  27. Hard // Hard float.
  28. };
  29. }
  30. namespace FPOpFusion {
  31. enum FPOpFusionMode {
  32. Fast, // Enable fusion of FP ops wherever it's profitable.
  33. Standard, // Only allow fusion of 'blessed' ops (currently just fmuladd).
  34. Strict // Never fuse FP-ops.
  35. };
  36. }
  37. namespace JumpTable {
  38. enum JumpTableType {
  39. Single, // Use a single table for all indirect jumptable calls.
  40. Arity, // Use one table per number of function parameters.
  41. Simplified, // Use one table per function type, with types projected
  42. // into 4 types: pointer to non-function, struct,
  43. // primitive, and function pointer.
  44. Full // Use one table per unique function type
  45. };
  46. }
  47. namespace ThreadModel {
  48. enum Model {
  49. POSIX, // POSIX Threads
  50. Single // Single Threaded Environment
  51. };
  52. }
  53. class TargetOptions {
  54. public:
  55. TargetOptions()
  56. : PrintMachineCode(false),
  57. LessPreciseFPMADOption(false), UnsafeFPMath(false),
  58. NoInfsFPMath(false), NoNaNsFPMath(false),
  59. HonorSignDependentRoundingFPMathOption(false),
  60. NoZerosInBSS(false),
  61. GuaranteedTailCallOpt(false),
  62. StackAlignmentOverride(0),
  63. EnableFastISel(false), PositionIndependentExecutable(false),
  64. UseInitArray(false), DisableIntegratedAS(false),
  65. CompressDebugSections(false), FunctionSections(false),
  66. DataSections(false), UniqueSectionNames(true), TrapUnreachable(false),
  67. FloatABIType(FloatABI::Default),
  68. AllowFPOpFusion(FPOpFusion::Standard), Reciprocals(TargetRecip()),
  69. JTType(JumpTable::Single),
  70. ThreadModel(ThreadModel::POSIX) {}
  71. /// PrintMachineCode - This flag is enabled when the -print-machineinstrs
  72. /// option is specified on the command line, and should enable debugging
  73. /// output from the code generator.
  74. unsigned PrintMachineCode : 1;
  75. /// DisableFramePointerElim - This returns true if frame pointer elimination
  76. /// optimization should be disabled for the given machine function.
  77. bool DisableFramePointerElim(const MachineFunction &MF) const;
  78. /// LessPreciseFPMAD - This flag is enabled when the
  79. /// -enable-fp-mad is specified on the command line. When this flag is off
  80. /// (the default), the code generator is not allowed to generate mad
  81. /// (multiply add) if the result is "less precise" than doing those
  82. /// operations individually.
  83. unsigned LessPreciseFPMADOption : 1;
  84. bool LessPreciseFPMAD() const;
  85. /// UnsafeFPMath - This flag is enabled when the
  86. /// -enable-unsafe-fp-math flag is specified on the command line. When
  87. /// this flag is off (the default), the code generator is not allowed to
  88. /// produce results that are "less precise" than IEEE allows. This includes
  89. /// use of X86 instructions like FSIN and FCOS instead of libcalls.
  90. /// UnsafeFPMath implies LessPreciseFPMAD.
  91. unsigned UnsafeFPMath : 1;
  92. /// NoInfsFPMath - This flag is enabled when the
  93. /// -enable-no-infs-fp-math flag is specified on the command line. When
  94. /// this flag is off (the default), the code generator is not allowed to
  95. /// assume the FP arithmetic arguments and results are never +-Infs.
  96. unsigned NoInfsFPMath : 1;
  97. /// NoNaNsFPMath - This flag is enabled when the
  98. /// -enable-no-nans-fp-math flag is specified on the command line. When
  99. /// this flag is off (the default), the code generator is not allowed to
  100. /// assume the FP arithmetic arguments and results are never NaNs.
  101. unsigned NoNaNsFPMath : 1;
  102. /// HonorSignDependentRoundingFPMath - This returns true when the
  103. /// -enable-sign-dependent-rounding-fp-math is specified. If this returns
  104. /// false (the default), the code generator is allowed to assume that the
  105. /// rounding behavior is the default (round-to-zero for all floating point
  106. /// to integer conversions, and round-to-nearest for all other arithmetic
  107. /// truncations). If this is enabled (set to true), the code generator must
  108. /// assume that the rounding mode may dynamically change.
  109. unsigned HonorSignDependentRoundingFPMathOption : 1;
  110. bool HonorSignDependentRoundingFPMath() const;
  111. /// NoZerosInBSS - By default some codegens place zero-initialized data to
  112. /// .bss section. This flag disables such behaviour (necessary, e.g. for
  113. /// crt*.o compiling).
  114. unsigned NoZerosInBSS : 1;
  115. /// GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is
  116. /// specified on the commandline. When the flag is on, participating targets
  117. /// will perform tail call optimization on all calls which use the fastcc
  118. /// calling convention and which satisfy certain target-independent
  119. /// criteria (being at the end of a function, having the same return type
  120. /// as their parent function, etc.), using an alternate ABI if necessary.
  121. unsigned GuaranteedTailCallOpt : 1;
  122. /// StackAlignmentOverride - Override default stack alignment for target.
  123. unsigned StackAlignmentOverride;
  124. /// EnableFastISel - This flag enables fast-path instruction selection
  125. /// which trades away generated code quality in favor of reducing
  126. /// compile time.
  127. unsigned EnableFastISel : 1;
  128. /// PositionIndependentExecutable - This flag indicates whether the code
  129. /// will eventually be linked into a single executable, despite the PIC
  130. /// relocation model being in use. It's value is undefined (and irrelevant)
  131. /// if the relocation model is anything other than PIC.
  132. unsigned PositionIndependentExecutable : 1;
  133. /// UseInitArray - Use .init_array instead of .ctors for static
  134. /// constructors.
  135. unsigned UseInitArray : 1;
  136. /// Disable the integrated assembler.
  137. unsigned DisableIntegratedAS : 1;
  138. /// Compress DWARF debug sections.
  139. unsigned CompressDebugSections : 1;
  140. /// Emit functions into separate sections.
  141. unsigned FunctionSections : 1;
  142. /// Emit data into separate sections.
  143. unsigned DataSections : 1;
  144. unsigned UniqueSectionNames : 1;
  145. /// Emit target-specific trap instruction for 'unreachable' IR instructions.
  146. unsigned TrapUnreachable : 1;
  147. /// FloatABIType - This setting is set by -float-abi=xxx option is specfied
  148. /// on the command line. This setting may either be Default, Soft, or Hard.
  149. /// Default selects the target's default behavior. Soft selects the ABI for
  150. /// software floating point, but does not indicate that FP hardware may not
  151. /// be used. Such a combination is unfortunately popular (e.g.
  152. /// arm-apple-darwin). Hard presumes that the normal FP ABI is used.
  153. FloatABI::ABIType FloatABIType;
  154. /// AllowFPOpFusion - This flag is set by the -fuse-fp-ops=xxx option.
  155. /// This controls the creation of fused FP ops that store intermediate
  156. /// results in higher precision than IEEE allows (E.g. FMAs).
  157. ///
  158. /// Fast mode - allows formation of fused FP ops whenever they're
  159. /// profitable.
  160. /// Standard mode - allow fusion only for 'blessed' FP ops. At present the
  161. /// only blessed op is the fmuladd intrinsic. In the future more blessed ops
  162. /// may be added.
  163. /// Strict mode - allow fusion only if/when it can be proven that the excess
  164. /// precision won't effect the result.
  165. ///
  166. /// Note: This option only controls formation of fused ops by the
  167. /// optimizers. Fused operations that are explicitly specified (e.g. FMA
  168. /// via the llvm.fma.* intrinsic) will always be honored, regardless of
  169. /// the value of this option.
  170. FPOpFusion::FPOpFusionMode AllowFPOpFusion;
  171. /// This class encapsulates options for reciprocal-estimate code generation.
  172. TargetRecip Reciprocals;
  173. /// JTType - This flag specifies the type of jump-instruction table to
  174. /// create for functions that have the jumptable attribute.
  175. JumpTable::JumpTableType JTType;
  176. /// ThreadModel - This flag specifies the type of threading model to assume
  177. /// for things like atomics
  178. ThreadModel::Model ThreadModel;
  179. /// Machine level options.
  180. MCTargetOptions MCOptions;
  181. };
  182. // Comparison operators:
  183. inline bool operator==(const TargetOptions &LHS,
  184. const TargetOptions &RHS) {
  185. #define ARE_EQUAL(X) LHS.X == RHS.X
  186. return
  187. ARE_EQUAL(UnsafeFPMath) &&
  188. ARE_EQUAL(NoInfsFPMath) &&
  189. ARE_EQUAL(NoNaNsFPMath) &&
  190. ARE_EQUAL(HonorSignDependentRoundingFPMathOption) &&
  191. ARE_EQUAL(NoZerosInBSS) &&
  192. ARE_EQUAL(GuaranteedTailCallOpt) &&
  193. ARE_EQUAL(StackAlignmentOverride) &&
  194. ARE_EQUAL(EnableFastISel) &&
  195. ARE_EQUAL(PositionIndependentExecutable) &&
  196. ARE_EQUAL(UseInitArray) &&
  197. ARE_EQUAL(TrapUnreachable) &&
  198. ARE_EQUAL(FloatABIType) &&
  199. ARE_EQUAL(AllowFPOpFusion) &&
  200. ARE_EQUAL(Reciprocals) &&
  201. ARE_EQUAL(JTType) &&
  202. ARE_EQUAL(ThreadModel) &&
  203. ARE_EQUAL(MCOptions);
  204. #undef ARE_EQUAL
  205. }
  206. inline bool operator!=(const TargetOptions &LHS,
  207. const TargetOptions &RHS) {
  208. return !(LHS == RHS);
  209. }
  210. } // End llvm namespace
  211. #endif