TargetOptions.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. //===-- llvm/Target/TargetOptions.h - Target Options ------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file defines command line option flags that are shared across various
  10. // targets.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_TARGET_TARGETOPTIONS_H
  14. #define LLVM_TARGET_TARGETOPTIONS_H
  15. #include "llvm/ADT/FloatingPointMode.h"
  16. #include "llvm/MC/MCTargetOptions.h"
  17. #include <memory>
  18. namespace llvm {
  19. struct fltSemantics;
  20. class MachineFunction;
  21. class MemoryBuffer;
  22. namespace FloatABI {
  23. enum ABIType {
  24. Default, // Target-specific (either soft or hard depending on triple, etc).
  25. Soft, // Soft float.
  26. Hard // Hard float.
  27. };
  28. }
  29. namespace FPOpFusion {
  30. enum FPOpFusionMode {
  31. Fast, // Enable fusion of FP ops wherever it's profitable.
  32. Standard, // Only allow fusion of 'blessed' ops (currently just fmuladd).
  33. Strict // Never fuse FP-ops.
  34. };
  35. }
  36. namespace JumpTable {
  37. enum JumpTableType {
  38. Single, // Use a single table for all indirect jumptable calls.
  39. Arity, // Use one table per number of function parameters.
  40. Simplified, // Use one table per function type, with types projected
  41. // into 4 types: pointer to non-function, struct,
  42. // primitive, and function pointer.
  43. Full // Use one table per unique function type
  44. };
  45. }
  46. namespace ThreadModel {
  47. enum Model {
  48. POSIX, // POSIX Threads
  49. Single // Single Threaded Environment
  50. };
  51. }
  52. enum class BasicBlockSection {
  53. All, // Use Basic Block Sections for all basic blocks. A section
  54. // for every basic block can significantly bloat object file sizes.
  55. List, // Get list of functions & BBs from a file. Selectively enables
  56. // basic block sections for a subset of basic blocks which can be
  57. // used to control object size bloats from creating sections.
  58. Labels, // Do not use Basic Block Sections but label basic blocks. This
  59. // is useful when associating profile counts from virtual addresses
  60. // to basic blocks.
  61. Preset, // Similar to list but the blocks are identified by passes which
  62. // seek to use Basic Block Sections, e.g. MachineFunctionSplitter.
  63. // This option cannot be set via the command line.
  64. None // Do not use Basic Block Sections.
  65. };
  66. enum class EABI {
  67. Unknown,
  68. Default, // Default means not specified
  69. EABI4, // Target-specific (either 4, 5 or gnu depending on triple).
  70. EABI5,
  71. GNU
  72. };
  73. /// Identify a debugger for "tuning" the debug info.
  74. ///
  75. /// The "debugger tuning" concept allows us to present a more intuitive
  76. /// interface that unpacks into different sets of defaults for the various
  77. /// individual feature-flag settings, that suit the preferences of the
  78. /// various debuggers. However, it's worth remembering that debuggers are
  79. /// not the only consumers of debug info, and some variations in DWARF might
  80. /// better be treated as target/platform issues. Fundamentally,
  81. /// o if the feature is useful (or not) to a particular debugger, regardless
  82. /// of the target, that's a tuning decision;
  83. /// o if the feature is useful (or not) on a particular platform, regardless
  84. /// of the debugger, that's a target decision.
  85. /// It's not impossible to see both factors in some specific case.
  86. enum class DebuggerKind {
  87. Default, ///< No specific tuning requested.
  88. GDB, ///< Tune debug info for gdb.
  89. LLDB, ///< Tune debug info for lldb.
  90. SCE, ///< Tune debug info for SCE targets (e.g. PS4).
  91. DBX ///< Tune debug info for dbx.
  92. };
  93. /// Enable abort calls when global instruction selection fails to lower/select
  94. /// an instruction.
  95. enum class GlobalISelAbortMode {
  96. Disable, // Disable the abort.
  97. Enable, // Enable the abort.
  98. DisableWithDiag // Disable the abort but emit a diagnostic on failure.
  99. };
  100. class TargetOptions {
  101. public:
  102. TargetOptions()
  103. : UnsafeFPMath(false), NoInfsFPMath(false), NoNaNsFPMath(false),
  104. NoTrappingFPMath(true), NoSignedZerosFPMath(false),
  105. EnableAIXExtendedAltivecABI(false),
  106. HonorSignDependentRoundingFPMathOption(false), NoZerosInBSS(false),
  107. GuaranteedTailCallOpt(false), StackSymbolOrdering(true),
  108. EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false),
  109. DisableIntegratedAS(false), RelaxELFRelocations(false),
  110. FunctionSections(false), DataSections(false),
  111. IgnoreXCOFFVisibility(false), XCOFFTracebackTable(true),
  112. UniqueSectionNames(true), UniqueBasicBlockSectionNames(false),
  113. TrapUnreachable(false), NoTrapAfterNoreturn(false), TLSSize(0),
  114. EmulatedTLS(false), ExplicitEmulatedTLS(false), EnableIPRA(false),
  115. EmitStackSizeSection(false), EnableMachineOutliner(false),
  116. EnableMachineFunctionSplitter(false), SupportsDefaultOutlining(false),
  117. EmitAddrsig(false), EmitCallSiteInfo(false),
  118. SupportsDebugEntryValues(false), EnableDebugEntryValues(false),
  119. PseudoProbeForProfiling(false), ValueTrackingVariableLocations(false),
  120. ForceDwarfFrameSection(false), XRayOmitFunctionIndex(false),
  121. DebugStrictDwarf(false),
  122. FPDenormalMode(DenormalMode::IEEE, DenormalMode::IEEE) {}
  123. /// DisableFramePointerElim - This returns true if frame pointer elimination
  124. /// optimization should be disabled for the given machine function.
  125. bool DisableFramePointerElim(const MachineFunction &MF) const;
  126. /// If greater than 0, override the default value of
  127. /// MCAsmInfo::BinutilsVersion.
  128. std::pair<int, int> BinutilsVersion{0, 0};
  129. /// UnsafeFPMath - This flag is enabled when the
  130. /// -enable-unsafe-fp-math flag is specified on the command line. When
  131. /// this flag is off (the default), the code generator is not allowed to
  132. /// produce results that are "less precise" than IEEE allows. This includes
  133. /// use of X86 instructions like FSIN and FCOS instead of libcalls.
  134. unsigned UnsafeFPMath : 1;
  135. /// NoInfsFPMath - This flag is enabled when the
  136. /// -enable-no-infs-fp-math flag is specified on the command line. When
  137. /// this flag is off (the default), the code generator is not allowed to
  138. /// assume the FP arithmetic arguments and results are never +-Infs.
  139. unsigned NoInfsFPMath : 1;
  140. /// NoNaNsFPMath - This flag is enabled when the
  141. /// -enable-no-nans-fp-math flag is specified on the command line. When
  142. /// this flag is off (the default), the code generator is not allowed to
  143. /// assume the FP arithmetic arguments and results are never NaNs.
  144. unsigned NoNaNsFPMath : 1;
  145. /// NoTrappingFPMath - This flag is enabled when the
  146. /// -enable-no-trapping-fp-math is specified on the command line. This
  147. /// specifies that there are no trap handlers to handle exceptions.
  148. unsigned NoTrappingFPMath : 1;
  149. /// NoSignedZerosFPMath - This flag is enabled when the
  150. /// -enable-no-signed-zeros-fp-math is specified on the command line. This
  151. /// specifies that optimizations are allowed to treat the sign of a zero
  152. /// argument or result as insignificant.
  153. unsigned NoSignedZerosFPMath : 1;
  154. /// EnableAIXExtendedAltivecABI - This flag returns true when -vec-extabi is
  155. /// specified. The code generator is then able to use both volatile and
  156. /// nonvolitle vector regisers. When false, the code generator only uses
  157. /// volatile vector registers which is the default setting on AIX.
  158. unsigned EnableAIXExtendedAltivecABI : 1;
  159. /// HonorSignDependentRoundingFPMath - This returns true when the
  160. /// -enable-sign-dependent-rounding-fp-math is specified. If this returns
  161. /// false (the default), the code generator is allowed to assume that the
  162. /// rounding behavior is the default (round-to-zero for all floating point
  163. /// to integer conversions, and round-to-nearest for all other arithmetic
  164. /// truncations). If this is enabled (set to true), the code generator must
  165. /// assume that the rounding mode may dynamically change.
  166. unsigned HonorSignDependentRoundingFPMathOption : 1;
  167. bool HonorSignDependentRoundingFPMath() const;
  168. /// NoZerosInBSS - By default some codegens place zero-initialized data to
  169. /// .bss section. This flag disables such behaviour (necessary, e.g. for
  170. /// crt*.o compiling).
  171. unsigned NoZerosInBSS : 1;
  172. /// GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is
  173. /// specified on the commandline. When the flag is on, participating targets
  174. /// will perform tail call optimization on all calls which use the fastcc
  175. /// calling convention and which satisfy certain target-independent
  176. /// criteria (being at the end of a function, having the same return type
  177. /// as their parent function, etc.), using an alternate ABI if necessary.
  178. unsigned GuaranteedTailCallOpt : 1;
  179. /// StackAlignmentOverride - Override default stack alignment for target.
  180. unsigned StackAlignmentOverride = 0;
  181. /// StackSymbolOrdering - When true, this will allow CodeGen to order
  182. /// the local stack symbols (for code size, code locality, or any other
  183. /// heuristics). When false, the local symbols are left in whatever order
  184. /// they were generated. Default is true.
  185. unsigned StackSymbolOrdering : 1;
  186. /// EnableFastISel - This flag enables fast-path instruction selection
  187. /// which trades away generated code quality in favor of reducing
  188. /// compile time.
  189. unsigned EnableFastISel : 1;
  190. /// EnableGlobalISel - This flag enables global instruction selection.
  191. unsigned EnableGlobalISel : 1;
  192. /// EnableGlobalISelAbort - Control abort behaviour when global instruction
  193. /// selection fails to lower/select an instruction.
  194. GlobalISelAbortMode GlobalISelAbort = GlobalISelAbortMode::Enable;
  195. /// UseInitArray - Use .init_array instead of .ctors for static
  196. /// constructors.
  197. unsigned UseInitArray : 1;
  198. /// Disable the integrated assembler.
  199. unsigned DisableIntegratedAS : 1;
  200. /// Compress DWARF debug sections.
  201. DebugCompressionType CompressDebugSections = DebugCompressionType::None;
  202. unsigned RelaxELFRelocations : 1;
  203. /// Emit functions into separate sections.
  204. unsigned FunctionSections : 1;
  205. /// Emit data into separate sections.
  206. unsigned DataSections : 1;
  207. /// Do not emit visibility attribute for xcoff.
  208. unsigned IgnoreXCOFFVisibility : 1;
  209. /// Emit XCOFF traceback table.
  210. unsigned XCOFFTracebackTable : 1;
  211. unsigned UniqueSectionNames : 1;
  212. /// Use unique names for basic block sections.
  213. unsigned UniqueBasicBlockSectionNames : 1;
  214. /// Emit target-specific trap instruction for 'unreachable' IR instructions.
  215. unsigned TrapUnreachable : 1;
  216. /// Do not emit a trap instruction for 'unreachable' IR instructions behind
  217. /// noreturn calls, even if TrapUnreachable is true.
  218. unsigned NoTrapAfterNoreturn : 1;
  219. /// Bit size of immediate TLS offsets (0 == use the default).
  220. unsigned TLSSize : 8;
  221. /// EmulatedTLS - This flag enables emulated TLS model, using emutls
  222. /// function in the runtime library..
  223. unsigned EmulatedTLS : 1;
  224. /// Whether -emulated-tls or -no-emulated-tls is set.
  225. unsigned ExplicitEmulatedTLS : 1;
  226. /// This flag enables InterProcedural Register Allocation (IPRA).
  227. unsigned EnableIPRA : 1;
  228. /// Emit section containing metadata on function stack sizes.
  229. unsigned EmitStackSizeSection : 1;
  230. /// Enables the MachineOutliner pass.
  231. unsigned EnableMachineOutliner : 1;
  232. /// Enables the MachineFunctionSplitter pass.
  233. unsigned EnableMachineFunctionSplitter : 1;
  234. /// Set if the target supports default outlining behaviour.
  235. unsigned SupportsDefaultOutlining : 1;
  236. /// Emit address-significance table.
  237. unsigned EmitAddrsig : 1;
  238. /// Emit basic blocks into separate sections.
  239. BasicBlockSection BBSections = BasicBlockSection::None;
  240. /// Memory Buffer that contains information on sampled basic blocks and used
  241. /// to selectively generate basic block sections.
  242. std::shared_ptr<MemoryBuffer> BBSectionsFuncListBuf;
  243. /// The flag enables call site info production. It is used only for debug
  244. /// info, and it is restricted only to optimized code. This can be used for
  245. /// something else, so that should be controlled in the frontend.
  246. unsigned EmitCallSiteInfo : 1;
  247. /// Set if the target supports the debug entry values by default.
  248. unsigned SupportsDebugEntryValues : 1;
  249. /// When set to true, the EnableDebugEntryValues option forces production
  250. /// of debug entry values even if the target does not officially support
  251. /// it. Useful for testing purposes only. This flag should never be checked
  252. /// directly, always use \ref ShouldEmitDebugEntryValues instead.
  253. unsigned EnableDebugEntryValues : 1;
  254. /// NOTE: There are targets that still do not support the debug entry values
  255. /// production.
  256. bool ShouldEmitDebugEntryValues() const;
  257. /// Emit pseudo probes into the binary for sample profiling
  258. unsigned PseudoProbeForProfiling : 1;
  259. // When set to true, use experimental new debug variable location tracking,
  260. // which seeks to follow the values of variables rather than their location,
  261. // post isel.
  262. unsigned ValueTrackingVariableLocations : 1;
  263. /// Emit DWARF debug frame section.
  264. unsigned ForceDwarfFrameSection : 1;
  265. /// Emit XRay Function Index section
  266. unsigned XRayOmitFunctionIndex : 1;
  267. /// When set to true, don't use DWARF extensions in later DWARF versions.
  268. /// By default, it is set to false.
  269. unsigned DebugStrictDwarf : 1;
  270. /// Name of the stack usage file (i.e., .su file) if user passes
  271. /// -fstack-usage. If empty, it can be implied that -fstack-usage is not
  272. /// passed on the command line.
  273. std::string StackUsageOutput;
  274. /// FloatABIType - This setting is set by -float-abi=xxx option is specfied
  275. /// on the command line. This setting may either be Default, Soft, or Hard.
  276. /// Default selects the target's default behavior. Soft selects the ABI for
  277. /// software floating point, but does not indicate that FP hardware may not
  278. /// be used. Such a combination is unfortunately popular (e.g.
  279. /// arm-apple-darwin). Hard presumes that the normal FP ABI is used.
  280. FloatABI::ABIType FloatABIType = FloatABI::Default;
  281. /// AllowFPOpFusion - This flag is set by the -fuse-fp-ops=xxx option.
  282. /// This controls the creation of fused FP ops that store intermediate
  283. /// results in higher precision than IEEE allows (E.g. FMAs).
  284. ///
  285. /// Fast mode - allows formation of fused FP ops whenever they're
  286. /// profitable.
  287. /// Standard mode - allow fusion only for 'blessed' FP ops. At present the
  288. /// only blessed op is the fmuladd intrinsic. In the future more blessed ops
  289. /// may be added.
  290. /// Strict mode - allow fusion only if/when it can be proven that the excess
  291. /// precision won't effect the result.
  292. ///
  293. /// Note: This option only controls formation of fused ops by the
  294. /// optimizers. Fused operations that are explicitly specified (e.g. FMA
  295. /// via the llvm.fma.* intrinsic) will always be honored, regardless of
  296. /// the value of this option.
  297. FPOpFusion::FPOpFusionMode AllowFPOpFusion = FPOpFusion::Standard;
  298. /// ThreadModel - This flag specifies the type of threading model to assume
  299. /// for things like atomics
  300. ThreadModel::Model ThreadModel = ThreadModel::POSIX;
  301. /// EABIVersion - This flag specifies the EABI version
  302. EABI EABIVersion = EABI::Default;
  303. /// Which debugger to tune for.
  304. DebuggerKind DebuggerTuning = DebuggerKind::Default;
  305. private:
  306. /// Flushing mode to assume in default FP environment.
  307. DenormalMode FPDenormalMode;
  308. /// Flushing mode to assume in default FP environment, for float/vector of
  309. /// float.
  310. DenormalMode FP32DenormalMode;
  311. public:
  312. void setFPDenormalMode(DenormalMode Mode) {
  313. FPDenormalMode = Mode;
  314. }
  315. void setFP32DenormalMode(DenormalMode Mode) {
  316. FP32DenormalMode = Mode;
  317. }
  318. DenormalMode getRawFPDenormalMode() const {
  319. return FPDenormalMode;
  320. }
  321. DenormalMode getRawFP32DenormalMode() const {
  322. return FP32DenormalMode;
  323. }
  324. DenormalMode getDenormalMode(const fltSemantics &FPType) const;
  325. /// What exception model to use
  326. ExceptionHandling ExceptionModel = ExceptionHandling::None;
  327. /// Machine level options.
  328. MCTargetOptions MCOptions;
  329. };
  330. } // End llvm namespace
  331. #endif