[PATCH] D149367: Emit the CodeView `S_ARMSWITCHTABLE` debug symbol for jump tables

Daniel Paoliello via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 17 14:05:23 PDT 2023


dpaoliello added inline comments.


================
Comment at: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp:3483
+            // and the jump table that it uses in the debug info.
+            if (MO.getType() == MachineOperand::MO_JumpTableIndex) {
+              // For label-difference jump tables, find the base expression.
----------------
efriedma wrote:
> efriedma wrote:
> > I'm concerned this could fail to find the jump table, or find the wrong jump table.  It is possible to hoist some jump-table-related operations into an earlier block.  For example:
> > 
> > ```
> >  extern "C" void f1();
> >  extern "C" void f2();
> >  extern "C" void f3();
> >  extern "C" void f4();
> >  extern "C" void f5();
> >  extern "C" void func(int i, int j){
> >    for (int k = 0; k < j; ++k) {
> >      switch (i) {
> >          case 0: f1(); break;
> >          case 1: f2(); break;
> >          case 2: f3(); break;
> >          case 3: f4(); break;
> >      }
> >    }
> >  }
> > ```
> > 
> > On AArch64, we produce:
> > 
> > ```
> > // %bb.1:
> >         mov     w19, w1
> >         mov     w20, w0
> >         mov     w21, w0
> >         adrp    x22, .LJTI0_0
> >         add     x22, x22, :lo12:.LJTI0_0
> >         b       .LBB0_4
> > .LBB0_2:                                // %sw.bb3
> >                                         //   in Loop: Header=BB0_4 Depth=1
> >         bl      f4
> > .LBB0_3:                                // %for.inc
> >                                         //   in Loop: Header=BB0_4 Depth=1
> >         subs    w19, w19, #1
> >         b.eq    .LBB0_9
> > .LBB0_4:                                // %for.body
> >                                         // =>This Inner Loop Header: Depth=1
> >         cmp     w20, #3
> >         b.hi    .LBB0_3
> > // %bb.5:                               // %for.body
> >                                         //   in Loop: Header=BB0_4 Depth=1
> >         adr     x8, .LBB0_2
> >         ldrb    w9, [x22, x21]
> >         add     x8, x8, x9, lsl #2
> >         br      x8
> > ```
> > 
> > Off the top of my head, I'm not sure how to write a testcase where it actually finds the wrong table, but I suspect it's possible.
> > 
> > We might need to encode the associated jump table into the MachineInstrs some other way.  I'm not sure what that looks like, exactly; maybe a pseudo-instruction just before the jump?
> Err, I guess on aarch64, you can pull the table out of the JumpTableDest32 instruction, which we currently don't hoist.  But on x86, we don't do jump table compression, so there's no such operand.
I've been trying to figure out how to do this, and I'm lost: I can see where the branch instructions are added, but I don't know how to create a pseudo-instruction just before them. There also seems to be DbgValues, which seems like it may be useful but I also don't understand how to create those either.

Don't suppose someone can point me to an example where someone else has done something similar?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149367/new/

https://reviews.llvm.org/D149367



More information about the llvm-commits mailing list