brintos

brintos / llvm-project-archived public Read only

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