LLVM 24.0.0git
SparcSubtarget.cpp
Go to the documentation of this file.
1//===-- SparcSubtarget.cpp - SPARC Subtarget Information ------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the SPARC specific subclass of TargetSubtargetInfo.
10//
11//===----------------------------------------------------------------------===//
12
13#include "SparcSubtarget.h"
15#include "SparcTargetMachine.h"
16#include "llvm/ADT/StringRef.h"
20
21using namespace llvm;
22
23#define DEBUG_TYPE "sparc-subtarget"
24
25#define GET_SUBTARGETINFO_TARGET_DESC
26#define GET_SUBTARGETINFO_CTOR
27#include "SparcGenSubtargetInfo.inc"
28
29#define OPTIONS_STRUCT_DEFS
30#include "SparcOptions.inc"
31
32void SparcSubtarget::anchor() { }
33
35 StringRef CPU, StringRef TuneCPU, StringRef FS) {
36 const Triple &TT = getTargetTriple();
37 // Determine default and user specified characteristics
38 std::string CPUName = std::string(CPU);
39 if (CPUName.empty())
40 CPUName = TT.isSPARC64() ? "v9" : "v8";
41
42 if (TuneCPU.empty())
43 TuneCPU = CPUName;
44
45 // Parse features string.
46 ParseSubtargetFeatures(CPUName, TuneCPU, FS);
47
48 if (!Is64Bit && TT.isSPARC64()) {
49 FeatureBitset Features = getFeatureBits();
50 setFeatureBits(Features.set(Sparc::Feature64Bit));
51 Is64Bit = true;
52 }
53
54 // Popc is a v9-only instruction.
55 if (!IsV9)
56 UsePopc = false;
57
58 return *this;
59}
60
62 const StringRef &FS,
63 const SparcTargetMachine &TM)
64 : SparcGenSubtargetInfo(TM.getTargetTriple(), CPU, TuneCPU, FS),
65 CLOpts(TM.getCLOpts()),
66 ReserveRegister(TM.getMCRegisterInfo().getNumRegs()),
67 InstrInfo(initializeSubtargetDependencies(CPU, TuneCPU, FS)),
68 TLInfo(TM, *this), FrameLowering(*this) {
69 TSInfo = std::make_unique<SparcSelectionDAGInfo>();
70}
71
73
75 return TSInfo.get();
76}
77
79 if (hasHardQuad())
80 return;
81
82 // Setup Runtime library names.
83 if (is64Bit() && !useSoftFloat()) {
84 Info.setLibcallImpl(RTLIB::ADD_F128, RTLIB::impl__Qp_add);
85 Info.setLibcallImpl(RTLIB::SUB_F128, RTLIB::impl__Qp_sub);
86 Info.setLibcallImpl(RTLIB::MUL_F128, RTLIB::impl__Qp_mul);
87 Info.setLibcallImpl(RTLIB::DIV_F128, RTLIB::impl__Qp_div);
88 Info.setLibcallImpl(RTLIB::SQRT_F128, RTLIB::impl__Qp_sqrt);
89 Info.setLibcallImpl(RTLIB::FPTOSINT_F128_I32, RTLIB::impl__Qp_qtoi);
90 Info.setLibcallImpl(RTLIB::FPTOUINT_F128_I32, RTLIB::impl__Qp_qtoui);
91 Info.setLibcallImpl(RTLIB::SINTTOFP_I32_F128, RTLIB::impl__Qp_itoq);
92 Info.setLibcallImpl(RTLIB::UINTTOFP_I32_F128, RTLIB::impl__Qp_uitoq);
93 Info.setLibcallImpl(RTLIB::FPTOSINT_F128_I64, RTLIB::impl__Qp_qtox);
94 Info.setLibcallImpl(RTLIB::FPTOUINT_F128_I64, RTLIB::impl__Qp_qtoux);
95 Info.setLibcallImpl(RTLIB::SINTTOFP_I64_F128, RTLIB::impl__Qp_xtoq);
96 Info.setLibcallImpl(RTLIB::UINTTOFP_I64_F128, RTLIB::impl__Qp_uxtoq);
97 Info.setLibcallImpl(RTLIB::FPEXT_F32_F128, RTLIB::impl__Qp_stoq);
98 Info.setLibcallImpl(RTLIB::FPEXT_F64_F128, RTLIB::impl__Qp_dtoq);
99 Info.setLibcallImpl(RTLIB::FPROUND_F128_F32, RTLIB::impl__Qp_qtos);
100 Info.setLibcallImpl(RTLIB::FPROUND_F128_F64, RTLIB::impl__Qp_qtod);
101 } else if (!useSoftFloat()) {
102 Info.setLibcallImpl(RTLIB::ADD_F128, RTLIB::impl__Q_add);
103 Info.setLibcallImpl(RTLIB::SUB_F128, RTLIB::impl__Q_sub);
104 Info.setLibcallImpl(RTLIB::MUL_F128, RTLIB::impl__Q_mul);
105 Info.setLibcallImpl(RTLIB::DIV_F128, RTLIB::impl__Q_div);
106 Info.setLibcallImpl(RTLIB::SQRT_F128, RTLIB::impl__Q_sqrt);
107 Info.setLibcallImpl(RTLIB::FPTOSINT_F128_I32, RTLIB::impl__Q_qtoi);
108 Info.setLibcallImpl(RTLIB::FPTOUINT_F128_I32, RTLIB::impl__Q_qtou);
109 Info.setLibcallImpl(RTLIB::SINTTOFP_I32_F128, RTLIB::impl__Q_itoq);
110 Info.setLibcallImpl(RTLIB::UINTTOFP_I32_F128, RTLIB::impl__Q_utoq);
111 Info.setLibcallImpl(RTLIB::FPEXT_F32_F128, RTLIB::impl__Q_stoq);
112 Info.setLibcallImpl(RTLIB::FPEXT_F64_F128, RTLIB::impl__Q_dtoq);
113 Info.setLibcallImpl(RTLIB::FPROUND_F128_F32, RTLIB::impl__Q_qtos);
114 Info.setLibcallImpl(RTLIB::FPROUND_F128_F64, RTLIB::impl__Q_qtod);
115 }
116}
117
118int SparcSubtarget::getAdjustedFrameSize(int frameSize) const {
119
120 if (is64Bit()) {
121 // All 64-bit stack frames must be 16-byte aligned, and must reserve space
122 // for spilling the 16 window registers at %sp+BIAS..%sp+BIAS+128.
123 frameSize += 128;
124 // Frames with calls must also reserve space for 6 outgoing arguments
125 // whether they are used or not. LowerCall_64 takes care of that.
126 frameSize = alignTo(frameSize, 16);
127 } else {
128 // Emit the correct save instruction based on the number of bytes in
129 // the frame. Minimum stack frame size according to V8 ABI is:
130 // 16 words for register window spill
131 // 1 word for address of returned aggregate-value
132 // + 6 words for passing parameters on the stack
133 // ----------
134 // 23 words * 4 bytes per word = 92 bytes
135 frameSize += 92;
136
137 // Round up to next doubleword boundary -- a double-word boundary
138 // is required by the ABI.
139 frameSize = alignTo(frameSize, 8);
140 }
141 return frameSize;
142}
143
145 return true;
146}
static bool is64Bit(const char *name)
Container class for subtarget features.
FeatureBitset & set()
Tracks which library functions to use for a particular subtarget or function.
Targets can subclass this to parameterize the SelectionDAG lowering and instruction selection process...
void initLibcallLoweringInfo(LibcallLoweringInfo &Info) const override
~SparcSubtarget() override
int getAdjustedFrameSize(int stackSize) const
Given a actual stack size as determined by FrameInfo, this function returns adjusted framesize which ...
bool enableMachineScheduler() const override
SparcSubtarget(const StringRef &CPU, const StringRef &TuneCPU, const StringRef &FS, const SparcTargetMachine &TM)
const SparcOptions & getCLOpts() const
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
ParseSubtargetFeatures - Parses features string setting specified subtarget options.
SparcSubtarget & initializeSubtargetDependencies(StringRef CPU, StringRef TuneCPU, StringRef FS)
const SelectionDAGTargetInfo * getSelectionDAGInfo() const override
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
This is an optimization pass for GlobalISel generic memory operations.
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:144