TargetOptions.h 18 KB

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