mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01:00
Port -instnamer to NPM
Some clang tests use this. Reviewed By: akhuang Differential Revision: https://reviews.llvm.org/D89931
This commit is contained in:
parent
8b9f3c8506
commit
e666973053
20
include/llvm/Transforms/Utils/InstructionNamer.h
Normal file
20
include/llvm/Transforms/Utils/InstructionNamer.h
Normal 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
|
@ -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"
|
||||
|
@ -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())
|
||||
|
@ -13,15 +13,35 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#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 {
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct InstNamer : public FunctionPass {
|
||||
static char ID; // Pass identification, replacement for typeid
|
||||
InstNamer() : FunctionPass(ID) {
|
||||
initializeInstNamerPass(*PassRegistry::getPassRegistry());
|
||||
@ -32,24 +52,13 @@ namespace {
|
||||
}
|
||||
|
||||
bool runOnFunction(Function &F) override {
|
||||
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");
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user