Lines Matching +full:lookup +full:- +full:table
1 //===- RelLookupTableConverterPass - Rel Table Conv -----------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements relative lookup table converter that converts
10 // lookup tables to relative lookup tables to make them PIC-friendly.
12 //===----------------------------------------------------------------------===//
25 // If lookup table has more than one user,
26 // do not generate a relative lookup table.
28 // TODO: Add support for lookup tables with multiple uses.
29 // For ex, this can happen when a function that uses a lookup table gets
37 dyn_cast<GetElementPtrInst>(GV.use_begin()->getUser());
38 if (!GEP || !GEP->hasOneUse() ||
39 GV.getValueType() != GEP->getSourceElementType())
42 LoadInst *Load = dyn_cast<LoadInst>(GEP->use_begin()->getUser());
43 if (!Load || !Load->hasOneUse() ||
44 Load->getType() != GEP->getResultElementType())
47 // If the original lookup table does not have local linkage and is
48 // not dso_local, do not generate a relative lookup table.
49 // This optimization creates a relative lookup table that consists of
50 // offsets between the start of the lookup table and its elements.
51 // To be able to generate these offsets, relative lookup table and
63 // If values are not 64-bit pointers, do not generate a relative lookup table.
65 Type *ElemType = Array->getType()->getElementType();
66 if (!ElemType->isPointerTy() || DL.getPointerTypeSizeInBits(ElemType) != 64)
69 for (const Use &Op : Array->operands()) {
74 // If an operand is not a constant offset from a lookup table,
75 // do not generate a relative lookup table.
79 // If operand is mutable, do not generate a relative lookup table.
81 if (!GlovalVarOp || !GlovalVarOp->isConstant())
84 if (!GlovalVarOp->hasLocalLinkage() ||
85 !GlovalVarOp->isDSOLocal() ||
86 !GlovalVarOp->isImplicitDSOLocal())
98 unsigned NumElts = LookupTableArr->getType()->getNumElements();
111 for (Use &Operand : LookupTableArr->operands()) {
124 RelLookupTable->setInitializer(Initializer);
125 RelLookupTable->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
126 RelLookupTable->setAlignment(llvm::Align(4));
132 cast<GetElementPtrInst>(LookupTable.use_begin()->getUser());
133 LoadInst *Load = cast<LoadInst>(GEP->use_begin()->getUser());
136 BasicBlock *BB = GEP->getParent();
138 Function &Func = *BB->getParent();
145 Value *Index = GEP->getOperand(2);
146 IntegerType *IntTy = cast<IntegerType>(Index->getType());
155 &M, Intrinsic::load_relative, {Index->getType()});
158 // by adding base address (lookup table address) and relative offset.
163 Load->replaceAllUsesWith(Result);
165 Load->eraseFromParent();
166 GEP->eraseFromParent();
169 // Convert lookup tables to relative lookup tables in the module.
176 // Check if we have a target that supports relative lookup tables.
192 // Remove the original lookup table.
206 auto GetTTI = [&](Function &F) -> TargetTransformInfo & {