blob: 74c90ed54e2f2c96602fcc422436418cbaa70156 [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 Cheng4c1aa862006-02-22 20:19:42 +000029 Reloc::Model RelocationModel;
Misha Brukmanf90e4022004-06-21 21:44:12 +000030};
Brian Gaeke323819e2004-03-04 19:16:23 +000031namespace {
32 cl::opt<bool, true> PrintCode("print-machineinstrs",
33 cl::desc("Print generated machine code"),
34 cl::location(PrintMachineCode), cl::init(false));
Misha Brukman0fb5a662004-06-21 21:08:45 +000035
Misha Brukmanf976c852005-04-21 22:55:34 +000036 cl::opt<bool, true>
Misha Brukman0fb5a662004-06-21 21:08:45 +000037 DisableFPElim("disable-fp-elim",
38 cl::desc("Disable frame pointer elimination optimization"),
Misha Brukman66d6ee42004-06-21 21:17:44 +000039 cl::location(NoFramePointerElim),
40 cl::init(false));
Chris Lattner45554a62005-01-15 06:00:32 +000041 cl::opt<bool, true>
42 DisableExcessPrecision("disable-excess-fp-precision",
Nate Begemanf8b02942005-04-15 22:12:16 +000043 cl::desc("Disable optimizations that may increase FP precision"),
44 cl::location(NoExcessFPPrecision),
45 cl::init(false));
Chris Lattner34f74a62005-04-30 04:09:52 +000046 cl::opt<bool, true>
47 EnableUnsafeFPMath("enable-unsafe-fp-math",
48 cl::desc("Enable optimizations that may decrease FP precision"),
49 cl::location(UnsafeFPMath),
50 cl::init(false));
Evan Cheng4c1aa862006-02-22 20:19:42 +000051 cl::opt<llvm::Reloc::Model, true>
52 DefRelocationModel(
53 "relocation-model",
54 cl::desc("Choose relocation model"),
55 cl::location(RelocationModel),
56 cl::init(Reloc::Default),
57 cl::values(
58 clEnumValN(Reloc::Default, "default",
59 "Target default relocation model"),
60 clEnumValN(Reloc::Static, "static",
61 "Non-relocatable code"),
62 clEnumValN(Reloc::PIC, "pic",
63 "Fully relocatable, position independent code"),
64 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
65 "Relocatable external references, non-relocatable code"),
66 clEnumValEnd));
Brian Gaeke323819e2004-03-04 19:16:23 +000067};
68
69//---------------------------------------------------------------------------
Chris Lattnerf70e0c22003-12-28 21:23:38 +000070// TargetMachine Class
71//
Chris Lattnerbc641b92006-03-23 05:43:16 +000072TargetMachine::TargetMachine(const std::string &name, bool LittleEndian,
Chris Lattnerf70e0c22003-12-28 21:23:38 +000073 unsigned char PtrSize, unsigned char PtrAl,
74 unsigned char DoubleAl, unsigned char FloatAl,
75 unsigned char LongAl, unsigned char IntAl,
Misha Brukmanc8e87642004-07-23 01:09:52 +000076 unsigned char ShortAl, unsigned char ByteAl,
77 unsigned char BoolAl)
Chris Lattnerf70e0c22003-12-28 21:23:38 +000078 : Name(name), DataLayout(name, LittleEndian,
79 PtrSize, PtrAl, DoubleAl, FloatAl, LongAl,
Misha Brukmanc8e87642004-07-23 01:09:52 +000080 IntAl, ShortAl, ByteAl, BoolAl) {
Chris Lattnerf70e0c22003-12-28 21:23:38 +000081}
Misha Brukman167deff2004-08-10 23:10:25 +000082
Chris Lattnerbc641b92006-03-23 05:43:16 +000083TargetMachine::TargetMachine(const std::string &name, const TargetData &TD)
Misha Brukman167deff2004-08-10 23:10:25 +000084 : Name(name), DataLayout(TD) {
Misha Brukman167deff2004-08-10 23:10:25 +000085}
86
Chris Lattnerbc641b92006-03-23 05:43:16 +000087TargetMachine::TargetMachine(const std::string &name, const Module &M)
Chris Lattner2bed9ec2004-03-03 02:12:47 +000088 : Name(name), DataLayout(name, &M) {
Chris Lattner2bed9ec2004-03-03 02:12:47 +000089}
Vikram S. Advedaae6992001-07-21 12:42:08 +000090
Chris Lattnerf70e0c22003-12-28 21:23:38 +000091TargetMachine::~TargetMachine() {
Chris Lattnerf70e0c22003-12-28 21:23:38 +000092}
93
Evan Cheng4c1aa862006-02-22 20:19:42 +000094/// getRelocationModel - Returns the code generation relocation model. The
95/// choices are static, PIC, and dynamic-no-pic, and target default.
96Reloc::Model TargetMachine::getRelocationModel() {
97 return RelocationModel;
98}
99
100/// setRelocationModel - Sets the code generation relocation model.
101void TargetMachine::setRelocationModel(Reloc::Model Model) {
102 RelocationModel = Model;
103}