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; |
Anton Korobeynikov | b214a52 | 2008-04-23 18:18:10 +0000 | [diff] [blame] | 38 | unsigned StackAlignment; |
Evan Cheng | 0eeed44 | 2008-07-01 23:18:29 +0000 | [diff] [blame] | 39 | bool RealignStack; |
| 40 | bool VerboseAsm; |
Dale Johannesen | 493492f | 2008-07-31 18:13:12 +0000 | [diff] [blame] | 41 | bool DisableJumpTables; |
Owen Anderson | bac9ae2 | 2008-10-07 20:22:28 +0000 | [diff] [blame] | 42 | bool StrongPHIElim; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 43 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 44 | |
Dan Gohman | 089efff | 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)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 48 | |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 49 | static cl::opt<bool, true> |
Evan Cheng | 94b0676 | 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 | 089efff | 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)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 75 | |
Dan Gohman | 089efff | 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 | e2d6bbb | 2007-10-11 19:40:01 +0000 | [diff] [blame] | 96 | |
Dan Gohman | 089efff | 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", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame^] | 105 | "Target default relocation model"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 106 | clEnumValN(Reloc::Static, "static", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame^] | 107 | "Non-relocatable code"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 108 | clEnumValN(Reloc::PIC_, "pic", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame^] | 109 | "Fully relocatable, position independent code"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 110 | clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame^] | 111 | "Relocatable external references, non-relocatable code"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 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", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame^] | 121 | "Target default code model"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 122 | clEnumValN(CodeModel::Small, "small", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame^] | 123 | "Small code model"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 124 | clEnumValN(CodeModel::Kernel, "kernel", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame^] | 125 | "Kernel code model"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 126 | clEnumValN(CodeModel::Medium, "medium", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame^] | 127 | "Medium code model"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 128 | clEnumValN(CodeModel::Large, "large", |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame^] | 129 | "Large code model"), |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 130 | clEnumValEnd)); |
Anton Korobeynikov | b214a52 | 2008-04-23 18:18:10 +0000 | [diff] [blame] | 131 | |
Dan Gohman | 089efff | 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)); |
Anton Korobeynikov | b214a52 | 2008-04-23 18:18:10 +0000 | [diff] [blame] | 137 | |
Evan Cheng | 0eeed44 | 2008-07-01 23:18:29 +0000 | [diff] [blame] | 138 | static cl::opt<unsigned, true> |
| 139 | OverrideStackAlignment("stack-alignment", |
| 140 | cl::desc("Override default stack alignment"), |
| 141 | cl::location(StackAlignment), |
| 142 | cl::init(0)); |
| 143 | |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 144 | static cl::opt<bool, true> |
| 145 | EnableRealignStack("realign-stack", |
| 146 | cl::desc("Realign stack if needed"), |
| 147 | cl::location(RealignStack), |
| 148 | cl::init(true)); |
| 149 | |
Evan Cheng | 0eeed44 | 2008-07-01 23:18:29 +0000 | [diff] [blame] | 150 | static cl::opt<bool, true> |
| 151 | AsmVerbose("asm-verbose", cl::desc("Add comments to directives."), |
| 152 | cl::location(VerboseAsm), |
| 153 | cl::init(false)); |
| 154 | |
Dale Johannesen | 493492f | 2008-07-31 18:13:12 +0000 | [diff] [blame] | 155 | static cl::opt<bool, true> |
| 156 | DisableSwitchTables(cl::Hidden, "disable-jump-tables", |
| 157 | cl::desc("Do not generate jump tables."), |
| 158 | cl::location(DisableJumpTables), |
| 159 | cl::init(false)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 160 | |
Owen Anderson | bac9ae2 | 2008-10-07 20:22:28 +0000 | [diff] [blame] | 161 | static cl::opt<bool, true> |
| 162 | EnableStrongPHIElim(cl::Hidden, "strong-phi-elim", |
| 163 | cl::desc("Use strong PHI elimination."), |
| 164 | cl::location(StrongPHIElim), |
| 165 | cl::init(false)); |
| 166 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 167 | //--------------------------------------------------------------------------- |
| 168 | // TargetMachine Class |
| 169 | // |
| 170 | |
| 171 | TargetMachine::~TargetMachine() { |
| 172 | delete AsmInfo; |
| 173 | } |
| 174 | |
| 175 | /// getRelocationModel - Returns the code generation relocation model. The |
| 176 | /// choices are static, PIC, and dynamic-no-pic, and target default. |
| 177 | Reloc::Model TargetMachine::getRelocationModel() { |
| 178 | return RelocationModel; |
| 179 | } |
| 180 | |
| 181 | /// setRelocationModel - Sets the code generation relocation model. |
| 182 | void TargetMachine::setRelocationModel(Reloc::Model Model) { |
| 183 | RelocationModel = Model; |
| 184 | } |
| 185 | |
| 186 | /// getCodeModel - Returns the code model. The choices are small, kernel, |
| 187 | /// medium, large, and target default. |
| 188 | CodeModel::Model TargetMachine::getCodeModel() { |
| 189 | return CMModel; |
| 190 | } |
| 191 | |
| 192 | /// setCodeModel - Sets the code model. |
| 193 | void TargetMachine::setCodeModel(CodeModel::Model Model) { |
| 194 | CMModel = Model; |
| 195 | } |
| 196 | |
| 197 | namespace llvm { |
| 198 | /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math |
| 199 | /// option is specified on the command line. If this returns false (default), |
| 200 | /// the code generator is not allowed to assume that FP arithmetic arguments |
| 201 | /// and results are never NaNs or +-Infs. |
| 202 | bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; } |
| 203 | |
| 204 | /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume |
| 205 | /// that the rounding mode of the FPU can change from its default. |
| 206 | bool HonorSignDependentRoundingFPMath() { |
| 207 | return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption; |
| 208 | } |
| 209 | } |
| 210 | |