Chris Lattner | b26bcc5 | 2001-09-14 05:34:53 +0000 | [diff] [blame] | 1 | //===-- TargetMachine.cpp - General Target Information ---------------------==// |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 2 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 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. |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 7 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | b26bcc5 | 2001-09-14 05:34:53 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file describes the general parts of a Target machine. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
Vikram S. Adve | daae699 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 13 | |
Jim Laskey | a0f3d17 | 2006-09-07 22:06:40 +0000 | [diff] [blame] | 14 | #include "llvm/Target/TargetAsmInfo.h" |
Misha Brukman | e67d5fb | 2004-06-21 21:20:23 +0000 | [diff] [blame] | 15 | #include "llvm/Target/TargetMachine.h" |
Evan Cheng | 4c1aa86 | 2006-02-22 20:19:42 +0000 | [diff] [blame] | 16 | #include "llvm/Target/TargetOptions.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 17 | #include "llvm/Support/CommandLine.h" |
Chris Lattner | f70e0c2 | 2003-12-28 21:23:38 +0000 | [diff] [blame] | 18 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 19 | |
Vikram S. Adve | e1f7280 | 2002-09-16 15:39:26 +0000 | [diff] [blame] | 20 | //--------------------------------------------------------------------------- |
Brian Gaeke | 323819e | 2004-03-04 19:16:23 +0000 | [diff] [blame] | 21 | // Command-line options that tend to be useful on more than one back-end. |
| 22 | // |
| 23 | |
Misha Brukman | f90e402 | 2004-06-21 21:44:12 +0000 | [diff] [blame] | 24 | namespace llvm { |
| 25 | bool PrintMachineCode; |
| 26 | bool NoFramePointerElim; |
Chris Lattner | 45554a6 | 2005-01-15 06:00:32 +0000 | [diff] [blame] | 27 | bool NoExcessFPPrecision; |
Chris Lattner | 34f74a6 | 2005-04-30 04:09:52 +0000 | [diff] [blame] | 28 | bool UnsafeFPMath; |
Evan Cheng | 80235d5 | 2006-05-23 18:18:46 +0000 | [diff] [blame] | 29 | bool FiniteOnlyFPMathOption; |
Chris Lattner | a7ad3d1 | 2007-05-03 00:27:11 +0000 | [diff] [blame] | 30 | bool HonorSignDependentRoundingFPMathOption; |
Evan Cheng | c9ab2f3 | 2006-12-09 02:41:30 +0000 | [diff] [blame] | 31 | bool UseSoftFloat; |
Anton Korobeynikov | 5032e5a | 2007-01-17 10:33:08 +0000 | [diff] [blame] | 32 | bool NoZerosInBSS; |
Jim Laskey | 1b340dc | 2007-01-29 20:48:32 +0000 | [diff] [blame] | 33 | bool ExceptionHandling; |
Dale Johannesen | 3541af7 | 2008-04-14 17:54:17 +0000 | [diff] [blame] | 34 | bool UnwindTablesMandatory; |
Evan Cheng | 4c1aa86 | 2006-02-22 20:19:42 +0000 | [diff] [blame] | 35 | Reloc::Model RelocationModel; |
Evan Cheng | 152ed05 | 2006-07-06 01:53:36 +0000 | [diff] [blame] | 36 | CodeModel::Model CMModel; |
Arnold Schwaighofer | c85e171 | 2007-10-11 19:40:01 +0000 | [diff] [blame] | 37 | bool PerformTailCallOpt; |
Anton Korobeynikov | 45709ae | 2008-04-23 18:18:10 +0000 | [diff] [blame] | 38 | unsigned StackAlignment; |
Evan Cheng | 6547e40 | 2008-07-01 23:18:29 +0000 | [diff] [blame] | 39 | bool RealignStack; |
| 40 | bool VerboseAsm; |
Dale Johannesen | 7232464 | 2008-07-31 18:13:12 +0000 | [diff] [blame] | 41 | bool DisableJumpTables; |
Owen Anderson | 95dad83 | 2008-10-07 20:22:28 +0000 | [diff] [blame] | 42 | bool StrongPHIElim; |
Dan Gohman | 92f4f16 | 2009-01-26 22:22:31 +0000 | [diff] [blame^] | 43 | bool DisableRedZone; |
Chris Lattner | d74ea2b | 2006-05-24 17:04:05 +0000 | [diff] [blame] | 44 | } |
Misha Brukman | 0fb5a66 | 2004-06-21 21:08:45 +0000 | [diff] [blame] | 45 | |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 46 | static cl::opt<bool, true> PrintCode("print-machineinstrs", |
| 47 | cl::desc("Print generated machine code"), |
| 48 | cl::location(PrintMachineCode), cl::init(false)); |
Chris Lattner | aa4f1e1 | 2007-05-03 00:16:07 +0000 | [diff] [blame] | 49 | |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 50 | static cl::opt<bool, true> |
Evan Cheng | 89df08c | 2008-05-30 22:39:18 +0000 | [diff] [blame] | 51 | DisableFPElim("disable-fp-elim", |
| 52 | cl::desc("Disable frame pointer elimination optimization"), |
| 53 | cl::location(NoFramePointerElim), |
| 54 | cl::init(false)); |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 55 | static cl::opt<bool, true> |
| 56 | DisableExcessPrecision("disable-excess-fp-precision", |
| 57 | cl::desc("Disable optimizations that may increase FP precision"), |
| 58 | cl::location(NoExcessFPPrecision), |
| 59 | cl::init(false)); |
| 60 | static cl::opt<bool, true> |
| 61 | EnableUnsafeFPMath("enable-unsafe-fp-math", |
| 62 | cl::desc("Enable optimizations that may decrease FP precision"), |
| 63 | cl::location(UnsafeFPMath), |
| 64 | cl::init(false)); |
| 65 | static cl::opt<bool, true> |
| 66 | EnableFiniteOnlyFPMath("enable-finite-only-fp-math", |
| 67 | cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"), |
| 68 | cl::location(FiniteOnlyFPMathOption), |
| 69 | cl::init(false)); |
| 70 | static cl::opt<bool, true> |
| 71 | EnableHonorSignDependentRoundingFPMath(cl::Hidden, |
| 72 | "enable-sign-dependent-rounding-fp-math", |
| 73 | cl::desc("Force codegen to assume rounding mode can change dynamically"), |
| 74 | cl::location(HonorSignDependentRoundingFPMathOption), |
| 75 | cl::init(false)); |
Evan Cheng | c9ab2f3 | 2006-12-09 02:41:30 +0000 | [diff] [blame] | 76 | |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 77 | static cl::opt<bool, true> |
| 78 | GenerateSoftFloatCalls("soft-float", |
| 79 | cl::desc("Generate software floating point library calls"), |
| 80 | cl::location(UseSoftFloat), |
| 81 | cl::init(false)); |
| 82 | static cl::opt<bool, true> |
| 83 | DontPlaceZerosInBSS("nozero-initialized-in-bss", |
| 84 | cl::desc("Don't place zero-initialized symbols into bss section"), |
| 85 | cl::location(NoZerosInBSS), |
| 86 | cl::init(false)); |
| 87 | static cl::opt<bool, true> |
| 88 | EnableExceptionHandling("enable-eh", |
| 89 | cl::desc("Emit DWARF exception handling (default if target supports)"), |
| 90 | cl::location(ExceptionHandling), |
| 91 | cl::init(false)); |
| 92 | static cl::opt<bool, true> |
| 93 | EnableUnwindTables("unwind-tables", |
| 94 | cl::desc("Generate unwinding tables for all functions"), |
| 95 | cl::location(UnwindTablesMandatory), |
| 96 | cl::init(false)); |
Arnold Schwaighofer | c85e171 | 2007-10-11 19:40:01 +0000 | [diff] [blame] | 97 | |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 98 | static cl::opt<llvm::Reloc::Model, true> |
| 99 | DefRelocationModel( |
| 100 | "relocation-model", |
| 101 | cl::desc("Choose relocation model"), |
| 102 | cl::location(RelocationModel), |
| 103 | cl::init(Reloc::Default), |
| 104 | cl::values( |
| 105 | clEnumValN(Reloc::Default, "default", |
Dan Gohman | b8cab92 | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 106 | "Target default relocation model"), |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 107 | clEnumValN(Reloc::Static, "static", |
Dan Gohman | b8cab92 | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 108 | "Non-relocatable code"), |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 109 | clEnumValN(Reloc::PIC_, "pic", |
Dan Gohman | b8cab92 | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 110 | "Fully relocatable, position independent code"), |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 111 | clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic", |
Dan Gohman | b8cab92 | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 112 | "Relocatable external references, non-relocatable code"), |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 113 | clEnumValEnd)); |
| 114 | static cl::opt<llvm::CodeModel::Model, true> |
| 115 | DefCodeModel( |
| 116 | "code-model", |
| 117 | cl::desc("Choose code model"), |
| 118 | cl::location(CMModel), |
| 119 | cl::init(CodeModel::Default), |
| 120 | cl::values( |
| 121 | clEnumValN(CodeModel::Default, "default", |
Dan Gohman | b8cab92 | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 122 | "Target default code model"), |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 123 | clEnumValN(CodeModel::Small, "small", |
Dan Gohman | b8cab92 | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 124 | "Small code model"), |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 125 | clEnumValN(CodeModel::Kernel, "kernel", |
Dan Gohman | b8cab92 | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 126 | "Kernel code model"), |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 127 | clEnumValN(CodeModel::Medium, "medium", |
Dan Gohman | b8cab92 | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 128 | "Medium code model"), |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 129 | clEnumValN(CodeModel::Large, "large", |
Dan Gohman | b8cab92 | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 130 | "Large code model"), |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 131 | clEnumValEnd)); |
Anton Korobeynikov | 45709ae | 2008-04-23 18:18:10 +0000 | [diff] [blame] | 132 | |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 133 | static cl::opt<bool, true> |
| 134 | EnablePerformTailCallOpt("tailcallopt", |
| 135 | cl::desc("Turn on tail call optimization."), |
| 136 | cl::location(PerformTailCallOpt), |
| 137 | cl::init(false)); |
Anton Korobeynikov | 45709ae | 2008-04-23 18:18:10 +0000 | [diff] [blame] | 138 | |
Evan Cheng | 6547e40 | 2008-07-01 23:18:29 +0000 | [diff] [blame] | 139 | static cl::opt<unsigned, true> |
| 140 | OverrideStackAlignment("stack-alignment", |
| 141 | cl::desc("Override default stack alignment"), |
| 142 | cl::location(StackAlignment), |
| 143 | cl::init(0)); |
| 144 | |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 145 | static cl::opt<bool, true> |
| 146 | EnableRealignStack("realign-stack", |
| 147 | cl::desc("Realign stack if needed"), |
| 148 | cl::location(RealignStack), |
| 149 | cl::init(true)); |
| 150 | |
Evan Cheng | 6547e40 | 2008-07-01 23:18:29 +0000 | [diff] [blame] | 151 | static cl::opt<bool, true> |
| 152 | AsmVerbose("asm-verbose", cl::desc("Add comments to directives."), |
| 153 | cl::location(VerboseAsm), |
| 154 | cl::init(false)); |
| 155 | |
Dale Johannesen | 7232464 | 2008-07-31 18:13:12 +0000 | [diff] [blame] | 156 | static cl::opt<bool, true> |
| 157 | DisableSwitchTables(cl::Hidden, "disable-jump-tables", |
| 158 | cl::desc("Do not generate jump tables."), |
| 159 | cl::location(DisableJumpTables), |
| 160 | cl::init(false)); |
Brian Gaeke | 323819e | 2004-03-04 19:16:23 +0000 | [diff] [blame] | 161 | |
Owen Anderson | 95dad83 | 2008-10-07 20:22:28 +0000 | [diff] [blame] | 162 | static cl::opt<bool, true> |
| 163 | EnableStrongPHIElim(cl::Hidden, "strong-phi-elim", |
| 164 | cl::desc("Use strong PHI elimination."), |
| 165 | cl::location(StrongPHIElim), |
| 166 | cl::init(false)); |
| 167 | |
Dan Gohman | 92f4f16 | 2009-01-26 22:22:31 +0000 | [diff] [blame^] | 168 | static cl::opt<bool, true> |
| 169 | DisableRedZoneOption("disable-red-zone", |
| 170 | cl::desc("Do not emit code that uses the red zone."), |
| 171 | cl::location(DisableRedZone), |
| 172 | cl::init(true)); |
| 173 | |
Brian Gaeke | 323819e | 2004-03-04 19:16:23 +0000 | [diff] [blame] | 174 | //--------------------------------------------------------------------------- |
Chris Lattner | f70e0c2 | 2003-12-28 21:23:38 +0000 | [diff] [blame] | 175 | // TargetMachine Class |
| 176 | // |
Misha Brukman | 167deff | 2004-08-10 23:10:25 +0000 | [diff] [blame] | 177 | |
Chris Lattner | f70e0c2 | 2003-12-28 21:23:38 +0000 | [diff] [blame] | 178 | TargetMachine::~TargetMachine() { |
Jim Laskey | fde1b3b | 2006-09-07 23:39:26 +0000 | [diff] [blame] | 179 | delete AsmInfo; |
Chris Lattner | f70e0c2 | 2003-12-28 21:23:38 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Evan Cheng | 4c1aa86 | 2006-02-22 20:19:42 +0000 | [diff] [blame] | 182 | /// getRelocationModel - Returns the code generation relocation model. The |
| 183 | /// choices are static, PIC, and dynamic-no-pic, and target default. |
| 184 | Reloc::Model TargetMachine::getRelocationModel() { |
| 185 | return RelocationModel; |
| 186 | } |
| 187 | |
| 188 | /// setRelocationModel - Sets the code generation relocation model. |
| 189 | void TargetMachine::setRelocationModel(Reloc::Model Model) { |
| 190 | RelocationModel = Model; |
| 191 | } |
Evan Cheng | 80235d5 | 2006-05-23 18:18:46 +0000 | [diff] [blame] | 192 | |
Evan Cheng | 152ed05 | 2006-07-06 01:53:36 +0000 | [diff] [blame] | 193 | /// getCodeModel - Returns the code model. The choices are small, kernel, |
| 194 | /// medium, large, and target default. |
| 195 | CodeModel::Model TargetMachine::getCodeModel() { |
| 196 | return CMModel; |
| 197 | } |
| 198 | |
| 199 | /// setCodeModel - Sets the code model. |
| 200 | void TargetMachine::setCodeModel(CodeModel::Model Model) { |
| 201 | CMModel = Model; |
| 202 | } |
| 203 | |
Evan Cheng | 80235d5 | 2006-05-23 18:18:46 +0000 | [diff] [blame] | 204 | namespace llvm { |
| 205 | /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math |
| 206 | /// option is specified on the command line. If this returns false (default), |
| 207 | /// the code generator is not allowed to assume that FP arithmetic arguments |
| 208 | /// and results are never NaNs or +-Infs. |
| 209 | bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; } |
Chris Lattner | aa4f1e1 | 2007-05-03 00:16:07 +0000 | [diff] [blame] | 210 | |
| 211 | /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume |
| 212 | /// that the rounding mode of the FPU can change from its default. |
| 213 | bool HonorSignDependentRoundingFPMath() { |
| 214 | return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption; |
| 215 | } |
Reid Spencer | 077b387 | 2006-05-24 19:05:21 +0000 | [diff] [blame] | 216 | } |
Chris Lattner | 3199af2 | 2006-09-04 04:06:01 +0000 | [diff] [blame] | 217 | |