LLVM  5.0.0
FEntryInserter.cpp
Go to the documentation of this file.
1 //===-- FEntryInsertion.cpp - Patchable prologues for LLVM -------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file edits function bodies to insert fentry calls.
11 //
12 //===----------------------------------------------------------------------===//
13 
17 #include "llvm/CodeGen/Passes.h"
18 #include "llvm/IR/Function.h"
19 #include "llvm/IR/Module.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 =
39  MF.getFunction()->getFnAttribute("fentry-call").getValueAsString();
40  if (FEntryName != "true")
41  return false;
42 
43  auto &FirstMBB = *MF.begin();
44  auto &FirstMI = *FirstMBB.begin();
45 
46  auto *TII = MF.getSubtarget().getInstrInfo();
47  BuildMI(FirstMBB, FirstMI, FirstMI.getDebugLoc(),
48  TII->get(TargetOpcode::FENTRY_CALL));
49  return true;
50 }
51 
52 char FEntryInserter::ID = 0;
54 INITIALIZE_PASS(FEntryInserter, "fentry-insert", "Insert fentry calls", false,
55  false)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
char & FEntryInserterID
This pass inserts FEntry calls.
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.h:262
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
#define F(x, y, z)
Definition: MD5.cpp:55
void initializeFEntryInserterPass(PassRegistry &)
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:34
Module.h This file contains the declarations for the Module class.
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:195
virtual const TargetInstrInfo * getInstrInfo() const