TargetMachine.cpp revision bc641b9d8b5ecafe0137c1a49f4777608981d81b
1//===-- TargetMachine.cpp - General Target Information ---------------------==//
2//
3//                     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.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the general parts of a Target machine.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/Target/TargetMachine.h"
15#include "llvm/Target/TargetOptions.h"
16#include "llvm/Type.h"
17#include "llvm/Support/CommandLine.h"
18using namespace llvm;
19
20//---------------------------------------------------------------------------
21// Command-line options that tend to be useful on more than one back-end.
22//
23
24namespace llvm {
25  bool PrintMachineCode;
26  bool NoFramePointerElim;
27  bool NoExcessFPPrecision;
28  bool UnsafeFPMath;
29  Reloc::Model RelocationModel;
30};
31namespace {
32  cl::opt<bool, true> PrintCode("print-machineinstrs",
33    cl::desc("Print generated machine code"),
34    cl::location(PrintMachineCode), cl::init(false));
35
36  cl::opt<bool, true>
37    DisableFPElim("disable-fp-elim",
38                  cl::desc("Disable frame pointer elimination optimization"),
39                  cl::location(NoFramePointerElim),
40                  cl::init(false));
41  cl::opt<bool, true>
42  DisableExcessPrecision("disable-excess-fp-precision",
43               cl::desc("Disable optimizations that may increase FP precision"),
44               cl::location(NoExcessFPPrecision),
45               cl::init(false));
46  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));
51  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));
67};
68
69//---------------------------------------------------------------------------
70// TargetMachine Class
71//
72TargetMachine::TargetMachine(const std::string &name, bool LittleEndian,
73                             unsigned char PtrSize, unsigned char PtrAl,
74                             unsigned char DoubleAl, unsigned char FloatAl,
75                             unsigned char LongAl, unsigned char IntAl,
76                             unsigned char ShortAl, unsigned char ByteAl,
77                             unsigned char BoolAl)
78  : Name(name), DataLayout(name, LittleEndian,
79                           PtrSize, PtrAl, DoubleAl, FloatAl, LongAl,
80                           IntAl, ShortAl, ByteAl, BoolAl) {
81}
82
83TargetMachine::TargetMachine(const std::string &name, const TargetData &TD)
84  : Name(name), DataLayout(TD) {
85}
86
87TargetMachine::TargetMachine(const std::string &name, const Module &M)
88  : Name(name), DataLayout(name, &M) {
89}
90
91TargetMachine::~TargetMachine() {
92}
93
94/// 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}
104