TargetOptions.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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 EABI {
  72. Unknown,
  73. Default, // Default means not specified
  74. EABI4, // Target-specific (either 4, 5 or gnu depending on triple).
  75. EABI5,
  76. GNU
  77. };
  78. /// Identify a debugger for "tuning" the debug info.
  79. ///
  80. /// The "debugger tuning" concept allows us to present a more intuitive
  81. /// interface that unpacks into different sets of defaults for the various
  82. /// individual feature-flag settings, that suit the preferences of the
  83. /// various debuggers. However, it's worth remembering that debuggers are
  84. /// not the only consumers of debug info, and some variations in DWARF might
  85. /// better be treated as target/platform issues. Fundamentally,
  86. /// o if the feature is useful (or not) to a particular debugger, regardless
  87. /// of the target, that's a tuning decision;
  88. /// o if the feature is useful (or not) on a particular platform, regardless
  89. /// of the debugger, that's a target decision.
  90. /// It's not impossible to see both factors in some specific case.
  91. enum class DebuggerKind {
  92. Default, ///< No specific tuning requested.
  93. GDB, ///< Tune debug info for gdb.
  94. LLDB, ///< Tune debug info for lldb.
  95. SCE, ///< Tune debug info for SCE targets (e.g. PS4).
  96. DBX ///< Tune debug info for dbx.
  97. };
  98. /// Enable abort calls when global instruction selection fails to lower/select
  99. /// an instruction.
  100. enum class GlobalISelAbortMode {
  101. Disable, // Disable the abort.
  102. Enable, // Enable the abort.
  103. DisableWithDiag // Disable the abort but emit a diagnostic on failure.
  104. };
  105. /// Indicates when and how the Swift async frame pointer bit should be set.
  106. enum class SwiftAsyncFramePointerMode {
  107. /// Determine whether to set the bit statically or dynamically based
  108. /// on the deployment target.
  109. DeploymentBased,
  110. /// Always set the bit.
  111. Always,
  112. /// Never set the bit.
  113. Never,
  114. };
  115. class TargetOptions {
  116. public:
  117. TargetOptions()
  118. : UnsafeFPMath(false), NoInfsFPMath(false), NoNaNsFPMath(false),
  119. NoTrappingFPMath(true), NoSignedZerosFPMath(false),
  120. ApproxFuncFPMath(false), EnableAIXExtendedAltivecABI(false),
  121. HonorSignDependentRoundingFPMathOption(false), NoZerosInBSS(false),
  122. GuaranteedTailCallOpt(false), StackSymbolOrdering(true),
  123. EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false),
  124. DisableIntegratedAS(false), RelaxELFRelocations(false),
  125. FunctionSections(false), DataSections(false),
  126. IgnoreXCOFFVisibility(false), XCOFFTracebackTable(true),
  127. UniqueSectionNames(true), UniqueBasicBlockSectionNames(false),
  128. TrapUnreachable(false), NoTrapAfterNoreturn(false), TLSSize(0),
  129. EmulatedTLS(false), ExplicitEmulatedTLS(false), EnableIPRA(false),
  130. EmitStackSizeSection(false), EnableMachineOutliner(false),
  131. EnableMachineFunctionSplitter(false), SupportsDefaultOutlining(false),
  132. EmitAddrsig(false), EmitCallSiteInfo(false),
  133. SupportsDebugEntryValues(false), EnableDebugEntryValues(false),
  134. ValueTrackingVariableLocations(false), ForceDwarfFrameSection(false),
  135. XRayOmitFunctionIndex(false), DebugStrictDwarf(false),
  136. Hotpatch(false),
  137. FPDenormalMode(DenormalMode::IEEE, DenormalMode::IEEE) {}
  138. /// DisableFramePointerElim - This returns true if frame pointer elimination
  139. /// optimization should be disabled for the given machine function.
  140. bool DisableFramePointerElim(const MachineFunction &MF) const;
  141. /// If greater than 0, override the default value of
  142. /// MCAsmInfo::BinutilsVersion.
  143. std::pair<int, int> BinutilsVersion{0, 0};
  144. /// UnsafeFPMath - This flag is enabled when the
  145. /// -enable-unsafe-fp-math flag is specified on the command line. When
  146. /// this flag is off (the default), the code generator is not allowed to
  147. /// produce results that are "less precise" than IEEE allows. This includes
  148. /// use of X86 instructions like FSIN and FCOS instead of libcalls.
  149. unsigned UnsafeFPMath : 1;
  150. /// NoInfsFPMath - This flag is enabled when the
  151. /// -enable-no-infs-fp-math flag is specified on the command line. When
  152. /// this flag is off (the default), the code generator is not allowed to
  153. /// assume the FP arithmetic arguments and results are never +-Infs.
  154. unsigned NoInfsFPMath : 1;
  155. /// NoNaNsFPMath - This flag is enabled when the
  156. /// -enable-no-nans-fp-math flag is specified on the command line. When
  157. /// this flag is off (the default), the code generator is not allowed to
  158. /// assume the FP arithmetic arguments and results are never NaNs.
  159. unsigned NoNaNsFPMath : 1;
  160. /// NoTrappingFPMath - This flag is enabled when the
  161. /// -enable-no-trapping-fp-math is specified on the command line. This
  162. /// specifies that there are no trap handlers to handle exceptions.
  163. unsigned NoTrappingFPMath : 1;
  164. /// NoSignedZerosFPMath - This flag is enabled when the
  165. /// -enable-no-signed-zeros-fp-math is specified on the command line. This
  166. /// specifies that optimizations are allowed to treat the sign of a zero
  167. /// argument or result as insignificant.
  168. unsigned NoSignedZerosFPMath : 1;
  169. /// ApproxFuncFPMath - This flag is enabled when the
  170. /// -enable-approx-func-fp-math is specified on the command line. This
  171. /// specifies that optimizations are allowed to substitute math functions
  172. /// with approximate calculations
  173. unsigned ApproxFuncFPMath : 1;
  174. /// EnableAIXExtendedAltivecABI - This flag returns true when -vec-extabi is
  175. /// specified. The code generator is then able to use both volatile and
  176. /// nonvolitle vector registers. When false, the code generator only uses
  177. /// volatile vector registers which is the default setting on AIX.
  178. unsigned EnableAIXExtendedAltivecABI : 1;
  179. /// HonorSignDependentRoundingFPMath - This returns true when the
  180. /// -enable-sign-dependent-rounding-fp-math is specified. If this returns
  181. /// false (the default), the code generator is allowed to assume that the
  182. /// rounding behavior is the default (round-to-zero for all floating point
  183. /// to integer conversions, and round-to-nearest for all other arithmetic
  184. /// truncations). If this is enabled (set to true), the code generator must
  185. /// assume that the rounding mode may dynamically change.
  186. unsigned HonorSignDependentRoundingFPMathOption : 1;
  187. bool HonorSignDependentRoundingFPMath() const;
  188. /// NoZerosInBSS - By default some codegens place zero-initialized data to
  189. /// .bss section. This flag disables such behaviour (necessary, e.g. for
  190. /// crt*.o compiling).
  191. unsigned NoZerosInBSS : 1;
  192. /// GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is
  193. /// specified on the commandline. When the flag is on, participating targets
  194. /// will perform tail call optimization on all calls which use the fastcc
  195. /// calling convention and which satisfy certain target-independent
  196. /// criteria (being at the end of a function, having the same return type
  197. /// as their parent function, etc.), using an alternate ABI if necessary.
  198. unsigned GuaranteedTailCallOpt : 1;
  199. /// StackSymbolOrdering - When true, this will allow CodeGen to order
  200. /// the local stack symbols (for code size, code locality, or any other
  201. /// heuristics). When false, the local symbols are left in whatever order
  202. /// they were generated. Default is true.
  203. unsigned StackSymbolOrdering : 1;
  204. /// EnableFastISel - This flag enables fast-path instruction selection
  205. /// which trades away generated code quality in favor of reducing
  206. /// compile time.
  207. unsigned EnableFastISel : 1;
  208. /// EnableGlobalISel - This flag enables global instruction selection.
  209. unsigned EnableGlobalISel : 1;
  210. /// EnableGlobalISelAbort - Control abort behaviour when global instruction
  211. /// selection fails to lower/select an instruction.
  212. GlobalISelAbortMode GlobalISelAbort = GlobalISelAbortMode::Enable;
  213. /// Control when and how the Swift async frame pointer bit should
  214. /// be set.
  215. SwiftAsyncFramePointerMode SwiftAsyncFramePointer =
  216. SwiftAsyncFramePointerMode::Always;
  217. /// UseInitArray - Use .init_array instead of .ctors for static
  218. /// constructors.
  219. unsigned UseInitArray : 1;
  220. /// Disable the integrated assembler.
  221. unsigned DisableIntegratedAS : 1;
  222. /// Compress DWARF debug sections.
  223. DebugCompressionType CompressDebugSections = DebugCompressionType::None;
  224. unsigned RelaxELFRelocations : 1;
  225. /// Emit functions into separate sections.
  226. unsigned FunctionSections : 1;
  227. /// Emit data into separate sections.
  228. unsigned DataSections : 1;
  229. /// Do not emit visibility attribute for xcoff.
  230. unsigned IgnoreXCOFFVisibility : 1;
  231. /// Emit XCOFF traceback table.
  232. unsigned XCOFFTracebackTable : 1;
  233. unsigned UniqueSectionNames : 1;
  234. /// Use unique names for basic block sections.
  235. unsigned UniqueBasicBlockSectionNames : 1;
  236. /// Emit target-specific trap instruction for 'unreachable' IR instructions.
  237. unsigned TrapUnreachable : 1;
  238. /// Do not emit a trap instruction for 'unreachable' IR instructions behind
  239. /// noreturn calls, even if TrapUnreachable is true.
  240. unsigned NoTrapAfterNoreturn : 1;
  241. /// Bit size of immediate TLS offsets (0 == use the default).
  242. unsigned TLSSize : 8;
  243. /// EmulatedTLS - This flag enables emulated TLS model, using emutls
  244. /// function in the runtime library..
  245. unsigned EmulatedTLS : 1;
  246. /// Whether -emulated-tls or -no-emulated-tls is set.
  247. unsigned ExplicitEmulatedTLS : 1;
  248. /// This flag enables InterProcedural Register Allocation (IPRA).
  249. unsigned EnableIPRA : 1;
  250. /// Emit section containing metadata on function stack sizes.
  251. unsigned EmitStackSizeSection : 1;
  252. /// Enables the MachineOutliner pass.
  253. unsigned EnableMachineOutliner : 1;
  254. /// Enables the MachineFunctionSplitter pass.
  255. unsigned EnableMachineFunctionSplitter : 1;
  256. /// Set if the target supports default outlining behaviour.
  257. unsigned SupportsDefaultOutlining : 1;
  258. /// Emit address-significance table.
  259. unsigned EmitAddrsig : 1;
  260. /// Emit basic blocks into separate sections.
  261. BasicBlockSection BBSections = BasicBlockSection::None;
  262. /// Memory Buffer that contains information on sampled basic blocks and used
  263. /// to selectively generate basic block sections.
  264. std::shared_ptr<MemoryBuffer> BBSectionsFuncListBuf;
  265. /// The flag enables call site info production. It is used only for debug
  266. /// info, and it is restricted only to optimized code. This can be used for
  267. /// something else, so that should be controlled in the frontend.
  268. unsigned EmitCallSiteInfo : 1;
  269. /// Set if the target supports the debug entry values by default.
  270. unsigned SupportsDebugEntryValues : 1;
  271. /// When set to true, the EnableDebugEntryValues option forces production
  272. /// of debug entry values even if the target does not officially support
  273. /// it. Useful for testing purposes only. This flag should never be checked
  274. /// directly, always use \ref ShouldEmitDebugEntryValues instead.
  275. unsigned EnableDebugEntryValues : 1;
  276. /// NOTE: There are targets that still do not support the debug entry values
  277. /// production.
  278. bool ShouldEmitDebugEntryValues() const;
  279. // When set to true, use experimental new debug variable location tracking,
  280. // which seeks to follow the values of variables rather than their location,
  281. // post isel.
  282. unsigned ValueTrackingVariableLocations : 1;
  283. /// Emit DWARF debug frame section.
  284. unsigned ForceDwarfFrameSection : 1;
  285. /// Emit XRay Function Index section
  286. unsigned XRayOmitFunctionIndex : 1;
  287. /// When set to true, don't use DWARF extensions in later DWARF versions.
  288. /// By default, it is set to false.
  289. unsigned DebugStrictDwarf : 1;
  290. /// Emit the hotpatch flag in CodeView debug.
  291. unsigned Hotpatch : 1;
  292. /// Name of the stack usage file (i.e., .su file) if user passes
  293. /// -fstack-usage. If empty, it can be implied that -fstack-usage is not
  294. /// passed on the command line.
  295. std::string StackUsageOutput;
  296. /// If greater than 0, override TargetLoweringBase::PrefLoopAlignment.
  297. unsigned LoopAlignment = 0;
  298. /// FloatABIType - This setting is set by -float-abi=xxx option is specfied
  299. /// on the command line. This setting may either be Default, Soft, or Hard.
  300. /// Default selects the target's default behavior. Soft selects the ABI for
  301. /// software floating point, but does not indicate that FP hardware may not
  302. /// be used. Such a combination is unfortunately popular (e.g.
  303. /// arm-apple-darwin). Hard presumes that the normal FP ABI is used.
  304. FloatABI::ABIType FloatABIType = FloatABI::Default;
  305. /// AllowFPOpFusion - This flag is set by the -fp-contract=xxx option.
  306. /// This controls the creation of fused FP ops that store intermediate
  307. /// results in higher precision than IEEE allows (E.g. FMAs).
  308. ///
  309. /// Fast mode - allows formation of fused FP ops whenever they're
  310. /// profitable.
  311. /// Standard mode - allow fusion only for 'blessed' FP ops. At present the
  312. /// only blessed op is the fmuladd intrinsic. In the future more blessed ops
  313. /// may be added.
  314. /// Strict mode - allow fusion only if/when it can be proven that the excess
  315. /// precision won't effect the result.
  316. ///
  317. /// Note: This option only controls formation of fused ops by the
  318. /// optimizers. Fused operations that are explicitly specified (e.g. FMA
  319. /// via the llvm.fma.* intrinsic) will always be honored, regardless of
  320. /// the value of this option.
  321. FPOpFusion::FPOpFusionMode AllowFPOpFusion = FPOpFusion::Standard;
  322. /// ThreadModel - This flag specifies the type of threading model to assume
  323. /// for things like atomics
  324. ThreadModel::Model ThreadModel = ThreadModel::POSIX;
  325. /// EABIVersion - This flag specifies the EABI version
  326. EABI EABIVersion = EABI::Default;
  327. /// Which debugger to tune for.
  328. DebuggerKind DebuggerTuning = DebuggerKind::Default;
  329. private:
  330. /// Flushing mode to assume in default FP environment.
  331. DenormalMode FPDenormalMode;
  332. /// Flushing mode to assume in default FP environment, for float/vector of
  333. /// float.
  334. DenormalMode FP32DenormalMode;
  335. public:
  336. void setFPDenormalMode(DenormalMode Mode) {
  337. FPDenormalMode = Mode;
  338. }
  339. void setFP32DenormalMode(DenormalMode Mode) {
  340. FP32DenormalMode = Mode;
  341. }
  342. DenormalMode getRawFPDenormalMode() const {
  343. return FPDenormalMode;
  344. }
  345. DenormalMode getRawFP32DenormalMode() const {
  346. return FP32DenormalMode;
  347. }
  348. DenormalMode getDenormalMode(const fltSemantics &FPType) const;
  349. /// What exception model to use
  350. ExceptionHandling ExceptionModel = ExceptionHandling::None;
  351. /// Machine level options.
  352. MCTargetOptions MCOptions;
  353. /// Stores the filename/path of the final .o/.obj file, to be written in the
  354. /// debug information. This is used for emitting the CodeView S_OBJNAME
  355. /// record.
  356. std::string ObjectFilenameForDebug;
  357. };
  358. } // End llvm namespace
  359. #endif
  360. #ifdef __GNUC__
  361. #pragma GCC diagnostic pop
  362. #endif