MachineModuleSlotTracker.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //===-- llvm/CodeGen/MachineModuleInfo.cpp ----------------------*- C++ -*-===//
  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. #include "llvm/CodeGen/MachineModuleSlotTracker.h"
  9. #include "llvm/CodeGen/MachineFunction.h"
  10. #include "llvm/CodeGen/MachineModuleInfo.h"
  11. using namespace llvm;
  12. void MachineModuleSlotTracker::processMachineFunctionMetadata(
  13. AbstractSlotTrackerStorage *AST, const MachineFunction &MF) {
  14. // Create metadata created within the backend.
  15. for (const MachineBasicBlock &MBB : MF)
  16. for (const MachineInstr &MI : MBB.instrs())
  17. for (const MachineMemOperand *MMO : MI.memoperands()) {
  18. AAMDNodes AAInfo = MMO->getAAInfo();
  19. if (AAInfo.TBAA)
  20. AST->createMetadataSlot(AAInfo.TBAA);
  21. if (AAInfo.TBAAStruct)
  22. AST->createMetadataSlot(AAInfo.TBAAStruct);
  23. if (AAInfo.Scope)
  24. AST->createMetadataSlot(AAInfo.Scope);
  25. if (AAInfo.NoAlias)
  26. AST->createMetadataSlot(AAInfo.NoAlias);
  27. }
  28. }
  29. void MachineModuleSlotTracker::processMachineModule(
  30. AbstractSlotTrackerStorage *AST, const Module *M,
  31. bool ShouldInitializeAllMetadata) {
  32. if (ShouldInitializeAllMetadata) {
  33. for (const Function &F : *M) {
  34. if (&F != &TheFunction)
  35. continue;
  36. MDNStartSlot = AST->getNextMetadataSlot();
  37. if (auto *MF = TheMMI.getMachineFunction(F))
  38. processMachineFunctionMetadata(AST, *MF);
  39. MDNEndSlot = AST->getNextMetadataSlot();
  40. break;
  41. }
  42. }
  43. }
  44. void MachineModuleSlotTracker::processMachineFunction(
  45. AbstractSlotTrackerStorage *AST, const Function *F,
  46. bool ShouldInitializeAllMetadata) {
  47. if (!ShouldInitializeAllMetadata && F == &TheFunction) {
  48. MDNStartSlot = AST->getNextMetadataSlot();
  49. if (auto *MF = TheMMI.getMachineFunction(*F))
  50. processMachineFunctionMetadata(AST, *MF);
  51. MDNEndSlot = AST->getNextMetadataSlot();
  52. }
  53. }
  54. void MachineModuleSlotTracker::collectMachineMDNodes(
  55. MachineMDNodeListType &L) const {
  56. collectMDNodes(L, MDNStartSlot, MDNEndSlot);
  57. }
  58. MachineModuleSlotTracker::MachineModuleSlotTracker(
  59. const MachineFunction *MF, bool ShouldInitializeAllMetadata)
  60. : ModuleSlotTracker(MF->getFunction().getParent(),
  61. ShouldInitializeAllMetadata),
  62. TheFunction(MF->getFunction()), TheMMI(MF->getMMI()) {
  63. setProcessHook([this](AbstractSlotTrackerStorage *AST, const Module *M,
  64. bool ShouldInitializeAllMetadata) {
  65. this->processMachineModule(AST, M, ShouldInitializeAllMetadata);
  66. });
  67. setProcessHook([this](AbstractSlotTrackerStorage *AST, const Function *F,
  68. bool ShouldInitializeAllMetadata) {
  69. this->processMachineFunction(AST, F, ShouldInitializeAllMetadata);
  70. });
  71. }
  72. MachineModuleSlotTracker::~MachineModuleSlotTracker() = default;