blob: 4ddf9f92836c0cb9946a7f47923cb34e6c7f7765 [file] [log] [blame]
Nirav Dave53d52e92017-01-31 17:00:27 +00001//===-- 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
14#include "llvm/CodeGen/MachineFunction.h"
15#include "llvm/CodeGen/MachineFunctionPass.h"
16#include "llvm/CodeGen/MachineInstrBuilder.h"
17#include "llvm/CodeGen/Passes.h"
David Blaikie48319232017-11-08 01:01:31 +000018#include "llvm/CodeGen/TargetFrameLowering.h"
19#include "llvm/CodeGen/TargetInstrInfo.h"
David Blaikiee3a9b4c2017-11-17 01:07:10 +000020#include "llvm/CodeGen/TargetSubtargetInfo.h"
Nirav Dave53d52e92017-01-31 17:00:27 +000021#include "llvm/IR/Function.h"
22#include "llvm/IR/Module.h"
Nirav Dave53d52e92017-01-31 17:00:27 +000023
24using namespace llvm;
25
26namespace {
27struct FEntryInserter : public MachineFunctionPass {
28 static char ID; // Pass identification, replacement for typeid
29 FEntryInserter() : MachineFunctionPass(ID) {
30 initializeFEntryInserterPass(*PassRegistry::getPassRegistry());
31 }
32
33 bool runOnMachineFunction(MachineFunction &F) override;
34};
35}
36
37bool FEntryInserter::runOnMachineFunction(MachineFunction &MF) {
38 const std::string FEntryName =
Matthias Braund3181392017-12-15 22:22:58 +000039 MF.getFunction().getFnAttribute("fentry-call").getValueAsString();
Nirav Dave53d52e92017-01-31 17:00:27 +000040 if (FEntryName != "true")
41 return false;
42
43 auto &FirstMBB = *MF.begin();
Nirav Dave53d52e92017-01-31 17:00:27 +000044 auto *TII = MF.getSubtarget().getInstrInfo();
Manoj Guptaf6fecfa2017-08-01 15:39:12 +000045 BuildMI(FirstMBB, FirstMBB.begin(), DebugLoc(),
Nirav Dave53d52e92017-01-31 17:00:27 +000046 TII->get(TargetOpcode::FENTRY_CALL));
47 return true;
48}
49
50char FEntryInserter::ID = 0;
51char &llvm::FEntryInserterID = FEntryInserter::ID;
52INITIALIZE_PASS(FEntryInserter, "fentry-insert", "Insert fentry calls", false,
53 false)