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