FEntryInserter.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #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"
  19. using namespace llvm;
  20. namespace {
  21. struct FEntryInserter : public MachineFunctionPass {
  22. static char ID; // Pass identification, replacement for typeid
  23. FEntryInserter() : MachineFunctionPass(ID) {
  24. initializeFEntryInserterPass(*PassRegistry::getPassRegistry());
  25. }
  26. bool runOnMachineFunction(MachineFunction &F) override;
  27. };
  28. }
  29. bool FEntryInserter::runOnMachineFunction(MachineFunction &MF) {
  30. const std::string FEntryName = std::string(
  31. MF.getFunction().getFnAttribute("fentry-call").getValueAsString());
  32. if (FEntryName != "true")
  33. return false;
  34. auto &FirstMBB = *MF.begin();
  35. auto *TII = MF.getSubtarget().getInstrInfo();
  36. BuildMI(FirstMBB, FirstMBB.begin(), DebugLoc(),
  37. TII->get(TargetOpcode::FENTRY_CALL));
  38. return true;
  39. }
  40. char FEntryInserter::ID = 0;
  41. char &llvm::FEntryInserterID = FEntryInserter::ID;
  42. INITIALIZE_PASS(FEntryInserter, "fentry-insert", "Insert fentry calls", false,
  43. false)