brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.5 KiB · 1e7c5e9 Raw
83 lines · cpp
1//===- CycleAnalysis.cpp - Compute CycleInfo for LLVM IR ------------------===//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/Analysis/CycleAnalysis.h"10#include "llvm/IR/CFG.h" // for successors found by ADL in GenericCycleImpl.h11#include "llvm/InitializePasses.h"12 13using namespace llvm;14 15namespace llvm {16class Module;17} // namespace llvm18 19CycleInfo CycleAnalysis::run(Function &F, FunctionAnalysisManager &) {20  CycleInfo CI;21  CI.compute(F);22  return CI;23}24 25AnalysisKey CycleAnalysis::Key;26 27CycleInfoPrinterPass::CycleInfoPrinterPass(raw_ostream &OS) : OS(OS) {}28 29PreservedAnalyses CycleInfoPrinterPass::run(Function &F,30                                            FunctionAnalysisManager &AM) {31  OS << "CycleInfo for function: " << F.getName() << "\n";32  AM.getResult<CycleAnalysis>(F).print(OS);33 34  return PreservedAnalyses::all();35}36 37PreservedAnalyses CycleInfoVerifierPass::run(Function &F,38                                             FunctionAnalysisManager &AM) {39  CycleInfo &CI = AM.getResult<CycleAnalysis>(F);40  CI.verify();41  return PreservedAnalyses::all();42}43 44//===----------------------------------------------------------------------===//45//  CycleInfoWrapperPass Implementation46//===----------------------------------------------------------------------===//47//48// The implementation details of the wrapper pass that holds a CycleInfo49// suitable for use with the legacy pass manager.50//51//===----------------------------------------------------------------------===//52 53char CycleInfoWrapperPass::ID = 0;54 55CycleInfoWrapperPass::CycleInfoWrapperPass() : FunctionPass(ID) {}56 57INITIALIZE_PASS_BEGIN(CycleInfoWrapperPass, "cycles", "Cycle Info Analysis",58                      true, true)59INITIALIZE_PASS_END(CycleInfoWrapperPass, "cycles", "Cycle Info Analysis", true,60                    true)61 62void CycleInfoWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {63  AU.setPreservesAll();64}65 66bool CycleInfoWrapperPass::runOnFunction(Function &Func) {67  CI.clear();68 69  F = &Func;70  CI.compute(Func);71  return false;72}73 74void CycleInfoWrapperPass::print(raw_ostream &OS, const Module *) const {75  OS << "CycleInfo for function: " << F->getName() << "\n";76  CI.print(OS);77}78 79void CycleInfoWrapperPass::releaseMemory() {80  CI.clear();81  F = nullptr;82}83