blob: e3ea42254c61f6a338f42b1ea45c3ac143fac188 [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
Misha Brukmane67d5fb2004-06-21 21:20:23 +000014#include "llvm/Target/TargetMachine.h"
Evan Cheng4c1aa862006-02-22 20:19:42 +000015#include "llvm/Target/TargetOptions.h"
Chris Lattner93fa7052002-10-28 23:55:33 +000016#include "llvm/Type.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 Cheng4c1aa862006-02-22 20:19:42 +000030 Reloc::Model RelocationModel;
Evan Cheng152ed052006-07-06 01:53:36 +000031 CodeModel::Model CMModel;
Chris Lattnerd74ea2b2006-05-24 17:04:05 +000032}
Brian Gaeke323819e2004-03-04 19:16:23 +000033namespace {
34 cl::opt<bool, true> PrintCode("print-machineinstrs",
35 cl::desc("Print generated machine code"),
36 cl::location(PrintMachineCode), cl::init(false));
Misha Brukman0fb5a662004-06-21 21:08:45 +000037
Misha Brukmanf976c852005-04-21 22:55:34 +000038 cl::opt<bool, true>
Misha Brukman0fb5a662004-06-21 21:08:45 +000039 DisableFPElim("disable-fp-elim",
40 cl::desc("Disable frame pointer elimination optimization"),
Misha Brukman66d6ee42004-06-21 21:17:44 +000041 cl::location(NoFramePointerElim),
42 cl::init(false));
Chris Lattner45554a62005-01-15 06:00:32 +000043 cl::opt<bool, true>
44 DisableExcessPrecision("disable-excess-fp-precision",
Nate Begemanf8b02942005-04-15 22:12:16 +000045 cl::desc("Disable optimizations that may increase FP precision"),
46 cl::location(NoExcessFPPrecision),
47 cl::init(false));
Chris Lattner34f74a62005-04-30 04:09:52 +000048 cl::opt<bool, true>
49 EnableUnsafeFPMath("enable-unsafe-fp-math",
50 cl::desc("Enable optimizations that may decrease FP precision"),
51 cl::location(UnsafeFPMath),
52 cl::init(false));
Evan Cheng95942d72006-05-23 06:39:12 +000053 cl::opt<bool, true>
54 EnableFiniteOnltFPMath("enable-finite-only-fp-math",
55 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
Evan Cheng80235d52006-05-23 18:18:46 +000056 cl::location(FiniteOnlyFPMathOption),
Evan Cheng95942d72006-05-23 06:39:12 +000057 cl::init(false));
Evan Cheng4c1aa862006-02-22 20:19:42 +000058 cl::opt<llvm::Reloc::Model, true>
59 DefRelocationModel(
60 "relocation-model",
61 cl::desc("Choose relocation model"),
62 cl::location(RelocationModel),
63 cl::init(Reloc::Default),
64 cl::values(
65 clEnumValN(Reloc::Default, "default",
Jim Laskey85aaf902006-08-29 15:13:10 +000066 " Target default relocation model"),
Evan Cheng4c1aa862006-02-22 20:19:42 +000067 clEnumValN(Reloc::Static, "static",
Jim Laskey85aaf902006-08-29 15:13:10 +000068 " Non-relocatable code"),
Chris Lattner35d86fe2006-07-26 21:12:04 +000069 clEnumValN(Reloc::PIC_, "pic",
Jim Laskey85aaf902006-08-29 15:13:10 +000070 " Fully relocatable, position independent code"),
Evan Cheng4c1aa862006-02-22 20:19:42 +000071 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
Jim Laskey85aaf902006-08-29 15:13:10 +000072 " Relocatable external references, non-relocatable code"),
Evan Cheng4c1aa862006-02-22 20:19:42 +000073 clEnumValEnd));
Evan Cheng152ed052006-07-06 01:53:36 +000074 cl::opt<llvm::CodeModel::Model, true>
75 DefCodeModel(
76 "code-model",
77 cl::desc("Choose relocation model"),
78 cl::location(CMModel),
79 cl::init(CodeModel::Default),
80 cl::values(
81 clEnumValN(CodeModel::Default, "default",
Jim Laskey85aaf902006-08-29 15:13:10 +000082 " Target default code model"),
Evan Cheng152ed052006-07-06 01:53:36 +000083 clEnumValN(CodeModel::Small, "small",
Jim Laskey85aaf902006-08-29 15:13:10 +000084 " Small code model"),
Evan Cheng152ed052006-07-06 01:53:36 +000085 clEnumValN(CodeModel::Kernel, "kernel",
Jim Laskey85aaf902006-08-29 15:13:10 +000086 " Kernel code model"),
Evan Cheng152ed052006-07-06 01:53:36 +000087 clEnumValN(CodeModel::Medium, "medium",
Jim Laskey85aaf902006-08-29 15:13:10 +000088 " Medium code model"),
Evan Cheng152ed052006-07-06 01:53:36 +000089 clEnumValN(CodeModel::Large, "large",
Jim Laskey85aaf902006-08-29 15:13:10 +000090 " Large code model"),
Evan Cheng152ed052006-07-06 01:53:36 +000091 clEnumValEnd));
Chris Lattnerd74ea2b2006-05-24 17:04:05 +000092}
Brian Gaeke323819e2004-03-04 19:16:23 +000093
94//---------------------------------------------------------------------------
Chris Lattnerf70e0c22003-12-28 21:23:38 +000095// TargetMachine Class
96//
Misha Brukman167deff2004-08-10 23:10:25 +000097
Chris Lattnerf70e0c22003-12-28 21:23:38 +000098TargetMachine::~TargetMachine() {
Chris Lattnerf70e0c22003-12-28 21:23:38 +000099}
100
Evan Cheng4c1aa862006-02-22 20:19:42 +0000101/// getRelocationModel - Returns the code generation relocation model. The
102/// choices are static, PIC, and dynamic-no-pic, and target default.
103Reloc::Model TargetMachine::getRelocationModel() {
104 return RelocationModel;
105}
106
107/// setRelocationModel - Sets the code generation relocation model.
108void TargetMachine::setRelocationModel(Reloc::Model Model) {
109 RelocationModel = Model;
110}
Evan Cheng80235d52006-05-23 18:18:46 +0000111
Evan Cheng152ed052006-07-06 01:53:36 +0000112/// getCodeModel - Returns the code model. The choices are small, kernel,
113/// medium, large, and target default.
114CodeModel::Model TargetMachine::getCodeModel() {
115 return CMModel;
116}
117
118/// setCodeModel - Sets the code model.
119void TargetMachine::setCodeModel(CodeModel::Model Model) {
120 CMModel = Model;
121}
122
Evan Cheng80235d52006-05-23 18:18:46 +0000123namespace llvm {
124 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
125 /// option is specified on the command line. If this returns false (default),
126 /// the code generator is not allowed to assume that FP arithmetic arguments
127 /// and results are never NaNs or +-Infs.
128 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
Reid Spencer077b3872006-05-24 19:05:21 +0000129}