1 //===- PowerPCSubtarget.cpp - PPC Subtarget Information ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file implements the PPC specific subclass of TargetSubtarget.
12 //===----------------------------------------------------------------------===//
14 #include "PPCSubtarget.h"
16 #include "llvm/Module.h"
17 #include "llvm/Support/CommandLine.h"
18 #include "llvm/Target/SubtargetFeature.h"
21 PPCTargetEnum llvm::PPCTarget = TargetDefault;
24 cl::opt<PPCTargetEnum, true>
25 PPCTargetArg(cl::desc("Force generation of code for a specific PPC target:"),
27 clEnumValN(TargetAIX, "aix", " Enable AIX codegen"),
28 clEnumValN(TargetDarwin,"darwin",
29 " Enable Darwin codegen"),
31 cl::location(PPCTarget), cl::init(TargetDefault));
35 PowerPCFeature64Bit = 1 << 0,
36 PowerPCFeatureAltivec = 1 << 1,
37 PowerPCFeatureFSqrt = 1 << 2,
38 PowerPCFeatureGPUL = 1 << 3,
39 PowerPCFeature64BRegs = 1 << 4
42 /// Sorted (by key) array of values for CPU subtype.
43 static const SubtargetFeatureKV PowerPCSubTypeKV[] = {
44 { "601" , "Select the PowerPC 601 processor", 0 },
45 { "602" , "Select the PowerPC 602 processor", 0 },
46 { "603" , "Select the PowerPC 603 processor", 0 },
47 { "603e" , "Select the PowerPC 603e processor", 0 },
48 { "603ev" , "Select the PowerPC 603ev processor", 0 },
49 { "604" , "Select the PowerPC 604 processor", 0 },
50 { "604e" , "Select the PowerPC 604e processor", 0 },
51 { "620" , "Select the PowerPC 620 processor", 0 },
52 { "7400" , "Select the PowerPC 7400 (G4) processor",
53 PowerPCFeatureAltivec },
54 { "7450" , "Select the PowerPC 7450 (G4+) processor",
55 PowerPCFeatureAltivec },
56 { "750" , "Select the PowerPC 750 (G3) processor", 0 },
57 { "970" , "Select the PowerPC 970 (G5 - GPUL) processor",
58 PowerPCFeature64Bit | PowerPCFeatureAltivec |
59 PowerPCFeatureFSqrt | PowerPCFeatureGPUL },
60 { "g3" , "Select the PowerPC G3 (750) processor", 0 },
61 { "g4" , "Select the PowerPC G4 (7400) processor",
62 PowerPCFeatureAltivec },
63 { "g4+" , "Select the PowerPC G4+ (7450) processor",
64 PowerPCFeatureAltivec },
65 { "g5" , "Select the PowerPC g5 (970 - GPUL) processor",
66 PowerPCFeature64Bit | PowerPCFeatureAltivec |
67 PowerPCFeatureFSqrt | PowerPCFeatureGPUL },
68 { "generic", "Select instructions for a generic PowerPC processor", 0 }
70 /// Length of PowerPCSubTypeKV.
71 static const unsigned PowerPCSubTypeKVSize = sizeof(PowerPCSubTypeKV)
72 / sizeof(SubtargetFeatureKV);
74 /// Sorted (by key) array of values for CPU features.
75 static SubtargetFeatureKV PowerPCFeatureKV[] = {
76 { "64bit" , "Should 64 bit instructions be used" , PowerPCFeature64Bit },
77 { "64bitregs", "Should 64 bit registers be used" , PowerPCFeature64BRegs },
78 { "altivec", "Should Altivec instructions be used" , PowerPCFeatureAltivec },
79 { "fsqrt" , "Should the fsqrt instruction be used", PowerPCFeatureFSqrt },
80 { "gpul" , "Should GPUL instructions be used" , PowerPCFeatureGPUL }
82 /// Length of PowerPCFeatureKV.
83 static const unsigned PowerPCFeatureKVSize = sizeof(PowerPCFeatureKV)
84 / sizeof(SubtargetFeatureKV);
87 #if defined(__APPLE__)
88 #include <mach/mach.h>
89 #include <mach/mach_host.h>
90 #include <mach/host_info.h>
91 #include <mach/machine.h>
93 /// GetCurrentPowerPCFeatures - Returns the current CPUs features.
94 static const char *GetCurrentPowerPCCPU() {
95 host_basic_info_data_t hostInfo;
96 mach_msg_type_number_t infoCount;
98 infoCount = HOST_BASIC_INFO_COUNT;
99 host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo,
102 if (hostInfo.cpu_type != CPU_TYPE_POWERPC) return "generic";
104 switch(hostInfo.cpu_subtype) {
105 case CPU_SUBTYPE_POWERPC_601: return "601";
106 case CPU_SUBTYPE_POWERPC_602: return "602";
107 case CPU_SUBTYPE_POWERPC_603: return "603";
108 case CPU_SUBTYPE_POWERPC_603e: return "603e";
109 case CPU_SUBTYPE_POWERPC_603ev: return "603ev";
110 case CPU_SUBTYPE_POWERPC_604: return "604";
111 case CPU_SUBTYPE_POWERPC_604e: return "604e";
112 case CPU_SUBTYPE_POWERPC_620: return "620";
113 case CPU_SUBTYPE_POWERPC_750: return "750";
114 case CPU_SUBTYPE_POWERPC_7400: return "7400";
115 case CPU_SUBTYPE_POWERPC_7450: return "7450";
116 case CPU_SUBTYPE_POWERPC_970: return "970";
124 PPCSubtarget::PPCSubtarget(const Module &M, const std::string &FS)
125 : StackAlignment(16), IsGigaProcessor(false), IsAIX(false), IsDarwin(false) {
127 // Determine default and user specified characteristics
128 std::string CPU = "generic";
129 #if defined(__APPLE__)
130 CPU = GetCurrentPowerPCCPU();
133 SubtargetFeatures::Parse(FS, CPU,
134 PowerPCSubTypeKV, PowerPCSubTypeKVSize,
135 PowerPCFeatureKV, PowerPCFeatureKVSize);
136 IsGigaProcessor = (Bits & PowerPCFeatureGPUL ) != 0;
137 Is64Bit = (Bits & PowerPCFeature64Bit) != 0;
138 HasFSQRT = (Bits & PowerPCFeatureFSqrt) != 0;
139 Has64BitRegs = (Bits & PowerPCFeature64BRegs) != 0;
141 // Set the boolean corresponding to the current target triple, or the default
142 // if one cannot be determined, to true.
143 const std::string& TT = M.getTargetTriple();
144 if (TT.length() > 5) {
145 IsDarwin = TT.find("darwin") != std::string::npos;
146 } else if (TT.empty()) {
149 #elif defined(__APPLE__)