blob: 0efc1c152d84c95a740b32aaf6428c02a01fd77d [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"),
Chris Lattner1e9de3e2005-09-02 18:33:05 +000028 clEnumValN(TargetDarwin,"darwin",
29 " Enable Darwin codegen"),
Chris Lattner3c304a32005-08-05 22:05:03 +000030 clEnumValEnd),
31 cl::location(PPCTarget), cl::init(TargetDefault));
Chris Lattner3c304a32005-08-05 22:05:03 +000032}
Nate Begeman8c00f8c2005-08-04 07:12:09 +000033
Jim Laskeyb1e11802005-09-01 21:38:21 +000034enum PowerPCFeature {
35 PowerPCFeature64Bit = 1 << 0,
36 PowerPCFeatureAltivec = 1 << 1,
37 PowerPCFeatureFSqrt = 1 << 2,
38 PowerPCFeatureGPUL = 1 << 3,
39};
40
41/// Sorted (by key) array of values for CPU subtype.
42static const SubtargetFeatureKV PowerPCSubTypeKV[] = {
43 { "601" , 0 },
44 { "602" , 0 },
45 { "603" , 0 },
46 { "603e" , 0 },
47 { "603ev" , 0 },
48 { "604" , 0 },
49 { "604e" , 0 },
50 { "620" , 0 },
51 { "7400" , PowerPCFeatureAltivec },
52 { "7450" , PowerPCFeatureAltivec },
53 { "750" , 0 },
54 { "970" , PowerPCFeature64Bit | PowerPCFeatureAltivec |
55 PowerPCFeatureFSqrt | PowerPCFeatureGPUL },
56 { "g3" , 0 },
57 { "g4" , PowerPCFeatureAltivec },
58 { "g4+" , PowerPCFeatureAltivec },
59 { "g5" , PowerPCFeature64Bit | PowerPCFeatureAltivec |
60 PowerPCFeatureFSqrt | PowerPCFeatureGPUL },
61 { "generic", 0 }
62};
63/// Length of PowerPCSubTypeKV.
64static const unsigned PowerPCSubTypeKVSize = sizeof(PowerPCSubTypeKV)
65 / sizeof(SubtargetFeatureKV);
66
67/// Sorted (by key) array of values for CPU features.
68static SubtargetFeatureKV PowerPCFeatureKV[] = {
69 { "64bit" , PowerPCFeature64Bit },
70 { "altivec", PowerPCFeatureAltivec },
71 { "fsqrt" , PowerPCFeatureFSqrt },
72 { "gpul" , PowerPCFeatureGPUL }
73 };
74/// Length of PowerPCFeatureKV.
75static const unsigned PowerPCFeatureKVSize = sizeof(PowerPCFeatureKV)
76 / sizeof(SubtargetFeatureKV);
77
78
Nate Begeman8c00f8c2005-08-04 07:12:09 +000079#if defined(__APPLE__)
80#include <mach/mach.h>
81#include <mach/mach_host.h>
82#include <mach/host_info.h>
83#include <mach/machine.h>
84
Jim Laskeyb1e11802005-09-01 21:38:21 +000085/// GetCurrentPowerPCFeatures - Returns the current CPUs features.
86static const char *GetCurrentPowerPCCPU() {
Nate Begeman8c00f8c2005-08-04 07:12:09 +000087 host_basic_info_data_t hostInfo;
88 mach_msg_type_number_t infoCount;
89
90 infoCount = HOST_BASIC_INFO_COUNT;
91 host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo,
92 &infoCount);
Jim Laskeyb1e11802005-09-01 21:38:21 +000093
94 if (hostInfo.cpu_type != CPU_TYPE_POWERPC) return "generic";
95
96 switch(hostInfo.cpu_subtype) {
97 case CPU_SUBTYPE_POWERPC_601: return "601";
98 case CPU_SUBTYPE_POWERPC_602: return "602";
99 case CPU_SUBTYPE_POWERPC_603: return "603";
100 case CPU_SUBTYPE_POWERPC_603e: return "603e";
101 case CPU_SUBTYPE_POWERPC_603ev: return "603ev";
102 case CPU_SUBTYPE_POWERPC_604: return "604";
103 case CPU_SUBTYPE_POWERPC_604e: return "604e";
104 case CPU_SUBTYPE_POWERPC_620: return "620";
105 case CPU_SUBTYPE_POWERPC_750: return "750";
106 case CPU_SUBTYPE_POWERPC_7400: return "7400";
107 case CPU_SUBTYPE_POWERPC_7450: return "7450";
108 case CPU_SUBTYPE_POWERPC_970: return "970";
109 default: ;
110 }
Nate Begeman8c00f8c2005-08-04 07:12:09 +0000111
Jim Laskeyb1e11802005-09-01 21:38:21 +0000112 return "generic";
113}
Nate Begeman8c00f8c2005-08-04 07:12:09 +0000114#endif
115
Jim Laskeyb1e11802005-09-01 21:38:21 +0000116PPCSubtarget::PPCSubtarget(const Module &M, const std::string &FS)
Chris Lattner3c304a32005-08-05 22:05:03 +0000117 : StackAlignment(16), IsGigaProcessor(false), IsAIX(false), IsDarwin(false) {
118
Jim Laskeyb1e11802005-09-01 21:38:21 +0000119 // Determine default and user specified characteristics
120 std::string CPU;
121#if defined(__APPLE__)
122 CPU = GetCurrentPowerPCCPU();
123#endif
124 uint32_t Bits =
125 SubtargetFeatures::Parse(FS, CPU,
126 PowerPCSubTypeKV, PowerPCSubTypeKVSize,
127 PowerPCFeatureKV, PowerPCFeatureKVSize);
Chris Lattner1e9de3e2005-09-02 18:33:05 +0000128 IsGigaProcessor = (Bits & PowerPCFeatureGPUL ) != 0;
129 HasFSQRT = (Bits & PowerPCFeatureFSqrt) != 0;
Jim Laskeyb1e11802005-09-01 21:38:21 +0000130
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 }
Nate Begeman8c00f8c2005-08-04 07:12:09 +0000143}