1b1c73532SDimitry Andric //===- StructuralHash.cpp - Function Hash Printing ------------------------===// 2b1c73532SDimitry Andric // 3b1c73532SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4b1c73532SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5b1c73532SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6b1c73532SDimitry Andric // 7b1c73532SDimitry Andric //===----------------------------------------------------------------------===// 8b1c73532SDimitry Andric // 9b1c73532SDimitry Andric // This file defines the StructuralHashPrinterPass which is used to show 10b1c73532SDimitry Andric // the structural hash of all functions in a module and the module itself. 11b1c73532SDimitry Andric // 12b1c73532SDimitry Andric //===----------------------------------------------------------------------===// 13b1c73532SDimitry Andric 14b1c73532SDimitry Andric #include "llvm/Analysis/StructuralHash.h" 15ac9a064cSDimitry Andric #include "llvm/IR/Module.h" 16b1c73532SDimitry Andric #include "llvm/IR/StructuralHash.h" 17b1c73532SDimitry Andric #include "llvm/Support/CommandLine.h" 18b1c73532SDimitry Andric 19b1c73532SDimitry Andric using namespace llvm; 20b1c73532SDimitry Andric run(Module & M,ModuleAnalysisManager & MAM)21b1c73532SDimitry AndricPreservedAnalyses StructuralHashPrinterPass::run(Module &M, 22b1c73532SDimitry Andric ModuleAnalysisManager &MAM) { 23b1c73532SDimitry Andric OS << "Module Hash: " 24b1c73532SDimitry Andric << Twine::utohexstr(StructuralHash(M, EnableDetailedStructuralHash)) 25b1c73532SDimitry Andric << "\n"; 26b1c73532SDimitry Andric for (Function &F : M) { 27b1c73532SDimitry Andric if (F.isDeclaration()) 28b1c73532SDimitry Andric continue; 29b1c73532SDimitry Andric OS << "Function " << F.getName() << " Hash: " 30b1c73532SDimitry Andric << Twine::utohexstr(StructuralHash(F, EnableDetailedStructuralHash)) 31b1c73532SDimitry Andric << "\n"; 32b1c73532SDimitry Andric } 33b1c73532SDimitry Andric return PreservedAnalyses::all(); 34b1c73532SDimitry Andric } 35