~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/lib/Transforms/IPO/InlineSimple.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
//===- InlineSimple.cpp - Code to perform simple function inlining --------===//
 
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 bottom-up inlining of functions into callees.
 
11
//
 
12
//===----------------------------------------------------------------------===//
 
13
 
 
14
#define DEBUG_TYPE "inline"
 
15
#include "llvm/CallingConv.h"
 
16
#include "llvm/Instructions.h"
 
17
#include "llvm/IntrinsicInst.h"
 
18
#include "llvm/Module.h"
 
19
#include "llvm/Type.h"
 
20
#include "llvm/Analysis/CallGraph.h"
 
21
#include "llvm/Analysis/InlineCost.h"
 
22
#include "llvm/Support/CallSite.h"
 
23
#include "llvm/Transforms/IPO.h"
 
24
#include "llvm/Transforms/IPO/InlinerPass.h"
 
25
#include "llvm/ADT/SmallPtrSet.h"
 
26
 
 
27
using namespace llvm;
 
28
 
 
29
namespace {
 
30
 
 
31
  class SimpleInliner : public Inliner {
 
32
    // Functions that are never inlined
 
33
    SmallPtrSet<const Function*, 16> NeverInline; 
 
34
    InlineCostAnalyzer CA;
 
35
  public:
 
36
    SimpleInliner() : Inliner(&ID) {}
 
37
    SimpleInliner(int Threshold) : Inliner(&ID, Threshold) {}
 
38
    static char ID; // Pass identification, replacement for typeid
 
39
    InlineCost getInlineCost(CallSite CS) {
 
40
      return CA.getInlineCost(CS, NeverInline);
 
41
    }
 
42
    float getInlineFudgeFactor(CallSite CS) {
 
43
      return CA.getInlineFudgeFactor(CS);
 
44
    }
 
45
    void resetCachedCostInfo(Function *Caller) {
 
46
      CA.resetCachedCostInfo(Caller);
 
47
    }
 
48
    virtual bool doInitialization(CallGraph &CG);
 
49
  };
 
50
}
 
51
 
 
52
char SimpleInliner::ID = 0;
 
53
static RegisterPass<SimpleInliner>
 
54
X("inline", "Function Integration/Inlining");
 
55
 
 
56
Pass *llvm::createFunctionInliningPass() { return new SimpleInliner(); }
 
57
 
 
58
Pass *llvm::createFunctionInliningPass(int Threshold) { 
 
59
  return new SimpleInliner(Threshold);
 
60
}
 
61
 
 
62
// doInitialization - Initializes the vector of functions that have been
 
63
// annotated with the noinline attribute.
 
64
bool SimpleInliner::doInitialization(CallGraph &CG) {
 
65
  
 
66
  Module &M = CG.getModule();
 
67
  
 
68
  for (Module::iterator I = M.begin(), E = M.end();
 
69
       I != E; ++I)
 
70
    if (!I->isDeclaration() && I->hasFnAttr(Attribute::NoInline))
 
71
      NeverInline.insert(I);
 
72
 
 
73
  // Get llvm.noinline
 
74
  GlobalVariable *GV = M.getNamedGlobal("llvm.noinline");
 
75
  
 
76
  if (GV == 0)
 
77
    return false;
 
78
 
 
79
  // Don't crash on invalid code
 
80
  if (!GV->hasDefinitiveInitializer())
 
81
    return false;
 
82
  
 
83
  const ConstantArray *InitList = dyn_cast<ConstantArray>(GV->getInitializer());
 
84
  
 
85
  if (InitList == 0)
 
86
    return false;
 
87
 
 
88
  // Iterate over each element and add to the NeverInline set
 
89
  for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
 
90
        
 
91
    // Get Source
 
92
    const Constant *Elt = InitList->getOperand(i);
 
93
        
 
94
    if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(Elt))
 
95
      if (CE->getOpcode() == Instruction::BitCast) 
 
96
        Elt = CE->getOperand(0);
 
97
    
 
98
    // Insert into set of functions to never inline
 
99
    if (const Function *F = dyn_cast<Function>(Elt))
 
100
      NeverInline.insert(F);
 
101
  }
 
102
  
 
103
  return false;
 
104
}
 
105