LLVM 20.0.0git
Classes | Namespaces
RelLookupTableConverter.h File Reference

This file implements relative lookup table converter that converts lookup tables to relative lookup tables to make them PIC-friendly. More...

#include "llvm/IR/PassManager.h"

Go to the source code of this file.

Classes

class  llvm::RelLookupTableConverterPass
 

Namespaces

namespace  llvm
 This is an optimization pass for GlobalISel generic memory operations.
 

Detailed Description

This file implements relative lookup table converter that converts lookup tables to relative lookup tables to make them PIC-friendly.

Switch lookup table example: @switch.table.foo = private unnamed_addr constant [3 x i8*] [ i8* getelementptr inbounds ([5 x i8], [5 x i8]* .str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* .str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* .str.2, i64 0, i64 0) ], align 8

switch.lookup: %1 = sext i32 cond to i64 switch.gep = getelementptr inbounds [3 x i8*], [3 x i8*]* @switch.table.foo, i64 0, i64 %1 switch.load = load i8*, i8** switch.gep, align 8 ret i8* switch.load

Switch lookup table will become a relative lookup table that consists of relative offsets.

@reltable.foo = private unnamed_addr constant [3 x i32] [ i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* .str to i64), i64 ptrtoint ([3 x i32]* @reltable.foo to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* .str.1 to i64), i64 ptrtoint ([3 x i32]* @reltable.foo to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* .str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.foo to i64)) to i32) ], align 4

IR after converting to a relative lookup table: switch.lookup: %1 = sext i32 cond to i64 reltable.shift = shl i64 %1, 2 reltable.intrinsic = call i8* @llvm.load.relative.i64( i8* bitcast ([3 x i32]* @reltable.foo to i8*), i64 reltable.shift) ret i8* reltable.intrinsic

Definition in file RelLookupTableConverter.h.