LLVM  14.0.0git
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 #include "llvm/InitializePasses.h"
27 
28 using namespace llvm;
29 
30 namespace llvm {
31 extern char &MIRNamerID;
32 } // namespace llvm
33 
34 #define DEBUG_TYPE "mir-namer"
35 
36 namespace {
37 
38 class MIRNamer : public MachineFunctionPass {
39 public:
40  static char ID;
41  MIRNamer() : MachineFunctionPass(ID) {}
42 
43  StringRef getPassName() const override {
44  return "Rename virtual register operands";
45  }
46 
47  void getAnalysisUsage(AnalysisUsage &AU) const override {
48  AU.setPreservesCFG();
50  }
51 
52  bool runOnMachineFunction(MachineFunction &MF) override {
53  bool Changed = false;
54 
55  if (MF.empty())
56  return Changed;
57 
58  VRegRenamer Renamer(MF.getRegInfo());
59 
60  unsigned BBIndex = 0;
62  for (auto &MBB : RPOT)
63  Changed |= Renamer.renameVRegs(MBB, BBIndex++);
64 
65  return Changed;
66  }
67 };
68 
69 } // end anonymous namespace
70 
71 char MIRNamer::ID;
72 
74 
75 INITIALIZE_PASS_BEGIN(MIRNamer, "mir-namer", "Rename Register Operands", false,
76  false)
77 
78 INITIALIZE_PASS_END(MIRNamer, "mir-namer", "Rename Register Operands", false,
79  false)
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
MIRVRegNamerUtils.h
namer
mir namer
Definition: MIRNamerPass.cpp:78
llvm::MachineFunctionPass
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Definition: MachineFunctionPass.h:30
INITIALIZE_PASS_BEGIN
INITIALIZE_PASS_BEGIN(MIRNamer, "mir-namer", "Rename Register Operands", false, false) INITIALIZE_PASS_END(MIRNamer
STLExtras.h
llvm::MachineFunctionPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition: MachineFunctionPass.cpp:102
MachineRegisterInfo.h
llvm::MachineFunction::getRegInfo
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Definition: MachineFunction.h:640
llvm::VRegRenamer::renameVRegs
bool renameVRegs(MachineBasicBlock *MBB, unsigned BBNum)
Same as the above, but sets a BBNum depending on BB traversal that will be used as prefix for the vre...
Definition: MIRVRegNamerUtils.h:89
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
false
Definition: StackSlotColoring.cpp:142
llvm::MIRNamerID
char & MIRNamerID
Definition: MIRNamerPass.cpp:73
llvm::MachineFunction::begin
iterator begin()
Definition: MachineFunction.h:812
INITIALIZE_PASS_END
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:58
Operands
mir Rename Register Operands
Definition: MIRNamerPass.cpp:78
Passes.h
MachineFunctionPass.h
llvm::MachineFunction
Definition: MachineFunction.h:234
llvm::AnalysisUsage::setPreservesCFG
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition: Pass.cpp:253
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::VRegRenamer
VRegRenamer - This class is used for renaming vregs in a machine basic block according to semantics o...
Definition: MIRVRegNamerUtils.h:34
llvm::ReversePostOrderTraversal
Definition: PostOrderIterator.h:290
PostOrderIterator.h
MachineInstrBuilder.h
llvm::MachineFunction::empty
bool empty() const
Definition: MachineFunction.h:823
InitializePasses.h
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37