LLVM 22.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
20#include "llvm/IR/Function.h"
22
23using namespace llvm;
24
25namespace {
26struct FEntryInserter {
27 bool run(MachineFunction &MF);
28};
29
30struct FEntryInserterLegacy : public MachineFunctionPass {
31 static char ID; // Pass identification, replacement for typeid
32 FEntryInserterLegacy() : MachineFunctionPass(ID) {
34 }
35
36 bool runOnMachineFunction(MachineFunction &F) override {
37 return FEntryInserter().run(F);
38 }
39};
40}
41
48
49bool FEntryInserter::run(MachineFunction &MF) {
50 const std::string FEntryName = std::string(
51 MF.getFunction().getFnAttribute("fentry-call").getValueAsString());
52 if (FEntryName != "true")
53 return false;
54
55 auto &FirstMBB = *MF.begin();
56 auto *TII = MF.getSubtarget().getInstrInfo();
57 BuildMI(FirstMBB, FirstMBB.begin(), DebugLoc(),
58 TII->get(TargetOpcode::FENTRY_CALL));
59 return true;
60}
61
62char FEntryInserterLegacy::ID = 0;
63char &llvm::FEntryInserterID = FEntryInserterLegacy::ID;
64INITIALIZE_PASS(FEntryInserterLegacy, "fentry-insert", "Insert fentry calls",
65 false, false)
const HexagonInstrInfo * TII
#define F(x, y, z)
Definition MD5.cpp:55
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
LLVM_ABI StringRef getValueAsString() const
Return the attribute's value as a string.
A debug info location.
Definition DebugLoc.h:124
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition Function.cpp:762
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
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 LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
virtual const TargetInstrInfo * getInstrInfo() const
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI 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.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI void initializeFEntryInserterLegacyPass(PassRegistry &)
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.