37 dyn_cast<GetElementPtrInst>(GV.
use_begin()->getUser());
38 if (!
GEP || !
GEP->hasOneUse() ||
42 LoadInst *Load = dyn_cast<LoadInst>(
GEP->use_begin()->getUser());
43 if (!Load || !Load->hasOneUse() ||
44 Load->getType() !=
GEP->getResultElementType())
65 Type *ElemType = Array->getType()->getElementType();
66 if (!ElemType->
isPointerTy() ||
DL.getPointerTypeSizeInBits(ElemType) != 64)
70 Triple TT = M.getTargetTriple();
72 bool ShouldDropUnnamedAddr =
81 || (TT.isX86() && TT.isOSDarwin());
83 for (
const Use &
Op : Array->operands()) {
94 auto *GlovalVarOp = dyn_cast<GlobalVariable>(GVOp);
95 if (!GlovalVarOp || !GlovalVarOp->isConstant())
98 if (!GlovalVarOp->hasLocalLinkage() ||
99 !GlovalVarOp->isDSOLocal() ||
100 !GlovalVarOp->isImplicitDSOLocal())
103 if (ShouldDropUnnamedAddr)
107 if (ShouldDropUnnamedAddr)
108 for (
auto *GVOp : GVOps)
109 GVOp->setUnnamedAddr(GlobalValue::UnnamedAddr::None);
116 Module &M = *Func.getParent();
118 cast<ConstantArray>(LookupTable.getInitializer());
124 M, IntArrayTy, LookupTable.isConstant(), LookupTable.getLinkage(),
125 nullptr, LookupTable.getName() +
".rel", &LookupTable,
126 LookupTable.getThreadLocalMode(), LookupTable.getAddressSpace(),
127 LookupTable.isExternallyInitialized());
133 Constant *Element = cast<Constant>(Operand);
134 Type *IntPtrTy = M.getDataLayout().getIntPtrType(M.getContext());
140 RelLookupTableContents[
Idx++] = RelOffset;
148 return RelLookupTable;
153 cast<GetElementPtrInst>(LookupTable.use_begin()->getUser());
154 LoadInst *Load = cast<LoadInst>(
GEP->use_begin()->getUser());
156 Module &M = *LookupTable.getParent();
167 IntegerType *IntTy = cast<IntegerType>(Index->getType());
169 Builder.
CreateShl(Index, ConstantInt::get(IntTy, 2),
"reltable.shift");
176 &M, Intrinsic::load_relative, {Index->getType()});
181 "reltable.intrinsic");
184 Load->replaceAllUsesWith(Result);
186 Load->eraseFromParent();
187 GEP->eraseFromParent();
194 if (
F.isDeclaration())
198 if (!GetTTI(
F).shouldBuildRelLookupTables())
205 bool Changed =
false;
214 GV.eraseFromParent();
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Module.h This file contains the declarations for the Module class.
FunctionAnalysisManager FAM
static bool shouldConvertToRelLookupTable(Module &M, GlobalVariable &GV)
static void convertToRelLookupTable(GlobalVariable &LookupTable)
static bool convertToRelativeLookupTables(Module &M, function_ref< TargetTransformInfo &(Function &)> GetTTI)
static GlobalVariable * createRelLookupTable(Function &Func, GlobalVariable &LookupTable)
This file implements relative lookup table converter that converts lookup tables to relative lookup t...
Class for arbitrary precision integers.
A container for analyses that lazily runs them and caches their results.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
uint64_t getNumElements() const
LLVM Basic Block Representation.
const Function * getParent() const
Return the enclosing method, or null if none.
Represents analyses that only rely on functions' control flow.
ConstantArray - Constant Array Declarations.
static LLVM_ABI Constant * get(ArrayType *T, ArrayRef< Constant * > V)
ArrayType * getType() const
Specialize the getType() method to always return an ArrayType, which reduces the amount of casting ne...
static LLVM_ABI Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static LLVM_ABI Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static LLVM_ABI Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
This is an important base class in LLVM.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
bool isImplicitDSOLocal() const
void setUnnamedAddr(UnnamedAddr Val)
bool hasLocalLinkage() const
Type * getValueType() const
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
LLVM_ABI void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
bool hasInitializer() const
Definitions have initializers, declarations don't.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalVariable.
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Class to represent integer types.
An instruction for reading from memory.
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Analysis pass providing the TargetTransformInfo.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isPointerTy() const
True if this is an instance of PointerType.
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
bool hasOneUse() const
Return true if there is exactly one use of this value.
An efficient, type-erasing, non-owning reference to a callable.
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > Tys={})
Look up the Function declaration of the intrinsic id in the Module M.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI bool IsConstantOffsetFromGlobal(Constant *C, GlobalValue *&GV, APInt &Offset, const DataLayout &DL, DSOLocalEquivalent **DSOEquiv=nullptr)
If this constant is a constant offset from a global, return the global and the constant.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
@ Sub
Subtraction of integers.
This struct is a compact representation of a valid (non-zero power of two) alignment.