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