TargetOptions.h 17 KB

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