TargetMachine.cpp revision 4ee451de366474b9c228b4e5fa573795a715216d
1//===-- TargetMachine.cpp - General Target Information ---------------------==// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// 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/TargetAsmInfo.h" 15#include "llvm/Target/TargetMachine.h" 16#include "llvm/Target/TargetOptions.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 bool FiniteOnlyFPMathOption; 30 bool HonorSignDependentRoundingFPMathOption; 31 bool UseSoftFloat; 32 bool NoZerosInBSS; 33 bool ExceptionHandling; 34 Reloc::Model RelocationModel; 35 CodeModel::Model CMModel; 36 bool PerformTailCallOpt; 37} 38namespace { 39 cl::opt<bool, true> PrintCode("print-machineinstrs", 40 cl::desc("Print generated machine code"), 41 cl::location(PrintMachineCode), cl::init(false)); 42 43 cl::opt<bool, true> 44 DisableFPElim("disable-fp-elim", 45 cl::desc("Disable frame pointer elimination optimization"), 46 cl::location(NoFramePointerElim), 47 cl::init(false)); 48 cl::opt<bool, true> 49 DisableExcessPrecision("disable-excess-fp-precision", 50 cl::desc("Disable optimizations that may increase FP precision"), 51 cl::location(NoExcessFPPrecision), 52 cl::init(false)); 53 cl::opt<bool, true> 54 EnableUnsafeFPMath("enable-unsafe-fp-math", 55 cl::desc("Enable optimizations that may decrease FP precision"), 56 cl::location(UnsafeFPMath), 57 cl::init(false)); 58 cl::opt<bool, true> 59 EnableFiniteOnlyFPMath("enable-finite-only-fp-math", 60 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"), 61 cl::location(FiniteOnlyFPMathOption), 62 cl::init(false)); 63 cl::opt<bool, true> 64 EnableHonorSignDependentRoundingFPMath(cl::Hidden, 65 "enable-sign-dependent-rounding-fp-math", 66 cl::desc("Force codegen to assume rounding mode can change dynamically"), 67 cl::location(HonorSignDependentRoundingFPMathOption), 68 cl::init(false)); 69 70 cl::opt<bool, true> 71 GenerateSoftFloatCalls("soft-float", 72 cl::desc("Generate software floating point library calls"), 73 cl::location(UseSoftFloat), 74 cl::init(false)); 75 cl::opt<bool, true> 76 DontPlaceZerosInBSS("nozero-initialized-in-bss", 77 cl::desc("Don't place zero-initialized symbols into bss section"), 78 cl::location(NoZerosInBSS), 79 cl::init(false)); 80 cl::opt<bool, true> 81 EnableExceptionHandling("enable-eh", 82 cl::desc("Exception handling should be emitted."), 83 cl::location(ExceptionHandling), 84 cl::init(false)); 85 86 cl::opt<llvm::Reloc::Model, true> 87 DefRelocationModel( 88 "relocation-model", 89 cl::desc("Choose relocation model"), 90 cl::location(RelocationModel), 91 cl::init(Reloc::Default), 92 cl::values( 93 clEnumValN(Reloc::Default, "default", 94 " Target default relocation model"), 95 clEnumValN(Reloc::Static, "static", 96 " Non-relocatable code"), 97 clEnumValN(Reloc::PIC_, "pic", 98 " Fully relocatable, position independent code"), 99 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic", 100 " Relocatable external references, non-relocatable code"), 101 clEnumValEnd)); 102 cl::opt<llvm::CodeModel::Model, true> 103 DefCodeModel( 104 "code-model", 105 cl::desc("Choose code model"), 106 cl::location(CMModel), 107 cl::init(CodeModel::Default), 108 cl::values( 109 clEnumValN(CodeModel::Default, "default", 110 " Target default code model"), 111 clEnumValN(CodeModel::Small, "small", 112 " Small code model"), 113 clEnumValN(CodeModel::Kernel, "kernel", 114 " Kernel code model"), 115 clEnumValN(CodeModel::Medium, "medium", 116 " Medium code model"), 117 clEnumValN(CodeModel::Large, "large", 118 " Large code model"), 119 clEnumValEnd)); 120 121 cl::opt<bool, true> 122 EnablePerformTailCallOpt("tailcallopt", 123 cl::desc("Turn on tail call optimization."), 124 cl::location(PerformTailCallOpt), 125 cl::init(false)); 126} 127 128//--------------------------------------------------------------------------- 129// TargetMachine Class 130// 131 132TargetMachine::~TargetMachine() { 133 delete AsmInfo; 134} 135 136/// getRelocationModel - Returns the code generation relocation model. The 137/// choices are static, PIC, and dynamic-no-pic, and target default. 138Reloc::Model TargetMachine::getRelocationModel() { 139 return RelocationModel; 140} 141 142/// setRelocationModel - Sets the code generation relocation model. 143void TargetMachine::setRelocationModel(Reloc::Model Model) { 144 RelocationModel = Model; 145} 146 147/// getCodeModel - Returns the code model. The choices are small, kernel, 148/// medium, large, and target default. 149CodeModel::Model TargetMachine::getCodeModel() { 150 return CMModel; 151} 152 153/// setCodeModel - Sets the code model. 154void TargetMachine::setCodeModel(CodeModel::Model Model) { 155 CMModel = Model; 156} 157 158namespace llvm { 159 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math 160 /// option is specified on the command line. If this returns false (default), 161 /// the code generator is not allowed to assume that FP arithmetic arguments 162 /// and results are never NaNs or +-Infs. 163 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; } 164 165 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume 166 /// that the rounding mode of the FPU can change from its default. 167 bool HonorSignDependentRoundingFPMath() { 168 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption; 169 } 170} 171 172