-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[Xtensa] Lower GlobalAddress/BlockAddress/JumpTable #95256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
#include "llvm/CodeGen/MachineModuleInfoImpls.h" | ||
#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h" | ||
#include "llvm/MC/MCExpr.h" | ||
#include "llvm/MC/MCInstBuilder.h" | ||
#include "llvm/MC/MCSectionELF.h" | ||
#include "llvm/MC/MCStreamer.h" | ||
#include "llvm/MC/MCSymbol.h" | ||
|
@@ -42,26 +43,48 @@ getModifierVariantKind(XtensaCP::XtensaCPModifier Modifier) { | |
} | ||
|
||
void XtensaAsmPrinter::emitInstruction(const MachineInstr *MI) { | ||
MCInst LoweredMI; | ||
lowerToMCInst(MI, LoweredMI); | ||
EmitToStreamer(*OutStreamer, LoweredMI); | ||
unsigned Opc = MI->getOpcode(); | ||
|
||
switch (Opc) { | ||
case Xtensa::BR_JT: | ||
EmitToStreamer( | ||
*OutStreamer, | ||
MCInstBuilder(Xtensa::JX).addReg(MI->getOperand(0).getReg())); | ||
return; | ||
default: | ||
MCInst LoweredMI; | ||
lowerToMCInst(MI, LoweredMI); | ||
EmitToStreamer(*OutStreamer, LoweredMI); | ||
return; | ||
} | ||
} | ||
|
||
void XtensaAsmPrinter::emitMachineConstantPoolValue( | ||
MachineConstantPoolValue *MCPV) { | ||
XtensaConstantPoolValue *ACPV = static_cast<XtensaConstantPoolValue *>(MCPV); | ||
MCSymbol *MCSym; | ||
|
||
assert(ACPV->isExtSymbol() && "unrecognized constant pool value"); | ||
|
||
XtensaConstantPoolSymbol *XtensaSym = cast<XtensaConstantPoolSymbol>(ACPV); | ||
const char *Sym = XtensaSym->getSymbol(); | ||
std::string SymName(Sym); | ||
|
||
if (XtensaSym->isPrivateLinkage()) | ||
SymName = ".L" + SymName; | ||
if (ACPV->isBlockAddress()) { | ||
const BlockAddress *BA = | ||
cast<XtensaConstantPoolConstant>(ACPV)->getBlockAddress(); | ||
MCSym = GetBlockAddressSymbol(BA); | ||
} else if (ACPV->isJumpTable()) { | ||
unsigned Idx = cast<XtensaConstantPoolJumpTable>(ACPV)->getIndex(); | ||
MCSym = this->GetJTISymbol(Idx, false); | ||
} else { | ||
assert(ACPV->isExtSymbol() && "unrecognized constant pool value"); | ||
XtensaConstantPoolSymbol *XtensaSym = cast<XtensaConstantPoolSymbol>(ACPV); | ||
const char *SymName = XtensaSym->getSymbol(); | ||
|
||
if (XtensaSym->isPrivateLinkage()) { | ||
const DataLayout &DL = getDataLayout(); | ||
MCSym = OutContext.getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) + | ||
SymName); | ||
Comment on lines
+81
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think something further down is supposed to append the prefix for you but I'm no MC expert There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've found that that "DL.getPrivateGlobalPrefix()" code returns appropriate prefix for Xtensa for private linkage case and such code is used for similar purposes in ARM backend and other backends. So, I used it to substitute hardcoded ".L" prefix. |
||
} else { | ||
MCSym = OutContext.getOrCreateSymbol(SymName); | ||
} | ||
} | ||
|
||
MCSym = GetExternalSymbolSymbol(StringRef(SymName)); | ||
MCSymbol *LblSym = GetCPISymbol(ACPV->getLabelId()); | ||
auto *TS = | ||
static_cast<XtensaTargetStreamer *>(OutStreamer->getTargetStreamer()); | ||
|
@@ -71,7 +94,7 @@ void XtensaAsmPrinter::emitMachineConstantPoolValue( | |
std::string SymName(MCSym->getName()); | ||
StringRef Modifier = ACPV->getModifierText(); | ||
SymName += Modifier; | ||
MCSym = GetExternalSymbolSymbol(StringRef(SymName)); | ||
MCSym = OutContext.getOrCreateSymbol(SymName); | ||
} | ||
|
||
const MCExpr *Expr = MCSymbolRefExpr::create(MCSym, VK, OutContext); | ||
|
@@ -140,6 +163,10 @@ XtensaAsmPrinter::GetConstantPoolIndexSymbol(const MachineOperand &MO) const { | |
return GetCPISymbol(MO.getIndex()); | ||
} | ||
|
||
MCSymbol *XtensaAsmPrinter::GetJumpTableSymbol(const MachineOperand &MO) const { | ||
return GetJTISymbol(MO.getIndex()); | ||
} | ||
|
||
MCOperand | ||
XtensaAsmPrinter::LowerSymbolOperand(const MachineOperand &MO, | ||
MachineOperand::MachineOperandType MOTy, | ||
|
@@ -152,6 +179,20 @@ XtensaAsmPrinter::LowerSymbolOperand(const MachineOperand &MO, | |
Symbol = getSymbol(MO.getGlobal()); | ||
Offset += MO.getOffset(); | ||
break; | ||
case MachineOperand::MO_MachineBasicBlock: | ||
Symbol = MO.getMBB()->getSymbol(); | ||
break; | ||
case MachineOperand::MO_BlockAddress: | ||
Symbol = GetBlockAddressSymbol(MO.getBlockAddress()); | ||
Offset += MO.getOffset(); | ||
break; | ||
case MachineOperand::MO_ExternalSymbol: | ||
Symbol = GetExternalSymbolSymbol(MO.getSymbolName()); | ||
Offset += MO.getOffset(); | ||
break; | ||
case MachineOperand::MO_JumpTableIndex: | ||
Symbol = GetJumpTableSymbol(MO); | ||
break; | ||
case MachineOperand::MO_ConstantPoolIndex: | ||
Symbol = GetConstantPoolIndexSymbol(MO); | ||
Offset += MO.getOffset(); | ||
|
@@ -191,6 +232,10 @@ MCOperand XtensaAsmPrinter::lowerOperand(const MachineOperand &MO, | |
case MachineOperand::MO_RegisterMask: | ||
break; | ||
case MachineOperand::MO_GlobalAddress: | ||
case MachineOperand::MO_MachineBasicBlock: | ||
case MachineOperand::MO_BlockAddress: | ||
case MachineOperand::MO_ExternalSymbol: | ||
case MachineOperand::MO_JumpTableIndex: | ||
case MachineOperand::MO_ConstantPoolIndex: | ||
return LowerSymbolOperand(MO, MOTy, Offset); | ||
default: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
; RUN: llc --mtriple=xtensa < %s | FileCheck %s | ||
|
||
@addr = global ptr null | ||
|
||
define void @test_blockaddress() { | ||
|
||
store volatile ptr blockaddress(@test_blockaddress, %block), ptr @addr | ||
; CHECK: .literal_position | ||
; CHECK-NEXT: .literal .LCPI0_0, addr | ||
; CHECK-NEXT: .literal .LCPI0_1, .Ltmp0 | ||
; CHECK-LABEL: test_blockaddress: | ||
; CHECK: # %bb.0: | ||
; CHECK-NEXT: l32r a8, .LCPI0_0 | ||
; CHECK-NEXT: l32r a9, .LCPI0_1 | ||
; CHECK-NEXT: s32i a9, a8, 0 | ||
; CHECK-NEXT: l32i a8, a8, 0 | ||
; CHECK-NEXT: jx a8 | ||
; CHECK-NEXT: .Ltmp0: | ||
; CHECK-NEXT: .LBB0_1: | ||
|
||
%val = load volatile ptr, ptr @addr | ||
indirectbr ptr %val, [label %block] | ||
|
||
block: | ||
ret void | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created "default" case