1 //===-- SparcSubtarget.cpp - SPARC Subtarget Information ------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the SPARC specific subclass of TargetSubtargetInfo.
12 //===----------------------------------------------------------------------===//
14 #include "SparcSubtarget.h"
16 #include "llvm/Support/MathExtras.h"
17 #include "llvm/Support/TargetRegistry.h"
21 #define DEBUG_TYPE "sparc-subtarget"
23 #define GET_SUBTARGETINFO_TARGET_DESC
24 #define GET_SUBTARGETINFO_CTOR
25 #include "SparcGenSubtargetInfo.inc"
27 void SparcSubtarget::anchor() { }
29 static std::string computeDataLayout(const SparcSubtarget &ST) {
30 // Sparc is big endian.
31 std::string Ret = "E-m:e";
33 // Some ABIs have 32bit pointers.
37 // Alignments for 64 bit integers.
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.
45 Ret += "-f128:64-n32";
55 SparcSubtarget &SparcSubtarget::initializeSubtargetDependencies(StringRef CPU,
58 V8DeprecatedInsts = false;
63 // Determine default and user specified characteristics
64 std::string CPUName = CPU;
66 CPUName = (Is64Bit) ? "v9" : "v8";
68 // Parse features string.
69 ParseSubtargetFeatures(CPUName, FS);
71 // Popc is a v9-only instruction.
78 SparcSubtarget::SparcSubtarget(const std::string &TT, const std::string &CPU,
79 const std::string &FS, TargetMachine &TM,
81 : SparcGenSubtargetInfo(TT, CPU, FS), Is64Bit(is64Bit),
82 DL(computeDataLayout(initializeSubtargetDependencies(CPU, FS))),
83 InstrInfo(*this), TLInfo(TM), TSInfo(DL), FrameLowering(*this) {}
85 int SparcSubtarget::getAdjustedFrameSize(int frameSize) const {
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.
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");
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
101 // 23 words * 4 bytes per word = 92 bytes
104 // Round up to next doubleword boundary -- a double-word boundary
105 // is required by the ABI.
106 frameSize = RoundUpToAlignment(frameSize, 8);