Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- Instrumentation.cpp - TransformUtils Infrastructure ---------------===//
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
// This file defines the common initialization infrastructure for the
10
// Instrumentation library.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "llvm/Transforms/Instrumentation.h"
15
#include "llvm-c/Initialization.h"
16
#include "llvm/ADT/Triple.h"
17
#include "llvm/IR/IntrinsicInst.h"
18
#include "llvm/IR/Module.h"
19
#include "llvm/InitializePasses.h"
20
#include "llvm/PassRegistry.h"
21
22
using namespace llvm;
23
24
/// Moves I before IP. Returns new insert point.
25
4
static BasicBlock::iterator moveBeforeInsertPoint(BasicBlock::iterator I, BasicBlock::iterator IP) {
26
4
  // If I is IP, move the insert point down.
27
4
  if (I == IP) {
28
4
    ++IP;
29
4
  } else {
30
0
    // Otherwise, move I before IP and return IP.
31
0
    I->moveBefore(&*IP);
32
0
  }
33
4
  return IP;
34
4
}
35
36
/// Instrumentation passes often insert conditional checks into entry blocks.
37
/// Call this function before splitting the entry block to move instructions
38
/// that must remain in the entry block up before the split point. Static
39
/// allocas and llvm.localescape calls, for example, must remain in the entry
40
/// block.
41
BasicBlock::iterator llvm::PrepareToSplitEntryBlock(BasicBlock &BB,
42
69
                                                    BasicBlock::iterator IP) {
43
69
  assert(&BB.getParent()->getEntryBlock() == &BB);
44
244
  for (auto I = IP, E = BB.end(); I != E; 
++I175
) {
45
175
    bool KeepInEntry = false;
46
175
    if (auto *AI = dyn_cast<AllocaInst>(I)) {
47
4
      if (AI->isStaticAlloca())
48
4
        KeepInEntry = true;
49
171
    } else if (auto *II = dyn_cast<IntrinsicInst>(I)) {
50
9
      if (II->getIntrinsicID() == llvm::Intrinsic::localescape)
51
0
        KeepInEntry = true;
52
9
    }
53
175
    if (KeepInEntry)
54
4
      IP = moveBeforeInsertPoint(I, IP);
55
175
  }
56
69
  return IP;
57
69
}
58
59
// Create a constant for Str so that we can pass it to the run-time lib.
60
GlobalVariable *llvm::createPrivateGlobalForString(Module &M, StringRef Str,
61
                                                   bool AllowMerging,
62
557
                                                   const char *NamePrefix) {
63
557
  Constant *StrConst = ConstantDataArray::getString(M.getContext(), Str);
64
557
  // We use private linkage for module-local strings. If they can be merged
65
557
  // with another one, we set the unnamed_addr attribute.
66
557
  GlobalVariable *GV =
67
557
      new GlobalVariable(M, StrConst->getType(), true,
68
557
                         GlobalValue::PrivateLinkage, StrConst, NamePrefix);
69
557
  if (AllowMerging)
70
486
    GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
71
557
  GV->setAlignment(1);  // Strings may not be merged w/o setting align 1.
72
557
  return GV;
73
557
}
74
75
Comdat *llvm::GetOrCreateFunctionComdat(Function &F, Triple &T,
76
57
                                        const std::string &ModuleId) {
77
57
  if (auto Comdat = F.getComdat()) 
return Comdat9
;
78
48
  assert(F.hasName());
79
48
  Module *M = F.getParent();
80
48
  std::string Name = F.getName();
81
48
82
48
  // Make a unique comdat name for internal linkage things on ELF. On COFF, the
83
48
  // name of the comdat group identifies the leader symbol of the comdat group.
84
48
  // The linkage of the leader symbol is considered during comdat resolution,
85
48
  // and internal symbols with the same name from different objects will not be
86
48
  // merged.
87
48
  if (T.isOSBinFormatELF() && 
F.hasLocalLinkage()35
) {
88
0
    if (ModuleId.empty())
89
0
      return nullptr;
90
0
    Name += ModuleId;
91
0
  }
92
48
93
48
  // Make a new comdat for the function. Use the "no duplicates" selection kind
94
48
  // for non-weak symbols if the object file format supports it.
95
48
  Comdat *C = M->getOrInsertComdat(Name);
96
48
  if (T.isOSBinFormatCOFF() && 
!F.isWeakForLinker()13
)
97
11
    C->setSelectionKind(Comdat::NoDuplicates);
98
48
  F.setComdat(C);
99
48
  return C;
100
48
}
101
102
/// initializeInstrumentation - Initialize all passes in the TransformUtils
103
/// library.
104
11.0k
void llvm::initializeInstrumentation(PassRegistry &Registry) {
105
11.0k
  initializeAddressSanitizerLegacyPassPass(Registry);
106
11.0k
  initializeModuleAddressSanitizerLegacyPassPass(Registry);
107
11.0k
  initializeBoundsCheckingLegacyPassPass(Registry);
108
11.0k
  initializeControlHeightReductionLegacyPassPass(Registry);
109
11.0k
  initializeGCOVProfilerLegacyPassPass(Registry);
110
11.0k
  initializePGOInstrumentationGenLegacyPassPass(Registry);
111
11.0k
  initializePGOInstrumentationUseLegacyPassPass(Registry);
112
11.0k
  initializePGOIndirectCallPromotionLegacyPassPass(Registry);
113
11.0k
  initializePGOMemOPSizeOptLegacyPassPass(Registry);
114
11.0k
  initializeInstrOrderFileLegacyPassPass(Registry);
115
11.0k
  initializeInstrProfilingLegacyPassPass(Registry);
116
11.0k
  initializeMemorySanitizerLegacyPassPass(Registry);
117
11.0k
  initializeHWAddressSanitizerLegacyPassPass(Registry);
118
11.0k
  initializeThreadSanitizerLegacyPassPass(Registry);
119
11.0k
  initializeSanitizerCoverageModulePass(Registry);
120
11.0k
  initializeDataFlowSanitizerPass(Registry);
121
11.0k
}
122
123
/// LLVMInitializeInstrumentation - C binding for
124
/// initializeInstrumentation.
125
0
void LLVMInitializeInstrumentation(LLVMPassRegistryRef R) {
126
0
  initializeInstrumentation(*unwrap(R));
127
0
}