blob: a978380b627f8e60783f3a52dc19845ce5e2bf7a [file] [log] [blame]
Evan Chenga8e29892007-01-19 07:51:42 +00001//===-- ARMSubtarget.cpp - ARM Subtarget Information ------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Evan Chenga8e29892007-01-19 07:51:42 +00007//
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"
Anton Korobeynikov0eebf652009-06-08 22:53:56 +000017#include "llvm/Target/TargetMachine.h"
18#include "llvm/Target/TargetOptions.h"
Evan Chenga8e29892007-01-19 07:51:42 +000019using namespace llvm;
20
Anton Korobeynikovd4022c32009-05-29 23:41:08 +000021ARMSubtarget::ARMSubtarget(const Module &M, const std::string &FS,
22 bool isThumb)
Evan Cheng1a3771e2007-01-19 19:22:40 +000023 : ARMArchVersion(V4T)
Anton Korobeynikov6d7d2aa2009-05-23 19:51:43 +000024 , ARMFPUType(None)
Anton Korobeynikov70459be2009-06-01 20:00:48 +000025 , IsThumb(isThumb)
26 , ThumbMode(Thumb1)
Evan Cheng1a3771e2007-01-19 19:22:40 +000027 , UseThumbBacktraces(false)
28 , IsR9Reserved(false)
Lauro Ramos Venancio3630e782007-02-13 19:52:28 +000029 , stackAlignment(4)
Anton Korobeynikov41a02432009-05-23 19:50:50 +000030 , CPUString("generic")
Lauro Ramos Venancio3630e782007-02-13 19:52:28 +000031 , TargetType(isELF) // Default to ELF unless otherwise specified.
32 , TargetABI(ARM_ABI_APCS) {
Anton Korobeynikov0eebf652009-06-08 22:53:56 +000033 // default to soft float ABI
34 if (FloatABIType == FloatABI::Default)
35 FloatABIType = FloatABI::Soft;
36
Evan Chenga8e29892007-01-19 07:51:42 +000037 // Determine default and user specified characteristics
Evan Chenga8e29892007-01-19 07:51:42 +000038
39 // Parse features string.
Anton Korobeynikov41a02432009-05-23 19:50:50 +000040 CPUString = ParseSubtargetFeatures(FS, CPUString);
Evan Chenga8e29892007-01-19 07:51:42 +000041
Evan Chenga8e29892007-01-19 07:51:42 +000042 // Set the boolean corresponding to the current target triple, or the default
43 // if one cannot be determined, to true.
44 const std::string& TT = M.getTargetTriple();
Evan Cheng4b174742009-03-08 04:02:49 +000045 unsigned Len = TT.length();
Evan Cheng8c6b9912009-03-09 20:25:39 +000046 unsigned Idx = 0;
Anton Korobeynikovd4022c32009-05-29 23:41:08 +000047
Evan Cheng8c6b9912009-03-09 20:25:39 +000048 if (Len >= 5 && TT.substr(0, 4) == "armv")
49 Idx = 4;
50 else if (Len >= 6 && TT.substr(0, 6) == "thumb") {
Anton Korobeynikov70459be2009-06-01 20:00:48 +000051 IsThumb = true;
Evan Cheng8c6b9912009-03-09 20:25:39 +000052 if (Len >= 7 && TT[5] == 'v')
53 Idx = 6;
54 }
55 if (Idx) {
56 unsigned SubVer = TT[Idx];
57 if (SubVer > '4' && SubVer <= '9') {
Anton Korobeynikov70459be2009-06-01 20:00:48 +000058 if (SubVer >= '7')
Anton Korobeynikovd4022c32009-05-29 23:41:08 +000059 ARMArchVersion = V7A;
Anton Korobeynikov70459be2009-06-01 20:00:48 +000060 else if (SubVer == '6')
Evan Cheng8c6b9912009-03-09 20:25:39 +000061 ARMArchVersion = V6;
Anton Korobeynikov70459be2009-06-01 20:00:48 +000062 else if (SubVer == '5') {
Evan Cheng8c6b9912009-03-09 20:25:39 +000063 ARMArchVersion = V5T;
64 if (Len >= Idx+3 && TT[Idx+1] == 't' && TT[Idx+2] == 'e')
65 ARMArchVersion = V5TE;
Evan Cheng4b174742009-03-08 04:02:49 +000066 }
67 }
68 }
69
Evan Cheng8c6b9912009-03-09 20:25:39 +000070 if (Len >= 10) {
Evan Cheng1a3771e2007-01-19 19:22:40 +000071 if (TT.find("-darwin") != std::string::npos)
Evan Cheng8c6b9912009-03-09 20:25:39 +000072 // arm-darwin
Evan Cheng1a3771e2007-01-19 19:22:40 +000073 TargetType = isDarwin;
Evan Chenga8e29892007-01-19 07:51:42 +000074 } else if (TT.empty()) {
75#if defined(__APPLE__)
Evan Cheng1a3771e2007-01-19 19:22:40 +000076 TargetType = isDarwin;
Evan Chenga8e29892007-01-19 07:51:42 +000077#endif
78 }
79
Lauro Ramos Venancio3630e782007-02-13 19:52:28 +000080 if (TT.find("eabi") != std::string::npos)
81 TargetABI = ARM_ABI_AAPCS;
82
83 if (isAAPCS_ABI())
84 stackAlignment = 8;
85
Evan Cheng1a3771e2007-01-19 19:22:40 +000086 if (isTargetDarwin()) {
Evan Chenga8e29892007-01-19 07:51:42 +000087 UseThumbBacktraces = true;
88 IsR9Reserved = true;
Lauro Ramos Venancio3630e782007-02-13 19:52:28 +000089 }
Evan Chenga8e29892007-01-19 07:51:42 +000090}