blob: 15164ca28dfc0a59f82bf593b9b74cc4670ff0f9 [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;
Evan Cheng4c1aa862006-02-22 20:19:42 +000034 Reloc::Model RelocationModel;
Evan Cheng152ed052006-07-06 01:53:36 +000035 CodeModel::Model CMModel;
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +000036 bool PerformTailCallOpt;
Chris Lattnerd74ea2b2006-05-24 17:04:05 +000037}
Brian Gaeke323819e2004-03-04 19:16:23 +000038namespace {
39 cl::opt<bool, true> PrintCode("print-machineinstrs",
40 cl::desc("Print generated machine code"),
41 cl::location(PrintMachineCode), cl::init(false));
Misha Brukman0fb5a662004-06-21 21:08:45 +000042
Misha Brukmanf976c852005-04-21 22:55:34 +000043 cl::opt<bool, true>
Misha Brukman0fb5a662004-06-21 21:08:45 +000044 DisableFPElim("disable-fp-elim",
45 cl::desc("Disable frame pointer elimination optimization"),
Misha Brukman66d6ee42004-06-21 21:17:44 +000046 cl::location(NoFramePointerElim),
47 cl::init(false));
Chris Lattner45554a62005-01-15 06:00:32 +000048 cl::opt<bool, true>
49 DisableExcessPrecision("disable-excess-fp-precision",
Nate Begemanf8b02942005-04-15 22:12:16 +000050 cl::desc("Disable optimizations that may increase FP precision"),
51 cl::location(NoExcessFPPrecision),
52 cl::init(false));
Chris Lattner34f74a62005-04-30 04:09:52 +000053 cl::opt<bool, true>
54 EnableUnsafeFPMath("enable-unsafe-fp-math",
55 cl::desc("Enable optimizations that may decrease FP precision"),
56 cl::location(UnsafeFPMath),
57 cl::init(false));
Evan Cheng95942d72006-05-23 06:39:12 +000058 cl::opt<bool, true>
Chris Lattneraa4f1e12007-05-03 00:16:07 +000059 EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
Evan Cheng95942d72006-05-23 06:39:12 +000060 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
Evan Cheng80235d52006-05-23 18:18:46 +000061 cl::location(FiniteOnlyFPMathOption),
Evan Cheng95942d72006-05-23 06:39:12 +000062 cl::init(false));
Evan Chengc9ab2f32006-12-09 02:41:30 +000063 cl::opt<bool, true>
Chris Lattneraa4f1e12007-05-03 00:16:07 +000064 EnableHonorSignDependentRoundingFPMath(cl::Hidden,
65 "enable-sign-dependent-rounding-fp-math",
66 cl::desc("Force codegen to assume rounding mode can change dynamically"),
67 cl::location(HonorSignDependentRoundingFPMathOption),
68 cl::init(false));
69
70 cl::opt<bool, true>
Evan Chengc9ab2f32006-12-09 02:41:30 +000071 GenerateSoftFloatCalls("soft-float",
72 cl::desc("Generate software floating point library calls"),
73 cl::location(UseSoftFloat),
74 cl::init(false));
Anton Korobeynikov5032e5a2007-01-17 10:33:08 +000075 cl::opt<bool, true>
76 DontPlaceZerosInBSS("nozero-initialized-in-bss",
Chris Lattneraa4f1e12007-05-03 00:16:07 +000077 cl::desc("Don't place zero-initialized symbols into bss section"),
78 cl::location(NoZerosInBSS),
79 cl::init(false));
Jim Laskey1b340dc2007-01-29 20:48:32 +000080 cl::opt<bool, true>
Jim Laskey73c56242007-01-29 22:40:03 +000081 EnableExceptionHandling("enable-eh",
Jim Laskey1b340dc2007-01-29 20:48:32 +000082 cl::desc("Exception handling should be emitted."),
83 cl::location(ExceptionHandling),
84 cl::init(false));
Evan Chengc9ab2f32006-12-09 02:41:30 +000085
Evan Cheng4c1aa862006-02-22 20:19:42 +000086 cl::opt<llvm::Reloc::Model, true>
87 DefRelocationModel(
88 "relocation-model",
89 cl::desc("Choose relocation model"),
90 cl::location(RelocationModel),
91 cl::init(Reloc::Default),
92 cl::values(
93 clEnumValN(Reloc::Default, "default",
Jim Laskey85aaf902006-08-29 15:13:10 +000094 " Target default relocation model"),
Evan Cheng4c1aa862006-02-22 20:19:42 +000095 clEnumValN(Reloc::Static, "static",
Jim Laskey85aaf902006-08-29 15:13:10 +000096 " Non-relocatable code"),
Chris Lattner35d86fe2006-07-26 21:12:04 +000097 clEnumValN(Reloc::PIC_, "pic",
Jim Laskey85aaf902006-08-29 15:13:10 +000098 " Fully relocatable, position independent code"),
Evan Cheng4c1aa862006-02-22 20:19:42 +000099 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
Jim Laskey85aaf902006-08-29 15:13:10 +0000100 " Relocatable external references, non-relocatable code"),
Evan Cheng4c1aa862006-02-22 20:19:42 +0000101 clEnumValEnd));
Evan Cheng152ed052006-07-06 01:53:36 +0000102 cl::opt<llvm::CodeModel::Model, true>
103 DefCodeModel(
104 "code-model",
Chris Lattner3e1b03f2007-04-19 18:42:38 +0000105 cl::desc("Choose code model"),
Evan Cheng152ed052006-07-06 01:53:36 +0000106 cl::location(CMModel),
107 cl::init(CodeModel::Default),
108 cl::values(
109 clEnumValN(CodeModel::Default, "default",
Jim Laskey85aaf902006-08-29 15:13:10 +0000110 " Target default code model"),
Evan Cheng152ed052006-07-06 01:53:36 +0000111 clEnumValN(CodeModel::Small, "small",
Jim Laskey85aaf902006-08-29 15:13:10 +0000112 " Small code model"),
Evan Cheng152ed052006-07-06 01:53:36 +0000113 clEnumValN(CodeModel::Kernel, "kernel",
Jim Laskey85aaf902006-08-29 15:13:10 +0000114 " Kernel code model"),
Evan Cheng152ed052006-07-06 01:53:36 +0000115 clEnumValN(CodeModel::Medium, "medium",
Jim Laskey85aaf902006-08-29 15:13:10 +0000116 " Medium code model"),
Evan Cheng152ed052006-07-06 01:53:36 +0000117 clEnumValN(CodeModel::Large, "large",
Jim Laskey85aaf902006-08-29 15:13:10 +0000118 " Large code model"),
Evan Cheng152ed052006-07-06 01:53:36 +0000119 clEnumValEnd));
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +0000120
121 cl::opt<bool, true>
122 EnablePerformTailCallOpt("tailcallopt",
123 cl::desc("Turn on tail call optimization."),
124 cl::location(PerformTailCallOpt),
125 cl::init(false));
Chris Lattnerd74ea2b2006-05-24 17:04:05 +0000126}
Brian Gaeke323819e2004-03-04 19:16:23 +0000127
128//---------------------------------------------------------------------------
Chris Lattnerf70e0c22003-12-28 21:23:38 +0000129// TargetMachine Class
130//
Misha Brukman167deff2004-08-10 23:10:25 +0000131
Chris Lattnerf70e0c22003-12-28 21:23:38 +0000132TargetMachine::~TargetMachine() {
Jim Laskeyfde1b3b2006-09-07 23:39:26 +0000133 delete AsmInfo;
Chris Lattnerf70e0c22003-12-28 21:23:38 +0000134}
135
Evan Cheng4c1aa862006-02-22 20:19:42 +0000136/// getRelocationModel - Returns the code generation relocation model. The
137/// choices are static, PIC, and dynamic-no-pic, and target default.
138Reloc::Model TargetMachine::getRelocationModel() {
139 return RelocationModel;
140}
141
142/// setRelocationModel - Sets the code generation relocation model.
143void TargetMachine::setRelocationModel(Reloc::Model Model) {
144 RelocationModel = Model;
145}
Evan Cheng80235d52006-05-23 18:18:46 +0000146
Evan Cheng152ed052006-07-06 01:53:36 +0000147/// getCodeModel - Returns the code model. The choices are small, kernel,
148/// medium, large, and target default.
149CodeModel::Model TargetMachine::getCodeModel() {
150 return CMModel;
151}
152
153/// setCodeModel - Sets the code model.
154void TargetMachine::setCodeModel(CodeModel::Model Model) {
155 CMModel = Model;
156}
157
Evan Cheng80235d52006-05-23 18:18:46 +0000158namespace llvm {
159 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
160 /// option is specified on the command line. If this returns false (default),
161 /// the code generator is not allowed to assume that FP arithmetic arguments
162 /// and results are never NaNs or +-Infs.
163 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
Chris Lattneraa4f1e12007-05-03 00:16:07 +0000164
165 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
166 /// that the rounding mode of the FPU can change from its default.
167 bool HonorSignDependentRoundingFPMath() {
168 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
169 }
Reid Spencer077b3872006-05-24 19:05:21 +0000170}
Chris Lattner3199af22006-09-04 04:06:01 +0000171