aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-10-28 23:09:45 +0000
committerChris Lattner <sabre@nondot.org>2003-10-28 23:09:45 +0000
commitc2bcde4da07910253b24009132c1a5adc81c88fd (patch)
treed0cf1a2961ec42898ebee5a21d3b062cd6ff214a /lib/Analysis
parentdd73e9d0d589f54bfd2dadb5b23c4b1fea593659 (diff)
Fix PR62, and llvm/test/Regression/CBackend/2003-10-28-CastToPtrToStruct.ll
ConstantExpr's can use unrelated types, make sure to scan them. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9569 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r--lib/Analysis/IPA/FindUsedTypes.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/lib/Analysis/IPA/FindUsedTypes.cpp b/lib/Analysis/IPA/FindUsedTypes.cpp
index 91b599017e..db5d64c0a0 100644
--- a/lib/Analysis/IPA/FindUsedTypes.cpp
+++ b/lib/Analysis/IPA/FindUsedTypes.cpp
@@ -12,10 +12,11 @@
//===----------------------------------------------------------------------===//
#include "llvm/Analysis/FindUsedTypes.h"
-#include "llvm/Assembly/CachedWriter.h"
-#include "llvm/SymbolTable.h"
+#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Module.h"
+#include "llvm/SymbolTable.h"
+#include "llvm/Assembly/CachedWriter.h"
#include "llvm/Support/InstIterator.h"
static RegisterAnalysis<FindUsedTypes>
@@ -50,6 +51,18 @@ void FindUsedTypes::IncorporateSymbolTable(const SymbolTable &ST) {
IncorporateType(cast<Type>(I->second));
}
+void FindUsedTypes::IncorporateValue(const Value *V) {
+ IncorporateType(V->getType());
+
+ // If this is a constant, it could be using other types...
+ if (const Constant *C = dyn_cast<Constant>(V)) {
+ for (User::const_op_iterator OI = C->op_begin(), OE = C->op_end();
+ OI != OE; ++OI)
+ IncorporateValue(*OI);
+ }
+}
+
+
// run - This incorporates all types used by the specified module
//
bool FindUsedTypes::run(Module &m) {
@@ -58,8 +71,11 @@ bool FindUsedTypes::run(Module &m) {
IncorporateSymbolTable(m.getSymbolTable());
// Loop over global variables, incorporating their types
- for (Module::const_giterator I = m.gbegin(), E = m.gend(); I != E; ++I)
+ for (Module::const_giterator I = m.gbegin(), E = m.gend(); I != E; ++I) {
IncorporateType(I->getType());
+ if (I->hasInitializer())
+ IncorporateValue(I->getInitializer());
+ }
for (Module::iterator MI = m.begin(), ME = m.end(); MI != ME; ++MI) {
IncorporateType(MI->getType());
@@ -77,8 +93,7 @@ bool FindUsedTypes::run(Module &m) {
IncorporateType(Ty); // Incorporate the type of the instruction
for (User::const_op_iterator OI = I->op_begin(), OE = I->op_end();
OI != OE; ++OI)
- if ((*OI)->getType() != Ty) // Avoid set lookup in common case
- IncorporateType((*OI)->getType());// Insert inst operand types as well
+ IncorporateValue(*OI); // Insert inst operand types as well
}
}