Path: blob/main/contrib/llvm-project/llvm/lib/Transforms/Utils/InstructionNamer.cpp
35271 views
//===- InstructionNamer.cpp - Give anonymous instructions names -----------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This is a little utility pass that gives instructions names, this is mostly9// useful when diffing the effect of an optimization because deleting an10// unnamed instruction can change all other instruction numbering, making the11// diff very noisy.12//13//===----------------------------------------------------------------------===//1415#include "llvm/Transforms/Utils/InstructionNamer.h"16#include "llvm/IR/Function.h"17#include "llvm/IR/PassManager.h"18#include "llvm/IR/Type.h"1920using namespace llvm;2122namespace {23void nameInstructions(Function &F) {24for (auto &Arg : F.args()) {25if (!Arg.hasName())26Arg.setName("arg");27}2829for (BasicBlock &BB : F) {30if (!BB.hasName())31BB.setName("bb");3233for (Instruction &I : BB) {34if (!I.hasName() && !I.getType()->isVoidTy())35I.setName("i");36}37}38}3940} // namespace4142PreservedAnalyses InstructionNamerPass::run(Function &F,43FunctionAnalysisManager &FAM) {44nameInstructions(F);45return PreservedAnalyses::all();46}474849