32#define DEBUG_TYPE "ppc-merge-strings"
34STATISTIC(NumPooledStrings,
"Number of Strings Pooled");
40 cl::desc(
"Maximum Number of Strings to Pool."));
44 cl::desc(
"Minimum number of string candidates before "
45 "pooling is considered."));
53 Align LHSAlign =
LHS->getAlign().valueOrOne();
54 Align RHSAlign =
RHS->getAlign().valueOrOne();
55 if (LHSAlign > RHSAlign)
57 else if (LHSAlign < RHSAlign)
70 dyn_cast<ConstantDataSequential>(ConstLHS);
75 dyn_cast<ConstantDataSequential>(ConstRHS);
81 return LHSSize < RHSSize;
105 std::vector<GlobalVariable *> MergeableStrings;
107 Type *PooledStructType;
109 void collectCandidateConstants(
Module &M);
110 bool mergeModuleStringPool(
Module &M);
112 unsigned ElementIndex);
121 if (
auto *
I = dyn_cast<Instruction>(CurrentUser)) {
126 if (
auto *
II = dyn_cast<IntrinsicInst>(
I)) {
128 if (
II->getIntrinsicID() == Intrinsic::eh_typeid_for)
141 if (isa<GlobalValue>(CurrentUser))
145 if (!isa<Constant>(CurrentUser))
155void PPCMergeStringPool::collectCandidateConstants(
Module &M) {
164 AllUsedGlobals.
insert(UsedVCompiler.
begin(), UsedVCompiler.
end());
192 dyn_cast<ConstantDataSequential>(
Global.getInitializer());
202 if (!hasReplaceableUsers(
Global))
205 Align AlignOfGlobal =
Global.getAlign().valueOrOne();
223 MergeableStrings.push_back(&
Global);
224 if (MaxAlignment < AlignOfGlobal)
225 MaxAlignment = AlignOfGlobal;
234bool PPCMergeStringPool::mergeModuleStringPool(
Module &M) {
238 LLVM_DEBUG(
dbgs() <<
"Number of globals is: " <<
M.global_size() <<
"\n");
240 collectCandidateConstants(M);
248 std::sort(MergeableStrings.begin(), MergeableStrings.end(), CompareConstants);
270 LLVM_DEBUG(
dbgs() <<
"Constructing global variable for string pool: ");
273 Context = &
M.getContext();
274 size_t ElementIndex = 0;
283 replaceUsesWithGEP(GV, PooledGlobal, ElementIndex);
291 PooledStructType, PooledGlobal, Indices);
309void PPCMergeStringPool::replaceUsesWithGEP(
GlobalVariable *GlobalToReplace,
311 unsigned ElementIndex) {
327char PPCMergeStringPool::ID = 0;
333 return new PPCMergeStringPool();
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Module.h This file contains the declarations for the Module class.
uint64_t IntrinsicInst * II
static cl::opt< unsigned > MaxStringsPooled("ppc-max-strings-pooled", cl::Hidden, cl::init(-1), cl::desc("Maximum Number of Strings to Pool."))
static cl::opt< unsigned > MinStringsBeforePool("ppc-min-strings-before-pool", cl::Hidden, cl::init(2), cl::desc("Minimum number of string candidates before " "pooling is considered."))
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This is the interface for a SCEV-based alias analysis.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Represent the analysis usage information of a pass.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
uint64_t getElementByteSize() const
Return the size (in bytes) of each element in the array/vector.
unsigned getNumElements() const
Return the number of elements in the array or vector.
static Constant * getInBoundsGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList)
Create an "inbounds" getelementptr.
static Constant * getAnon(ArrayRef< Constant * > V, bool Packed=false)
Return an anonymous struct that has the specified elements.
This is an important base class in LLVM.
Legacy analysis pass which computes a DominatorTree.
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalObject.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ InternalLinkage
Rename collisions when linking (static functions).
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
This is an important class for using LLVM in a threaded context.
The legacy pass manager's analysis pass to compute loop information.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
virtual bool runOnModule(Module &M)=0
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
A Module instance is used to store all the information related to an LLVM module.
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
virtual bool doInitialization(Module &)
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Legacy wrapper pass to provide the SCEVAAResult object.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
The instances of the Type class are immutable: once they are created, they are never changed.
static IntegerType * getInt32Ty(LLVMContext &C)
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
iterator_range< user_iterator > users()
bool isUsedByMetadata() const
Return true if there is metadata referencing this value.
unsigned getNumUses() const
This method computes the number of uses of this Value.
void dump() const
Support for debugging, callable in GDB: V->dump()
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
ModulePass * createPPCMergeStringPoolPass()
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
@ Global
Append to llvm.global_dtors.
GlobalVariable * collectUsedGlobalVariables(const Module &M, SmallVectorImpl< GlobalValue * > &Vec, bool CompilerUsed)
Given "llvm.used" or "llvm.compiler.used" as a global name, collect the initializer elements of that ...
This struct is a compact representation of a valid (non-zero power of two) alignment.
uint64_t value() const
This is a hole in the type system and should not be abused.