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