blob: 1065b095bc8c4c2571d341259c6ce2740e3e7b70 [file] [log] [blame]
Chris Lattnerb26bcc52001-09-14 05:34:53 +00001//===-- TargetMachine.cpp - General Target Information ---------------------==//
Misha Brukmanf976c852005-04-21 22:55:34 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-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 Brukmanf976c852005-04-21 22:55:34 +00007//
John Criswellb576c942003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattnerb26bcc52001-09-14 05:34:53 +00009//
10// This file describes the general parts of a Target machine.
11//
12//===----------------------------------------------------------------------===//
Vikram S. Advedaae6992001-07-21 12:42:08 +000013
Jim Laskeya0f3d172006-09-07 22:06:40 +000014#include "llvm/Target/TargetAsmInfo.h"
Misha Brukmane67d5fb2004-06-21 21:20:23 +000015#include "llvm/Target/TargetMachine.h"
Evan Cheng4c1aa862006-02-22 20:19:42 +000016#include "llvm/Target/TargetOptions.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000017#include "llvm/Support/CommandLine.h"
Chris Lattnerf70e0c22003-12-28 21:23:38 +000018using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000019
Vikram S. Advee1f72802002-09-16 15:39:26 +000020//---------------------------------------------------------------------------
Brian Gaeke323819e2004-03-04 19:16:23 +000021// Command-line options that tend to be useful on more than one back-end.
22//
23
Misha Brukmanf90e4022004-06-21 21:44:12 +000024namespace llvm {
25 bool PrintMachineCode;
26 bool NoFramePointerElim;
Chris Lattner45554a62005-01-15 06:00:32 +000027 bool NoExcessFPPrecision;
Chris Lattner34f74a62005-04-30 04:09:52 +000028 bool UnsafeFPMath;
Evan Cheng80235d52006-05-23 18:18:46 +000029 bool FiniteOnlyFPMathOption;
Chris Lattnera7ad3d12007-05-03 00:27:11 +000030 bool HonorSignDependentRoundingFPMathOption;
Evan Chengc9ab2f32006-12-09 02:41:30 +000031 bool UseSoftFloat;
Anton Korobeynikov5032e5a2007-01-17 10:33:08 +000032 bool NoZerosInBSS;
Jim Laskey1b340dc2007-01-29 20:48:32 +000033 bool ExceptionHandling;
Dale Johannesen3541af72008-04-14 17:54:17 +000034 bool UnwindTablesMandatory;
Evan Cheng4c1aa862006-02-22 20:19:42 +000035 Reloc::Model RelocationModel;
Evan Cheng152ed052006-07-06 01:53:36 +000036 CodeModel::Model CMModel;
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +000037 bool PerformTailCallOpt;
Devang Patel55c666a2008-03-25 21:02:35 +000038 bool OptimizeForSize;
Anton Korobeynikov45709ae2008-04-23 18:18:10 +000039 bool RealignStack;
40 unsigned StackAlignment;
Chris Lattnerd74ea2b2006-05-24 17:04:05 +000041}
Brian Gaeke323819e2004-03-04 19:16:23 +000042namespace {
Dan Gohman3c02aca2008-04-23 23:15:23 +000043 static cl::opt<bool, true> PrintCode("print-machineinstrs",
Brian Gaeke323819e2004-03-04 19:16:23 +000044 cl::desc("Print generated machine code"),
45 cl::location(PrintMachineCode), cl::init(false));
Misha Brukman0fb5a662004-06-21 21:08:45 +000046
Dan Gohman3c02aca2008-04-23 23:15:23 +000047 static cl::opt<bool, true>
Misha Brukman0fb5a662004-06-21 21:08:45 +000048 DisableFPElim("disable-fp-elim",
49 cl::desc("Disable frame pointer elimination optimization"),
Misha Brukman66d6ee42004-06-21 21:17:44 +000050 cl::location(NoFramePointerElim),
51 cl::init(false));
Dan Gohman3c02aca2008-04-23 23:15:23 +000052 static cl::opt<bool, true>
Chris Lattner45554a62005-01-15 06:00:32 +000053 DisableExcessPrecision("disable-excess-fp-precision",
Nate Begemanf8b02942005-04-15 22:12:16 +000054 cl::desc("Disable optimizations that may increase FP precision"),
55 cl::location(NoExcessFPPrecision),
56 cl::init(false));
Dan Gohman3c02aca2008-04-23 23:15:23 +000057 static cl::opt<bool, true>
Chris Lattner34f74a62005-04-30 04:09:52 +000058 EnableUnsafeFPMath("enable-unsafe-fp-math",
59 cl::desc("Enable optimizations that may decrease FP precision"),
60 cl::location(UnsafeFPMath),
61 cl::init(false));
Dan Gohman3c02aca2008-04-23 23:15:23 +000062 static cl::opt<bool, true>
Chris Lattneraa4f1e12007-05-03 00:16:07 +000063 EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
Evan Cheng95942d72006-05-23 06:39:12 +000064 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
Evan Cheng80235d52006-05-23 18:18:46 +000065 cl::location(FiniteOnlyFPMathOption),
Evan Cheng95942d72006-05-23 06:39:12 +000066 cl::init(false));
Dan Gohman3c02aca2008-04-23 23:15:23 +000067 static cl::opt<bool, true>
Chris Lattneraa4f1e12007-05-03 00:16:07 +000068 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 Gohman3c02aca2008-04-23 23:15:23 +000074 static cl::opt<bool, true>
Evan Chengc9ab2f32006-12-09 02:41:30 +000075 GenerateSoftFloatCalls("soft-float",
76 cl::desc("Generate software floating point library calls"),
77 cl::location(UseSoftFloat),
78 cl::init(false));
Dan Gohman3c02aca2008-04-23 23:15:23 +000079 static cl::opt<bool, true>
Anton Korobeynikov5032e5a2007-01-17 10:33:08 +000080 DontPlaceZerosInBSS("nozero-initialized-in-bss",
Chris Lattneraa4f1e12007-05-03 00:16:07 +000081 cl::desc("Don't place zero-initialized symbols into bss section"),
82 cl::location(NoZerosInBSS),
83 cl::init(false));
Dan Gohman3c02aca2008-04-23 23:15:23 +000084 static cl::opt<bool, true>
Jim Laskey73c56242007-01-29 22:40:03 +000085 EnableExceptionHandling("enable-eh",
Dale Johannesen4e1b7942008-04-08 00:10:24 +000086 cl::desc("Emit DWARF exception handling (default if target supports)"),
Jim Laskey1b340dc2007-01-29 20:48:32 +000087 cl::location(ExceptionHandling),
88 cl::init(false));
Dan Gohman3c02aca2008-04-23 23:15:23 +000089 static cl::opt<bool, true>
Dale Johannesen3541af72008-04-14 17:54:17 +000090 EnableUnwindTables("unwind-tables",
91 cl::desc("Generate unwinding tables for all functions"),
92 cl::location(UnwindTablesMandatory),
Dale Johannesen4e1b7942008-04-08 00:10:24 +000093 cl::init(false));
Evan Chengc9ab2f32006-12-09 02:41:30 +000094
Dan Gohman3c02aca2008-04-23 23:15:23 +000095 static cl::opt<llvm::Reloc::Model, true>
Evan Cheng4c1aa862006-02-22 20:19:42 +000096 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",
Jim Laskey85aaf902006-08-29 15:13:10 +0000103 " Target default relocation model"),
Evan Cheng4c1aa862006-02-22 20:19:42 +0000104 clEnumValN(Reloc::Static, "static",
Jim Laskey85aaf902006-08-29 15:13:10 +0000105 " Non-relocatable code"),
Chris Lattner35d86fe2006-07-26 21:12:04 +0000106 clEnumValN(Reloc::PIC_, "pic",
Jim Laskey85aaf902006-08-29 15:13:10 +0000107 " Fully relocatable, position independent code"),
Evan Cheng4c1aa862006-02-22 20:19:42 +0000108 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
Jim Laskey85aaf902006-08-29 15:13:10 +0000109 " Relocatable external references, non-relocatable code"),
Evan Cheng4c1aa862006-02-22 20:19:42 +0000110 clEnumValEnd));
Dan Gohman3c02aca2008-04-23 23:15:23 +0000111 static cl::opt<llvm::CodeModel::Model, true>
Evan Cheng152ed052006-07-06 01:53:36 +0000112 DefCodeModel(
113 "code-model",
Chris Lattner3e1b03f2007-04-19 18:42:38 +0000114 cl::desc("Choose code model"),
Evan Cheng152ed052006-07-06 01:53:36 +0000115 cl::location(CMModel),
116 cl::init(CodeModel::Default),
117 cl::values(
118 clEnumValN(CodeModel::Default, "default",
Jim Laskey85aaf902006-08-29 15:13:10 +0000119 " Target default code model"),
Evan Cheng152ed052006-07-06 01:53:36 +0000120 clEnumValN(CodeModel::Small, "small",
Jim Laskey85aaf902006-08-29 15:13:10 +0000121 " Small code model"),
Evan Cheng152ed052006-07-06 01:53:36 +0000122 clEnumValN(CodeModel::Kernel, "kernel",
Jim Laskey85aaf902006-08-29 15:13:10 +0000123 " Kernel code model"),
Evan Cheng152ed052006-07-06 01:53:36 +0000124 clEnumValN(CodeModel::Medium, "medium",
Jim Laskey85aaf902006-08-29 15:13:10 +0000125 " Medium code model"),
Evan Cheng152ed052006-07-06 01:53:36 +0000126 clEnumValN(CodeModel::Large, "large",
Jim Laskey85aaf902006-08-29 15:13:10 +0000127 " Large code model"),
Evan Cheng152ed052006-07-06 01:53:36 +0000128 clEnumValEnd));
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +0000129
Dan Gohman3c02aca2008-04-23 23:15:23 +0000130 static cl::opt<bool, true>
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +0000131 EnablePerformTailCallOpt("tailcallopt",
132 cl::desc("Turn on tail call optimization."),
133 cl::location(PerformTailCallOpt),
134 cl::init(false));
Dan Gohman3c02aca2008-04-23 23:15:23 +0000135 static cl::opt<bool, true>
Evan Cheng26593432008-03-25 22:28:39 +0000136 EnableOptimizeForSize("optimize-size",
Devang Patel55c666a2008-03-25 21:02:35 +0000137 cl::desc("Optimize for size."),
138 cl::location(OptimizeForSize),
139 cl::init(false));
Anton Korobeynikov45709ae2008-04-23 18:18:10 +0000140
Dan Gohman4a3f6c82008-05-06 01:53:16 +0000141 static cl::opt<bool, true>
Anton Korobeynikov45709ae2008-04-23 18:18:10 +0000142 EnableRealignStack("realign-stack",
143 cl::desc("Realign stack if needed"),
144 cl::location(RealignStack),
145 cl::init(true));
146
Dan Gohman4a3f6c82008-05-06 01:53:16 +0000147 static cl::opt<unsigned, true>
Anton Korobeynikov45709ae2008-04-23 18:18:10 +0000148 OverrideStackAlignment("stack-alignment",
149 cl::desc("Override default stack alignment"),
150 cl::location(StackAlignment),
151 cl::init(0));
Chris Lattnerd74ea2b2006-05-24 17:04:05 +0000152}
Brian Gaeke323819e2004-03-04 19:16:23 +0000153
154//---------------------------------------------------------------------------
Chris Lattnerf70e0c22003-12-28 21:23:38 +0000155// TargetMachine Class
156//
Misha Brukman167deff2004-08-10 23:10:25 +0000157
Chris Lattnerf70e0c22003-12-28 21:23:38 +0000158TargetMachine::~TargetMachine() {
Jim Laskeyfde1b3b2006-09-07 23:39:26 +0000159 delete AsmInfo;
Chris Lattnerf70e0c22003-12-28 21:23:38 +0000160}
161
Evan Cheng4c1aa862006-02-22 20:19:42 +0000162/// getRelocationModel - Returns the code generation relocation model. The
163/// choices are static, PIC, and dynamic-no-pic, and target default.
164Reloc::Model TargetMachine::getRelocationModel() {
165 return RelocationModel;
166}
167
168/// setRelocationModel - Sets the code generation relocation model.
169void TargetMachine::setRelocationModel(Reloc::Model Model) {
170 RelocationModel = Model;
171}
Evan Cheng80235d52006-05-23 18:18:46 +0000172
Evan Cheng152ed052006-07-06 01:53:36 +0000173/// getCodeModel - Returns the code model. The choices are small, kernel,
174/// medium, large, and target default.
175CodeModel::Model TargetMachine::getCodeModel() {
176 return CMModel;
177}
178
179/// setCodeModel - Sets the code model.
180void TargetMachine::setCodeModel(CodeModel::Model Model) {
181 CMModel = Model;
182}
183
Evan Cheng80235d52006-05-23 18:18:46 +0000184namespace 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; }
Chris Lattneraa4f1e12007-05-03 00:16:07 +0000190
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 }
Reid Spencer077b3872006-05-24 19:05:21 +0000196}
Chris Lattner3199af22006-09-04 04:06:01 +0000197