Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===-- TargetMachine.cpp - General Target Information ---------------------==// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 081ce94 | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file describes the general parts of a Target machine. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | 621c44d | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCAsmInfo.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 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 { |
Mon P Wang | 473bc86 | 2009-03-20 05:06:58 +0000 | [diff] [blame] | 25 | bool LessPreciseFPMADOption; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 26 | bool PrintMachineCode; |
| 27 | bool NoFramePointerElim; |
| 28 | bool NoExcessFPPrecision; |
| 29 | bool UnsafeFPMath; |
| 30 | bool FiniteOnlyFPMathOption; |
| 31 | bool HonorSignDependentRoundingFPMathOption; |
| 32 | bool UseSoftFloat; |
Anton Korobeynikov | 1171332 | 2009-06-08 22:53:56 +0000 | [diff] [blame] | 33 | FloatABI::ABIType FloatABIType; |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 34 | bool NoImplicitFloat; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 35 | bool NoZerosInBSS; |
Jim Grosbach | 29feb6a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 36 | bool DwarfExceptionHandling; |
| 37 | bool SjLjExceptionHandling; |
Reid Kleckner | 738b4f2 | 2009-09-20 23:52:43 +0000 | [diff] [blame] | 38 | bool JITEmitDebugInfo; |
| 39 | bool JITEmitDebugInfoToDisk; |
Dale Johannesen | b369e8d | 2008-04-14 17:54:17 +0000 | [diff] [blame] | 40 | bool UnwindTablesMandatory; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 41 | Reloc::Model RelocationModel; |
| 42 | CodeModel::Model CMModel; |
Arnold Schwaighofer | e2d6bbb | 2007-10-11 19:40:01 +0000 | [diff] [blame] | 43 | bool PerformTailCallOpt; |
Anton Korobeynikov | b214a52 | 2008-04-23 18:18:10 +0000 | [diff] [blame] | 44 | unsigned StackAlignment; |
Evan Cheng | 0eeed44 | 2008-07-01 23:18:29 +0000 | [diff] [blame] | 45 | bool RealignStack; |
Dale Johannesen | 493492f | 2008-07-31 18:13:12 +0000 | [diff] [blame] | 46 | bool DisableJumpTables; |
Owen Anderson | bac9ae2 | 2008-10-07 20:22:28 +0000 | [diff] [blame] | 47 | bool StrongPHIElim; |
Evan Cheng | 42ceb47 | 2009-03-25 01:47:28 +0000 | [diff] [blame] | 48 | bool AsmVerbosityDefault(false); |
Bill Wendling | 339b153 | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 49 | bool DisableScheduling; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 50 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 51 | |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 52 | static cl::opt<bool, true> |
| 53 | PrintCode("print-machineinstrs", |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 54 | cl::desc("Print generated machine code"), |
| 55 | cl::location(PrintMachineCode), cl::init(false)); |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 56 | static cl::opt<bool, true> |
Evan Cheng | 94b0676 | 2008-05-30 22:39:18 +0000 | [diff] [blame] | 57 | DisableFPElim("disable-fp-elim", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 58 | cl::desc("Disable frame pointer elimination optimization"), |
| 59 | cl::location(NoFramePointerElim), |
| 60 | cl::init(false)); |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 61 | static cl::opt<bool, true> |
| 62 | DisableExcessPrecision("disable-excess-fp-precision", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 63 | cl::desc("Disable optimizations that may increase FP precision"), |
| 64 | cl::location(NoExcessFPPrecision), |
| 65 | cl::init(false)); |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 66 | static cl::opt<bool, true> |
Mon P Wang | 473bc86 | 2009-03-20 05:06:58 +0000 | [diff] [blame] | 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> |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 72 | EnableUnsafeFPMath("enable-unsafe-fp-math", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 73 | cl::desc("Enable optimizations that may decrease FP precision"), |
| 74 | cl::location(UnsafeFPMath), |
| 75 | cl::init(false)); |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 76 | static cl::opt<bool, true> |
| 77 | EnableFiniteOnlyFPMath("enable-finite-only-fp-math", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 78 | cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"), |
| 79 | cl::location(FiniteOnlyFPMathOption), |
| 80 | cl::init(false)); |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 81 | static cl::opt<bool, true> |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 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)); |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 87 | static cl::opt<bool, true> |
| 88 | GenerateSoftFloatCalls("soft-float", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 89 | cl::desc("Generate software floating point library calls"), |
| 90 | cl::location(UseSoftFloat), |
| 91 | cl::init(false)); |
Anton Korobeynikov | 1171332 | 2009-06-08 22:53:56 +0000 | [diff] [blame] | 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)); |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 105 | static cl::opt<bool, true> |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 106 | DontPlaceZerosInBSS("nozero-initialized-in-bss", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 107 | cl::desc("Don't place zero-initialized symbols into bss section"), |
| 108 | cl::location(NoZerosInBSS), |
| 109 | cl::init(false)); |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 110 | static cl::opt<bool, true> |
Jim Grosbach | 29feb6a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 111 | EnableDwarfExceptionHandling("enable-eh", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 112 | cl::desc("Emit DWARF exception handling (default if target supports)"), |
Jim Grosbach | 29feb6a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 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), |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 119 | cl::init(false)); |
Reid Kleckner | 738b4f2 | 2009-09-20 23:52:43 +0000 | [diff] [blame] | 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)); |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 138 | static cl::opt<bool, true> |
| 139 | EnableUnwindTables("unwind-tables", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 140 | cl::desc("Generate unwinding tables for all functions"), |
| 141 | cl::location(UnwindTablesMandatory), |
| 142 | cl::init(false)); |
Arnold Schwaighofer | e2d6bbb | 2007-10-11 19:40:01 +0000 | [diff] [blame] | 143 | |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 144 | static cl::opt<llvm::Reloc::Model, true> |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 145 | DefRelocationModel("relocation-model", |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 146 | cl::desc("Choose relocation model"), |
| 147 | cl::location(RelocationModel), |
| 148 | cl::init(Reloc::Default), |
| 149 | cl::values( |
| 150 | clEnumValN(Reloc::Default, "default", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 151 | "Target default relocation model"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 152 | clEnumValN(Reloc::Static, "static", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 153 | "Non-relocatable code"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 154 | clEnumValN(Reloc::PIC_, "pic", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 155 | "Fully relocatable, position independent code"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 156 | clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 157 | "Relocatable external references, non-relocatable code"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 158 | clEnumValEnd)); |
| 159 | static cl::opt<llvm::CodeModel::Model, true> |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 160 | DefCodeModel("code-model", |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 161 | cl::desc("Choose code model"), |
| 162 | cl::location(CMModel), |
| 163 | cl::init(CodeModel::Default), |
| 164 | cl::values( |
| 165 | clEnumValN(CodeModel::Default, "default", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 166 | "Target default code model"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 167 | clEnumValN(CodeModel::Small, "small", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 168 | "Small code model"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 169 | clEnumValN(CodeModel::Kernel, "kernel", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 170 | "Kernel code model"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 171 | clEnumValN(CodeModel::Medium, "medium", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 172 | "Medium code model"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 173 | clEnumValN(CodeModel::Large, "large", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 174 | "Large code model"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 175 | clEnumValEnd)); |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 176 | static cl::opt<bool, true> |
| 177 | EnablePerformTailCallOpt("tailcallopt", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 178 | cl::desc("Turn on tail call optimization."), |
| 179 | cl::location(PerformTailCallOpt), |
| 180 | cl::init(false)); |
Evan Cheng | 0eeed44 | 2008-07-01 23:18:29 +0000 | [diff] [blame] | 181 | static cl::opt<unsigned, true> |
| 182 | OverrideStackAlignment("stack-alignment", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 183 | cl::desc("Override default stack alignment"), |
| 184 | cl::location(StackAlignment), |
| 185 | cl::init(0)); |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 186 | static cl::opt<bool, true> |
| 187 | EnableRealignStack("realign-stack", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 188 | cl::desc("Realign stack if needed"), |
| 189 | cl::location(RealignStack), |
| 190 | cl::init(true)); |
Evan Cheng | 0eeed44 | 2008-07-01 23:18:29 +0000 | [diff] [blame] | 191 | static cl::opt<bool, true> |
Dale Johannesen | 493492f | 2008-07-31 18:13:12 +0000 | [diff] [blame] | 192 | DisableSwitchTables(cl::Hidden, "disable-jump-tables", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 193 | cl::desc("Do not generate jump tables."), |
| 194 | cl::location(DisableJumpTables), |
| 195 | cl::init(false)); |
Owen Anderson | bac9ae2 | 2008-10-07 20:22:28 +0000 | [diff] [blame] | 196 | static cl::opt<bool, true> |
| 197 | EnableStrongPHIElim(cl::Hidden, "strong-phi-elim", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 198 | cl::desc("Use strong PHI elimination."), |
| 199 | cl::location(StrongPHIElim), |
| 200 | cl::init(false)); |
Bill Wendling | 339b153 | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 201 | static cl::opt<bool, true> |
| 202 | DisableInstScheduling("disable-scheduling", |
| 203 | cl::desc("Disable instruction scheduling"), |
| 204 | cl::location(DisableScheduling), |
| 205 | cl::init(false)); |
Dan Gohman | b3e9a71 | 2009-01-26 22:22:31 +0000 | [diff] [blame] | 206 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 207 | //--------------------------------------------------------------------------- |
| 208 | // TargetMachine Class |
| 209 | // |
| 210 | |
Daniel Dunbar | fe5939f | 2009-07-15 20:24:03 +0000 | [diff] [blame] | 211 | TargetMachine::TargetMachine(const Target &T) |
| 212 | : TheTarget(T), AsmInfo(0) { |
Anton Korobeynikov | 1171332 | 2009-06-08 22:53:56 +0000 | [diff] [blame] | 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 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 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 | |
Evan Cheng | 42ceb47 | 2009-03-25 01:47:28 +0000 | [diff] [blame] | 245 | bool TargetMachine::getAsmVerbosityDefault() { |
| 246 | return AsmVerbosityDefault; |
| 247 | } |
| 248 | |
| 249 | void TargetMachine::setAsmVerbosityDefault(bool V) { |
| 250 | AsmVerbosityDefault = V; |
| 251 | } |
| 252 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 253 | namespace llvm { |
Mon P Wang | 473bc86 | 2009-03-20 05:06:58 +0000 | [diff] [blame] | 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 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 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 | } |