blob: c7a34280ea7e46d040c4eda90ae4d6738e218227 [file] [log] [blame]
Chris Lattner96909792006-01-28 05:40:47 +00001//===- PowerPCSubtarget.cpp - PPC Subtarget Information -------------------===//
Nate Begeman8c00f8c2005-08-04 07:12:09 +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 PPC specific subclass of TargetSubtarget.
11//
12//===----------------------------------------------------------------------===//
13
Chris Lattner26689592005-10-14 23:51:18 +000014#include "PPCSubtarget.h"
15#include "PPC.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 Laskeyf5fc2cb2005-10-21 19:05:19 +000018#include "PPCGenSubtarget.inc"
Jim Laskeyb1e11802005-09-01 21:38:21 +000019
Chris Lattner3c304a32005-08-05 22:05:03 +000020using namespace llvm;
21PPCTargetEnum llvm::PPCTarget = TargetDefault;
Chris Lattner1d05cb42005-11-17 18:55:48 +000022bool llvm::PPCGenerateStaticCode = false;
Chris Lattner3c304a32005-08-05 22:05:03 +000023
24namespace llvm {
25 cl::opt<PPCTargetEnum, true>
26 PPCTargetArg(cl::desc("Force generation of code for a specific PPC target:"),
27 cl::values(
28 clEnumValN(TargetAIX, "aix", " Enable AIX codegen"),
Chris Lattner1e9de3e2005-09-02 18:33:05 +000029 clEnumValN(TargetDarwin,"darwin",
30 " Enable Darwin codegen"),
Chris Lattner3c304a32005-08-05 22:05:03 +000031 clEnumValEnd),
32 cl::location(PPCTarget), cl::init(TargetDefault));
Chris Lattner1d05cb42005-11-17 18:55:48 +000033
34 cl::opt<bool, true>
35 PPCStaticCode("ppc-static",
36 cl::desc("PowerPC: generate completely non-pic code"),
37 cl::location(PPCGenerateStaticCode));
Jim Laskeyf5fc2cb2005-10-21 19:05:19 +000038}
39
Nate Begeman8c00f8c2005-08-04 07:12:09 +000040#if defined(__APPLE__)
41#include <mach/mach.h>
42#include <mach/mach_host.h>
43#include <mach/host_info.h>
44#include <mach/machine.h>
45
Jim Laskeyb1e11802005-09-01 21:38:21 +000046/// GetCurrentPowerPCFeatures - Returns the current CPUs features.
47static const char *GetCurrentPowerPCCPU() {
Nate Begeman8c00f8c2005-08-04 07:12:09 +000048 host_basic_info_data_t hostInfo;
49 mach_msg_type_number_t infoCount;
50
51 infoCount = HOST_BASIC_INFO_COUNT;
52 host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo,
53 &infoCount);
Jim Laskeyb1e11802005-09-01 21:38:21 +000054
55 if (hostInfo.cpu_type != CPU_TYPE_POWERPC) return "generic";
56
57 switch(hostInfo.cpu_subtype) {
58 case CPU_SUBTYPE_POWERPC_601: return "601";
59 case CPU_SUBTYPE_POWERPC_602: return "602";
60 case CPU_SUBTYPE_POWERPC_603: return "603";
61 case CPU_SUBTYPE_POWERPC_603e: return "603e";
62 case CPU_SUBTYPE_POWERPC_603ev: return "603ev";
63 case CPU_SUBTYPE_POWERPC_604: return "604";
64 case CPU_SUBTYPE_POWERPC_604e: return "604e";
65 case CPU_SUBTYPE_POWERPC_620: return "620";
66 case CPU_SUBTYPE_POWERPC_750: return "750";
67 case CPU_SUBTYPE_POWERPC_7400: return "7400";
68 case CPU_SUBTYPE_POWERPC_7450: return "7450";
69 case CPU_SUBTYPE_POWERPC_970: return "970";
70 default: ;
71 }
Nate Begeman8c00f8c2005-08-04 07:12:09 +000072
Jim Laskeyb1e11802005-09-01 21:38:21 +000073 return "generic";
74}
Nate Begeman8c00f8c2005-08-04 07:12:09 +000075#endif
76
Jim Laskey581a8f72005-10-26 17:30:34 +000077
Jim Laskeyb1e11802005-09-01 21:38:21 +000078PPCSubtarget::PPCSubtarget(const Module &M, const std::string &FS)
Jim Laskey581a8f72005-10-26 17:30:34 +000079 : StackAlignment(16)
Jim Laskey6cee6302005-11-01 20:06:59 +000080 , InstrItins()
Jim Laskey581a8f72005-10-26 17:30:34 +000081 , IsGigaProcessor(false)
82 , Is64Bit(false)
83 , Has64BitRegs(false)
84 , HasAltivec(false)
85 , HasFSQRT(false)
86 , IsAIX(false)
87 , IsDarwin(false) {
Chris Lattner3c304a32005-08-05 22:05:03 +000088
Jim Laskeyb1e11802005-09-01 21:38:21 +000089 // Determine default and user specified characteristics
Chris Lattnerc98d8232005-09-07 05:45:33 +000090 std::string CPU = "generic";
Jim Laskeyb1e11802005-09-01 21:38:21 +000091#if defined(__APPLE__)
92 CPU = GetCurrentPowerPCCPU();
93#endif
Jim Laskey581a8f72005-10-26 17:30:34 +000094
95 // Parse features string.
96 ParseSubtargetFeatures(FS, CPU);
Jim Laskeyb1e11802005-09-01 21:38:21 +000097
98 // Set the boolean corresponding to the current target triple, or the default
Nate Begeman8c00f8c2005-08-04 07:12:09 +000099 // if one cannot be determined, to true.
100 const std::string& TT = M.getTargetTriple();
101 if (TT.length() > 5) {
Chris Lattner3c304a32005-08-05 22:05:03 +0000102 IsDarwin = TT.find("darwin") != std::string::npos;
Nate Begeman8c00f8c2005-08-04 07:12:09 +0000103 } else if (TT.empty()) {
104#if defined(_POWER)
Chris Lattner3c304a32005-08-05 22:05:03 +0000105 IsAIX = true;
Nate Begeman8c00f8c2005-08-04 07:12:09 +0000106#elif defined(__APPLE__)
Chris Lattner3c304a32005-08-05 22:05:03 +0000107 IsDarwin = true;
Nate Begeman8c00f8c2005-08-04 07:12:09 +0000108#endif
109 }
Nate Begeman8c00f8c2005-08-04 07:12:09 +0000110}