xref: /freebsd/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYConstantPoolValue.cpp (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
104eeddc0SDimitry Andric //===-- CSKYConstantPoolValue.cpp - CSKY constantpool value ---------------===//
204eeddc0SDimitry Andric //
304eeddc0SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
404eeddc0SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
504eeddc0SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
604eeddc0SDimitry Andric //
704eeddc0SDimitry Andric //===----------------------------------------------------------------------===//
804eeddc0SDimitry Andric //
904eeddc0SDimitry Andric // This file implements the CSKY specific constantpool value class.
1004eeddc0SDimitry Andric //
1104eeddc0SDimitry Andric //===----------------------------------------------------------------------===//
1204eeddc0SDimitry Andric 
1304eeddc0SDimitry Andric #include "CSKYConstantPoolValue.h"
1404eeddc0SDimitry Andric #include "llvm/ADT/FoldingSet.h"
1504eeddc0SDimitry Andric #include "llvm/CodeGen/MachineBasicBlock.h"
1604eeddc0SDimitry Andric #include "llvm/IR/Constant.h"
1704eeddc0SDimitry Andric #include "llvm/IR/Constants.h"
1804eeddc0SDimitry Andric #include "llvm/IR/GlobalValue.h"
1904eeddc0SDimitry Andric #include "llvm/IR/Type.h"
2004eeddc0SDimitry Andric #include "llvm/Support/raw_ostream.h"
2104eeddc0SDimitry Andric using namespace llvm;
2204eeddc0SDimitry Andric 
2304eeddc0SDimitry Andric //===----------------------------------------------------------------------===//
2404eeddc0SDimitry Andric // CSKYConstantPoolValue
2504eeddc0SDimitry Andric //===----------------------------------------------------------------------===//
2604eeddc0SDimitry Andric 
CSKYConstantPoolValue(Type * Ty,CSKYCP::CSKYCPKind Kind,unsigned PCAdjust,CSKYCP::CSKYCPModifier Modifier,bool AddCurrentAddress,unsigned ID)2704eeddc0SDimitry Andric CSKYConstantPoolValue::CSKYConstantPoolValue(Type *Ty, CSKYCP::CSKYCPKind Kind,
2804eeddc0SDimitry Andric                                              unsigned PCAdjust,
2904eeddc0SDimitry Andric                                              CSKYCP::CSKYCPModifier Modifier,
3004eeddc0SDimitry Andric                                              bool AddCurrentAddress,
3104eeddc0SDimitry Andric                                              unsigned ID)
3204eeddc0SDimitry Andric     : MachineConstantPoolValue(Ty), Kind(Kind), PCAdjust(PCAdjust),
3304eeddc0SDimitry Andric       Modifier(Modifier), AddCurrentAddress(AddCurrentAddress), LabelId(ID) {}
3404eeddc0SDimitry Andric 
getModifierText() const3504eeddc0SDimitry Andric const char *CSKYConstantPoolValue::getModifierText() const {
3604eeddc0SDimitry Andric   switch (Modifier) {
3704eeddc0SDimitry Andric   case CSKYCP::ADDR:
3804eeddc0SDimitry Andric     return "ADDR";
3904eeddc0SDimitry Andric   case CSKYCP::GOT:
4004eeddc0SDimitry Andric     return "GOT";
4104eeddc0SDimitry Andric   case CSKYCP::GOTOFF:
4204eeddc0SDimitry Andric     return "GOTOFF";
4304eeddc0SDimitry Andric   case CSKYCP::PLT:
4404eeddc0SDimitry Andric     return "PLT";
4504eeddc0SDimitry Andric   case CSKYCP::TLSIE:
4604eeddc0SDimitry Andric     return "TLSIE";
4704eeddc0SDimitry Andric   case CSKYCP::TLSLE:
4804eeddc0SDimitry Andric     return "TLSLE";
4904eeddc0SDimitry Andric   case CSKYCP::TLSGD:
5004eeddc0SDimitry Andric     return "TLSGD";
5104eeddc0SDimitry Andric   case CSKYCP::NO_MOD:
5204eeddc0SDimitry Andric     return "";
5304eeddc0SDimitry Andric   }
5404eeddc0SDimitry Andric   llvm_unreachable("Unknown modifier!");
5504eeddc0SDimitry Andric }
5604eeddc0SDimitry Andric 
getExistingMachineCPValue(MachineConstantPool * CP,Align Alignment)5704eeddc0SDimitry Andric int CSKYConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
5804eeddc0SDimitry Andric                                                      Align Alignment) {
5904eeddc0SDimitry Andric   llvm_unreachable("Shouldn't be calling this directly!");
6004eeddc0SDimitry Andric }
6104eeddc0SDimitry Andric 
addSelectionDAGCSEId(FoldingSetNodeID & ID)6204eeddc0SDimitry Andric void CSKYConstantPoolValue::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
6304eeddc0SDimitry Andric   ID.AddInteger(LabelId);
6404eeddc0SDimitry Andric   ID.AddInteger(PCAdjust);
6504eeddc0SDimitry Andric   ID.AddInteger(Modifier);
6604eeddc0SDimitry Andric }
6704eeddc0SDimitry Andric 
print(raw_ostream & O) const6804eeddc0SDimitry Andric void CSKYConstantPoolValue::print(raw_ostream &O) const {
6904eeddc0SDimitry Andric   if (Modifier)
7004eeddc0SDimitry Andric     O << "(" << getModifierText() << ")";
7104eeddc0SDimitry Andric   if (PCAdjust)
7204eeddc0SDimitry Andric     O << " + " << PCAdjust;
7304eeddc0SDimitry Andric }
7404eeddc0SDimitry Andric 
7504eeddc0SDimitry Andric //===----------------------------------------------------------------------===//
7604eeddc0SDimitry Andric // CSKYConstantPoolConstant
7704eeddc0SDimitry Andric //===----------------------------------------------------------------------===//
7804eeddc0SDimitry Andric 
CSKYConstantPoolConstant(const Constant * C,Type * Ty,CSKYCP::CSKYCPKind Kind,unsigned PCAdjust,CSKYCP::CSKYCPModifier Modifier,bool AddCurrentAddress,unsigned ID)7904eeddc0SDimitry Andric CSKYConstantPoolConstant::CSKYConstantPoolConstant(
80*bdd1243dSDimitry Andric     const Constant *C, Type *Ty, CSKYCP::CSKYCPKind Kind, unsigned PCAdjust,
8104eeddc0SDimitry Andric     CSKYCP::CSKYCPModifier Modifier, bool AddCurrentAddress, unsigned ID)
82*bdd1243dSDimitry Andric     : CSKYConstantPoolValue(Ty, Kind, PCAdjust, Modifier, AddCurrentAddress,
83*bdd1243dSDimitry Andric                             ID),
8404eeddc0SDimitry Andric       CVal(C) {}
8504eeddc0SDimitry Andric 
Create(const Constant * C,CSKYCP::CSKYCPKind Kind,unsigned PCAdjust,CSKYCP::CSKYCPModifier Modifier,bool AddCurrentAddress,unsigned ID)8604eeddc0SDimitry Andric CSKYConstantPoolConstant *CSKYConstantPoolConstant::Create(
8704eeddc0SDimitry Andric     const Constant *C, CSKYCP::CSKYCPKind Kind, unsigned PCAdjust,
8804eeddc0SDimitry Andric     CSKYCP::CSKYCPModifier Modifier, bool AddCurrentAddress, unsigned ID) {
89*bdd1243dSDimitry Andric   return new CSKYConstantPoolConstant(C, C->getType(), Kind, PCAdjust, Modifier,
90*bdd1243dSDimitry Andric                                       AddCurrentAddress, ID);
91*bdd1243dSDimitry Andric }
92*bdd1243dSDimitry Andric 
Create(const Constant * C,Type * Ty,CSKYCP::CSKYCPKind Kind,unsigned PCAdjust,CSKYCP::CSKYCPModifier Modifier,bool AddCurrentAddress,unsigned ID)93*bdd1243dSDimitry Andric CSKYConstantPoolConstant *CSKYConstantPoolConstant::Create(
94*bdd1243dSDimitry Andric     const Constant *C, Type *Ty, CSKYCP::CSKYCPKind Kind, unsigned PCAdjust,
95*bdd1243dSDimitry Andric     CSKYCP::CSKYCPModifier Modifier, bool AddCurrentAddress, unsigned ID) {
96*bdd1243dSDimitry Andric   return new CSKYConstantPoolConstant(C, Ty, Kind, PCAdjust, Modifier,
9704eeddc0SDimitry Andric                                       AddCurrentAddress, ID);
9804eeddc0SDimitry Andric }
9904eeddc0SDimitry Andric 
getGV() const10004eeddc0SDimitry Andric const GlobalValue *CSKYConstantPoolConstant::getGV() const {
10104eeddc0SDimitry Andric   assert(isa<GlobalValue>(CVal) && "CVal should be GlobalValue");
10204eeddc0SDimitry Andric   return cast<GlobalValue>(CVal);
10304eeddc0SDimitry Andric }
10404eeddc0SDimitry Andric 
getBlockAddress() const10504eeddc0SDimitry Andric const BlockAddress *CSKYConstantPoolConstant::getBlockAddress() const {
10604eeddc0SDimitry Andric   assert(isa<BlockAddress>(CVal) && "CVal should be BlockAddress");
10704eeddc0SDimitry Andric   return cast<BlockAddress>(CVal);
10804eeddc0SDimitry Andric }
10904eeddc0SDimitry Andric 
getConstantPool() const110*bdd1243dSDimitry Andric const Constant *CSKYConstantPoolConstant::getConstantPool() const {
111*bdd1243dSDimitry Andric   return CVal;
112*bdd1243dSDimitry Andric }
113*bdd1243dSDimitry Andric 
getExistingMachineCPValue(MachineConstantPool * CP,Align Alignment)11404eeddc0SDimitry Andric int CSKYConstantPoolConstant::getExistingMachineCPValue(MachineConstantPool *CP,
11504eeddc0SDimitry Andric                                                         Align Alignment) {
11604eeddc0SDimitry Andric   return getExistingMachineCPValueImpl<CSKYConstantPoolConstant>(CP, Alignment);
11704eeddc0SDimitry Andric }
11804eeddc0SDimitry Andric 
addSelectionDAGCSEId(FoldingSetNodeID & ID)11904eeddc0SDimitry Andric void CSKYConstantPoolConstant::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
12004eeddc0SDimitry Andric   ID.AddPointer(CVal);
12104eeddc0SDimitry Andric 
12204eeddc0SDimitry Andric   CSKYConstantPoolValue::addSelectionDAGCSEId(ID);
12304eeddc0SDimitry Andric }
12404eeddc0SDimitry Andric 
print(raw_ostream & O) const12504eeddc0SDimitry Andric void CSKYConstantPoolConstant::print(raw_ostream &O) const {
12604eeddc0SDimitry Andric   O << CVal->getName();
12704eeddc0SDimitry Andric   CSKYConstantPoolValue::print(O);
12804eeddc0SDimitry Andric }
12904eeddc0SDimitry Andric 
13004eeddc0SDimitry Andric //===----------------------------------------------------------------------===//
13104eeddc0SDimitry Andric // CSKYConstantPoolSymbol
13204eeddc0SDimitry Andric //===----------------------------------------------------------------------===//
13304eeddc0SDimitry Andric 
CSKYConstantPoolSymbol(Type * Ty,const char * S,unsigned PCAdjust,CSKYCP::CSKYCPModifier Modifier,bool AddCurrentAddress)13404eeddc0SDimitry Andric CSKYConstantPoolSymbol::CSKYConstantPoolSymbol(Type *Ty, const char *S,
13504eeddc0SDimitry Andric                                                unsigned PCAdjust,
13604eeddc0SDimitry Andric                                                CSKYCP::CSKYCPModifier Modifier,
13704eeddc0SDimitry Andric                                                bool AddCurrentAddress)
13804eeddc0SDimitry Andric     : CSKYConstantPoolValue(Ty, CSKYCP::CPExtSymbol, PCAdjust, Modifier,
13904eeddc0SDimitry Andric                             AddCurrentAddress),
14004eeddc0SDimitry Andric       S(strdup(S)) {}
14104eeddc0SDimitry Andric 
14204eeddc0SDimitry Andric CSKYConstantPoolSymbol *
Create(Type * Ty,const char * S,unsigned PCAdjust,CSKYCP::CSKYCPModifier Modifier)14304eeddc0SDimitry Andric CSKYConstantPoolSymbol::Create(Type *Ty, const char *S, unsigned PCAdjust,
14404eeddc0SDimitry Andric                                CSKYCP::CSKYCPModifier Modifier) {
14504eeddc0SDimitry Andric   return new CSKYConstantPoolSymbol(Ty, S, PCAdjust, Modifier, false);
14604eeddc0SDimitry Andric }
14704eeddc0SDimitry Andric 
getExistingMachineCPValue(MachineConstantPool * CP,Align Alignment)14804eeddc0SDimitry Andric int CSKYConstantPoolSymbol::getExistingMachineCPValue(MachineConstantPool *CP,
14904eeddc0SDimitry Andric                                                       Align Alignment) {
15004eeddc0SDimitry Andric 
15104eeddc0SDimitry Andric   return getExistingMachineCPValueImpl<CSKYConstantPoolSymbol>(CP, Alignment);
15204eeddc0SDimitry Andric }
15304eeddc0SDimitry Andric 
addSelectionDAGCSEId(FoldingSetNodeID & ID)15404eeddc0SDimitry Andric void CSKYConstantPoolSymbol::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
15504eeddc0SDimitry Andric   ID.AddString(S);
15604eeddc0SDimitry Andric   CSKYConstantPoolValue::addSelectionDAGCSEId(ID);
15704eeddc0SDimitry Andric }
15804eeddc0SDimitry Andric 
print(raw_ostream & O) const15904eeddc0SDimitry Andric void CSKYConstantPoolSymbol::print(raw_ostream &O) const {
16004eeddc0SDimitry Andric   O << S;
16104eeddc0SDimitry Andric   CSKYConstantPoolValue::print(O);
16204eeddc0SDimitry Andric }
16304eeddc0SDimitry Andric 
16404eeddc0SDimitry Andric //===----------------------------------------------------------------------===//
16504eeddc0SDimitry Andric // CSKYConstantPoolMBB
16604eeddc0SDimitry Andric //===----------------------------------------------------------------------===//
16704eeddc0SDimitry Andric 
CSKYConstantPoolMBB(Type * Ty,const MachineBasicBlock * Mbb,unsigned PCAdjust,CSKYCP::CSKYCPModifier Modifier,bool AddCurrentAddress)16804eeddc0SDimitry Andric CSKYConstantPoolMBB::CSKYConstantPoolMBB(Type *Ty, const MachineBasicBlock *Mbb,
16904eeddc0SDimitry Andric                                          unsigned PCAdjust,
17004eeddc0SDimitry Andric                                          CSKYCP::CSKYCPModifier Modifier,
17104eeddc0SDimitry Andric                                          bool AddCurrentAddress)
17204eeddc0SDimitry Andric     : CSKYConstantPoolValue(Ty, CSKYCP::CPMachineBasicBlock, PCAdjust, Modifier,
17304eeddc0SDimitry Andric                             AddCurrentAddress),
17404eeddc0SDimitry Andric       MBB(Mbb) {}
17504eeddc0SDimitry Andric 
Create(Type * Ty,const MachineBasicBlock * Mbb,unsigned PCAdjust)17604eeddc0SDimitry Andric CSKYConstantPoolMBB *CSKYConstantPoolMBB::Create(Type *Ty,
17704eeddc0SDimitry Andric                                                  const MachineBasicBlock *Mbb,
17804eeddc0SDimitry Andric                                                  unsigned PCAdjust) {
17904eeddc0SDimitry Andric   return new CSKYConstantPoolMBB(Ty, Mbb, PCAdjust, CSKYCP::ADDR, false);
18004eeddc0SDimitry Andric }
18104eeddc0SDimitry Andric 
getExistingMachineCPValue(MachineConstantPool * CP,Align Alignment)18204eeddc0SDimitry Andric int CSKYConstantPoolMBB::getExistingMachineCPValue(MachineConstantPool *CP,
18304eeddc0SDimitry Andric                                                    Align Alignment) {
18404eeddc0SDimitry Andric   return getExistingMachineCPValueImpl<CSKYConstantPoolMBB>(CP, Alignment);
18504eeddc0SDimitry Andric }
18604eeddc0SDimitry Andric 
addSelectionDAGCSEId(FoldingSetNodeID & ID)18704eeddc0SDimitry Andric void CSKYConstantPoolMBB::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
18804eeddc0SDimitry Andric   ID.AddPointer(MBB);
18904eeddc0SDimitry Andric   CSKYConstantPoolValue::addSelectionDAGCSEId(ID);
19004eeddc0SDimitry Andric }
19104eeddc0SDimitry Andric 
print(raw_ostream & O) const19204eeddc0SDimitry Andric void CSKYConstantPoolMBB::print(raw_ostream &O) const {
19304eeddc0SDimitry Andric   O << "BB#" << MBB->getNumber();
19404eeddc0SDimitry Andric   CSKYConstantPoolValue::print(O);
19504eeddc0SDimitry Andric }
19604eeddc0SDimitry Andric 
19704eeddc0SDimitry Andric //===----------------------------------------------------------------------===//
19804eeddc0SDimitry Andric // CSKYConstantPoolJT
19904eeddc0SDimitry Andric //===----------------------------------------------------------------------===//
20004eeddc0SDimitry Andric 
CSKYConstantPoolJT(Type * Ty,int JTIndex,unsigned PCAdj,CSKYCP::CSKYCPModifier Modifier,bool AddCurrentAddress)20104eeddc0SDimitry Andric CSKYConstantPoolJT::CSKYConstantPoolJT(Type *Ty, int JTIndex, unsigned PCAdj,
20204eeddc0SDimitry Andric                                        CSKYCP::CSKYCPModifier Modifier,
20304eeddc0SDimitry Andric                                        bool AddCurrentAddress)
20404eeddc0SDimitry Andric     : CSKYConstantPoolValue(Ty, CSKYCP::CPJT, PCAdj, Modifier,
20504eeddc0SDimitry Andric                             AddCurrentAddress),
20604eeddc0SDimitry Andric       JTI(JTIndex) {}
20704eeddc0SDimitry Andric 
20804eeddc0SDimitry Andric CSKYConstantPoolJT *
Create(Type * Ty,int JTI,unsigned PCAdj,CSKYCP::CSKYCPModifier Modifier)20904eeddc0SDimitry Andric CSKYConstantPoolJT::Create(Type *Ty, int JTI, unsigned PCAdj,
21004eeddc0SDimitry Andric                            CSKYCP::CSKYCPModifier Modifier) {
21104eeddc0SDimitry Andric   return new CSKYConstantPoolJT(Ty, JTI, PCAdj, Modifier, false);
21204eeddc0SDimitry Andric }
21304eeddc0SDimitry Andric 
getExistingMachineCPValue(MachineConstantPool * CP,Align Alignment)21404eeddc0SDimitry Andric int CSKYConstantPoolJT::getExistingMachineCPValue(MachineConstantPool *CP,
21504eeddc0SDimitry Andric                                                   Align Alignment) {
21604eeddc0SDimitry Andric   return getExistingMachineCPValueImpl<CSKYConstantPoolJT>(CP, Alignment);
21704eeddc0SDimitry Andric }
21804eeddc0SDimitry Andric 
addSelectionDAGCSEId(FoldingSetNodeID & ID)21904eeddc0SDimitry Andric void CSKYConstantPoolJT::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
22004eeddc0SDimitry Andric   ID.AddInteger(JTI);
22104eeddc0SDimitry Andric   CSKYConstantPoolValue::addSelectionDAGCSEId(ID);
22204eeddc0SDimitry Andric }
22304eeddc0SDimitry Andric 
print(raw_ostream & O) const22404eeddc0SDimitry Andric void CSKYConstantPoolJT::print(raw_ostream &O) const {
22504eeddc0SDimitry Andric   O << "JTI#" << JTI;
22604eeddc0SDimitry Andric   CSKYConstantPoolValue::print(O);
22704eeddc0SDimitry Andric }
228