LLVM  13.0.0git
Instrumentation.cpp
Go to the documentation of this file.
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 
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.
26  // If I is IP, move the insert point down.
27  if (I == IP) {
28  ++IP;
29  } else {
30  // Otherwise, move I before IP and return IP.
31  I->moveBefore(&*IP);
32  }
33  return IP;
34 }
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.
43  assert(&BB.getParent()->getEntryBlock() == &BB);
44  for (auto I = IP, E = BB.end(); I != E; ++I) {
45  bool KeepInEntry = false;
46  if (auto *AI = dyn_cast<AllocaInst>(I)) {
47  if (AI->isStaticAlloca())
48  KeepInEntry = true;
49  } else if (auto *II = dyn_cast<IntrinsicInst>(I)) {
50  if (II->getIntrinsicID() == llvm::Intrinsic::localescape)
51  KeepInEntry = true;
52  }
53  if (KeepInEntry)
55  }
56  return IP;
57 }
58 
59 // Create a constant for Str so that we can pass it to the run-time lib.
61  bool AllowMerging,
62  const char *NamePrefix) {
63  Constant *StrConst = ConstantDataArray::getString(M.getContext(), Str);
64  // We use private linkage for module-local strings. If they can be merged
65  // with another one, we set the unnamed_addr attribute.
66  GlobalVariable *GV =
67  new GlobalVariable(M, StrConst->getType(), true,
68  GlobalValue::PrivateLinkage, StrConst, NamePrefix);
69  if (AllowMerging)
71  GV->setAlignment(Align(1)); // Strings may not be merged w/o setting
72  // alignment explicitly.
73  return GV;
74 }
75 
77  if (auto Comdat = F.getComdat()) return Comdat;
78  assert(F.hasName());
79  Module *M = F.getParent();
80 
81  // Make a new comdat for the function. Use the "no duplicates" selection kind
82  // if the object file format supports it. For COFF we restrict it to non-weak
83  // symbols.
84  Comdat *C = M->getOrInsertComdat(F.getName());
85  if (T.isOSBinFormatELF() || (T.isOSBinFormatCOFF() && !F.isWeakForLinker()))
86  C->setSelectionKind(Comdat::NoDuplicates);
87  F.setComdat(C);
88  return C;
89 }
90 
91 /// initializeInstrumentation - Initialize all passes in the TransformUtils
92 /// library.
113 }
114 
115 /// LLVMInitializeInstrumentation - C binding for
116 /// initializeInstrumentation.
119 }
Instrumentation.h
llvm::initializeMemProfilerLegacyPassPass
void initializeMemProfilerLegacyPassPass(PassRegistry &)
llvm::createPrivateGlobalForString
GlobalVariable * createPrivateGlobalForString(Module &M, StringRef Str, bool AllowMerging, const char *NamePrefix="")
Definition: Instrumentation.cpp:60
moveBeforeInsertPoint
static BasicBlock::iterator moveBeforeInsertPoint(BasicBlock::iterator I, BasicBlock::iterator IP)
Moves I before IP. Returns new insert point.
Definition: Instrumentation.cpp:25
llvm::PrepareToSplitEntryBlock
BasicBlock::iterator PrepareToSplitEntryBlock(BasicBlock &BB, BasicBlock::iterator IP)
Instrumentation passes often insert conditional checks into entry blocks.
Definition: Instrumentation.cpp:41
llvm
Definition: AllocatorList.h:23
llvm::initializeBoundsCheckingLegacyPassPass
void initializeBoundsCheckingLegacyPassPass(PassRegistry &)
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::Comdat::NoDuplicates
@ NoDuplicates
No other Module may specify this COMDAT.
Definition: Comdat.h:37
llvm::BasicBlock::iterator
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:90
IntrinsicInst.h
LLVMPassRegistryRef
struct LLVMOpaquePassRegistry * LLVMPassRegistryRef
Definition: Types.h:130
llvm::initializeAddressSanitizerLegacyPassPass
void initializeAddressSanitizerLegacyPassPass(PassRegistry &)
llvm::Function
Definition: Function.h:61
llvm::GlobalVariable
Definition: GlobalVariable.h:40
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
Module.h
llvm::initializeHWAddressSanitizerLegacyPassPass
void initializeHWAddressSanitizerLegacyPassPass(PassRegistry &)
llvm::GlobalValue::UnnamedAddr::Global
@ Global
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::GlobalValue::setUnnamedAddr
void setUnnamedAddr(UnnamedAddr Val)
Definition: GlobalValue.h:212
PassRegistry.h
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
llvm::initializeCGProfileLegacyPassPass
void initializeCGProfileLegacyPassPass(PassRegistry &)
llvm::initializeDataFlowSanitizerLegacyPassPass
void initializeDataFlowSanitizerLegacyPassPass(PassRegistry &)
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::initializeGCOVProfilerLegacyPassPass
void initializeGCOVProfilerLegacyPassPass(PassRegistry &)
IP
Definition: NVPTXLowerArgs.cpp:166
llvm::PassRegistry
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:38
llvm::unwrap
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:244
llvm::initializeModuleSanitizerCoverageLegacyPassPass
void initializeModuleSanitizerCoverageLegacyPassPass(PassRegistry &)
Align
uint64_t Align
Definition: ELFObjHandler.cpp:83
llvm::Comdat
Definition: Comdat.h:31
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::initializePGOIndirectCallPromotionLegacyPassPass
void initializePGOIndirectCallPromotionLegacyPassPass(PassRegistry &)
I
#define I(x, y, z)
Definition: MD5.cpp:59
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::initializeMemorySanitizerLegacyPassPass
void initializeMemorySanitizerLegacyPassPass(PassRegistry &)
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
Triple.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:256
llvm::initializeModuleAddressSanitizerLegacyPassPass
void initializeModuleAddressSanitizerLegacyPassPass(PassRegistry &)
llvm::ConstantDataArray::getString
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
Definition: Constants.cpp:3053
llvm::initializePGOInstrumentationUseLegacyPassPass
void initializePGOInstrumentationUseLegacyPassPass(PassRegistry &)
llvm::initializeModuleMemProfilerLegacyPassPass
void initializeModuleMemProfilerLegacyPassPass(PassRegistry &)
llvm::getOrCreateFunctionComdat
Comdat * getOrCreateFunctionComdat(Function &F, Triple &T)
Definition: Instrumentation.cpp:76
llvm::initializeInstrOrderFileLegacyPassPass
void initializeInstrOrderFileLegacyPassPass(PassRegistry &)
llvm::GlobalValue::PrivateLinkage
@ PrivateLinkage
Like Internal, but omit from symbol table.
Definition: GlobalValue.h:56
llvm::Registry
A global registry used in conjunction with static constructors to make pluggable components (like tar...
Definition: Registry.h:44
LLVMInitializeInstrumentation
void LLVMInitializeInstrumentation(LLVMPassRegistryRef R)
LLVMInitializeInstrumentation - C binding for initializeInstrumentation.
Definition: Instrumentation.cpp:117
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::GlobalObject::setAlignment
void setAlignment(MaybeAlign Align)
Definition: Globals.cpp:117
llvm::initializePGOInstrumentationGenLegacyPassPass
void initializePGOInstrumentationGenLegacyPassPass(PassRegistry &)
llvm::initializeInstrProfilingLegacyPassPass
void initializeInstrProfilingLegacyPassPass(PassRegistry &)
InitializePasses.h
llvm::initializeThreadSanitizerLegacyPassPass
void initializeThreadSanitizerLegacyPassPass(PassRegistry &)
llvm::initializeInstrumentation
void initializeInstrumentation(PassRegistry &)
Initialize all passes linked into the Instrumentation library.
Definition: Instrumentation.cpp:93
llvm::initializePGOMemOPSizeOptLegacyPassPass
void initializePGOMemOPSizeOptLegacyPassPass(PassRegistry &)
Initialization.h
llvm::initializeControlHeightReductionLegacyPassPass
void initializeControlHeightReductionLegacyPassPass(PassRegistry &)