LLVM 20.0.0git
FEntryInserter.cpp
Go to the documentation of this file.
1//===-- FEntryInsertion.cpp - Patchable prologues for LLVM -------------===//
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 edits function bodies to insert fentry calls.
10//
11//===----------------------------------------------------------------------===//
12
18#include "llvm/IR/Function.h"
20
21using namespace llvm;
22
23namespace {
24struct FEntryInserter : public MachineFunctionPass {
25 static char ID; // Pass identification, replacement for typeid
26 FEntryInserter() : MachineFunctionPass(ID) {
28 }
29
31};
32}
33
34bool FEntryInserter::runOnMachineFunction(MachineFunction &MF) {
35 const std::string FEntryName = std::string(
36 MF.getFunction().getFnAttribute("fentry-call").getValueAsString());
37 if (FEntryName != "true")
38 return false;
39
40 auto &FirstMBB = *MF.begin();
41 auto *TII = MF.getSubtarget().getInstrInfo();
42 BuildMI(FirstMBB, FirstMBB.begin(), DebugLoc(),
43 TII->get(TargetOpcode::FENTRY_CALL));
44 return true;
45}
46
47char FEntryInserter::ID = 0;
48char &llvm::FEntryInserterID = FEntryInserter::ID;
49INITIALIZE_PASS(FEntryInserter, "fentry-insert", "Insert fentry calls", false,
50 false)
const HexagonInstrInfo * TII
#define F(x, y, z)
Definition: MD5.cpp:55
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:38
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:392
A debug info location.
Definition: DebugLoc.h:33
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.cpp:766
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Function & getFunction()
Return the LLVM function that this machine code represents.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual const TargetInstrInfo * getInstrInfo() const
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
char & FEntryInserterID
This pass inserts FEntry calls.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
void initializeFEntryInserterPass(PassRegistry &)