blob: f9ce0984f45a73a9bf559ac8f91a070e0dd6720d [file] [log] [blame]
Jia Liu31d157a2012-02-18 12:03:15 +00001//===-- SparcSubtarget.cpp - SPARC Subtarget Information ------------------===//
Chris Lattner0d170a72006-01-26 06:51:21 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner0d170a72006-01-26 06:51:21 +00007//
8//===----------------------------------------------------------------------===//
9//
Evan Cheng5b1b44892011-07-01 21:01:15 +000010// This file implements the SPARC specific subclass of TargetSubtargetInfo.
Chris Lattner0d170a72006-01-26 06:51:21 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattner7c90f732006-02-05 05:50:24 +000014#include "SparcSubtarget.h"
Evan Chengffc0e732011-07-09 05:47:46 +000015#include "Sparc.h"
Venkatraman Govindaraju72ad17c2013-06-01 04:51:18 +000016#include "llvm/Support/MathExtras.h"
Evan Cheng3e74d6f2011-08-24 18:08:43 +000017#include "llvm/Support/TargetRegistry.h"
Evan Cheng94214702011-07-01 20:45:01 +000018
Evan Cheng94214702011-07-01 20:45:01 +000019#define GET_SUBTARGETINFO_TARGET_DESC
Evan Chengebdeeab2011-07-08 01:53:10 +000020#define GET_SUBTARGETINFO_CTOR
Evan Cheng385e9302011-07-01 22:36:09 +000021#include "SparcGenSubtargetInfo.inc"
Evan Cheng94214702011-07-01 20:45:01 +000022
Chris Lattner0d170a72006-01-26 06:51:21 +000023using namespace llvm;
24
David Blaikie2d24e2a2011-12-20 02:50:00 +000025void SparcSubtarget::anchor() { }
26
Evan Cheng276365d2011-06-30 01:53:36 +000027SparcSubtarget::SparcSubtarget(const std::string &TT, const std::string &CPU,
28 const std::string &FS, bool is64Bit) :
Evan Cheng0ddff1b2011-07-07 07:07:08 +000029 SparcGenSubtargetInfo(TT, CPU, FS),
Chris Lattner87c06d62010-02-04 06:34:01 +000030 IsV9(false),
31 V8DeprecatedInsts(false),
32 IsVIS(false),
33 Is64Bit(is64Bit) {
Venkatraman Govindaraju1e06bcb2013-06-04 18:33:25 +000034
Chris Lattner0d170a72006-01-26 06:51:21 +000035 // Determine default and user specified characteristics
Evan Cheng276365d2011-06-30 01:53:36 +000036 std::string CPUName = CPU;
37 if (CPUName.empty()) {
38 if (is64Bit)
39 CPUName = "v9";
40 else
41 CPUName = "v8";
Chris Lattner87c06d62010-02-04 06:34:01 +000042 }
Evan Cheng276365d2011-06-30 01:53:36 +000043 IsV9 = CPUName == "v9";
Chris Lattner0d170a72006-01-26 06:51:21 +000044
Chris Lattner0d170a72006-01-26 06:51:21 +000045 // Parse features string.
Evan Cheng0ddff1b2011-07-07 07:07:08 +000046 ParseSubtargetFeatures(CPUName, FS);
Chris Lattnerd74ea2b2006-05-24 17:04:05 +000047}
Venkatraman Govindaraju72ad17c2013-06-01 04:51:18 +000048
49
50int SparcSubtarget::getAdjustedFrameSize(int frameSize) const {
51
52 if (is64Bit()) {
53 // All 64-bit stack frames must be 16-byte aligned, and must reserve space
54 // for spilling the 16 window registers at %sp+BIAS..%sp+BIAS+128.
55 frameSize += 128;
56 // Frames with calls must also reserve space for 6 outgoing arguments
57 // whether they are used or not. LowerCall_64 takes care of that.
58 assert(frameSize % 16 == 0 && "Stack size not 16-byte aligned");
59 } else {
60 // Emit the correct save instruction based on the number of bytes in
61 // the frame. Minimum stack frame size according to V8 ABI is:
62 // 16 words for register window spill
63 // 1 word for address of returned aggregate-value
64 // + 6 words for passing parameters on the stack
65 // ----------
66 // 23 words * 4 bytes per word = 92 bytes
67 frameSize += 92;
68
69 // Round up to next doubleword boundary -- a double-word boundary
70 // is required by the ABI.
71 frameSize = RoundUpToAlignment(frameSize, 8);
72 }
73 return frameSize;
74}