LLVM  14.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 
16 #include "llvm/CodeGen/Passes.h"
20 #include "llvm/IR/Function.h"
21 #include "llvm/IR/Module.h"
22 #include "llvm/InitializePasses.h"
23 
24 using namespace llvm;
25 
26 namespace {
27 struct FEntryInserter : public MachineFunctionPass {
28  static char ID; // Pass identification, replacement for typeid
29  FEntryInserter() : MachineFunctionPass(ID) {
31  }
32 
33  bool runOnMachineFunction(MachineFunction &F) override;
34 };
35 }
36 
37 bool FEntryInserter::runOnMachineFunction(MachineFunction &MF) {
38  const std::string FEntryName = std::string(
39  MF.getFunction().getFnAttribute("fentry-call").getValueAsString());
40  if (FEntryName != "true")
41  return false;
42 
43  auto &FirstMBB = *MF.begin();
44  auto *TII = MF.getSubtarget().getInstrInfo();
45  BuildMI(FirstMBB, FirstMBB.begin(), DebugLoc(),
46  TII->get(TargetOpcode::FENTRY_CALL));
47  return true;
48 }
49 
50 char FEntryInserter::ID = 0;
52 INITIALIZE_PASS(FEntryInserter, "fentry-insert", "Insert fentry calls", false,
53  false)
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
TargetFrameLowering.h
llvm::TargetSubtargetInfo::getInstrInfo
virtual const TargetInstrInfo * getInstrInfo() const
Definition: TargetSubtargetInfo.h:92
llvm::MachineFunctionPass
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Definition: MachineFunctionPass.h:30
Module.h
TargetInstrInfo.h
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:31
llvm::FEntryInserterID
char & FEntryInserterID
This pass inserts FEntry calls.
Definition: FEntryInserter.cpp:51
INITIALIZE_PASS
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:37
TII
const HexagonInstrInfo * TII
Definition: HexagonCopyToCombine.cpp:129
llvm::Function::getFnAttribute
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.cpp:652
llvm::MachineFunction::begin
iterator begin()
Definition: MachineFunction.h:812
llvm::Attribute::getValueAsString
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:301
Passes.h
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:630
MachineFunctionPass.h
llvm::MachineFunction
Definition: MachineFunction.h:234
TargetSubtargetInfo.h
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:596
Function.h
llvm::initializeFEntryInserterPass
void initializeFEntryInserterPass(PassRegistry &)
MachineInstrBuilder.h
llvm::BuildMI
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
Definition: MachineInstrBuilder.h:328
llvm::DebugLoc
A debug info location.
Definition: DebugLoc.h:33
MachineFunction.h
InitializePasses.h
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37