LLVM  13.0.0git
RelLookupTableConverter.h
Go to the documentation of this file.
1 //===-- RelLookupTableConverterPass.h - Rel Table Conv ----------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 /// \file
10 /// This file implements relative lookup table converter that converts
11 /// lookup tables to relative lookup tables to make them PIC-friendly.
12 ///
13 /// Switch lookup table example:
14 /// @switch.table.foo = private unnamed_addr constant [3 x i8*]
15 /// [
16 /// i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0),
17 /// i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0),
18 /// i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
19 /// ], align 8
20 ///
21 /// switch.lookup:
22 /// %1 = sext i32 %cond to i64
23 /// %switch.gep = getelementptr inbounds [3 x i8*],
24 /// [3 x i8*]* @switch.table.foo, i64 0, i64 %1
25 /// %switch.load = load i8*, i8** %switch.gep, align 8
26 /// ret i8* %switch.load
27 ///
28 /// Switch lookup table will become a relative lookup table that
29 /// consists of relative offsets.
30 ///
31 /// @reltable.foo = private unnamed_addr constant [3 x i32]
32 /// [
33 /// i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str to i64),
34 /// i64 ptrtoint ([3 x i32]* @reltable.foo to i64)) to i32),
35 /// i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.1 to i64),
36 /// i64 ptrtoint ([3 x i32]* @reltable.foo to i64)) to i32),
37 /// i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.2 to i64),
38 /// i64 ptrtoint ([3 x i32]* @reltable.foo to i64)) to i32)
39 /// ], align 4
40 ///
41 /// IR after converting to a relative lookup table:
42 /// switch.lookup:
43 /// %1 = sext i32 %cond to i64
44 /// %reltable.shift = shl i64 %1, 2
45 /// %reltable.intrinsic = call i8* @llvm.load.relative.i64(
46 /// i8* bitcast ([3 x i32]* @reltable.foo to i8*),
47 /// i64 %reltable.shift)
48 /// ret i8* %reltable.intrinsic
49 //===----------------------------------------------------------------------===//
50 
51 #ifndef LLVM_TRANSFORMS_UTILS_RELLOOKUPTABLECONVERTER_H
52 #define LLVM_TRANSFORMS_UTILS_RELLOOKUPTABLECONVERTER_H
53 
54 #include "llvm/IR/Module.h"
55 #include "llvm/IR/PassManager.h"
56 
57 namespace llvm {
58 
59 // Pass that converts lookup tables to relative lookup tables.
61  : public PassInfoMixin<RelLookupTableConverterPass> {
62 public:
63  RelLookupTableConverterPass() = default;
64 
66 };
67 
68 } // end namespace llvm
69 
70 #endif // LLVM_TRANSFORMS_UTILS_RELLOOKUPTABLECONVERTER_H
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:155
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::RelLookupTableConverterPass::run
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Definition: RelLookupTableConverter.cpp:197
llvm::PassInfoMixin
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:374
Module.h
llvm::RelLookupTableConverterPass::RelLookupTableConverterPass
RelLookupTableConverterPass()=default
llvm::RelLookupTableConverterPass
Definition: RelLookupTableConverter.h:60
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
PassManager.h
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:44