1234353Sdim//===-- SparcSubtarget.cpp - SPARC Subtarget Information ------------------===//
2193323Sed//
3193323Sed//                     The LLVM Compiler Infrastructure
4193323Sed//
5193323Sed// This file is distributed under the University of Illinois Open Source
6193323Sed// License. See LICENSE.TXT for details.
7193323Sed//
8193323Sed//===----------------------------------------------------------------------===//
9193323Sed//
10224145Sdim// This file implements the SPARC specific subclass of TargetSubtargetInfo.
11193323Sed//
12193323Sed//===----------------------------------------------------------------------===//
13193323Sed
14193323Sed#include "SparcSubtarget.h"
15224145Sdim#include "Sparc.h"
16263508Sdim#include "llvm/Support/MathExtras.h"
17226633Sdim#include "llvm/Support/TargetRegistry.h"
18224145Sdim
19224145Sdim#define GET_SUBTARGETINFO_TARGET_DESC
20224145Sdim#define GET_SUBTARGETINFO_CTOR
21224145Sdim#include "SparcGenSubtargetInfo.inc"
22224145Sdim
23193323Sedusing namespace llvm;
24193323Sed
25234353Sdimvoid SparcSubtarget::anchor() { }
26234353Sdim
27224145SdimSparcSubtarget::SparcSubtarget(const std::string &TT, const std::string &CPU,
28224145Sdim                               const std::string &FS,  bool is64Bit) :
29224145Sdim  SparcGenSubtargetInfo(TT, CPU, FS),
30203954Srdivacky  IsV9(false),
31203954Srdivacky  V8DeprecatedInsts(false),
32203954Srdivacky  IsVIS(false),
33263508Sdim  Is64Bit(is64Bit),
34263763Sdim  HasHardQuad(false),
35263763Sdim  UsePopc(false) {
36263508Sdim
37193323Sed  // Determine default and user specified characteristics
38224145Sdim  std::string CPUName = CPU;
39263763Sdim  if (CPUName.empty())
40263763Sdim    CPUName = (is64Bit) ? "v9" : "v8";
41193323Sed
42193323Sed  // Parse features string.
43224145Sdim  ParseSubtargetFeatures(CPUName, FS);
44263763Sdim
45263763Sdim  // Popc is a v9-only instruction.
46263763Sdim  if (!IsV9)
47263763Sdim    UsePopc = false;
48193323Sed}
49263508Sdim
50263508Sdim
51263508Sdimint SparcSubtarget::getAdjustedFrameSize(int frameSize) const {
52263508Sdim
53263508Sdim  if (is64Bit()) {
54263508Sdim    // All 64-bit stack frames must be 16-byte aligned, and must reserve space
55263508Sdim    // for spilling the 16 window registers at %sp+BIAS..%sp+BIAS+128.
56263508Sdim    frameSize += 128;
57263508Sdim    // Frames with calls must also reserve space for 6 outgoing arguments
58263508Sdim    // whether they are used or not. LowerCall_64 takes care of that.
59263508Sdim    assert(frameSize % 16 == 0 && "Stack size not 16-byte aligned");
60263508Sdim  } else {
61263508Sdim    // Emit the correct save instruction based on the number of bytes in
62263508Sdim    // the frame. Minimum stack frame size according to V8 ABI is:
63263508Sdim    //   16 words for register window spill
64263508Sdim    //    1 word for address of returned aggregate-value
65263508Sdim    // +  6 words for passing parameters on the stack
66263508Sdim    // ----------
67263508Sdim    //   23 words * 4 bytes per word = 92 bytes
68263508Sdim    frameSize += 92;
69263508Sdim
70263508Sdim    // Round up to next doubleword boundary -- a double-word boundary
71263508Sdim    // is required by the ABI.
72263508Sdim    frameSize = RoundUpToAlignment(frameSize, 8);
73263508Sdim  }
74263508Sdim  return frameSize;
75263508Sdim}
76