xref: /llvm-project/llvm/lib/Target/Sparc/SparcSubtarget.cpp (revision 2cc9da9a654ca1f9f90d1eaaea889516074f975f)
1 //===-- SparcSubtarget.cpp - SPARC 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 SPARC specific subclass of TargetSubtargetInfo.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "SparcSubtarget.h"
15 #include "Sparc.h"
16 #include "llvm/Support/MathExtras.h"
17 #include "llvm/Support/TargetRegistry.h"
18 
19 using namespace llvm;
20 
21 #define DEBUG_TYPE "sparc-subtarget"
22 
23 #define GET_SUBTARGETINFO_TARGET_DESC
24 #define GET_SUBTARGETINFO_CTOR
25 #include "SparcGenSubtargetInfo.inc"
26 
27 void SparcSubtarget::anchor() { }
28 
29 SparcSubtarget &SparcSubtarget::initializeSubtargetDependencies(StringRef CPU,
30                                                                 StringRef FS) {
31   IsV9 = false;
32   IsLeon = false;
33   V8DeprecatedInsts = false;
34   IsVIS = false;
35   HasHardQuad = false;
36   UsePopc = false;
37   UseSoftFloat = false;
38 
39   // Leon features
40   HasLeonCasa = false;
41   HasUmacSmac = false;
42   InsertNOPLoad = false;
43   FixFSMULD = false;
44   ReplaceFMULS = false;
45   FixAllFDIVSQRT = false;
46 
47   // Determine default and user specified characteristics
48   std::string CPUName = CPU;
49   if (CPUName.empty())
50     CPUName = (Is64Bit) ? "v9" : "v8";
51 
52   // Parse features string.
53   ParseSubtargetFeatures(CPUName, FS);
54 
55   // Popc is a v9-only instruction.
56   if (!IsV9)
57     UsePopc = false;
58 
59   return *this;
60 }
61 
62 SparcSubtarget::SparcSubtarget(const Triple &TT, const std::string &CPU,
63                                const std::string &FS, const TargetMachine &TM,
64                                bool is64Bit)
65     : SparcGenSubtargetInfo(TT, CPU, FS), TargetTriple(TT), Is64Bit(is64Bit),
66       InstrInfo(initializeSubtargetDependencies(CPU, FS)), TLInfo(TM, *this),
67       FrameLowering(*this) {}
68 
69 int SparcSubtarget::getAdjustedFrameSize(int frameSize) const {
70 
71   if (is64Bit()) {
72     // All 64-bit stack frames must be 16-byte aligned, and must reserve space
73     // for spilling the 16 window registers at %sp+BIAS..%sp+BIAS+128.
74     frameSize += 128;
75     // Frames with calls must also reserve space for 6 outgoing arguments
76     // whether they are used or not. LowerCall_64 takes care of that.
77     frameSize = alignTo(frameSize, 16);
78   } else {
79     // Emit the correct save instruction based on the number of bytes in
80     // the frame. Minimum stack frame size according to V8 ABI is:
81     //   16 words for register window spill
82     //    1 word for address of returned aggregate-value
83     // +  6 words for passing parameters on the stack
84     // ----------
85     //   23 words * 4 bytes per word = 92 bytes
86     frameSize += 92;
87 
88     // Round up to next doubleword boundary -- a double-word boundary
89     // is required by the ABI.
90     frameSize = alignTo(frameSize, 8);
91   }
92   return frameSize;
93 }
94 
95 bool SparcSubtarget::enableMachineScheduler() const {
96   return true;
97 }
98