blob: c252368b1a3b4c9a940fa44cc5c26dd55423b5b1 [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;
Anton Korobeynikov3f6d5282007-01-17 10:33:08 +000032 bool NoZerosInBSS;
Jim Laskeyd1154862007-01-29 20:48:32 +000033 bool ExceptionHandling;
Dale Johannesen876224b2008-04-14 17:54:17 +000034 bool UnwindTablesMandatory;
Evan Cheng73136df2006-02-22 20:19:42 +000035 Reloc::Model RelocationModel;
Evan Cheng04417462006-07-06 01:53:36 +000036 CodeModel::Model CMModel;
Arnold Schwaighofer9ccea992007-10-11 19:40:01 +000037 bool PerformTailCallOpt;
Devang Patel246a5272008-03-25 21:02:35 +000038 bool OptimizeForSize;
Chris Lattneraa2372562006-05-24 17:04:05 +000039}
Brian Gaeke8351d8c2004-03-04 19:16:23 +000040namespace {
41 cl::opt<bool, true> PrintCode("print-machineinstrs",
42 cl::desc("Print generated machine code"),
43 cl::location(PrintMachineCode), cl::init(false));
Misha Brukman069ca062004-06-21 21:08:45 +000044
Misha Brukman10468d82005-04-21 22:55:34 +000045 cl::opt<bool, true>
Misha Brukman069ca062004-06-21 21:08:45 +000046 DisableFPElim("disable-fp-elim",
47 cl::desc("Disable frame pointer elimination optimization"),
Misha Brukmanc22299d2004-06-21 21:17:44 +000048 cl::location(NoFramePointerElim),
49 cl::init(false));
Chris Lattner9de58902005-01-15 06:00:32 +000050 cl::opt<bool, true>
51 DisableExcessPrecision("disable-excess-fp-precision",
Nate Begeman779c5cb2005-04-15 22:12:16 +000052 cl::desc("Disable optimizations that may increase FP precision"),
53 cl::location(NoExcessFPPrecision),
54 cl::init(false));
Chris Lattner4a2cc662005-04-30 04:09:52 +000055 cl::opt<bool, true>
56 EnableUnsafeFPMath("enable-unsafe-fp-math",
57 cl::desc("Enable optimizations that may decrease FP precision"),
58 cl::location(UnsafeFPMath),
59 cl::init(false));
Evan Chengea145072006-05-23 06:39:12 +000060 cl::opt<bool, true>
Chris Lattner6ac3a372007-05-03 00:16:07 +000061 EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
Evan Chengea145072006-05-23 06:39:12 +000062 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
Evan Chengac4f66f2006-05-23 18:18:46 +000063 cl::location(FiniteOnlyFPMathOption),
Evan Chengea145072006-05-23 06:39:12 +000064 cl::init(false));
Evan Chenge107a8b2006-12-09 02:41:30 +000065 cl::opt<bool, true>
Chris Lattner6ac3a372007-05-03 00:16:07 +000066 EnableHonorSignDependentRoundingFPMath(cl::Hidden,
67 "enable-sign-dependent-rounding-fp-math",
68 cl::desc("Force codegen to assume rounding mode can change dynamically"),
69 cl::location(HonorSignDependentRoundingFPMathOption),
70 cl::init(false));
71
72 cl::opt<bool, true>
Evan Chenge107a8b2006-12-09 02:41:30 +000073 GenerateSoftFloatCalls("soft-float",
74 cl::desc("Generate software floating point library calls"),
75 cl::location(UseSoftFloat),
76 cl::init(false));
Anton Korobeynikov3f6d5282007-01-17 10:33:08 +000077 cl::opt<bool, true>
78 DontPlaceZerosInBSS("nozero-initialized-in-bss",
Chris Lattner6ac3a372007-05-03 00:16:07 +000079 cl::desc("Don't place zero-initialized symbols into bss section"),
80 cl::location(NoZerosInBSS),
81 cl::init(false));
Jim Laskeyd1154862007-01-29 20:48:32 +000082 cl::opt<bool, true>
Jim Laskey52726f52007-01-29 22:40:03 +000083 EnableExceptionHandling("enable-eh",
Dale Johannesen344aec22008-04-08 00:10:24 +000084 cl::desc("Emit DWARF exception handling (default if target supports)"),
Jim Laskeyd1154862007-01-29 20:48:32 +000085 cl::location(ExceptionHandling),
86 cl::init(false));
Dale Johannesen344aec22008-04-08 00:10:24 +000087 cl::opt<bool, true>
Dale Johannesen876224b2008-04-14 17:54:17 +000088 EnableUnwindTables("unwind-tables",
89 cl::desc("Generate unwinding tables for all functions"),
90 cl::location(UnwindTablesMandatory),
Dale Johannesen344aec22008-04-08 00:10:24 +000091 cl::init(false));
Evan Chenge107a8b2006-12-09 02:41:30 +000092
Evan Cheng73136df2006-02-22 20:19:42 +000093 cl::opt<llvm::Reloc::Model, true>
94 DefRelocationModel(
95 "relocation-model",
96 cl::desc("Choose relocation model"),
97 cl::location(RelocationModel),
98 cl::init(Reloc::Default),
99 cl::values(
100 clEnumValN(Reloc::Default, "default",
Jim Laskey82dc16c2006-08-29 15:13:10 +0000101 " Target default relocation model"),
Evan Cheng73136df2006-02-22 20:19:42 +0000102 clEnumValN(Reloc::Static, "static",
Jim Laskey82dc16c2006-08-29 15:13:10 +0000103 " Non-relocatable code"),
Chris Lattner9e56e5c2006-07-26 21:12:04 +0000104 clEnumValN(Reloc::PIC_, "pic",
Jim Laskey82dc16c2006-08-29 15:13:10 +0000105 " Fully relocatable, position independent code"),
Evan Cheng73136df2006-02-22 20:19:42 +0000106 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
Jim Laskey82dc16c2006-08-29 15:13:10 +0000107 " Relocatable external references, non-relocatable code"),
Evan Cheng73136df2006-02-22 20:19:42 +0000108 clEnumValEnd));
Evan Cheng04417462006-07-06 01:53:36 +0000109 cl::opt<llvm::CodeModel::Model, true>
110 DefCodeModel(
111 "code-model",
Chris Lattner25e62eb2007-04-19 18:42:38 +0000112 cl::desc("Choose code model"),
Evan Cheng04417462006-07-06 01:53:36 +0000113 cl::location(CMModel),
114 cl::init(CodeModel::Default),
115 cl::values(
116 clEnumValN(CodeModel::Default, "default",
Jim Laskey82dc16c2006-08-29 15:13:10 +0000117 " Target default code model"),
Evan Cheng04417462006-07-06 01:53:36 +0000118 clEnumValN(CodeModel::Small, "small",
Jim Laskey82dc16c2006-08-29 15:13:10 +0000119 " Small code model"),
Evan Cheng04417462006-07-06 01:53:36 +0000120 clEnumValN(CodeModel::Kernel, "kernel",
Jim Laskey82dc16c2006-08-29 15:13:10 +0000121 " Kernel code model"),
Evan Cheng04417462006-07-06 01:53:36 +0000122 clEnumValN(CodeModel::Medium, "medium",
Jim Laskey82dc16c2006-08-29 15:13:10 +0000123 " Medium code model"),
Evan Cheng04417462006-07-06 01:53:36 +0000124 clEnumValN(CodeModel::Large, "large",
Jim Laskey82dc16c2006-08-29 15:13:10 +0000125 " Large code model"),
Evan Cheng04417462006-07-06 01:53:36 +0000126 clEnumValEnd));
Arnold Schwaighofer9ccea992007-10-11 19:40:01 +0000127
128 cl::opt<bool, true>
129 EnablePerformTailCallOpt("tailcallopt",
130 cl::desc("Turn on tail call optimization."),
131 cl::location(PerformTailCallOpt),
132 cl::init(false));
Devang Patel246a5272008-03-25 21:02:35 +0000133 cl::opt<bool, true>
Evan Cheng88c44ef2008-03-25 22:28:39 +0000134 EnableOptimizeForSize("optimize-size",
Devang Patel246a5272008-03-25 21:02:35 +0000135 cl::desc("Optimize for size."),
136 cl::location(OptimizeForSize),
137 cl::init(false));
Chris Lattneraa2372562006-05-24 17:04:05 +0000138}
Brian Gaeke8351d8c2004-03-04 19:16:23 +0000139
140//---------------------------------------------------------------------------
Chris Lattner5d236002003-12-28 21:23:38 +0000141// TargetMachine Class
142//
Misha Brukman3decf862004-08-10 23:10:25 +0000143
Chris Lattner5d236002003-12-28 21:23:38 +0000144TargetMachine::~TargetMachine() {
Jim Laskeyae92ce82006-09-07 23:39:26 +0000145 delete AsmInfo;
Chris Lattner5d236002003-12-28 21:23:38 +0000146}
147
Evan Cheng73136df2006-02-22 20:19:42 +0000148/// getRelocationModel - Returns the code generation relocation model. The
149/// choices are static, PIC, and dynamic-no-pic, and target default.
150Reloc::Model TargetMachine::getRelocationModel() {
151 return RelocationModel;
152}
153
154/// setRelocationModel - Sets the code generation relocation model.
155void TargetMachine::setRelocationModel(Reloc::Model Model) {
156 RelocationModel = Model;
157}
Evan Chengac4f66f2006-05-23 18:18:46 +0000158
Evan Cheng04417462006-07-06 01:53:36 +0000159/// getCodeModel - Returns the code model. The choices are small, kernel,
160/// medium, large, and target default.
161CodeModel::Model TargetMachine::getCodeModel() {
162 return CMModel;
163}
164
165/// setCodeModel - Sets the code model.
166void TargetMachine::setCodeModel(CodeModel::Model Model) {
167 CMModel = Model;
168}
169
Evan Chengac4f66f2006-05-23 18:18:46 +0000170namespace llvm {
171 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
172 /// option is specified on the command line. If this returns false (default),
173 /// the code generator is not allowed to assume that FP arithmetic arguments
174 /// and results are never NaNs or +-Infs.
175 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
Chris Lattner6ac3a372007-05-03 00:16:07 +0000176
177 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
178 /// that the rounding mode of the FPU can change from its default.
179 bool HonorSignDependentRoundingFPMath() {
180 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
181 }
Reid Spencer94531bf2006-05-24 19:05:21 +0000182}
Chris Lattner2f93c0f2006-09-04 04:06:01 +0000183