blob: 507253722e21e354a5de104682b20cb0be0760fc [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;
Chris Lattnerd74ea2b2006-05-24 17:04:05 +000031}
Brian Gaeke323819e2004-03-04 19:16:23 +000032namespace {
33 cl::opt<bool, true> PrintCode("print-machineinstrs",
34 cl::desc("Print generated machine code"),
35 cl::location(PrintMachineCode), cl::init(false));
Misha Brukman0fb5a662004-06-21 21:08:45 +000036
Misha Brukmanf976c852005-04-21 22:55:34 +000037 cl::opt<bool, true>
Misha Brukman0fb5a662004-06-21 21:08:45 +000038 DisableFPElim("disable-fp-elim",
39 cl::desc("Disable frame pointer elimination optimization"),
Misha Brukman66d6ee42004-06-21 21:17:44 +000040 cl::location(NoFramePointerElim),
41 cl::init(false));
Chris Lattner45554a62005-01-15 06:00:32 +000042 cl::opt<bool, true>
43 DisableExcessPrecision("disable-excess-fp-precision",
Nate Begemanf8b02942005-04-15 22:12:16 +000044 cl::desc("Disable optimizations that may increase FP precision"),
45 cl::location(NoExcessFPPrecision),
46 cl::init(false));
Chris Lattner34f74a62005-04-30 04:09:52 +000047 cl::opt<bool, true>
48 EnableUnsafeFPMath("enable-unsafe-fp-math",
49 cl::desc("Enable optimizations that may decrease FP precision"),
50 cl::location(UnsafeFPMath),
51 cl::init(false));
Evan Cheng95942d72006-05-23 06:39:12 +000052 cl::opt<bool, true>
53 EnableFiniteOnltFPMath("enable-finite-only-fp-math",
54 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
Evan Cheng80235d52006-05-23 18:18:46 +000055 cl::location(FiniteOnlyFPMathOption),
Evan Cheng95942d72006-05-23 06:39:12 +000056 cl::init(false));
Evan Cheng4c1aa862006-02-22 20:19:42 +000057 cl::opt<llvm::Reloc::Model, true>
58 DefRelocationModel(
59 "relocation-model",
60 cl::desc("Choose relocation model"),
61 cl::location(RelocationModel),
62 cl::init(Reloc::Default),
63 cl::values(
64 clEnumValN(Reloc::Default, "default",
65 "Target default relocation model"),
66 clEnumValN(Reloc::Static, "static",
67 "Non-relocatable code"),
68 clEnumValN(Reloc::PIC, "pic",
69 "Fully relocatable, position independent code"),
70 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
71 "Relocatable external references, non-relocatable code"),
72 clEnumValEnd));
Chris Lattnerd74ea2b2006-05-24 17:04:05 +000073}
Brian Gaeke323819e2004-03-04 19:16:23 +000074
75//---------------------------------------------------------------------------
Chris Lattnerf70e0c22003-12-28 21:23:38 +000076// TargetMachine Class
77//
Misha Brukman167deff2004-08-10 23:10:25 +000078
Chris Lattnerbc641b92006-03-23 05:43:16 +000079TargetMachine::TargetMachine(const std::string &name, const Module &M)
Owen Andersona69571c2006-05-03 01:29:57 +000080 : Name(name) {
Chris Lattner2bed9ec2004-03-03 02:12:47 +000081}
Vikram S. Advedaae6992001-07-21 12:42:08 +000082
Chris Lattnerf70e0c22003-12-28 21:23:38 +000083TargetMachine::~TargetMachine() {
Chris Lattnerf70e0c22003-12-28 21:23:38 +000084}
85
Evan Cheng4c1aa862006-02-22 20:19:42 +000086/// getRelocationModel - Returns the code generation relocation model. The
87/// choices are static, PIC, and dynamic-no-pic, and target default.
88Reloc::Model TargetMachine::getRelocationModel() {
89 return RelocationModel;
90}
91
92/// setRelocationModel - Sets the code generation relocation model.
93void TargetMachine::setRelocationModel(Reloc::Model Model) {
94 RelocationModel = Model;
95}
Evan Cheng80235d52006-05-23 18:18:46 +000096
97namespace llvm {
98 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
99 /// option is specified on the command line. If this returns false (default),
100 /// the code generator is not allowed to assume that FP arithmetic arguments
101 /// and results are never NaNs or +-Infs.
102 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
Reid Spencer077b3872006-05-24 19:05:21 +0000103}