blob: 5393b1d6393afb3e60e3f0a970ebd1af4d1145c5 [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 Laskeyb1e11802005-09-01 21:38:21 +000018#include "llvm/Target/SubtargetFeature.h"
Jim Laskeyf5fc2cb2005-10-21 19:05:19 +000019#include "PPCGenSubtarget.inc"
Jim Laskeyb1e11802005-09-01 21:38:21 +000020
Chris Lattner3c304a32005-08-05 22:05:03 +000021using namespace llvm;
22PPCTargetEnum llvm::PPCTarget = TargetDefault;
23
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));
Jim Laskeyf5fc2cb2005-10-21 19:05:19 +000033}
34
35/// Length of FeatureKV.
36static const unsigned FeatureKVSize = sizeof(FeatureKV)
Jim Laskeyb1e11802005-09-01 21:38:21 +000037 / sizeof(SubtargetFeatureKV);
Jim Laskeyf5fc2cb2005-10-21 19:05:19 +000038/// Length of SubTypeKV.
39static const unsigned SubTypeKVSize = sizeof(SubTypeKV)
40 / sizeof(SubtargetFeatureKV);
Jim Laskeyb1e11802005-09-01 21:38:21 +000041
42
Nate Begeman8c00f8c2005-08-04 07:12:09 +000043#if defined(__APPLE__)
44#include <mach/mach.h>
45#include <mach/mach_host.h>
46#include <mach/host_info.h>
47#include <mach/machine.h>
48
Jim Laskeyb1e11802005-09-01 21:38:21 +000049/// GetCurrentPowerPCFeatures - Returns the current CPUs features.
50static const char *GetCurrentPowerPCCPU() {
Nate Begeman8c00f8c2005-08-04 07:12:09 +000051 host_basic_info_data_t hostInfo;
52 mach_msg_type_number_t infoCount;
53
54 infoCount = HOST_BASIC_INFO_COUNT;
55 host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo,
56 &infoCount);
Jim Laskeyb1e11802005-09-01 21:38:21 +000057
58 if (hostInfo.cpu_type != CPU_TYPE_POWERPC) return "generic";
59
60 switch(hostInfo.cpu_subtype) {
61 case CPU_SUBTYPE_POWERPC_601: return "601";
62 case CPU_SUBTYPE_POWERPC_602: return "602";
63 case CPU_SUBTYPE_POWERPC_603: return "603";
64 case CPU_SUBTYPE_POWERPC_603e: return "603e";
65 case CPU_SUBTYPE_POWERPC_603ev: return "603ev";
66 case CPU_SUBTYPE_POWERPC_604: return "604";
67 case CPU_SUBTYPE_POWERPC_604e: return "604e";
68 case CPU_SUBTYPE_POWERPC_620: return "620";
69 case CPU_SUBTYPE_POWERPC_750: return "750";
70 case CPU_SUBTYPE_POWERPC_7400: return "7400";
71 case CPU_SUBTYPE_POWERPC_7450: return "7450";
72 case CPU_SUBTYPE_POWERPC_970: return "970";
73 default: ;
74 }
Nate Begeman8c00f8c2005-08-04 07:12:09 +000075
Jim Laskeyb1e11802005-09-01 21:38:21 +000076 return "generic";
77}
Nate Begeman8c00f8c2005-08-04 07:12:09 +000078#endif
79
Jim Laskeyb1e11802005-09-01 21:38:21 +000080PPCSubtarget::PPCSubtarget(const Module &M, const std::string &FS)
Chris Lattner3c304a32005-08-05 22:05:03 +000081 : StackAlignment(16), IsGigaProcessor(false), IsAIX(false), IsDarwin(false) {
82
Jim Laskeyb1e11802005-09-01 21:38:21 +000083 // Determine default and user specified characteristics
Chris Lattnerc98d8232005-09-07 05:45:33 +000084 std::string CPU = "generic";
Jim Laskeyb1e11802005-09-01 21:38:21 +000085#if defined(__APPLE__)
86 CPU = GetCurrentPowerPCCPU();
87#endif
88 uint32_t Bits =
89 SubtargetFeatures::Parse(FS, CPU,
Jim Laskeyf5fc2cb2005-10-21 19:05:19 +000090 SubTypeKV, SubTypeKVSize, FeatureKV, FeatureKVSize);
91 IsGigaProcessor = (Bits & FeatureGPUL ) != 0;
92 Is64Bit = (Bits & Feature64Bit) != 0;
93 HasFSQRT = (Bits & FeatureFSqrt) != 0;
94 Has64BitRegs = (Bits & Feature64BitRegs) != 0;
Jim Laskeyb1e11802005-09-01 21:38:21 +000095
96 // Set the boolean corresponding to the current target triple, or the default
Nate Begeman8c00f8c2005-08-04 07:12:09 +000097 // if one cannot be determined, to true.
98 const std::string& TT = M.getTargetTriple();
99 if (TT.length() > 5) {
Chris Lattner3c304a32005-08-05 22:05:03 +0000100 IsDarwin = TT.find("darwin") != std::string::npos;
Nate Begeman8c00f8c2005-08-04 07:12:09 +0000101 } else if (TT.empty()) {
102#if defined(_POWER)
Chris Lattner3c304a32005-08-05 22:05:03 +0000103 IsAIX = true;
Nate Begeman8c00f8c2005-08-04 07:12:09 +0000104#elif defined(__APPLE__)
Chris Lattner3c304a32005-08-05 22:05:03 +0000105 IsDarwin = true;
Nate Begeman8c00f8c2005-08-04 07:12:09 +0000106#endif
107 }
Nate Begeman8c00f8c2005-08-04 07:12:09 +0000108}