LLVM  10.0.0svn
MIRNamerPass.cpp
Go to the documentation of this file.
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.
12 //
13 // Basic Usage:
14 //
15 // llc -o - -run-pass mir-namer example.mir
16 //
17 //===----------------------------------------------------------------------===//
18 
19 #include "MIRVRegNamerUtils.h"
21 #include "llvm/ADT/STLExtras.h"
25 #include "llvm/CodeGen/Passes.h"
26 
27 using namespace llvm;
28 
29 namespace llvm {
30 extern char &MIRNamerID;
31 } // namespace llvm
32 
33 #define DEBUG_TYPE "mir-namer"
34 
35 namespace {
36 
37 class MIRNamer : public MachineFunctionPass {
38 public:
39  static char ID;
40  MIRNamer() : MachineFunctionPass(ID) {}
41 
42  StringRef getPassName() const override {
43  return "Rename virtual register operands";
44  }
45 
46  void getAnalysisUsage(AnalysisUsage &AU) const override {
47  AU.setPreservesCFG();
49  }
50 
51  bool runOnMachineFunction(MachineFunction &MF) override {
52  bool Changed = false;
53 
54  if (MF.empty())
55  return Changed;
56 
57  NamedVRegCursor NVC(MF.getRegInfo());
58 
60  for (auto &MBB : RPOT)
61  Changed |= NVC.renameVRegs(MBB);
62 
63  return Changed;
64  }
65 };
66 
67 } // end anonymous namespace
68 
69 char MIRNamer::ID;
70 
72 
73 INITIALIZE_PASS_BEGIN(MIRNamer, "mir-namer", "Rename Register Operands", false,
74  false)
75 
76 INITIALIZE_PASS_END(MIRNamer, "mir-namer", "Rename Register Operands", false,
77  false)
This class represents lattice values for constants.
Definition: AllocatorList.h:23
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
mir namer
mir Rename Register Operands
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Represent the analysis usage information of a pass.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition: Pass.cpp:301
NamedVRegCursor - The cursor is an object that keeps track of what the next vreg name should be...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
char & MIRNamerID
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
INITIALIZE_PASS_BEGIN(MIRNamer, "mir-namer", "Rename Register Operands", false, false) INITIALIZE_PASS_END(MIRNamer