blob: eea0c8c33c6ab0122d82a450d61e5c56e41d7ef1 [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
Stephen Hinesdce4a402014-05-29 02:49:00 -070019using namespace llvm;
20
21#define DEBUG_TYPE "sparc-subtarget"
22
Evan Cheng94214702011-07-01 20:45:01 +000023#define GET_SUBTARGETINFO_TARGET_DESC
Evan Chengebdeeab2011-07-08 01:53:10 +000024#define GET_SUBTARGETINFO_CTOR
Evan Cheng385e9302011-07-01 22:36:09 +000025#include "SparcGenSubtargetInfo.inc"
Evan Cheng94214702011-07-01 20:45:01 +000026
David Blaikie2d24e2a2011-12-20 02:50:00 +000027void SparcSubtarget::anchor() { }
28
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -070029static std::string computeDataLayout(const SparcSubtarget &ST) {
30 // Sparc is big endian.
31 std::string Ret = "E-m:e";
32
33 // Some ABIs have 32bit pointers.
34 if (!ST.is64Bit())
35 Ret += "-p:32:32";
36
37 // Alignments for 64 bit integers.
38 Ret += "-i64:64";
39
40 // On SparcV9 128 floats are aligned to 128 bits, on others only to 64.
41 // On SparcV9 registers can hold 64 or 32 bits, on others only 32.
42 if (ST.is64Bit())
43 Ret += "-n32:64";
44 else
45 Ret += "-f128:64-n32";
46
47 if (ST.is64Bit())
48 Ret += "-S128";
49 else
50 Ret += "-S64";
51
52 return Ret;
53}
54
55SparcSubtarget &SparcSubtarget::initializeSubtargetDependencies(StringRef CPU,
56 StringRef FS) {
57 IsV9 = false;
58 V8DeprecatedInsts = false;
59 IsVIS = false;
60 HasHardQuad = false;
61 UsePopc = false;
Venkatraman Govindaraju1e06bcb2013-06-04 18:33:25 +000062
Chris Lattner0d170a72006-01-26 06:51:21 +000063 // Determine default and user specified characteristics
Evan Cheng276365d2011-06-30 01:53:36 +000064 std::string CPUName = CPU;
Stephen Hines36b56882014-04-23 16:57:46 -070065 if (CPUName.empty())
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -070066 CPUName = (Is64Bit) ? "v9" : "v8";
Chris Lattner0d170a72006-01-26 06:51:21 +000067
Chris Lattner0d170a72006-01-26 06:51:21 +000068 // Parse features string.
Evan Cheng0ddff1b2011-07-07 07:07:08 +000069 ParseSubtargetFeatures(CPUName, FS);
Stephen Hines36b56882014-04-23 16:57:46 -070070
71 // Popc is a v9-only instruction.
72 if (!IsV9)
73 UsePopc = false;
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -070074
75 return *this;
Chris Lattnerd74ea2b2006-05-24 17:04:05 +000076}
Venkatraman Govindaraju72ad17c2013-06-01 04:51:18 +000077
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -070078SparcSubtarget::SparcSubtarget(const std::string &TT, const std::string &CPU,
79 const std::string &FS, TargetMachine &TM,
80 bool is64Bit)
81 : SparcGenSubtargetInfo(TT, CPU, FS), Is64Bit(is64Bit),
82 DL(computeDataLayout(initializeSubtargetDependencies(CPU, FS))),
83 InstrInfo(*this), TLInfo(TM), TSInfo(DL), FrameLowering(*this) {}
Venkatraman Govindaraju72ad17c2013-06-01 04:51:18 +000084
85int SparcSubtarget::getAdjustedFrameSize(int frameSize) const {
86
87 if (is64Bit()) {
88 // All 64-bit stack frames must be 16-byte aligned, and must reserve space
89 // for spilling the 16 window registers at %sp+BIAS..%sp+BIAS+128.
90 frameSize += 128;
91 // Frames with calls must also reserve space for 6 outgoing arguments
92 // whether they are used or not. LowerCall_64 takes care of that.
93 assert(frameSize % 16 == 0 && "Stack size not 16-byte aligned");
94 } else {
95 // Emit the correct save instruction based on the number of bytes in
96 // the frame. Minimum stack frame size according to V8 ABI is:
97 // 16 words for register window spill
98 // 1 word for address of returned aggregate-value
99 // + 6 words for passing parameters on the stack
100 // ----------
101 // 23 words * 4 bytes per word = 92 bytes
102 frameSize += 92;
103
104 // Round up to next doubleword boundary -- a double-word boundary
105 // is required by the ABI.
106 frameSize = RoundUpToAlignment(frameSize, 8);
107 }
108 return frameSize;
109}