blob: 2aed083341266a79b6e73c5633ea48fd5cab63f9 [file] [log] [blame]
Chris Lattner22a6a902001-09-14 05:34:53 +00001//===-- TargetMachine.cpp - General Target Information ---------------------==//
Misha Brukman10468d82005-04-21 22:55:34 +00002//
John Criswell482202a2003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman10468d82005-04-21 22:55:34 +00007//
John Criswell482202a2003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner22a6a902001-09-14 05:34:53 +00009//
10// This file describes the general parts of a Target machine.
11//
12//===----------------------------------------------------------------------===//
Vikram S. Adve3414e782001-07-21 12:42:08 +000013
Jim Laskey261779b2006-09-07 22:06:40 +000014#include "llvm/Target/TargetAsmInfo.h"
Misha Brukman0bfea682004-06-21 21:20:23 +000015#include "llvm/Target/TargetMachine.h"
Evan Cheng73136df2006-02-22 20:19:42 +000016#include "llvm/Target/TargetOptions.h"
Reid Spencer7c16caa2004-09-01 22:55:40 +000017#include "llvm/Support/CommandLine.h"
Chris Lattner5d236002003-12-28 21:23:38 +000018using namespace llvm;
Brian Gaeke960707c2003-11-11 22:41:34 +000019
Vikram S. Adve36d3e032002-09-16 15:39:26 +000020//---------------------------------------------------------------------------
Brian Gaeke8351d8c2004-03-04 19:16:23 +000021// Command-line options that tend to be useful on more than one back-end.
22//
23
Misha Brukman96041e52004-06-21 21:44:12 +000024namespace llvm {
25 bool PrintMachineCode;
26 bool NoFramePointerElim;
Chris Lattner9de58902005-01-15 06:00:32 +000027 bool NoExcessFPPrecision;
Chris Lattner4a2cc662005-04-30 04:09:52 +000028 bool UnsafeFPMath;
Evan Chengac4f66f2006-05-23 18:18:46 +000029 bool FiniteOnlyFPMathOption;
Chris Lattnerf65f18b2007-05-03 00:27:11 +000030 bool HonorSignDependentRoundingFPMathOption;
Evan Chenge107a8b2006-12-09 02:41:30 +000031 bool UseSoftFloat;
Bill Wendling42adc732009-03-11 22:30:01 +000032 bool NoImplicitFloat;
Anton Korobeynikov3f6d5282007-01-17 10:33:08 +000033 bool NoZerosInBSS;
Jim Laskeyd1154862007-01-29 20:48:32 +000034 bool ExceptionHandling;
Dale Johannesen876224b2008-04-14 17:54:17 +000035 bool UnwindTablesMandatory;
Evan Cheng73136df2006-02-22 20:19:42 +000036 Reloc::Model RelocationModel;
Evan Cheng04417462006-07-06 01:53:36 +000037 CodeModel::Model CMModel;
Arnold Schwaighofer9ccea992007-10-11 19:40:01 +000038 bool PerformTailCallOpt;
Anton Korobeynikovcb195f52008-04-23 18:18:10 +000039 unsigned StackAlignment;
Evan Chengc963f6c2008-07-01 23:18:29 +000040 bool RealignStack;
41 bool VerboseAsm;
Dale Johannesenc31eb202008-07-31 18:13:12 +000042 bool DisableJumpTables;
Owen Anderson1d338fc2008-10-07 20:22:28 +000043 bool StrongPHIElim;
Dan Gohmanb6d36e12009-01-26 22:22:31 +000044 bool DisableRedZone;
Chris Lattneraa2372562006-05-24 17:04:05 +000045}
Misha Brukman069ca062004-06-21 21:08:45 +000046
Bill Wendling42adc732009-03-11 22:30:01 +000047static cl::opt<bool, true>
48PrintCode("print-machineinstrs",
Dan Gohmand78c4002008-05-13 00:00:25 +000049 cl::desc("Print generated machine code"),
50 cl::location(PrintMachineCode), cl::init(false));
Dan Gohmand78c4002008-05-13 00:00:25 +000051static cl::opt<bool, true>
Evan Cheng864541a2008-05-30 22:39:18 +000052DisableFPElim("disable-fp-elim",
Bill Wendling42adc732009-03-11 22:30:01 +000053 cl::desc("Disable frame pointer elimination optimization"),
54 cl::location(NoFramePointerElim),
55 cl::init(false));
Dan Gohmand78c4002008-05-13 00:00:25 +000056static cl::opt<bool, true>
57DisableExcessPrecision("disable-excess-fp-precision",
Bill Wendling42adc732009-03-11 22:30:01 +000058 cl::desc("Disable optimizations that may increase FP precision"),
59 cl::location(NoExcessFPPrecision),
60 cl::init(false));
Dan Gohmand78c4002008-05-13 00:00:25 +000061static cl::opt<bool, true>
62EnableUnsafeFPMath("enable-unsafe-fp-math",
Bill Wendling42adc732009-03-11 22:30:01 +000063 cl::desc("Enable optimizations that may decrease FP precision"),
64 cl::location(UnsafeFPMath),
65 cl::init(false));
Dan Gohmand78c4002008-05-13 00:00:25 +000066static cl::opt<bool, true>
67EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
Bill Wendling42adc732009-03-11 22:30:01 +000068 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
69 cl::location(FiniteOnlyFPMathOption),
70 cl::init(false));
Dan Gohmand78c4002008-05-13 00:00:25 +000071static cl::opt<bool, true>
Bill Wendling42adc732009-03-11 22:30:01 +000072EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
73 cl::Hidden,
74 cl::desc("Force codegen to assume rounding mode can change dynamically"),
75 cl::location(HonorSignDependentRoundingFPMathOption),
76 cl::init(false));
Dan Gohmand78c4002008-05-13 00:00:25 +000077static cl::opt<bool, true>
78GenerateSoftFloatCalls("soft-float",
Bill Wendling42adc732009-03-11 22:30:01 +000079 cl::desc("Generate software floating point library calls"),
80 cl::location(UseSoftFloat),
81 cl::init(false));
82static cl::opt<bool, true>
83GenerateNoImplicitFloats("no-implicit-float",
84 cl::desc("Don't generate implicit floating point instructions (x86-only)"),
85 cl::location(NoImplicitFloat),
86 cl::init(false));
Dan Gohmand78c4002008-05-13 00:00:25 +000087static cl::opt<bool, true>
88DontPlaceZerosInBSS("nozero-initialized-in-bss",
Bill Wendling42adc732009-03-11 22:30:01 +000089 cl::desc("Don't place zero-initialized symbols into bss section"),
90 cl::location(NoZerosInBSS),
91 cl::init(false));
Dan Gohmand78c4002008-05-13 00:00:25 +000092static cl::opt<bool, true>
93EnableExceptionHandling("enable-eh",
Bill Wendling42adc732009-03-11 22:30:01 +000094 cl::desc("Emit DWARF exception handling (default if target supports)"),
95 cl::location(ExceptionHandling),
96 cl::init(false));
Dan Gohmand78c4002008-05-13 00:00:25 +000097static cl::opt<bool, true>
98EnableUnwindTables("unwind-tables",
Bill Wendling42adc732009-03-11 22:30:01 +000099 cl::desc("Generate unwinding tables for all functions"),
100 cl::location(UnwindTablesMandatory),
101 cl::init(false));
Arnold Schwaighofer9ccea992007-10-11 19:40:01 +0000102
Dan Gohmand78c4002008-05-13 00:00:25 +0000103static cl::opt<llvm::Reloc::Model, true>
Bill Wendling42adc732009-03-11 22:30:01 +0000104DefRelocationModel("relocation-model",
Dan Gohmand78c4002008-05-13 00:00:25 +0000105 cl::desc("Choose relocation model"),
106 cl::location(RelocationModel),
107 cl::init(Reloc::Default),
108 cl::values(
109 clEnumValN(Reloc::Default, "default",
Dan Gohman9c4b7d52008-10-14 20:25:08 +0000110 "Target default relocation model"),
Dan Gohmand78c4002008-05-13 00:00:25 +0000111 clEnumValN(Reloc::Static, "static",
Dan Gohman9c4b7d52008-10-14 20:25:08 +0000112 "Non-relocatable code"),
Dan Gohmand78c4002008-05-13 00:00:25 +0000113 clEnumValN(Reloc::PIC_, "pic",
Dan Gohman9c4b7d52008-10-14 20:25:08 +0000114 "Fully relocatable, position independent code"),
Dan Gohmand78c4002008-05-13 00:00:25 +0000115 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
Dan Gohman9c4b7d52008-10-14 20:25:08 +0000116 "Relocatable external references, non-relocatable code"),
Dan Gohmand78c4002008-05-13 00:00:25 +0000117 clEnumValEnd));
118static cl::opt<llvm::CodeModel::Model, true>
Bill Wendling42adc732009-03-11 22:30:01 +0000119DefCodeModel("code-model",
Dan Gohmand78c4002008-05-13 00:00:25 +0000120 cl::desc("Choose code model"),
121 cl::location(CMModel),
122 cl::init(CodeModel::Default),
123 cl::values(
124 clEnumValN(CodeModel::Default, "default",
Dan Gohman9c4b7d52008-10-14 20:25:08 +0000125 "Target default code model"),
Dan Gohmand78c4002008-05-13 00:00:25 +0000126 clEnumValN(CodeModel::Small, "small",
Dan Gohman9c4b7d52008-10-14 20:25:08 +0000127 "Small code model"),
Dan Gohmand78c4002008-05-13 00:00:25 +0000128 clEnumValN(CodeModel::Kernel, "kernel",
Dan Gohman9c4b7d52008-10-14 20:25:08 +0000129 "Kernel code model"),
Dan Gohmand78c4002008-05-13 00:00:25 +0000130 clEnumValN(CodeModel::Medium, "medium",
Dan Gohman9c4b7d52008-10-14 20:25:08 +0000131 "Medium code model"),
Dan Gohmand78c4002008-05-13 00:00:25 +0000132 clEnumValN(CodeModel::Large, "large",
Dan Gohman9c4b7d52008-10-14 20:25:08 +0000133 "Large code model"),
Dan Gohmand78c4002008-05-13 00:00:25 +0000134 clEnumValEnd));
Dan Gohmand78c4002008-05-13 00:00:25 +0000135static cl::opt<bool, true>
136EnablePerformTailCallOpt("tailcallopt",
Bill Wendling42adc732009-03-11 22:30:01 +0000137 cl::desc("Turn on tail call optimization."),
138 cl::location(PerformTailCallOpt),
139 cl::init(false));
Evan Chengc963f6c2008-07-01 23:18:29 +0000140static cl::opt<unsigned, true>
141OverrideStackAlignment("stack-alignment",
Bill Wendling42adc732009-03-11 22:30:01 +0000142 cl::desc("Override default stack alignment"),
143 cl::location(StackAlignment),
144 cl::init(0));
Dan Gohmand78c4002008-05-13 00:00:25 +0000145static cl::opt<bool, true>
146EnableRealignStack("realign-stack",
Bill Wendling42adc732009-03-11 22:30:01 +0000147 cl::desc("Realign stack if needed"),
148 cl::location(RealignStack),
149 cl::init(true));
Evan Chengc963f6c2008-07-01 23:18:29 +0000150static cl::opt<bool, true>
151AsmVerbose("asm-verbose", cl::desc("Add comments to directives."),
Bill Wendling42adc732009-03-11 22:30:01 +0000152 cl::location(VerboseAsm),
153 cl::init(false));
Dale Johannesenc31eb202008-07-31 18:13:12 +0000154static cl::opt<bool, true>
155DisableSwitchTables(cl::Hidden, "disable-jump-tables",
Bill Wendling42adc732009-03-11 22:30:01 +0000156 cl::desc("Do not generate jump tables."),
157 cl::location(DisableJumpTables),
158 cl::init(false));
Owen Anderson1d338fc2008-10-07 20:22:28 +0000159static cl::opt<bool, true>
160EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
Bill Wendling42adc732009-03-11 22:30:01 +0000161 cl::desc("Use strong PHI elimination."),
162 cl::location(StrongPHIElim),
163 cl::init(false));
Dan Gohmanb6d36e12009-01-26 22:22:31 +0000164static cl::opt<bool, true>
165DisableRedZoneOption("disable-red-zone",
Bill Wendling42adc732009-03-11 22:30:01 +0000166 cl::desc("Do not emit code that uses the red zone."),
167 cl::location(DisableRedZone),
168 cl::init(false));
Dan Gohmanb6d36e12009-01-26 22:22:31 +0000169
Brian Gaeke8351d8c2004-03-04 19:16:23 +0000170//---------------------------------------------------------------------------
Chris Lattner5d236002003-12-28 21:23:38 +0000171// TargetMachine Class
172//
Misha Brukman3decf862004-08-10 23:10:25 +0000173
Chris Lattner5d236002003-12-28 21:23:38 +0000174TargetMachine::~TargetMachine() {
Jim Laskeyae92ce82006-09-07 23:39:26 +0000175 delete AsmInfo;
Chris Lattner5d236002003-12-28 21:23:38 +0000176}
177
Evan Cheng73136df2006-02-22 20:19:42 +0000178/// getRelocationModel - Returns the code generation relocation model. The
179/// choices are static, PIC, and dynamic-no-pic, and target default.
180Reloc::Model TargetMachine::getRelocationModel() {
181 return RelocationModel;
182}
183
184/// setRelocationModel - Sets the code generation relocation model.
185void TargetMachine::setRelocationModel(Reloc::Model Model) {
186 RelocationModel = Model;
187}
Evan Chengac4f66f2006-05-23 18:18:46 +0000188
Evan Cheng04417462006-07-06 01:53:36 +0000189/// getCodeModel - Returns the code model. The choices are small, kernel,
190/// medium, large, and target default.
191CodeModel::Model TargetMachine::getCodeModel() {
192 return CMModel;
193}
194
195/// setCodeModel - Sets the code model.
196void TargetMachine::setCodeModel(CodeModel::Model Model) {
197 CMModel = Model;
198}
199
Evan Chengac4f66f2006-05-23 18:18:46 +0000200namespace llvm {
201 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
202 /// option is specified on the command line. If this returns false (default),
203 /// the code generator is not allowed to assume that FP arithmetic arguments
204 /// and results are never NaNs or +-Infs.
205 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
Chris Lattner6ac3a372007-05-03 00:16:07 +0000206
207 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
208 /// that the rounding mode of the FPU can change from its default.
209 bool HonorSignDependentRoundingFPMath() {
210 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
211 }
Reid Spencer94531bf2006-05-24 19:05:21 +0000212}
Chris Lattner2f93c0f2006-09-04 04:06:01 +0000213