Skip to content

Commit

Permalink
[BOLT] Provide generic implementations for isLoad/isStore
Browse files Browse the repository at this point in the history
`MCInstrDesc` provides the `mayLoad` and `mayStore` flags that seem
appropriate to use as a target-independent way to implement `isLoad` and
`isStore`.

I believe this is currently good enough to use for the RISC-V target as
well. I've provided a test for this that checks the generated dyno
stats (which seems to be the only thing both `isLoad` and `isStore` are
used for).

Reviewed By: maksfb

Differential Revision: https://reviews.llvm.org/D159266
  • Loading branch information
mtvec committed Sep 1, 2023
1 parent 9f53354 commit 76f040b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 2 additions & 4 deletions bolt/include/bolt/Core/MCPlusBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -614,13 +614,11 @@ class MCPlusBuilder {
virtual bool isMoveMem2Reg(const MCInst &Inst) const { return false; }

virtual bool isLoad(const MCInst &Inst) const {
llvm_unreachable("not implemented");
return false;
return Info->get(Inst.getOpcode()).mayLoad();
}

virtual bool isStore(const MCInst &Inst) const {
llvm_unreachable("not implemented");
return false;
return Info->get(Inst.getOpcode()).mayStore();
}

virtual bool isCleanRegXOR(const MCInst &Inst) const {
Expand Down
16 changes: 16 additions & 0 deletions bolt/test/RISCV/load-store.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %clang %cflags -o %t %s
// RUN: link_fdata --no-lbr %s %t %t.fdata
// RUN: llvm-bolt %t -o /dev/null --data=%t.fdata --dyno-stats | FileCheck %s

// CHECK: BOLT-INFO: program-wide dynostats after all optimizations before SCTC and FOP (no change):
// CHECK: 3000 : executed instructions
// CHECK: 1000 : executed load instructions
// CHECK: 1000 : executed store instructions

.globl _start
_start:
# FDATA: 1 _start #_start# 1
ld t0, (gp)
sd t0, (gp)
ret
.size _start, .-_start

0 comments on commit 76f040b

Please sign in to comment.