LLVM API Documentation
00001 //===-- TargetMachine.cpp - General Target Information ---------------------==// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // 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/TargetAsmInfo.h" 00015 #include "llvm/Target/TargetMachine.h" 00016 #include "llvm/Target/TargetOptions.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 LessPreciseFPMADOption; 00026 bool PrintMachineCode; 00027 bool NoFramePointerElim; 00028 bool NoExcessFPPrecision; 00029 bool UnsafeFPMath; 00030 bool FiniteOnlyFPMathOption; 00031 bool HonorSignDependentRoundingFPMathOption; 00032 bool UseSoftFloat; 00033 FloatABI::ABIType FloatABIType; 00034 bool NoImplicitFloat; 00035 bool NoZerosInBSS; 00036 bool DwarfExceptionHandling; 00037 bool SjLjExceptionHandling; 00038 bool UnwindTablesMandatory; 00039 Reloc::Model RelocationModel; 00040 CodeModel::Model CMModel; 00041 bool PerformTailCallOpt; 00042 unsigned StackAlignment; 00043 bool RealignStack; 00044 bool DisableJumpTables; 00045 bool StrongPHIElim; 00046 bool AsmVerbosityDefault(false); 00047 } 00048 00049 static cl::opt<bool, true> 00050 PrintCode("print-machineinstrs", 00051 cl::desc("Print generated machine code"), 00052 cl::location(PrintMachineCode), cl::init(false)); 00053 static cl::opt<bool, true> 00054 DisableFPElim("disable-fp-elim", 00055 cl::desc("Disable frame pointer elimination optimization"), 00056 cl::location(NoFramePointerElim), 00057 cl::init(false)); 00058 static cl::opt<bool, true> 00059 DisableExcessPrecision("disable-excess-fp-precision", 00060 cl::desc("Disable optimizations that may increase FP precision"), 00061 cl::location(NoExcessFPPrecision), 00062 cl::init(false)); 00063 static cl::opt<bool, true> 00064 EnableFPMAD("enable-fp-mad", 00065 cl::desc("Enable less precise MAD instructions to be generated"), 00066 cl::location(LessPreciseFPMADOption), 00067 cl::init(false)); 00068 static cl::opt<bool, true> 00069 EnableUnsafeFPMath("enable-unsafe-fp-math", 00070 cl::desc("Enable optimizations that may decrease FP precision"), 00071 cl::location(UnsafeFPMath), 00072 cl::init(false)); 00073 static cl::opt<bool, true> 00074 EnableFiniteOnlyFPMath("enable-finite-only-fp-math", 00075 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"), 00076 cl::location(FiniteOnlyFPMathOption), 00077 cl::init(false)); 00078 static cl::opt<bool, true> 00079 EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math", 00080 cl::Hidden, 00081 cl::desc("Force codegen to assume rounding mode can change dynamically"), 00082 cl::location(HonorSignDependentRoundingFPMathOption), 00083 cl::init(false)); 00084 static cl::opt<bool, true> 00085 GenerateSoftFloatCalls("soft-float", 00086 cl::desc("Generate software floating point library calls"), 00087 cl::location(UseSoftFloat), 00088 cl::init(false)); 00089 static cl::opt<llvm::FloatABI::ABIType, true> 00090 FloatABIForCalls("float-abi", 00091 cl::desc("Choose float ABI type"), 00092 cl::location(FloatABIType), 00093 cl::init(FloatABI::Default), 00094 cl::values( 00095 clEnumValN(FloatABI::Default, "default", 00096 "Target default float ABI type"), 00097 clEnumValN(FloatABI::Soft, "soft", 00098 "Soft float ABI (implied by -soft-float)"), 00099 clEnumValN(FloatABI::Hard, "hard", 00100 "Hard float ABI (uses FP registers)"), 00101 clEnumValEnd)); 00102 static cl::opt<bool, true> 00103 DontPlaceZerosInBSS("nozero-initialized-in-bss", 00104 cl::desc("Don't place zero-initialized symbols into bss section"), 00105 cl::location(NoZerosInBSS), 00106 cl::init(false)); 00107 static cl::opt<bool, true> 00108 EnableDwarfExceptionHandling("enable-eh", 00109 cl::desc("Emit DWARF exception handling (default if target supports)"), 00110 cl::location(DwarfExceptionHandling), 00111 cl::init(false)); 00112 static cl::opt<bool, true> 00113 EnableSjLjExceptionHandling("enable-sjlj-eh", 00114 cl::desc("Emit SJLJ exception handling (default if target supports)"), 00115 cl::location(SjLjExceptionHandling), 00116 cl::init(false)); 00117 static cl::opt<bool, true> 00118 EnableUnwindTables("unwind-tables", 00119 cl::desc("Generate unwinding tables for all functions"), 00120 cl::location(UnwindTablesMandatory), 00121 cl::init(false)); 00122 00123 static cl::opt<llvm::Reloc::Model, true> 00124 DefRelocationModel("relocation-model", 00125 cl::desc("Choose relocation model"), 00126 cl::location(RelocationModel), 00127 cl::init(Reloc::Default), 00128 cl::values( 00129 clEnumValN(Reloc::Default, "default", 00130 "Target default relocation model"), 00131 clEnumValN(Reloc::Static, "static", 00132 "Non-relocatable code"), 00133 clEnumValN(Reloc::PIC_, "pic", 00134 "Fully relocatable, position independent code"), 00135 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic", 00136 "Relocatable external references, non-relocatable code"), 00137 clEnumValEnd)); 00138 static cl::opt<llvm::CodeModel::Model, true> 00139 DefCodeModel("code-model", 00140 cl::desc("Choose code model"), 00141 cl::location(CMModel), 00142 cl::init(CodeModel::Default), 00143 cl::values( 00144 clEnumValN(CodeModel::Default, "default", 00145 "Target default code model"), 00146 clEnumValN(CodeModel::Small, "small", 00147 "Small code model"), 00148 clEnumValN(CodeModel::Kernel, "kernel", 00149 "Kernel code model"), 00150 clEnumValN(CodeModel::Medium, "medium", 00151 "Medium code model"), 00152 clEnumValN(CodeModel::Large, "large", 00153 "Large code model"), 00154 clEnumValEnd)); 00155 static cl::opt<bool, true> 00156 EnablePerformTailCallOpt("tailcallopt", 00157 cl::desc("Turn on tail call optimization."), 00158 cl::location(PerformTailCallOpt), 00159 cl::init(false)); 00160 static cl::opt<unsigned, true> 00161 OverrideStackAlignment("stack-alignment", 00162 cl::desc("Override default stack alignment"), 00163 cl::location(StackAlignment), 00164 cl::init(0)); 00165 static cl::opt<bool, true> 00166 EnableRealignStack("realign-stack", 00167 cl::desc("Realign stack if needed"), 00168 cl::location(RealignStack), 00169 cl::init(true)); 00170 static cl::opt<bool, true> 00171 DisableSwitchTables(cl::Hidden, "disable-jump-tables", 00172 cl::desc("Do not generate jump tables."), 00173 cl::location(DisableJumpTables), 00174 cl::init(false)); 00175 static cl::opt<bool, true> 00176 EnableStrongPHIElim(cl::Hidden, "strong-phi-elim", 00177 cl::desc("Use strong PHI elimination."), 00178 cl::location(StrongPHIElim), 00179 cl::init(false)); 00180 00181 //--------------------------------------------------------------------------- 00182 // TargetMachine Class 00183 // 00184 00185 TargetMachine::TargetMachine(const Target &T) 00186 : TheTarget(T), AsmInfo(0) { 00187 // Typically it will be subtargets that will adjust FloatABIType from Default 00188 // to Soft or Hard. 00189 if (UseSoftFloat) 00190 FloatABIType = FloatABI::Soft; 00191 } 00192 00193 TargetMachine::~TargetMachine() { 00194 delete AsmInfo; 00195 } 00196 00197 /// getRelocationModel - Returns the code generation relocation model. The 00198 /// choices are static, PIC, and dynamic-no-pic, and target default. 00199 Reloc::Model TargetMachine::getRelocationModel() { 00200 return RelocationModel; 00201 } 00202 00203 /// setRelocationModel - Sets the code generation relocation model. 00204 void TargetMachine::setRelocationModel(Reloc::Model Model) { 00205 RelocationModel = Model; 00206 } 00207 00208 /// getCodeModel - Returns the code model. The choices are small, kernel, 00209 /// medium, large, and target default. 00210 CodeModel::Model TargetMachine::getCodeModel() { 00211 return CMModel; 00212 } 00213 00214 /// setCodeModel - Sets the code model. 00215 void TargetMachine::setCodeModel(CodeModel::Model Model) { 00216 CMModel = Model; 00217 } 00218 00219 bool TargetMachine::getAsmVerbosityDefault() { 00220 return AsmVerbosityDefault; 00221 } 00222 00223 void TargetMachine::setAsmVerbosityDefault(bool V) { 00224 AsmVerbosityDefault = V; 00225 } 00226 00227 namespace llvm { 00228 /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option 00229 /// is specified on the command line. When this flag is off(default), the 00230 /// code generator is not allowed to generate mad (multiply add) if the 00231 /// result is "less precise" than doing those operations individually. 00232 bool LessPreciseFPMAD() { return UnsafeFPMath || LessPreciseFPMADOption; } 00233 00234 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math 00235 /// option is specified on the command line. If this returns false (default), 00236 /// the code generator is not allowed to assume that FP arithmetic arguments 00237 /// and results are never NaNs or +-Infs. 00238 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; } 00239 00240 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume 00241 /// that the rounding mode of the FPU can change from its default. 00242 bool HonorSignDependentRoundingFPMath() { 00243 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption; 00244 } 00245 } 00246