[WebAssembly] Add new target feature in support of 'extended-const' proposal
[llvm-project.git] / llvm / lib / CodeGen / MIRNamerPass.cpp
blob9f61dd9ef243a15ef3bd4fcc66dd3ebccc901310
1 //===----------------------- MIRNamer.cpp - MIR Namer ---------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // The purpose of this pass is to rename virtual register operands with the goal
10 // of making it easier to author easier to read tests for MIR. This pass reuses
11 // the vreg renamer used by MIRCanonicalizerPass.
13 // Basic Usage:
15 // llc -o - -run-pass mir-namer example.mir
17 //===----------------------------------------------------------------------===//
19 #include "MIRVRegNamerUtils.h"
20 #include "llvm/ADT/PostOrderIterator.h"
21 #include "llvm/ADT/STLExtras.h"
22 #include "llvm/CodeGen/MachineFunctionPass.h"
23 #include "llvm/CodeGen/MachineInstrBuilder.h"
24 #include "llvm/CodeGen/MachineRegisterInfo.h"
25 #include "llvm/CodeGen/Passes.h"
26 #include "llvm/InitializePasses.h"
28 using namespace llvm;
30 namespace llvm {
31 extern char &MIRNamerID;
32 } // namespace llvm
34 #define DEBUG_TYPE "mir-namer"
36 namespace {
38 class MIRNamer : public MachineFunctionPass {
39 public:
40 static char ID;
41 MIRNamer() : MachineFunctionPass(ID) {}
43 StringRef getPassName() const override {
44 return "Rename virtual register operands";
47 void getAnalysisUsage(AnalysisUsage &AU) const override {
48 AU.setPreservesCFG();
49 MachineFunctionPass::getAnalysisUsage(AU);
52 bool runOnMachineFunction(MachineFunction &MF) override {
53 bool Changed = false;
55 if (MF.empty())
56 return Changed;
58 VRegRenamer Renamer(MF.getRegInfo());
60 unsigned BBIndex = 0;
61 ReversePostOrderTraversal<MachineBasicBlock *> RPOT(&*MF.begin());
62 for (auto &MBB : RPOT)
63 Changed |= Renamer.renameVRegs(MBB, BBIndex++);
65 return Changed;
69 } // end anonymous namespace
71 char MIRNamer::ID;
73 char &llvm::MIRNamerID = MIRNamer::ID;
75 INITIALIZE_PASS_BEGIN(MIRNamer, "mir-namer", "Rename Register Operands", false,
76 false)
78 INITIALIZE_PASS_END(MIRNamer, "mir-namer", "Rename Register Operands", false,
79 false)