[llvm-dev] Instruction selection for 'load' based on static vs. dynamic data

Dr. ERDI Gergo via llvm-dev llvm-dev at lists.llvm.org
Tue May 9 04:51:29 PDT 2017


On Mon, 8 May 2017, Krzysztof Parzyszek via llvm-dev wrote:

> You can create the differentiation between objects in the data memory and in 
> the program memory in LowerGlobalAddress (e.g. you can create different ISD 
> opcodes that generate these addresses) and then use those to select 
> corresponding instructions.

Right, which is how I also understand Zhai Xiang's suggestion with the 
link to existing AVR target code. This is already done to some extent, 
since the AVR backend already inserts an AVRISD::WRAPPER node to mark the 
static data's address.

However, what's still missing with that plan is how to propagate that 
information "upwards". By the time it gets to instruction selection, the 
`getelementptr` is already expanded into some arithmetic expression of a 
base address and some arbitrary offset calculations.

So for example, with this code:

%switch.gep = getelementptr inbounds [15 x i8], [15 x i8]* @switch.table, i16 0, i16 %2
%switch.load = load i8, i8* %switch.gep, align 1

by instrucion selection time, the argument to 'load' is

(add
   (sign_extend (CopyFromReg %vreg2))
   (WRAPPER TargetGlobalAddress<@switch.table>))

not a WRAPPER directly.


More information about the llvm-dev mailing list