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