LLVM API Documentation
00001 //===-- ARMTargetMachine.cpp - Define TargetMachine for ARM ---------------===// 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 // 00011 //===----------------------------------------------------------------------===// 00012 00013 #include "ARMTargetMachine.h" 00014 #include "ARMTargetAsmInfo.h" 00015 #include "ARMFrameInfo.h" 00016 #include "ARM.h" 00017 #include "llvm/Module.h" 00018 #include "llvm/PassManager.h" 00019 #include "llvm/CodeGen/Passes.h" 00020 #include "llvm/Support/CommandLine.h" 00021 #include "llvm/Support/raw_ostream.h" 00022 #include "llvm/Target/TargetMachineRegistry.h" 00023 #include "llvm/Target/TargetOptions.h" 00024 using namespace llvm; 00025 00026 static cl::opt<bool> DisableLdStOpti("disable-arm-loadstore-opti", cl::Hidden, 00027 cl::desc("Disable load store optimization pass")); 00028 static cl::opt<bool> DisableIfConversion("disable-arm-if-conversion",cl::Hidden, 00029 cl::desc("Disable if-conversion pass")); 00030 00031 /// ARMTargetMachineModule - Note that this is used on hosts that cannot link 00032 /// in a library unless there are references into the library. In particular, 00033 /// it seems that it is not possible to get things to work on Win32 without 00034 /// this. Though it is unused, do not remove it. 00035 extern "C" int ARMTargetMachineModule; 00036 int ARMTargetMachineModule = 0; 00037 00038 // Register the target. 00039 static RegisterTarget<ARMTargetMachine> X("arm", "ARM"); 00040 static RegisterTarget<ThumbTargetMachine> Y("thumb", "Thumb"); 00041 00042 // No assembler printer by default 00043 ARMTargetMachine::AsmPrinterCtorFn ARMTargetMachine::AsmPrinterCtor = 0; 00044 00045 /// ThumbTargetMachine - Create an Thumb architecture model. 00046 /// 00047 unsigned ThumbTargetMachine::getJITMatchQuality() { 00048 #if defined(__thumb__) 00049 return 10; 00050 #endif 00051 return 0; 00052 } 00053 00054 unsigned ThumbTargetMachine::getModuleMatchQuality(const Module &M) { 00055 std::string TT = M.getTargetTriple(); 00056 if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "thumb-") 00057 return 20; 00058 00059 // If the target triple is something non-thumb, we don't match. 00060 if (!TT.empty()) return 0; 00061 00062 if (M.getEndianness() == Module::LittleEndian && 00063 M.getPointerSize() == Module::Pointer32) 00064 return 10; // Weak match 00065 else if (M.getEndianness() != Module::AnyEndianness || 00066 M.getPointerSize() != Module::AnyPointerSize) 00067 return 0; // Match for some other target 00068 00069 return getJITMatchQuality()/2; 00070 } 00071 00072 ThumbTargetMachine::ThumbTargetMachine(const Module &M, const std::string &FS) 00073 : ARMTargetMachine(M, FS, true) { 00074 } 00075 00076 /// TargetMachine ctor - Create an ARM architecture model. 00077 /// 00078 ARMTargetMachine::ARMTargetMachine(const Module &M, const std::string &FS, 00079 bool isThumb) 00080 : Subtarget(M, FS, isThumb), 00081 DataLayout(Subtarget.isAPCS_ABI() ? 00082 // APCS ABI 00083 (isThumb ? 00084 std::string("e-p:32:32-f64:32:32-i64:32:32-" 00085 "i16:16:32-i8:8:32-i1:8:32-a:0:32") : 00086 std::string("e-p:32:32-f64:32:32-i64:32:32")) : 00087 // AAPCS ABI 00088 (isThumb ? 00089 std::string("e-p:32:32-f64:64:64-i64:64:64-" 00090 "i16:16:32-i8:8:32-i1:8:32-a:0:32") : 00091 std::string("e-p:32:32-f64:64:64-i64:64:64"))), 00092 InstrInfo(Subtarget), 00093 FrameInfo(Subtarget), 00094 JITInfo(), 00095 TLInfo(*this) { 00096 DefRelocModel = getRelocationModel(); 00097 } 00098 00099 unsigned ARMTargetMachine::getJITMatchQuality() { 00100 #if defined(__arm__) 00101 return 10; 00102 #endif 00103 return 0; 00104 } 00105 00106 unsigned ARMTargetMachine::getModuleMatchQuality(const Module &M) { 00107 std::string TT = M.getTargetTriple(); 00108 if (TT.size() >= 4 && // Match arm-foo-bar, as well as things like armv5blah-* 00109 (TT.substr(0, 4) == "arm-" || TT.substr(0, 4) == "armv")) 00110 return 20; 00111 // If the target triple is something non-arm, we don't match. 00112 if (!TT.empty()) return 0; 00113 00114 if (M.getEndianness() == Module::LittleEndian && 00115 M.getPointerSize() == Module::Pointer32) 00116 return 10; // Weak match 00117 else if (M.getEndianness() != Module::AnyEndianness || 00118 M.getPointerSize() != Module::AnyPointerSize) 00119 return 0; // Match for some other target 00120 00121 return getJITMatchQuality()/2; 00122 } 00123 00124 00125 const TargetAsmInfo *ARMTargetMachine::createTargetAsmInfo() const { 00126 switch (Subtarget.TargetType) { 00127 case ARMSubtarget::isDarwin: 00128 return new ARMDarwinTargetAsmInfo(*this); 00129 case ARMSubtarget::isELF: 00130 return new ARMELFTargetAsmInfo(*this); 00131 default: 00132 return new ARMGenericTargetAsmInfo(*this); 00133 } 00134 } 00135 00136 00137 // Pass Pipeline Configuration 00138 bool ARMTargetMachine::addInstSelector(PassManagerBase &PM, bool Fast) { 00139 PM.add(createARMISelDag(*this)); 00140 return false; 00141 } 00142 00143 bool ARMTargetMachine::addPreEmitPass(PassManagerBase &PM, bool Fast) { 00144 // FIXME: temporarily disabling load / store optimization pass for Thumb mode. 00145 if (!Fast && !DisableLdStOpti && !Subtarget.isThumb()) 00146 PM.add(createARMLoadStoreOptimizationPass()); 00147 00148 if (!Fast && !DisableIfConversion && !Subtarget.isThumb()) 00149 PM.add(createIfConverterPass()); 00150 00151 PM.add(createARMConstantIslandPass()); 00152 return true; 00153 } 00154 00155 bool ARMTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast, 00156 raw_ostream &Out) { 00157 // Output assembly language. 00158 assert(AsmPrinterCtor && "AsmPrinter was not linked in"); 00159 if (AsmPrinterCtor) 00160 PM.add(AsmPrinterCtor(Out, *this)); 00161 00162 return false; 00163 } 00164 00165 00166 bool ARMTargetMachine::addCodeEmitter(PassManagerBase &PM, bool Fast, 00167 bool DumpAsm, MachineCodeEmitter &MCE) { 00168 // FIXME: Move this to TargetJITInfo! 00169 if (DefRelocModel == Reloc::Default) 00170 setRelocationModel(Reloc::Static); 00171 00172 // Machine code emitter pass for ARM. 00173 PM.add(createARMCodeEmitterPass(*this, MCE)); 00174 if (DumpAsm) { 00175 assert(AsmPrinterCtor && "AsmPrinter was not linked in"); 00176 if (AsmPrinterCtor) 00177 PM.add(AsmPrinterCtor(errs(), *this)); 00178 } 00179 00180 return false; 00181 } 00182 00183 bool ARMTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, bool Fast, 00184 bool DumpAsm, MachineCodeEmitter &MCE) { 00185 // Machine code emitter pass for ARM. 00186 PM.add(createARMCodeEmitterPass(*this, MCE)); 00187 if (DumpAsm) { 00188 assert(AsmPrinterCtor && "AsmPrinter was not linked in"); 00189 if (AsmPrinterCtor) 00190 PM.add(AsmPrinterCtor(errs(), *this)); 00191 } 00192 00193 return false; 00194 }