~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/lib/Analysis/IPA/FindUsedTypes.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-03-12 11:30:04 UTC
  • mfrom: (0.41.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100312113004-b0fop4bkycszdd0z
Tags: 0.96~rc1+dfsg-0ubuntu1
* New upstream RC - FFE (LP: #537636):
  - Add OfficialDatabaseOnly option to clamav-base.postinst.in
  - Add LocalSocketGroup option to clamav-base.postinst.in
  - Add LocalSocketMode option to clamav-base.postinst.in
  - Add CrossFilesystems option to clamav-base.postinst.in
  - Add ClamukoScannerCount option to clamav-base.postinst.in
  - Add BytecodeSecurity opiton to clamav-base.postinst.in
  - Add DetectionStatsHostID option to clamav-freshclam.postinst.in
  - Add Bytecode option to clamav-freshclam.postinst.in
  - Add MilterSocketGroup option to clamav-milter.postinst.in
  - Add MilterSocketMode option to clamav-milter.postinst.in
  - Add ReportHostname option to clamav-milter.postinst.in
  - Bump libclamav SO version to 6.1.0 in libclamav6.install
  - Drop clamdmon from clamav.examples (no longer shipped by upstream)
  - Drop libclamav.a from libclamav-dev.install (not built by upstream)
  - Update SO version for lintian override for libclamav6
  - Add new Bytecode Testing Tool, usr/bin/clambc, to clamav.install
  - Add build-depends on python and python-setuptools for new test suite
  - Update debian/copyright for the embedded copy of llvm (using the system
    llvm is not currently feasible)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//===- FindUsedTypes.cpp - Find all Types used by a module ----------------===//
 
2
//
 
3
//                     The LLVM Compiler Infrastructure
 
4
//
 
5
// This file is distributed under the University of Illinois Open Source
 
6
// License. See LICENSE.TXT for details.
 
7
//
 
8
//===----------------------------------------------------------------------===//
 
9
//
 
10
// This pass is used to seek out all of the types in use by the program.  Note
 
11
// that this analysis explicitly does not include types only used by the symbol
 
12
// table.
 
13
//
 
14
//===----------------------------------------------------------------------===//
 
15
 
 
16
#include "llvm/Analysis/FindUsedTypes.h"
 
17
#include "llvm/Constants.h"
 
18
#include "llvm/DerivedTypes.h"
 
19
#include "llvm/Module.h"
 
20
#include "llvm/Assembly/Writer.h"
 
21
#include "llvm/Support/InstIterator.h"
 
22
#include "llvm/Support/raw_ostream.h"
 
23
using namespace llvm;
 
24
 
 
25
char FindUsedTypes::ID = 0;
 
26
static RegisterPass<FindUsedTypes>
 
27
X("print-used-types", "Find Used Types", false, true);
 
28
 
 
29
// IncorporateType - Incorporate one type and all of its subtypes into the
 
30
// collection of used types.
 
31
//
 
32
void FindUsedTypes::IncorporateType(const Type *Ty) {
 
33
  // If ty doesn't already exist in the used types map, add it now, otherwise
 
34
  // return.
 
35
  if (!UsedTypes.insert(Ty).second) return;  // Already contain Ty.
 
36
 
 
37
  // Make sure to add any types this type references now.
 
38
  //
 
39
  for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end();
 
40
       I != E; ++I)
 
41
    IncorporateType(*I);
 
42
}
 
43
 
 
44
void FindUsedTypes::IncorporateValue(const Value *V) {
 
45
  IncorporateType(V->getType());
 
46
 
 
47
  // If this is a constant, it could be using other types...
 
48
  if (const Constant *C = dyn_cast<Constant>(V)) {
 
49
    if (!isa<GlobalValue>(C))
 
50
      for (User::const_op_iterator OI = C->op_begin(), OE = C->op_end();
 
51
           OI != OE; ++OI)
 
52
        IncorporateValue(*OI);
 
53
  }
 
54
}
 
55
 
 
56
 
 
57
// run - This incorporates all types used by the specified module
 
58
//
 
59
bool FindUsedTypes::runOnModule(Module &m) {
 
60
  UsedTypes.clear();  // reset if run multiple times...
 
61
 
 
62
  // Loop over global variables, incorporating their types
 
63
  for (Module::const_global_iterator I = m.global_begin(), E = m.global_end();
 
64
       I != E; ++I) {
 
65
    IncorporateType(I->getType());
 
66
    if (I->hasInitializer())
 
67
      IncorporateValue(I->getInitializer());
 
68
  }
 
69
 
 
70
  for (Module::iterator MI = m.begin(), ME = m.end(); MI != ME; ++MI) {
 
71
    IncorporateType(MI->getType());
 
72
    const Function &F = *MI;
 
73
 
 
74
    // Loop over all of the instructions in the function, adding their return
 
75
    // type as well as the types of their operands.
 
76
    //
 
77
    for (const_inst_iterator II = inst_begin(F), IE = inst_end(F);
 
78
         II != IE; ++II) {
 
79
      const Instruction &I = *II;
 
80
 
 
81
      IncorporateType(I.getType());  // Incorporate the type of the instruction
 
82
      for (User::const_op_iterator OI = I.op_begin(), OE = I.op_end();
 
83
           OI != OE; ++OI)
 
84
        IncorporateValue(*OI);  // Insert inst operand types as well
 
85
    }
 
86
  }
 
87
 
 
88
  return false;
 
89
}
 
90
 
 
91
// Print the types found in the module.  If the optional Module parameter is
 
92
// passed in, then the types are printed symbolically if possible, using the
 
93
// symbol table from the module.
 
94
//
 
95
void FindUsedTypes::print(raw_ostream &OS, const Module *M) const {
 
96
  OS << "Types in use by this module:\n";
 
97
  for (std::set<const Type *>::const_iterator I = UsedTypes.begin(),
 
98
       E = UsedTypes.end(); I != E; ++I) {
 
99
    OS << "   ";
 
100
    WriteTypeSymbolic(OS, *I, M);
 
101
    OS << '\n';
 
102
  }
 
103
}