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; |
Dan Gohman | ea8579c | 2010-02-08 20:27:50 +0000 | [diff] [blame] | 43 | bool GuaranteedTailCallOpt; |
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); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 49 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 50 | |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 51 | static cl::opt<bool, true> |
| 52 | PrintCode("print-machineinstrs", |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 53 | cl::desc("Print generated machine code"), |
| 54 | cl::location(PrintMachineCode), cl::init(false)); |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 55 | static cl::opt<bool, true> |
Evan Cheng | 94b0676 | 2008-05-30 22:39:18 +0000 | [diff] [blame] | 56 | DisableFPElim("disable-fp-elim", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 57 | cl::desc("Disable frame pointer elimination optimization"), |
| 58 | cl::location(NoFramePointerElim), |
| 59 | cl::init(false)); |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 60 | static cl::opt<bool, true> |
| 61 | DisableExcessPrecision("disable-excess-fp-precision", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 62 | cl::desc("Disable optimizations that may increase FP precision"), |
| 63 | cl::location(NoExcessFPPrecision), |
| 64 | cl::init(false)); |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 65 | static cl::opt<bool, true> |
Mon P Wang | 473bc86 | 2009-03-20 05:06:58 +0000 | [diff] [blame] | 66 | EnableFPMAD("enable-fp-mad", |
| 67 | cl::desc("Enable less precise MAD instructions to be generated"), |
| 68 | cl::location(LessPreciseFPMADOption), |
| 69 | cl::init(false)); |
| 70 | static cl::opt<bool, true> |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 71 | EnableUnsafeFPMath("enable-unsafe-fp-math", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 72 | cl::desc("Enable optimizations that may decrease FP precision"), |
| 73 | cl::location(UnsafeFPMath), |
| 74 | cl::init(false)); |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 75 | static cl::opt<bool, true> |
| 76 | EnableFiniteOnlyFPMath("enable-finite-only-fp-math", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 77 | cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"), |
| 78 | cl::location(FiniteOnlyFPMathOption), |
| 79 | cl::init(false)); |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 80 | static cl::opt<bool, true> |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 81 | EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math", |
| 82 | cl::Hidden, |
| 83 | cl::desc("Force codegen to assume rounding mode can change dynamically"), |
| 84 | cl::location(HonorSignDependentRoundingFPMathOption), |
| 85 | cl::init(false)); |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 86 | static cl::opt<bool, true> |
| 87 | GenerateSoftFloatCalls("soft-float", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 88 | cl::desc("Generate software floating point library calls"), |
| 89 | cl::location(UseSoftFloat), |
| 90 | cl::init(false)); |
Anton Korobeynikov | 1171332 | 2009-06-08 22:53:56 +0000 | [diff] [blame] | 91 | static cl::opt<llvm::FloatABI::ABIType, true> |
| 92 | FloatABIForCalls("float-abi", |
| 93 | cl::desc("Choose float ABI type"), |
| 94 | cl::location(FloatABIType), |
| 95 | cl::init(FloatABI::Default), |
| 96 | cl::values( |
| 97 | clEnumValN(FloatABI::Default, "default", |
| 98 | "Target default float ABI type"), |
| 99 | clEnumValN(FloatABI::Soft, "soft", |
| 100 | "Soft float ABI (implied by -soft-float)"), |
| 101 | clEnumValN(FloatABI::Hard, "hard", |
| 102 | "Hard float ABI (uses FP registers)"), |
| 103 | clEnumValEnd)); |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 104 | static cl::opt<bool, true> |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 105 | DontPlaceZerosInBSS("nozero-initialized-in-bss", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 106 | cl::desc("Don't place zero-initialized symbols into bss section"), |
| 107 | cl::location(NoZerosInBSS), |
| 108 | cl::init(false)); |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 109 | static cl::opt<bool, true> |
Jim Grosbach | 29feb6a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 110 | EnableDwarfExceptionHandling("enable-eh", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 111 | cl::desc("Emit DWARF exception handling (default if target supports)"), |
Jim Grosbach | 29feb6a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 112 | cl::location(DwarfExceptionHandling), |
| 113 | cl::init(false)); |
| 114 | static cl::opt<bool, true> |
| 115 | EnableSjLjExceptionHandling("enable-sjlj-eh", |
| 116 | cl::desc("Emit SJLJ exception handling (default if target supports)"), |
| 117 | cl::location(SjLjExceptionHandling), |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 118 | cl::init(false)); |
Reid Kleckner | 738b4f2 | 2009-09-20 23:52:43 +0000 | [diff] [blame] | 119 | // In debug builds, make this default to true. |
| 120 | #ifdef NDEBUG |
| 121 | #define EMIT_DEBUG false |
| 122 | #else |
| 123 | #define EMIT_DEBUG true |
| 124 | #endif |
| 125 | static cl::opt<bool, true> |
| 126 | EmitJitDebugInfo("jit-emit-debug", |
| 127 | cl::desc("Emit debug information to debugger"), |
| 128 | cl::location(JITEmitDebugInfo), |
| 129 | cl::init(EMIT_DEBUG)); |
| 130 | #undef EMIT_DEBUG |
| 131 | static cl::opt<bool, true> |
| 132 | EmitJitDebugInfoToDisk("jit-emit-debug-to-disk", |
| 133 | cl::Hidden, |
| 134 | cl::desc("Emit debug info objfiles to disk"), |
| 135 | cl::location(JITEmitDebugInfoToDisk), |
| 136 | cl::init(false)); |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 137 | static cl::opt<bool, true> |
| 138 | EnableUnwindTables("unwind-tables", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 139 | cl::desc("Generate unwinding tables for all functions"), |
| 140 | cl::location(UnwindTablesMandatory), |
| 141 | cl::init(false)); |
Arnold Schwaighofer | e2d6bbb | 2007-10-11 19:40:01 +0000 | [diff] [blame] | 142 | |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 143 | static cl::opt<llvm::Reloc::Model, true> |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 144 | DefRelocationModel("relocation-model", |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 145 | cl::desc("Choose relocation model"), |
| 146 | cl::location(RelocationModel), |
| 147 | cl::init(Reloc::Default), |
| 148 | cl::values( |
| 149 | clEnumValN(Reloc::Default, "default", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 150 | "Target default relocation model"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 151 | clEnumValN(Reloc::Static, "static", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 152 | "Non-relocatable code"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 153 | clEnumValN(Reloc::PIC_, "pic", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 154 | "Fully relocatable, position independent code"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 155 | clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 156 | "Relocatable external references, non-relocatable code"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 157 | clEnumValEnd)); |
| 158 | static cl::opt<llvm::CodeModel::Model, true> |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 159 | DefCodeModel("code-model", |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 160 | cl::desc("Choose code model"), |
| 161 | cl::location(CMModel), |
| 162 | cl::init(CodeModel::Default), |
| 163 | cl::values( |
| 164 | clEnumValN(CodeModel::Default, "default", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 165 | "Target default code model"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 166 | clEnumValN(CodeModel::Small, "small", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 167 | "Small code model"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 168 | clEnumValN(CodeModel::Kernel, "kernel", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 169 | "Kernel code model"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 170 | clEnumValN(CodeModel::Medium, "medium", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 171 | "Medium code model"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 172 | clEnumValN(CodeModel::Large, "large", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 173 | "Large code model"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 174 | clEnumValEnd)); |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 175 | static cl::opt<bool, true> |
Dan Gohman | ea8579c | 2010-02-08 20:27:50 +0000 | [diff] [blame] | 176 | EnableGuaranteedTailCallOpt("tailcallopt", |
Evan Cheng | 7ec5928 | 2010-01-27 00:10:09 +0000 | [diff] [blame] | 177 | cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."), |
Dan Gohman | ea8579c | 2010-02-08 20:27:50 +0000 | [diff] [blame] | 178 | cl::location(GuaranteedTailCallOpt), |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 179 | cl::init(false)); |
Evan Cheng | 0eeed44 | 2008-07-01 23:18:29 +0000 | [diff] [blame] | 180 | static cl::opt<unsigned, true> |
| 181 | OverrideStackAlignment("stack-alignment", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 182 | cl::desc("Override default stack alignment"), |
| 183 | cl::location(StackAlignment), |
| 184 | cl::init(0)); |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 185 | static cl::opt<bool, true> |
| 186 | EnableRealignStack("realign-stack", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 187 | cl::desc("Realign stack if needed"), |
| 188 | cl::location(RealignStack), |
| 189 | cl::init(true)); |
Evan Cheng | 0eeed44 | 2008-07-01 23:18:29 +0000 | [diff] [blame] | 190 | static cl::opt<bool, true> |
Dale Johannesen | 493492f | 2008-07-31 18:13:12 +0000 | [diff] [blame] | 191 | DisableSwitchTables(cl::Hidden, "disable-jump-tables", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 192 | cl::desc("Do not generate jump tables."), |
| 193 | cl::location(DisableJumpTables), |
| 194 | cl::init(false)); |
Owen Anderson | bac9ae2 | 2008-10-07 20:22:28 +0000 | [diff] [blame] | 195 | static cl::opt<bool, true> |
| 196 | EnableStrongPHIElim(cl::Hidden, "strong-phi-elim", |
Bill Wendling | 042eda3 | 2009-03-11 22:30:01 +0000 | [diff] [blame] | 197 | cl::desc("Use strong PHI elimination."), |
| 198 | cl::location(StrongPHIElim), |
| 199 | cl::init(false)); |
Dan Gohman | b3e9a71 | 2009-01-26 22:22:31 +0000 | [diff] [blame] | 200 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 201 | //--------------------------------------------------------------------------- |
| 202 | // TargetMachine Class |
| 203 | // |
| 204 | |
Daniel Dunbar | fe5939f | 2009-07-15 20:24:03 +0000 | [diff] [blame] | 205 | TargetMachine::TargetMachine(const Target &T) |
| 206 | : TheTarget(T), AsmInfo(0) { |
Anton Korobeynikov | 1171332 | 2009-06-08 22:53:56 +0000 | [diff] [blame] | 207 | // Typically it will be subtargets that will adjust FloatABIType from Default |
| 208 | // to Soft or Hard. |
| 209 | if (UseSoftFloat) |
| 210 | FloatABIType = FloatABI::Soft; |
| 211 | } |
| 212 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 213 | TargetMachine::~TargetMachine() { |
| 214 | delete AsmInfo; |
| 215 | } |
| 216 | |
| 217 | /// getRelocationModel - Returns the code generation relocation model. The |
| 218 | /// choices are static, PIC, and dynamic-no-pic, and target default. |
| 219 | Reloc::Model TargetMachine::getRelocationModel() { |
| 220 | return RelocationModel; |
| 221 | } |
| 222 | |
| 223 | /// setRelocationModel - Sets the code generation relocation model. |
| 224 | void TargetMachine::setRelocationModel(Reloc::Model Model) { |
| 225 | RelocationModel = Model; |
| 226 | } |
| 227 | |
| 228 | /// getCodeModel - Returns the code model. The choices are small, kernel, |
| 229 | /// medium, large, and target default. |
| 230 | CodeModel::Model TargetMachine::getCodeModel() { |
| 231 | return CMModel; |
| 232 | } |
| 233 | |
| 234 | /// setCodeModel - Sets the code model. |
| 235 | void TargetMachine::setCodeModel(CodeModel::Model Model) { |
| 236 | CMModel = Model; |
| 237 | } |
| 238 | |
Evan Cheng | 42ceb47 | 2009-03-25 01:47:28 +0000 | [diff] [blame] | 239 | bool TargetMachine::getAsmVerbosityDefault() { |
| 240 | return AsmVerbosityDefault; |
| 241 | } |
| 242 | |
| 243 | void TargetMachine::setAsmVerbosityDefault(bool V) { |
| 244 | AsmVerbosityDefault = V; |
| 245 | } |
| 246 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 247 | namespace llvm { |
Mon P Wang | 473bc86 | 2009-03-20 05:06:58 +0000 | [diff] [blame] | 248 | /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option |
| 249 | /// is specified on the command line. When this flag is off(default), the |
| 250 | /// code generator is not allowed to generate mad (multiply add) if the |
| 251 | /// result is "less precise" than doing those operations individually. |
| 252 | bool LessPreciseFPMAD() { return UnsafeFPMath || LessPreciseFPMADOption; } |
| 253 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 254 | /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math |
| 255 | /// option is specified on the command line. If this returns false (default), |
| 256 | /// the code generator is not allowed to assume that FP arithmetic arguments |
| 257 | /// and results are never NaNs or +-Infs. |
| 258 | bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; } |
| 259 | |
| 260 | /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume |
| 261 | /// that the rounding mode of the FPU can change from its default. |
| 262 | bool HonorSignDependentRoundingFPMath() { |
| 263 | return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption; |
| 264 | } |
| 265 | } |