1ac1d23edSserge-sans-paille //===-- CommandFlags.cpp - Command Line Flags Interface ---------*- C++ -*-===// 2ac1d23edSserge-sans-paille // 3ac1d23edSserge-sans-paille // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4ac1d23edSserge-sans-paille // See https://llvm.org/LICENSE.txt for license information. 5ac1d23edSserge-sans-paille // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6ac1d23edSserge-sans-paille // 7ac1d23edSserge-sans-paille //===----------------------------------------------------------------------===// 8ac1d23edSserge-sans-paille // 9ac1d23edSserge-sans-paille // This file contains codegen-specific flags that are shared between different 10ac1d23edSserge-sans-paille // command line tools. The tools "llc" and "opt" both use this file to prevent 11ac1d23edSserge-sans-paille // flag duplication. 12ac1d23edSserge-sans-paille // 13ac1d23edSserge-sans-paille //===----------------------------------------------------------------------===// 14ac1d23edSserge-sans-paille 15ac1d23edSserge-sans-paille #include "llvm/CodeGen/CommandFlags.h" 16d9b9ce6cSSimon Pilgrim #include "llvm/IR/Module.h" 17d9b9ce6cSSimon Pilgrim #include "llvm/MC/SubtargetFeature.h" 18d9b9ce6cSSimon Pilgrim #include "llvm/Support/CommandLine.h" 19d9b9ce6cSSimon Pilgrim #include "llvm/Support/Host.h" 20ba7a92c0SNico Weber #include "llvm/Support/MemoryBuffer.h" 21ac1d23edSserge-sans-paille 22ac1d23edSserge-sans-paille using namespace llvm; 23ac1d23edSserge-sans-paille 24ac1d23edSserge-sans-paille #define CGOPT(TY, NAME) \ 25ac1d23edSserge-sans-paille static cl::opt<TY> *NAME##View; \ 26ac1d23edSserge-sans-paille TY codegen::get##NAME() { \ 27ac1d23edSserge-sans-paille assert(NAME##View && "RegisterCodeGenFlags not created."); \ 28ac1d23edSserge-sans-paille return *NAME##View; \ 29ac1d23edSserge-sans-paille } 30ac1d23edSserge-sans-paille 31ac1d23edSserge-sans-paille #define CGLIST(TY, NAME) \ 32ac1d23edSserge-sans-paille static cl::list<TY> *NAME##View; \ 33ac1d23edSserge-sans-paille std::vector<TY> codegen::get##NAME() { \ 34ac1d23edSserge-sans-paille assert(NAME##View && "RegisterCodeGenFlags not created."); \ 35ac1d23edSserge-sans-paille return *NAME##View; \ 36ac1d23edSserge-sans-paille } 37ac1d23edSserge-sans-paille 38ac1d23edSserge-sans-paille #define CGOPT_EXP(TY, NAME) \ 39ac1d23edSserge-sans-paille CGOPT(TY, NAME) \ 40ac1d23edSserge-sans-paille Optional<TY> codegen::getExplicit##NAME() { \ 41ac1d23edSserge-sans-paille if (NAME##View->getNumOccurrences()) { \ 42ac1d23edSserge-sans-paille TY res = *NAME##View; \ 43ac1d23edSserge-sans-paille return res; \ 44ac1d23edSserge-sans-paille } \ 45ac1d23edSserge-sans-paille return None; \ 46ac1d23edSserge-sans-paille } 47ac1d23edSserge-sans-paille 48ac1d23edSserge-sans-paille CGOPT(std::string, MArch) 49ac1d23edSserge-sans-paille CGOPT(std::string, MCPU) 50ac1d23edSserge-sans-paille CGLIST(std::string, MAttrs) 51ac1d23edSserge-sans-paille CGOPT_EXP(Reloc::Model, RelocModel) 52ac1d23edSserge-sans-paille CGOPT(ThreadModel::Model, ThreadModel) 53ac1d23edSserge-sans-paille CGOPT_EXP(CodeModel::Model, CodeModel) 54ac1d23edSserge-sans-paille CGOPT(ExceptionHandling, ExceptionModel) 55ac1d23edSserge-sans-paille CGOPT_EXP(CodeGenFileType, FileType) 562786e673SFangrui Song CGOPT(FramePointerKind, FramePointerUsage) 57ac1d23edSserge-sans-paille CGOPT(bool, EnableUnsafeFPMath) 58ac1d23edSserge-sans-paille CGOPT(bool, EnableNoInfsFPMath) 59ac1d23edSserge-sans-paille CGOPT(bool, EnableNoNaNsFPMath) 60ac1d23edSserge-sans-paille CGOPT(bool, EnableNoSignedZerosFPMath) 61*256d2533SMasoud Ataei CGOPT(bool, EnableApproxFuncFPMath) 62ac1d23edSserge-sans-paille CGOPT(bool, EnableNoTrappingFPMath) 63c92f29b0SZarko Todorovski CGOPT(bool, EnableAIXExtendedAltivecABI) 640ab5b5b8SMatt Arsenault CGOPT(DenormalMode::DenormalModeKind, DenormalFPMath) 65a8cc9047SMatt Arsenault CGOPT(DenormalMode::DenormalModeKind, DenormalFP32Math) 66ac1d23edSserge-sans-paille CGOPT(bool, EnableHonorSignDependentRoundingFPMath) 67ac1d23edSserge-sans-paille CGOPT(FloatABI::ABIType, FloatABIForCalls) 68ac1d23edSserge-sans-paille CGOPT(FPOpFusion::FPOpFusionMode, FuseFPOps) 69a773db7dSDoug Gregor CGOPT(SwiftAsyncFramePointerMode, SwiftAsyncFramePointer) 70ac1d23edSserge-sans-paille CGOPT(bool, DontPlaceZerosInBSS) 71ac1d23edSserge-sans-paille CGOPT(bool, EnableGuaranteedTailCallOpt) 72ac1d23edSserge-sans-paille CGOPT(bool, DisableTailCalls) 73ac1d23edSserge-sans-paille CGOPT(bool, StackSymbolOrdering) 74ac1d23edSserge-sans-paille CGOPT(bool, StackRealign) 75ac1d23edSserge-sans-paille CGOPT(std::string, TrapFuncName) 76ac1d23edSserge-sans-paille CGOPT(bool, UseCtors) 77ac1d23edSserge-sans-paille CGOPT(bool, RelaxELFRelocations) 78ac1d23edSserge-sans-paille CGOPT_EXP(bool, DataSections) 79ac1d23edSserge-sans-paille CGOPT_EXP(bool, FunctionSections) 8092bca128Sdiggerlin CGOPT(bool, IgnoreXCOFFVisibility) 81997d286fSdiggerlin CGOPT(bool, XCOFFTracebackTable) 82ac1d23edSserge-sans-paille CGOPT(std::string, BBSections) 83ac1d23edSserge-sans-paille CGOPT(unsigned, TLSSize) 84ac1d23edSserge-sans-paille CGOPT(bool, EmulatedTLS) 85ac1d23edSserge-sans-paille CGOPT(bool, UniqueSectionNames) 86e0bca46bSSriraman Tallam CGOPT(bool, UniqueBasicBlockSectionNames) 87ac1d23edSserge-sans-paille CGOPT(EABI, EABIVersion) 88ac1d23edSserge-sans-paille CGOPT(DebuggerKind, DebuggerTuningOpt) 89ac1d23edSserge-sans-paille CGOPT(bool, EnableStackSizeSection) 90ac1d23edSserge-sans-paille CGOPT(bool, EnableAddrsig) 91ac1d23edSserge-sans-paille CGOPT(bool, EmitCallSiteInfo) 9294faadacSSnehasish Kumar CGOPT(bool, EnableMachineFunctionSplitter) 93ac1d23edSserge-sans-paille CGOPT(bool, EnableDebugEntryValues) 94ac1d23edSserge-sans-paille CGOPT(bool, ForceDwarfFrameSection) 957c7c8e0dSIan Levesque CGOPT(bool, XRayOmitFunctionIndex) 96a0ca4c46SChen Zheng CGOPT(bool, DebugStrictDwarf) 97a1944386SFangrui Song CGOPT(unsigned, AlignLoops) 98ac1d23edSserge-sans-paille 99ac1d23edSserge-sans-paille codegen::RegisterCodeGenFlags::RegisterCodeGenFlags() { 100ac1d23edSserge-sans-paille #define CGBINDOPT(NAME) \ 101ac1d23edSserge-sans-paille do { \ 102ac1d23edSserge-sans-paille NAME##View = std::addressof(NAME); \ 103ac1d23edSserge-sans-paille } while (0) 104ac1d23edSserge-sans-paille 105ac1d23edSserge-sans-paille static cl::opt<std::string> MArch( 106ac1d23edSserge-sans-paille "march", cl::desc("Architecture to generate code for (see --version)")); 107ac1d23edSserge-sans-paille CGBINDOPT(MArch); 108ac1d23edSserge-sans-paille 109ac1d23edSserge-sans-paille static cl::opt<std::string> MCPU( 110ac1d23edSserge-sans-paille "mcpu", cl::desc("Target a specific cpu type (-mcpu=help for details)"), 111ac1d23edSserge-sans-paille cl::value_desc("cpu-name"), cl::init("")); 112ac1d23edSserge-sans-paille CGBINDOPT(MCPU); 113ac1d23edSserge-sans-paille 114ac1d23edSserge-sans-paille static cl::list<std::string> MAttrs( 115ac1d23edSserge-sans-paille "mattr", cl::CommaSeparated, 116ac1d23edSserge-sans-paille cl::desc("Target specific attributes (-mattr=help for details)"), 117ac1d23edSserge-sans-paille cl::value_desc("a1,+a2,-a3,...")); 118ac1d23edSserge-sans-paille CGBINDOPT(MAttrs); 119ac1d23edSserge-sans-paille 120ac1d23edSserge-sans-paille static cl::opt<Reloc::Model> RelocModel( 121ac1d23edSserge-sans-paille "relocation-model", cl::desc("Choose relocation model"), 122ac1d23edSserge-sans-paille cl::values( 123ac1d23edSserge-sans-paille clEnumValN(Reloc::Static, "static", "Non-relocatable code"), 124ac1d23edSserge-sans-paille clEnumValN(Reloc::PIC_, "pic", 125ac1d23edSserge-sans-paille "Fully relocatable, position independent code"), 126ac1d23edSserge-sans-paille clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic", 127ac1d23edSserge-sans-paille "Relocatable external references, non-relocatable code"), 128ac1d23edSserge-sans-paille clEnumValN( 129ac1d23edSserge-sans-paille Reloc::ROPI, "ropi", 130ac1d23edSserge-sans-paille "Code and read-only data relocatable, accessed PC-relative"), 131ac1d23edSserge-sans-paille clEnumValN( 132ac1d23edSserge-sans-paille Reloc::RWPI, "rwpi", 133ac1d23edSserge-sans-paille "Read-write data relocatable, accessed relative to static base"), 134ac1d23edSserge-sans-paille clEnumValN(Reloc::ROPI_RWPI, "ropi-rwpi", 135ac1d23edSserge-sans-paille "Combination of ropi and rwpi"))); 136ac1d23edSserge-sans-paille CGBINDOPT(RelocModel); 137ac1d23edSserge-sans-paille 138ac1d23edSserge-sans-paille static cl::opt<ThreadModel::Model> ThreadModel( 139ac1d23edSserge-sans-paille "thread-model", cl::desc("Choose threading model"), 140ac1d23edSserge-sans-paille cl::init(ThreadModel::POSIX), 141ac1d23edSserge-sans-paille cl::values( 142ac1d23edSserge-sans-paille clEnumValN(ThreadModel::POSIX, "posix", "POSIX thread model"), 143ac1d23edSserge-sans-paille clEnumValN(ThreadModel::Single, "single", "Single thread model"))); 144ac1d23edSserge-sans-paille CGBINDOPT(ThreadModel); 145ac1d23edSserge-sans-paille 146ac1d23edSserge-sans-paille static cl::opt<CodeModel::Model> CodeModel( 147ac1d23edSserge-sans-paille "code-model", cl::desc("Choose code model"), 148ac1d23edSserge-sans-paille cl::values(clEnumValN(CodeModel::Tiny, "tiny", "Tiny code model"), 149ac1d23edSserge-sans-paille clEnumValN(CodeModel::Small, "small", "Small code model"), 150ac1d23edSserge-sans-paille clEnumValN(CodeModel::Kernel, "kernel", "Kernel code model"), 151ac1d23edSserge-sans-paille clEnumValN(CodeModel::Medium, "medium", "Medium code model"), 152ac1d23edSserge-sans-paille clEnumValN(CodeModel::Large, "large", "Large code model"))); 153ac1d23edSserge-sans-paille CGBINDOPT(CodeModel); 154ac1d23edSserge-sans-paille 155ac1d23edSserge-sans-paille static cl::opt<ExceptionHandling> ExceptionModel( 156ac1d23edSserge-sans-paille "exception-model", cl::desc("exception model"), 157ac1d23edSserge-sans-paille cl::init(ExceptionHandling::None), 158ac1d23edSserge-sans-paille cl::values( 159ac1d23edSserge-sans-paille clEnumValN(ExceptionHandling::None, "default", 160ac1d23edSserge-sans-paille "default exception handling model"), 161ac1d23edSserge-sans-paille clEnumValN(ExceptionHandling::DwarfCFI, "dwarf", 162ac1d23edSserge-sans-paille "DWARF-like CFI based exception handling"), 163ac1d23edSserge-sans-paille clEnumValN(ExceptionHandling::SjLj, "sjlj", 164ac1d23edSserge-sans-paille "SjLj exception handling"), 165ac1d23edSserge-sans-paille clEnumValN(ExceptionHandling::ARM, "arm", "ARM EHABI exceptions"), 166ac1d23edSserge-sans-paille clEnumValN(ExceptionHandling::WinEH, "wineh", 167ac1d23edSserge-sans-paille "Windows exception model"), 168ac1d23edSserge-sans-paille clEnumValN(ExceptionHandling::Wasm, "wasm", 169ac1d23edSserge-sans-paille "WebAssembly exception handling"))); 170ac1d23edSserge-sans-paille CGBINDOPT(ExceptionModel); 171ac1d23edSserge-sans-paille 172ac1d23edSserge-sans-paille static cl::opt<CodeGenFileType> FileType( 173ac1d23edSserge-sans-paille "filetype", cl::init(CGFT_AssemblyFile), 174ac1d23edSserge-sans-paille cl::desc( 175ac1d23edSserge-sans-paille "Choose a file type (not all types are supported by all targets):"), 176ac1d23edSserge-sans-paille cl::values( 177ac1d23edSserge-sans-paille clEnumValN(CGFT_AssemblyFile, "asm", "Emit an assembly ('.s') file"), 178ac1d23edSserge-sans-paille clEnumValN(CGFT_ObjectFile, "obj", 179ac1d23edSserge-sans-paille "Emit a native object ('.o') file"), 180ac1d23edSserge-sans-paille clEnumValN(CGFT_Null, "null", 181ac1d23edSserge-sans-paille "Emit nothing, for performance testing"))); 182ac1d23edSserge-sans-paille CGBINDOPT(FileType); 183ac1d23edSserge-sans-paille 1842786e673SFangrui Song static cl::opt<FramePointerKind> FramePointerUsage( 185ac1d23edSserge-sans-paille "frame-pointer", 186ac1d23edSserge-sans-paille cl::desc("Specify frame pointer elimination optimization"), 1872786e673SFangrui Song cl::init(FramePointerKind::None), 188ac1d23edSserge-sans-paille cl::values( 1892786e673SFangrui Song clEnumValN(FramePointerKind::All, "all", 190ac1d23edSserge-sans-paille "Disable frame pointer elimination"), 1912786e673SFangrui Song clEnumValN(FramePointerKind::NonLeaf, "non-leaf", 192ac1d23edSserge-sans-paille "Disable frame pointer elimination for non-leaf frame"), 1932786e673SFangrui Song clEnumValN(FramePointerKind::None, "none", 194ac1d23edSserge-sans-paille "Enable frame pointer elimination"))); 195ac1d23edSserge-sans-paille CGBINDOPT(FramePointerUsage); 196ac1d23edSserge-sans-paille 197ac1d23edSserge-sans-paille static cl::opt<bool> EnableUnsafeFPMath( 198ac1d23edSserge-sans-paille "enable-unsafe-fp-math", 199ac1d23edSserge-sans-paille cl::desc("Enable optimizations that may decrease FP precision"), 200ac1d23edSserge-sans-paille cl::init(false)); 201ac1d23edSserge-sans-paille CGBINDOPT(EnableUnsafeFPMath); 202ac1d23edSserge-sans-paille 203ac1d23edSserge-sans-paille static cl::opt<bool> EnableNoInfsFPMath( 204ac1d23edSserge-sans-paille "enable-no-infs-fp-math", 205ac1d23edSserge-sans-paille cl::desc("Enable FP math optimizations that assume no +-Infs"), 206ac1d23edSserge-sans-paille cl::init(false)); 207ac1d23edSserge-sans-paille CGBINDOPT(EnableNoInfsFPMath); 208ac1d23edSserge-sans-paille 209ac1d23edSserge-sans-paille static cl::opt<bool> EnableNoNaNsFPMath( 210ac1d23edSserge-sans-paille "enable-no-nans-fp-math", 211ac1d23edSserge-sans-paille cl::desc("Enable FP math optimizations that assume no NaNs"), 212ac1d23edSserge-sans-paille cl::init(false)); 213ac1d23edSserge-sans-paille CGBINDOPT(EnableNoNaNsFPMath); 214ac1d23edSserge-sans-paille 215ac1d23edSserge-sans-paille static cl::opt<bool> EnableNoSignedZerosFPMath( 216ac1d23edSserge-sans-paille "enable-no-signed-zeros-fp-math", 217ac1d23edSserge-sans-paille cl::desc("Enable FP math optimizations that assume " 218ac1d23edSserge-sans-paille "the sign of 0 is insignificant"), 219ac1d23edSserge-sans-paille cl::init(false)); 220ac1d23edSserge-sans-paille CGBINDOPT(EnableNoSignedZerosFPMath); 221ac1d23edSserge-sans-paille 222*256d2533SMasoud Ataei static cl::opt<bool> EnableApproxFuncFPMath( 223*256d2533SMasoud Ataei "enable-approx-func-fp-math", 224*256d2533SMasoud Ataei cl::desc("Enable FP math optimizations that assume approx func"), 225*256d2533SMasoud Ataei cl::init(false)); 226*256d2533SMasoud Ataei CGBINDOPT(EnableApproxFuncFPMath); 227*256d2533SMasoud Ataei 228ac1d23edSserge-sans-paille static cl::opt<bool> EnableNoTrappingFPMath( 229ac1d23edSserge-sans-paille "enable-no-trapping-fp-math", 230ac1d23edSserge-sans-paille cl::desc("Enable setting the FP exceptions build " 231ac1d23edSserge-sans-paille "attribute not to use exceptions"), 232ac1d23edSserge-sans-paille cl::init(false)); 233ac1d23edSserge-sans-paille CGBINDOPT(EnableNoTrappingFPMath); 234ac1d23edSserge-sans-paille 235a8cc9047SMatt Arsenault static const auto DenormFlagEnumOptions = 236a8cc9047SMatt Arsenault cl::values(clEnumValN(DenormalMode::IEEE, "ieee", 237a8cc9047SMatt Arsenault "IEEE 754 denormal numbers"), 2380ab5b5b8SMatt Arsenault clEnumValN(DenormalMode::PreserveSign, "preserve-sign", 239ac1d23edSserge-sans-paille "the sign of a flushed-to-zero number is preserved " 240ac1d23edSserge-sans-paille "in the sign of 0"), 2410ab5b5b8SMatt Arsenault clEnumValN(DenormalMode::PositiveZero, "positive-zero", 242a8cc9047SMatt Arsenault "denormals are flushed to positive zero")); 243a8cc9047SMatt Arsenault 244a8cc9047SMatt Arsenault // FIXME: Doesn't have way to specify separate input and output modes. 245a8cc9047SMatt Arsenault static cl::opt<DenormalMode::DenormalModeKind> DenormalFPMath( 246a8cc9047SMatt Arsenault "denormal-fp-math", 247a8cc9047SMatt Arsenault cl::desc("Select which denormal numbers the code is permitted to require"), 248a8cc9047SMatt Arsenault cl::init(DenormalMode::IEEE), 249a8cc9047SMatt Arsenault DenormFlagEnumOptions); 250ac1d23edSserge-sans-paille CGBINDOPT(DenormalFPMath); 251ac1d23edSserge-sans-paille 252a8cc9047SMatt Arsenault static cl::opt<DenormalMode::DenormalModeKind> DenormalFP32Math( 253a8cc9047SMatt Arsenault "denormal-fp-math-f32", 254a8cc9047SMatt Arsenault cl::desc("Select which denormal numbers the code is permitted to require for float"), 255a8cc9047SMatt Arsenault cl::init(DenormalMode::Invalid), 256a8cc9047SMatt Arsenault DenormFlagEnumOptions); 257a8cc9047SMatt Arsenault CGBINDOPT(DenormalFP32Math); 258a8cc9047SMatt Arsenault 259ac1d23edSserge-sans-paille static cl::opt<bool> EnableHonorSignDependentRoundingFPMath( 260ac1d23edSserge-sans-paille "enable-sign-dependent-rounding-fp-math", cl::Hidden, 261ac1d23edSserge-sans-paille cl::desc("Force codegen to assume rounding mode can change dynamically"), 262ac1d23edSserge-sans-paille cl::init(false)); 263ac1d23edSserge-sans-paille CGBINDOPT(EnableHonorSignDependentRoundingFPMath); 264ac1d23edSserge-sans-paille 265ac1d23edSserge-sans-paille static cl::opt<FloatABI::ABIType> FloatABIForCalls( 266ac1d23edSserge-sans-paille "float-abi", cl::desc("Choose float ABI type"), 267ac1d23edSserge-sans-paille cl::init(FloatABI::Default), 268ac1d23edSserge-sans-paille cl::values(clEnumValN(FloatABI::Default, "default", 269ac1d23edSserge-sans-paille "Target default float ABI type"), 270ac1d23edSserge-sans-paille clEnumValN(FloatABI::Soft, "soft", 271ac1d23edSserge-sans-paille "Soft float ABI (implied by -soft-float)"), 272ac1d23edSserge-sans-paille clEnumValN(FloatABI::Hard, "hard", 273ac1d23edSserge-sans-paille "Hard float ABI (uses FP registers)"))); 274ac1d23edSserge-sans-paille CGBINDOPT(FloatABIForCalls); 275ac1d23edSserge-sans-paille 276ac1d23edSserge-sans-paille static cl::opt<FPOpFusion::FPOpFusionMode> FuseFPOps( 277ac1d23edSserge-sans-paille "fp-contract", cl::desc("Enable aggressive formation of fused FP ops"), 278ac1d23edSserge-sans-paille cl::init(FPOpFusion::Standard), 279ac1d23edSserge-sans-paille cl::values( 280ac1d23edSserge-sans-paille clEnumValN(FPOpFusion::Fast, "fast", 281ac1d23edSserge-sans-paille "Fuse FP ops whenever profitable"), 282ac1d23edSserge-sans-paille clEnumValN(FPOpFusion::Standard, "on", "Only fuse 'blessed' FP ops."), 283ac1d23edSserge-sans-paille clEnumValN(FPOpFusion::Strict, "off", 284ac1d23edSserge-sans-paille "Only fuse FP ops when the result won't be affected."))); 285ac1d23edSserge-sans-paille CGBINDOPT(FuseFPOps); 286ac1d23edSserge-sans-paille 287a773db7dSDoug Gregor static cl::opt<SwiftAsyncFramePointerMode> SwiftAsyncFramePointer( 288a773db7dSDoug Gregor "swift-async-fp", 289a773db7dSDoug Gregor cl::desc("Determine when the Swift async frame pointer should be set"), 290a773db7dSDoug Gregor cl::init(SwiftAsyncFramePointerMode::Always), 291a773db7dSDoug Gregor cl::values(clEnumValN(SwiftAsyncFramePointerMode::DeploymentBased, "auto", 292a773db7dSDoug Gregor "Determine based on deployment target"), 293a773db7dSDoug Gregor clEnumValN(SwiftAsyncFramePointerMode::Always, "always", 294a773db7dSDoug Gregor "Always set the bit"), 295a773db7dSDoug Gregor clEnumValN(SwiftAsyncFramePointerMode::Never, "never", 296a773db7dSDoug Gregor "Never set the bit"))); 297a773db7dSDoug Gregor CGBINDOPT(SwiftAsyncFramePointer); 298a773db7dSDoug Gregor 299ac1d23edSserge-sans-paille static cl::opt<bool> DontPlaceZerosInBSS( 300ac1d23edSserge-sans-paille "nozero-initialized-in-bss", 301ac1d23edSserge-sans-paille cl::desc("Don't place zero-initialized symbols into bss section"), 302ac1d23edSserge-sans-paille cl::init(false)); 303ac1d23edSserge-sans-paille CGBINDOPT(DontPlaceZerosInBSS); 304ac1d23edSserge-sans-paille 305c92f29b0SZarko Todorovski static cl::opt<bool> EnableAIXExtendedAltivecABI( 306c92f29b0SZarko Todorovski "vec-extabi", cl::desc("Enable the AIX Extended Altivec ABI."), 307c92f29b0SZarko Todorovski cl::init(false)); 308c92f29b0SZarko Todorovski CGBINDOPT(EnableAIXExtendedAltivecABI); 309c92f29b0SZarko Todorovski 310ac1d23edSserge-sans-paille static cl::opt<bool> EnableGuaranteedTailCallOpt( 311ac1d23edSserge-sans-paille "tailcallopt", 312ac1d23edSserge-sans-paille cl::desc( 313ac1d23edSserge-sans-paille "Turn fastcc calls into tail calls by (potentially) changing ABI."), 314ac1d23edSserge-sans-paille cl::init(false)); 315ac1d23edSserge-sans-paille CGBINDOPT(EnableGuaranteedTailCallOpt); 316ac1d23edSserge-sans-paille 317ac1d23edSserge-sans-paille static cl::opt<bool> DisableTailCalls( 318ac1d23edSserge-sans-paille "disable-tail-calls", cl::desc("Never emit tail calls"), cl::init(false)); 319ac1d23edSserge-sans-paille CGBINDOPT(DisableTailCalls); 320ac1d23edSserge-sans-paille 321ac1d23edSserge-sans-paille static cl::opt<bool> StackSymbolOrdering( 322ac1d23edSserge-sans-paille "stack-symbol-ordering", cl::desc("Order local stack symbols."), 323ac1d23edSserge-sans-paille cl::init(true)); 324ac1d23edSserge-sans-paille CGBINDOPT(StackSymbolOrdering); 325ac1d23edSserge-sans-paille 326ac1d23edSserge-sans-paille static cl::opt<bool> StackRealign( 327ac1d23edSserge-sans-paille "stackrealign", 328ac1d23edSserge-sans-paille cl::desc("Force align the stack to the minimum alignment"), 329ac1d23edSserge-sans-paille cl::init(false)); 330ac1d23edSserge-sans-paille CGBINDOPT(StackRealign); 331ac1d23edSserge-sans-paille 332ac1d23edSserge-sans-paille static cl::opt<std::string> TrapFuncName( 333ac1d23edSserge-sans-paille "trap-func", cl::Hidden, 334ac1d23edSserge-sans-paille cl::desc("Emit a call to trap function rather than a trap instruction"), 335ac1d23edSserge-sans-paille cl::init("")); 336ac1d23edSserge-sans-paille CGBINDOPT(TrapFuncName); 337ac1d23edSserge-sans-paille 338ac1d23edSserge-sans-paille static cl::opt<bool> UseCtors("use-ctors", 339ac1d23edSserge-sans-paille cl::desc("Use .ctors instead of .init_array."), 340ac1d23edSserge-sans-paille cl::init(false)); 341ac1d23edSserge-sans-paille CGBINDOPT(UseCtors); 342ac1d23edSserge-sans-paille 343ac1d23edSserge-sans-paille static cl::opt<bool> RelaxELFRelocations( 344ac1d23edSserge-sans-paille "relax-elf-relocations", 345ac1d23edSserge-sans-paille cl::desc( 346ac1d23edSserge-sans-paille "Emit GOTPCRELX/REX_GOTPCRELX instead of GOTPCREL on x86-64 ELF"), 347ac1d23edSserge-sans-paille cl::init(false)); 348ac1d23edSserge-sans-paille CGBINDOPT(RelaxELFRelocations); 349ac1d23edSserge-sans-paille 350ac1d23edSserge-sans-paille static cl::opt<bool> DataSections( 351ac1d23edSserge-sans-paille "data-sections", cl::desc("Emit data into separate sections"), 352ac1d23edSserge-sans-paille cl::init(false)); 353ac1d23edSserge-sans-paille CGBINDOPT(DataSections); 354ac1d23edSserge-sans-paille 355ac1d23edSserge-sans-paille static cl::opt<bool> FunctionSections( 356ac1d23edSserge-sans-paille "function-sections", cl::desc("Emit functions into separate sections"), 357ac1d23edSserge-sans-paille cl::init(false)); 358ac1d23edSserge-sans-paille CGBINDOPT(FunctionSections); 359ac1d23edSserge-sans-paille 36092bca128Sdiggerlin static cl::opt<bool> IgnoreXCOFFVisibility( 36192bca128Sdiggerlin "ignore-xcoff-visibility", 36292bca128Sdiggerlin cl::desc("Not emit the visibility attribute for asm in AIX OS or give " 36392bca128Sdiggerlin "all symbols 'unspecified' visibility in XCOFF object file"), 36492bca128Sdiggerlin cl::init(false)); 36592bca128Sdiggerlin CGBINDOPT(IgnoreXCOFFVisibility); 36692bca128Sdiggerlin 367997d286fSdiggerlin static cl::opt<bool> XCOFFTracebackTable( 368997d286fSdiggerlin "xcoff-traceback-table", cl::desc("Emit the XCOFF traceback table"), 369997d286fSdiggerlin cl::init(true)); 370997d286fSdiggerlin CGBINDOPT(XCOFFTracebackTable); 371997d286fSdiggerlin 372ac1d23edSserge-sans-paille static cl::opt<std::string> BBSections( 373ca6b6d40SSriraman Tallam "basic-block-sections", 374ac1d23edSserge-sans-paille cl::desc("Emit basic blocks into separate sections"), 375ac1d23edSserge-sans-paille cl::value_desc("all | <function list (file)> | labels | none"), 376ac1d23edSserge-sans-paille cl::init("none")); 377ac1d23edSserge-sans-paille CGBINDOPT(BBSections); 378ac1d23edSserge-sans-paille 379ac1d23edSserge-sans-paille static cl::opt<unsigned> TLSSize( 380ac1d23edSserge-sans-paille "tls-size", cl::desc("Bit size of immediate TLS offsets"), cl::init(0)); 381ac1d23edSserge-sans-paille CGBINDOPT(TLSSize); 382ac1d23edSserge-sans-paille 383ac1d23edSserge-sans-paille static cl::opt<bool> EmulatedTLS( 384ac1d23edSserge-sans-paille "emulated-tls", cl::desc("Use emulated TLS model"), cl::init(false)); 385ac1d23edSserge-sans-paille CGBINDOPT(EmulatedTLS); 386ac1d23edSserge-sans-paille 387ac1d23edSserge-sans-paille static cl::opt<bool> UniqueSectionNames( 388ac1d23edSserge-sans-paille "unique-section-names", cl::desc("Give unique names to every section"), 389ac1d23edSserge-sans-paille cl::init(true)); 390ac1d23edSserge-sans-paille CGBINDOPT(UniqueSectionNames); 391ac1d23edSserge-sans-paille 392e0bca46bSSriraman Tallam static cl::opt<bool> UniqueBasicBlockSectionNames( 393ca6b6d40SSriraman Tallam "unique-basic-block-section-names", 394ac1d23edSserge-sans-paille cl::desc("Give unique names to every basic block section"), 395ac1d23edSserge-sans-paille cl::init(false)); 396e0bca46bSSriraman Tallam CGBINDOPT(UniqueBasicBlockSectionNames); 397ac1d23edSserge-sans-paille 398ac1d23edSserge-sans-paille static cl::opt<EABI> EABIVersion( 399ac1d23edSserge-sans-paille "meabi", cl::desc("Set EABI type (default depends on triple):"), 400ac1d23edSserge-sans-paille cl::init(EABI::Default), 401ac1d23edSserge-sans-paille cl::values( 402ac1d23edSserge-sans-paille clEnumValN(EABI::Default, "default", "Triple default EABI version"), 403ac1d23edSserge-sans-paille clEnumValN(EABI::EABI4, "4", "EABI version 4"), 404ac1d23edSserge-sans-paille clEnumValN(EABI::EABI5, "5", "EABI version 5"), 405ac1d23edSserge-sans-paille clEnumValN(EABI::GNU, "gnu", "EABI GNU"))); 406ac1d23edSserge-sans-paille CGBINDOPT(EABIVersion); 407ac1d23edSserge-sans-paille 408ac1d23edSserge-sans-paille static cl::opt<DebuggerKind> DebuggerTuningOpt( 409ac1d23edSserge-sans-paille "debugger-tune", cl::desc("Tune debug info for a particular debugger"), 410ac1d23edSserge-sans-paille cl::init(DebuggerKind::Default), 411ac1d23edSserge-sans-paille cl::values( 412ac1d23edSserge-sans-paille clEnumValN(DebuggerKind::GDB, "gdb", "gdb"), 413ac1d23edSserge-sans-paille clEnumValN(DebuggerKind::LLDB, "lldb", "lldb"), 4140c36da72SEsme-Yi clEnumValN(DebuggerKind::DBX, "dbx", "dbx"), 415ac1d23edSserge-sans-paille clEnumValN(DebuggerKind::SCE, "sce", "SCE targets (e.g. PS4)"))); 416ac1d23edSserge-sans-paille CGBINDOPT(DebuggerTuningOpt); 417ac1d23edSserge-sans-paille 418ac1d23edSserge-sans-paille static cl::opt<bool> EnableStackSizeSection( 419ac1d23edSserge-sans-paille "stack-size-section", 420ac1d23edSserge-sans-paille cl::desc("Emit a section containing stack size metadata"), 421ac1d23edSserge-sans-paille cl::init(false)); 422ac1d23edSserge-sans-paille CGBINDOPT(EnableStackSizeSection); 423ac1d23edSserge-sans-paille 424ac1d23edSserge-sans-paille static cl::opt<bool> EnableAddrsig( 425ac1d23edSserge-sans-paille "addrsig", cl::desc("Emit an address-significance table"), 426ac1d23edSserge-sans-paille cl::init(false)); 427ac1d23edSserge-sans-paille CGBINDOPT(EnableAddrsig); 428ac1d23edSserge-sans-paille 429ac1d23edSserge-sans-paille static cl::opt<bool> EmitCallSiteInfo( 430ac1d23edSserge-sans-paille "emit-call-site-info", 431ac1d23edSserge-sans-paille cl::desc( 432ac1d23edSserge-sans-paille "Emit call site debug information, if debug information is enabled."), 433ac1d23edSserge-sans-paille cl::init(false)); 434ac1d23edSserge-sans-paille CGBINDOPT(EmitCallSiteInfo); 435ac1d23edSserge-sans-paille 436ac1d23edSserge-sans-paille static cl::opt<bool> EnableDebugEntryValues( 437ac1d23edSserge-sans-paille "debug-entry-values", 438d9b96210SDjordje Todorovic cl::desc("Enable debug info for the debug entry values."), 439ac1d23edSserge-sans-paille cl::init(false)); 440ac1d23edSserge-sans-paille CGBINDOPT(EnableDebugEntryValues); 441ac1d23edSserge-sans-paille 44294faadacSSnehasish Kumar static cl::opt<bool> EnableMachineFunctionSplitter( 44394faadacSSnehasish Kumar "split-machine-functions", 44494faadacSSnehasish Kumar cl::desc("Split out cold basic blocks from machine functions based on " 44594faadacSSnehasish Kumar "profile information"), 44694faadacSSnehasish Kumar cl::init(false)); 44794faadacSSnehasish Kumar CGBINDOPT(EnableMachineFunctionSplitter); 44894faadacSSnehasish Kumar 449ac1d23edSserge-sans-paille static cl::opt<bool> ForceDwarfFrameSection( 450ac1d23edSserge-sans-paille "force-dwarf-frame-section", 451ac1d23edSserge-sans-paille cl::desc("Always emit a debug frame section."), cl::init(false)); 452ac1d23edSserge-sans-paille CGBINDOPT(ForceDwarfFrameSection); 453ac1d23edSserge-sans-paille 4547c7c8e0dSIan Levesque static cl::opt<bool> XRayOmitFunctionIndex( 4557c7c8e0dSIan Levesque "no-xray-index", cl::desc("Don't emit xray_fn_idx section"), 4567c7c8e0dSIan Levesque cl::init(false)); 4577c7c8e0dSIan Levesque CGBINDOPT(XRayOmitFunctionIndex); 4587c7c8e0dSIan Levesque 459a0ca4c46SChen Zheng static cl::opt<bool> DebugStrictDwarf( 460a0ca4c46SChen Zheng "strict-dwarf", cl::desc("use strict dwarf"), cl::init(false)); 461a0ca4c46SChen Zheng CGBINDOPT(DebugStrictDwarf); 462a0ca4c46SChen Zheng 463a1944386SFangrui Song static cl::opt<unsigned> AlignLoops("align-loops", 464a1944386SFangrui Song cl::desc("Default alignment for loops")); 465a1944386SFangrui Song CGBINDOPT(AlignLoops); 466a1944386SFangrui Song 467ac1d23edSserge-sans-paille #undef CGBINDOPT 468ac1d23edSserge-sans-paille 469ac1d23edSserge-sans-paille mc::RegisterMCTargetOptionsFlags(); 470ac1d23edSserge-sans-paille } 471ac1d23edSserge-sans-paille 472ac1d23edSserge-sans-paille llvm::BasicBlockSection 473ac1d23edSserge-sans-paille codegen::getBBSectionsMode(llvm::TargetOptions &Options) { 474ac1d23edSserge-sans-paille if (getBBSections() == "all") 475ac1d23edSserge-sans-paille return BasicBlockSection::All; 476ac1d23edSserge-sans-paille else if (getBBSections() == "labels") 477ac1d23edSserge-sans-paille return BasicBlockSection::Labels; 478ac1d23edSserge-sans-paille else if (getBBSections() == "none") 479ac1d23edSserge-sans-paille return BasicBlockSection::None; 480ac1d23edSserge-sans-paille else { 481ac1d23edSserge-sans-paille ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr = 482ac1d23edSserge-sans-paille MemoryBuffer::getFile(getBBSections()); 483ac1d23edSserge-sans-paille if (!MBOrErr) { 484ac1d23edSserge-sans-paille errs() << "Error loading basic block sections function list file: " 485ac1d23edSserge-sans-paille << MBOrErr.getError().message() << "\n"; 486ac1d23edSserge-sans-paille } else { 487ac1d23edSserge-sans-paille Options.BBSectionsFuncListBuf = std::move(*MBOrErr); 488ac1d23edSserge-sans-paille } 489ac1d23edSserge-sans-paille return BasicBlockSection::List; 490ac1d23edSserge-sans-paille } 491ac1d23edSserge-sans-paille } 492ac1d23edSserge-sans-paille 493ac1d23edSserge-sans-paille // Common utility function tightly tied to the options listed here. Initializes 494ac1d23edSserge-sans-paille // a TargetOptions object with CodeGen flags and returns it. 495f85bcc21Sjasonliu TargetOptions 496f85bcc21Sjasonliu codegen::InitTargetOptionsFromCodeGenFlags(const Triple &TheTriple) { 497ac1d23edSserge-sans-paille TargetOptions Options; 498ac1d23edSserge-sans-paille Options.AllowFPOpFusion = getFuseFPOps(); 499ac1d23edSserge-sans-paille Options.UnsafeFPMath = getEnableUnsafeFPMath(); 500ac1d23edSserge-sans-paille Options.NoInfsFPMath = getEnableNoInfsFPMath(); 501ac1d23edSserge-sans-paille Options.NoNaNsFPMath = getEnableNoNaNsFPMath(); 502ac1d23edSserge-sans-paille Options.NoSignedZerosFPMath = getEnableNoSignedZerosFPMath(); 503*256d2533SMasoud Ataei Options.ApproxFuncFPMath = getEnableApproxFuncFPMath(); 504ac1d23edSserge-sans-paille Options.NoTrappingFPMath = getEnableNoTrappingFPMath(); 5050ab5b5b8SMatt Arsenault 5060ab5b5b8SMatt Arsenault DenormalMode::DenormalModeKind DenormKind = getDenormalFPMath(); 5070ab5b5b8SMatt Arsenault 5080ab5b5b8SMatt Arsenault // FIXME: Should have separate input and output flags 5090ab5b5b8SMatt Arsenault Options.setFPDenormalMode(DenormalMode(DenormKind, DenormKind)); 5100ab5b5b8SMatt Arsenault 511ac1d23edSserge-sans-paille Options.HonorSignDependentRoundingFPMathOption = 512ac1d23edSserge-sans-paille getEnableHonorSignDependentRoundingFPMath(); 513ac1d23edSserge-sans-paille if (getFloatABIForCalls() != FloatABI::Default) 514ac1d23edSserge-sans-paille Options.FloatABIType = getFloatABIForCalls(); 515c92f29b0SZarko Todorovski Options.EnableAIXExtendedAltivecABI = getEnableAIXExtendedAltivecABI(); 516ac1d23edSserge-sans-paille Options.NoZerosInBSS = getDontPlaceZerosInBSS(); 517ac1d23edSserge-sans-paille Options.GuaranteedTailCallOpt = getEnableGuaranteedTailCallOpt(); 518ac1d23edSserge-sans-paille Options.StackSymbolOrdering = getStackSymbolOrdering(); 519ac1d23edSserge-sans-paille Options.UseInitArray = !getUseCtors(); 520ac1d23edSserge-sans-paille Options.RelaxELFRelocations = getRelaxELFRelocations(); 521f85bcc21Sjasonliu Options.DataSections = 522f85bcc21Sjasonliu getExplicitDataSections().getValueOr(TheTriple.hasDefaultDataSections()); 523ac1d23edSserge-sans-paille Options.FunctionSections = getFunctionSections(); 52492bca128Sdiggerlin Options.IgnoreXCOFFVisibility = getIgnoreXCOFFVisibility(); 525997d286fSdiggerlin Options.XCOFFTracebackTable = getXCOFFTracebackTable(); 526ac1d23edSserge-sans-paille Options.BBSections = getBBSectionsMode(Options); 527ac1d23edSserge-sans-paille Options.UniqueSectionNames = getUniqueSectionNames(); 528e0bca46bSSriraman Tallam Options.UniqueBasicBlockSectionNames = getUniqueBasicBlockSectionNames(); 529ac1d23edSserge-sans-paille Options.TLSSize = getTLSSize(); 530ac1d23edSserge-sans-paille Options.EmulatedTLS = getEmulatedTLS(); 531ac1d23edSserge-sans-paille Options.ExplicitEmulatedTLS = EmulatedTLSView->getNumOccurrences() > 0; 532ac1d23edSserge-sans-paille Options.ExceptionModel = getExceptionModel(); 533ac1d23edSserge-sans-paille Options.EmitStackSizeSection = getEnableStackSizeSection(); 53494faadacSSnehasish Kumar Options.EnableMachineFunctionSplitter = getEnableMachineFunctionSplitter(); 535ac1d23edSserge-sans-paille Options.EmitAddrsig = getEnableAddrsig(); 536ac1d23edSserge-sans-paille Options.EmitCallSiteInfo = getEmitCallSiteInfo(); 537ac1d23edSserge-sans-paille Options.EnableDebugEntryValues = getEnableDebugEntryValues(); 538ac1d23edSserge-sans-paille Options.ForceDwarfFrameSection = getForceDwarfFrameSection(); 5397c7c8e0dSIan Levesque Options.XRayOmitFunctionIndex = getXRayOmitFunctionIndex(); 540a0ca4c46SChen Zheng Options.DebugStrictDwarf = getDebugStrictDwarf(); 541a1944386SFangrui Song Options.LoopAlignment = getAlignLoops(); 542ac1d23edSserge-sans-paille 543ac1d23edSserge-sans-paille Options.MCOptions = mc::InitMCTargetOptionsFromFlags(); 544ac1d23edSserge-sans-paille 545ac1d23edSserge-sans-paille Options.ThreadModel = getThreadModel(); 546ac1d23edSserge-sans-paille Options.EABIVersion = getEABIVersion(); 547ac1d23edSserge-sans-paille Options.DebuggerTuning = getDebuggerTuningOpt(); 548a773db7dSDoug Gregor Options.SwiftAsyncFramePointer = getSwiftAsyncFramePointer(); 549ac1d23edSserge-sans-paille return Options; 550ac1d23edSserge-sans-paille } 551ac1d23edSserge-sans-paille 552ac1d23edSserge-sans-paille std::string codegen::getCPUStr() { 553ac1d23edSserge-sans-paille // If user asked for the 'native' CPU, autodetect here. If autodection fails, 554ac1d23edSserge-sans-paille // this will set the CPU to an empty string which tells the target to 555ac1d23edSserge-sans-paille // pick a basic default. 556ac1d23edSserge-sans-paille if (getMCPU() == "native") 557ac1d23edSserge-sans-paille return std::string(sys::getHostCPUName()); 558ac1d23edSserge-sans-paille 559ac1d23edSserge-sans-paille return getMCPU(); 560ac1d23edSserge-sans-paille } 561ac1d23edSserge-sans-paille 562ac1d23edSserge-sans-paille std::string codegen::getFeaturesStr() { 563ac1d23edSserge-sans-paille SubtargetFeatures Features; 564ac1d23edSserge-sans-paille 565ac1d23edSserge-sans-paille // If user asked for the 'native' CPU, we need to autodetect features. 566ac1d23edSserge-sans-paille // This is necessary for x86 where the CPU might not support all the 567ac1d23edSserge-sans-paille // features the autodetected CPU name lists in the target. For example, 568ac1d23edSserge-sans-paille // not all Sandybridge processors support AVX. 569ac1d23edSserge-sans-paille if (getMCPU() == "native") { 570ac1d23edSserge-sans-paille StringMap<bool> HostFeatures; 571ac1d23edSserge-sans-paille if (sys::getHostCPUFeatures(HostFeatures)) 572ac1d23edSserge-sans-paille for (auto &F : HostFeatures) 573ac1d23edSserge-sans-paille Features.AddFeature(F.first(), F.second); 574ac1d23edSserge-sans-paille } 575ac1d23edSserge-sans-paille 576ac1d23edSserge-sans-paille for (auto const &MAttr : getMAttrs()) 577ac1d23edSserge-sans-paille Features.AddFeature(MAttr); 578ac1d23edSserge-sans-paille 579ac1d23edSserge-sans-paille return Features.getString(); 580ac1d23edSserge-sans-paille } 581ac1d23edSserge-sans-paille 582ac1d23edSserge-sans-paille std::vector<std::string> codegen::getFeatureList() { 583ac1d23edSserge-sans-paille SubtargetFeatures Features; 584ac1d23edSserge-sans-paille 585ac1d23edSserge-sans-paille // If user asked for the 'native' CPU, we need to autodetect features. 586ac1d23edSserge-sans-paille // This is necessary for x86 where the CPU might not support all the 587ac1d23edSserge-sans-paille // features the autodetected CPU name lists in the target. For example, 588ac1d23edSserge-sans-paille // not all Sandybridge processors support AVX. 589ac1d23edSserge-sans-paille if (getMCPU() == "native") { 590ac1d23edSserge-sans-paille StringMap<bool> HostFeatures; 591ac1d23edSserge-sans-paille if (sys::getHostCPUFeatures(HostFeatures)) 592ac1d23edSserge-sans-paille for (auto &F : HostFeatures) 593ac1d23edSserge-sans-paille Features.AddFeature(F.first(), F.second); 594ac1d23edSserge-sans-paille } 595ac1d23edSserge-sans-paille 596ac1d23edSserge-sans-paille for (auto const &MAttr : getMAttrs()) 597ac1d23edSserge-sans-paille Features.AddFeature(MAttr); 598ac1d23edSserge-sans-paille 599ac1d23edSserge-sans-paille return Features.getFeatures(); 600ac1d23edSserge-sans-paille } 601ac1d23edSserge-sans-paille 602ac1d23edSserge-sans-paille void codegen::renderBoolStringAttr(AttrBuilder &B, StringRef Name, bool Val) { 603ac1d23edSserge-sans-paille B.addAttribute(Name, Val ? "true" : "false"); 604ac1d23edSserge-sans-paille } 605ac1d23edSserge-sans-paille 606ac1d23edSserge-sans-paille #define HANDLE_BOOL_ATTR(CL, AttrName) \ 607ac1d23edSserge-sans-paille do { \ 608ac1d23edSserge-sans-paille if (CL->getNumOccurrences() > 0 && !F.hasFnAttribute(AttrName)) \ 609ac1d23edSserge-sans-paille renderBoolStringAttr(NewAttrs, AttrName, *CL); \ 610ac1d23edSserge-sans-paille } while (0) 611ac1d23edSserge-sans-paille 612ac1d23edSserge-sans-paille /// Set function attributes of function \p F based on CPU, Features, and command 613ac1d23edSserge-sans-paille /// line flags. 614ac1d23edSserge-sans-paille void codegen::setFunctionAttributes(StringRef CPU, StringRef Features, 615ac1d23edSserge-sans-paille Function &F) { 616ac1d23edSserge-sans-paille auto &Ctx = F.getContext(); 617ac1d23edSserge-sans-paille AttributeList Attrs = F.getAttributes(); 618d2cc6c2dSSerge Guelton AttrBuilder NewAttrs(Ctx); 619ac1d23edSserge-sans-paille 620ac1d23edSserge-sans-paille if (!CPU.empty() && !F.hasFnAttribute("target-cpu")) 621ac1d23edSserge-sans-paille NewAttrs.addAttribute("target-cpu", CPU); 622ac1d23edSserge-sans-paille if (!Features.empty()) { 623ac1d23edSserge-sans-paille // Append the command line features to any that are already on the function. 624ac1d23edSserge-sans-paille StringRef OldFeatures = 625ac1d23edSserge-sans-paille F.getFnAttribute("target-features").getValueAsString(); 626ac1d23edSserge-sans-paille if (OldFeatures.empty()) 627ac1d23edSserge-sans-paille NewAttrs.addAttribute("target-features", Features); 628ac1d23edSserge-sans-paille else { 629ac1d23edSserge-sans-paille SmallString<256> Appended(OldFeatures); 630ac1d23edSserge-sans-paille Appended.push_back(','); 631ac1d23edSserge-sans-paille Appended.append(Features); 632ac1d23edSserge-sans-paille NewAttrs.addAttribute("target-features", Appended); 633ac1d23edSserge-sans-paille } 634ac1d23edSserge-sans-paille } 635ac1d23edSserge-sans-paille if (FramePointerUsageView->getNumOccurrences() > 0 && 636ac1d23edSserge-sans-paille !F.hasFnAttribute("frame-pointer")) { 6372786e673SFangrui Song if (getFramePointerUsage() == FramePointerKind::All) 638ac1d23edSserge-sans-paille NewAttrs.addAttribute("frame-pointer", "all"); 6392786e673SFangrui Song else if (getFramePointerUsage() == FramePointerKind::NonLeaf) 640ac1d23edSserge-sans-paille NewAttrs.addAttribute("frame-pointer", "non-leaf"); 6412786e673SFangrui Song else if (getFramePointerUsage() == FramePointerKind::None) 642ac1d23edSserge-sans-paille NewAttrs.addAttribute("frame-pointer", "none"); 643ac1d23edSserge-sans-paille } 644ac1d23edSserge-sans-paille if (DisableTailCallsView->getNumOccurrences() > 0) 645ac1d23edSserge-sans-paille NewAttrs.addAttribute("disable-tail-calls", 646ac1d23edSserge-sans-paille toStringRef(getDisableTailCalls())); 647ac1d23edSserge-sans-paille if (getStackRealign()) 648ac1d23edSserge-sans-paille NewAttrs.addAttribute("stackrealign"); 649ac1d23edSserge-sans-paille 650ac1d23edSserge-sans-paille HANDLE_BOOL_ATTR(EnableUnsafeFPMathView, "unsafe-fp-math"); 651ac1d23edSserge-sans-paille HANDLE_BOOL_ATTR(EnableNoInfsFPMathView, "no-infs-fp-math"); 652ac1d23edSserge-sans-paille HANDLE_BOOL_ATTR(EnableNoNaNsFPMathView, "no-nans-fp-math"); 653ac1d23edSserge-sans-paille HANDLE_BOOL_ATTR(EnableNoSignedZerosFPMathView, "no-signed-zeros-fp-math"); 654*256d2533SMasoud Ataei HANDLE_BOOL_ATTR(EnableApproxFuncFPMathView, "approx-func-fp-math"); 655ac1d23edSserge-sans-paille 6560ab5b5b8SMatt Arsenault if (DenormalFPMathView->getNumOccurrences() > 0 && 6570ab5b5b8SMatt Arsenault !F.hasFnAttribute("denormal-fp-math")) { 6580ab5b5b8SMatt Arsenault DenormalMode::DenormalModeKind DenormKind = getDenormalFPMath(); 6590ab5b5b8SMatt Arsenault 6600ab5b5b8SMatt Arsenault // FIXME: Command line flag should expose separate input/output modes. 6610ab5b5b8SMatt Arsenault NewAttrs.addAttribute("denormal-fp-math", 6620ab5b5b8SMatt Arsenault DenormalMode(DenormKind, DenormKind).str()); 6630ab5b5b8SMatt Arsenault } 6640ab5b5b8SMatt Arsenault 665a8cc9047SMatt Arsenault if (DenormalFP32MathView->getNumOccurrences() > 0 && 666a8cc9047SMatt Arsenault !F.hasFnAttribute("denormal-fp-math-f32")) { 667a8cc9047SMatt Arsenault // FIXME: Command line flag should expose separate input/output modes. 668a8cc9047SMatt Arsenault DenormalMode::DenormalModeKind DenormKind = getDenormalFP32Math(); 669a8cc9047SMatt Arsenault 670a8cc9047SMatt Arsenault NewAttrs.addAttribute( 671a8cc9047SMatt Arsenault "denormal-fp-math-f32", 672a8cc9047SMatt Arsenault DenormalMode(DenormKind, DenormKind).str()); 673a8cc9047SMatt Arsenault } 674a8cc9047SMatt Arsenault 675ac1d23edSserge-sans-paille if (TrapFuncNameView->getNumOccurrences() > 0) 676ac1d23edSserge-sans-paille for (auto &B : F) 677ac1d23edSserge-sans-paille for (auto &I : B) 678ac1d23edSserge-sans-paille if (auto *Call = dyn_cast<CallInst>(&I)) 679ac1d23edSserge-sans-paille if (const auto *F = Call->getCalledFunction()) 680ac1d23edSserge-sans-paille if (F->getIntrinsicID() == Intrinsic::debugtrap || 681ac1d23edSserge-sans-paille F->getIntrinsicID() == Intrinsic::trap) 6823f4d00bcSArthur Eubanks Call->addFnAttr( 683ac1d23edSserge-sans-paille Attribute::get(Ctx, "trap-func-name", getTrapFuncName())); 684ac1d23edSserge-sans-paille 685ac1d23edSserge-sans-paille // Let NewAttrs override Attrs. 686de0ae9e8SArthur Eubanks F.setAttributes(Attrs.addFnAttributes(Ctx, NewAttrs)); 687ac1d23edSserge-sans-paille } 688ac1d23edSserge-sans-paille 689ac1d23edSserge-sans-paille /// Set function attributes of functions in Module M based on CPU, 690ac1d23edSserge-sans-paille /// Features, and command line flags. 691ac1d23edSserge-sans-paille void codegen::setFunctionAttributes(StringRef CPU, StringRef Features, 692ac1d23edSserge-sans-paille Module &M) { 693ac1d23edSserge-sans-paille for (Function &F : M) 694ac1d23edSserge-sans-paille setFunctionAttributes(CPU, Features, F); 695ac1d23edSserge-sans-paille } 696651122fcSJeremy Morse 697