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 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 PrintMachineCode;
00026   bool NoFramePointerElim;
00027   bool NoExcessFPPrecision;
00028   bool UnsafeFPMath;
00029   bool FiniteOnlyFPMathOption;
00030   bool HonorSignDependentRoundingFPMathOption;
00031   bool UseSoftFloat;
00032   bool NoZerosInBSS;
00033   bool ExceptionHandling;
00034   bool UnwindTablesMandatory;
00035   Reloc::Model RelocationModel;
00036   CodeModel::Model CMModel;
00037   bool PerformTailCallOpt;
00038   unsigned StackAlignment;
00039   bool RealignStack;
00040   bool VerboseAsm;
00041   bool DisableJumpTables;
00042   bool StrongPHIElim;
00043   bool DisableRedZone;
00044 }
00045 
00046 static cl::opt<bool, true> PrintCode("print-machineinstrs",
00047   cl::desc("Print generated machine code"),
00048   cl::location(PrintMachineCode), cl::init(false));
00049 
00050 static cl::opt<bool, true>
00051 DisableFPElim("disable-fp-elim",
00052               cl::desc("Disable frame pointer elimination optimization"),
00053               cl::location(NoFramePointerElim),
00054               cl::init(false));
00055 static cl::opt<bool, true>
00056 DisableExcessPrecision("disable-excess-fp-precision",
00057              cl::desc("Disable optimizations that may increase FP precision"),
00058              cl::location(NoExcessFPPrecision),
00059              cl::init(false));
00060 static cl::opt<bool, true>
00061 EnableUnsafeFPMath("enable-unsafe-fp-math",
00062              cl::desc("Enable optimizations that may decrease FP precision"),
00063              cl::location(UnsafeFPMath),
00064              cl::init(false));
00065 static cl::opt<bool, true>
00066 EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
00067              cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
00068              cl::location(FiniteOnlyFPMathOption),
00069              cl::init(false));
00070 static cl::opt<bool, true>
00071 EnableHonorSignDependentRoundingFPMath(cl::Hidden,
00072              "enable-sign-dependent-rounding-fp-math",
00073      cl::desc("Force codegen to assume rounding mode can change dynamically"),
00074              cl::location(HonorSignDependentRoundingFPMathOption),
00075              cl::init(false));
00076 
00077 static cl::opt<bool, true>
00078 GenerateSoftFloatCalls("soft-float",
00079              cl::desc("Generate software floating point library calls"),
00080              cl::location(UseSoftFloat),
00081              cl::init(false));
00082 static cl::opt<bool, true>
00083 DontPlaceZerosInBSS("nozero-initialized-in-bss",
00084             cl::desc("Don't place zero-initialized symbols into bss section"),
00085             cl::location(NoZerosInBSS),
00086             cl::init(false));
00087 static cl::opt<bool, true>
00088 EnableExceptionHandling("enable-eh",
00089              cl::desc("Emit DWARF exception handling (default if target supports)"),
00090              cl::location(ExceptionHandling),
00091              cl::init(false));
00092 static cl::opt<bool, true>
00093 EnableUnwindTables("unwind-tables",
00094              cl::desc("Generate unwinding tables for all functions"),
00095              cl::location(UnwindTablesMandatory),
00096              cl::init(false));
00097 
00098 static cl::opt<llvm::Reloc::Model, true>
00099 DefRelocationModel(
00100   "relocation-model",
00101   cl::desc("Choose relocation model"),
00102   cl::location(RelocationModel),
00103   cl::init(Reloc::Default),
00104   cl::values(
00105     clEnumValN(Reloc::Default, "default",
00106                "Target default relocation model"),
00107     clEnumValN(Reloc::Static, "static",
00108                "Non-relocatable code"),
00109     clEnumValN(Reloc::PIC_, "pic",
00110                "Fully relocatable, position independent code"),
00111     clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
00112                "Relocatable external references, non-relocatable code"),
00113     clEnumValEnd));
00114 static cl::opt<llvm::CodeModel::Model, true>
00115 DefCodeModel(
00116   "code-model",
00117   cl::desc("Choose code model"),
00118   cl::location(CMModel),
00119   cl::init(CodeModel::Default),
00120   cl::values(
00121     clEnumValN(CodeModel::Default, "default",
00122                "Target default code model"),
00123     clEnumValN(CodeModel::Small, "small",
00124                "Small code model"),
00125     clEnumValN(CodeModel::Kernel, "kernel",
00126                "Kernel code model"),
00127     clEnumValN(CodeModel::Medium, "medium",
00128                "Medium code model"),
00129     clEnumValN(CodeModel::Large, "large",
00130                "Large code model"),
00131     clEnumValEnd));
00132 
00133 static cl::opt<bool, true>
00134 EnablePerformTailCallOpt("tailcallopt",
00135                          cl::desc("Turn on tail call optimization."),
00136                          cl::location(PerformTailCallOpt),
00137                          cl::init(false));
00138 
00139 static cl::opt<unsigned, true>
00140 OverrideStackAlignment("stack-alignment",
00141                        cl::desc("Override default stack alignment"),
00142                        cl::location(StackAlignment),
00143                        cl::init(0));
00144 
00145 static cl::opt<bool, true>
00146 EnableRealignStack("realign-stack",
00147                    cl::desc("Realign stack if needed"),
00148                    cl::location(RealignStack),
00149                    cl::init(true));
00150 
00151 static cl::opt<bool, true>
00152 AsmVerbose("asm-verbose", cl::desc("Add comments to directives."),
00153            cl::location(VerboseAsm),
00154            cl::init(false));
00155 
00156 static cl::opt<bool, true>
00157 DisableSwitchTables(cl::Hidden, "disable-jump-tables", 
00158            cl::desc("Do not generate jump tables."),
00159            cl::location(DisableJumpTables),
00160            cl::init(false));
00161 
00162 static cl::opt<bool, true>
00163 EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
00164            cl::desc("Use strong PHI elimination."),
00165            cl::location(StrongPHIElim),
00166            cl::init(false));
00167 
00168 static cl::opt<bool, true>
00169 DisableRedZoneOption("disable-red-zone",
00170            cl::desc("Do not emit code that uses the red zone."),
00171            cl::location(DisableRedZone),
00172            cl::init(false));
00173 
00174 //---------------------------------------------------------------------------
00175 // TargetMachine Class
00176 //
00177 
00178 TargetMachine::~TargetMachine() {
00179   delete AsmInfo;
00180 }
00181 
00182 /// getRelocationModel - Returns the code generation relocation model. The
00183 /// choices are static, PIC, and dynamic-no-pic, and target default.
00184 Reloc::Model TargetMachine::getRelocationModel() {
00185   return RelocationModel;
00186 }
00187 
00188 /// setRelocationModel - Sets the code generation relocation model.
00189 void TargetMachine::setRelocationModel(Reloc::Model Model) {
00190   RelocationModel = Model;
00191 }
00192 
00193 /// getCodeModel - Returns the code model. The choices are small, kernel,
00194 /// medium, large, and target default.
00195 CodeModel::Model TargetMachine::getCodeModel() {
00196   return CMModel;
00197 }
00198 
00199 /// setCodeModel - Sets the code model.
00200 void TargetMachine::setCodeModel(CodeModel::Model Model) {
00201   CMModel = Model;
00202 }
00203 
00204 namespace llvm {
00205   /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
00206   /// option is specified on the command line. If this returns false (default),
00207   /// the code generator is not allowed to assume that FP arithmetic arguments
00208   /// and results are never NaNs or +-Infs.
00209   bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
00210   
00211   /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
00212   /// that the rounding mode of the FPU can change from its default.
00213   bool HonorSignDependentRoundingFPMath() {
00214     return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
00215   }
00216 }
00217