LLVM 24.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
21#include "llvm/IR/Function.h"
23
24using namespace llvm;
25
26namespace {
27struct FEntryInserter {
28 bool run(MachineFunction &MF);
29};
30
31struct FEntryInserterLegacy : public MachineFunctionPass {
32 static char ID; // Pass identification, replacement for typeid
33 FEntryInserterLegacy() : MachineFunctionPass(ID) {}
34
35 bool runOnMachineFunction(MachineFunction &F) override {
36 return FEntryInserter().run(F);
37 }
38
39 void getAnalysisUsage(AnalysisUsage &AU) const override {
40 AU.addPreserved<MachineRegisterClassInfoWrapperPass>();
42 }
43};
44}
45
52
53bool FEntryInserter::run(MachineFunction &MF) {
54 const std::string FEntryName = std::string(
55 MF.getFunction().getFnAttribute("fentry-call").getValueAsString());
56 if (FEntryName != "true")
57 return false;
58
59 auto &FirstMBB = *MF.begin();
60 auto *TII = MF.getSubtarget().getInstrInfo();
61 BuildMI(FirstMBB, FirstMBB.begin(), DebugLoc(),
62 TII->get(TargetOpcode::FENTRY_CALL));
63 return true;
64}
65
66char FEntryInserterLegacy::ID = 0;
67char &llvm::FEntryInserterID = FEntryInserterLegacy::ID;
68INITIALIZE_PASS(FEntryInserterLegacy, "fentry-insert", "Insert fentry calls",
69 false, false)
const HexagonInstrInfo * TII
#define F(x, y, z)
Definition MD5.cpp:54
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
LLVM_ABI StringRef getValueAsString() const
Return the attribute's value as a string.
A debug info location.
Definition DebugLoc.h:126
LLVM_ABI 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...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
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.
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
DXILDebugInfoMap run(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 PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.