44 return !(*
this ==
Other);
52 if (!UseInfo.GEP || !UseInfo.GEP->hasOneUse())
56 if (!UseInfo.Load || UseInfo.Load->isVolatile())
61 Pattern.ElemType = UseInfo.Load->getType();
62 if (!
Pattern.ElemType->isPointerTy() ||
63 DL.getPointerTypeSizeInBits(
Pattern.ElemType) != 64)
67 unsigned IndexWidth =
DL.getIndexTypeSizeInBits(UseInfo.GEP->getType());
69 APInt ConstOffset(IndexWidth, 0);
70 if (!UseInfo.GEP->collectOffset(
DL, IndexWidth, VarOffsets, ConstOffset) ||
71 !ConstOffset.
isZero() || VarOffsets.
size() != 1)
76 UseInfo.Index = VarOffsets.
front().first;
100 Triple TT = M->getTargetTriple();
102 bool ShouldDropUnnamedAddr =
111 || (TT.isX86() && TT.isOSDarwin());
116 bool HasNonPoison =
false;
124 Info.Ptrs.push_back(
C);
138 if (!GlobalVarOp || !GlobalVarOp->isConstant())
148 if (GlobalVarOp->isWeakForLinker() || !GlobalVarOp->isImplicitDSOLocal())
155 if (TT.isAArch64() &&
156 (!GlobalVarOp->hasInitializer() ||
157 GlobalVarOp->getInitializer()->needsDynamicRelocation()))
160 if (ShouldDropUnnamedAddr)
161 Info.DropUnnamedAddrGVs.push_back(GlobalVarOp);
164 Info.Ptrs.push_back(
C);
172 for (
auto *GV : Info.DropUnnamedAddrGVs)
175 Module &M = *LookupTable.getParent();
180 M, IntArrayTy, LookupTable.isConstant(), LookupTable.getLinkage(),
181 nullptr, LookupTable.getName() +
".rel", &LookupTable,
182 LookupTable.getThreadLocalMode(), LookupTable.getAddressSpace(),
183 LookupTable.isExternallyInitialized());
185 Type *
IntPtrTy = M.getDataLayout().getIntPtrType(M.getContext());
192 for (
Constant *Element : Info.Ptrs) {
201 RelLookupTableContents[Idx++] = RelOffset;
209 return RelLookupTable;
218 Builder.SetInsertPoint(UseInfo.GEP);
220 Value *
Offset = Builder.CreateShl(UseInfo.Index, ConstantInt::get(IntTy, 2),
227 Builder.SetInsertPoint(UseInfo.Load);
229 M, Intrinsic::load_relative, {UseInfo.Index->getType()});
233 Value *Result = Builder.CreateCall(LoadRelIntrinsic,
234 {UseInfo.GEP->getPointerOperand(),
Offset},
235 "reltable.intrinsic");
238 UseInfo.Load->replaceAllUsesWith(Result);
240 UseInfo.Load->eraseFromParent();
241 UseInfo.GEP->eraseFromParent();
248 if (
F.isDeclaration())
252 if (!GetTTI(
F).shouldBuildRelLookupTables())
268 std::optional<AccessPattern>
Pattern;
271 Worklist.
insert(GV.user_begin(), GV.user_end());
272 for (
unsigned I = 0;
I < Worklist.
size(); ++
I) {
273 User *Usr = Worklist[
I];
284 Worklist.
insert(OpGV->user_begin(), OpGV->user_end());
297 else if (*
Pattern != CurPattern)
300 Uses.push_back(CurUse);
307 for (
auto &[GV, Info] : GVs)
316 for (
auto &[GV, Info] : GVs) {
318 GV->replaceAllUsesWith(RelLookupTable);
330 DeadGV->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 isEligibleForRelLookupTable(const GlobalVariable &GV)
static bool convertToRelativeLookupTables(Module &M, function_ref< TargetTransformInfo &(Function &)> GetTTI)
static bool analyzeLookupTable(LookupTableInfo &Info, const AccessPattern &Pattern, GlobalVariable &GV)
static GlobalVariable * createRelLookupTable(const LookupTableInfo &Info, GlobalVariable &LookupTable)
static bool analyzeLookupTableUse(AccessPattern &Pattern, LookupTableUse &UseInfo, User *Usr)
static void convertLookupTableUse(const LookupTableUse &UseInfo)
This file implements relative lookup table converter that converts lookup tables to relative lookup t...
Remove Loads Into Fake Uses
This file implements a set that has insertion order iteration characteristics.
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.
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.
LLVM_ABI const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
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
Module * getParent()
Get the module that this global value is contained inside of...
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< iterator, bool > try_emplace(const KeyT &Key, Ts &&...Args)
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)
size_type size() const
Determine the number of elements in the SetVector.
bool insert(const value_type &X)
Insert a new element into the SetVector.
A SetVector that performs no allocations if smaller than a certain size.
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.
user_iterator user_begin()
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.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
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.
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.
DWARFExpression::Operation Op
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
SmallVector< GlobalVariable * > DropUnnamedAddrGVs
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.