Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/Transforms/IPO/InferFunctionAttrs.cpp
Line
Count
Source
1
//===- InferFunctionAttrs.cpp - Infer implicit function attributes --------===//
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
#include "llvm/Transforms/IPO/InferFunctionAttrs.h"
11
#include "llvm/Analysis/MemoryBuiltins.h"
12
#include "llvm/Analysis/TargetLibraryInfo.h"
13
#include "llvm/IR/Function.h"
14
#include "llvm/IR/LLVMContext.h"
15
#include "llvm/IR/Module.h"
16
#include "llvm/Support/Debug.h"
17
#include "llvm/Support/raw_ostream.h"
18
#include "llvm/Transforms/Utils/BuildLibCalls.h"
19
using namespace llvm;
20
21
#define DEBUG_TYPE "inferattrs"
22
23
static bool inferAllPrototypeAttributes(Module &M,
24
17.5k
                                        const TargetLibraryInfo &TLI) {
25
17.5k
  bool Changed = false;
26
17.5k
27
17.5k
  for (Function &F : M.functions())
28
17.5k
    // We only infer things using the prototype and the name; we don't need
29
17.5k
    // definitions.
30
2.41M
    
if (2.41M
F.isDeclaration() && 2.41M
!F.hasFnAttribute((Attribute::OptimizeNone))1.65M
)
31
1.65M
      Changed |= inferLibFuncAttributes(F, TLI);
32
17.5k
33
17.5k
  return Changed;
34
17.5k
}
35
36
PreservedAnalyses InferFunctionAttrsPass::run(Module &M,
37
62
                                              ModuleAnalysisManager &AM) {
38
62
  auto &TLI = AM.getResult<TargetLibraryAnalysis>(M);
39
62
40
62
  if (!inferAllPrototypeAttributes(M, TLI))
41
62
    // If we didn't infer anything, preserve all analyses.
42
60
    return PreservedAnalyses::all();
43
2
44
2
  // Otherwise, we may have changed fundamental function attributes, so clear
45
2
  // out all the passes.
46
2
  return PreservedAnalyses::none();
47
2
}
48
49
namespace {
50
struct InferFunctionAttrsLegacyPass : public ModulePass {
51
  static char ID; // Pass identification, replacement for typeid
52
17.4k
  InferFunctionAttrsLegacyPass() : ModulePass(ID) {
53
17.4k
    initializeInferFunctionAttrsLegacyPassPass(
54
17.4k
        *PassRegistry::getPassRegistry());
55
17.4k
  }
56
57
17.4k
  void getAnalysisUsage(AnalysisUsage &AU) const override {
58
17.4k
    AU.addRequired<TargetLibraryInfoWrapperPass>();
59
17.4k
  }
60
61
17.4k
  bool runOnModule(Module &M) override {
62
17.4k
    if (skipModule(M))
63
2
      return false;
64
17.4k
65
17.4k
    auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
66
17.4k
    return inferAllPrototypeAttributes(M, TLI);
67
17.4k
  }
68
};
69
}
70
71
char InferFunctionAttrsLegacyPass::ID = 0;
72
25.1k
INITIALIZE_PASS_BEGIN25.1k
(InferFunctionAttrsLegacyPass, "inferattrs",
73
25.1k
                      "Infer set function attributes", false, false)
74
25.1k
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
75
25.1k
INITIALIZE_PASS_END(InferFunctionAttrsLegacyPass, "inferattrs",
76
                    "Infer set function attributes", false, false)
77
78
17.4k
Pass *llvm::createInferFunctionAttrsLegacyPass() {
79
17.4k
  return new InferFunctionAttrsLegacyPass();
80
17.4k
}