1 //===-- VESubtarget.cpp - VE 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 VE specific subclass of TargetSubtargetInfo.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "VESubtarget.h"
14 #include "VE.h"
15 #include "llvm/Support/MathExtras.h"
16 #include "llvm/Support/TargetRegistry.h"
17 
18 using namespace llvm;
19 
20 #define DEBUG_TYPE "ve-subtarget"
21 
22 #define GET_SUBTARGETINFO_TARGET_DESC
23 #define GET_SUBTARGETINFO_CTOR
24 #include "VEGenSubtargetInfo.inc"
25 
26 void VESubtarget::anchor() {}
27 
28 VESubtarget &VESubtarget::initializeSubtargetDependencies(StringRef CPU,
29                                                           StringRef FS) {
30   // Default feature settings
31   EnableVPU = false;
32 
33   // Determine default and user specified characteristics
34   std::string CPUName = std::string(CPU);
35   if (CPUName.empty())
36     CPUName = "ve";
37 
38   // Parse features string.
39   ParseSubtargetFeatures(CPUName, /*TuneCPU=*/CPU, FS);
40 
41   return *this;
42 }
43 
44 VESubtarget::VESubtarget(const Triple &TT, const std::string &CPU,
45                          const std::string &FS, const TargetMachine &TM)
46     : VEGenSubtargetInfo(TT, CPU, /*TuneCPU=*/CPU, FS), TargetTriple(TT),
47       InstrInfo(initializeSubtargetDependencies(CPU, FS)), TLInfo(TM, *this),
48       FrameLowering(*this) {}
49 
50 int VESubtarget::getAdjustedFrameSize(int frameSize) const {
51 
52   // VE stack frame:
53   //
54   //         +----------------------------------------+
55   //         | Locals and temporaries                 |
56   //         +----------------------------------------+
57   //         | Parameter area for callee              |
58   // 176(fp) |                                        |
59   //         +----------------------------------------+
60   //         | Register save area (RSA) for callee    |
61   //         |                                        |
62   //  16(fp) |                         20 * 8 bytes   |
63   //         +----------------------------------------+
64   //   8(fp) | Return address                         |
65   //         +----------------------------------------+
66   //   0(fp) | Frame pointer of caller                |
67   // --------+----------------------------------------+--------
68   //         | Locals and temporaries for callee      |
69   //         +----------------------------------------+
70   //         | Parameter area for callee of callee    |
71   //         +----------------------------------------+
72   //  16(sp) | RSA for callee of callee               |
73   //         +----------------------------------------+
74   //   8(sp) | Return address                         |
75   //         +----------------------------------------+
76   //   0(sp) | Frame pointer of callee                |
77   //         +----------------------------------------+
78 
79   // RSA frame:
80   //         +----------------------------------------------+
81   // 168(fp) | %s33                                         |
82   //         +----------------------------------------------+
83   //         | %s19...%s32                                  |
84   //         +----------------------------------------------+
85   //  48(fp) | %s18                                         |
86   //         +----------------------------------------------+
87   //  40(fp) | Linkage area register (%s17)                 |
88   //         +----------------------------------------------+
89   //  32(fp) | Procedure linkage table register (%plt=%s16) |
90   //         +----------------------------------------------+
91   //  24(fp) | Global offset table register (%got=%s15)     |
92   //         +----------------------------------------------+
93   //  16(fp) | Thread pointer register (%tp=%s14)           |
94   //         +----------------------------------------------+
95 
96   frameSize += 176;                   // for RSA, RA, and FP
97   frameSize = alignTo(frameSize, 16); // requires 16 bytes alignment
98 
99   return frameSize;
100 }
101 
102 bool VESubtarget::enableMachineScheduler() const { return true; }
103