42 return !(*
this ==
Other);
50 if (!UseInfo.GEP || !UseInfo.GEP->hasOneUse())
54 if (!UseInfo.Load || UseInfo.Load->isVolatile())
59 Pattern.ElemType = UseInfo.Load->getType();
60 if (!
Pattern.ElemType->isPointerTy() ||
61 DL.getPointerTypeSizeInBits(
Pattern.ElemType) != 64)
65 unsigned IndexWidth =
DL.getIndexTypeSizeInBits(UseInfo.GEP->getType());
67 APInt ConstOffset(IndexWidth, 0);
68 if (!UseInfo.GEP->collectOffset(
DL, IndexWidth, VarOffsets, ConstOffset) ||
69 !ConstOffset.
isZero() || VarOffsets.
size() != 1)
74 UseInfo.Index = VarOffsets.
front().first;
96 std::optional<AccessPattern>
Pattern;
106 else if (*
Pattern != CurPattern)
109 Uses.push_back(CurUse);
115 Triple TT = M.getTargetTriple();
117 bool ShouldDropUnnamedAddr =
126 || (TT.isX86() && TT.isOSDarwin());
131 bool HasNonPoison =
false;
139 Info.Ptrs.push_back(
C);
153 if (!GlobalVarOp || !GlobalVarOp->isConstant())
163 if (GlobalVarOp->isWeakForLinker() || !GlobalVarOp->isImplicitDSOLocal())
170 if (TT.isAArch64() &&
171 (!GlobalVarOp->hasInitializer() ||
172 GlobalVarOp->getInitializer()->needsDynamicRelocation()))
175 if (ShouldDropUnnamedAddr)
179 Info.Ptrs.push_back(
C);
185 if (ShouldDropUnnamedAddr)
186 for (
auto *GVOp : GVOps)
194 Module &M = *LookupTable.getParent();
199 M, IntArrayTy, LookupTable.isConstant(), LookupTable.getLinkage(),
200 nullptr, LookupTable.getName() +
".rel", &LookupTable,
201 LookupTable.getThreadLocalMode(), LookupTable.getAddressSpace(),
202 LookupTable.isExternallyInitialized());
204 Type *
IntPtrTy = M.getDataLayout().getIntPtrType(M.getContext());
211 for (
Constant *Element : Info.Ptrs) {
220 RelLookupTableContents[Idx++] = RelOffset;
228 return RelLookupTable;
238 Module &M = *LookupTable.getParent();
244 Builder.SetInsertPoint(UseInfo.GEP);
246 Value *
Offset = Builder.CreateShl(UseInfo.Index, ConstantInt::get(IntTy, 2),
253 Builder.SetInsertPoint(UseInfo.Load);
255 &M, Intrinsic::load_relative, {UseInfo.Index->getType()});
259 Value *Result = Builder.CreateCall(
260 LoadRelIntrinsic, {RelLookupTable,
Offset},
"reltable.intrinsic");
263 UseInfo.Load->replaceAllUsesWith(Result);
265 UseInfo.Load->eraseFromParent();
266 UseInfo.GEP->eraseFromParent();
274 if (
F.isDeclaration())
278 if (!GetTTI(
F).shouldBuildRelLookupTables())
296 GV.eraseFromParent();
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
Module.h This file contains the declarations for the Module class.
FunctionAnalysisManager FAM
static bool convertToRelativeLookupTables(Module &M, function_ref< TargetTransformInfo &(Function &)> GetTTI)
static void convertToRelLookupTable(const LookupTableInfo &Info, ArrayRef< LookupTableUse > Uses, GlobalVariable &LookupTable)
static GlobalVariable * createRelLookupTable(const LookupTableInfo &Info, GlobalVariable &LookupTable)
static bool shouldConvertToRelLookupTable(LookupTableInfo &Info, SmallVectorImpl< LookupTableUse > &Uses, Module &M, GlobalVariable &GV)
static bool analyzeLookupTableUse(AccessPattern &Pattern, LookupTableUse &UseInfo, User *Usr)
This file implements relative lookup table converter that converts lookup tables to relative lookup t...
Remove Loads Into Fake Uses
Class for arbitrary precision integers.
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
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.
static LLVM_ABI Constant * get(ArrayType *T, ArrayRef< Constant * > V)
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.
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
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.
LLVM_ABI uint64_t getGlobalSize(const DataLayout &DL) const
Get the size of this global variable in bytes.
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.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Class to represent integer types.
An instruction for reading from memory.
std::pair< KeyT, ValueT > & front()
A Module instance is used to store all the information related to an LLVM module.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
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.
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
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.
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
LLVM Value Representation.
iterator_range< user_iterator > users()
An efficient, type-erasing, non-owning reference to a callable.
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > OverloadTys={})
Look up the Function declaration of the intrinsic id in the Module M.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
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...
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
LLVM_ABI Constant * ConstantFoldLoadFromConst(Constant *C, Type *Ty, const APInt &Offset, const DataLayout &DL)
Extract value of C at the given Offset reinterpreted as Ty.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
@ Sub
Subtraction of integers.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
bool operator!=(const AccessPattern &Other) const
bool operator==(const AccessPattern &Other) const
SmallVector< Constant * > Ptrs
This struct is a compact representation of a valid (non-zero power of two) alignment.
A MapVector that performs no allocations if smaller than a certain size.