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   Reloc::Model RelocationModel;
00030 };
00031 namespace {
00032   cl::opt<bool, true> PrintCode("print-machineinstrs",
00033     cl::desc("Print generated machine code"),
00034     cl::location(PrintMachineCode), cl::init(false));
00035 
00036   cl::opt<bool, true>
00037     DisableFPElim("disable-fp-elim",
00038                   cl::desc("Disable frame pointer elimination optimization"),
00039                   cl::location(NoFramePointerElim),
00040                   cl::init(false));
00041   cl::opt<bool, true>
00042   DisableExcessPrecision("disable-excess-fp-precision",
00043                cl::desc("Disable optimizations that may increase FP precision"),
00044                cl::location(NoExcessFPPrecision),
00045                cl::init(false));
00046   cl::opt<bool, true>
00047   EnableUnsafeFPMath("enable-unsafe-fp-math",
00048                cl::desc("Enable optimizations that may decrease FP precision"),
00049                cl::location(UnsafeFPMath),
00050                cl::init(false));
00051   cl::opt<llvm::Reloc::Model, true>
00052   DefRelocationModel(
00053     "relocation-model",
00054     cl::desc("Choose relocation model"),
00055     cl::location(RelocationModel),
00056     cl::init(Reloc::Default),
00057     cl::values(
00058       clEnumValN(Reloc::Default, "default",
00059                  "Target default relocation model"),
00060       clEnumValN(Reloc::Static, "static",
00061                  "Non-relocatable code"),
00062       clEnumValN(Reloc::PIC, "pic",
00063                  "Fully relocatable, position independent code"),
00064       clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
00065                  "Relocatable external references, non-relocatable code"),
00066       clEnumValEnd));
00067 };
00068 
00069 //---------------------------------------------------------------------------
00070 // TargetMachine Class
00071 //
00072 TargetMachine::TargetMachine(const std::string &name, bool LittleEndian,
00073                              unsigned char PtrSize, unsigned char PtrAl,
00074                              unsigned char DoubleAl, unsigned char FloatAl,
00075                              unsigned char LongAl, unsigned char IntAl,
00076                              unsigned char ShortAl, unsigned char ByteAl,
00077                              unsigned char BoolAl)
00078   : Name(name), DataLayout(name, LittleEndian,
00079                            PtrSize, PtrAl, DoubleAl, FloatAl, LongAl,
00080                            IntAl, ShortAl, ByteAl, BoolAl) {
00081 }
00082 
00083 TargetMachine::TargetMachine(const std::string &name, const TargetData &TD)
00084   : Name(name), DataLayout(TD) {
00085 }
00086 
00087 TargetMachine::TargetMachine(const std::string &name, const Module &M)
00088   : Name(name), DataLayout(name, &M) {
00089 }
00090 
00091 TargetMachine::~TargetMachine() {
00092 }
00093 
00094 /// getRelocationModel - Returns the code generation relocation model. The
00095 /// choices are static, PIC, and dynamic-no-pic, and target default.
00096 Reloc::Model TargetMachine::getRelocationModel() {
00097   return RelocationModel;
00098 }
00099 
00100 /// setRelocationModel - Sets the code generation relocation model.
00101 void TargetMachine::setRelocationModel(Reloc::Model Model) {
00102   RelocationModel = Model;
00103 }