summaryrefslogtreecommitdiffstats
path: root/llvm/utils
diff options
context:
space:
mode:
authorWouter van Oortmerssen <aardappel@gmail.com>2019-02-05 01:19:45 +0000
committerWouter van Oortmerssen <aardappel@gmail.com>2019-02-05 01:19:45 +0000
commit1a91cb0402270a3ce77a9397abda655384d89a43 (patch)
treec55a16056aad9f18a9e8fde3934cac4409cf9a63 /llvm/utils
parent60731071dedd20ca77e2f53d17b148e25d3bf489 (diff)
downloadbcm5719-llvm-1a91cb0402270a3ce77a9397abda655384d89a43.tar.gz
bcm5719-llvm-1a91cb0402270a3ce77a9397abda655384d89a43.zip
[WebAssembly] Make disassembler always emit most canonical name.
Summary: There are a few instructions that all map to the same opcode, so when disassembling, we have to pick one. That was just the first one before (the except_ref variant in the case of "call"), now it is the one marked as IsCanonical in tablegen, or failing that, the shortest name (which is typically the "canonical" one). Also introduced a canonical "end" instruction for this purpose. Reviewers: dschuff, tlively Subscribers: sbc100, jgravelle-google, aheejin, llvm-commits, sunfish Tags: #llvm Differential Revision: https://reviews.llvm.org/D57713 llvm-svn: 353131
Diffstat (limited to 'llvm/utils')
-rw-r--r--llvm/utils/TableGen/WebAssemblyDisassemblerEmitter.cpp31
1 files changed, 26 insertions, 5 deletions
diff --git a/llvm/utils/TableGen/WebAssemblyDisassemblerEmitter.cpp b/llvm/utils/TableGen/WebAssemblyDisassemblerEmitter.cpp
index 249be3b1b95..9f5ae70f836 100644
--- a/llvm/utils/TableGen/WebAssemblyDisassemblerEmitter.cpp
+++ b/llvm/utils/TableGen/WebAssemblyDisassemblerEmitter.cpp
@@ -50,12 +50,33 @@ void emitWebAssemblyDisassemblerTables(
auto IsStackBased =
StackString &&
reinterpret_cast<const StringInit *>(StackString)->getValue() == "true";
- if (IsStackBased && !CGIP.second) {
- // this picks the first of many typed variants, which is
- // currently the except_ref one, though this shouldn't matter for
- // disassembly purposes.
- CGIP = std::make_pair(I, &CGI);
+ if (!IsStackBased)
+ continue;
+ if (CGIP.second) {
+ // We already have an instruction for this slot, so decide which one
+ // should be the canonical one. This determines which variant gets
+ // printed in a disassembly. We want e.g. "call" not "i32.call", and
+ // "end" when we don't know if its "end_loop" or "end_block" etc.
+ auto IsCanonicalExisting = CGIP.second->TheDef->getValue("IsCanonical")
+ ->getValue()
+ ->getAsString() == "1";
+ // We already have one marked explicitly as canonical, so keep it.
+ if (IsCanonicalExisting)
+ continue;
+ auto IsCanonicalNew =
+ Def.getValue("IsCanonical")->getValue()->getAsString() == "1";
+ // If the new one is explicitly marked as canonical, take it.
+ if (!IsCanonicalNew) {
+ // Neither the existing or new instruction is canonical.
+ // Pick the one with with the shortest name as heuristic.
+ // Though ideally IsCanonical is always defined for at least one
+ // variant so this never has to apply.
+ if (CGIP.second->AsmString.size() <= CGI.AsmString.size())
+ continue;
+ }
}
+ // Set this instruction as the one to use.
+ CGIP = std::make_pair(I, &CGI);
}
OS << "#include \"MCTargetDesc/WebAssemblyMCTargetDesc.h\"\n";
OS << "\n";
OpenPOWER on IntegriCloud