[PATCH] D71137: [RFC][mips][llvm-exegesis] Fix missing TargetStreamer in the Streamer for reading snippets

Miloš Stojanović via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 6 11:38:02 PST 2019


mstojanovic created this revision.
mstojanovic added reviewers: courbet, gchatelet, atanasyan, petarj.
Herald added subscribers: tschuett, hiraditya, arichardson, sdardis.
Herald added a project: LLVM.

To extract instructions from custom code snippets, `llvm-exegesis` creates a minimal parser in `readSnippets()`. The parser doesn't initialize the `TargetStreamer` because it's not used on X86 (and most other architectures) but the `MipsAsmParser` assumes that it is initialized which creates a problem when extending the implementation.

One solution could be to add the initialization of the `TargetStreamer`, but the functions that can be used for that usually create arch specific streamers like `MipsTargetELFStreamer` which (again, unlike most other architectures) needs an Assembler which isn't initialized. Since the `BenchmarkStreamer` only inherits the `MCStreamer` it's unclear what type of reorganization would be needed to accommodate additional information like the Assembler.

Another solution, submitted here, is to check whether `TargetStreamer` returns a null reference (which AFAIK isn't allowed by definition but still happens) from the Mips side and skip accessing it. This might miss edge cases or future uses where the `TargetStreamer` is erroneously missing but it works for this case. The `TargetStreamer` is usally used in cases where some additional instructions need to be emitted, but since the tool is only reading the snippets most of the code should be skipped, so there shouldn't be problems with not initilizing variables like `TOut`. This is just a basic patch which enables running exegesis with an empty file: `llvm-exegesis -mode latency -snippets-file=/dev/null` or a file containing simple instructions. To be able to run this for `DIV` for example, `TOut` in `expandDivRem()` would have to adapted in a similar way, and so on for other instructions. A possible improvement of this solution could be to use `dyn_cast` to determine the origin of the Streamer instead of assuming that it's from exegesis if the `TargetStreamer` isn't initialized. This would requires `dyn_cast` to be implemented for streamers which it currently isn't.

These are some ideas that don't constitute a perfect solution so I hope you can help me get a clearer insight into how to a better one might look like.


https://reviews.llvm.org/D71137

Files:
  llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71137.232607.patch
Type: text/x-patch
Size: 4732 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191206/10a86f46/attachment.bin>


More information about the llvm-commits mailing list