1 //===-- CommandFlags.h - Command Line Flags Interface -----------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file contains codegen-specific flags that are shared between different 10 // command line tools. The tools "llc" and "opt" both use this file to prevent 11 // flag duplication. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_CODEGEN_COMMANDFLAGS_H 16 #define LLVM_CODEGEN_COMMANDFLAGS_H 17 18 #include "llvm/ADT/FloatingPointMode.h" 19 #include "llvm/Support/CodeGen.h" 20 #include "llvm/Target/TargetOptions.h" 21 #include <optional> 22 #include <string> 23 #include <vector> 24 25 namespace llvm { 26 27 class Module; 28 class AttrBuilder; 29 class Function; 30 class Triple; 31 class TargetMachine; 32 33 namespace codegen { 34 35 std::string getMArch(); 36 37 std::string getMCPU(); 38 39 std::vector<std::string> getMAttrs(); 40 41 Reloc::Model getRelocModel(); 42 std::optional<Reloc::Model> getExplicitRelocModel(); 43 44 ThreadModel::Model getThreadModel(); 45 46 CodeModel::Model getCodeModel(); 47 std::optional<CodeModel::Model> getExplicitCodeModel(); 48 49 uint64_t getLargeDataThreshold(); 50 std::optional<uint64_t> getExplicitLargeDataThreshold(); 51 52 llvm::ExceptionHandling getExceptionModel(); 53 54 std::optional<CodeGenFileType> getExplicitFileType(); 55 56 CodeGenFileType getFileType(); 57 58 FramePointerKind getFramePointerUsage(); 59 60 bool getEnableUnsafeFPMath(); 61 62 bool getEnableNoInfsFPMath(); 63 64 bool getEnableNoNaNsFPMath(); 65 66 bool getEnableNoSignedZerosFPMath(); 67 68 bool getEnableApproxFuncFPMath(); 69 70 bool getEnableNoTrappingFPMath(); 71 72 DenormalMode::DenormalModeKind getDenormalFPMath(); 73 DenormalMode::DenormalModeKind getDenormalFP32Math(); 74 75 bool getEnableHonorSignDependentRoundingFPMath(); 76 77 llvm::FloatABI::ABIType getFloatABIForCalls(); 78 79 llvm::FPOpFusion::FPOpFusionMode getFuseFPOps(); 80 81 SwiftAsyncFramePointerMode getSwiftAsyncFramePointer(); 82 83 bool getDontPlaceZerosInBSS(); 84 85 bool getEnableGuaranteedTailCallOpt(); 86 87 bool getEnableAIXExtendedAltivecABI(); 88 89 bool getDisableTailCalls(); 90 91 bool getStackSymbolOrdering(); 92 93 bool getStackRealign(); 94 95 std::string getTrapFuncName(); 96 97 bool getUseCtors(); 98 99 bool getDisableIntegratedAS(); 100 101 bool getRelaxELFRelocations(); 102 103 bool getDataSections(); 104 std::optional<bool> getExplicitDataSections(); 105 106 bool getFunctionSections(); 107 std::optional<bool> getExplicitFunctionSections(); 108 109 bool getIgnoreXCOFFVisibility(); 110 111 bool getXCOFFTracebackTable(); 112 113 std::string getBBSections(); 114 115 unsigned getTLSSize(); 116 117 bool getEmulatedTLS(); 118 std::optional<bool> getExplicitEmulatedTLS(); 119 120 bool getEnableTLSDESC(); 121 std::optional<bool> getExplicitEnableTLSDESC(); 122 123 bool getUniqueSectionNames(); 124 125 bool getUniqueBasicBlockSectionNames(); 126 127 llvm::EABI getEABIVersion(); 128 129 llvm::DebuggerKind getDebuggerTuningOpt(); 130 131 bool getEnableStackSizeSection(); 132 133 bool getEnableAddrsig(); 134 135 bool getEmitCallSiteInfo(); 136 137 bool getEnableMachineFunctionSplitter(); 138 139 bool getEnableDebugEntryValues(); 140 141 bool getValueTrackingVariableLocations(); 142 std::optional<bool> getExplicitValueTrackingVariableLocations(); 143 144 bool getForceDwarfFrameSection(); 145 146 bool getXRayFunctionIndex(); 147 148 bool getDebugStrictDwarf(); 149 150 unsigned getAlignLoops(); 151 152 bool getJMCInstrument(); 153 154 bool getXCOFFReadOnlyPointers(); 155 156 /// Create this object with static storage to register codegen-related command 157 /// line options. 158 struct RegisterCodeGenFlags { 159 RegisterCodeGenFlags(); 160 }; 161 162 llvm::BasicBlockSection getBBSectionsMode(llvm::TargetOptions &Options); 163 164 /// Common utility function tightly tied to the options listed here. Initializes 165 /// a TargetOptions object with CodeGen flags and returns it. 166 /// \p TheTriple is used to determine the default value for options if 167 /// options are not explicitly specified. If those triple dependant options 168 /// value do not have effect for your component, a default Triple() could be 169 /// passed in. 170 TargetOptions InitTargetOptionsFromCodeGenFlags(const llvm::Triple &TheTriple); 171 172 std::string getCPUStr(); 173 174 std::string getFeaturesStr(); 175 176 std::vector<std::string> getFeatureList(); 177 178 void renderBoolStringAttr(AttrBuilder &B, StringRef Name, bool Val); 179 180 /// Set function attributes of function \p F based on CPU, Features, and command 181 /// line flags. 182 void setFunctionAttributes(StringRef CPU, StringRef Features, Function &F); 183 184 /// Set function attributes of functions in Module M based on CPU, 185 /// Features, and command line flags. 186 void setFunctionAttributes(StringRef CPU, StringRef Features, Module &M); 187 188 /// Should value-tracking variable locations / instruction referencing be 189 /// enabled by default for this triple? 190 bool getDefaultValueTrackingVariableLocations(const llvm::Triple &T); 191 192 /// Creates a TargetMachine instance with the options defined on the command 193 /// line. This can be used for tools that do not need further customization of 194 /// the TargetOptions. 195 Expected<std::unique_ptr<TargetMachine>> createTargetMachineForTriple( 196 StringRef TargetTriple, 197 CodeGenOptLevel OptLevel = CodeGenOptLevel::Default); 198 199 } // namespace codegen 200 } // namespace llvm 201 202 #endif // LLVM_CODEGEN_COMMANDFLAGS_H 203