[x86] fix assert with horizontal math + broadcast of vector (PR43402)
[llvm-core.git] / lib / CodeGen / MIRVRegNamerUtils.h
blobc5b52a9685380e3f8610787e2561ad3c7114c9bd
2 //===------------ MIRVRegNamerUtils.h - MIR VReg Renaming Utilities -------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // The purpose of these utilities is to abstract out parts of the MIRCanon pass
11 // that are responsible for renaming virtual registers with the purpose of
12 // sharing code with a MIRVRegNamer pass that could be the analog of the
13 // opt -instnamer pass.
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_LIB_CODEGEN_MIRVREGNAMERUTILS_H
18 #define LLVM_LIB_CODEGEN_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/Support/raw_ostream.h"
28 #include <queue>
30 namespace llvm {
32 /// NamedVRegCursor - The cursor is an object that keeps track of what the next
33 /// vreg name should be. It does book keeping to determine when to skip the
34 /// index value and by how much, or if the next vreg name should be an increment
35 /// from the previous.
36 class NamedVRegCursor {
37 MachineRegisterInfo &MRI;
39 /// virtualVRegNumber - Book keeping of the last vreg position.
40 unsigned virtualVRegNumber;
42 /// SkipGapSize - Used to calculate a modulo amount to skip by after every
43 /// sequence of instructions starting from a given side-effecting
44 /// MachineInstruction for a given MachineBasicBlock. The general idea is that
45 /// for a given program compiled with two different opt pipelines, there
46 /// shouldn't be greater than SkipGapSize difference in how many vregs are in
47 /// play between the two and for every def-use graph of vregs we rename we
48 /// will round up to the next SkipGapSize'th number so that we have a high
49 /// change of landing on the same name for two given matching side-effects
50 /// for the two compilation outcomes.
51 const unsigned SkipGapSize;
53 /// RenamedInOtherBB - VRegs that we already renamed: ie breadcrumbs.
54 std::vector<Register> RenamedInOtherBB;
56 public:
57 NamedVRegCursor() = delete;
58 /// 1000 for the SkipGapSize was a good heuristic at the time of the writing
59 /// of the MIRCanonicalizerPass. Adjust as needed.
60 NamedVRegCursor(MachineRegisterInfo &MRI, unsigned SkipGapSize = 1000)
61 : MRI(MRI), virtualVRegNumber(0), SkipGapSize(SkipGapSize) {}
63 /// SkipGapSize - Skips modulo a gap value of indices. Indices are used to
64 /// produce the next vreg name.
65 void skipVRegs();
67 unsigned getVirtualVReg() const { return virtualVRegNumber; }
69 /// incrementVirtualVReg - This increments an index value that us used to
70 /// create a new vreg name. This is not a Register.
71 unsigned incrementVirtualVReg(unsigned incr = 1) {
72 virtualVRegNumber += incr;
73 return virtualVRegNumber;
76 /// createVirtualRegister - Given an existing vreg, create a named vreg to
77 /// take its place.
78 unsigned createVirtualRegister(unsigned VReg);
80 /// renameVRegs - For a given MachineBasicBlock, scan for side-effecting
81 /// instructions, walk the def-use from each side-effecting root (in sorted
82 /// root order) and rename the encountered vregs in the def-use graph in a
83 /// canonical ordering. This method maintains book keeping for which vregs
84 /// were already renamed in RenamedInOtherBB.
85 // @return changed
86 bool renameVRegs(MachineBasicBlock *MBB);
89 } // namespace llvm
91 #endif