~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/lib/Transforms/Scalar/ConstantProp.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
//===- ConstantProp.cpp - Code to perform Simple Constant Propagation -----===//
 
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 file implements constant propagation and merging:
 
11
//
 
12
// Specifically, this:
 
13
//   * Converts instructions like "add int 1, 2" into 3
 
14
//
 
15
// Notice that:
 
16
//   * This pass has a habit of making definitions be dead.  It is a good idea
 
17
//     to run a DIE pass sometime after running this pass.
 
18
//
 
19
//===----------------------------------------------------------------------===//
 
20
 
 
21
#define DEBUG_TYPE "constprop"
 
22
#include "llvm/Transforms/Scalar.h"
 
23
#include "llvm/Analysis/ConstantFolding.h"
 
24
#include "llvm/Constant.h"
 
25
#include "llvm/Instruction.h"
 
26
#include "llvm/Pass.h"
 
27
#include "llvm/Support/InstIterator.h"
 
28
#include "llvm/ADT/Statistic.h"
 
29
#include <set>
 
30
using namespace llvm;
 
31
 
 
32
STATISTIC(NumInstKilled, "Number of instructions killed");
 
33
 
 
34
namespace {
 
35
  struct ConstantPropagation : public FunctionPass {
 
36
    static char ID; // Pass identification, replacement for typeid
 
37
    ConstantPropagation() : FunctionPass(&ID) {}
 
38
 
 
39
    bool runOnFunction(Function &F);
 
40
 
 
41
    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
 
42
      AU.setPreservesCFG();
 
43
    }
 
44
  };
 
45
}
 
46
 
 
47
char ConstantPropagation::ID = 0;
 
48
static RegisterPass<ConstantPropagation>
 
49
X("constprop", "Simple constant propagation");
 
50
 
 
51
FunctionPass *llvm::createConstantPropagationPass() {
 
52
  return new ConstantPropagation();
 
53
}
 
54
 
 
55
 
 
56
bool ConstantPropagation::runOnFunction(Function &F) {
 
57
  // Initialize the worklist to all of the instructions ready to process...
 
58
  std::set<Instruction*> WorkList;
 
59
  for(inst_iterator i = inst_begin(F), e = inst_end(F); i != e; ++i) {
 
60
      WorkList.insert(&*i);
 
61
  }
 
62
  bool Changed = false;
 
63
 
 
64
  while (!WorkList.empty()) {
 
65
    Instruction *I = *WorkList.begin();
 
66
    WorkList.erase(WorkList.begin());    // Get an element from the worklist...
 
67
 
 
68
    if (!I->use_empty())                 // Don't muck with dead instructions...
 
69
      if (Constant *C = ConstantFoldInstruction(I)) {
 
70
        // Add all of the users of this instruction to the worklist, they might
 
71
        // be constant propagatable now...
 
72
        for (Value::use_iterator UI = I->use_begin(), UE = I->use_end();
 
73
             UI != UE; ++UI)
 
74
          WorkList.insert(cast<Instruction>(*UI));
 
75
 
 
76
        // Replace all of the uses of a variable with uses of the constant.
 
77
        I->replaceAllUsesWith(C);
 
78
 
 
79
        // Remove the dead instruction.
 
80
        WorkList.erase(I);
 
81
        I->eraseFromParent();
 
82
 
 
83
        // We made a change to the function...
 
84
        Changed = true;
 
85
        ++NumInstKilled;
 
86
      }
 
87
  }
 
88
  return Changed;
 
89
}