10b57cec5SDimitry Andric //===- InstructionNamer.cpp - Give anonymous instructions names -----------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // This is a little utility pass that gives instructions names, this is mostly 100b57cec5SDimitry Andric // useful when diffing the effect of an optimization because deleting an 110b57cec5SDimitry Andric // unnamed instruction can change all other instruction numbering, making the 120b57cec5SDimitry Andric // diff very noisy. 130b57cec5SDimitry Andric // 140b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 150b57cec5SDimitry Andric 16*e8d8bef9SDimitry Andric #include "llvm/Transforms/Utils/InstructionNamer.h" 170b57cec5SDimitry Andric #include "llvm/IR/Function.h" 18*e8d8bef9SDimitry Andric #include "llvm/IR/PassManager.h" 190b57cec5SDimitry Andric #include "llvm/IR/Type.h" 20*e8d8bef9SDimitry Andric 210b57cec5SDimitry Andric using namespace llvm; 220b57cec5SDimitry Andric 230b57cec5SDimitry Andric namespace { nameInstructions(Function & F)24*e8d8bef9SDimitry Andricvoid nameInstructions(Function &F) { 25*e8d8bef9SDimitry Andric for (auto &Arg : F.args()) { 26*e8d8bef9SDimitry Andric if (!Arg.hasName()) 27*e8d8bef9SDimitry Andric Arg.setName("arg"); 28*e8d8bef9SDimitry Andric } 29*e8d8bef9SDimitry Andric 30*e8d8bef9SDimitry Andric for (BasicBlock &BB : F) { 31*e8d8bef9SDimitry Andric if (!BB.hasName()) 32*e8d8bef9SDimitry Andric BB.setName("bb"); 33*e8d8bef9SDimitry Andric 34*e8d8bef9SDimitry Andric for (Instruction &I : BB) { 35*e8d8bef9SDimitry Andric if (!I.hasName() && !I.getType()->isVoidTy()) 36*e8d8bef9SDimitry Andric I.setName("i"); 37*e8d8bef9SDimitry Andric } 38*e8d8bef9SDimitry Andric } 39*e8d8bef9SDimitry Andric } 40*e8d8bef9SDimitry Andric 41*e8d8bef9SDimitry Andric } // namespace 420b57cec5SDimitry Andric run(Function & F,FunctionAnalysisManager & FAM)43*e8d8bef9SDimitry AndricPreservedAnalyses InstructionNamerPass::run(Function &F, 44*e8d8bef9SDimitry Andric FunctionAnalysisManager &FAM) { 45*e8d8bef9SDimitry Andric nameInstructions(F); 46*e8d8bef9SDimitry Andric return PreservedAnalyses::all(); 47*e8d8bef9SDimitry Andric } 48