[PATCH] D150138: [BOLT] Use MCInstPrinter in createRetpolineFunctionTag
Amir Ayupov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 8 16:30:48 PDT 2023
Amir updated this revision to Diff 520512.
Amir added a comment.
Update retpoline-synthetic.test
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D150138/new/
https://reviews.llvm.org/D150138
Files:
bolt/lib/Passes/RetpolineInsertion.cpp
bolt/test/runtime/X86/retpoline-synthetic.test
Index: bolt/test/runtime/X86/retpoline-synthetic.test
===================================================================
--- bolt/test/runtime/X86/retpoline-synthetic.test
+++ bolt/test/runtime/X86/retpoline-synthetic.test
@@ -20,5 +20,12 @@
RUN: llvm-objdump -d -j ".text" %t | FileCheck %s -check-prefix=CHECK-JUMP
CHECK-JUMP-NOT: jmpq *
+# Check generated retpoline stub names
+RUN: llvm-strings %t | FileCheck %s -check-prefix=CHECK-STRINGS
+CHECK-STRINGS-DAG: __retpoline_%rax_
+CHECK-STRINGS-DAG: __retpoline_mem_%rip+DATAat0x[[#]]
+CHECK-STRINGS-DAG: __retpoline_mem_%rax+0
+CHECK-STRINGS-DAG: __retpoline_mem_%r12+0+8*%rbx
+
RUN: %t 1000 3 | FileCheck %s
CHECK: 30000000
Index: bolt/lib/Passes/RetpolineInsertion.cpp
===================================================================
--- bolt/lib/Passes/RetpolineInsertion.cpp
+++ bolt/lib/Passes/RetpolineInsertion.cpp
@@ -22,6 +22,7 @@
//===----------------------------------------------------------------------===//
#include "bolt/Passes/RetpolineInsertion.h"
+#include "llvm/MC/MCInstPrinter.h"
#include "llvm/Support/raw_ostream.h"
#define DEBUG_TYPE "bolt-retpoline"
@@ -173,39 +174,45 @@
std::string createRetpolineFunctionTag(BinaryContext &BC,
const IndirectBranchInfo &BrInfo,
bool R11Available) {
- if (BrInfo.isReg())
- return "__retpoline_r" + to_string(BrInfo.BranchReg) + "_";
+ std::string Tag;
+ llvm::raw_string_ostream TagOS(Tag);
+ TagOS << "__retpoline_";
+
+ if (BrInfo.isReg()) {
+ BC.InstPrinter->printRegName(TagOS, BrInfo.BranchReg);
+ TagOS << "_";
+ TagOS.flush();
+ return Tag;
+ }
// Memory Branch
if (R11Available)
return "__retpoline_r11";
- std::string Tag = "__retpoline_mem_";
-
const IndirectBranchInfo::MemOpInfo &MemRef = BrInfo.Memory;
- std::string DispExprStr;
- if (MemRef.DispExpr) {
- llvm::raw_string_ostream Ostream(DispExprStr);
- MemRef.DispExpr->print(Ostream, BC.AsmInfo.get());
- Ostream.flush();
- }
+ TagOS << "mem_";
- Tag += MemRef.BaseRegNum != BC.MIB->getNoRegister()
- ? "r" + to_string(MemRef.BaseRegNum)
- : "";
+ if (MemRef.BaseRegNum != BC.MIB->getNoRegister())
+ BC.InstPrinter->printRegName(TagOS, MemRef.BaseRegNum);
- Tag += MemRef.DispExpr ? "+" + DispExprStr : "+" + to_string(MemRef.DispImm);
+ TagOS << "+";
+ if (MemRef.DispExpr)
+ MemRef.DispExpr->print(TagOS, BC.AsmInfo.get());
+ else
+ TagOS << MemRef.DispImm;
- Tag += MemRef.IndexRegNum != BC.MIB->getNoRegister()
- ? "+" + to_string(MemRef.ScaleImm) + "*" +
- to_string(MemRef.IndexRegNum)
- : "";
+ if (MemRef.IndexRegNum != BC.MIB->getNoRegister()) {
+ TagOS << "+" << MemRef.ScaleImm << "*";
+ BC.InstPrinter->printRegName(TagOS, MemRef.IndexRegNum);
+ }
- Tag += MemRef.SegRegNum != BC.MIB->getNoRegister()
- ? "_seg_" + to_string(MemRef.SegRegNum)
- : "";
+ if (MemRef.SegRegNum != BC.MIB->getNoRegister()) {
+ TagOS << "_seg_";
+ BC.InstPrinter->printRegName(TagOS, MemRef.SegRegNum);
+ }
+ TagOS.flush();
return Tag;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150138.520512.patch
Type: text/x-patch
Size: 3206 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230508/91d40f38/attachment.bin>
More information about the llvm-commits
mailing list