What should be the last unnecessary <iostream>s in the library.
[oota-llvm.git] / lib / Target / PowerPC / PPCSubtarget.cpp
1 //===- PowerPCSubtarget.cpp - PPC Subtarget Information -------------------===//
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 "PPCSubtarget.h"
15 #include "PPC.h"
16 #include "llvm/Module.h"
17 #include "PPCGenSubtarget.inc"
18 using namespace llvm;
19
20 #if defined(__APPLE__)
21 #include <mach/mach.h>
22 #include <mach/mach_host.h>
23 #include <mach/host_info.h>
24 #include <mach/machine.h>
25
26 /// GetCurrentPowerPCFeatures - Returns the current CPUs features.
27 static const char *GetCurrentPowerPCCPU() {
28   host_basic_info_data_t hostInfo;
29   mach_msg_type_number_t infoCount;
30
31   infoCount = HOST_BASIC_INFO_COUNT;
32   host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, 
33             &infoCount);
34             
35   if (hostInfo.cpu_type != CPU_TYPE_POWERPC) return "generic";
36
37   switch(hostInfo.cpu_subtype) {
38   case CPU_SUBTYPE_POWERPC_601:   return "601";
39   case CPU_SUBTYPE_POWERPC_602:   return "602";
40   case CPU_SUBTYPE_POWERPC_603:   return "603";
41   case CPU_SUBTYPE_POWERPC_603e:  return "603e";
42   case CPU_SUBTYPE_POWERPC_603ev: return "603ev";
43   case CPU_SUBTYPE_POWERPC_604:   return "604";
44   case CPU_SUBTYPE_POWERPC_604e:  return "604e";
45   case CPU_SUBTYPE_POWERPC_620:   return "620";
46   case CPU_SUBTYPE_POWERPC_750:   return "750";
47   case CPU_SUBTYPE_POWERPC_7400:  return "7400";
48   case CPU_SUBTYPE_POWERPC_7450:  return "7450";
49   case CPU_SUBTYPE_POWERPC_970:   return "970";
50   default: ;
51   }
52   
53   return "generic";
54 }
55 #endif
56
57
58 PPCSubtarget::PPCSubtarget(const Module &M, const std::string &FS, bool is64Bit)
59   : StackAlignment(16)
60   , InstrItins()
61   , IsGigaProcessor(false)
62   , Has64BitSupport(false)
63   , Use64BitRegs(false)
64   , IsPPC64(is64Bit)
65   , HasAltivec(false)
66   , HasFSQRT(false)
67   , HasSTFIWX(false)
68   , IsDarwin(false) {
69
70   // Determine default and user specified characteristics
71   std::string CPU = "generic";
72 #if defined(__APPLE__)
73   CPU = GetCurrentPowerPCCPU();
74 #endif
75
76   // Parse features string.
77   ParseSubtargetFeatures(FS, CPU);
78
79   // If we are generating code for ppc64, verify that options make sense.
80   if (is64Bit) {
81     if (!has64BitSupport()) {
82       cerr << "PPC: Generation of 64-bit code for a 32-bit processor "
83            << "requested.  Ignoring 32-bit processor feature.\n";
84       Has64BitSupport = true;
85     }
86     // Silently force 64-bit register use on ppc64.
87     Use64BitRegs = true;
88   }
89   
90   // If the user requested use of 64-bit regs, but the cpu selected doesn't
91   // support it, warn and ignore.
92   if (use64BitRegs() && !has64BitSupport()) {
93     cerr << "PPC: 64-bit registers requested on CPU without support.  "
94          << "Disabling 64-bit register use.\n";
95     Use64BitRegs = false;
96   }
97   
98   // Set the boolean corresponding to the current target triple, or the default
99   // if one cannot be determined, to true.
100   const std::string& TT = M.getTargetTriple();
101   if (TT.length() > 5) {
102     IsDarwin = TT.find("-darwin") != std::string::npos;
103   } else if (TT.empty()) {
104 #if defined(__APPLE__)
105     IsDarwin = true;
106 #endif
107   }
108 }