Path: blob/main/contrib/llvm-project/llvm/lib/CodeGen/FEntryInserter.cpp
35233 views
//===-- FEntryInsertion.cpp - Patchable prologues for LLVM -------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file edits function bodies to insert fentry calls.9//10//===----------------------------------------------------------------------===//1112#include "llvm/CodeGen/MachineFunction.h"13#include "llvm/CodeGen/MachineFunctionPass.h"14#include "llvm/CodeGen/MachineInstrBuilder.h"15#include "llvm/CodeGen/TargetInstrInfo.h"16#include "llvm/CodeGen/TargetSubtargetInfo.h"17#include "llvm/IR/Function.h"18#include "llvm/InitializePasses.h"1920using namespace llvm;2122namespace {23struct FEntryInserter : public MachineFunctionPass {24static char ID; // Pass identification, replacement for typeid25FEntryInserter() : MachineFunctionPass(ID) {26initializeFEntryInserterPass(*PassRegistry::getPassRegistry());27}2829bool runOnMachineFunction(MachineFunction &F) override;30};31}3233bool FEntryInserter::runOnMachineFunction(MachineFunction &MF) {34const std::string FEntryName = std::string(35MF.getFunction().getFnAttribute("fentry-call").getValueAsString());36if (FEntryName != "true")37return false;3839auto &FirstMBB = *MF.begin();40auto *TII = MF.getSubtarget().getInstrInfo();41BuildMI(FirstMBB, FirstMBB.begin(), DebugLoc(),42TII->get(TargetOpcode::FENTRY_CALL));43return true;44}4546char FEntryInserter::ID = 0;47char &llvm::FEntryInserterID = FEntryInserter::ID;48INITIALIZE_PASS(FEntryInserter, "fentry-insert", "Insert fentry calls", false,49false)505152