~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/lib/Transforms/Scalar/GEPSplitter.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
//===- GEPSplitter.cpp - Split complex GEPs into simple ones --------------===//
 
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 function breaks GEPs with more than 2 non-zero operands into smaller
 
11
// GEPs each with no more than 2 non-zero operands. This exposes redundancy
 
12
// between GEPs with common initial operand sequences.
 
13
//
 
14
//===----------------------------------------------------------------------===//
 
15
 
 
16
#define DEBUG_TYPE "split-geps"
 
17
#include "llvm/Transforms/Scalar.h"
 
18
#include "llvm/Constants.h"
 
19
#include "llvm/Function.h"
 
20
#include "llvm/Instructions.h"
 
21
#include "llvm/Pass.h"
 
22
using namespace llvm;
 
23
 
 
24
namespace {
 
25
  class GEPSplitter : public FunctionPass {
 
26
    virtual bool runOnFunction(Function &F);
 
27
    virtual void getAnalysisUsage(AnalysisUsage &AU) const;
 
28
  public:
 
29
    static char ID; // Pass identification, replacement for typeid
 
30
    explicit GEPSplitter() : FunctionPass(&ID) {}
 
31
  };
 
32
}
 
33
 
 
34
char GEPSplitter::ID = 0;
 
35
static RegisterPass<GEPSplitter> X("split-geps",
 
36
                                   "split complex GEPs into simple GEPs");
 
37
 
 
38
FunctionPass *llvm::createGEPSplitterPass() {
 
39
  return new GEPSplitter();
 
40
}
 
41
 
 
42
bool GEPSplitter::runOnFunction(Function &F) {
 
43
  bool Changed = false;
 
44
 
 
45
  // Visit each GEP instruction.
 
46
  for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
 
47
    for (BasicBlock::iterator II = I->begin(), IE = I->end(); II != IE; )
 
48
      if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(II++)) {
 
49
        unsigned NumOps = GEP->getNumOperands();
 
50
        // Ignore GEPs which are already simple.
 
51
        if (NumOps <= 2)
 
52
          continue;
 
53
        bool FirstIndexIsZero = isa<ConstantInt>(GEP->getOperand(1)) &&
 
54
                                cast<ConstantInt>(GEP->getOperand(1))->isZero();
 
55
        if (NumOps == 3 && FirstIndexIsZero)
 
56
          continue;
 
57
        // The first index is special and gets expanded with a 2-operand GEP
 
58
        // (unless it's zero, in which case we can skip this).
 
59
        Value *NewGEP = FirstIndexIsZero ?
 
60
          GEP->getOperand(0) :
 
61
          GetElementPtrInst::Create(GEP->getOperand(0), GEP->getOperand(1),
 
62
                                    "tmp", GEP);
 
63
        // All remaining indices get expanded with a 3-operand GEP with zero
 
64
        // as the second operand.
 
65
        Value *Idxs[2];
 
66
        Idxs[0] = ConstantInt::get(Type::getInt64Ty(F.getContext()), 0);
 
67
        for (unsigned i = 2; i != NumOps; ++i) {
 
68
          Idxs[1] = GEP->getOperand(i);
 
69
          NewGEP = GetElementPtrInst::Create(NewGEP, Idxs, Idxs+2, "tmp", GEP);
 
70
        }
 
71
        GEP->replaceAllUsesWith(NewGEP);
 
72
        GEP->eraseFromParent();
 
73
        Changed = true;
 
74
      }
 
75
 
 
76
  return Changed;
 
77
}
 
78
 
 
79
void GEPSplitter::getAnalysisUsage(AnalysisUsage &AU) const {
 
80
  AU.setPreservesCFG();
 
81
}