blob: 7f5ad587211dcd67d5caaf78e2e83be57503e969 [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//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source 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;
Evan Chengc9ab2f32006-12-09 02:41:30 +000030 bool UseSoftFloat;
Anton Korobeynikov5032e5a2007-01-17 10:33:08 +000031 bool NoZerosInBSS;
Jim Laskey1b340dc2007-01-29 20:48:32 +000032 bool ExceptionHandling;
Evan Cheng4c1aa862006-02-22 20:19:42 +000033 Reloc::Model RelocationModel;
Evan Cheng152ed052006-07-06 01:53:36 +000034 CodeModel::Model CMModel;
Chris Lattnerd74ea2b2006-05-24 17:04:05 +000035}
Brian Gaeke323819e2004-03-04 19:16:23 +000036namespace {
37 cl::opt<bool, true> PrintCode("print-machineinstrs",
38 cl::desc("Print generated machine code"),
39 cl::location(PrintMachineCode), cl::init(false));
Misha Brukman0fb5a662004-06-21 21:08:45 +000040
Misha Brukmanf976c852005-04-21 22:55:34 +000041 cl::opt<bool, true>
Misha Brukman0fb5a662004-06-21 21:08:45 +000042 DisableFPElim("disable-fp-elim",
43 cl::desc("Disable frame pointer elimination optimization"),
Misha Brukman66d6ee42004-06-21 21:17:44 +000044 cl::location(NoFramePointerElim),
45 cl::init(false));
Chris Lattner45554a62005-01-15 06:00:32 +000046 cl::opt<bool, true>
47 DisableExcessPrecision("disable-excess-fp-precision",
Nate Begemanf8b02942005-04-15 22:12:16 +000048 cl::desc("Disable optimizations that may increase FP precision"),
49 cl::location(NoExcessFPPrecision),
50 cl::init(false));
Chris Lattner34f74a62005-04-30 04:09:52 +000051 cl::opt<bool, true>
52 EnableUnsafeFPMath("enable-unsafe-fp-math",
53 cl::desc("Enable optimizations that may decrease FP precision"),
54 cl::location(UnsafeFPMath),
55 cl::init(false));
Evan Cheng95942d72006-05-23 06:39:12 +000056 cl::opt<bool, true>
57 EnableFiniteOnltFPMath("enable-finite-only-fp-math",
58 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
Evan Cheng80235d52006-05-23 18:18:46 +000059 cl::location(FiniteOnlyFPMathOption),
Evan Cheng95942d72006-05-23 06:39:12 +000060 cl::init(false));
Evan Chengc9ab2f32006-12-09 02:41:30 +000061 cl::opt<bool, true>
62 GenerateSoftFloatCalls("soft-float",
63 cl::desc("Generate software floating point library calls"),
64 cl::location(UseSoftFloat),
65 cl::init(false));
Anton Korobeynikov5032e5a2007-01-17 10:33:08 +000066 cl::opt<bool, true>
67 DontPlaceZerosInBSS("nozero-initialized-in-bss",
68 cl::desc("Don't place zero-initialized symbols into bss section"),
69 cl::location(NoZerosInBSS),
70 cl::init(false));
Jim Laskey1b340dc2007-01-29 20:48:32 +000071 cl::opt<bool, true>
Jim Laskey73c56242007-01-29 22:40:03 +000072 EnableExceptionHandling("enable-eh",
Jim Laskey1b340dc2007-01-29 20:48:32 +000073 cl::desc("Exception handling should be emitted."),
74 cl::location(ExceptionHandling),
75 cl::init(false));
Evan Chengc9ab2f32006-12-09 02:41:30 +000076
Evan Cheng4c1aa862006-02-22 20:19:42 +000077 cl::opt<llvm::Reloc::Model, true>
78 DefRelocationModel(
79 "relocation-model",
80 cl::desc("Choose relocation model"),
81 cl::location(RelocationModel),
82 cl::init(Reloc::Default),
83 cl::values(
84 clEnumValN(Reloc::Default, "default",
Jim Laskey85aaf902006-08-29 15:13:10 +000085 " Target default relocation model"),
Evan Cheng4c1aa862006-02-22 20:19:42 +000086 clEnumValN(Reloc::Static, "static",
Jim Laskey85aaf902006-08-29 15:13:10 +000087 " Non-relocatable code"),
Chris Lattner35d86fe2006-07-26 21:12:04 +000088 clEnumValN(Reloc::PIC_, "pic",
Jim Laskey85aaf902006-08-29 15:13:10 +000089 " Fully relocatable, position independent code"),
Evan Cheng4c1aa862006-02-22 20:19:42 +000090 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
Jim Laskey85aaf902006-08-29 15:13:10 +000091 " Relocatable external references, non-relocatable code"),
Evan Cheng4c1aa862006-02-22 20:19:42 +000092 clEnumValEnd));
Evan Cheng152ed052006-07-06 01:53:36 +000093 cl::opt<llvm::CodeModel::Model, true>
94 DefCodeModel(
95 "code-model",
96 cl::desc("Choose relocation model"),
97 cl::location(CMModel),
98 cl::init(CodeModel::Default),
99 cl::values(
100 clEnumValN(CodeModel::Default, "default",
Jim Laskey85aaf902006-08-29 15:13:10 +0000101 " Target default code model"),
Evan Cheng152ed052006-07-06 01:53:36 +0000102 clEnumValN(CodeModel::Small, "small",
Jim Laskey85aaf902006-08-29 15:13:10 +0000103 " Small code model"),
Evan Cheng152ed052006-07-06 01:53:36 +0000104 clEnumValN(CodeModel::Kernel, "kernel",
Jim Laskey85aaf902006-08-29 15:13:10 +0000105 " Kernel code model"),
Evan Cheng152ed052006-07-06 01:53:36 +0000106 clEnumValN(CodeModel::Medium, "medium",
Jim Laskey85aaf902006-08-29 15:13:10 +0000107 " Medium code model"),
Evan Cheng152ed052006-07-06 01:53:36 +0000108 clEnumValN(CodeModel::Large, "large",
Jim Laskey85aaf902006-08-29 15:13:10 +0000109 " Large code model"),
Evan Cheng152ed052006-07-06 01:53:36 +0000110 clEnumValEnd));
Chris Lattnerd74ea2b2006-05-24 17:04:05 +0000111}
Brian Gaeke323819e2004-03-04 19:16:23 +0000112
113//---------------------------------------------------------------------------
Chris Lattnerf70e0c22003-12-28 21:23:38 +0000114// TargetMachine Class
115//
Misha Brukman167deff2004-08-10 23:10:25 +0000116
Chris Lattnerf70e0c22003-12-28 21:23:38 +0000117TargetMachine::~TargetMachine() {
Jim Laskeyfde1b3b2006-09-07 23:39:26 +0000118 delete AsmInfo;
Chris Lattnerf70e0c22003-12-28 21:23:38 +0000119}
120
Evan Cheng4c1aa862006-02-22 20:19:42 +0000121/// getRelocationModel - Returns the code generation relocation model. The
122/// choices are static, PIC, and dynamic-no-pic, and target default.
123Reloc::Model TargetMachine::getRelocationModel() {
124 return RelocationModel;
125}
126
127/// setRelocationModel - Sets the code generation relocation model.
128void TargetMachine::setRelocationModel(Reloc::Model Model) {
129 RelocationModel = Model;
130}
Evan Cheng80235d52006-05-23 18:18:46 +0000131
Evan Cheng152ed052006-07-06 01:53:36 +0000132/// getCodeModel - Returns the code model. The choices are small, kernel,
133/// medium, large, and target default.
134CodeModel::Model TargetMachine::getCodeModel() {
135 return CMModel;
136}
137
138/// setCodeModel - Sets the code model.
139void TargetMachine::setCodeModel(CodeModel::Model Model) {
140 CMModel = Model;
141}
142
Evan Cheng80235d52006-05-23 18:18:46 +0000143namespace llvm {
144 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
145 /// option is specified on the command line. If this returns false (default),
146 /// the code generator is not allowed to assume that FP arithmetic arguments
147 /// and results are never NaNs or +-Infs.
148 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
Reid Spencer077b3872006-05-24 19:05:21 +0000149}
Chris Lattner3199af22006-09-04 04:06:01 +0000150