1 //===-- TargetMachine.cpp - General Target Information ---------------------==//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file describes the general parts of a Target machine.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Target/TargetMachine.h"
15 #include "llvm/Target/TargetOptions.h"
16 #include "llvm/Type.h"
17 #include "llvm/Support/CommandLine.h"
20 //---------------------------------------------------------------------------
21 // Command-line options that tend to be useful on more than one back-end.
25 bool PrintMachineCode;
26 bool NoFramePointerElim;
27 bool NoExcessFPPrecision;
29 bool FiniteOnlyFPMathOption;
30 Reloc::Model RelocationModel;
33 cl::opt<bool, true> PrintCode("print-machineinstrs",
34 cl::desc("Print generated machine code"),
35 cl::location(PrintMachineCode), cl::init(false));
38 DisableFPElim("disable-fp-elim",
39 cl::desc("Disable frame pointer elimination optimization"),
40 cl::location(NoFramePointerElim),
43 DisableExcessPrecision("disable-excess-fp-precision",
44 cl::desc("Disable optimizations that may increase FP precision"),
45 cl::location(NoExcessFPPrecision),
48 EnableUnsafeFPMath("enable-unsafe-fp-math",
49 cl::desc("Enable optimizations that may decrease FP precision"),
50 cl::location(UnsafeFPMath),
53 EnableFiniteOnltFPMath("enable-finite-only-fp-math",
54 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
55 cl::location(FiniteOnlyFPMathOption),
57 cl::opt<llvm::Reloc::Model, true>
60 cl::desc("Choose relocation model"),
61 cl::location(RelocationModel),
62 cl::init(Reloc::Default),
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"),
75 //---------------------------------------------------------------------------
76 // TargetMachine Class
79 TargetMachine::TargetMachine(const std::string &name, const Module &M)
83 TargetMachine::~TargetMachine() {
86 /// getRelocationModel - Returns the code generation relocation model. The
87 /// choices are static, PIC, and dynamic-no-pic, and target default.
88 Reloc::Model TargetMachine::getRelocationModel() {
89 return RelocationModel;
92 /// setRelocationModel - Sets the code generation relocation model.
93 void TargetMachine::setRelocationModel(Reloc::Model Model) {
94 RelocationModel = Model;
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; }