[PATCH] D153343: [BOLT][RISCV] Fix implementation of getTargetSymbol
Job Noorman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 20 06:54:35 PDT 2023
jobnoorman created this revision.
jobnoorman added reviewers: rafauler, maksfb, yota9, Amir.
Herald added subscribers: asb, luke, treapster, pmatos, ayermolo, VincentWu, vkmr, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, arichardson.
Herald added a project: All.
jobnoorman requested review of this revision.
Herald added subscribers: llvm-commits, wangpc, eopXD, MaskRay.
Herald added a project: LLVM.
- Correctly handle OpNum == 0 (auto select operand)
- Implement MCExpr overload
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D153343
Files:
bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp
Index: bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp
===================================================================
--- bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp
+++ bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp
@@ -79,23 +79,9 @@
"Invalid instruction");
unsigned SymOpIndex;
-
- switch (Inst.getOpcode()) {
- default:
- llvm_unreachable("not implemented");
- case RISCV::C_J:
- SymOpIndex = 0;
- break;
- case RISCV::JAL:
- case RISCV::C_BEQZ:
- case RISCV::C_BNEZ:
- SymOpIndex = 1;
- break;
- case RISCV::BEQ:
- case RISCV::BGE:
- SymOpIndex = 2;
- break;
- }
+ auto Result = getSymbolRefOperandNum(Inst, SymOpIndex);
+ (void)Result;
+ assert(Result && "unimplemented branch");
Inst.getOperand(SymOpIndex) = MCOperand::createExpr(
MCSymbolRefExpr::create(TBB, MCSymbolRefExpr::VK_None, *Ctx));
@@ -206,8 +192,50 @@
return true;
}
+ bool getSymbolRefOperandNum(const MCInst &Inst, unsigned &OpNum) const {
+ switch (Inst.getOpcode()) {
+ default:
+ return false;
+ case RISCV::C_J:
+ OpNum = 0;
+ return true;
+ case RISCV::JAL:
+ case RISCV::C_BEQZ:
+ case RISCV::C_BNEZ:
+ OpNum = 1;
+ return true;
+ case RISCV::BEQ:
+ case RISCV::BGE:
+ case RISCV::BGEU:
+ case RISCV::BNE:
+ case RISCV::BLT:
+ case RISCV::BLTU:
+ OpNum = 2;
+ return true;
+ }
+ }
+
+ const MCSymbol *getTargetSymbol(const MCExpr *Expr) const override {
+ auto *RISCVExpr = dyn_cast<RISCVMCExpr>(Expr);
+ if (RISCVExpr && RISCVExpr->getSubExpr())
+ return getTargetSymbol(RISCVExpr->getSubExpr());
+
+ auto *BinExpr = dyn_cast<MCBinaryExpr>(Expr);
+ if (BinExpr)
+ return getTargetSymbol(BinExpr->getLHS());
+
+ auto *SymExpr = dyn_cast<MCSymbolRefExpr>(Expr);
+ if (SymExpr && SymExpr->getKind() == MCSymbolRefExpr::VK_None)
+ return &SymExpr->getSymbol();
+
+ return nullptr;
+ }
+
const MCSymbol *getTargetSymbol(const MCInst &Inst,
unsigned OpNum = 0) const override {
+ if (!OpNum && !getSymbolRefOperandNum(Inst, OpNum))
+ return nullptr;
+
const MCOperand &Op = Inst.getOperand(OpNum);
if (!Op.isExpr())
return nullptr;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153343.532906.patch
Type: text/x-patch
Size: 2300 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230620/0d820b32/attachment.bin>
More information about the llvm-commits
mailing list