57 if (!isa<Constant>(U))
61 if (!
GEP || !
GEP->getInRangeIndex() || *
GEP->getInRangeIndex() != 1 ||
62 !isa<ConstantInt>(
GEP->getOperand(1)) ||
63 !cast<ConstantInt>(
GEP->getOperand(1))->
isZero() ||
64 !isa<ConstantInt>(
GEP->getOperand(2)))
76 std::vector<GlobalVariable *> SplitGlobals(
Init->getNumOperands());
77 for (
unsigned I = 0;
I !=
Init->getNumOperands(); ++
I) {
83 SplitGlobals[
I] = SplitGV;
86 unsigned SplitEnd = (
I ==
Init->getNumOperands() - 1)
93 uint64_t ByteOffset = cast<ConstantInt>(
94 cast<ConstantAsMetadata>(
Type->getOperand(0))->getValue())
104 uint64_t AttachedTo = (ByteOffset == 0) ? ByteOffset : ByteOffset - 1;
105 if (AttachedTo < SplitBegin || AttachedTo >= SplitEnd)
107 SplitGV->addMetadata(
112 Type->getOperand(1)}));
117 auto *
GEP = cast<GEPOperator>(U);
118 unsigned I = cast<ConstantInt>(
GEP->getOperand(2))->getZExtValue();
119 if (I >= SplitGlobals.size())
124 for (
unsigned I = 3; I !=
GEP->getNumOperands(); ++
I)
130 GEP->replaceAllUsesWith(NewGEP);
149 if ((!TypeTestFunc || TypeTestFunc->
use_empty()) &&
150 (!TypeCheckedLoadFunc || TypeCheckedLoadFunc->
use_empty()))
153 bool Changed =
false;
171 bool runOnModule(
Module &M)
override {
183 INITIALIZE_PASS(GlobalSplit,
"globalsplit",
"Global splitter",
false,
false)
186 return new GlobalSplit;
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
A parsed version of the target data layout string in and methods for querying it. ...
bool hasLocalLinkage() const
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant *> IdxList, bool InBounds=false, Optional< unsigned > InRangeIndex=None, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
void push_back(const T &Elt)
void initializeGlobalSplitPass(PassRegistry &)
Like Internal, but omit from symbol table.
LLVMContext & getContext() const
All values hold a context through their type.
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
static bool splitGlobals(Module &M)
global_iterator global_begin()
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
A set of analyses that are preserved following a run of a transformation pass.
The instances of the Type class are immutable: once they are created, they are never changed...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
Class to represent integer types.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
static wasm::ValType getType(const TargetRegisterClass *RC)
ModulePass * createGlobalSplitPass()
This pass splits globals into pieces for the benefit of whole-program devirtualization and control-fl...
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
global_iterator global_end()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
uint64_t getSizeInBytes() const
static Constant * getInitializer(Constant *C)
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
std::string utostr(uint64_t X, bool isNeg=false)
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
iterator_range< user_iterator > users()
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
uint64_t getElementOffset(unsigned Idx) const
static IntegerType * getInt32Ty(LLVMContext &C)
StringRef getName() const
Return a constant reference to the value's name.
static bool splitGlobal(GlobalVariable &GV)
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Module * getParent()
Get the module that this global value is contained inside of...
A container for analyses that lazily runs them and caches their results.
PointerType * getType() const
Global values are always pointers.