1 //===-- TargetMachine.cpp - General Target Information ---------------------==// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file describes the general parts of a Target machine. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "llvm/MC/MCAsmInfo.h" 15 #include "llvm/Target/TargetMachine.h" 16 #include "llvm/Target/TargetOptions.h" 17 #include "llvm/Support/CommandLine.h" 18 using namespace llvm; 19 20 //--------------------------------------------------------------------------- 21 // Command-line options that tend to be useful on more than one back-end. 22 // 23 24 namespace llvm { 25 bool LessPreciseFPMADOption; 26 bool PrintMachineCode; 27 bool NoFramePointerElim; 28 bool NoExcessFPPrecision; 29 bool UnsafeFPMath; 30 bool FiniteOnlyFPMathOption; 31 bool HonorSignDependentRoundingFPMathOption; 32 bool UseSoftFloat; 33 FloatABI::ABIType FloatABIType; 34 bool NoImplicitFloat; 35 bool NoZerosInBSS; 36 bool DwarfExceptionHandling; 37 bool SjLjExceptionHandling; 38 bool JITEmitDebugInfo; 39 bool JITEmitDebugInfoToDisk; 40 bool UnwindTablesMandatory; 41 Reloc::Model RelocationModel; 42 CodeModel::Model CMModel; 43 bool PerformTailCallOpt; 44 unsigned StackAlignment; 45 bool RealignStack; 46 bool DisableJumpTables; 47 bool StrongPHIElim; 48 bool AsmVerbosityDefault(false); 49 bool DisableScheduling; 50 } 51 52 static cl::opt<bool, true> 53 PrintCode("print-machineinstrs", 54 cl::desc("Print generated machine code"), 55 cl::location(PrintMachineCode), cl::init(false)); 56 static cl::opt<bool, true> 57 DisableFPElim("disable-fp-elim", 58 cl::desc("Disable frame pointer elimination optimization"), 59 cl::location(NoFramePointerElim), 60 cl::init(false)); 61 static cl::opt<bool, true> 62 DisableExcessPrecision("disable-excess-fp-precision", 63 cl::desc("Disable optimizations that may increase FP precision"), 64 cl::location(NoExcessFPPrecision), 65 cl::init(false)); 66 static cl::opt<bool, true> 67 EnableFPMAD("enable-fp-mad", 68 cl::desc("Enable less precise MAD instructions to be generated"), 69 cl::location(LessPreciseFPMADOption), 70 cl::init(false)); 71 static cl::opt<bool, true> 72 EnableUnsafeFPMath("enable-unsafe-fp-math", 73 cl::desc("Enable optimizations that may decrease FP precision"), 74 cl::location(UnsafeFPMath), 75 cl::init(false)); 76 static cl::opt<bool, true> 77 EnableFiniteOnlyFPMath("enable-finite-only-fp-math", 78 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"), 79 cl::location(FiniteOnlyFPMathOption), 80 cl::init(false)); 81 static cl::opt<bool, true> 82 EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math", 83 cl::Hidden, 84 cl::desc("Force codegen to assume rounding mode can change dynamically"), 85 cl::location(HonorSignDependentRoundingFPMathOption), 86 cl::init(false)); 87 static cl::opt<bool, true> 88 GenerateSoftFloatCalls("soft-float", 89 cl::desc("Generate software floating point library calls"), 90 cl::location(UseSoftFloat), 91 cl::init(false)); 92 static cl::opt<llvm::FloatABI::ABIType, true> 93 FloatABIForCalls("float-abi", 94 cl::desc("Choose float ABI type"), 95 cl::location(FloatABIType), 96 cl::init(FloatABI::Default), 97 cl::values( 98 clEnumValN(FloatABI::Default, "default", 99 "Target default float ABI type"), 100 clEnumValN(FloatABI::Soft, "soft", 101 "Soft float ABI (implied by -soft-float)"), 102 clEnumValN(FloatABI::Hard, "hard", 103 "Hard float ABI (uses FP registers)"), 104 clEnumValEnd)); 105 static cl::opt<bool, true> 106 DontPlaceZerosInBSS("nozero-initialized-in-bss", 107 cl::desc("Don't place zero-initialized symbols into bss section"), 108 cl::location(NoZerosInBSS), 109 cl::init(false)); 110 static cl::opt<bool, true> 111 EnableDwarfExceptionHandling("enable-eh", 112 cl::desc("Emit DWARF exception handling (default if target supports)"), 113 cl::location(DwarfExceptionHandling), 114 cl::init(false)); 115 static cl::opt<bool, true> 116 EnableSjLjExceptionHandling("enable-sjlj-eh", 117 cl::desc("Emit SJLJ exception handling (default if target supports)"), 118 cl::location(SjLjExceptionHandling), 119 cl::init(false)); 120 // In debug builds, make this default to true. 121 #ifdef NDEBUG 122 #define EMIT_DEBUG false 123 #else 124 #define EMIT_DEBUG true 125 #endif 126 static cl::opt<bool, true> 127 EmitJitDebugInfo("jit-emit-debug", 128 cl::desc("Emit debug information to debugger"), 129 cl::location(JITEmitDebugInfo), 130 cl::init(EMIT_DEBUG)); 131 #undef EMIT_DEBUG 132 static cl::opt<bool, true> 133 EmitJitDebugInfoToDisk("jit-emit-debug-to-disk", 134 cl::Hidden, 135 cl::desc("Emit debug info objfiles to disk"), 136 cl::location(JITEmitDebugInfoToDisk), 137 cl::init(false)); 138 static cl::opt<bool, true> 139 EnableUnwindTables("unwind-tables", 140 cl::desc("Generate unwinding tables for all functions"), 141 cl::location(UnwindTablesMandatory), 142 cl::init(false)); 143 144 static cl::opt<llvm::Reloc::Model, true> 145 DefRelocationModel("relocation-model", 146 cl::desc("Choose relocation model"), 147 cl::location(RelocationModel), 148 cl::init(Reloc::Default), 149 cl::values( 150 clEnumValN(Reloc::Default, "default", 151 "Target default relocation model"), 152 clEnumValN(Reloc::Static, "static", 153 "Non-relocatable code"), 154 clEnumValN(Reloc::PIC_, "pic", 155 "Fully relocatable, position independent code"), 156 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic", 157 "Relocatable external references, non-relocatable code"), 158 clEnumValEnd)); 159 static cl::opt<llvm::CodeModel::Model, true> 160 DefCodeModel("code-model", 161 cl::desc("Choose code model"), 162 cl::location(CMModel), 163 cl::init(CodeModel::Default), 164 cl::values( 165 clEnumValN(CodeModel::Default, "default", 166 "Target default code model"), 167 clEnumValN(CodeModel::Small, "small", 168 "Small code model"), 169 clEnumValN(CodeModel::Kernel, "kernel", 170 "Kernel code model"), 171 clEnumValN(CodeModel::Medium, "medium", 172 "Medium code model"), 173 clEnumValN(CodeModel::Large, "large", 174 "Large code model"), 175 clEnumValEnd)); 176 static cl::opt<bool, true> 177 EnablePerformTailCallOpt("tailcallopt", 178 cl::desc("Turn on tail call optimization."), 179 cl::location(PerformTailCallOpt), 180 cl::init(false)); 181 static cl::opt<unsigned, true> 182 OverrideStackAlignment("stack-alignment", 183 cl::desc("Override default stack alignment"), 184 cl::location(StackAlignment), 185 cl::init(0)); 186 static cl::opt<bool, true> 187 EnableRealignStack("realign-stack", 188 cl::desc("Realign stack if needed"), 189 cl::location(RealignStack), 190 cl::init(true)); 191 static cl::opt<bool, true> 192 DisableSwitchTables(cl::Hidden, "disable-jump-tables", 193 cl::desc("Do not generate jump tables."), 194 cl::location(DisableJumpTables), 195 cl::init(false)); 196 static cl::opt<bool, true> 197 EnableStrongPHIElim(cl::Hidden, "strong-phi-elim", 198 cl::desc("Use strong PHI elimination."), 199 cl::location(StrongPHIElim), 200 cl::init(false)); 201 static cl::opt<bool, true> 202 DisableInstScheduling("disable-scheduling", 203 cl::desc("Disable instruction scheduling"), 204 cl::location(DisableScheduling), 205 cl::init(false)); 206 207 //--------------------------------------------------------------------------- 208 // TargetMachine Class 209 // 210 211 TargetMachine::TargetMachine(const Target &T) 212 : TheTarget(T), AsmInfo(0) { 213 // Typically it will be subtargets that will adjust FloatABIType from Default 214 // to Soft or Hard. 215 if (UseSoftFloat) 216 FloatABIType = FloatABI::Soft; 217 } 218 219 TargetMachine::~TargetMachine() { 220 delete AsmInfo; 221 } 222 223 /// getRelocationModel - Returns the code generation relocation model. The 224 /// choices are static, PIC, and dynamic-no-pic, and target default. 225 Reloc::Model TargetMachine::getRelocationModel() { 226 return RelocationModel; 227 } 228 229 /// setRelocationModel - Sets the code generation relocation model. 230 void TargetMachine::setRelocationModel(Reloc::Model Model) { 231 RelocationModel = Model; 232 } 233 234 /// getCodeModel - Returns the code model. The choices are small, kernel, 235 /// medium, large, and target default. 236 CodeModel::Model TargetMachine::getCodeModel() { 237 return CMModel; 238 } 239 240 /// setCodeModel - Sets the code model. 241 void TargetMachine::setCodeModel(CodeModel::Model Model) { 242 CMModel = Model; 243 } 244 245 bool TargetMachine::getAsmVerbosityDefault() { 246 return AsmVerbosityDefault; 247 } 248 249 void TargetMachine::setAsmVerbosityDefault(bool V) { 250 AsmVerbosityDefault = V; 251 } 252 253 namespace llvm { 254 /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option 255 /// is specified on the command line. When this flag is off(default), the 256 /// code generator is not allowed to generate mad (multiply add) if the 257 /// result is "less precise" than doing those operations individually. 258 bool LessPreciseFPMAD() { return UnsafeFPMath || LessPreciseFPMADOption; } 259 260 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math 261 /// option is specified on the command line. If this returns false (default), 262 /// the code generator is not allowed to assume that FP arithmetic arguments 263 /// and results are never NaNs or +-Infs. 264 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; } 265 266 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume 267 /// that the rounding mode of the FPU can change from its default. 268 bool HonorSignDependentRoundingFPMath() { 269 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption; 270 } 271 } 272