Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,28 +265,32 @@ void LoongArchAsmPrinter::emitJumpTableInfo() {

assert(TM.getTargetTriple().isOSBinFormatELF());

unsigned Size = getDataLayout().getPointerSize();
auto *LAFI = MF->getInfo<LoongArchMachineFunctionInfo>();
unsigned EntrySize = LAFI->getJumpInfoSize();
auto JTI = MF->getJumpTableInfo();

if (0 == EntrySize)
if (!JTI || 0 == EntrySize)
return;

unsigned Size = getDataLayout().getPointerSize();
auto JT = JTI->getJumpTables();

// Emit an additional section to store the correlation info as pairs of
// addresses, each pair contains the address of a jump instruction (jr) and
// the address of the jump table.
OutStreamer->switchSection(MMI->getContext().getELFSection(
".discard.tablejump_annotate", ELF::SHT_PROGBITS, 0));

for (unsigned Idx = 0; Idx < EntrySize; ++Idx) {
int JTIIdx = LAFI->getJumpInfoJTIIndex(Idx);
if (JT[JTIIdx].MBBs.empty())
continue;
OutStreamer->emitValue(
MCSymbolRefExpr::create(LAFI->getJumpInfoJrMI(Idx)->getPreInstrSymbol(),
OutContext),
Size);
OutStreamer->emitValue(
MCSymbolRefExpr::create(
GetJTISymbol(LAFI->getJumpInfoJTIMO(Idx)->getIndex()), OutContext),
Size);
MCSymbolRefExpr::create(GetJTISymbol(JTIIdx), OutContext), Size);
}
}

Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,8 @@ void LoongArchPreRAExpandPseudo::annotateTableJump(
if (MO.isJTI()) {
MBBI->setPreInstrSymbol(
*MF, MF->getContext().createNamedTempSymbol("jrtb_"));
MF->getInfo<LoongArchMachineFunctionInfo>()->setJumpInfo(&*MBBI, &MO);
MF->getInfo<LoongArchMachineFunctionInfo>()->setJumpInfo(
&*MBBI, MO.getIndex());
IsFound = true;
return;
}
Expand Down
10 changes: 4 additions & 6 deletions llvm/lib/Target/LoongArch/LoongArchMachineFunctionInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class LoongArchMachineFunctionInfo : public MachineFunctionInfo {

/// Pairs of `jr` instructions and corresponding JTI operands, used for the
/// `annotate-tablejump` option.
SmallVector<std::pair<MachineInstr *, MachineOperand *>, 4> JumpInfos;
SmallVector<std::pair<MachineInstr *, int>, 4> JumpInfos;

public:
LoongArchMachineFunctionInfo(const Function &F,
Expand Down Expand Up @@ -76,14 +76,12 @@ class LoongArchMachineFunctionInfo : public MachineFunctionInfo {
return is_contained(SExt32Registers, Reg);
}

void setJumpInfo(MachineInstr *JrMI, MachineOperand *JTIMO) {
JumpInfos.push_back(std::make_pair(JrMI, JTIMO));
void setJumpInfo(MachineInstr *JrMI, int JTIIdx) {
JumpInfos.push_back(std::make_pair(JrMI, JTIIdx));
}
unsigned getJumpInfoSize() { return JumpInfos.size(); }
MachineInstr *getJumpInfoJrMI(unsigned Idx) { return JumpInfos[Idx].first; }
MachineOperand *getJumpInfoJTIMO(unsigned Idx) {
return JumpInfos[Idx].second;
}
int getJumpInfoJTIIndex(unsigned Idx) { return JumpInfos[Idx].second; }
};

} // end namespace llvm
Expand Down