forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCSKYConstantPoolValue.cpp
216 lines (181 loc) · 7.99 KB
/
CSKYConstantPoolValue.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
//===-- CSKYConstantPoolValue.cpp - CSKY constantpool value ---------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements the CSKY specific constantpool value class.
//
//===----------------------------------------------------------------------===//
#include "CSKYConstantPoolValue.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/Type.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
//===----------------------------------------------------------------------===//
// CSKYConstantPoolValue
//===----------------------------------------------------------------------===//
CSKYConstantPoolValue::CSKYConstantPoolValue(Type *Ty, CSKYCP::CSKYCPKind Kind,
unsigned PCAdjust,
CSKYCP::CSKYCPModifier Modifier,
bool AddCurrentAddress,
unsigned ID)
: MachineConstantPoolValue(Ty), Kind(Kind), PCAdjust(PCAdjust),
Modifier(Modifier), AddCurrentAddress(AddCurrentAddress), LabelId(ID) {}
const char *CSKYConstantPoolValue::getModifierText() const {
switch (Modifier) {
case CSKYCP::ADDR:
return "ADDR";
case CSKYCP::GOT:
return "GOT";
case CSKYCP::GOTOFF:
return "GOTOFF";
case CSKYCP::PLT:
return "PLT";
case CSKYCP::TLSIE:
return "TLSIE";
case CSKYCP::TLSLE:
return "TLSLE";
case CSKYCP::TLSGD:
return "TLSGD";
case CSKYCP::NO_MOD:
return "";
}
llvm_unreachable("Unknown modifier!");
}
int CSKYConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
Align Alignment) {
llvm_unreachable("Shouldn't be calling this directly!");
}
void CSKYConstantPoolValue::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
ID.AddInteger(LabelId);
ID.AddInteger(PCAdjust);
ID.AddInteger(Modifier);
}
void CSKYConstantPoolValue::print(raw_ostream &O) const {
if (Modifier)
O << "(" << getModifierText() << ")";
if (PCAdjust)
O << " + " << PCAdjust;
}
//===----------------------------------------------------------------------===//
// CSKYConstantPoolConstant
//===----------------------------------------------------------------------===//
CSKYConstantPoolConstant::CSKYConstantPoolConstant(
const Constant *C, CSKYCP::CSKYCPKind Kind, unsigned PCAdjust,
CSKYCP::CSKYCPModifier Modifier, bool AddCurrentAddress, unsigned ID)
: CSKYConstantPoolValue(C->getType(), Kind, PCAdjust, Modifier,
AddCurrentAddress, ID),
CVal(C) {}
CSKYConstantPoolConstant *CSKYConstantPoolConstant::Create(
const Constant *C, CSKYCP::CSKYCPKind Kind, unsigned PCAdjust,
CSKYCP::CSKYCPModifier Modifier, bool AddCurrentAddress, unsigned ID) {
return new CSKYConstantPoolConstant(C, Kind, PCAdjust, Modifier,
AddCurrentAddress, ID);
}
const GlobalValue *CSKYConstantPoolConstant::getGV() const {
assert(isa<GlobalValue>(CVal) && "CVal should be GlobalValue");
return cast<GlobalValue>(CVal);
}
const BlockAddress *CSKYConstantPoolConstant::getBlockAddress() const {
assert(isa<BlockAddress>(CVal) && "CVal should be BlockAddress");
return cast<BlockAddress>(CVal);
}
int CSKYConstantPoolConstant::getExistingMachineCPValue(MachineConstantPool *CP,
Align Alignment) {
return getExistingMachineCPValueImpl<CSKYConstantPoolConstant>(CP, Alignment);
}
void CSKYConstantPoolConstant::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
ID.AddPointer(CVal);
CSKYConstantPoolValue::addSelectionDAGCSEId(ID);
}
void CSKYConstantPoolConstant::print(raw_ostream &O) const {
O << CVal->getName();
CSKYConstantPoolValue::print(O);
}
//===----------------------------------------------------------------------===//
// CSKYConstantPoolSymbol
//===----------------------------------------------------------------------===//
CSKYConstantPoolSymbol::CSKYConstantPoolSymbol(Type *Ty, const char *S,
unsigned PCAdjust,
CSKYCP::CSKYCPModifier Modifier,
bool AddCurrentAddress)
: CSKYConstantPoolValue(Ty, CSKYCP::CPExtSymbol, PCAdjust, Modifier,
AddCurrentAddress),
S(strdup(S)) {}
CSKYConstantPoolSymbol *
CSKYConstantPoolSymbol::Create(Type *Ty, const char *S, unsigned PCAdjust,
CSKYCP::CSKYCPModifier Modifier) {
return new CSKYConstantPoolSymbol(Ty, S, PCAdjust, Modifier, false);
}
int CSKYConstantPoolSymbol::getExistingMachineCPValue(MachineConstantPool *CP,
Align Alignment) {
return getExistingMachineCPValueImpl<CSKYConstantPoolSymbol>(CP, Alignment);
}
void CSKYConstantPoolSymbol::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
ID.AddString(S);
CSKYConstantPoolValue::addSelectionDAGCSEId(ID);
}
void CSKYConstantPoolSymbol::print(raw_ostream &O) const {
O << S;
CSKYConstantPoolValue::print(O);
}
//===----------------------------------------------------------------------===//
// CSKYConstantPoolMBB
//===----------------------------------------------------------------------===//
CSKYConstantPoolMBB::CSKYConstantPoolMBB(Type *Ty, const MachineBasicBlock *Mbb,
unsigned PCAdjust,
CSKYCP::CSKYCPModifier Modifier,
bool AddCurrentAddress)
: CSKYConstantPoolValue(Ty, CSKYCP::CPMachineBasicBlock, PCAdjust, Modifier,
AddCurrentAddress),
MBB(Mbb) {}
CSKYConstantPoolMBB *CSKYConstantPoolMBB::Create(Type *Ty,
const MachineBasicBlock *Mbb,
unsigned PCAdjust) {
return new CSKYConstantPoolMBB(Ty, Mbb, PCAdjust, CSKYCP::ADDR, false);
}
int CSKYConstantPoolMBB::getExistingMachineCPValue(MachineConstantPool *CP,
Align Alignment) {
return getExistingMachineCPValueImpl<CSKYConstantPoolMBB>(CP, Alignment);
}
void CSKYConstantPoolMBB::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
ID.AddPointer(MBB);
CSKYConstantPoolValue::addSelectionDAGCSEId(ID);
}
void CSKYConstantPoolMBB::print(raw_ostream &O) const {
O << "BB#" << MBB->getNumber();
CSKYConstantPoolValue::print(O);
}
//===----------------------------------------------------------------------===//
// CSKYConstantPoolJT
//===----------------------------------------------------------------------===//
CSKYConstantPoolJT::CSKYConstantPoolJT(Type *Ty, int JTIndex, unsigned PCAdj,
CSKYCP::CSKYCPModifier Modifier,
bool AddCurrentAddress)
: CSKYConstantPoolValue(Ty, CSKYCP::CPJT, PCAdj, Modifier,
AddCurrentAddress),
JTI(JTIndex) {}
CSKYConstantPoolJT *
CSKYConstantPoolJT::Create(Type *Ty, int JTI, unsigned PCAdj,
CSKYCP::CSKYCPModifier Modifier) {
return new CSKYConstantPoolJT(Ty, JTI, PCAdj, Modifier, false);
}
int CSKYConstantPoolJT::getExistingMachineCPValue(MachineConstantPool *CP,
Align Alignment) {
return getExistingMachineCPValueImpl<CSKYConstantPoolJT>(CP, Alignment);
}
void CSKYConstantPoolJT::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
ID.AddInteger(JTI);
CSKYConstantPoolValue::addSelectionDAGCSEId(ID);
}
void CSKYConstantPoolJT::print(raw_ostream &O) const {
O << "JTI#" << JTI;
CSKYConstantPoolValue::print(O);
}