LLVM 22.0.0git
CSKYConstantPoolValue.cpp
Go to the documentation of this file.
1//===-- CSKYConstantPoolValue.cpp - CSKY constantpool value ---------------===//
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 CSKY specific constantpool value class.
10//
11//===----------------------------------------------------------------------===//
12
14#include "llvm/ADT/FoldingSet.h"
16#include "llvm/IR/Constant.h"
17#include "llvm/IR/Constants.h"
18#include "llvm/IR/GlobalValue.h"
19#include "llvm/IR/Type.h"
21using namespace llvm;
22
23//===----------------------------------------------------------------------===//
24// CSKYConstantPoolValue
25//===----------------------------------------------------------------------===//
26
34
36 switch (Modifier) {
37 case CSKYCP::ADDR:
38 return "ADDR";
39 case CSKYCP::GOT:
40 return "GOT";
41 case CSKYCP::GOTOFF:
42 return "GOTOFF";
43 case CSKYCP::PLT:
44 return "PLT";
45 case CSKYCP::TLSIE:
46 return "TLSIE";
47 case CSKYCP::TLSLE:
48 return "TLSLE";
49 case CSKYCP::TLSGD:
50 return "TLSGD";
51 case CSKYCP::NO_MOD:
52 return "";
53 }
54 llvm_unreachable("Unknown modifier!");
55}
56
58 Align Alignment) {
59 llvm_unreachable("Shouldn't be calling this directly!");
60}
61
63 ID.AddInteger(LabelId);
64 ID.AddInteger(PCAdjust);
65 ID.AddInteger(Modifier);
66}
67
69 if (Modifier)
70 O << "(" << getModifierText() << ")";
71 if (PCAdjust)
72 O << " + " << PCAdjust;
73}
74
75//===----------------------------------------------------------------------===//
76// CSKYConstantPoolConstant
77//===----------------------------------------------------------------------===//
78
79CSKYConstantPoolConstant::CSKYConstantPoolConstant(
80 const Constant *C, Type *Ty, CSKYCP::CSKYCPKind Kind, unsigned PCAdjust,
81 CSKYCP::CSKYCPModifier Modifier, bool AddCurrentAddress, unsigned ID)
82 : CSKYConstantPoolValue(Ty, Kind, PCAdjust, Modifier, AddCurrentAddress,
83 ID),
84 CVal(C) {}
85
86CSKYConstantPoolConstant *CSKYConstantPoolConstant::Create(
87 const Constant *C, CSKYCP::CSKYCPKind Kind, unsigned PCAdjust,
89 return new CSKYConstantPoolConstant(C, C->getType(), Kind, PCAdjust, Modifier,
91}
92
93CSKYConstantPoolConstant *CSKYConstantPoolConstant::Create(
94 const Constant *C, Type *Ty, CSKYCP::CSKYCPKind Kind, unsigned PCAdjust,
96 return new CSKYConstantPoolConstant(C, Ty, Kind, PCAdjust, Modifier,
98}
99
101 assert(isa<GlobalValue>(CVal) && "CVal should be GlobalValue");
102 return cast<GlobalValue>(CVal);
103}
104
106 assert(isa<BlockAddress>(CVal) && "CVal should be BlockAddress");
107 return cast<BlockAddress>(CVal);
108}
109
111 return CVal;
112}
113
118
124
126 O << CVal->getName();
128}
129
130//===----------------------------------------------------------------------===//
131// CSKYConstantPoolSymbol
132//===----------------------------------------------------------------------===//
133
134CSKYConstantPoolSymbol::CSKYConstantPoolSymbol(Type *Ty, const char *S,
135 unsigned PCAdjust,
136 CSKYCP::CSKYCPModifier Modifier,
137 bool AddCurrentAddress)
138 : CSKYConstantPoolValue(Ty, CSKYCP::CPExtSymbol, PCAdjust, Modifier,
139 AddCurrentAddress),
140 S(strdup(S)) {}
141
143CSKYConstantPoolSymbol::Create(Type *Ty, const char *S, unsigned PCAdjust,
145 return new CSKYConstantPoolSymbol(Ty, S, PCAdjust, Modifier, false);
146}
147
153
158
163
164//===----------------------------------------------------------------------===//
165// CSKYConstantPoolMBB
166//===----------------------------------------------------------------------===//
167
168CSKYConstantPoolMBB::CSKYConstantPoolMBB(Type *Ty, const MachineBasicBlock *Mbb,
169 unsigned PCAdjust,
170 CSKYCP::CSKYCPModifier Modifier,
171 bool AddCurrentAddress)
172 : CSKYConstantPoolValue(Ty, CSKYCP::CPMachineBasicBlock, PCAdjust, Modifier,
173 AddCurrentAddress),
174 MBB(Mbb) {}
175
176CSKYConstantPoolMBB *CSKYConstantPoolMBB::Create(Type *Ty,
177 const MachineBasicBlock *Mbb,
178 unsigned PCAdjust) {
179 return new CSKYConstantPoolMBB(Ty, Mbb, PCAdjust, CSKYCP::ADDR, false);
180}
181
186
191
193 O << "BB#" << MBB->getNumber();
195}
196
197//===----------------------------------------------------------------------===//
198// CSKYConstantPoolJT
199//===----------------------------------------------------------------------===//
200
201CSKYConstantPoolJT::CSKYConstantPoolJT(Type *Ty, int JTIndex, unsigned PCAdj,
202 CSKYCP::CSKYCPModifier Modifier,
203 bool AddCurrentAddress)
204 : CSKYConstantPoolValue(Ty, CSKYCP::CPJT, PCAdj, Modifier,
205 AddCurrentAddress),
206 JTI(JTIndex) {}
207
209CSKYConstantPoolJT::Create(Type *Ty, int JTI, unsigned PCAdj,
211 return new CSKYConstantPoolJT(Ty, JTI, PCAdj, Modifier, false);
212}
213
218
223
225 O << "JTI#" << JTI;
227}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines a hash set that can be used to remove duplication of nodes in a graph.
The address of a basic block.
Definition Constants.h:899
const GlobalValue * getGV() const
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
void print(raw_ostream &O) const override
print - Implement operator<<
static CSKYConstantPoolConstant * Create(const Constant *C, CSKYCP::CSKYCPKind Kind, unsigned PCAdjust, CSKYCP::CSKYCPModifier Modifier, bool AddCurrentAddress, unsigned ID=0)
const BlockAddress * getBlockAddress() const
const Constant * getConstantPool() const
CSKY-specific constantpool value of a jump table.
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
static CSKYConstantPoolJT * Create(Type *Ty, int JTI, unsigned PCAdj, CSKYCP::CSKYCPModifier Modifier)
void print(raw_ostream &O) const override
print - Implement operator<<
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
static CSKYConstantPoolMBB * Create(Type *Ty, const MachineBasicBlock *Mbb, unsigned PCAdjust)
void print(raw_ostream &O) const override
print - Implement operator<<
CSKYConstantPoolSymbol - CSKY-specific constantpool values for external symbols.
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
void print(raw_ostream &O) const override
print - Implement operator<<
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
static CSKYConstantPoolSymbol * Create(Type *Ty, const char *S, unsigned PCAdjust, CSKYCP::CSKYCPModifier Modifier)
CSKYConstantPoolValue - CSKY specific constantpool value.
void print(raw_ostream &O) const override
print - Implement operator<<
CSKYConstantPoolValue(Type *Ty, CSKYCP::CSKYCPKind Kind, unsigned PCAdjust, CSKYCP::CSKYCPModifier Modifier, bool AddCurrentAddress, unsigned ID=0)
int getExistingMachineCPValueImpl(MachineConstantPool *CP, Align Alignment)
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
CSKYCP::CSKYCPModifier Modifier
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
This is an important base class in LLVM.
Definition Constant.h:43
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition FoldingSet.h:330
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:548
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:565
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39