blob: 1995e1ceb077461a7189b4161a437930f834da64 [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
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;
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));
Jim Laskeyf5fc2cb2005-10-21 19:05:19 +000032}
33
Nate Begeman8c00f8c2005-08-04 07:12:09 +000034#if defined(__APPLE__)
35#include <mach/mach.h>
36#include <mach/mach_host.h>
37#include <mach/host_info.h>
38#include <mach/machine.h>
39
Jim Laskeyb1e11802005-09-01 21:38:21 +000040/// GetCurrentPowerPCFeatures - Returns the current CPUs features.
41static const char *GetCurrentPowerPCCPU() {
Nate Begeman8c00f8c2005-08-04 07:12:09 +000042 host_basic_info_data_t hostInfo;
43 mach_msg_type_number_t infoCount;
44
45 infoCount = HOST_BASIC_INFO_COUNT;
46 host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo,
47 &infoCount);
Jim Laskeyb1e11802005-09-01 21:38:21 +000048
49 if (hostInfo.cpu_type != CPU_TYPE_POWERPC) return "generic";
50
51 switch(hostInfo.cpu_subtype) {
52 case CPU_SUBTYPE_POWERPC_601: return "601";
53 case CPU_SUBTYPE_POWERPC_602: return "602";
54 case CPU_SUBTYPE_POWERPC_603: return "603";
55 case CPU_SUBTYPE_POWERPC_603e: return "603e";
56 case CPU_SUBTYPE_POWERPC_603ev: return "603ev";
57 case CPU_SUBTYPE_POWERPC_604: return "604";
58 case CPU_SUBTYPE_POWERPC_604e: return "604e";
59 case CPU_SUBTYPE_POWERPC_620: return "620";
60 case CPU_SUBTYPE_POWERPC_750: return "750";
61 case CPU_SUBTYPE_POWERPC_7400: return "7400";
62 case CPU_SUBTYPE_POWERPC_7450: return "7450";
63 case CPU_SUBTYPE_POWERPC_970: return "970";
64 default: ;
65 }
Nate Begeman8c00f8c2005-08-04 07:12:09 +000066
Jim Laskeyb1e11802005-09-01 21:38:21 +000067 return "generic";
68}
Nate Begeman8c00f8c2005-08-04 07:12:09 +000069#endif
70
Jim Laskeyb1e11802005-09-01 21:38:21 +000071PPCSubtarget::PPCSubtarget(const Module &M, const std::string &FS)
Chris Lattner3c304a32005-08-05 22:05:03 +000072 : StackAlignment(16), IsGigaProcessor(false), IsAIX(false), IsDarwin(false) {
73
Jim Laskeyb1e11802005-09-01 21:38:21 +000074 // Determine default and user specified characteristics
Chris Lattnerc98d8232005-09-07 05:45:33 +000075 std::string CPU = "generic";
Jim Laskeyb1e11802005-09-01 21:38:21 +000076#if defined(__APPLE__)
77 CPU = GetCurrentPowerPCCPU();
78#endif
Jim Laskey34bd5d52005-10-25 15:15:28 +000079 SubtargetFeatures Features(FS);
80 Features.setCPUIfNone(CPU);
81 uint32_t Bits = Features.getBits(SubTypeKV, SubTypeKVSize,
82 FeatureKV, FeatureKVSize);
Jim Laskeyf5fc2cb2005-10-21 19:05:19 +000083 IsGigaProcessor = (Bits & FeatureGPUL ) != 0;
84 Is64Bit = (Bits & Feature64Bit) != 0;
85 HasFSQRT = (Bits & FeatureFSqrt) != 0;
86 Has64BitRegs = (Bits & Feature64BitRegs) != 0;
Jim Laskeyb1e11802005-09-01 21:38:21 +000087
88 // Set the boolean corresponding to the current target triple, or the default
Nate Begeman8c00f8c2005-08-04 07:12:09 +000089 // if one cannot be determined, to true.
90 const std::string& TT = M.getTargetTriple();
91 if (TT.length() > 5) {
Chris Lattner3c304a32005-08-05 22:05:03 +000092 IsDarwin = TT.find("darwin") != std::string::npos;
Nate Begeman8c00f8c2005-08-04 07:12:09 +000093 } else if (TT.empty()) {
94#if defined(_POWER)
Chris Lattner3c304a32005-08-05 22:05:03 +000095 IsAIX = true;
Nate Begeman8c00f8c2005-08-04 07:12:09 +000096#elif defined(__APPLE__)
Chris Lattner3c304a32005-08-05 22:05:03 +000097 IsDarwin = true;
Nate Begeman8c00f8c2005-08-04 07:12:09 +000098#endif
99 }
Nate Begeman8c00f8c2005-08-04 07:12:09 +0000100}