[llvm] r340864 - [WebAssembly][NFC] Document stackifier tablegen backend

Thomas Lively via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 28 11:49:47 PDT 2018


Author: tlively
Date: Tue Aug 28 11:49:47 2018
New Revision: 340864

URL: http://llvm.org/viewvc/llvm-project?rev=340864&view=rev
Log:
[WebAssembly][NFC] Document stackifier tablegen backend

Summary:
Add comments to help readers avoid having to read tablegen backends to
understand the code. Also remove unecessary breaks from the output.

Reviewers: dschuff, aheejin

Subscribers: sbc100, jgravelle-google, sunfish, llvm-commits

Differential Revision: https://reviews.llvm.org/D51371

Modified:
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
    llvm/trunk/utils/TableGen/WebAssemblyStackifierEmitter.cpp

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp?rev=340864&r1=340863&r2=340864&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp Tue Aug 28 11:49:47 2018
@@ -285,8 +285,13 @@ static void removeRegisterOperands(const
 static unsigned regInstructionToStackInstruction(unsigned OpCode) {
   // For most opcodes, this function could have been implemented as "return
   // OpCode + 1", but since table-gen alphabetically sorts them, this cannot be
-  // guaranteed (see e.g. BR and BR_IF), so we table-gen a giant switch
-  // statement instead.
+  // guaranteed (see e.g. BR and BR_IF). Instead we use a giant switch statement
+  // generated by a custom TableGen backend (WebAssemblyStackifierEmitter.cpp)
+  // that emits switch cases of the form
+  //
+  //   case WebAssembly::RegisterInstr: return WebAssembly::StackInstr;
+  //
+  // for every pair of equivalent register and stack instructions.
   switch (OpCode) {
   default:
     llvm_unreachable(

Modified: llvm/trunk/utils/TableGen/WebAssemblyStackifierEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/WebAssemblyStackifierEmitter.cpp?rev=340864&r1=340863&r2=340864&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/WebAssemblyStackifierEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/WebAssemblyStackifierEmitter.cpp Tue Aug 28 11:49:47 2018
@@ -17,6 +17,17 @@
 
 namespace llvm {
 
+// Find all register WebAssembly instructions and their corresponding stack
+// instructions. For each pair, emit a switch case of the form
+//
+//   case WebAssembly::RegisterInstr: return WebAssembly::StackInstr;
+//
+// For example,
+//
+//   case WebAssembly::ADD_I32: return WebAssembly::ADD_I32_S;
+//
+// This is useful for converting instructions from their register form to their
+// equivalent stack form.
 void EmitWebAssemblyStackifier(RecordKeeper &RK, raw_ostream &OS) {
   Record *InstrClass = RK.getClass("WebAssemblyInst");
   for (auto &RecordPair : RK.getDefs()) {
@@ -26,7 +37,7 @@ void EmitWebAssemblyStackifier(RecordKee
     if (IsStackBased)
       continue;
     OS << "  case WebAssembly::" << RecordPair.first << ": return "
-       << "WebAssembly::" << RecordPair.first << "_S; break;\n";
+       << "WebAssembly::" << RecordPair.first << "_S;\n";
   }
 }
 




More information about the llvm-commits mailing list