Skip to content

Commit 43bf22a

Browse files
committed
[Xtensa] Add initial implementation of the Constant Pool.
1 parent d7a0f08 commit 43bf22a

File tree

3 files changed

+478
-0
lines changed

3 files changed

+478
-0
lines changed

llvm/lib/Target/Xtensa/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ add_public_tablegen_target(XtensaCommonTableGen)
1616

1717
add_llvm_target(XtensaCodeGen
1818
XtensaAsmPrinter.cpp
19+
XtensaConstantPoolValue.cpp
1920
XtensaFrameLowering.cpp
2021
XtensaInstrInfo.cpp
2122
XtensaISelDAGToDAG.cpp
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
//===- XtensaConstantPoolValue.cpp - Xtensa constantpool value ------------===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6+
// See https://llvm.org/LICENSE.txt for license information.
7+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
//
9+
//===----------------------------------------------------------------------===//
10+
//
11+
// This file implements the Xtensa specific constantpool value class.
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
#include "XtensaConstantPoolValue.h"
16+
#include "llvm/ADT/FoldingSet.h"
17+
#include "llvm/CodeGen/MachineBasicBlock.h"
18+
#include "llvm/IR/Constant.h"
19+
#include "llvm/IR/Constants.h"
20+
#include "llvm/IR/GlobalValue.h"
21+
#include "llvm/IR/Type.h"
22+
#include "llvm/Support/raw_ostream.h"
23+
#include <cstdlib>
24+
using namespace llvm;
25+
26+
XtensaConstantPoolValue::XtensaConstantPoolValue(
27+
Type *Ty, unsigned id, XtensaCP::XtensaCPKind kind,
28+
XtensaCP::XtensaCPModifier modifier)
29+
: MachineConstantPoolValue(Ty), LabelId(id), Kind(kind),
30+
Modifier(modifier) {}
31+
32+
XtensaConstantPoolValue::XtensaConstantPoolValue(
33+
LLVMContext &C, unsigned id, XtensaCP::XtensaCPKind kind,
34+
XtensaCP::XtensaCPModifier modifier)
35+
: MachineConstantPoolValue((Type *)Type::getInt32Ty(C)), LabelId(id),
36+
Kind(kind), Modifier(modifier) {}
37+
38+
XtensaConstantPoolValue::~XtensaConstantPoolValue() {}
39+
40+
StringRef XtensaConstantPoolValue::getModifierText() const {
41+
switch (Modifier) {
42+
case XtensaCP::no_modifier:
43+
return "";
44+
case XtensaCP::TPOFF:
45+
return "@TPOFF";
46+
}
47+
report_fatal_error("Unknown modifier!");
48+
}
49+
50+
int XtensaConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
51+
Align Alignment) {
52+
report_fatal_error("Shouldn't be calling this directly!");
53+
}
54+
55+
void XtensaConstantPoolValue::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
56+
ID.AddInteger(LabelId);
57+
}
58+
59+
bool XtensaConstantPoolValue::hasSameValue(XtensaConstantPoolValue *ACPV) {
60+
if (ACPV->Kind == Kind) {
61+
if (ACPV->LabelId == LabelId)
62+
return true;
63+
}
64+
return false;
65+
}
66+
67+
void XtensaConstantPoolValue::dump() const { errs() << " " << *this; }
68+
69+
void XtensaConstantPoolValue::print(raw_ostream &O) const {}
70+
71+
//===----------------------------------------------------------------------===//
72+
// XtensaConstantPoolConstant
73+
//===----------------------------------------------------------------------===//
74+
75+
XtensaConstantPoolConstant::XtensaConstantPoolConstant(
76+
const Constant *C, unsigned ID, XtensaCP::XtensaCPKind Kind)
77+
: XtensaConstantPoolValue((Type *)C->getType(), ID, Kind),
78+
CVal(C) {}
79+
80+
XtensaConstantPoolConstant *
81+
XtensaConstantPoolConstant::Create(const Constant *C, unsigned ID,
82+
XtensaCP::XtensaCPKind Kind) {
83+
return new XtensaConstantPoolConstant(C, ID, Kind);
84+
}
85+
86+
const BlockAddress *XtensaConstantPoolConstant::getBlockAddress() const {
87+
return dyn_cast_or_null<BlockAddress>(CVal);
88+
}
89+
90+
int XtensaConstantPoolConstant::getExistingMachineCPValue(
91+
MachineConstantPool *CP, Align Alignment) {
92+
return getExistingMachineCPValueImpl<XtensaConstantPoolConstant>(CP,
93+
Alignment);
94+
}
95+
96+
bool XtensaConstantPoolConstant::hasSameValue(XtensaConstantPoolValue *ACPV) {
97+
const XtensaConstantPoolConstant *ACPC =
98+
dyn_cast<XtensaConstantPoolConstant>(ACPV);
99+
return ACPC && ACPC->CVal == CVal &&
100+
XtensaConstantPoolValue::hasSameValue(ACPV);
101+
}
102+
103+
void XtensaConstantPoolConstant::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
104+
ID.AddPointer(CVal);
105+
XtensaConstantPoolValue::addSelectionDAGCSEId(ID);
106+
}
107+
108+
void XtensaConstantPoolConstant::print(raw_ostream &O) const {
109+
O << CVal->getName();
110+
XtensaConstantPoolValue::print(O);
111+
}
112+
113+
XtensaConstantPoolSymbol::XtensaConstantPoolSymbol(
114+
LLVMContext &C, const char *s, unsigned id, bool PrivLinkage,
115+
XtensaCP::XtensaCPModifier Modifier)
116+
: XtensaConstantPoolValue(C, id, XtensaCP::CPExtSymbol, Modifier), S(s),
117+
PrivateLinkage(PrivLinkage) {}
118+
119+
XtensaConstantPoolSymbol *
120+
XtensaConstantPoolSymbol::Create(LLVMContext &C, const char *s, unsigned ID,
121+
bool PrivLinkage,
122+
XtensaCP::XtensaCPModifier Modifier)
123+
124+
{
125+
return new XtensaConstantPoolSymbol(C, s, ID, PrivLinkage, Modifier);
126+
}
127+
128+
int XtensaConstantPoolSymbol::getExistingMachineCPValue(MachineConstantPool *CP,
129+
Align Alignment) {
130+
return getExistingMachineCPValueImpl<XtensaConstantPoolSymbol>(CP, Alignment);
131+
}
132+
133+
bool XtensaConstantPoolSymbol::hasSameValue(XtensaConstantPoolValue *ACPV) {
134+
const XtensaConstantPoolSymbol *ACPS =
135+
dyn_cast<XtensaConstantPoolSymbol>(ACPV);
136+
return ACPS && ACPS->S == S && XtensaConstantPoolValue::hasSameValue(ACPV);
137+
}
138+
139+
void XtensaConstantPoolSymbol::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
140+
ID.AddString(S);
141+
XtensaConstantPoolValue::addSelectionDAGCSEId(ID);
142+
}
143+
144+
void XtensaConstantPoolSymbol::print(raw_ostream &O) const {
145+
O << S;
146+
XtensaConstantPoolValue::print(O);
147+
}
148+
149+
XtensaConstantPoolMBB::XtensaConstantPoolMBB(LLVMContext &C,
150+
const MachineBasicBlock *mbb,
151+
unsigned id)
152+
: XtensaConstantPoolValue(C, 0, XtensaCP::CPMachineBasicBlock),
153+
MBB(mbb) {}
154+
155+
XtensaConstantPoolMBB *
156+
XtensaConstantPoolMBB::Create(LLVMContext &C, const MachineBasicBlock *mbb,
157+
unsigned idx) {
158+
return new XtensaConstantPoolMBB(C, mbb, idx);
159+
}
160+
161+
int XtensaConstantPoolMBB::getExistingMachineCPValue(MachineConstantPool *CP,
162+
Align Alignment) {
163+
return getExistingMachineCPValueImpl<XtensaConstantPoolMBB>(CP, Alignment);
164+
}
165+
166+
bool XtensaConstantPoolMBB::hasSameValue(XtensaConstantPoolValue *ACPV) {
167+
const XtensaConstantPoolMBB *ACPMBB = dyn_cast<XtensaConstantPoolMBB>(ACPV);
168+
return ACPMBB && ACPMBB->MBB == MBB &&
169+
XtensaConstantPoolValue::hasSameValue(ACPV);
170+
}
171+
172+
void XtensaConstantPoolMBB::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
173+
ID.AddPointer(MBB);
174+
XtensaConstantPoolValue::addSelectionDAGCSEId(ID);
175+
}
176+
177+
void XtensaConstantPoolMBB::print(raw_ostream &O) const {
178+
O << "BB#" << MBB->getNumber();
179+
XtensaConstantPoolValue::print(O);
180+
}
181+
182+
XtensaConstantPoolJumpTable::XtensaConstantPoolJumpTable(LLVMContext &C,
183+
unsigned idx)
184+
: XtensaConstantPoolValue(C, 0, XtensaCP::CPJumpTable), IDX(idx) {}
185+
186+
XtensaConstantPoolJumpTable *XtensaConstantPoolJumpTable::Create(LLVMContext &C,
187+
unsigned idx) {
188+
return new XtensaConstantPoolJumpTable(C, idx);
189+
}
190+
191+
int XtensaConstantPoolJumpTable::getExistingMachineCPValue(
192+
MachineConstantPool *CP, Align Alignment) {
193+
return getExistingMachineCPValueImpl<XtensaConstantPoolJumpTable>(CP,
194+
Alignment);
195+
}
196+
197+
bool XtensaConstantPoolJumpTable::hasSameValue(XtensaConstantPoolValue *ACPV) {
198+
const XtensaConstantPoolJumpTable *ACPJT =
199+
dyn_cast<XtensaConstantPoolJumpTable>(ACPV);
200+
return ACPJT && ACPJT->IDX == IDX &&
201+
XtensaConstantPoolValue::hasSameValue(ACPV);
202+
}
203+
204+
void XtensaConstantPoolJumpTable::addSelectionDAGCSEId(FoldingSetNodeID &ID) {}
205+
206+
void XtensaConstantPoolJumpTable::print(raw_ostream &O) const {
207+
O << "JT" << IDX;
208+
XtensaConstantPoolValue::print(O);
209+
}
210+

0 commit comments

Comments
 (0)