27 Module &M = *InsertionPt->getParent()->getParent()->getParent();
30 if (Func ==
"mcount" ||
32 Func ==
"llvm.arm.gnu.eabi.mcount" ||
33 Func ==
"\01_mcount" ||
34 Func ==
"\01mcount" ||
37 Func ==
"__cyg_profile_func_enter_bare") {
38 Triple TargetTriple(M.getTargetTriple());
39 if (TargetTriple.
isOSAIX() && Func ==
"__mcount") {
40 Type *SizeTy = M.getDataLayout().getIntPtrType(
C);
41 Type *SizePtrTy = PointerType::getUnqual(
C);
44 ConstantInt::get(SizeTy, 0));
46 M.getOrInsertFunction(Func,
49 {GV},
"", InsertionPt);
50 Call->setDebugLoc(
DL);
54 Call->setDebugLoc(
DL);
59 if (Func ==
"__cyg_profile_func_enter" || Func ==
"__cyg_profile_func_exit") {
60 Type *ArgTypes[] = {PointerType::getUnqual(
C), PointerType::getUnqual(
C)};
71 Value *Args[] = {&CurFn, RetAddr};
74 Call->setDebugLoc(
DL);
88 if (
F.hasFnAttribute(Attribute::Naked))
91 StringRef EntryAttr = PostInlining ?
"instrument-function-entry-inlined"
92 :
"instrument-function-entry";
94 StringRef ExitAttr = PostInlining ?
"instrument-function-exit-inlined"
95 :
"instrument-function-exit";
97 StringRef EntryFunc =
F.getFnAttribute(EntryAttr).getValueAsString();
98 StringRef ExitFunc =
F.getFnAttribute(ExitAttr).getValueAsString();
100 bool Changed =
false;
106 if (!EntryFunc.
empty()) {
108 if (
auto SP =
F.getSubprogram())
109 DL = DILocation::get(SP->getContext(), SP->getScopeLine(), 0, SP);
113 F.removeFnAttr(EntryAttr);
116 if (!ExitFunc.
empty()) {
119 if (!isa<ReturnInst>(
T))
123 if (
CallInst *CI = BB.getTerminatingMustTailCall())
127 if (
DebugLoc TerminatorDL =
T->getDebugLoc())
129 else if (
auto SP =
F.getSubprogram())
130 DL = DILocation::get(SP->getContext(), 0, 0, SP);
135 F.removeFnAttr(ExitAttr);
142struct PostInlineEntryExitInstrumenter :
public FunctionPass {
154char PostInlineEntryExitInstrumenter::ID = 0;
158 PostInlineEntryExitInstrumenter,
"post-inline-ee-instrument",
159 "Instrument function entry/exit with calls to e.g. mcount() "
170 return new PostInlineEntryExitInstrumenter();
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Performs the initial survey of the specified function
post inline ee instrument
static bool runOnFunction(Function &F, bool PostInlining)
post inline ee Instrument function entry exit with calls to e g mcount() " "(post inlining)"
static void insertCall(Function &CurFn, StringRef Func, BasicBlock::iterator InsertionPt, DebugLoc DL)
This is the interface for a simple mod/ref and alias analysis over globals.
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
INLINE void g(uint32_t *state, size_t a, size_t b, size_t c, size_t d, uint32_t x, uint32_t y)
A container for analyses that lazily runs them and caches their results.
Represent the analysis usage information of a pass.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM Basic Block Representation.
InstListType::iterator iterator
Instruction iterators...
Represents analyses that only rely on functions' control flow.
This class represents a function call, abstracting a target machine's calling convention.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Legacy analysis pass which computes a DominatorTree.
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
FunctionPass class - This class is used to implement most global optimizations.
virtual bool runOnFunction(Function &F)=0
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
@ InternalLinkage
Rename collisions when linking (static functions).
Legacy wrapper pass to provide the GlobalsAAResult object.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
This is an important class for using LLVM in a threaded context.
A Module instance is used to store all the information related to an LLVM module.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void preserveSet()
Mark an analysis set as preserved.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
Triple - Helper class for working with autoconf configuration names.
bool isOSAIX() const
Tests whether the OS is AIX.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
static Type * getVoidTy(LLVMContext &C)
static IntegerType * getInt32Ty(LLVMContext &C)
LLVM Value Representation.
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
@ C
The default llvm calling convention, compatible with C.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > Tys={})
Look up the Function declaration of the intrinsic id in the Module M.
This is an optimization pass for GlobalISel generic memory operations.
FunctionPass * createPostInlineEntryExitInstrumenterPass()
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
void initializePostInlineEntryExitInstrumenterPass(PassRegistry &)
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
A CRTP mix-in to automatically provide informational APIs needed for passes.