brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.5 KiB · 4e53aa5 Raw
208 lines · cpp
1//===- XtensaConstantPoolValue.cpp - Xtensa 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-exception6//7//===----------------------------------------------------------------------===//8//9// This file implements the Xtensa specific constantpool value class.10//11//===----------------------------------------------------------------------===//12 13#include "XtensaConstantPoolValue.h"14#include "llvm/ADT/FoldingSet.h"15#include "llvm/CodeGen/MachineBasicBlock.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"20#include "llvm/Support/raw_ostream.h"21#include <cstdlib>22using namespace llvm;23 24XtensaConstantPoolValue::XtensaConstantPoolValue(25    Type *Ty, unsigned ID, XtensaCP::XtensaCPKind Kind,26    XtensaCP::XtensaCPModifier modifier)27    : MachineConstantPoolValue(Ty), LabelId(ID), Kind(Kind),28      Modifier(modifier) {}29 30XtensaConstantPoolValue::XtensaConstantPoolValue(31    LLVMContext &C, unsigned ID, XtensaCP::XtensaCPKind Kind,32    XtensaCP::XtensaCPModifier Modifier)33    : MachineConstantPoolValue((Type *)Type::getInt32Ty(C)), LabelId(ID),34      Kind(Kind), Modifier(Modifier) {}35 36XtensaConstantPoolValue::~XtensaConstantPoolValue() {}37 38StringRef XtensaConstantPoolValue::getModifierText() const {39  switch (Modifier) {40  case XtensaCP::no_modifier:41    return "";42  case XtensaCP::TPOFF:43    return "@TPOFF";44  }45  report_fatal_error("Unknown modifier!");46}47 48int XtensaConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,49                                                       Align Alignment) {50  report_fatal_error("Shouldn't be calling this directly!");51}52 53void XtensaConstantPoolValue::addSelectionDAGCSEId(FoldingSetNodeID &ID) {54  ID.AddInteger(LabelId);55}56 57bool XtensaConstantPoolValue::hasSameValue(XtensaConstantPoolValue *ACPV) {58  if (ACPV->Kind == Kind) {59    if (ACPV->LabelId == LabelId)60      return true;61  }62  return false;63}64 65#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)66void XtensaConstantPoolValue::dump() const { errs() << "  " << *this; }67#endif68 69void XtensaConstantPoolValue::print(raw_ostream &O) const {}70 71//===----------------------------------------------------------------------===//72// XtensaConstantPoolConstant73//===----------------------------------------------------------------------===//74 75XtensaConstantPoolConstant::XtensaConstantPoolConstant(76    const Constant *C, unsigned ID, XtensaCP::XtensaCPKind Kind)77    : XtensaConstantPoolValue(C->getType(), ID, Kind), CVal(C) {}78 79XtensaConstantPoolConstant *80XtensaConstantPoolConstant::Create(const Constant *C, unsigned ID,81                                   XtensaCP::XtensaCPKind Kind) {82  return new XtensaConstantPoolConstant(C, ID, Kind);83}84 85const BlockAddress *XtensaConstantPoolConstant::getBlockAddress() const {86  return dyn_cast_or_null<BlockAddress>(CVal);87}88 89int XtensaConstantPoolConstant::getExistingMachineCPValue(90    MachineConstantPool *CP, Align Alignment) {91  return getExistingMachineCPValueImpl<XtensaConstantPoolConstant>(CP,92                                                                   Alignment);93}94 95bool XtensaConstantPoolConstant::hasSameValue(XtensaConstantPoolValue *ACPV) {96  const XtensaConstantPoolConstant *ACPC =97      dyn_cast<XtensaConstantPoolConstant>(ACPV);98  return ACPC && ACPC->CVal == CVal &&99         XtensaConstantPoolValue::hasSameValue(ACPV);100}101 102void XtensaConstantPoolConstant::addSelectionDAGCSEId(FoldingSetNodeID &ID) {103  ID.AddPointer(CVal);104  XtensaConstantPoolValue::addSelectionDAGCSEId(ID);105}106 107void XtensaConstantPoolConstant::print(raw_ostream &O) const {108  O << CVal->getName();109  XtensaConstantPoolValue::print(O);110}111 112XtensaConstantPoolSymbol::XtensaConstantPoolSymbol(113    LLVMContext &C, const char *Str, unsigned ID, bool PrivLinkage,114    XtensaCP::XtensaCPModifier Modifier)115    : XtensaConstantPoolValue(C, ID, XtensaCP::CPExtSymbol, Modifier), S(Str),116      PrivateLinkage(PrivLinkage) {}117 118XtensaConstantPoolSymbol *119XtensaConstantPoolSymbol::Create(LLVMContext &C, const char *Str, unsigned ID,120                                 bool PrivLinkage,121                                 XtensaCP::XtensaCPModifier Modifier)122 123{124  return new XtensaConstantPoolSymbol(C, Str, ID, PrivLinkage, Modifier);125}126 127int XtensaConstantPoolSymbol::getExistingMachineCPValue(MachineConstantPool *CP,128                                                        Align Alignment) {129  return getExistingMachineCPValueImpl<XtensaConstantPoolSymbol>(CP, Alignment);130}131 132bool XtensaConstantPoolSymbol::hasSameValue(XtensaConstantPoolValue *ACPV) {133  const XtensaConstantPoolSymbol *ACPS =134      dyn_cast<XtensaConstantPoolSymbol>(ACPV);135  return ACPS && ACPS->S == S && XtensaConstantPoolValue::hasSameValue(ACPV);136}137 138void XtensaConstantPoolSymbol::addSelectionDAGCSEId(FoldingSetNodeID &ID) {139  ID.AddString(S);140  XtensaConstantPoolValue::addSelectionDAGCSEId(ID);141}142 143void XtensaConstantPoolSymbol::print(raw_ostream &O) const {144  O << S;145  XtensaConstantPoolValue::print(O);146}147 148XtensaConstantPoolMBB::XtensaConstantPoolMBB(LLVMContext &C,149                                             const MachineBasicBlock *M,150                                             unsigned Id)151    : XtensaConstantPoolValue(C, 0, XtensaCP::CPMachineBasicBlock), MBB(M) {}152 153XtensaConstantPoolMBB *XtensaConstantPoolMBB::Create(LLVMContext &C,154                                                     const MachineBasicBlock *M,155                                                     unsigned Idx) {156  return new XtensaConstantPoolMBB(C, M, Idx);157}158 159int XtensaConstantPoolMBB::getExistingMachineCPValue(MachineConstantPool *CP,160                                                     Align Alignment) {161  return getExistingMachineCPValueImpl<XtensaConstantPoolMBB>(CP, Alignment);162}163 164bool XtensaConstantPoolMBB::hasSameValue(XtensaConstantPoolValue *ACPV) {165  const XtensaConstantPoolMBB *ACPMBB = dyn_cast<XtensaConstantPoolMBB>(ACPV);166  return ACPMBB && ACPMBB->MBB == MBB &&167         XtensaConstantPoolValue::hasSameValue(ACPV);168}169 170void XtensaConstantPoolMBB::addSelectionDAGCSEId(FoldingSetNodeID &ID) {171  ID.AddPointer(MBB);172  XtensaConstantPoolValue::addSelectionDAGCSEId(ID);173}174 175void XtensaConstantPoolMBB::print(raw_ostream &O) const {176  O << "BB#" << MBB->getNumber();177  XtensaConstantPoolValue::print(O);178}179 180XtensaConstantPoolJumpTable::XtensaConstantPoolJumpTable(LLVMContext &C,181                                                         unsigned Index)182    : XtensaConstantPoolValue(C, 0, XtensaCP::CPJumpTable), Idx(Index) {}183 184XtensaConstantPoolJumpTable *XtensaConstantPoolJumpTable::Create(LLVMContext &C,185                                                                 unsigned Idx) {186  return new XtensaConstantPoolJumpTable(C, Idx);187}188 189int XtensaConstantPoolJumpTable::getExistingMachineCPValue(190    MachineConstantPool *CP, Align Alignment) {191  return getExistingMachineCPValueImpl<XtensaConstantPoolJumpTable>(CP,192                                                                    Alignment);193}194 195bool XtensaConstantPoolJumpTable::hasSameValue(XtensaConstantPoolValue *ACPV) {196  const XtensaConstantPoolJumpTable *ACPJT =197      dyn_cast<XtensaConstantPoolJumpTable>(ACPV);198  return ACPJT && ACPJT->Idx == Idx &&199         XtensaConstantPoolValue::hasSameValue(ACPV);200}201 202void XtensaConstantPoolJumpTable::addSelectionDAGCSEId(FoldingSetNodeID &ID) {}203 204void XtensaConstantPoolJumpTable::print(raw_ostream &O) const {205  O << "JT" << Idx;206  XtensaConstantPoolValue::print(O);207}208