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);
65 Call->setDebugLoc(
DL);
74 Call->setDebugLoc(
DL);
79 if (Func ==
"__cyg_profile_func_enter" || Func ==
"__cyg_profile_func_exit") {
80 Type *ArgTypes[] = {PointerType::getUnqual(
C), PointerType::getUnqual(
C)};
91 Value *Args[] = {&CurFn, RetAddr};
94 Call->setDebugLoc(
DL);
108 if (
F.hasFnAttribute(Attribute::Naked))
114 if (
F.hasAvailableExternallyLinkage())
117 StringRef EntryAttr = PostInlining ?
"instrument-function-entry-inlined"
118 :
"instrument-function-entry";
120 StringRef ExitAttr = PostInlining ?
"instrument-function-exit-inlined"
121 :
"instrument-function-exit";
123 StringRef EntryFunc =
F.getFnAttribute(EntryAttr).getValueAsString();
124 StringRef ExitFunc =
F.getFnAttribute(ExitAttr).getValueAsString();
126 bool Changed =
false;
132 if (!EntryFunc.
empty()) {
134 if (
auto SP =
F.getSubprogram())
135 DL = DILocation::get(SP->getContext(), SP->getScopeLine(), 0, SP);
139 F.removeFnAttr(EntryAttr);
142 if (!ExitFunc.
empty()) {
145 if (!isa<ReturnInst>(
T))
149 if (
CallInst *CI = BB.getTerminatingMustTailCall())
153 if (
DebugLoc TerminatorDL =
T->getDebugLoc())
155 else if (
auto SP =
F.getSubprogram())
156 DL = DILocation::get(SP->getContext(), 0, 0, SP);
161 F.removeFnAttr(ExitAttr);
168struct PostInlineEntryExitInstrumenter :
public FunctionPass {
180char PostInlineEntryExitInstrumenter::ID = 0;
184 PostInlineEntryExitInstrumenter,
"post-inline-ee-instrument",
185 "Instrument function entry/exit with calls to e.g. mcount() "
196 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),...
static LLVM_ABI Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
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.
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
@ 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 LLVM_ABI 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.
PreservedAnalyses & 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 isRISCV() const
Tests whether the target is RISC-V (32- and 64-bit).
bool isOSAIX() const
Tests whether the OS is AIX.
bool isAArch64() const
Tests whether the target is AArch64 (little and big endian).
bool isSystemZ() const
Tests whether the target is SystemZ.
bool isLoongArch() const
Tests whether the target is LoongArch (32- and 64-bit).
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 LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
static LLVM_ABI Type * getVoidTy(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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
LLVM_ABI 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.
LLVM_ABI FunctionPass * createPostInlineEntryExitInstrumenterPass()
LLVM_ABI void initializePostInlineEntryExitInstrumenterPass(PassRegistry &)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
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.