[llvm] b5b79e5 - [NFC][exegesis] `BenchmarkCodeStreamer`: use existing RegNameToRegNo map
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 5 09:12:34 PST 2023
Author: Roman Lebedev
Date: 2023-01-05T20:11:56+03:00
New Revision: b5b79e51b4c7e4f59c07aa970b3cfef5bf21f5e6
URL: https://github.com/llvm/llvm-project/commit/b5b79e51b4c7e4f59c07aa970b3cfef5bf21f5e6
DIFF: https://github.com/llvm/llvm-project/commit/b5b79e51b4c7e4f59c07aa970b3cfef5bf21f5e6.diff
LOG: [NFC][exegesis] `BenchmarkCodeStreamer`: use existing RegNameToRegNo map
Added:
Modified:
llvm/tools/llvm-exegesis/lib/SnippetFile.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp b/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp
index 706c794f08a9..0b69a79b02cc 100644
--- a/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp
+++ b/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp
@@ -29,10 +29,10 @@ namespace {
// An MCStreamer that reads a BenchmarkCode definition from a file.
class BenchmarkCodeStreamer : public MCStreamer, public AsmCommentConsumer {
public:
- explicit BenchmarkCodeStreamer(MCContext *Context,
- const MCRegisterInfo *TheRegInfo,
- BenchmarkCode *Result)
- : MCStreamer(*Context), RegInfo(TheRegInfo), Result(Result) {}
+ explicit BenchmarkCodeStreamer(
+ MCContext *Context, const DenseMap<StringRef, unsigned> &RegNameToRegNo,
+ BenchmarkCode *Result)
+ : MCStreamer(*Context), RegNameToRegNo(RegNameToRegNo), Result(Result) {}
// Implementation of the MCStreamer interface. We only care about
// instructions.
@@ -99,17 +99,15 @@ class BenchmarkCodeStreamer : public MCStreamer, public AsmCommentConsumer {
Align ByteAlignment, SMLoc Loc) override {}
unsigned findRegisterByName(const StringRef RegName) const {
- // FIXME: Can we do better than this ?
- for (unsigned I = 0, E = RegInfo->getNumRegs(); I < E; ++I) {
- if (RegName == RegInfo->getName(I))
- return I;
- }
+ auto Iter = RegNameToRegNo.find(RegName);
+ if (Iter != RegNameToRegNo.end())
+ return Iter->second;
errs() << "'" << RegName
<< "' is not a valid register name for the target\n";
return 0;
}
- const MCRegisterInfo *const RegInfo;
+ const DenseMap<StringRef, unsigned> &RegNameToRegNo;
BenchmarkCode *const Result;
unsigned InvalidComments = 0;
};
@@ -137,7 +135,8 @@ Expected<std::vector<BenchmarkCode>> readSnippets(const LLVMState &State,
TM.getTarget().createMCObjectFileInfo(Context, /*PIC=*/false));
Context.setObjectFileInfo(ObjectFileInfo.get());
Context.initInlineSourceManager();
- BenchmarkCodeStreamer Streamer(&Context, TM.getMCRegisterInfo(), &Result);
+ BenchmarkCodeStreamer Streamer(&Context, State.getRegNameToRegNoMapping(),
+ &Result);
std::string Error;
raw_string_ostream ErrorStream(Error);
More information about the llvm-commits
mailing list