[PATCH] D35578: Add -fswitch-tables and -fno-switch-tables flags

Sumanth Gundapaneni via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 18 14:02:22 PDT 2017


sgundapa added a comment.

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 more an array return values as opposed to an array of pointers in jump table.

The "-fno-XXX-flags" disable the generation of these tables. 
-fno-switch-tables implies both -fno-jump-tables and -fno-lookup-tables


https://reviews.llvm.org/D35578





More information about the cfe-commits mailing list