Look up table in function section

I have legit requirement to keep the switch generated lookup table in function section.

The lookup table is being generated in SimplifyCFG pass and is treated as a global.

Is there a good way to mark these lookup tables and recognize them later to keep them in function sections.

–Sumanth

There are target hooks to suppress the generation of lookup tables, if you need that. See shouldBuildLookupTables and shouldBuildLookupTablesForConstant in TargetTransformInfo. If you need something beyond that, you’ll have to modify the transform. You can set a section on a global, but it sounds like that isn’t what you want? In terms of putting IR globals into a function, the only precedent I can think of is the arm-constant-promote transform. -Eli

Err, sorry, I meant “arm-promote-constant”; see promoteToConstantPool in ARMISelLowering.cpp.

Jump table location is configurable for the generic case too
(obviously, assuming an IR pass hasn't already made that decision for
you). The callback is
TargetLoweringObjectFile::shouldPutJumpTableInFunctionSection, and I
believe that just puts the tables at the end of a function.

It's not usually that useful though: more gadgets to exploit and in
the RISCy targets I know of you still have to address them as a
full-on global to ensure they're in range.

If at all possible, I wouldn't recommend going the ARMConstantIslands
route and putting the tables in the middle of a function. That pass is
a constant source of bugs.

Tim.

For us this is to keep the jump table/lookup table in the tightly coupled memory. For functions that are not in TCM it doesn't matter that much, but functions in TCM may suffer a long delay on loads from non-TCM. We need to be able to put both tables in the same section as the function. The hook you mentioned works for jump tables, but we need some mechanism to do the same for lookup tables.

-Krzysztof

There is differentiation between switch generated jump table and a switch generated look up table.
To be clear, I still want to generate a lookup table and put it in the function section.
As Tim mentioned, the generation and placement of jump tables can be controlled by targets but not the look up tables

--Sumanth