blob: 2c1b7839a5fc2a520586627ece6b6d483913cbd1 [file] [log] [blame]
Nate Begeman8c00f8c2005-08-04 07:12:09 +00001//===- PowerPCSubtarget.cpp - PPC Subtarget Information ---------*- C++ -*-===//
2//
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 PPC specific subclass of TargetSubtarget.
11//
12//===----------------------------------------------------------------------===//
13
14#include "PowerPCSubtarget.h"
Chris Lattner3c304a32005-08-05 22:05:03 +000015#include "PowerPC.h"
Nate Begeman8c00f8c2005-08-04 07:12:09 +000016#include "llvm/Module.h"
Chris Lattner3c304a32005-08-05 22:05:03 +000017#include "llvm/Support/CommandLine.h"
Jim Laskeyb1e11802005-09-01 21:38:21 +000018#include "llvm/Target/SubtargetFeature.h"
19
Chris Lattner3c304a32005-08-05 22:05:03 +000020using namespace llvm;
21PPCTargetEnum llvm::PPCTarget = TargetDefault;
22
23namespace llvm {
24 cl::opt<PPCTargetEnum, true>
25 PPCTargetArg(cl::desc("Force generation of code for a specific PPC target:"),
26 cl::values(
27 clEnumValN(TargetAIX, "aix", " Enable AIX codegen"),
28 clEnumValN(TargetDarwin,"darwin"," Enable Darwin codegen"),
29 clEnumValEnd),
30 cl::location(PPCTarget), cl::init(TargetDefault));
31 cl::opt<bool> EnableGPOPT("enable-gpopt", cl::Hidden,
32 cl::desc("Enable optimizations for GP cpus"));
33}
Nate Begeman8c00f8c2005-08-04 07:12:09 +000034
Jim Laskeyb1e11802005-09-01 21:38:21 +000035enum PowerPCFeature {
36 PowerPCFeature64Bit = 1 << 0,
37 PowerPCFeatureAltivec = 1 << 1,
38 PowerPCFeatureFSqrt = 1 << 2,
39 PowerPCFeatureGPUL = 1 << 3,
40};
41
42/// Sorted (by key) array of values for CPU subtype.
43static const SubtargetFeatureKV PowerPCSubTypeKV[] = {
44 { "601" , 0 },
45 { "602" , 0 },
46 { "603" , 0 },
47 { "603e" , 0 },
48 { "603ev" , 0 },
49 { "604" , 0 },
50 { "604e" , 0 },
51 { "620" , 0 },
52 { "7400" , PowerPCFeatureAltivec },
53 { "7450" , PowerPCFeatureAltivec },
54 { "750" , 0 },
55 { "970" , PowerPCFeature64Bit | PowerPCFeatureAltivec |
56 PowerPCFeatureFSqrt | PowerPCFeatureGPUL },
57 { "g3" , 0 },
58 { "g4" , PowerPCFeatureAltivec },
59 { "g4+" , PowerPCFeatureAltivec },
60 { "g5" , PowerPCFeature64Bit | PowerPCFeatureAltivec |
61 PowerPCFeatureFSqrt | PowerPCFeatureGPUL },
62 { "generic", 0 }
63};
64/// Length of PowerPCSubTypeKV.
65static const unsigned PowerPCSubTypeKVSize = sizeof(PowerPCSubTypeKV)
66 / sizeof(SubtargetFeatureKV);
67
68/// Sorted (by key) array of values for CPU features.
69static SubtargetFeatureKV PowerPCFeatureKV[] = {
70 { "64bit" , PowerPCFeature64Bit },
71 { "altivec", PowerPCFeatureAltivec },
72 { "fsqrt" , PowerPCFeatureFSqrt },
73 { "gpul" , PowerPCFeatureGPUL }
74 };
75/// Length of PowerPCFeatureKV.
76static const unsigned PowerPCFeatureKVSize = sizeof(PowerPCFeatureKV)
77 / sizeof(SubtargetFeatureKV);
78
79
Nate Begeman8c00f8c2005-08-04 07:12:09 +000080#if defined(__APPLE__)
81#include <mach/mach.h>
82#include <mach/mach_host.h>
83#include <mach/host_info.h>
84#include <mach/machine.h>
85
Jim Laskeyb1e11802005-09-01 21:38:21 +000086/// GetCurrentPowerPCFeatures - Returns the current CPUs features.
87static const char *GetCurrentPowerPCCPU() {
Nate Begeman8c00f8c2005-08-04 07:12:09 +000088 host_basic_info_data_t hostInfo;
89 mach_msg_type_number_t infoCount;
90
91 infoCount = HOST_BASIC_INFO_COUNT;
92 host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo,
93 &infoCount);
Jim Laskeyb1e11802005-09-01 21:38:21 +000094
95 if (hostInfo.cpu_type != CPU_TYPE_POWERPC) return "generic";
96
97 switch(hostInfo.cpu_subtype) {
98 case CPU_SUBTYPE_POWERPC_601: return "601";
99 case CPU_SUBTYPE_POWERPC_602: return "602";
100 case CPU_SUBTYPE_POWERPC_603: return "603";
101 case CPU_SUBTYPE_POWERPC_603e: return "603e";
102 case CPU_SUBTYPE_POWERPC_603ev: return "603ev";
103 case CPU_SUBTYPE_POWERPC_604: return "604";
104 case CPU_SUBTYPE_POWERPC_604e: return "604e";
105 case CPU_SUBTYPE_POWERPC_620: return "620";
106 case CPU_SUBTYPE_POWERPC_750: return "750";
107 case CPU_SUBTYPE_POWERPC_7400: return "7400";
108 case CPU_SUBTYPE_POWERPC_7450: return "7450";
109 case CPU_SUBTYPE_POWERPC_970: return "970";
110 default: ;
111 }
Nate Begeman8c00f8c2005-08-04 07:12:09 +0000112
Jim Laskeyb1e11802005-09-01 21:38:21 +0000113 return "generic";
114}
Nate Begeman8c00f8c2005-08-04 07:12:09 +0000115#endif
116
Jim Laskeyb1e11802005-09-01 21:38:21 +0000117PPCSubtarget::PPCSubtarget(const Module &M, const std::string &FS)
Chris Lattner3c304a32005-08-05 22:05:03 +0000118 : StackAlignment(16), IsGigaProcessor(false), IsAIX(false), IsDarwin(false) {
119
Jim Laskeyb1e11802005-09-01 21:38:21 +0000120 // Determine default and user specified characteristics
121 std::string CPU;
122#if defined(__APPLE__)
123 CPU = GetCurrentPowerPCCPU();
124#endif
125 uint32_t Bits =
126 SubtargetFeatures::Parse(FS, CPU,
127 PowerPCSubTypeKV, PowerPCSubTypeKVSize,
128 PowerPCFeatureKV, PowerPCFeatureKVSize);
129 IsGigaProcessor = (Bits & PowerPCFeatureGPUL) != 0;
130
131 // Set the boolean corresponding to the current target triple, or the default
Nate Begeman8c00f8c2005-08-04 07:12:09 +0000132 // if one cannot be determined, to true.
133 const std::string& TT = M.getTargetTriple();
134 if (TT.length() > 5) {
Chris Lattner3c304a32005-08-05 22:05:03 +0000135 IsDarwin = TT.find("darwin") != std::string::npos;
Nate Begeman8c00f8c2005-08-04 07:12:09 +0000136 } else if (TT.empty()) {
137#if defined(_POWER)
Chris Lattner3c304a32005-08-05 22:05:03 +0000138 IsAIX = true;
Nate Begeman8c00f8c2005-08-04 07:12:09 +0000139#elif defined(__APPLE__)
Chris Lattner3c304a32005-08-05 22:05:03 +0000140 IsDarwin = true;
Nate Begeman8c00f8c2005-08-04 07:12:09 +0000141#endif
142 }
Chris Lattner3c304a32005-08-05 22:05:03 +0000143
144 // If GP opts are forced on by the commandline, do so now.
145 if (EnableGPOPT) IsGigaProcessor = true;
Nate Begeman8c00f8c2005-08-04 07:12:09 +0000146}