[cleanup] Lift using directives, DEBUG_TYPE definitions, and even some
[oota-llvm.git] / lib / Target / Sparc / SparcSubtarget.cpp
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(const std::string &TT, const std::string &CPU,
30                                const std::string &FS,  bool is64Bit) :
31   SparcGenSubtargetInfo(TT, CPU, FS),
32   IsV9(false),
33   V8DeprecatedInsts(false),
34   IsVIS(false),
35   Is64Bit(is64Bit),
36   HasHardQuad(false),
37   UsePopc(false) {
38
39   // Determine default and user specified characteristics
40   std::string CPUName = CPU;
41   if (CPUName.empty())
42     CPUName = (is64Bit) ? "v9" : "v8";
43
44   // Parse features string.
45   ParseSubtargetFeatures(CPUName, FS);
46
47   // Popc is a v9-only instruction.
48   if (!IsV9)
49     UsePopc = false;
50 }
51
52
53 int SparcSubtarget::getAdjustedFrameSize(int frameSize) const {
54
55   if (is64Bit()) {
56     // All 64-bit stack frames must be 16-byte aligned, and must reserve space
57     // for spilling the 16 window registers at %sp+BIAS..%sp+BIAS+128.
58     frameSize += 128;
59     // Frames with calls must also reserve space for 6 outgoing arguments
60     // whether they are used or not. LowerCall_64 takes care of that.
61     assert(frameSize % 16 == 0 && "Stack size not 16-byte aligned");
62   } else {
63     // Emit the correct save instruction based on the number of bytes in
64     // the frame. Minimum stack frame size according to V8 ABI is:
65     //   16 words for register window spill
66     //    1 word for address of returned aggregate-value
67     // +  6 words for passing parameters on the stack
68     // ----------
69     //   23 words * 4 bytes per word = 92 bytes
70     frameSize += 92;
71
72     // Round up to next doubleword boundary -- a double-word boundary
73     // is required by the ABI.
74     frameSize = RoundUpToAlignment(frameSize, 8);
75   }
76   return frameSize;
77 }