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