2017-01-31 18:00:27 +01:00
|
|
|
//===-- FEntryInsertion.cpp - Patchable prologues for LLVM -------------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-01-31 18:00:27 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file edits function bodies to insert fentry calls.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2017-11-08 02:01:31 +01:00
|
|
|
#include "llvm/CodeGen/TargetFrameLowering.h"
|
|
|
|
#include "llvm/CodeGen/TargetInstrInfo.h"
|
2017-11-17 02:07:10 +01:00
|
|
|
#include "llvm/CodeGen/TargetSubtargetInfo.h"
|
2017-01-31 18:00:27 +01:00
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
struct FEntryInserter : public MachineFunctionPass {
|
|
|
|
static char ID; // Pass identification, replacement for typeid
|
|
|
|
FEntryInserter() : MachineFunctionPass(ID) {
|
|
|
|
initializeFEntryInserterPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool runOnMachineFunction(MachineFunction &F) override;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FEntryInserter::runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
const std::string FEntryName =
|
2017-12-15 23:22:58 +01:00
|
|
|
MF.getFunction().getFnAttribute("fentry-call").getValueAsString();
|
2017-01-31 18:00:27 +01:00
|
|
|
if (FEntryName != "true")
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto &FirstMBB = *MF.begin();
|
|
|
|
auto *TII = MF.getSubtarget().getInstrInfo();
|
2017-08-01 17:39:12 +02:00
|
|
|
BuildMI(FirstMBB, FirstMBB.begin(), DebugLoc(),
|
2017-01-31 18:00:27 +01:00
|
|
|
TII->get(TargetOpcode::FENTRY_CALL));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
char FEntryInserter::ID = 0;
|
|
|
|
char &llvm::FEntryInserterID = FEntryInserter::ID;
|
|
|
|
INITIALIZE_PASS(FEntryInserter, "fentry-insert", "Insert fentry calls", false,
|
|
|
|
false)
|