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) 61ac1d23edSserge-sans-paille CGOPT(bool, EnableNoTrappingFPMath) 62c92f29b0SZarko Todorovski CGOPT(bool, EnableAIXExtendedAltivecABI) 630ab5b5b8SMatt Arsenault CGOPT(DenormalMode::DenormalModeKind, DenormalFPMath) 64a8cc9047SMatt Arsenault CGOPT(DenormalMode::DenormalModeKind, DenormalFP32Math) 65ac1d23edSserge-sans-paille CGOPT(bool, EnableHonorSignDependentRoundingFPMath) 66ac1d23edSserge-sans-paille CGOPT(FloatABI::ABIType, FloatABIForCalls) 67ac1d23edSserge-sans-paille CGOPT(FPOpFusion::FPOpFusionMode, FuseFPOps) 68a773db7dSDoug Gregor CGOPT(SwiftAsyncFramePointerMode, SwiftAsyncFramePointer) 69ac1d23edSserge-sans-paille CGOPT(bool, DontPlaceZerosInBSS) 70ac1d23edSserge-sans-paille CGOPT(bool, EnableGuaranteedTailCallOpt) 71ac1d23edSserge-sans-paille CGOPT(bool, DisableTailCalls) 72ac1d23edSserge-sans-paille CGOPT(bool, StackSymbolOrdering) 73ac1d23edSserge-sans-paille CGOPT(bool, StackRealign) 74ac1d23edSserge-sans-paille CGOPT(std::string, TrapFuncName) 75ac1d23edSserge-sans-paille CGOPT(bool, UseCtors) 76ac1d23edSserge-sans-paille CGOPT(bool, RelaxELFRelocations) 77ac1d23edSserge-sans-paille CGOPT_EXP(bool, DataSections) 78ac1d23edSserge-sans-paille CGOPT_EXP(bool, FunctionSections) 7992bca128Sdiggerlin CGOPT(bool, IgnoreXCOFFVisibility) 80997d286fSdiggerlin CGOPT(bool, XCOFFTracebackTable) 81ac1d23edSserge-sans-paille CGOPT(std::string, BBSections) 82ac1d23edSserge-sans-paille CGOPT(unsigned, TLSSize) 83ac1d23edSserge-sans-paille CGOPT(bool, EmulatedTLS) 84ac1d23edSserge-sans-paille CGOPT(bool, UniqueSectionNames) 85e0bca46bSSriraman Tallam CGOPT(bool, UniqueBasicBlockSectionNames) 86ac1d23edSserge-sans-paille CGOPT(EABI, EABIVersion) 87ac1d23edSserge-sans-paille CGOPT(DebuggerKind, DebuggerTuningOpt) 88ac1d23edSserge-sans-paille CGOPT(bool, EnableStackSizeSection) 89ac1d23edSserge-sans-paille CGOPT(bool, EnableAddrsig) 90ac1d23edSserge-sans-paille CGOPT(bool, EmitCallSiteInfo) 9194faadacSSnehasish Kumar CGOPT(bool, EnableMachineFunctionSplitter) 92ac1d23edSserge-sans-paille CGOPT(bool, EnableDebugEntryValues) 93651122fcSJeremy Morse CGOPT_EXP(bool, ValueTrackingVariableLocations) 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 222ac1d23edSserge-sans-paille static cl::opt<bool> EnableNoTrappingFPMath( 223ac1d23edSserge-sans-paille "enable-no-trapping-fp-math", 224ac1d23edSserge-sans-paille cl::desc("Enable setting the FP exceptions build " 225ac1d23edSserge-sans-paille "attribute not to use exceptions"), 226ac1d23edSserge-sans-paille cl::init(false)); 227ac1d23edSserge-sans-paille CGBINDOPT(EnableNoTrappingFPMath); 228ac1d23edSserge-sans-paille 229a8cc9047SMatt Arsenault static const auto DenormFlagEnumOptions = 230a8cc9047SMatt Arsenault cl::values(clEnumValN(DenormalMode::IEEE, "ieee", 231a8cc9047SMatt Arsenault "IEEE 754 denormal numbers"), 2320ab5b5b8SMatt Arsenault clEnumValN(DenormalMode::PreserveSign, "preserve-sign", 233ac1d23edSserge-sans-paille "the sign of a flushed-to-zero number is preserved " 234ac1d23edSserge-sans-paille "in the sign of 0"), 2350ab5b5b8SMatt Arsenault clEnumValN(DenormalMode::PositiveZero, "positive-zero", 236a8cc9047SMatt Arsenault "denormals are flushed to positive zero")); 237a8cc9047SMatt Arsenault 238a8cc9047SMatt Arsenault // FIXME: Doesn't have way to specify separate input and output modes. 239a8cc9047SMatt Arsenault static cl::opt<DenormalMode::DenormalModeKind> DenormalFPMath( 240a8cc9047SMatt Arsenault "denormal-fp-math", 241a8cc9047SMatt Arsenault cl::desc("Select which denormal numbers the code is permitted to require"), 242a8cc9047SMatt Arsenault cl::init(DenormalMode::IEEE), 243a8cc9047SMatt Arsenault DenormFlagEnumOptions); 244ac1d23edSserge-sans-paille CGBINDOPT(DenormalFPMath); 245ac1d23edSserge-sans-paille 246a8cc9047SMatt Arsenault static cl::opt<DenormalMode::DenormalModeKind> DenormalFP32Math( 247a8cc9047SMatt Arsenault "denormal-fp-math-f32", 248a8cc9047SMatt Arsenault cl::desc("Select which denormal numbers the code is permitted to require for float"), 249a8cc9047SMatt Arsenault cl::init(DenormalMode::Invalid), 250a8cc9047SMatt Arsenault DenormFlagEnumOptions); 251a8cc9047SMatt Arsenault CGBINDOPT(DenormalFP32Math); 252a8cc9047SMatt Arsenault 253ac1d23edSserge-sans-paille static cl::opt<bool> EnableHonorSignDependentRoundingFPMath( 254ac1d23edSserge-sans-paille "enable-sign-dependent-rounding-fp-math", cl::Hidden, 255ac1d23edSserge-sans-paille cl::desc("Force codegen to assume rounding mode can change dynamically"), 256ac1d23edSserge-sans-paille cl::init(false)); 257ac1d23edSserge-sans-paille CGBINDOPT(EnableHonorSignDependentRoundingFPMath); 258ac1d23edSserge-sans-paille 259ac1d23edSserge-sans-paille static cl::opt<FloatABI::ABIType> FloatABIForCalls( 260ac1d23edSserge-sans-paille "float-abi", cl::desc("Choose float ABI type"), 261ac1d23edSserge-sans-paille cl::init(FloatABI::Default), 262ac1d23edSserge-sans-paille cl::values(clEnumValN(FloatABI::Default, "default", 263ac1d23edSserge-sans-paille "Target default float ABI type"), 264ac1d23edSserge-sans-paille clEnumValN(FloatABI::Soft, "soft", 265ac1d23edSserge-sans-paille "Soft float ABI (implied by -soft-float)"), 266ac1d23edSserge-sans-paille clEnumValN(FloatABI::Hard, "hard", 267ac1d23edSserge-sans-paille "Hard float ABI (uses FP registers)"))); 268ac1d23edSserge-sans-paille CGBINDOPT(FloatABIForCalls); 269ac1d23edSserge-sans-paille 270ac1d23edSserge-sans-paille static cl::opt<FPOpFusion::FPOpFusionMode> FuseFPOps( 271ac1d23edSserge-sans-paille "fp-contract", cl::desc("Enable aggressive formation of fused FP ops"), 272ac1d23edSserge-sans-paille cl::init(FPOpFusion::Standard), 273ac1d23edSserge-sans-paille cl::values( 274ac1d23edSserge-sans-paille clEnumValN(FPOpFusion::Fast, "fast", 275ac1d23edSserge-sans-paille "Fuse FP ops whenever profitable"), 276ac1d23edSserge-sans-paille clEnumValN(FPOpFusion::Standard, "on", "Only fuse 'blessed' FP ops."), 277ac1d23edSserge-sans-paille clEnumValN(FPOpFusion::Strict, "off", 278ac1d23edSserge-sans-paille "Only fuse FP ops when the result won't be affected."))); 279ac1d23edSserge-sans-paille CGBINDOPT(FuseFPOps); 280ac1d23edSserge-sans-paille 281a773db7dSDoug Gregor static cl::opt<SwiftAsyncFramePointerMode> SwiftAsyncFramePointer( 282a773db7dSDoug Gregor "swift-async-fp", 283a773db7dSDoug Gregor cl::desc("Determine when the Swift async frame pointer should be set"), 284a773db7dSDoug Gregor cl::init(SwiftAsyncFramePointerMode::Always), 285a773db7dSDoug Gregor cl::values(clEnumValN(SwiftAsyncFramePointerMode::DeploymentBased, "auto", 286a773db7dSDoug Gregor "Determine based on deployment target"), 287a773db7dSDoug Gregor clEnumValN(SwiftAsyncFramePointerMode::Always, "always", 288a773db7dSDoug Gregor "Always set the bit"), 289a773db7dSDoug Gregor clEnumValN(SwiftAsyncFramePointerMode::Never, "never", 290a773db7dSDoug Gregor "Never set the bit"))); 291a773db7dSDoug Gregor CGBINDOPT(SwiftAsyncFramePointer); 292a773db7dSDoug Gregor 293ac1d23edSserge-sans-paille static cl::opt<bool> DontPlaceZerosInBSS( 294ac1d23edSserge-sans-paille "nozero-initialized-in-bss", 295ac1d23edSserge-sans-paille cl::desc("Don't place zero-initialized symbols into bss section"), 296ac1d23edSserge-sans-paille cl::init(false)); 297ac1d23edSserge-sans-paille CGBINDOPT(DontPlaceZerosInBSS); 298ac1d23edSserge-sans-paille 299c92f29b0SZarko Todorovski static cl::opt<bool> EnableAIXExtendedAltivecABI( 300c92f29b0SZarko Todorovski "vec-extabi", cl::desc("Enable the AIX Extended Altivec ABI."), 301c92f29b0SZarko Todorovski cl::init(false)); 302c92f29b0SZarko Todorovski CGBINDOPT(EnableAIXExtendedAltivecABI); 303c92f29b0SZarko Todorovski 304ac1d23edSserge-sans-paille static cl::opt<bool> EnableGuaranteedTailCallOpt( 305ac1d23edSserge-sans-paille "tailcallopt", 306ac1d23edSserge-sans-paille cl::desc( 307ac1d23edSserge-sans-paille "Turn fastcc calls into tail calls by (potentially) changing ABI."), 308ac1d23edSserge-sans-paille cl::init(false)); 309ac1d23edSserge-sans-paille CGBINDOPT(EnableGuaranteedTailCallOpt); 310ac1d23edSserge-sans-paille 311ac1d23edSserge-sans-paille static cl::opt<bool> DisableTailCalls( 312ac1d23edSserge-sans-paille "disable-tail-calls", cl::desc("Never emit tail calls"), cl::init(false)); 313ac1d23edSserge-sans-paille CGBINDOPT(DisableTailCalls); 314ac1d23edSserge-sans-paille 315ac1d23edSserge-sans-paille static cl::opt<bool> StackSymbolOrdering( 316ac1d23edSserge-sans-paille "stack-symbol-ordering", cl::desc("Order local stack symbols."), 317ac1d23edSserge-sans-paille cl::init(true)); 318ac1d23edSserge-sans-paille CGBINDOPT(StackSymbolOrdering); 319ac1d23edSserge-sans-paille 320ac1d23edSserge-sans-paille static cl::opt<bool> StackRealign( 321ac1d23edSserge-sans-paille "stackrealign", 322ac1d23edSserge-sans-paille cl::desc("Force align the stack to the minimum alignment"), 323ac1d23edSserge-sans-paille cl::init(false)); 324ac1d23edSserge-sans-paille CGBINDOPT(StackRealign); 325ac1d23edSserge-sans-paille 326ac1d23edSserge-sans-paille static cl::opt<std::string> TrapFuncName( 327ac1d23edSserge-sans-paille "trap-func", cl::Hidden, 328ac1d23edSserge-sans-paille cl::desc("Emit a call to trap function rather than a trap instruction"), 329ac1d23edSserge-sans-paille cl::init("")); 330ac1d23edSserge-sans-paille CGBINDOPT(TrapFuncName); 331ac1d23edSserge-sans-paille 332ac1d23edSserge-sans-paille static cl::opt<bool> UseCtors("use-ctors", 333ac1d23edSserge-sans-paille cl::desc("Use .ctors instead of .init_array."), 334ac1d23edSserge-sans-paille cl::init(false)); 335ac1d23edSserge-sans-paille CGBINDOPT(UseCtors); 336ac1d23edSserge-sans-paille 337ac1d23edSserge-sans-paille static cl::opt<bool> RelaxELFRelocations( 338ac1d23edSserge-sans-paille "relax-elf-relocations", 339ac1d23edSserge-sans-paille cl::desc( 340ac1d23edSserge-sans-paille "Emit GOTPCRELX/REX_GOTPCRELX instead of GOTPCREL on x86-64 ELF"), 341ac1d23edSserge-sans-paille cl::init(false)); 342ac1d23edSserge-sans-paille CGBINDOPT(RelaxELFRelocations); 343ac1d23edSserge-sans-paille 344ac1d23edSserge-sans-paille static cl::opt<bool> DataSections( 345ac1d23edSserge-sans-paille "data-sections", cl::desc("Emit data into separate sections"), 346ac1d23edSserge-sans-paille cl::init(false)); 347ac1d23edSserge-sans-paille CGBINDOPT(DataSections); 348ac1d23edSserge-sans-paille 349ac1d23edSserge-sans-paille static cl::opt<bool> FunctionSections( 350ac1d23edSserge-sans-paille "function-sections", cl::desc("Emit functions into separate sections"), 351ac1d23edSserge-sans-paille cl::init(false)); 352ac1d23edSserge-sans-paille CGBINDOPT(FunctionSections); 353ac1d23edSserge-sans-paille 35492bca128Sdiggerlin static cl::opt<bool> IgnoreXCOFFVisibility( 35592bca128Sdiggerlin "ignore-xcoff-visibility", 35692bca128Sdiggerlin cl::desc("Not emit the visibility attribute for asm in AIX OS or give " 35792bca128Sdiggerlin "all symbols 'unspecified' visibility in XCOFF object file"), 35892bca128Sdiggerlin cl::init(false)); 35992bca128Sdiggerlin CGBINDOPT(IgnoreXCOFFVisibility); 36092bca128Sdiggerlin 361997d286fSdiggerlin static cl::opt<bool> XCOFFTracebackTable( 362997d286fSdiggerlin "xcoff-traceback-table", cl::desc("Emit the XCOFF traceback table"), 363997d286fSdiggerlin cl::init(true)); 364997d286fSdiggerlin CGBINDOPT(XCOFFTracebackTable); 365997d286fSdiggerlin 366ac1d23edSserge-sans-paille static cl::opt<std::string> BBSections( 367ca6b6d40SSriraman Tallam "basic-block-sections", 368ac1d23edSserge-sans-paille cl::desc("Emit basic blocks into separate sections"), 369ac1d23edSserge-sans-paille cl::value_desc("all | <function list (file)> | labels | none"), 370ac1d23edSserge-sans-paille cl::init("none")); 371ac1d23edSserge-sans-paille CGBINDOPT(BBSections); 372ac1d23edSserge-sans-paille 373ac1d23edSserge-sans-paille static cl::opt<unsigned> TLSSize( 374ac1d23edSserge-sans-paille "tls-size", cl::desc("Bit size of immediate TLS offsets"), cl::init(0)); 375ac1d23edSserge-sans-paille CGBINDOPT(TLSSize); 376ac1d23edSserge-sans-paille 377ac1d23edSserge-sans-paille static cl::opt<bool> EmulatedTLS( 378ac1d23edSserge-sans-paille "emulated-tls", cl::desc("Use emulated TLS model"), cl::init(false)); 379ac1d23edSserge-sans-paille CGBINDOPT(EmulatedTLS); 380ac1d23edSserge-sans-paille 381ac1d23edSserge-sans-paille static cl::opt<bool> UniqueSectionNames( 382ac1d23edSserge-sans-paille "unique-section-names", cl::desc("Give unique names to every section"), 383ac1d23edSserge-sans-paille cl::init(true)); 384ac1d23edSserge-sans-paille CGBINDOPT(UniqueSectionNames); 385ac1d23edSserge-sans-paille 386e0bca46bSSriraman Tallam static cl::opt<bool> UniqueBasicBlockSectionNames( 387ca6b6d40SSriraman Tallam "unique-basic-block-section-names", 388ac1d23edSserge-sans-paille cl::desc("Give unique names to every basic block section"), 389ac1d23edSserge-sans-paille cl::init(false)); 390e0bca46bSSriraman Tallam CGBINDOPT(UniqueBasicBlockSectionNames); 391ac1d23edSserge-sans-paille 392ac1d23edSserge-sans-paille static cl::opt<EABI> EABIVersion( 393ac1d23edSserge-sans-paille "meabi", cl::desc("Set EABI type (default depends on triple):"), 394ac1d23edSserge-sans-paille cl::init(EABI::Default), 395ac1d23edSserge-sans-paille cl::values( 396ac1d23edSserge-sans-paille clEnumValN(EABI::Default, "default", "Triple default EABI version"), 397ac1d23edSserge-sans-paille clEnumValN(EABI::EABI4, "4", "EABI version 4"), 398ac1d23edSserge-sans-paille clEnumValN(EABI::EABI5, "5", "EABI version 5"), 399ac1d23edSserge-sans-paille clEnumValN(EABI::GNU, "gnu", "EABI GNU"))); 400ac1d23edSserge-sans-paille CGBINDOPT(EABIVersion); 401ac1d23edSserge-sans-paille 402ac1d23edSserge-sans-paille static cl::opt<DebuggerKind> DebuggerTuningOpt( 403ac1d23edSserge-sans-paille "debugger-tune", cl::desc("Tune debug info for a particular debugger"), 404ac1d23edSserge-sans-paille cl::init(DebuggerKind::Default), 405ac1d23edSserge-sans-paille cl::values( 406ac1d23edSserge-sans-paille clEnumValN(DebuggerKind::GDB, "gdb", "gdb"), 407ac1d23edSserge-sans-paille clEnumValN(DebuggerKind::LLDB, "lldb", "lldb"), 4080c36da72SEsme-Yi clEnumValN(DebuggerKind::DBX, "dbx", "dbx"), 409ac1d23edSserge-sans-paille clEnumValN(DebuggerKind::SCE, "sce", "SCE targets (e.g. PS4)"))); 410ac1d23edSserge-sans-paille CGBINDOPT(DebuggerTuningOpt); 411ac1d23edSserge-sans-paille 412ac1d23edSserge-sans-paille static cl::opt<bool> EnableStackSizeSection( 413ac1d23edSserge-sans-paille "stack-size-section", 414ac1d23edSserge-sans-paille cl::desc("Emit a section containing stack size metadata"), 415ac1d23edSserge-sans-paille cl::init(false)); 416ac1d23edSserge-sans-paille CGBINDOPT(EnableStackSizeSection); 417ac1d23edSserge-sans-paille 418ac1d23edSserge-sans-paille static cl::opt<bool> EnableAddrsig( 419ac1d23edSserge-sans-paille "addrsig", cl::desc("Emit an address-significance table"), 420ac1d23edSserge-sans-paille cl::init(false)); 421ac1d23edSserge-sans-paille CGBINDOPT(EnableAddrsig); 422ac1d23edSserge-sans-paille 423ac1d23edSserge-sans-paille static cl::opt<bool> EmitCallSiteInfo( 424ac1d23edSserge-sans-paille "emit-call-site-info", 425ac1d23edSserge-sans-paille cl::desc( 426ac1d23edSserge-sans-paille "Emit call site debug information, if debug information is enabled."), 427ac1d23edSserge-sans-paille cl::init(false)); 428ac1d23edSserge-sans-paille CGBINDOPT(EmitCallSiteInfo); 429ac1d23edSserge-sans-paille 430ac1d23edSserge-sans-paille static cl::opt<bool> EnableDebugEntryValues( 431ac1d23edSserge-sans-paille "debug-entry-values", 432d9b96210SDjordje Todorovic cl::desc("Enable debug info for the debug entry values."), 433ac1d23edSserge-sans-paille cl::init(false)); 434ac1d23edSserge-sans-paille CGBINDOPT(EnableDebugEntryValues); 435ac1d23edSserge-sans-paille 436121a49d8SJeremy Morse static cl::opt<bool> ValueTrackingVariableLocations( 437121a49d8SJeremy Morse "experimental-debug-variable-locations", 438121a49d8SJeremy Morse cl::desc("Use experimental new value-tracking variable locations"), 439121a49d8SJeremy Morse cl::init(false)); 440121a49d8SJeremy Morse CGBINDOPT(ValueTrackingVariableLocations); 441121a49d8SJeremy Morse 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(); 503ac1d23edSserge-sans-paille Options.NoTrappingFPMath = getEnableNoTrappingFPMath(); 5040ab5b5b8SMatt Arsenault 5050ab5b5b8SMatt Arsenault DenormalMode::DenormalModeKind DenormKind = getDenormalFPMath(); 5060ab5b5b8SMatt Arsenault 5070ab5b5b8SMatt Arsenault // FIXME: Should have separate input and output flags 5080ab5b5b8SMatt Arsenault Options.setFPDenormalMode(DenormalMode(DenormKind, DenormKind)); 5090ab5b5b8SMatt Arsenault 510ac1d23edSserge-sans-paille Options.HonorSignDependentRoundingFPMathOption = 511ac1d23edSserge-sans-paille getEnableHonorSignDependentRoundingFPMath(); 512ac1d23edSserge-sans-paille if (getFloatABIForCalls() != FloatABI::Default) 513ac1d23edSserge-sans-paille Options.FloatABIType = getFloatABIForCalls(); 514c92f29b0SZarko Todorovski Options.EnableAIXExtendedAltivecABI = getEnableAIXExtendedAltivecABI(); 515ac1d23edSserge-sans-paille Options.NoZerosInBSS = getDontPlaceZerosInBSS(); 516ac1d23edSserge-sans-paille Options.GuaranteedTailCallOpt = getEnableGuaranteedTailCallOpt(); 517ac1d23edSserge-sans-paille Options.StackSymbolOrdering = getStackSymbolOrdering(); 518ac1d23edSserge-sans-paille Options.UseInitArray = !getUseCtors(); 519ac1d23edSserge-sans-paille Options.RelaxELFRelocations = getRelaxELFRelocations(); 520f85bcc21Sjasonliu Options.DataSections = 521f85bcc21Sjasonliu getExplicitDataSections().getValueOr(TheTriple.hasDefaultDataSections()); 522ac1d23edSserge-sans-paille Options.FunctionSections = getFunctionSections(); 52392bca128Sdiggerlin Options.IgnoreXCOFFVisibility = getIgnoreXCOFFVisibility(); 524997d286fSdiggerlin Options.XCOFFTracebackTable = getXCOFFTracebackTable(); 525ac1d23edSserge-sans-paille Options.BBSections = getBBSectionsMode(Options); 526ac1d23edSserge-sans-paille Options.UniqueSectionNames = getUniqueSectionNames(); 527e0bca46bSSriraman Tallam Options.UniqueBasicBlockSectionNames = getUniqueBasicBlockSectionNames(); 528ac1d23edSserge-sans-paille Options.TLSSize = getTLSSize(); 529ac1d23edSserge-sans-paille Options.EmulatedTLS = getEmulatedTLS(); 530ac1d23edSserge-sans-paille Options.ExplicitEmulatedTLS = EmulatedTLSView->getNumOccurrences() > 0; 531ac1d23edSserge-sans-paille Options.ExceptionModel = getExceptionModel(); 532ac1d23edSserge-sans-paille Options.EmitStackSizeSection = getEnableStackSizeSection(); 53394faadacSSnehasish Kumar Options.EnableMachineFunctionSplitter = getEnableMachineFunctionSplitter(); 534ac1d23edSserge-sans-paille Options.EmitAddrsig = getEnableAddrsig(); 535ac1d23edSserge-sans-paille Options.EmitCallSiteInfo = getEmitCallSiteInfo(); 536ac1d23edSserge-sans-paille Options.EnableDebugEntryValues = getEnableDebugEntryValues(); 537ac1d23edSserge-sans-paille Options.ForceDwarfFrameSection = getForceDwarfFrameSection(); 5387c7c8e0dSIan Levesque Options.XRayOmitFunctionIndex = getXRayOmitFunctionIndex(); 539a0ca4c46SChen Zheng Options.DebugStrictDwarf = getDebugStrictDwarf(); 540a1944386SFangrui Song Options.LoopAlignment = getAlignLoops(); 541ac1d23edSserge-sans-paille 542651122fcSJeremy Morse if (auto Opt = getExplicitValueTrackingVariableLocations()) 543651122fcSJeremy Morse Options.ValueTrackingVariableLocations = *Opt; 544651122fcSJeremy Morse else 545651122fcSJeremy Morse Options.ValueTrackingVariableLocations = 546651122fcSJeremy Morse getDefaultValueTrackingVariableLocations(TheTriple); 547651122fcSJeremy Morse 548ac1d23edSserge-sans-paille Options.MCOptions = mc::InitMCTargetOptionsFromFlags(); 549ac1d23edSserge-sans-paille 550ac1d23edSserge-sans-paille Options.ThreadModel = getThreadModel(); 551ac1d23edSserge-sans-paille Options.EABIVersion = getEABIVersion(); 552ac1d23edSserge-sans-paille Options.DebuggerTuning = getDebuggerTuningOpt(); 553a773db7dSDoug Gregor Options.SwiftAsyncFramePointer = getSwiftAsyncFramePointer(); 554ac1d23edSserge-sans-paille return Options; 555ac1d23edSserge-sans-paille } 556ac1d23edSserge-sans-paille 557ac1d23edSserge-sans-paille std::string codegen::getCPUStr() { 558ac1d23edSserge-sans-paille // If user asked for the 'native' CPU, autodetect here. If autodection fails, 559ac1d23edSserge-sans-paille // this will set the CPU to an empty string which tells the target to 560ac1d23edSserge-sans-paille // pick a basic default. 561ac1d23edSserge-sans-paille if (getMCPU() == "native") 562ac1d23edSserge-sans-paille return std::string(sys::getHostCPUName()); 563ac1d23edSserge-sans-paille 564ac1d23edSserge-sans-paille return getMCPU(); 565ac1d23edSserge-sans-paille } 566ac1d23edSserge-sans-paille 567ac1d23edSserge-sans-paille std::string codegen::getFeaturesStr() { 568ac1d23edSserge-sans-paille SubtargetFeatures Features; 569ac1d23edSserge-sans-paille 570ac1d23edSserge-sans-paille // If user asked for the 'native' CPU, we need to autodetect features. 571ac1d23edSserge-sans-paille // This is necessary for x86 where the CPU might not support all the 572ac1d23edSserge-sans-paille // features the autodetected CPU name lists in the target. For example, 573ac1d23edSserge-sans-paille // not all Sandybridge processors support AVX. 574ac1d23edSserge-sans-paille if (getMCPU() == "native") { 575ac1d23edSserge-sans-paille StringMap<bool> HostFeatures; 576ac1d23edSserge-sans-paille if (sys::getHostCPUFeatures(HostFeatures)) 577ac1d23edSserge-sans-paille for (auto &F : HostFeatures) 578ac1d23edSserge-sans-paille Features.AddFeature(F.first(), F.second); 579ac1d23edSserge-sans-paille } 580ac1d23edSserge-sans-paille 581ac1d23edSserge-sans-paille for (auto const &MAttr : getMAttrs()) 582ac1d23edSserge-sans-paille Features.AddFeature(MAttr); 583ac1d23edSserge-sans-paille 584ac1d23edSserge-sans-paille return Features.getString(); 585ac1d23edSserge-sans-paille } 586ac1d23edSserge-sans-paille 587ac1d23edSserge-sans-paille std::vector<std::string> codegen::getFeatureList() { 588ac1d23edSserge-sans-paille SubtargetFeatures Features; 589ac1d23edSserge-sans-paille 590ac1d23edSserge-sans-paille // If user asked for the 'native' CPU, we need to autodetect features. 591ac1d23edSserge-sans-paille // This is necessary for x86 where the CPU might not support all the 592ac1d23edSserge-sans-paille // features the autodetected CPU name lists in the target. For example, 593ac1d23edSserge-sans-paille // not all Sandybridge processors support AVX. 594ac1d23edSserge-sans-paille if (getMCPU() == "native") { 595ac1d23edSserge-sans-paille StringMap<bool> HostFeatures; 596ac1d23edSserge-sans-paille if (sys::getHostCPUFeatures(HostFeatures)) 597ac1d23edSserge-sans-paille for (auto &F : HostFeatures) 598ac1d23edSserge-sans-paille Features.AddFeature(F.first(), F.second); 599ac1d23edSserge-sans-paille } 600ac1d23edSserge-sans-paille 601ac1d23edSserge-sans-paille for (auto const &MAttr : getMAttrs()) 602ac1d23edSserge-sans-paille Features.AddFeature(MAttr); 603ac1d23edSserge-sans-paille 604ac1d23edSserge-sans-paille return Features.getFeatures(); 605ac1d23edSserge-sans-paille } 606ac1d23edSserge-sans-paille 607ac1d23edSserge-sans-paille void codegen::renderBoolStringAttr(AttrBuilder &B, StringRef Name, bool Val) { 608ac1d23edSserge-sans-paille B.addAttribute(Name, Val ? "true" : "false"); 609ac1d23edSserge-sans-paille } 610ac1d23edSserge-sans-paille 611ac1d23edSserge-sans-paille #define HANDLE_BOOL_ATTR(CL, AttrName) \ 612ac1d23edSserge-sans-paille do { \ 613ac1d23edSserge-sans-paille if (CL->getNumOccurrences() > 0 && !F.hasFnAttribute(AttrName)) \ 614ac1d23edSserge-sans-paille renderBoolStringAttr(NewAttrs, AttrName, *CL); \ 615ac1d23edSserge-sans-paille } while (0) 616ac1d23edSserge-sans-paille 617ac1d23edSserge-sans-paille /// Set function attributes of function \p F based on CPU, Features, and command 618ac1d23edSserge-sans-paille /// line flags. 619ac1d23edSserge-sans-paille void codegen::setFunctionAttributes(StringRef CPU, StringRef Features, 620ac1d23edSserge-sans-paille Function &F) { 621ac1d23edSserge-sans-paille auto &Ctx = F.getContext(); 622ac1d23edSserge-sans-paille AttributeList Attrs = F.getAttributes(); 623*d2cc6c2dSSerge Guelton AttrBuilder NewAttrs(Ctx); 624ac1d23edSserge-sans-paille 625ac1d23edSserge-sans-paille if (!CPU.empty() && !F.hasFnAttribute("target-cpu")) 626ac1d23edSserge-sans-paille NewAttrs.addAttribute("target-cpu", CPU); 627ac1d23edSserge-sans-paille if (!Features.empty()) { 628ac1d23edSserge-sans-paille // Append the command line features to any that are already on the function. 629ac1d23edSserge-sans-paille StringRef OldFeatures = 630ac1d23edSserge-sans-paille F.getFnAttribute("target-features").getValueAsString(); 631ac1d23edSserge-sans-paille if (OldFeatures.empty()) 632ac1d23edSserge-sans-paille NewAttrs.addAttribute("target-features", Features); 633ac1d23edSserge-sans-paille else { 634ac1d23edSserge-sans-paille SmallString<256> Appended(OldFeatures); 635ac1d23edSserge-sans-paille Appended.push_back(','); 636ac1d23edSserge-sans-paille Appended.append(Features); 637ac1d23edSserge-sans-paille NewAttrs.addAttribute("target-features", Appended); 638ac1d23edSserge-sans-paille } 639ac1d23edSserge-sans-paille } 640ac1d23edSserge-sans-paille if (FramePointerUsageView->getNumOccurrences() > 0 && 641ac1d23edSserge-sans-paille !F.hasFnAttribute("frame-pointer")) { 6422786e673SFangrui Song if (getFramePointerUsage() == FramePointerKind::All) 643ac1d23edSserge-sans-paille NewAttrs.addAttribute("frame-pointer", "all"); 6442786e673SFangrui Song else if (getFramePointerUsage() == FramePointerKind::NonLeaf) 645ac1d23edSserge-sans-paille NewAttrs.addAttribute("frame-pointer", "non-leaf"); 6462786e673SFangrui Song else if (getFramePointerUsage() == FramePointerKind::None) 647ac1d23edSserge-sans-paille NewAttrs.addAttribute("frame-pointer", "none"); 648ac1d23edSserge-sans-paille } 649ac1d23edSserge-sans-paille if (DisableTailCallsView->getNumOccurrences() > 0) 650ac1d23edSserge-sans-paille NewAttrs.addAttribute("disable-tail-calls", 651ac1d23edSserge-sans-paille toStringRef(getDisableTailCalls())); 652ac1d23edSserge-sans-paille if (getStackRealign()) 653ac1d23edSserge-sans-paille NewAttrs.addAttribute("stackrealign"); 654ac1d23edSserge-sans-paille 655ac1d23edSserge-sans-paille HANDLE_BOOL_ATTR(EnableUnsafeFPMathView, "unsafe-fp-math"); 656ac1d23edSserge-sans-paille HANDLE_BOOL_ATTR(EnableNoInfsFPMathView, "no-infs-fp-math"); 657ac1d23edSserge-sans-paille HANDLE_BOOL_ATTR(EnableNoNaNsFPMathView, "no-nans-fp-math"); 658ac1d23edSserge-sans-paille HANDLE_BOOL_ATTR(EnableNoSignedZerosFPMathView, "no-signed-zeros-fp-math"); 659ac1d23edSserge-sans-paille 6600ab5b5b8SMatt Arsenault if (DenormalFPMathView->getNumOccurrences() > 0 && 6610ab5b5b8SMatt Arsenault !F.hasFnAttribute("denormal-fp-math")) { 6620ab5b5b8SMatt Arsenault DenormalMode::DenormalModeKind DenormKind = getDenormalFPMath(); 6630ab5b5b8SMatt Arsenault 6640ab5b5b8SMatt Arsenault // FIXME: Command line flag should expose separate input/output modes. 6650ab5b5b8SMatt Arsenault NewAttrs.addAttribute("denormal-fp-math", 6660ab5b5b8SMatt Arsenault DenormalMode(DenormKind, DenormKind).str()); 6670ab5b5b8SMatt Arsenault } 6680ab5b5b8SMatt Arsenault 669a8cc9047SMatt Arsenault if (DenormalFP32MathView->getNumOccurrences() > 0 && 670a8cc9047SMatt Arsenault !F.hasFnAttribute("denormal-fp-math-f32")) { 671a8cc9047SMatt Arsenault // FIXME: Command line flag should expose separate input/output modes. 672a8cc9047SMatt Arsenault DenormalMode::DenormalModeKind DenormKind = getDenormalFP32Math(); 673a8cc9047SMatt Arsenault 674a8cc9047SMatt Arsenault NewAttrs.addAttribute( 675a8cc9047SMatt Arsenault "denormal-fp-math-f32", 676a8cc9047SMatt Arsenault DenormalMode(DenormKind, DenormKind).str()); 677a8cc9047SMatt Arsenault } 678a8cc9047SMatt Arsenault 679ac1d23edSserge-sans-paille if (TrapFuncNameView->getNumOccurrences() > 0) 680ac1d23edSserge-sans-paille for (auto &B : F) 681ac1d23edSserge-sans-paille for (auto &I : B) 682ac1d23edSserge-sans-paille if (auto *Call = dyn_cast<CallInst>(&I)) 683ac1d23edSserge-sans-paille if (const auto *F = Call->getCalledFunction()) 684ac1d23edSserge-sans-paille if (F->getIntrinsicID() == Intrinsic::debugtrap || 685ac1d23edSserge-sans-paille F->getIntrinsicID() == Intrinsic::trap) 6863f4d00bcSArthur Eubanks Call->addFnAttr( 687ac1d23edSserge-sans-paille Attribute::get(Ctx, "trap-func-name", getTrapFuncName())); 688ac1d23edSserge-sans-paille 689ac1d23edSserge-sans-paille // Let NewAttrs override Attrs. 690de0ae9e8SArthur Eubanks F.setAttributes(Attrs.addFnAttributes(Ctx, NewAttrs)); 691ac1d23edSserge-sans-paille } 692ac1d23edSserge-sans-paille 693ac1d23edSserge-sans-paille /// Set function attributes of functions in Module M based on CPU, 694ac1d23edSserge-sans-paille /// Features, and command line flags. 695ac1d23edSserge-sans-paille void codegen::setFunctionAttributes(StringRef CPU, StringRef Features, 696ac1d23edSserge-sans-paille Module &M) { 697ac1d23edSserge-sans-paille for (Function &F : M) 698ac1d23edSserge-sans-paille setFunctionAttributes(CPU, Features, F); 699ac1d23edSserge-sans-paille } 700651122fcSJeremy Morse 701651122fcSJeremy Morse bool codegen::getDefaultValueTrackingVariableLocations(const llvm::Triple &T) { 7023c045070SJeremy Morse if (T.getArch() == llvm::Triple::x86_64) 7033c045070SJeremy Morse return true; 704651122fcSJeremy Morse return false; 705651122fcSJeremy Morse } 706