1 //===-- ARMSubtarget.cpp - ARM Subtarget Information ------------*- C++ -*-===// 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 implements the ARM specific subclass of TargetSubtarget. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "ARMSubtarget.h" 15 #include "ARMGenSubtarget.inc" 16 #include "llvm/Module.h" 17 #include "llvm/Target/TargetMachine.h" 18 #include "llvm/Target/TargetOptions.h" 19 #include "llvm/Support/CommandLine.h" 20 using namespace llvm; 21 22 static cl::opt<bool> 23 ReserveR9("arm-reserve-r9", cl::Hidden, 24 cl::desc("Reserve R9, making it unavailable as GPR")); 25 26 ARMSubtarget::ARMSubtarget(const Module &M, const std::string &FS, 27 bool isThumb) 28 : ARMArchVersion(V4T) 29 , ARMFPUType(None) 30 , IsThumb(isThumb) 31 , ThumbMode(Thumb1) 32 , IsR9Reserved(ReserveR9) 33 , stackAlignment(4) 34 , CPUString("generic") 35 , TargetType(isELF) // Default to ELF unless otherwise specified. 36 , TargetABI(ARM_ABI_APCS) { 37 // default to soft float ABI 38 if (FloatABIType == FloatABI::Default) 39 FloatABIType = FloatABI::Soft; 40 41 // Determine default and user specified characteristics 42 43 // Parse features string. 44 CPUString = ParseSubtargetFeatures(FS, CPUString); 45 46 // Set the boolean corresponding to the current target triple, or the default 47 // if one cannot be determined, to true. 48 const std::string& TT = M.getTargetTriple(); 49 unsigned Len = TT.length(); 50 unsigned Idx = 0; 51 52 if (Len >= 5 && TT.substr(0, 4) == "armv") 53 Idx = 4; 54 else if (Len >= 6 && TT.substr(0, 5) == "thumb") { 55 IsThumb = true; 56 if (Len >= 7 && TT[5] == 'v') 57 Idx = 6; 58 } 59 if (Idx) { 60 unsigned SubVer = TT[Idx]; 61 if (SubVer > '4' && SubVer <= '9') { 62 if (SubVer >= '7') { 63 ARMArchVersion = V7A; 64 } else if (SubVer == '6') { 65 ARMArchVersion = V6; 66 if (Len >= Idx+3 && TT[Idx+1] == 't' && TT[Idx+2] == '2') 67 ARMArchVersion = V6T2; 68 } else if (SubVer == '5') { 69 ARMArchVersion = V5T; 70 if (Len >= Idx+3 && TT[Idx+1] == 't' && TT[Idx+2] == 'e') 71 ARMArchVersion = V5TE; 72 } 73 if (ARMArchVersion >= V6T2) 74 ThumbMode = Thumb2; 75 } 76 } 77 78 if (Len >= 10) { 79 if (TT.find("-darwin") != std::string::npos) 80 // arm-darwin 81 TargetType = isDarwin; 82 } else if (TT.empty()) { 83 #if defined(__APPLE__) 84 TargetType = isDarwin; 85 #endif 86 } 87 88 if (TT.find("eabi") != std::string::npos) 89 TargetABI = ARM_ABI_AAPCS; 90 91 if (isAAPCS_ABI()) 92 stackAlignment = 8; 93 94 if (isTargetDarwin()) 95 IsR9Reserved = ReserveR9 | (ARMArchVersion < V6); 96 } 97