LLVM API Documentation

TargetMachine.cpp

Go to the documentation of this file.
00001 //===-- TargetMachine.cpp - General Target Information ---------------------==//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file describes the general parts of a Target machine.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/Target/TargetMachine.h"
00015 #include "llvm/Target/TargetOptions.h"
00016 #include "llvm/Type.h"
00017 #include "llvm/Support/CommandLine.h"
00018 using namespace llvm;
00019 
00020 //---------------------------------------------------------------------------
00021 // Command-line options that tend to be useful on more than one back-end.
00022 //
00023 
00024 namespace llvm {
00025   bool PrintMachineCode;
00026   bool NoFramePointerElim;
00027   bool NoExcessFPPrecision;
00028   bool UnsafeFPMath;
00029   bool FiniteOnlyFPMathOption;
00030   Reloc::Model RelocationModel;
00031   CodeModel::Model CMModel;
00032 }
00033 namespace {
00034   cl::opt<bool, true> PrintCode("print-machineinstrs",
00035     cl::desc("Print generated machine code"),
00036     cl::location(PrintMachineCode), cl::init(false));
00037 
00038   cl::opt<bool, true>
00039     DisableFPElim("disable-fp-elim",
00040                   cl::desc("Disable frame pointer elimination optimization"),
00041                   cl::location(NoFramePointerElim),
00042                   cl::init(false));
00043   cl::opt<bool, true>
00044   DisableExcessPrecision("disable-excess-fp-precision",
00045                cl::desc("Disable optimizations that may increase FP precision"),
00046                cl::location(NoExcessFPPrecision),
00047                cl::init(false));
00048   cl::opt<bool, true>
00049   EnableUnsafeFPMath("enable-unsafe-fp-math",
00050                cl::desc("Enable optimizations that may decrease FP precision"),
00051                cl::location(UnsafeFPMath),
00052                cl::init(false));
00053   cl::opt<bool, true>
00054   EnableFiniteOnltFPMath("enable-finite-only-fp-math",
00055                cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
00056                cl::location(FiniteOnlyFPMathOption),
00057                cl::init(false));
00058   cl::opt<llvm::Reloc::Model, true>
00059   DefRelocationModel(
00060     "relocation-model",
00061     cl::desc("Choose relocation model"),
00062     cl::location(RelocationModel),
00063     cl::init(Reloc::Default),
00064     cl::values(
00065       clEnumValN(Reloc::Default, "default",
00066                  "Target default relocation model"),
00067       clEnumValN(Reloc::Static, "static",
00068                  "Non-relocatable code"),
00069       clEnumValN(Reloc::PIC_, "pic",
00070                  "Fully relocatable, position independent code"),
00071       clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
00072                  "Relocatable external references, non-relocatable code"),
00073       clEnumValEnd));
00074   cl::opt<llvm::CodeModel::Model, true>
00075   DefCodeModel(
00076     "code-model",
00077     cl::desc("Choose relocation model"),
00078     cl::location(CMModel),
00079     cl::init(CodeModel::Default),
00080     cl::values(
00081       clEnumValN(CodeModel::Default, "default",
00082                  "Target default code model"),
00083       clEnumValN(CodeModel::Small, "small",
00084                  "Small code model"),
00085       clEnumValN(CodeModel::Kernel, "kernel",
00086                  "Kernel code model"),
00087       clEnumValN(CodeModel::Medium, "medium",
00088                  "Medium code model"),
00089       clEnumValN(CodeModel::Large, "large",
00090                  "Large code model"),
00091       clEnumValEnd));
00092 }
00093 
00094 //---------------------------------------------------------------------------
00095 // TargetMachine Class
00096 //
00097 
00098 TargetMachine::TargetMachine(const std::string &name, const Module &M)
00099   : Name(name) {
00100 }
00101 
00102 TargetMachine::~TargetMachine() {
00103 }
00104 
00105 /// getRelocationModel - Returns the code generation relocation model. The
00106 /// choices are static, PIC, and dynamic-no-pic, and target default.
00107 Reloc::Model TargetMachine::getRelocationModel() {
00108   return RelocationModel;
00109 }
00110 
00111 /// setRelocationModel - Sets the code generation relocation model.
00112 void TargetMachine::setRelocationModel(Reloc::Model Model) {
00113   RelocationModel = Model;
00114 }
00115 
00116 /// getCodeModel - Returns the code model. The choices are small, kernel,
00117 /// medium, large, and target default.
00118 CodeModel::Model TargetMachine::getCodeModel() {
00119   return CMModel;
00120 }
00121 
00122 /// setCodeModel - Sets the code model.
00123 void TargetMachine::setCodeModel(CodeModel::Model Model) {
00124   CMModel = Model;
00125 }
00126 
00127 namespace llvm {
00128   /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
00129   /// option is specified on the command line. If this returns false (default),
00130   /// the code generator is not allowed to assume that FP arithmetic arguments
00131   /// and results are never NaNs or +-Infs.
00132   bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
00133 }