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