LLVM  15.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 
13 #include "CSKYConstantPoolValue.h"
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"
21 using namespace llvm;
22 
23 //===----------------------------------------------------------------------===//
24 // CSKYConstantPoolValue
25 //===----------------------------------------------------------------------===//
26 
28  unsigned PCAdjust,
29  CSKYCP::CSKYCPModifier Modifier,
30  bool AddCurrentAddress,
31  unsigned ID)
32  : MachineConstantPoolValue(Ty), Kind(Kind), PCAdjust(PCAdjust),
33  Modifier(Modifier), AddCurrentAddress(AddCurrentAddress), LabelId(ID) {}
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 
79 CSKYConstantPoolConstant::CSKYConstantPoolConstant(
80  const Constant *C, CSKYCP::CSKYCPKind Kind, unsigned PCAdjust,
81  CSKYCP::CSKYCPModifier Modifier, bool AddCurrentAddress, unsigned ID)
82  : CSKYConstantPoolValue(C->getType(), Kind, PCAdjust, Modifier,
83  AddCurrentAddress, ID),
84  CVal(C) {}
85 
87  const Constant *C, CSKYCP::CSKYCPKind Kind, unsigned PCAdjust,
88  CSKYCP::CSKYCPModifier Modifier, bool AddCurrentAddress, unsigned ID) {
91 }
92 
94  assert(isa<GlobalValue>(CVal) && "CVal should be GlobalValue");
95  return cast<GlobalValue>(CVal);
96 }
97 
99  assert(isa<BlockAddress>(CVal) && "CVal should be BlockAddress");
100  return cast<BlockAddress>(CVal);
101 }
102 
104  Align Alignment) {
105  return getExistingMachineCPValueImpl<CSKYConstantPoolConstant>(CP, Alignment);
106 }
107 
109  ID.AddPointer(CVal);
110 
112 }
113 
115  O << CVal->getName();
117 }
118 
119 //===----------------------------------------------------------------------===//
120 // CSKYConstantPoolSymbol
121 //===----------------------------------------------------------------------===//
122 
123 CSKYConstantPoolSymbol::CSKYConstantPoolSymbol(Type *Ty, const char *S,
124  unsigned PCAdjust,
125  CSKYCP::CSKYCPModifier Modifier,
126  bool AddCurrentAddress)
127  : CSKYConstantPoolValue(Ty, CSKYCP::CPExtSymbol, PCAdjust, Modifier,
128  AddCurrentAddress),
129  S(strdup(S)) {}
130 
132 CSKYConstantPoolSymbol::Create(Type *Ty, const char *S, unsigned PCAdjust,
133  CSKYCP::CSKYCPModifier Modifier) {
134  return new CSKYConstantPoolSymbol(Ty, S, PCAdjust, Modifier, false);
135 }
136 
138  Align Alignment) {
139 
140  return getExistingMachineCPValueImpl<CSKYConstantPoolSymbol>(CP, Alignment);
141 }
142 
144  ID.AddString(S);
146 }
147 
149  O << S;
151 }
152 
153 //===----------------------------------------------------------------------===//
154 // CSKYConstantPoolMBB
155 //===----------------------------------------------------------------------===//
156 
157 CSKYConstantPoolMBB::CSKYConstantPoolMBB(Type *Ty, const MachineBasicBlock *Mbb,
158  unsigned PCAdjust,
159  CSKYCP::CSKYCPModifier Modifier,
160  bool AddCurrentAddress)
161  : CSKYConstantPoolValue(Ty, CSKYCP::CPMachineBasicBlock, PCAdjust, Modifier,
162  AddCurrentAddress),
163  MBB(Mbb) {}
164 
166  const MachineBasicBlock *Mbb,
167  unsigned PCAdjust) {
168  return new CSKYConstantPoolMBB(Ty, Mbb, PCAdjust, CSKYCP::ADDR, false);
169 }
170 
172  Align Alignment) {
173  return getExistingMachineCPValueImpl<CSKYConstantPoolMBB>(CP, Alignment);
174 }
175 
177  ID.AddPointer(MBB);
179 }
180 
182  O << "BB#" << MBB->getNumber();
184 }
185 
186 //===----------------------------------------------------------------------===//
187 // CSKYConstantPoolJT
188 //===----------------------------------------------------------------------===//
189 
190 CSKYConstantPoolJT::CSKYConstantPoolJT(Type *Ty, int JTIndex, unsigned PCAdj,
191  CSKYCP::CSKYCPModifier Modifier,
192  bool AddCurrentAddress)
193  : CSKYConstantPoolValue(Ty, CSKYCP::CPJT, PCAdj, Modifier,
194  AddCurrentAddress),
195  JTI(JTIndex) {}
196 
198 CSKYConstantPoolJT::Create(Type *Ty, int JTI, unsigned PCAdj,
199  CSKYCP::CSKYCPModifier Modifier) {
200  return new CSKYConstantPoolJT(Ty, JTI, PCAdj, Modifier, false);
201 }
202 
204  Align Alignment) {
205  return getExistingMachineCPValueImpl<CSKYConstantPoolJT>(CP, Alignment);
206 }
207 
209  ID.AddInteger(JTI);
211 }
212 
214  O << "JTI#" << JTI;
216 }
llvm::CSKYConstantPoolSymbol::addSelectionDAGCSEId
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
Definition: CSKYConstantPoolValue.cpp:143
llvm::CSKYCP::PLT
@ PLT
Definition: CSKYConstantPoolValue.h:39
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::CSKYCP::TLSGD
@ TLSGD
Definition: CSKYConstantPoolValue.h:39
CSKYConstantPoolValue.h
llvm::CSKYConstantPoolJT::Create
static CSKYConstantPoolJT * Create(Type *Ty, int JTI, unsigned PCAdj, CSKYCP::CSKYCPModifier Modifier)
Definition: CSKYConstantPoolValue.cpp:198
llvm::CSKYConstantPoolValue::print
void print(raw_ostream &O) const override
print - Implement operator<<
Definition: CSKYConstantPoolValue.cpp:68
llvm::CSKYConstantPoolJT
CSKY-specific constantpool value of a jump table.
Definition: CSKYConstantPoolValue.h:193
llvm::CSKYConstantPoolMBB::print
void print(raw_ostream &O) const override
print - Implement operator<<
Definition: CSKYConstantPoolValue.cpp:181
llvm::CSKYConstantPoolValue::Modifier
CSKYCP::CSKYCPModifier Modifier
Definition: CSKYConstantPoolValue.h:49
llvm::CSKYConstantPoolConstant::Create
static CSKYConstantPoolConstant * Create(const Constant *C, CSKYCP::CSKYCPKind Kind, unsigned PCAdjust, CSKYCP::CSKYCPModifier Modifier, bool AddCurrentAddress, unsigned ID=0)
Definition: CSKYConstantPoolValue.cpp:86
llvm::ARMCP::CPMachineBasicBlock
@ CPMachineBasicBlock
Definition: ARMConstantPoolValue.h:42
MachineBasicBlock.h
llvm::MachineConstantPoolValue
Abstract base class for all machine specific constantpool value subclasses.
Definition: MachineConstantPool.h:35
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::CSKYConstantPoolJT::print
void print(raw_ostream &O) const override
print - Implement operator<<
Definition: CSKYConstantPoolValue.cpp:213
llvm::CSKYCP::GOT
@ GOT
Definition: CSKYConstantPoolValue.h:39
llvm::CSKYConstantPoolJT::getExistingMachineCPValue
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
Definition: CSKYConstantPoolValue.cpp:203
llvm::Intrinsic::getType
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
Definition: Function.cpp:1366
GlobalValue.h
Constants.h
llvm::ARMCP::CPExtSymbol
@ CPExtSymbol
Definition: ARMConstantPoolValue.h:39
llvm::CSKYCP::NO_MOD
@ NO_MOD
Definition: CSKYConstantPoolValue.h:39
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::CSKYCP::CPJT
@ CPJT
Definition: CSKYConstantPoolValue.h:36
llvm::CSKYConstantPoolJT::addSelectionDAGCSEId
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
Definition: CSKYConstantPoolValue.cpp:208
llvm::CSKYConstantPoolSymbol::print
void print(raw_ostream &O) const override
print - Implement operator<<
Definition: CSKYConstantPoolValue.cpp:148
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
Type.h
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:94
llvm::CSKYConstantPoolValue::getModifierText
const char * getModifierText() const
Definition: CSKYConstantPoolValue.cpp:35
llvm::CSKYConstantPoolValue::addSelectionDAGCSEId
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
Definition: CSKYConstantPoolValue.cpp:62
llvm::CSKYConstantPoolSymbol::Create
static CSKYConstantPoolSymbol * Create(Type *Ty, const char *S, unsigned PCAdjust, CSKYCP::CSKYCPModifier Modifier)
Definition: CSKYConstantPoolValue.cpp:132
llvm::CSKYConstantPoolConstant
CSKY-specific constant pool values for Constants, Functions, and BlockAddresses.
Definition: CSKYConstantPoolValue.h:105
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:239
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::CSKYConstantPoolValue::getExistingMachineCPValue
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
Definition: CSKYConstantPoolValue.cpp:57
llvm::MachineConstantPool
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
Definition: MachineConstantPool.h:117
llvm::CSKYConstantPoolValue
CSKYConstantPoolValue - CSKY specific constantpool value.
Definition: CSKYConstantPoolValue.h:45
llvm::CSKYCP::GOTOFF
@ GOTOFF
Definition: CSKYConstantPoolValue.h:39
llvm::CSKYConstantPoolSymbol::getExistingMachineCPValue
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
Definition: CSKYConstantPoolValue.cpp:137
llvm::CSKYCP::ADDR
@ ADDR
Definition: CSKYConstantPoolValue.h:39
llvm::CSKYConstantPoolConstant::print
void print(raw_ostream &O) const override
print - Implement operator<<
Definition: CSKYConstantPoolValue.cpp:114
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::CSKYConstantPoolMBB::Create
static CSKYConstantPoolMBB * Create(Type *Ty, const MachineBasicBlock *Mbb, unsigned PCAdjust)
Definition: CSKYConstantPoolValue.cpp:165
llvm::CSKYConstantPoolMBB::addSelectionDAGCSEId
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
Definition: CSKYConstantPoolValue.cpp:176
llvm::CSKYCP::CSKYCPKind
CSKYCPKind
Definition: CSKYConstantPoolValue.h:31
llvm::CSKYConstantPoolConstant::addSelectionDAGCSEId
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
Definition: CSKYConstantPoolValue.cpp:108
llvm::BlockAddress
The address of a basic block.
Definition: Constants.h:848
llvm::CSKYCP::TLSLE
@ TLSLE
Definition: CSKYConstantPoolValue.h:39
llvm::CSKYConstantPoolValue::PCAdjust
unsigned PCAdjust
Definition: CSKYConstantPoolValue.h:48
llvm::CSKYConstantPoolValue::LabelId
unsigned LabelId
Definition: CSKYConstantPoolValue.h:52
llvm::MachineBasicBlock::getNumber
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
Definition: MachineBasicBlock.h:1078
llvm::CSKYCP::CSKYCPModifier
CSKYCPModifier
Definition: CSKYConstantPoolValue.h:39
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::CSKYConstantPoolConstant::getExistingMachineCPValue
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
Definition: CSKYConstantPoolValue.cpp:103
llvm::FoldingSetNodeID
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:317
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::CSKYConstantPoolConstant::getBlockAddress
const BlockAddress * getBlockAddress() const
Definition: CSKYConstantPoolValue.cpp:98
llvm::Value::getName
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:305
llvm::CSKYConstantPoolValue::CSKYConstantPoolValue
CSKYConstantPoolValue(Type *Ty, CSKYCP::CSKYCPKind Kind, unsigned PCAdjust, CSKYCP::CSKYCPModifier Modifier, bool AddCurrentAddress, unsigned ID=0)
Definition: CSKYConstantPoolValue.cpp:27
FoldingSet.h
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::HexagonISD::CP
@ CP
Definition: HexagonISelLowering.h:53
llvm::CSKYConstantPoolValue::Kind
CSKYCP::CSKYCPKind Kind
Definition: CSKYConstantPoolValue.h:47
Constant.h
llvm::CSKYConstantPoolConstant::getGV
const GlobalValue * getGV() const
Definition: CSKYConstantPoolValue.cpp:93
llvm::CSKYConstantPoolValue::AddCurrentAddress
bool AddCurrentAddress
Definition: CSKYConstantPoolValue.h:50
llvm::CSKYConstantPoolSymbol
CSKYConstantPoolSymbol - CSKY-specific constantpool values for external symbols.
Definition: CSKYConstantPoolValue.h:136
llvm::CSKYConstantPoolMBB::getExistingMachineCPValue
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
Definition: CSKYConstantPoolValue.cpp:171
llvm::CSKYConstantPoolMBB
CSKYConstantPoolMBB - CSKY-specific constantpool value of a machine basic block.
Definition: CSKYConstantPoolValue.h:166
llvm::CSKYCP::TLSIE
@ TLSIE
Definition: CSKYConstantPoolValue.h:39
raw_ostream.h