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 UnwindTablesMandatory; 39 Reloc::Model RelocationModel; 40 CodeModel::Model CMModel; 41 bool PerformTailCallOpt; 42 unsigned StackAlignment; 43 bool RealignStack; 44 bool DisableJumpTables; 45 bool StrongPHIElim; 46 bool AsmVerbosityDefault(false); 47 } 48 49 static cl::opt<bool, true> 50 PrintCode("print-machineinstrs", 51 cl::desc("Print generated machine code"), 52 cl::location(PrintMachineCode), cl::init(false)); 53 static cl::opt<bool, true> 54 DisableFPElim("disable-fp-elim", 55 cl::desc("Disable frame pointer elimination optimization"), 56 cl::location(NoFramePointerElim), 57 cl::init(false)); 58 static cl::opt<bool, true> 59 DisableExcessPrecision("disable-excess-fp-precision", 60 cl::desc("Disable optimizations that may increase FP precision"), 61 cl::location(NoExcessFPPrecision), 62 cl::init(false)); 63 static cl::opt<bool, true> 64 EnableFPMAD("enable-fp-mad", 65 cl::desc("Enable less precise MAD instructions to be generated"), 66 cl::location(LessPreciseFPMADOption), 67 cl::init(false)); 68 static cl::opt<bool, true> 69 EnableUnsafeFPMath("enable-unsafe-fp-math", 70 cl::desc("Enable optimizations that may decrease FP precision"), 71 cl::location(UnsafeFPMath), 72 cl::init(false)); 73 static cl::opt<bool, true> 74 EnableFiniteOnlyFPMath("enable-finite-only-fp-math", 75 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"), 76 cl::location(FiniteOnlyFPMathOption), 77 cl::init(false)); 78 static cl::opt<bool, true> 79 EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math", 80 cl::Hidden, 81 cl::desc("Force codegen to assume rounding mode can change dynamically"), 82 cl::location(HonorSignDependentRoundingFPMathOption), 83 cl::init(false)); 84 static cl::opt<bool, true> 85 GenerateSoftFloatCalls("soft-float", 86 cl::desc("Generate software floating point library calls"), 87 cl::location(UseSoftFloat), 88 cl::init(false)); 89 static cl::opt<llvm::FloatABI::ABIType, true> 90 FloatABIForCalls("float-abi", 91 cl::desc("Choose float ABI type"), 92 cl::location(FloatABIType), 93 cl::init(FloatABI::Default), 94 cl::values( 95 clEnumValN(FloatABI::Default, "default", 96 "Target default float ABI type"), 97 clEnumValN(FloatABI::Soft, "soft", 98 "Soft float ABI (implied by -soft-float)"), 99 clEnumValN(FloatABI::Hard, "hard", 100 "Hard float ABI (uses FP registers)"), 101 clEnumValEnd)); 102 static cl::opt<bool, true> 103 DontPlaceZerosInBSS("nozero-initialized-in-bss", 104 cl::desc("Don't place zero-initialized symbols into bss section"), 105 cl::location(NoZerosInBSS), 106 cl::init(false)); 107 static cl::opt<bool, true> 108 EnableDwarfExceptionHandling("enable-eh", 109 cl::desc("Emit DWARF exception handling (default if target supports)"), 110 cl::location(DwarfExceptionHandling), 111 cl::init(false)); 112 static cl::opt<bool, true> 113 EnableSjLjExceptionHandling("enable-sjlj-eh", 114 cl::desc("Emit SJLJ exception handling (default if target supports)"), 115 cl::location(SjLjExceptionHandling), 116 cl::init(false)); 117 static cl::opt<bool, true> 118 EnableUnwindTables("unwind-tables", 119 cl::desc("Generate unwinding tables for all functions"), 120 cl::location(UnwindTablesMandatory), 121 cl::init(false)); 122 123 static cl::opt<llvm::Reloc::Model, true> 124 DefRelocationModel("relocation-model", 125 cl::desc("Choose relocation model"), 126 cl::location(RelocationModel), 127 cl::init(Reloc::Default), 128 cl::values( 129 clEnumValN(Reloc::Default, "default", 130 "Target default relocation model"), 131 clEnumValN(Reloc::Static, "static", 132 "Non-relocatable code"), 133 clEnumValN(Reloc::PIC_, "pic", 134 "Fully relocatable, position independent code"), 135 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic", 136 "Relocatable external references, non-relocatable code"), 137 clEnumValEnd)); 138 static cl::opt<llvm::CodeModel::Model, true> 139 DefCodeModel("code-model", 140 cl::desc("Choose code model"), 141 cl::location(CMModel), 142 cl::init(CodeModel::Default), 143 cl::values( 144 clEnumValN(CodeModel::Default, "default", 145 "Target default code model"), 146 clEnumValN(CodeModel::Small, "small", 147 "Small code model"), 148 clEnumValN(CodeModel::Kernel, "kernel", 149 "Kernel code model"), 150 clEnumValN(CodeModel::Medium, "medium", 151 "Medium code model"), 152 clEnumValN(CodeModel::Large, "large", 153 "Large code model"), 154 clEnumValEnd)); 155 static cl::opt<bool, true> 156 EnablePerformTailCallOpt("tailcallopt", 157 cl::desc("Turn on tail call optimization."), 158 cl::location(PerformTailCallOpt), 159 cl::init(false)); 160 static cl::opt<unsigned, true> 161 OverrideStackAlignment("stack-alignment", 162 cl::desc("Override default stack alignment"), 163 cl::location(StackAlignment), 164 cl::init(0)); 165 static cl::opt<bool, true> 166 EnableRealignStack("realign-stack", 167 cl::desc("Realign stack if needed"), 168 cl::location(RealignStack), 169 cl::init(true)); 170 static cl::opt<bool, true> 171 DisableSwitchTables(cl::Hidden, "disable-jump-tables", 172 cl::desc("Do not generate jump tables."), 173 cl::location(DisableJumpTables), 174 cl::init(false)); 175 static cl::opt<bool, true> 176 EnableStrongPHIElim(cl::Hidden, "strong-phi-elim", 177 cl::desc("Use strong PHI elimination."), 178 cl::location(StrongPHIElim), 179 cl::init(false)); 180 181 //--------------------------------------------------------------------------- 182 // TargetMachine Class 183 // 184 185 TargetMachine::TargetMachine(const Target &T) 186 : TheTarget(T), AsmInfo(0) { 187 // Typically it will be subtargets that will adjust FloatABIType from Default 188 // to Soft or Hard. 189 if (UseSoftFloat) 190 FloatABIType = FloatABI::Soft; 191 } 192 193 TargetMachine::~TargetMachine() { 194 delete AsmInfo; 195 } 196 197 /// getRelocationModel - Returns the code generation relocation model. The 198 /// choices are static, PIC, and dynamic-no-pic, and target default. 199 Reloc::Model TargetMachine::getRelocationModel() { 200 return RelocationModel; 201 } 202 203 /// setRelocationModel - Sets the code generation relocation model. 204 void TargetMachine::setRelocationModel(Reloc::Model Model) { 205 RelocationModel = Model; 206 } 207 208 /// getCodeModel - Returns the code model. The choices are small, kernel, 209 /// medium, large, and target default. 210 CodeModel::Model TargetMachine::getCodeModel() { 211 return CMModel; 212 } 213 214 /// setCodeModel - Sets the code model. 215 void TargetMachine::setCodeModel(CodeModel::Model Model) { 216 CMModel = Model; 217 } 218 219 bool TargetMachine::getAsmVerbosityDefault() { 220 return AsmVerbosityDefault; 221 } 222 223 void TargetMachine::setAsmVerbosityDefault(bool V) { 224 AsmVerbosityDefault = V; 225 } 226 227 namespace llvm { 228 /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option 229 /// is specified on the command line. When this flag is off(default), the 230 /// code generator is not allowed to generate mad (multiply add) if the 231 /// result is "less precise" than doing those operations individually. 232 bool LessPreciseFPMAD() { return UnsafeFPMath || LessPreciseFPMADOption; } 233 234 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math 235 /// option is specified on the command line. If this returns false (default), 236 /// the code generator is not allowed to assume that FP arithmetic arguments 237 /// and results are never NaNs or +-Infs. 238 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; } 239 240 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume 241 /// that the rounding mode of the FPU can change from its default. 242 bool HonorSignDependentRoundingFPMath() { 243 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption; 244 } 245 } 246 247