49 if (!isa<Constant>(U))
53 if (!
GEP || !
GEP->getInRangeIndex() || *
GEP->getInRangeIndex() != 1 ||
54 !isa<ConstantInt>(
GEP->getOperand(1)) ||
55 !cast<ConstantInt>(
GEP->getOperand(1))->
isZero() ||
56 !isa<ConstantInt>(
GEP->getOperand(2)))
68 std::vector<GlobalVariable *> SplitGlobals(
Init->getNumOperands());
69 for (
unsigned I = 0;
I !=
Init->getNumOperands(); ++
I) {
75 SplitGlobals[
I] = SplitGV;
78 unsigned SplitEnd = (
I ==
Init->getNumOperands() - 1)
85 uint64_t ByteOffset = cast<ConstantInt>(
86 cast<ConstantAsMetadata>(
Type->getOperand(0))->getValue())
88 if (ByteOffset < SplitBegin || ByteOffset >= SplitEnd)
95 Type->getOperand(1)}));
100 auto *
GEP = cast<GEPOperator>(U);
101 unsigned I = cast<ConstantInt>(
GEP->getOperand(2))->getZExtValue();
102 if (I >= SplitGlobals.size())
107 for (
unsigned I = 3; I !=
GEP->getNumOperands(); ++
I)
111 SplitGlobals[I]->getInitializer()->
getType(), SplitGlobals[I], Ops,
113 GEP->replaceAllUsesWith(NewGEP);
124 bool splitGlobals(
Module &M) {
132 if ((!TypeTestFunc || TypeTestFunc->
use_empty()) &&
133 (!TypeCheckedLoadFunc || TypeCheckedLoadFunc->
use_empty()))
136 bool Changed =
false;
140 Changed |= splitGlobal(GV);
150 bool runOnModule(
Module &M) {
154 return splitGlobals(M);
160 INITIALIZE_PASS(GlobalSplit,
"globalsplit",
"Global splitter",
false,
false)
161 char GlobalSplit::
ID = 0;
164 return new GlobalSplit;
168 if (!splitGlobals(M))
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
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.
void initializeGlobalSplitPass(PassRegistry &)
Like Internal, but omit from symbol table.
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
StringRef getName() const
Return a constant reference to the value's name.
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 StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
void eraseFromParent() override
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
global_iterator global_begin()
static std::string utostr(uint64_t X, bool isNeg=false)
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.
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
uint64_t getElementOffset(unsigned Idx) const
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...
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.
LLVMContext & getContext() const
All values hold a context through their type.
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 * 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.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
iterator_range< user_iterator > users()
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
PointerType * getType() const
Global values are always pointers.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
static IntegerType * getInt32Ty(LLVMContext &C)
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)
bool hasLocalLinkage() const
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.