summaryrefslogtreecommitdiff
path: root/lib/VMCore/Module.cpp
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2012-08-03 00:30:35 +0000
committerBill Wendling <isanbard@gmail.com>2012-08-03 00:30:35 +0000
commit573e97326766359d3a9747eed7b7d47b6c33fa0f (patch)
tree673f5f53704610e9160435ff0d435e8b8e600524 /lib/VMCore/Module.cpp
parente94ac8871a1ac79bece57335d2abece0feed9c02 (diff)
downloadllvm-573e97326766359d3a9747eed7b7d47b6c33fa0f.tar.gz
llvm-573e97326766359d3a9747eed7b7d47b6c33fa0f.tar.bz2
llvm-573e97326766359d3a9747eed7b7d47b6c33fa0f.tar.xz
Move the "findUsedStructTypes" functionality outside of the Module class.
The "findUsedStructTypes" method is very expensive to run. It needs to be optimized so that LTO can run faster. Splitting this method out of the Module class will help this occur. For instance, it can keep a list of seen objects so that it doesn't process them over and over again. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161228 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Module.cpp')
-rw-r--r--lib/VMCore/Module.cpp140
1 files changed, 0 insertions, 140 deletions
diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp
index 8ea36659b8..5b5176b3c7 100644
--- a/lib/VMCore/Module.cpp
+++ b/lib/VMCore/Module.cpp
@@ -467,143 +467,3 @@ void Module::removeLibrary(StringRef Lib) {
return;
}
}
-
-//===----------------------------------------------------------------------===//
-// Type finding functionality.
-//===----------------------------------------------------------------------===//
-
-namespace {
- /// TypeFinder - Walk over a module, identifying all of the types that are
- /// used by the module.
- class TypeFinder {
- // To avoid walking constant expressions multiple times and other IR
- // objects, we keep several helper maps.
- DenseSet<const Value*> VisitedConstants;
- DenseSet<Type*> VisitedTypes;
-
- std::vector<StructType*> &StructTypes;
- bool OnlyNamed;
- public:
- TypeFinder(std::vector<StructType*> &structTypes, bool onlyNamed)
- : StructTypes(structTypes), OnlyNamed(onlyNamed) {}
-
- void run(const Module &M) {
- // Get types from global variables.
- for (Module::const_global_iterator I = M.global_begin(),
- E = M.global_end(); I != E; ++I) {
- incorporateType(I->getType());
- if (I->hasInitializer())
- incorporateValue(I->getInitializer());
- }
-
- // Get types from aliases.
- for (Module::const_alias_iterator I = M.alias_begin(),
- E = M.alias_end(); I != E; ++I) {
- incorporateType(I->getType());
- if (const Value *Aliasee = I->getAliasee())
- incorporateValue(Aliasee);
- }
-
- // Get types from functions.
- SmallVector<std::pair<unsigned, MDNode*>, 4> MDForInst;
- for (Module::const_iterator FI = M.begin(), E = M.end(); FI != E; ++FI) {
- incorporateType(FI->getType());
-
- // First incorporate the arguments.
- for (Function::const_arg_iterator AI = FI->arg_begin(),
- AE = FI->arg_end(); AI != AE; ++AI)
- incorporateValue(AI);
-
- for (Function::const_iterator BB = FI->begin(), E = FI->end();
- BB != E;++BB)
- for (BasicBlock::const_iterator II = BB->begin(),
- E = BB->end(); II != E; ++II) {
- const Instruction &I = *II;
- // Incorporate the type of the instruction.
- incorporateType(I.getType());
-
- // Incorporate non-instruction operand types. (We are incorporating
- // all instructions with this loop.)
- for (User::const_op_iterator OI = I.op_begin(), OE = I.op_end();
- OI != OE; ++OI)
- if (!isa<Instruction>(OI))
- incorporateValue(*OI);
-
- // Incorporate types hiding in metadata.
- I.getAllMetadataOtherThanDebugLoc(MDForInst);
- for (unsigned i = 0, e = MDForInst.size(); i != e; ++i)
- incorporateMDNode(MDForInst[i].second);
- MDForInst.clear();
- }
- }
-
- for (Module::const_named_metadata_iterator I = M.named_metadata_begin(),
- E = M.named_metadata_end(); I != E; ++I) {
- const NamedMDNode *NMD = I;
- for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
- incorporateMDNode(NMD->getOperand(i));
- }
- }
-
- private:
- void incorporateType(Type *Ty) {
- // Check to see if we're already visited this type.
- if (!VisitedTypes.insert(Ty).second)
- return;
-
- // If this is a structure or opaque type, add a name for the type.
- if (StructType *STy = dyn_cast<StructType>(Ty))
- if (!OnlyNamed || STy->hasName())
- StructTypes.push_back(STy);
-
- // Recursively walk all contained types.
- for (Type::subtype_iterator I = Ty->subtype_begin(),
- E = Ty->subtype_end(); I != E; ++I)
- incorporateType(*I);
- }
-
- /// incorporateValue - This method is used to walk operand lists finding
- /// types hiding in constant expressions and other operands that won't be
- /// walked in other ways. GlobalValues, basic blocks, instructions, and
- /// inst operands are all explicitly enumerated.
- void incorporateValue(const Value *V) {
- if (const MDNode *M = dyn_cast<MDNode>(V))
- return incorporateMDNode(M);
- if (!isa<Constant>(V) || isa<GlobalValue>(V)) return;
-
- // Already visited?
- if (!VisitedConstants.insert(V).second)
- return;
-
- // Check this type.
- incorporateType(V->getType());
-
- // If this is an instruction, we incorporate it separately.
- if (isa<Instruction>(V))
- return;
-
- // Look in operands for types.
- const User *U = cast<User>(V);
- for (Constant::const_op_iterator I = U->op_begin(),
- E = U->op_end(); I != E;++I)
- incorporateValue(*I);
- }
-
- void incorporateMDNode(const MDNode *V) {
-
- // Already visited?
- if (!VisitedConstants.insert(V).second)
- return;
-
- // Look in operands for types.
- for (unsigned i = 0, e = V->getNumOperands(); i != e; ++i)
- if (Value *Op = V->getOperand(i))
- incorporateValue(Op);
- }
- };
-} // end anonymous namespace
-
-void Module::findUsedStructTypes(std::vector<StructType*> &StructTypes,
- bool OnlyNamed) const {
- TypeFinder(StructTypes, OnlyNamed).run(*this);
-}