Port -instnamer to NPM

Some clang tests use this.

Reviewed By: akhuang

Differential Revision: https://reviews.llvm.org/D89931
This commit is contained in:
Arthur Eubanks 2020-10-21 22:55:34 -07:00
parent a66311277a
commit 92d9a3868a
5 changed files with 61 additions and 23 deletions

View File

@ -0,0 +1,20 @@
//===- InstructionNamer.h - Give anonymous instructions names -------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TRANSFORMS_UTILS_INSTRUCTIONNAMER_H
#define LLVM_TRANSFORMS_UTILS_INSTRUCTIONNAMER_H
#include "llvm/IR/PassManager.h"
namespace llvm {
struct InstructionNamerPass : PassInfoMixin<InstructionNamerPass> {
PreservedAnalyses run(Function &, FunctionAnalysisManager &);
};
} // namespace llvm
#endif // LLVM_TRANSFORMS_UTILS_INSTRUCTIONNAMER_H

View File

@ -201,6 +201,7 @@
#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
#include "llvm/Transforms/Utils/FixIrreducible.h"
#include "llvm/Transforms/Utils/InjectTLIMappings.h"
#include "llvm/Transforms/Utils/InstructionNamer.h"
#include "llvm/Transforms/Utils/LCSSA.h"
#include "llvm/Transforms/Utils/LibCallsShrinkWrap.h"
#include "llvm/Transforms/Utils/LoopSimplify.h"

View File

@ -225,6 +225,7 @@ FUNCTION_PASS("no-op-function", NoOpFunctionPass())
FUNCTION_PASS("libcalls-shrinkwrap", LibCallsShrinkWrapPass())
FUNCTION_PASS("lint", LintPass())
FUNCTION_PASS("inject-tli-mappings", InjectTLIMappings())
FUNCTION_PASS("instnamer", InstructionNamerPass())
FUNCTION_PASS("loweratomic", LowerAtomicPass())
FUNCTION_PASS("lower-expect", LowerExpectIntrinsicPass())
FUNCTION_PASS("lower-guard-intrinsic", LowerGuardIntrinsicPass())

View File

@ -13,43 +13,52 @@
//
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/Utils/InstructionNamer.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/Type.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Transforms/Utils.h"
using namespace llvm;
namespace {
struct InstNamer : public FunctionPass {
static char ID; // Pass identification, replacement for typeid
InstNamer() : FunctionPass(ID) {
initializeInstNamerPass(*PassRegistry::getPassRegistry());
void nameInstructions(Function &F) {
for (auto &Arg : F.args()) {
if (!Arg.hasName())
Arg.setName("arg");
}
for (BasicBlock &BB : F) {
if (!BB.hasName())
BB.setName("bb");
for (Instruction &I : BB) {
if (!I.hasName() && !I.getType()->isVoidTy())
I.setName("i");
}
}
}
void getAnalysisUsage(AnalysisUsage &Info) const override {
Info.setPreservesAll();
}
struct InstNamer : public FunctionPass {
static char ID; // Pass identification, replacement for typeid
InstNamer() : FunctionPass(ID) {
initializeInstNamerPass(*PassRegistry::getPassRegistry());
}
bool runOnFunction(Function &F) override {
for (auto &Arg : F.args())
if (!Arg.hasName())
Arg.setName("arg");
void getAnalysisUsage(AnalysisUsage &Info) const override {
Info.setPreservesAll();
}
for (BasicBlock &BB : F) {
if (!BB.hasName())
BB.setName("bb");
for (Instruction &I : BB)
if (!I.hasName() && !I.getType()->isVoidTy())
I.setName("i");
}
return true;
}
};
bool runOnFunction(Function &F) override {
nameInstructions(F);
return true;
}
};
char InstNamer::ID = 0;
}
} // namespace
INITIALIZE_PASS(InstNamer, "instnamer",
"Assign names to anonymous instructions", false, false)
@ -61,3 +70,9 @@ char &llvm::InstructionNamerID = InstNamer::ID;
FunctionPass *llvm::createInstructionNamerPass() {
return new InstNamer();
}
PreservedAnalyses InstructionNamerPass::run(Function &F,
FunctionAnalysisManager &FAM) {
nameInstructions(F);
return PreservedAnalyses::all();
}

View File

@ -1,4 +1,5 @@
; RUN: opt -S -instnamer < %s | FileCheck %s
; RUN: opt -S -passes=instnamer < %s | FileCheck %s
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"