Add the PPC lfiwax instruction
[oota-llvm.git] / lib / Target / PowerPC / PPCSubtarget.cpp
1 //===-- PowerPCSubtarget.cpp - PPC Subtarget Information ------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the PPC specific subclass of TargetSubtargetInfo.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "PPCSubtarget.h"
15 #include "PPC.h"
16 #include "PPCRegisterInfo.h"
17 #include "llvm/IR/GlobalValue.h"
18 #include "llvm/Support/Host.h"
19 #include "llvm/Support/TargetRegistry.h"
20 #include "llvm/Target/TargetMachine.h"
21 #include <cstdlib>
22
23 #define GET_SUBTARGETINFO_TARGET_DESC
24 #define GET_SUBTARGETINFO_CTOR
25 #include "PPCGenSubtargetInfo.inc"
26
27 using namespace llvm;
28
29 PPCSubtarget::PPCSubtarget(const std::string &TT, const std::string &CPU,
30                            const std::string &FS, bool is64Bit)
31   : PPCGenSubtargetInfo(TT, CPU, FS)
32   , StackAlignment(16)
33   , DarwinDirective(PPC::DIR_NONE)
34   , HasMFOCRF(false)
35   , Has64BitSupport(false)
36   , Use64BitRegs(false)
37   , IsPPC64(is64Bit)
38   , HasAltivec(false)
39   , HasQPX(false)
40   , HasFSQRT(false)
41   , HasSTFIWX(false)
42   , HasLFIWAX(false)
43   , HasFPRND(false)
44   , HasISEL(false)
45   , HasPOPCNTD(false)
46   , HasLDBRX(false)
47   , IsBookE(false)
48   , HasLazyResolverStubs(false)
49   , IsJITCodeModel(false)
50   , TargetTriple(TT) {
51
52   // Determine default and user specified characteristics
53   std::string CPUName = CPU;
54   if (CPUName.empty())
55     CPUName = "generic";
56 #if (defined(__APPLE__) || defined(__linux__)) && \
57     (defined(__ppc__) || defined(__powerpc__))
58   if (CPUName == "generic")
59     CPUName = sys::getHostCPUName();
60 #endif
61
62   // Initialize scheduling itinerary for the specified CPU.
63   InstrItins = getInstrItineraryForCPU(CPUName);
64
65   // Make sure 64-bit features are available when CPUname is generic
66   std::string FullFS = FS;
67
68   // If we are generating code for ppc64, verify that options make sense.
69   if (is64Bit) {
70     Has64BitSupport = true;
71     // Silently force 64-bit register use on ppc64.
72     Use64BitRegs = true;
73     if (!FullFS.empty())
74       FullFS = "+64bit," + FullFS;
75     else
76       FullFS = "+64bit";
77   }
78
79   // Parse features string.
80   ParseSubtargetFeatures(CPUName, FullFS);
81
82   // If the user requested use of 64-bit regs, but the cpu selected doesn't
83   // support it, ignore.
84   if (use64BitRegs() && !has64BitSupport())
85     Use64BitRegs = false;
86
87   // Set up darwin-specific properties.
88   if (isDarwin())
89     HasLazyResolverStubs = true;
90
91   // QPX requires a 32-byte aligned stack. Note that we need to do this if
92   // we're compiling for a BG/Q system regardless of whether or not QPX
93   // is enabled because external functions will assume this alignment.
94   if (hasQPX() || isBGQ())
95     StackAlignment = 32;
96 }
97
98 /// SetJITMode - This is called to inform the subtarget info that we are
99 /// producing code for the JIT.
100 void PPCSubtarget::SetJITMode() {
101   // JIT mode doesn't want lazy resolver stubs, it knows exactly where
102   // everything is.  This matters for PPC64, which codegens in PIC mode without
103   // stubs.
104   HasLazyResolverStubs = false;
105
106   // Calls to external functions need to use indirect calls
107   IsJITCodeModel = true;
108 }
109
110
111 /// hasLazyResolverStub - Return true if accesses to the specified global have
112 /// to go through a dyld lazy resolution stub.  This means that an extra load
113 /// is required to get the address of the global.
114 bool PPCSubtarget::hasLazyResolverStub(const GlobalValue *GV,
115                                        const TargetMachine &TM) const {
116   // We never have stubs if HasLazyResolverStubs=false or if in static mode.
117   if (!HasLazyResolverStubs || TM.getRelocationModel() == Reloc::Static)
118     return false;
119   // If symbol visibility is hidden, the extra load is not needed if
120   // the symbol is definitely defined in the current translation unit.
121   bool isDecl = GV->isDeclaration() && !GV->isMaterializable();
122   if (GV->hasHiddenVisibility() && !isDecl && !GV->hasCommonLinkage())
123     return false;
124   return GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() ||
125          GV->hasCommonLinkage() || isDecl;
126 }
127
128 bool PPCSubtarget::enablePostRAScheduler(
129            CodeGenOpt::Level OptLevel,
130            TargetSubtargetInfo::AntiDepBreakMode& Mode,
131            RegClassVector& CriticalPathRCs) const {
132   // FIXME: It would be best to use TargetSubtargetInfo::ANTIDEP_ALL here,
133   // but we can't because we can't reassign the cr registers. There is a
134   // dependence between the cr register and the RLWINM instruction used
135   // to extract its value which the anti-dependency breaker can't currently
136   // see. Maybe we should make a late-expanded pseudo to encode this dependency.
137   // (the relevant code is in PPCDAGToDAGISel::SelectSETCC)
138
139   Mode = TargetSubtargetInfo::ANTIDEP_CRITICAL;
140
141   CriticalPathRCs.clear();
142
143   if (isPPC64())
144     CriticalPathRCs.push_back(&PPC::G8RCRegClass);
145   else
146     CriticalPathRCs.push_back(&PPC::GPRCRegClass);
147     
148   CriticalPathRCs.push_back(&PPC::F8RCRegClass);
149   CriticalPathRCs.push_back(&PPC::VRRCRegClass);
150
151   return OptLevel >= CodeGenOpt::Default;
152 }
153