LLVM  10.0.0svn
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 
23 using namespace llvm;
24 
25 namespace {
26 struct FEntryInserter : public MachineFunctionPass {
27  static char ID; // Pass identification, replacement for typeid
28  FEntryInserter() : MachineFunctionPass(ID) {
30  }
31 
32  bool runOnMachineFunction(MachineFunction &F) override;
33 };
34 }
35 
36 bool FEntryInserter::runOnMachineFunction(MachineFunction &MF) {
37  const std::string FEntryName =
38  MF.getFunction().getFnAttribute("fentry-call").getValueAsString();
39  if (FEntryName != "true")
40  return false;
41 
42  auto &FirstMBB = *MF.begin();
43  auto *TII = MF.getSubtarget().getInstrInfo();
44  BuildMI(FirstMBB, FirstMBB.begin(), DebugLoc(),
45  TII->get(TargetOpcode::FENTRY_CALL));
46  return true;
47 }
48 
49 char FEntryInserter::ID = 0;
51 INITIALIZE_PASS(FEntryInserter, "fentry-insert", "Insert fentry calls", false,
52  false)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
Definition: AllocatorList.h:23
char & FEntryInserterID
This pass inserts FEntry calls.
A debug info location.
Definition: DebugLoc.h:33
F(f)
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
virtual const TargetInstrInfo * getInstrInfo() const
void initializeFEntryInserterPass(PassRegistry &)
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:33
Module.h This file contains the declarations for the Module class.
const Function & getFunction() const
Return the LLVM function that this machine code represents.
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:223
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.h:333