1 //===-- FEntryInsertion.cpp - Patchable prologues for LLVM -------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file edits function bodies to insert fentry calls.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/CodeGen/MachineFunction.h"
14 #include "llvm/CodeGen/MachineFunctionPass.h"
15 #include "llvm/CodeGen/MachineInstrBuilder.h"
16 #include "llvm/CodeGen/TargetInstrInfo.h"
17 #include "llvm/CodeGen/TargetSubtargetInfo.h"
18 #include "llvm/IR/Function.h"
19 #include "llvm/InitializePasses.h"
24 struct FEntryInserter
: public MachineFunctionPass
{
25 static char ID
; // Pass identification, replacement for typeid
26 FEntryInserter() : MachineFunctionPass(ID
) {
27 initializeFEntryInserterPass(*PassRegistry::getPassRegistry());
30 bool runOnMachineFunction(MachineFunction
&F
) override
;
34 bool FEntryInserter::runOnMachineFunction(MachineFunction
&MF
) {
35 const std::string FEntryName
= std::string(
36 MF
.getFunction().getFnAttribute("fentry-call").getValueAsString());
37 if (FEntryName
!= "true")
40 auto &FirstMBB
= *MF
.begin();
41 auto *TII
= MF
.getSubtarget().getInstrInfo();
42 BuildMI(FirstMBB
, FirstMBB
.begin(), DebugLoc(),
43 TII
->get(TargetOpcode::FENTRY_CALL
));
47 char FEntryInserter::ID
= 0;
48 char &llvm::FEntryInserterID
= FEntryInserter::ID
;
49 INITIALIZE_PASS(FEntryInserter
, "fentry-insert", "Insert fentry calls", false,