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 getDataSections(); 102 std::optional<bool> getExplicitDataSections(); 103 104 bool getFunctionSections(); 105 std::optional<bool> getExplicitFunctionSections(); 106 107 bool getIgnoreXCOFFVisibility(); 108 109 bool getXCOFFTracebackTable(); 110 111 std::string getBBSections(); 112 113 unsigned getTLSSize(); 114 115 bool getEmulatedTLS(); 116 std::optional<bool> getExplicitEmulatedTLS(); 117 118 bool getEnableTLSDESC(); 119 std::optional<bool> getExplicitEnableTLSDESC(); 120 121 bool getUniqueSectionNames(); 122 123 bool getUniqueBasicBlockSectionNames(); 124 125 llvm::EABI getEABIVersion(); 126 127 llvm::DebuggerKind getDebuggerTuningOpt(); 128 129 bool getEnableStackSizeSection(); 130 131 bool getEnableAddrsig(); 132 133 bool getEmitCallSiteInfo(); 134 135 bool getEnableMachineFunctionSplitter(); 136 137 bool getEnableDebugEntryValues(); 138 139 bool getValueTrackingVariableLocations(); 140 std::optional<bool> getExplicitValueTrackingVariableLocations(); 141 142 bool getForceDwarfFrameSection(); 143 144 bool getXRayFunctionIndex(); 145 146 bool getDebugStrictDwarf(); 147 148 unsigned getAlignLoops(); 149 150 bool getJMCInstrument(); 151 152 bool getXCOFFReadOnlyPointers(); 153 154 /// Create this object with static storage to register codegen-related command 155 /// line options. 156 struct RegisterCodeGenFlags { 157 RegisterCodeGenFlags(); 158 }; 159 160 bool getEnableBBAddrMap(); 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