[PATCH] D35578: Add -fswitch-tables and -fno-switch-tables flags
Chad Rosier via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 18 14:20:48 PDT 2017
mcrosier added a comment.
In https://reviews.llvm.org/D35578#813548, @sgundapa wrote:
> The switch-case statements generate two kinds of tables.
>
> 1. Jump tables
> 2. Lookup tables.
>
> While the general assumption is that switch-case statements generate jump tables, the below case generates a lookup table by late simplifycfg
>
> int foo(int x) { switch (x) { case 0: return 9; case 1: return 20; case 2: return 14; case 3: return 22; case 4: return 12; default: return 19; } } generates a @switch.table.foo = private unnamed_addr constant [5 x i32] [i32 9, i32 20, i32 14, i32 22, i32 12] The lookup table is an array of return values as opposed to an array of pointers in jump table.
IIRC, we lower switches to a combination of binaries trees, jump tables and some bitmagic when there are 3 or fewer cases in the subtree. Somewhat beside the point, but just a bit of clarification... ...but before lowering the switch, simplifycfg may come along and introduce a lookup table if the cases are returning a constant value.
> The "-fno-XXX-flags" disable the generation of these tables.
> -fno-switch-tables implies both -fno-jump-tables and -fno-lookup-tables
Okay, now I understand the differences between the flags.
What exactly is the motivation? I'm trying to narrow down the justification for adding yet more flags.
https://reviews.llvm.org/D35578
More information about the cfe-commits
mailing list