|
14 | 14 | //===----------------------------------------------------------------------===//
|
15 | 15 |
|
16 | 16 | #include "XtensaAsmPrinter.h"
|
| 17 | +#include "XtensaConstantPoolValue.h" |
17 | 18 | #include "TargetInfo/XtensaTargetInfo.h"
|
18 | 19 | #include "XtensaMCInstLower.h"
|
19 | 20 | #include "llvm/ADT/StringExtras.h"
|
|
30 | 31 |
|
31 | 32 | using namespace llvm;
|
32 | 33 |
|
| 34 | +static MCSymbolRefExpr::VariantKind |
| 35 | +getModifierVariantKind(XtensaCP::XtensaCPModifier Modifier) { |
| 36 | + switch (Modifier) { |
| 37 | + case XtensaCP::no_modifier: |
| 38 | + return MCSymbolRefExpr::VK_None; |
| 39 | + case XtensaCP::TPOFF: |
| 40 | + return MCSymbolRefExpr::VK_TPOFF; |
| 41 | + } |
| 42 | + report_fatal_error("Invalid XtensaCPModifier!"); |
| 43 | +} |
| 44 | + |
33 | 45 | void XtensaAsmPrinter::emitInstruction(const MachineInstr *MI) {
|
34 | 46 | XtensaMCInstLower Lower(MF->getContext(), *this);
|
35 | 47 | MCInst LoweredMI;
|
36 | 48 | Lower.lower(MI, LoweredMI);
|
37 | 49 | EmitToStreamer(*OutStreamer, LoweredMI);
|
38 | 50 | }
|
39 | 51 |
|
| 52 | +void XtensaAsmPrinter::emitMachineConstantPoolValue( |
| 53 | + MachineConstantPoolValue *MCPV) { |
| 54 | + XtensaConstantPoolValue *ACPV = static_cast<XtensaConstantPoolValue *>(MCPV); |
| 55 | + |
| 56 | + MCSymbol *MCSym; |
| 57 | + if (ACPV->isBlockAddress()) { |
| 58 | + const BlockAddress *BA = |
| 59 | + cast<XtensaConstantPoolConstant>(ACPV)->getBlockAddress(); |
| 60 | + MCSym = GetBlockAddressSymbol(BA); |
| 61 | + } else { |
| 62 | + report_fatal_error( |
| 63 | + "This constant type is not supported yet in constantpool"); |
| 64 | + } |
| 65 | + |
| 66 | + MCSymbol *LblSym = GetCPISymbol(ACPV->getLabelId()); |
| 67 | + // TODO find a better way to check whether we emit data to .s file |
| 68 | + if (OutStreamer->hasRawTextSupport()) { |
| 69 | + std::string SymName("\t.literal "); |
| 70 | + SymName += LblSym->getName(); |
| 71 | + SymName += ", "; |
| 72 | + SymName += MCSym->getName(); |
| 73 | + |
| 74 | + StringRef Modifier = ACPV->getModifierText(); |
| 75 | + SymName += Modifier; |
| 76 | + |
| 77 | + OutStreamer->emitRawText(StringRef(SymName)); |
| 78 | + } else { |
| 79 | + MCSymbolRefExpr::VariantKind VK = |
| 80 | + getModifierVariantKind(ACPV->getModifier()); |
| 81 | + |
| 82 | + if (ACPV->getModifier() != XtensaCP::no_modifier) { |
| 83 | + std::string SymName(MCSym->getName()); |
| 84 | + MCSym = GetExternalSymbolSymbol(StringRef(SymName)); |
| 85 | + } |
| 86 | + |
| 87 | + const MCExpr *Expr = MCSymbolRefExpr::create(MCSym, VK, OutContext); |
| 88 | + uint64_t Size = getDataLayout().getTypeAllocSize(ACPV->getType()); |
| 89 | + OutStreamer->emitCodeAlignment( |
| 90 | + Align(4), OutStreamer->getContext().getSubtargetInfo()); |
| 91 | + OutStreamer->emitLabel(LblSym); |
| 92 | + OutStreamer->emitValue(Expr, Size); |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +void XtensaAsmPrinter::emitMachineConstantPoolEntry( |
| 97 | + const MachineConstantPoolEntry &CPE, int i) { |
| 98 | + if (CPE.isMachineConstantPoolEntry()) { |
| 99 | + XtensaConstantPoolValue *ACPV = |
| 100 | + static_cast<XtensaConstantPoolValue *>(CPE.Val.MachineCPVal); |
| 101 | + ACPV->setLabelId(i); |
| 102 | + emitMachineConstantPoolValue(CPE.Val.MachineCPVal); |
| 103 | + } else { |
| 104 | + MCSymbol *LblSym = GetCPISymbol(i); |
| 105 | + // TODO find a better way to check whether we emit data to .s file |
| 106 | + if (OutStreamer->hasRawTextSupport()) { |
| 107 | + std::string str("\t.literal "); |
| 108 | + str += LblSym->getName(); |
| 109 | + str += ", "; |
| 110 | + const Constant *C = CPE.Val.ConstVal; |
| 111 | + |
| 112 | + if (const auto *CFP = dyn_cast<ConstantFP>(C)) { |
| 113 | + str += toString(CFP->getValueAPF().bitcastToAPInt(), 10, true); |
| 114 | + } else if (const auto *CI = dyn_cast<ConstantInt>(C)) { |
| 115 | + str += toString(CI->getValue(), 10, true); |
| 116 | + } else { |
| 117 | + report_fatal_error( |
| 118 | + "This constant type is not supported yet in constantpool"); |
| 119 | + } |
| 120 | + |
| 121 | + OutStreamer->emitRawText(StringRef(str)); |
| 122 | + } else { |
| 123 | + OutStreamer->emitCodeAlignment( |
| 124 | + Align(4), OutStreamer->getContext().getSubtargetInfo()); |
| 125 | + OutStreamer->emitLabel(LblSym); |
| 126 | + emitGlobalConstant(getDataLayout(), CPE.Val.ConstVal); |
| 127 | + } |
| 128 | + } |
| 129 | +} |
| 130 | + |
40 | 131 | /// EmitConstantPool - Print to the current output stream assembly
|
41 | 132 | /// representations of the constants in the constant pool MCP. This is
|
42 | 133 | /// used to print out constants which have been "spilled to memory" by
|
@@ -82,32 +173,7 @@ void XtensaAsmPrinter::emitConstantPool() {
|
82 | 173 | }
|
83 | 174 | }
|
84 | 175 |
|
85 |
| - if (CPE.isMachineConstantPoolEntry()) { |
86 |
| - report_fatal_error("This constantpool type is not supported yet"); |
87 |
| - } else { |
88 |
| - MCSymbol *LblSym = GetCPISymbol(i); |
89 |
| - // TODO find a better way to check whether we emit data to .s file |
90 |
| - if (OutStreamer->hasRawTextSupport()) { |
91 |
| - std::string str("\t.literal "); |
92 |
| - str += LblSym->getName(); |
93 |
| - str += ", "; |
94 |
| - const Constant *C = CPE.Val.ConstVal; |
95 |
| - |
96 |
| - if (const auto *CFP = dyn_cast<ConstantFP>(C)) { |
97 |
| - str += toString(CFP->getValueAPF().bitcastToAPInt(), 10, true); |
98 |
| - } else if (const auto *CI = dyn_cast<ConstantInt>(C)) { |
99 |
| - str += toString(CI->getValue(), 10, true); |
100 |
| - } else { |
101 |
| - report_fatal_error( |
102 |
| - "This constant type is not supported yet in constantpool"); |
103 |
| - } |
104 |
| - |
105 |
| - OutStreamer->emitRawText(StringRef(str)); |
106 |
| - } else { |
107 |
| - OutStreamer->emitLabel(LblSym); |
108 |
| - emitGlobalConstant(getDataLayout(), CPE.Val.ConstVal); |
109 |
| - } |
110 |
| - } |
| 176 | + emitMachineConstantPoolEntry(CPE, i); |
111 | 177 | }
|
112 | 178 | }
|
113 | 179 |
|
|
0 commit comments