Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Transforms/IPO/InferFunctionAttrs.cpp
Line
Count
Source
1
//===- InferFunctionAttrs.cpp - Infer implicit function attributes --------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "llvm/Transforms/IPO/InferFunctionAttrs.h"
10
#include "llvm/Analysis/TargetLibraryInfo.h"
11
#include "llvm/IR/Function.h"
12
#include "llvm/IR/LLVMContext.h"
13
#include "llvm/IR/Module.h"
14
#include "llvm/Support/Debug.h"
15
#include "llvm/Support/raw_ostream.h"
16
#include "llvm/Transforms/Utils/BuildLibCalls.h"
17
using namespace llvm;
18
19
#define DEBUG_TYPE "inferattrs"
20
21
static bool inferAllPrototypeAttributes(Module &M,
22
13.5k
                                        const TargetLibraryInfo &TLI) {
23
13.5k
  bool Changed = false;
24
13.5k
25
13.5k
  for (Function &F : M.functions())
26
1.47M
    // We only infer things using the prototype and the name; we don't need
27
1.47M
    // definitions.
28
1.47M
    if (F.isDeclaration() && 
!F.hasOptNone()881k
)
29
881k
      Changed |= inferLibFuncAttributes(F, TLI);
30
13.5k
31
13.5k
  return Changed;
32
13.5k
}
33
34
PreservedAnalyses InferFunctionAttrsPass::run(Module &M,
35
183
                                              ModuleAnalysisManager &AM) {
36
183
  auto &TLI = AM.getResult<TargetLibraryAnalysis>(M);
37
183
38
183
  if (!inferAllPrototypeAttributes(M, TLI))
39
177
    // If we didn't infer anything, preserve all analyses.
40
177
    return PreservedAnalyses::all();
41
6
42
6
  // Otherwise, we may have changed fundamental function attributes, so clear
43
6
  // out all the passes.
44
6
  return PreservedAnalyses::none();
45
6
}
46
47
namespace {
48
struct InferFunctionAttrsLegacyPass : public ModulePass {
49
  static char ID; // Pass identification, replacement for typeid
50
13.4k
  InferFunctionAttrsLegacyPass() : ModulePass(ID) {
51
13.4k
    initializeInferFunctionAttrsLegacyPassPass(
52
13.4k
        *PassRegistry::getPassRegistry());
53
13.4k
  }
54
55
13.4k
  void getAnalysisUsage(AnalysisUsage &AU) const override {
56
13.4k
    AU.addRequired<TargetLibraryInfoWrapperPass>();
57
13.4k
  }
58
59
13.4k
  bool runOnModule(Module &M) override {
60
13.4k
    if (skipModule(M))
61
2
      return false;
62
13.4k
63
13.4k
    auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
64
13.4k
    return inferAllPrototypeAttributes(M, TLI);
65
13.4k
  }
66
};
67
}
68
69
char InferFunctionAttrsLegacyPass::ID = 0;
70
23.9k
INITIALIZE_PASS_BEGIN(InferFunctionAttrsLegacyPass, "inferattrs",
71
23.9k
                      "Infer set function attributes", false, false)
72
23.9k
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
73
23.9k
INITIALIZE_PASS_END(InferFunctionAttrsLegacyPass, "inferattrs",
74
                    "Infer set function attributes", false, false)
75
76
13.4k
Pass *llvm::createInferFunctionAttrsLegacyPass() {
77
13.4k
  return new InferFunctionAttrsLegacyPass();
78
13.4k
}