blob: e523f1448e054f5848e36dcf116d28402a7976f6 [file] [log] [blame]
Nate Begeman8c00f8c2005-08-04 07:12:09 +00001//===-- X86Subtarget.cpp - X86 Subtarget Information ------------*- C++ -*-===//
Nate Begemanfb5792f2005-07-12 01:41:54 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Nate Begeman and is distributed under the
6// University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the X86 specific subclass of TargetSubtarget.
11//
12//===----------------------------------------------------------------------===//
13
14#include "X86Subtarget.h"
15#include "llvm/Module.h"
Evan Cheng97c7fc32006-01-26 09:53:06 +000016#include "X86GenSubtarget.inc"
Nate Begemanfb5792f2005-07-12 01:41:54 +000017using namespace llvm;
18
Evan Cheng97c7fc32006-01-26 09:53:06 +000019#if defined(__APPLE__)
20#include <mach/mach.h>
21#include <mach/mach_host.h>
22#include <mach/host_info.h>
23#include <mach/machine.h>
24
25/// GetCurrentX86CPU - Returns the current CPUs features.
26static const char *GetCurrentX86CPU() {
27 host_basic_info_data_t hostInfo;
28 mach_msg_type_number_t infoCount;
29
30 infoCount = HOST_BASIC_INFO_COUNT;
31 host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo,
32 &infoCount);
33
34 if (hostInfo.cpu_type != CPU_TYPE_I386) return "generic";
35
36 switch(hostInfo.cpu_subtype) {
37 case CPU_SUBTYPE_386: return "i386";
38 case CPU_SUBTYPE_486:
39 case CPU_SUBTYPE_486SX: return "i486";
40 case CPU_SUBTYPE_PENT: return "pentium";
41 case CPU_SUBTYPE_PENTPRO: return "pentiumpro";
42 case CPU_SUBTYPE_PENTII_M3: return "pentium2";
43 case CPU_SUBTYPE_PENTII_M5: return "pentium2";
44 case CPU_SUBTYPE_CELERON:
45 case CPU_SUBTYPE_CELERON_MOBILE: return "celeron";
46 case CPU_SUBTYPE_PENTIUM_3: return "pentium3";
47 case CPU_SUBTYPE_PENTIUM_3_M: return "pentium3m";
48 case CPU_SUBTYPE_PENTIUM_3_XEON: return "pentium3"; // FIXME: not sure.
49 case CPU_SUBTYPE_PENTIUM_M: return "pentium-m";
50 case CPU_SUBTYPE_PENTIUM_4: return "pentium4";
51 case CPU_SUBTYPE_PENTIUM_4_M: return "pentium4m";
52 // FIXME: prescott, yonah? Check CPU_THREADTYPE_INTEL_HTT?
53 case CPU_SUBTYPE_XEON:
54 case CPU_SUBTYPE_XEON_MP: return "nocona";
55 default: ;
56 }
57
58 return "generic";
59}
60#endif
61
Jim Laskeyb1e11802005-09-01 21:38:21 +000062X86Subtarget::X86Subtarget(const Module &M, const std::string &FS)
Chris Lattnerd460f572005-11-21 22:43:58 +000063 : stackAlignment(8), indirectExternAndWeakGlobals(false) {
Chris Lattnere5600e52005-11-21 22:31:58 +000064
Evan Cheng97c7fc32006-01-26 09:53:06 +000065 // Determine default and user specified characteristics
66 std::string CPU = "generic";
67#if defined(__APPLE__)
68 CPU = GetCurrentX86CPU();
69#endif
70
71 // Parse features string.
72 ParseSubtargetFeatures(FS, CPU);
73
Chris Lattnere5600e52005-11-21 22:31:58 +000074 // Default to ELF unless otherwise specified.
75 TargetType = isELF;
76
Nate Begemanfb5792f2005-07-12 01:41:54 +000077 // Set the boolean corresponding to the current target triple, or the default
78 // if one cannot be determined, to true.
79 const std::string& TT = M.getTargetTriple();
80 if (TT.length() > 5) {
Chris Lattnere5600e52005-11-21 22:31:58 +000081 if (TT.find("cygwin") != std::string::npos ||
82 TT.find("mingw") != std::string::npos)
83 TargetType = isCygwin;
84 else if (TT.find("darwin") != std::string::npos)
85 TargetType = isDarwin;
86 else if (TT.find("win32") != std::string::npos)
87 TargetType = isWindows;
Nate Begemanfb5792f2005-07-12 01:41:54 +000088 } else if (TT.empty()) {
89#if defined(__CYGWIN__) || defined(__MINGW32__)
Chris Lattnere5600e52005-11-21 22:31:58 +000090 TargetType = isCygwin;
Nate Begemanfb5792f2005-07-12 01:41:54 +000091#elif defined(__APPLE__)
Chris Lattnere5600e52005-11-21 22:31:58 +000092 TargetType = isDarwin;
Nate Begemanfb5792f2005-07-12 01:41:54 +000093#elif defined(_WIN32)
Chris Lattnere5600e52005-11-21 22:31:58 +000094 TargetType = isWindows;
Nate Begemanfb5792f2005-07-12 01:41:54 +000095#endif
96 }
97
Chris Lattnerd460f572005-11-21 22:43:58 +000098 if (TargetType == isDarwin) {
Nate Begemanfb5792f2005-07-12 01:41:54 +000099 stackAlignment = 16;
100 indirectExternAndWeakGlobals = true;
Nate Begemanfb5792f2005-07-12 01:41:54 +0000101 }
102}