1fe723b9aSBill Schmidt //===----------- PPCVSXSwapRemoval.cpp - Remove VSX LE Swaps -------------===//
2fe723b9aSBill Schmidt //
3fe723b9aSBill Schmidt //                     The LLVM Compiler Infrastructure
4fe723b9aSBill Schmidt //
5fe723b9aSBill Schmidt // This file is distributed under the University of Illinois Open Source
6fe723b9aSBill Schmidt // License. See LICENSE.TXT for details.
7fe723b9aSBill Schmidt //
8fe723b9aSBill Schmidt //===---------------------------------------------------------------------===//
9fe723b9aSBill Schmidt //
10fe723b9aSBill Schmidt // This pass analyzes vector computations and removes unnecessary
11fe723b9aSBill Schmidt // doubleword swaps (xxswapd instructions).  This pass is performed
12fe723b9aSBill Schmidt // only for little-endian VSX code generation.
13fe723b9aSBill Schmidt //
14fe723b9aSBill Schmidt // For this specific case, loads and stores of v4i32, v4f32, v2i64,
15fe723b9aSBill Schmidt // and v2f64 vectors are inefficient.  These are implemented using
16fe723b9aSBill Schmidt // the lxvd2x and stxvd2x instructions, which invert the order of
17fe723b9aSBill Schmidt // doublewords in a vector register.  Thus code generation inserts
18fe723b9aSBill Schmidt // an xxswapd after each such load, and prior to each such store.
19fe723b9aSBill Schmidt //
20fe723b9aSBill Schmidt // The extra xxswapd instructions reduce performance.  The purpose
21fe723b9aSBill Schmidt // of this pass is to reduce the number of xxswapd instructions
22fe723b9aSBill Schmidt // required for correctness.
23fe723b9aSBill Schmidt //
24fe723b9aSBill Schmidt // The primary insight is that much code that operates on vectors
25fe723b9aSBill Schmidt // does not care about the relative order of elements in a register,
26fe723b9aSBill Schmidt // so long as the correct memory order is preserved.  If we have a
27fe723b9aSBill Schmidt // computation where all input values are provided by lxvd2x/xxswapd,
28fe723b9aSBill Schmidt // all outputs are stored using xxswapd/lxvd2x, and all intermediate
29fe723b9aSBill Schmidt // computations are lane-insensitive (independent of element order),
30fe723b9aSBill Schmidt // then all the xxswapd instructions associated with the loads and
31fe723b9aSBill Schmidt // stores may be removed without changing observable semantics.
32fe723b9aSBill Schmidt //
33fe723b9aSBill Schmidt // This pass uses standard equivalence class infrastructure to create
34fe723b9aSBill Schmidt // maximal webs of computations fitting the above description.  Each
35fe723b9aSBill Schmidt // such web is then optimized by removing its unnecessary xxswapd
36fe723b9aSBill Schmidt // instructions.
37fe723b9aSBill Schmidt //
38fe723b9aSBill Schmidt // There are some lane-sensitive operations for which we can still
39fe723b9aSBill Schmidt // permit the optimization, provided we modify those operations
40fe723b9aSBill Schmidt // accordingly.  Such operations are identified as using "special
41fe723b9aSBill Schmidt // handling" within this module.
42fe723b9aSBill Schmidt //
43fe723b9aSBill Schmidt //===---------------------------------------------------------------------===//
44fe723b9aSBill Schmidt 
45fe723b9aSBill Schmidt #include "PPCInstrInfo.h"
46fe723b9aSBill Schmidt #include "PPC.h"
47fe723b9aSBill Schmidt #include "PPCInstrBuilder.h"
48fe723b9aSBill Schmidt #include "PPCTargetMachine.h"
49fe723b9aSBill Schmidt #include "llvm/ADT/DenseMap.h"
50fe723b9aSBill Schmidt #include "llvm/ADT/EquivalenceClasses.h"
51fe723b9aSBill Schmidt #include "llvm/CodeGen/MachineFunctionPass.h"
52fe723b9aSBill Schmidt #include "llvm/CodeGen/MachineInstrBuilder.h"
53fe723b9aSBill Schmidt #include "llvm/CodeGen/MachineRegisterInfo.h"
54fe723b9aSBill Schmidt #include "llvm/Support/Debug.h"
55fe723b9aSBill Schmidt #include "llvm/Support/Format.h"
56fe723b9aSBill Schmidt #include "llvm/Support/raw_ostream.h"
57fe723b9aSBill Schmidt 
58fe723b9aSBill Schmidt using namespace llvm;
59fe723b9aSBill Schmidt 
60fe723b9aSBill Schmidt #define DEBUG_TYPE "ppc-vsx-swaps"
61fe723b9aSBill Schmidt 
62fe723b9aSBill Schmidt namespace llvm {
63fe723b9aSBill Schmidt   void initializePPCVSXSwapRemovalPass(PassRegistry&);
64fe723b9aSBill Schmidt }
65fe723b9aSBill Schmidt 
66fe723b9aSBill Schmidt namespace {
67fe723b9aSBill Schmidt 
68fe723b9aSBill Schmidt // A PPCVSXSwapEntry is created for each machine instruction that
69fe723b9aSBill Schmidt // is relevant to a vector computation.
70fe723b9aSBill Schmidt struct PPCVSXSwapEntry {
71fe723b9aSBill Schmidt   // Pointer to the instruction.
72fe723b9aSBill Schmidt   MachineInstr *VSEMI;
73fe723b9aSBill Schmidt 
74fe723b9aSBill Schmidt   // Unique ID (position in the swap vector).
75fe723b9aSBill Schmidt   int VSEId;
76fe723b9aSBill Schmidt 
77fe723b9aSBill Schmidt   // Attributes of this node.
78fe723b9aSBill Schmidt   unsigned int IsLoad : 1;
79fe723b9aSBill Schmidt   unsigned int IsStore : 1;
80fe723b9aSBill Schmidt   unsigned int IsSwap : 1;
81fe723b9aSBill Schmidt   unsigned int MentionsPhysVR : 1;
82fe723b9aSBill Schmidt   unsigned int IsSwappable : 1;
8315deb803SBill Schmidt   unsigned int MentionsPartialVR : 1;
84fe723b9aSBill Schmidt   unsigned int SpecialHandling : 3;
85fe723b9aSBill Schmidt   unsigned int WebRejected : 1;
86fe723b9aSBill Schmidt   unsigned int WillRemove : 1;
87fe723b9aSBill Schmidt };
88fe723b9aSBill Schmidt 
89fe723b9aSBill Schmidt enum SHValues {
90fe723b9aSBill Schmidt   SH_NONE = 0,
91fe723b9aSBill Schmidt   SH_EXTRACT,
92fe723b9aSBill Schmidt   SH_INSERT,
93fe723b9aSBill Schmidt   SH_NOSWAP_LD,
94fe723b9aSBill Schmidt   SH_NOSWAP_ST,
9515deb803SBill Schmidt   SH_SPLAT,
9615deb803SBill Schmidt   SH_XXPERMDI,
972be8054bSBill Schmidt   SH_COPYWIDEN
98fe723b9aSBill Schmidt };
99fe723b9aSBill Schmidt 
100fe723b9aSBill Schmidt struct PPCVSXSwapRemoval : public MachineFunctionPass {
101fe723b9aSBill Schmidt 
102fe723b9aSBill Schmidt   static char ID;
103fe723b9aSBill Schmidt   const PPCInstrInfo *TII;
104fe723b9aSBill Schmidt   MachineFunction *MF;
105fe723b9aSBill Schmidt   MachineRegisterInfo *MRI;
106fe723b9aSBill Schmidt 
107fe723b9aSBill Schmidt   // Swap entries are allocated in a vector for better performance.
108fe723b9aSBill Schmidt   std::vector<PPCVSXSwapEntry> SwapVector;
109fe723b9aSBill Schmidt 
110fe723b9aSBill Schmidt   // A mapping is maintained between machine instructions and
111fe723b9aSBill Schmidt   // their swap entries.  The key is the address of the MI.
112fe723b9aSBill Schmidt   DenseMap<MachineInstr*, int> SwapMap;
113fe723b9aSBill Schmidt 
114fe723b9aSBill Schmidt   // Equivalence classes are used to gather webs of related computation.
115fe723b9aSBill Schmidt   // Swap entries are represented by their VSEId fields.
116fe723b9aSBill Schmidt   EquivalenceClasses<int> *EC;
117fe723b9aSBill Schmidt 
118fe723b9aSBill Schmidt   PPCVSXSwapRemoval() : MachineFunctionPass(ID) {
119fe723b9aSBill Schmidt     initializePPCVSXSwapRemovalPass(*PassRegistry::getPassRegistry());
120fe723b9aSBill Schmidt   }
121fe723b9aSBill Schmidt 
122fe723b9aSBill Schmidt private:
123fe723b9aSBill Schmidt   // Initialize data structures.
124fe723b9aSBill Schmidt   void initialize(MachineFunction &MFParm);
125fe723b9aSBill Schmidt 
126fe723b9aSBill Schmidt   // Walk the machine instructions to gather vector usage information.
127fe723b9aSBill Schmidt   // Return true iff vector mentions are present.
128fe723b9aSBill Schmidt   bool gatherVectorInstructions();
129fe723b9aSBill Schmidt 
130fe723b9aSBill Schmidt   // Add an entry to the swap vector and swap map.
131fe723b9aSBill Schmidt   int addSwapEntry(MachineInstr *MI, PPCVSXSwapEntry &SwapEntry);
132fe723b9aSBill Schmidt 
133fe723b9aSBill Schmidt   // Hunt backwards through COPY and SUBREG_TO_REG chains for a
134fe723b9aSBill Schmidt   // source register.  VecIdx indicates the swap vector entry to
135fe723b9aSBill Schmidt   // mark as mentioning a physical register if the search leads
136fe723b9aSBill Schmidt   // to one.
137fe723b9aSBill Schmidt   unsigned lookThruCopyLike(unsigned SrcReg, unsigned VecIdx);
138fe723b9aSBill Schmidt 
139fe723b9aSBill Schmidt   // Generate equivalence classes for related computations (webs).
140fe723b9aSBill Schmidt   void formWebs();
141fe723b9aSBill Schmidt 
142fe723b9aSBill Schmidt   // Analyze webs and determine those that cannot be optimized.
143fe723b9aSBill Schmidt   void recordUnoptimizableWebs();
144fe723b9aSBill Schmidt 
145fe723b9aSBill Schmidt   // Record which swap instructions can be safely removed.
146fe723b9aSBill Schmidt   void markSwapsForRemoval();
147fe723b9aSBill Schmidt 
148fe723b9aSBill Schmidt   // Remove swaps and update other instructions requiring special
149fe723b9aSBill Schmidt   // handling.  Return true iff any changes are made.
150fe723b9aSBill Schmidt   bool removeSwaps();
151fe723b9aSBill Schmidt 
1522be8054bSBill Schmidt   // Insert a swap instruction from SrcReg to DstReg at the given
1532be8054bSBill Schmidt   // InsertPoint.
1542be8054bSBill Schmidt   void insertSwap(MachineInstr *MI, MachineBasicBlock::iterator InsertPoint,
1552be8054bSBill Schmidt                   unsigned DstReg, unsigned SrcReg);
1562be8054bSBill Schmidt 
157fe723b9aSBill Schmidt   // Update instructions requiring special handling.
158fe723b9aSBill Schmidt   void handleSpecialSwappables(int EntryIdx);
159fe723b9aSBill Schmidt 
160fe723b9aSBill Schmidt   // Dump a description of the entries in the swap vector.
161fe723b9aSBill Schmidt   void dumpSwapVector();
162fe723b9aSBill Schmidt 
163fe723b9aSBill Schmidt   // Return true iff the given register is in the given class.
164fe723b9aSBill Schmidt   bool isRegInClass(unsigned Reg, const TargetRegisterClass *RC) {
165fe723b9aSBill Schmidt     if (TargetRegisterInfo::isVirtualRegister(Reg))
166fe723b9aSBill Schmidt       return RC->hasSubClassEq(MRI->getRegClass(Reg));
167175a7cbfSAlexander Kornienko     return RC->contains(Reg);
168fe723b9aSBill Schmidt   }
169fe723b9aSBill Schmidt 
170fe723b9aSBill Schmidt   // Return true iff the given register is a full vector register.
171fe723b9aSBill Schmidt   bool isVecReg(unsigned Reg) {
172fe723b9aSBill Schmidt     return (isRegInClass(Reg, &PPC::VSRCRegClass) ||
173fe723b9aSBill Schmidt             isRegInClass(Reg, &PPC::VRRCRegClass));
174fe723b9aSBill Schmidt   }
175fe723b9aSBill Schmidt 
17615deb803SBill Schmidt   // Return true iff the given register is a partial vector register.
17715deb803SBill Schmidt   bool isScalarVecReg(unsigned Reg) {
17815deb803SBill Schmidt     return (isRegInClass(Reg, &PPC::VSFRCRegClass) ||
17915deb803SBill Schmidt             isRegInClass(Reg, &PPC::VSSRCRegClass));
18015deb803SBill Schmidt   }
18115deb803SBill Schmidt 
18215deb803SBill Schmidt   // Return true iff the given register mentions all or part of a
18315deb803SBill Schmidt   // vector register.  Also sets Partial to true if the mention
18415deb803SBill Schmidt   // is for just the floating-point register overlap of the register.
18515deb803SBill Schmidt   bool isAnyVecReg(unsigned Reg, bool &Partial) {
18615deb803SBill Schmidt     if (isScalarVecReg(Reg))
18715deb803SBill Schmidt       Partial = true;
18815deb803SBill Schmidt     return isScalarVecReg(Reg) || isVecReg(Reg);
18915deb803SBill Schmidt   }
19015deb803SBill Schmidt 
191fe723b9aSBill Schmidt public:
192fe723b9aSBill Schmidt   // Main entry point for this pass.
193fe723b9aSBill Schmidt   bool runOnMachineFunction(MachineFunction &MF) override {
194*289bd5f6SAndrew Kaylor     if (skipFunction(*MF.getFunction()))
195*289bd5f6SAndrew Kaylor       return false;
196*289bd5f6SAndrew Kaylor 
197fe723b9aSBill Schmidt     // If we don't have VSX on the subtarget, don't do anything.
198fe723b9aSBill Schmidt     const PPCSubtarget &STI = MF.getSubtarget<PPCSubtarget>();
199fe723b9aSBill Schmidt     if (!STI.hasVSX())
200fe723b9aSBill Schmidt       return false;
201fe723b9aSBill Schmidt 
202fe723b9aSBill Schmidt     bool Changed = false;
203fe723b9aSBill Schmidt     initialize(MF);
204fe723b9aSBill Schmidt 
205fe723b9aSBill Schmidt     if (gatherVectorInstructions()) {
206fe723b9aSBill Schmidt       formWebs();
207fe723b9aSBill Schmidt       recordUnoptimizableWebs();
208fe723b9aSBill Schmidt       markSwapsForRemoval();
209fe723b9aSBill Schmidt       Changed = removeSwaps();
210fe723b9aSBill Schmidt     }
211fe723b9aSBill Schmidt 
212fe723b9aSBill Schmidt     // FIXME: See the allocation of EC in initialize().
213fe723b9aSBill Schmidt     delete EC;
214fe723b9aSBill Schmidt     return Changed;
215fe723b9aSBill Schmidt   }
216fe723b9aSBill Schmidt };
217fe723b9aSBill Schmidt 
218fe723b9aSBill Schmidt // Initialize data structures for this pass.  In particular, clear the
219fe723b9aSBill Schmidt // swap vector and allocate the equivalence class mapping before
220fe723b9aSBill Schmidt // processing each function.
221fe723b9aSBill Schmidt void PPCVSXSwapRemoval::initialize(MachineFunction &MFParm) {
222fe723b9aSBill Schmidt   MF = &MFParm;
223fe723b9aSBill Schmidt   MRI = &MF->getRegInfo();
2248ed7cec1SBill Schmidt   TII = MF->getSubtarget<PPCSubtarget>().getInstrInfo();
225fe723b9aSBill Schmidt 
226fe723b9aSBill Schmidt   // An initial vector size of 256 appears to work well in practice.
227fe723b9aSBill Schmidt   // Small/medium functions with vector content tend not to incur a
228fe723b9aSBill Schmidt   // reallocation at this size.  Three of the vector tests in
229fe723b9aSBill Schmidt   // projects/test-suite reallocate, which seems like a reasonable rate.
230fe723b9aSBill Schmidt   const int InitialVectorSize(256);
231fe723b9aSBill Schmidt   SwapVector.clear();
232fe723b9aSBill Schmidt   SwapVector.reserve(InitialVectorSize);
233fe723b9aSBill Schmidt 
234fe723b9aSBill Schmidt   // FIXME: Currently we allocate EC each time because we don't have
235fe723b9aSBill Schmidt   // access to the set representation on which to call clear().  Should
236fe723b9aSBill Schmidt   // consider adding a clear() method to the EquivalenceClasses class.
237fe723b9aSBill Schmidt   EC = new EquivalenceClasses<int>;
238fe723b9aSBill Schmidt }
239fe723b9aSBill Schmidt 
240fe723b9aSBill Schmidt // Create an entry in the swap vector for each instruction that mentions
241fe723b9aSBill Schmidt // a full vector register, recording various characteristics of the
242fe723b9aSBill Schmidt // instructions there.
243fe723b9aSBill Schmidt bool PPCVSXSwapRemoval::gatherVectorInstructions() {
244fe723b9aSBill Schmidt   bool RelevantFunction = false;
245fe723b9aSBill Schmidt 
246fe723b9aSBill Schmidt   for (MachineBasicBlock &MBB : *MF) {
247fe723b9aSBill Schmidt     for (MachineInstr &MI : MBB) {
248fe723b9aSBill Schmidt 
24932fd189dSBill Schmidt       if (MI.isDebugValue())
25032fd189dSBill Schmidt         continue;
25132fd189dSBill Schmidt 
252fe723b9aSBill Schmidt       bool RelevantInstr = false;
25315deb803SBill Schmidt       bool Partial = false;
254fe723b9aSBill Schmidt 
255fe723b9aSBill Schmidt       for (const MachineOperand &MO : MI.operands()) {
256fe723b9aSBill Schmidt         if (!MO.isReg())
257fe723b9aSBill Schmidt           continue;
258fe723b9aSBill Schmidt         unsigned Reg = MO.getReg();
25915deb803SBill Schmidt         if (isAnyVecReg(Reg, Partial)) {
260fe723b9aSBill Schmidt           RelevantInstr = true;
261fe723b9aSBill Schmidt           break;
262fe723b9aSBill Schmidt         }
263fe723b9aSBill Schmidt       }
264fe723b9aSBill Schmidt 
265fe723b9aSBill Schmidt       if (!RelevantInstr)
266fe723b9aSBill Schmidt         continue;
267fe723b9aSBill Schmidt 
268fe723b9aSBill Schmidt       RelevantFunction = true;
269fe723b9aSBill Schmidt 
270fe723b9aSBill Schmidt       // Create a SwapEntry initialized to zeros, then fill in the
271fe723b9aSBill Schmidt       // instruction and ID fields before pushing it to the back
272fe723b9aSBill Schmidt       // of the swap vector.
273fe723b9aSBill Schmidt       PPCVSXSwapEntry SwapEntry{};
274fe723b9aSBill Schmidt       int VecIdx = addSwapEntry(&MI, SwapEntry);
275fe723b9aSBill Schmidt 
276fe723b9aSBill Schmidt       switch(MI.getOpcode()) {
277fe723b9aSBill Schmidt       default:
278fe723b9aSBill Schmidt         // Unless noted otherwise, an instruction is considered
279fe723b9aSBill Schmidt         // safe for the optimization.  There are a large number of
280fe723b9aSBill Schmidt         // such true-SIMD instructions (all vector math, logical,
28115deb803SBill Schmidt         // select, compare, etc.).  However, if the instruction
28215deb803SBill Schmidt         // mentions a partial vector register and does not have
28315deb803SBill Schmidt         // special handling defined, it is not swappable.
28415deb803SBill Schmidt         if (Partial)
28515deb803SBill Schmidt           SwapVector[VecIdx].MentionsPartialVR = 1;
28615deb803SBill Schmidt         else
287fe723b9aSBill Schmidt           SwapVector[VecIdx].IsSwappable = 1;
288fe723b9aSBill Schmidt         break;
2897c691feeSBill Schmidt       case PPC::XXPERMDI: {
290fe723b9aSBill Schmidt         // This is a swap if it is of the form XXPERMDI t, s, s, 2.
291fe723b9aSBill Schmidt         // Unfortunately, MachineCSE ignores COPY and SUBREG_TO_REG, so we
292fe723b9aSBill Schmidt         // can also see XXPERMDI t, SUBREG_TO_REG(s), SUBREG_TO_REG(s), 2,
293fe723b9aSBill Schmidt         // for example.  We have to look through chains of COPY and
294fe723b9aSBill Schmidt         // SUBREG_TO_REG to find the real source value for comparison.
295fe723b9aSBill Schmidt         // If the real source value is a physical register, then mark the
296fe723b9aSBill Schmidt         // XXPERMDI as mentioning a physical register.
2977c691feeSBill Schmidt         int immed = MI.getOperand(3).getImm();
2987c691feeSBill Schmidt         if (immed == 2) {
299fe723b9aSBill Schmidt           unsigned trueReg1 = lookThruCopyLike(MI.getOperand(1).getReg(),
300fe723b9aSBill Schmidt                                                VecIdx);
301fe723b9aSBill Schmidt           unsigned trueReg2 = lookThruCopyLike(MI.getOperand(2).getReg(),
302fe723b9aSBill Schmidt                                                VecIdx);
303fe723b9aSBill Schmidt           if (trueReg1 == trueReg2)
304fe723b9aSBill Schmidt             SwapVector[VecIdx].IsSwap = 1;
30515deb803SBill Schmidt           else {
30615deb803SBill Schmidt             // We can still handle these if the two registers are not
30715deb803SBill Schmidt             // identical, by adjusting the form of the XXPERMDI.
30815deb803SBill Schmidt             SwapVector[VecIdx].IsSwappable = 1;
30915deb803SBill Schmidt             SwapVector[VecIdx].SpecialHandling = SHValues::SH_XXPERMDI;
310fe723b9aSBill Schmidt           }
3117c691feeSBill Schmidt         // This is a doubleword splat if it is of the form
3127c691feeSBill Schmidt         // XXPERMDI t, s, s, 0 or XXPERMDI t, s, s, 3.  As above we
3137c691feeSBill Schmidt         // must look through chains of copy-likes to find the source
3147c691feeSBill Schmidt         // register.  We turn off the marking for mention of a physical
3157c691feeSBill Schmidt         // register, because splatting it is safe; the optimization
31615deb803SBill Schmidt         // will not swap the value in the physical register.  Whether
31715deb803SBill Schmidt         // or not the two input registers are identical, we can handle
31815deb803SBill Schmidt         // these by adjusting the form of the XXPERMDI.
31915deb803SBill Schmidt         } else if (immed == 0 || immed == 3) {
32015deb803SBill Schmidt 
32115deb803SBill Schmidt           SwapVector[VecIdx].IsSwappable = 1;
32215deb803SBill Schmidt           SwapVector[VecIdx].SpecialHandling = SHValues::SH_XXPERMDI;
32315deb803SBill Schmidt 
3247c691feeSBill Schmidt           unsigned trueReg1 = lookThruCopyLike(MI.getOperand(1).getReg(),
3257c691feeSBill Schmidt                                                VecIdx);
3267c691feeSBill Schmidt           unsigned trueReg2 = lookThruCopyLike(MI.getOperand(2).getReg(),
3277c691feeSBill Schmidt                                                VecIdx);
32815deb803SBill Schmidt           if (trueReg1 == trueReg2)
3297c691feeSBill Schmidt             SwapVector[VecIdx].MentionsPhysVR = 0;
33015deb803SBill Schmidt 
33115deb803SBill Schmidt         } else {
33215deb803SBill Schmidt           // We can still handle these by adjusting the form of the XXPERMDI.
33315deb803SBill Schmidt           SwapVector[VecIdx].IsSwappable = 1;
33415deb803SBill Schmidt           SwapVector[VecIdx].SpecialHandling = SHValues::SH_XXPERMDI;
3357c691feeSBill Schmidt         }
336fe723b9aSBill Schmidt         break;
3377c691feeSBill Schmidt       }
338fe723b9aSBill Schmidt       case PPC::LVX:
339fe723b9aSBill Schmidt         // Non-permuting loads are currently unsafe.  We can use special
340fe723b9aSBill Schmidt         // handling for this in the future.  By not marking these as
341fe723b9aSBill Schmidt         // IsSwap, we ensure computations containing them will be rejected
342fe723b9aSBill Schmidt         // for now.
343fe723b9aSBill Schmidt         SwapVector[VecIdx].IsLoad = 1;
344fe723b9aSBill Schmidt         break;
345fe723b9aSBill Schmidt       case PPC::LXVD2X:
346fe723b9aSBill Schmidt       case PPC::LXVW4X:
347fe723b9aSBill Schmidt         // Permuting loads are marked as both load and swap, and are
348fe723b9aSBill Schmidt         // safe for optimization.
349fe723b9aSBill Schmidt         SwapVector[VecIdx].IsLoad = 1;
350fe723b9aSBill Schmidt         SwapVector[VecIdx].IsSwap = 1;
351fe723b9aSBill Schmidt         break;
3522be8054bSBill Schmidt       case PPC::LXSDX:
3532be8054bSBill Schmidt       case PPC::LXSSPX:
3542be8054bSBill Schmidt         // A load of a floating-point value into the high-order half of
3552be8054bSBill Schmidt         // a vector register is safe, provided that we introduce a swap
3562be8054bSBill Schmidt         // following the load, which will be done by the SUBREG_TO_REG
3572be8054bSBill Schmidt         // support.  So just mark these as safe.
3582be8054bSBill Schmidt         SwapVector[VecIdx].IsLoad = 1;
3592be8054bSBill Schmidt         SwapVector[VecIdx].IsSwappable = 1;
3602be8054bSBill Schmidt         break;
361fe723b9aSBill Schmidt       case PPC::STVX:
362fe723b9aSBill Schmidt         // Non-permuting stores are currently unsafe.  We can use special
363fe723b9aSBill Schmidt         // handling for this in the future.  By not marking these as
364fe723b9aSBill Schmidt         // IsSwap, we ensure computations containing them will be rejected
365fe723b9aSBill Schmidt         // for now.
366fe723b9aSBill Schmidt         SwapVector[VecIdx].IsStore = 1;
367fe723b9aSBill Schmidt         break;
368fe723b9aSBill Schmidt       case PPC::STXVD2X:
369fe723b9aSBill Schmidt       case PPC::STXVW4X:
370fe723b9aSBill Schmidt         // Permuting stores are marked as both store and swap, and are
371fe723b9aSBill Schmidt         // safe for optimization.
372fe723b9aSBill Schmidt         SwapVector[VecIdx].IsStore = 1;
373fe723b9aSBill Schmidt         SwapVector[VecIdx].IsSwap = 1;
374fe723b9aSBill Schmidt         break;
375fe723b9aSBill Schmidt       case PPC::COPY:
376fe723b9aSBill Schmidt         // These are fine provided they are moving between full vector
377fe723b9aSBill Schmidt         // register classes.
378fe723b9aSBill Schmidt         if (isVecReg(MI.getOperand(0).getReg()) &&
379fe723b9aSBill Schmidt             isVecReg(MI.getOperand(1).getReg()))
380fe723b9aSBill Schmidt           SwapVector[VecIdx].IsSwappable = 1;
38115deb803SBill Schmidt         // If we have a copy from one scalar floating-point register
38215deb803SBill Schmidt         // to another, we can accept this even if it is a physical
38315deb803SBill Schmidt         // register.  The only way this gets involved is if it feeds
38415deb803SBill Schmidt         // a SUBREG_TO_REG, which is handled by introducing a swap.
38515deb803SBill Schmidt         else if (isScalarVecReg(MI.getOperand(0).getReg()) &&
38615deb803SBill Schmidt                  isScalarVecReg(MI.getOperand(1).getReg()))
38715deb803SBill Schmidt           SwapVector[VecIdx].IsSwappable = 1;
388fe723b9aSBill Schmidt         break;
38915deb803SBill Schmidt       case PPC::SUBREG_TO_REG: {
39015deb803SBill Schmidt         // These are fine provided they are moving between full vector
39115deb803SBill Schmidt         // register classes.  If they are moving from a scalar
39215deb803SBill Schmidt         // floating-point class to a vector class, we can handle those
39315deb803SBill Schmidt         // as well, provided we introduce a swap.  It is generally the
39415deb803SBill Schmidt         // case that we will introduce fewer swaps than we remove, but
39515deb803SBill Schmidt         // (FIXME) a cost model could be used.  However, introduced
39615deb803SBill Schmidt         // swaps could potentially be CSEd, so this is not trivial.
39715deb803SBill Schmidt         if (isVecReg(MI.getOperand(0).getReg()) &&
39815deb803SBill Schmidt             isVecReg(MI.getOperand(2).getReg()))
39915deb803SBill Schmidt           SwapVector[VecIdx].IsSwappable = 1;
40015deb803SBill Schmidt         else if (isVecReg(MI.getOperand(0).getReg()) &&
40115deb803SBill Schmidt                  isScalarVecReg(MI.getOperand(2).getReg())) {
40215deb803SBill Schmidt           SwapVector[VecIdx].IsSwappable = 1;
4032be8054bSBill Schmidt           SwapVector[VecIdx].SpecialHandling = SHValues::SH_COPYWIDEN;
40415deb803SBill Schmidt         }
40515deb803SBill Schmidt         break;
40615deb803SBill Schmidt       }
407fe723b9aSBill Schmidt       case PPC::VSPLTB:
408fe723b9aSBill Schmidt       case PPC::VSPLTH:
409fe723b9aSBill Schmidt       case PPC::VSPLTW:
410fe723b9aSBill Schmidt         // Splats are lane-sensitive, but we can use special handling
411fe723b9aSBill Schmidt         // to adjust the source lane for the splat.  This is not yet
412fe723b9aSBill Schmidt         // implemented.  When it is, we need to uncomment the following:
4135fe2e25fSBill Schmidt         SwapVector[VecIdx].IsSwappable = 1;
414fe723b9aSBill Schmidt         SwapVector[VecIdx].SpecialHandling = SHValues::SH_SPLAT;
415fe723b9aSBill Schmidt         break;
416fe723b9aSBill Schmidt       // The presence of the following lane-sensitive operations in a
417fe723b9aSBill Schmidt       // web will kill the optimization, at least for now.  For these
418fe723b9aSBill Schmidt       // we do nothing, causing the optimization to fail.
419fe723b9aSBill Schmidt       // FIXME: Some of these could be permitted with special handling,
420fe723b9aSBill Schmidt       // and will be phased in as time permits.
421fe723b9aSBill Schmidt       // FIXME: There is no simple and maintainable way to express a set
422fe723b9aSBill Schmidt       // of opcodes having a common attribute in TableGen.  Should this
423fe723b9aSBill Schmidt       // change, this is a prime candidate to use such a mechanism.
424fe723b9aSBill Schmidt       case PPC::INLINEASM:
425fe723b9aSBill Schmidt       case PPC::EXTRACT_SUBREG:
426fe723b9aSBill Schmidt       case PPC::INSERT_SUBREG:
427fe723b9aSBill Schmidt       case PPC::COPY_TO_REGCLASS:
428fe723b9aSBill Schmidt       case PPC::LVEBX:
429fe723b9aSBill Schmidt       case PPC::LVEHX:
430fe723b9aSBill Schmidt       case PPC::LVEWX:
431fe723b9aSBill Schmidt       case PPC::LVSL:
432fe723b9aSBill Schmidt       case PPC::LVSR:
433fe723b9aSBill Schmidt       case PPC::LVXL:
434fe723b9aSBill Schmidt       case PPC::STVEBX:
435fe723b9aSBill Schmidt       case PPC::STVEHX:
436fe723b9aSBill Schmidt       case PPC::STVEWX:
437fe723b9aSBill Schmidt       case PPC::STVXL:
4382be8054bSBill Schmidt         // We can handle STXSDX and STXSSPX similarly to LXSDX and LXSSPX,
4392be8054bSBill Schmidt         // by adding special handling for narrowing copies as well as
4402be8054bSBill Schmidt         // widening ones.  However, I've experimented with this, and in
4412be8054bSBill Schmidt         // practice we currently do not appear to use STXSDX fed by
4422be8054bSBill Schmidt         // a narrowing copy from a full vector register.  Since I can't
4432be8054bSBill Schmidt         // generate any useful test cases, I've left this alone for now.
444fe723b9aSBill Schmidt       case PPC::STXSDX:
4452be8054bSBill Schmidt       case PPC::STXSSPX:
446fe723b9aSBill Schmidt       case PPC::VCIPHER:
447fe723b9aSBill Schmidt       case PPC::VCIPHERLAST:
448fe723b9aSBill Schmidt       case PPC::VMRGHB:
449fe723b9aSBill Schmidt       case PPC::VMRGHH:
450fe723b9aSBill Schmidt       case PPC::VMRGHW:
451fe723b9aSBill Schmidt       case PPC::VMRGLB:
452fe723b9aSBill Schmidt       case PPC::VMRGLH:
453fe723b9aSBill Schmidt       case PPC::VMRGLW:
454fe723b9aSBill Schmidt       case PPC::VMULESB:
455fe723b9aSBill Schmidt       case PPC::VMULESH:
456fe723b9aSBill Schmidt       case PPC::VMULESW:
457fe723b9aSBill Schmidt       case PPC::VMULEUB:
458fe723b9aSBill Schmidt       case PPC::VMULEUH:
459fe723b9aSBill Schmidt       case PPC::VMULEUW:
460fe723b9aSBill Schmidt       case PPC::VMULOSB:
461fe723b9aSBill Schmidt       case PPC::VMULOSH:
462fe723b9aSBill Schmidt       case PPC::VMULOSW:
463fe723b9aSBill Schmidt       case PPC::VMULOUB:
464fe723b9aSBill Schmidt       case PPC::VMULOUH:
465fe723b9aSBill Schmidt       case PPC::VMULOUW:
466fe723b9aSBill Schmidt       case PPC::VNCIPHER:
467fe723b9aSBill Schmidt       case PPC::VNCIPHERLAST:
468fe723b9aSBill Schmidt       case PPC::VPERM:
469fe723b9aSBill Schmidt       case PPC::VPERMXOR:
470fe723b9aSBill Schmidt       case PPC::VPKPX:
471fe723b9aSBill Schmidt       case PPC::VPKSHSS:
472fe723b9aSBill Schmidt       case PPC::VPKSHUS:
4735ed84cdbSBill Schmidt       case PPC::VPKSDSS:
4745ed84cdbSBill Schmidt       case PPC::VPKSDUS:
475fe723b9aSBill Schmidt       case PPC::VPKSWSS:
476fe723b9aSBill Schmidt       case PPC::VPKSWUS:
4775ed84cdbSBill Schmidt       case PPC::VPKUDUM:
4785ed84cdbSBill Schmidt       case PPC::VPKUDUS:
479fe723b9aSBill Schmidt       case PPC::VPKUHUM:
480fe723b9aSBill Schmidt       case PPC::VPKUHUS:
481fe723b9aSBill Schmidt       case PPC::VPKUWUM:
482fe723b9aSBill Schmidt       case PPC::VPKUWUS:
483fe723b9aSBill Schmidt       case PPC::VPMSUMB:
484fe723b9aSBill Schmidt       case PPC::VPMSUMD:
485fe723b9aSBill Schmidt       case PPC::VPMSUMH:
486fe723b9aSBill Schmidt       case PPC::VPMSUMW:
487fe723b9aSBill Schmidt       case PPC::VRLB:
488fe723b9aSBill Schmidt       case PPC::VRLD:
489fe723b9aSBill Schmidt       case PPC::VRLH:
490fe723b9aSBill Schmidt       case PPC::VRLW:
491fe723b9aSBill Schmidt       case PPC::VSBOX:
492fe723b9aSBill Schmidt       case PPC::VSHASIGMAD:
493fe723b9aSBill Schmidt       case PPC::VSHASIGMAW:
494fe723b9aSBill Schmidt       case PPC::VSL:
495fe723b9aSBill Schmidt       case PPC::VSLDOI:
496fe723b9aSBill Schmidt       case PPC::VSLO:
497fe723b9aSBill Schmidt       case PPC::VSR:
498fe723b9aSBill Schmidt       case PPC::VSRO:
499fe723b9aSBill Schmidt       case PPC::VSUM2SWS:
500fe723b9aSBill Schmidt       case PPC::VSUM4SBS:
501fe723b9aSBill Schmidt       case PPC::VSUM4SHS:
502fe723b9aSBill Schmidt       case PPC::VSUM4UBS:
503fe723b9aSBill Schmidt       case PPC::VSUMSWS:
504fe723b9aSBill Schmidt       case PPC::VUPKHPX:
505fe723b9aSBill Schmidt       case PPC::VUPKHSB:
506fe723b9aSBill Schmidt       case PPC::VUPKHSH:
5075ed84cdbSBill Schmidt       case PPC::VUPKHSW:
508fe723b9aSBill Schmidt       case PPC::VUPKLPX:
509fe723b9aSBill Schmidt       case PPC::VUPKLSB:
510fe723b9aSBill Schmidt       case PPC::VUPKLSH:
5115ed84cdbSBill Schmidt       case PPC::VUPKLSW:
512fe723b9aSBill Schmidt       case PPC::XXMRGHW:
513fe723b9aSBill Schmidt       case PPC::XXMRGLW:
51415deb803SBill Schmidt       // XXSLDWI could be replaced by a general permute with one of three
51515deb803SBill Schmidt       // permute control vectors (for shift values 1, 2, 3).  However,
51615deb803SBill Schmidt       // VPERM has a more restrictive register class.
51715deb803SBill Schmidt       case PPC::XXSLDWI:
518fe723b9aSBill Schmidt       case PPC::XXSPLTW:
519fe723b9aSBill Schmidt         break;
520fe723b9aSBill Schmidt       }
521fe723b9aSBill Schmidt     }
522fe723b9aSBill Schmidt   }
523fe723b9aSBill Schmidt 
524fe723b9aSBill Schmidt   if (RelevantFunction) {
525fe723b9aSBill Schmidt     DEBUG(dbgs() << "Swap vector when first built\n\n");
526fe723b9aSBill Schmidt     dumpSwapVector();
527fe723b9aSBill Schmidt   }
528fe723b9aSBill Schmidt 
529fe723b9aSBill Schmidt   return RelevantFunction;
530fe723b9aSBill Schmidt }
531fe723b9aSBill Schmidt 
532fe723b9aSBill Schmidt // Add an entry to the swap vector and swap map, and make a
533fe723b9aSBill Schmidt // singleton equivalence class for the entry.
534fe723b9aSBill Schmidt int PPCVSXSwapRemoval::addSwapEntry(MachineInstr *MI,
535fe723b9aSBill Schmidt                                   PPCVSXSwapEntry& SwapEntry) {
536fe723b9aSBill Schmidt   SwapEntry.VSEMI = MI;
537fe723b9aSBill Schmidt   SwapEntry.VSEId = SwapVector.size();
538fe723b9aSBill Schmidt   SwapVector.push_back(SwapEntry);
539fe723b9aSBill Schmidt   EC->insert(SwapEntry.VSEId);
540fe723b9aSBill Schmidt   SwapMap[MI] = SwapEntry.VSEId;
541fe723b9aSBill Schmidt   return SwapEntry.VSEId;
542fe723b9aSBill Schmidt }
543fe723b9aSBill Schmidt 
544fe723b9aSBill Schmidt // This is used to find the "true" source register for an
545fe723b9aSBill Schmidt // XXPERMDI instruction, since MachineCSE does not handle the
546fe723b9aSBill Schmidt // "copy-like" operations (Copy and SubregToReg).  Returns
547fe723b9aSBill Schmidt // the original SrcReg unless it is the target of a copy-like
548fe723b9aSBill Schmidt // operation, in which case we chain backwards through all
549fe723b9aSBill Schmidt // such operations to the ultimate source register.  If a
550fe723b9aSBill Schmidt // physical register is encountered, we stop the search and
551fe723b9aSBill Schmidt // flag the swap entry indicated by VecIdx (the original
552a1c30053SBill Schmidt // XXPERMDI) as mentioning a physical register.
553fe723b9aSBill Schmidt unsigned PPCVSXSwapRemoval::lookThruCopyLike(unsigned SrcReg,
554fe723b9aSBill Schmidt                                              unsigned VecIdx) {
555fe723b9aSBill Schmidt   MachineInstr *MI = MRI->getVRegDef(SrcReg);
556fe723b9aSBill Schmidt   if (!MI->isCopyLike())
557fe723b9aSBill Schmidt     return SrcReg;
558fe723b9aSBill Schmidt 
559a1c30053SBill Schmidt   unsigned CopySrcReg;
560a1c30053SBill Schmidt   if (MI->isCopy())
561fe723b9aSBill Schmidt     CopySrcReg = MI->getOperand(1).getReg();
562a1c30053SBill Schmidt   else {
563fe723b9aSBill Schmidt     assert(MI->isSubregToReg() && "bad opcode for lookThruCopyLike");
564fe723b9aSBill Schmidt     CopySrcReg = MI->getOperand(2).getReg();
565fe723b9aSBill Schmidt   }
566fe723b9aSBill Schmidt 
567fe723b9aSBill Schmidt   if (!TargetRegisterInfo::isVirtualRegister(CopySrcReg)) {
5682be8054bSBill Schmidt     if (!isScalarVecReg(CopySrcReg))
569fe723b9aSBill Schmidt       SwapVector[VecIdx].MentionsPhysVR = 1;
570fe723b9aSBill Schmidt     return CopySrcReg;
571fe723b9aSBill Schmidt   }
572fe723b9aSBill Schmidt 
573fe723b9aSBill Schmidt   return lookThruCopyLike(CopySrcReg, VecIdx);
574fe723b9aSBill Schmidt }
575fe723b9aSBill Schmidt 
576fe723b9aSBill Schmidt // Generate equivalence classes for related computations (webs) by
577fe723b9aSBill Schmidt // def-use relationships of virtual registers.  Mention of a physical
578fe723b9aSBill Schmidt // register terminates the generation of equivalence classes as this
579fe723b9aSBill Schmidt // indicates a use of a parameter, definition of a return value, use
580fe723b9aSBill Schmidt // of a value returned from a call, or definition of a parameter to a
581fe723b9aSBill Schmidt // call.  Computations with physical register mentions are flagged
582fe723b9aSBill Schmidt // as such so their containing webs will not be optimized.
583fe723b9aSBill Schmidt void PPCVSXSwapRemoval::formWebs() {
584fe723b9aSBill Schmidt 
585fe723b9aSBill Schmidt   DEBUG(dbgs() << "\n*** Forming webs for swap removal ***\n\n");
586fe723b9aSBill Schmidt 
587fe723b9aSBill Schmidt   for (unsigned EntryIdx = 0; EntryIdx < SwapVector.size(); ++EntryIdx) {
588fe723b9aSBill Schmidt 
589fe723b9aSBill Schmidt     MachineInstr *MI = SwapVector[EntryIdx].VSEMI;
590fe723b9aSBill Schmidt 
591fe723b9aSBill Schmidt     DEBUG(dbgs() << "\n" << SwapVector[EntryIdx].VSEId << " ");
592fe723b9aSBill Schmidt     DEBUG(MI->dump());
593fe723b9aSBill Schmidt 
594fe723b9aSBill Schmidt     // It's sufficient to walk vector uses and join them to their unique
59515deb803SBill Schmidt     // definitions.  In addition, check full vector register operands
59615deb803SBill Schmidt     // for physical regs.  We exclude partial-vector register operands
59715deb803SBill Schmidt     // because we can handle them if copied to a full vector.
598fe723b9aSBill Schmidt     for (const MachineOperand &MO : MI->operands()) {
599fe723b9aSBill Schmidt       if (!MO.isReg())
600fe723b9aSBill Schmidt         continue;
601fe723b9aSBill Schmidt 
602fe723b9aSBill Schmidt       unsigned Reg = MO.getReg();
60315deb803SBill Schmidt       if (!isVecReg(Reg) && !isScalarVecReg(Reg))
604fe723b9aSBill Schmidt         continue;
605fe723b9aSBill Schmidt 
606fe723b9aSBill Schmidt       if (!TargetRegisterInfo::isVirtualRegister(Reg)) {
60715deb803SBill Schmidt         if (!(MI->isCopy() && isScalarVecReg(Reg)))
608fe723b9aSBill Schmidt           SwapVector[EntryIdx].MentionsPhysVR = 1;
609fe723b9aSBill Schmidt         continue;
610fe723b9aSBill Schmidt       }
611fe723b9aSBill Schmidt 
612fe723b9aSBill Schmidt       if (!MO.isUse())
613fe723b9aSBill Schmidt         continue;
614fe723b9aSBill Schmidt 
615fe723b9aSBill Schmidt       MachineInstr* DefMI = MRI->getVRegDef(Reg);
616fe723b9aSBill Schmidt       assert(SwapMap.find(DefMI) != SwapMap.end() &&
617fe723b9aSBill Schmidt              "Inconsistency: def of vector reg not found in swap map!");
618fe723b9aSBill Schmidt       int DefIdx = SwapMap[DefMI];
619fe723b9aSBill Schmidt       (void)EC->unionSets(SwapVector[DefIdx].VSEId,
620fe723b9aSBill Schmidt                           SwapVector[EntryIdx].VSEId);
621fe723b9aSBill Schmidt 
622fe723b9aSBill Schmidt       DEBUG(dbgs() << format("Unioning %d with %d\n", SwapVector[DefIdx].VSEId,
623fe723b9aSBill Schmidt                              SwapVector[EntryIdx].VSEId));
624fe723b9aSBill Schmidt       DEBUG(dbgs() << "  Def: ");
625fe723b9aSBill Schmidt       DEBUG(DefMI->dump());
626fe723b9aSBill Schmidt     }
627fe723b9aSBill Schmidt   }
628fe723b9aSBill Schmidt }
629fe723b9aSBill Schmidt 
630fe723b9aSBill Schmidt // Walk the swap vector entries looking for conditions that prevent their
631fe723b9aSBill Schmidt // containing computations from being optimized.  When such conditions are
632fe723b9aSBill Schmidt // found, mark the representative of the computation's equivalence class
633fe723b9aSBill Schmidt // as rejected.
634fe723b9aSBill Schmidt void PPCVSXSwapRemoval::recordUnoptimizableWebs() {
635fe723b9aSBill Schmidt 
636fe723b9aSBill Schmidt   DEBUG(dbgs() << "\n*** Rejecting webs for swap removal ***\n\n");
637fe723b9aSBill Schmidt 
638fe723b9aSBill Schmidt   for (unsigned EntryIdx = 0; EntryIdx < SwapVector.size(); ++EntryIdx) {
639fe723b9aSBill Schmidt     int Repr = EC->getLeaderValue(SwapVector[EntryIdx].VSEId);
640fe723b9aSBill Schmidt 
64115deb803SBill Schmidt     // If representative is already rejected, don't waste further time.
64215deb803SBill Schmidt     if (SwapVector[Repr].WebRejected)
64315deb803SBill Schmidt       continue;
64415deb803SBill Schmidt 
64515deb803SBill Schmidt     // Reject webs containing mentions of physical or partial registers, or
64615deb803SBill Schmidt     // containing operations that we don't know how to handle in a lane-
64715deb803SBill Schmidt     // permuted region.
648fe723b9aSBill Schmidt     if (SwapVector[EntryIdx].MentionsPhysVR ||
64915deb803SBill Schmidt         SwapVector[EntryIdx].MentionsPartialVR ||
650fe723b9aSBill Schmidt         !(SwapVector[EntryIdx].IsSwappable || SwapVector[EntryIdx].IsSwap)) {
651fe723b9aSBill Schmidt 
652fe723b9aSBill Schmidt       SwapVector[Repr].WebRejected = 1;
653fe723b9aSBill Schmidt 
654fe723b9aSBill Schmidt       DEBUG(dbgs() <<
6552be8054bSBill Schmidt             format("Web %d rejected for physreg, partial reg, or not "
6562be8054bSBill Schmidt                    "swap[pable]\n", Repr));
657fe723b9aSBill Schmidt       DEBUG(dbgs() << "  in " << EntryIdx << ": ");
658fe723b9aSBill Schmidt       DEBUG(SwapVector[EntryIdx].VSEMI->dump());
659fe723b9aSBill Schmidt       DEBUG(dbgs() << "\n");
660fe723b9aSBill Schmidt     }
661fe723b9aSBill Schmidt 
662fe723b9aSBill Schmidt     // Reject webs than contain swapping loads that feed something other
663fe723b9aSBill Schmidt     // than a swap instruction.
664fe723b9aSBill Schmidt     else if (SwapVector[EntryIdx].IsLoad && SwapVector[EntryIdx].IsSwap) {
665fe723b9aSBill Schmidt       MachineInstr *MI = SwapVector[EntryIdx].VSEMI;
666fe723b9aSBill Schmidt       unsigned DefReg = MI->getOperand(0).getReg();
667fe723b9aSBill Schmidt 
668fe723b9aSBill Schmidt       // We skip debug instructions in the analysis.  (Note that debug
669fe723b9aSBill Schmidt       // location information is still maintained by this optimization
670fe723b9aSBill Schmidt       // because it remains on the LXVD2X and STXVD2X instructions after
671fe723b9aSBill Schmidt       // the XXPERMDIs are removed.)
672fe723b9aSBill Schmidt       for (MachineInstr &UseMI : MRI->use_nodbg_instructions(DefReg)) {
673fe723b9aSBill Schmidt         int UseIdx = SwapMap[&UseMI];
674fe723b9aSBill Schmidt 
675fe723b9aSBill Schmidt         if (!SwapVector[UseIdx].IsSwap || SwapVector[UseIdx].IsLoad ||
676fe723b9aSBill Schmidt             SwapVector[UseIdx].IsStore) {
677fe723b9aSBill Schmidt 
678fe723b9aSBill Schmidt           SwapVector[Repr].WebRejected = 1;
679fe723b9aSBill Schmidt 
680fe723b9aSBill Schmidt           DEBUG(dbgs() <<
681fe723b9aSBill Schmidt                 format("Web %d rejected for load not feeding swap\n", Repr));
682fe723b9aSBill Schmidt           DEBUG(dbgs() << "  def " << EntryIdx << ": ");
683fe723b9aSBill Schmidt           DEBUG(MI->dump());
684fe723b9aSBill Schmidt           DEBUG(dbgs() << "  use " << UseIdx << ": ");
685fe723b9aSBill Schmidt           DEBUG(UseMI.dump());
686fe723b9aSBill Schmidt           DEBUG(dbgs() << "\n");
687fe723b9aSBill Schmidt         }
688fe723b9aSBill Schmidt       }
689fe723b9aSBill Schmidt 
69015deb803SBill Schmidt     // Reject webs that contain swapping stores that are fed by something
691fe723b9aSBill Schmidt     // other than a swap instruction.
692fe723b9aSBill Schmidt     } else if (SwapVector[EntryIdx].IsStore && SwapVector[EntryIdx].IsSwap) {
693fe723b9aSBill Schmidt       MachineInstr *MI = SwapVector[EntryIdx].VSEMI;
694fe723b9aSBill Schmidt       unsigned UseReg = MI->getOperand(0).getReg();
695fe723b9aSBill Schmidt       MachineInstr *DefMI = MRI->getVRegDef(UseReg);
696fe723b9aSBill Schmidt       int DefIdx = SwapMap[DefMI];
697fe723b9aSBill Schmidt 
698fe723b9aSBill Schmidt       if (!SwapVector[DefIdx].IsSwap || SwapVector[DefIdx].IsLoad ||
699fe723b9aSBill Schmidt           SwapVector[DefIdx].IsStore) {
700fe723b9aSBill Schmidt 
701fe723b9aSBill Schmidt         SwapVector[Repr].WebRejected = 1;
702fe723b9aSBill Schmidt 
703fe723b9aSBill Schmidt         DEBUG(dbgs() <<
704fe723b9aSBill Schmidt               format("Web %d rejected for store not fed by swap\n", Repr));
705fe723b9aSBill Schmidt         DEBUG(dbgs() << "  def " << DefIdx << ": ");
706fe723b9aSBill Schmidt         DEBUG(DefMI->dump());
707fe723b9aSBill Schmidt         DEBUG(dbgs() << "  use " << EntryIdx << ": ");
708fe723b9aSBill Schmidt         DEBUG(MI->dump());
709fe723b9aSBill Schmidt         DEBUG(dbgs() << "\n");
710fe723b9aSBill Schmidt       }
711fe723b9aSBill Schmidt     }
712fe723b9aSBill Schmidt   }
713fe723b9aSBill Schmidt 
714fe723b9aSBill Schmidt   DEBUG(dbgs() << "Swap vector after web analysis:\n\n");
715fe723b9aSBill Schmidt   dumpSwapVector();
716fe723b9aSBill Schmidt }
717fe723b9aSBill Schmidt 
718fe723b9aSBill Schmidt // Walk the swap vector entries looking for swaps fed by permuting loads
719fe723b9aSBill Schmidt // and swaps that feed permuting stores.  If the containing computation
720fe723b9aSBill Schmidt // has not been marked rejected, mark each such swap for removal.
721fe723b9aSBill Schmidt // (Removal is delayed in case optimization has disturbed the pattern,
722fe723b9aSBill Schmidt // such that multiple loads feed the same swap, etc.)
723fe723b9aSBill Schmidt void PPCVSXSwapRemoval::markSwapsForRemoval() {
724fe723b9aSBill Schmidt 
725fe723b9aSBill Schmidt   DEBUG(dbgs() << "\n*** Marking swaps for removal ***\n\n");
726fe723b9aSBill Schmidt 
727fe723b9aSBill Schmidt   for (unsigned EntryIdx = 0; EntryIdx < SwapVector.size(); ++EntryIdx) {
728fe723b9aSBill Schmidt 
729fe723b9aSBill Schmidt     if (SwapVector[EntryIdx].IsLoad && SwapVector[EntryIdx].IsSwap) {
730fe723b9aSBill Schmidt       int Repr = EC->getLeaderValue(SwapVector[EntryIdx].VSEId);
731fe723b9aSBill Schmidt 
732fe723b9aSBill Schmidt       if (!SwapVector[Repr].WebRejected) {
733fe723b9aSBill Schmidt         MachineInstr *MI = SwapVector[EntryIdx].VSEMI;
734fe723b9aSBill Schmidt         unsigned DefReg = MI->getOperand(0).getReg();
735fe723b9aSBill Schmidt 
736fe723b9aSBill Schmidt         for (MachineInstr &UseMI : MRI->use_nodbg_instructions(DefReg)) {
737fe723b9aSBill Schmidt           int UseIdx = SwapMap[&UseMI];
738fe723b9aSBill Schmidt           SwapVector[UseIdx].WillRemove = 1;
739fe723b9aSBill Schmidt 
740fe723b9aSBill Schmidt           DEBUG(dbgs() << "Marking swap fed by load for removal: ");
741fe723b9aSBill Schmidt           DEBUG(UseMI.dump());
742fe723b9aSBill Schmidt         }
743fe723b9aSBill Schmidt       }
744fe723b9aSBill Schmidt 
745fe723b9aSBill Schmidt     } else if (SwapVector[EntryIdx].IsStore && SwapVector[EntryIdx].IsSwap) {
746fe723b9aSBill Schmidt       int Repr = EC->getLeaderValue(SwapVector[EntryIdx].VSEId);
747fe723b9aSBill Schmidt 
748fe723b9aSBill Schmidt       if (!SwapVector[Repr].WebRejected) {
749fe723b9aSBill Schmidt         MachineInstr *MI = SwapVector[EntryIdx].VSEMI;
750fe723b9aSBill Schmidt         unsigned UseReg = MI->getOperand(0).getReg();
751fe723b9aSBill Schmidt         MachineInstr *DefMI = MRI->getVRegDef(UseReg);
752fe723b9aSBill Schmidt         int DefIdx = SwapMap[DefMI];
753fe723b9aSBill Schmidt         SwapVector[DefIdx].WillRemove = 1;
754fe723b9aSBill Schmidt 
755fe723b9aSBill Schmidt         DEBUG(dbgs() << "Marking swap feeding store for removal: ");
756fe723b9aSBill Schmidt         DEBUG(DefMI->dump());
757fe723b9aSBill Schmidt       }
758fe723b9aSBill Schmidt 
759fe723b9aSBill Schmidt     } else if (SwapVector[EntryIdx].IsSwappable &&
7605fe2e25fSBill Schmidt                SwapVector[EntryIdx].SpecialHandling != 0) {
7615fe2e25fSBill Schmidt       int Repr = EC->getLeaderValue(SwapVector[EntryIdx].VSEId);
7625fe2e25fSBill Schmidt 
7635fe2e25fSBill Schmidt       if (!SwapVector[Repr].WebRejected)
764fe723b9aSBill Schmidt         handleSpecialSwappables(EntryIdx);
765fe723b9aSBill Schmidt     }
766fe723b9aSBill Schmidt   }
7675fe2e25fSBill Schmidt }
768fe723b9aSBill Schmidt 
7692be8054bSBill Schmidt // Create an xxswapd instruction and insert it prior to the given point.
7702be8054bSBill Schmidt // MI is used to determine basic block and debug loc information.
7712be8054bSBill Schmidt // FIXME: When inserting a swap, we should check whether SrcReg is
7722be8054bSBill Schmidt // defined by another swap:  SrcReg = XXPERMDI Reg, Reg, 2;  If so,
7732be8054bSBill Schmidt // then instead we should generate a copy from Reg to DstReg.
7742be8054bSBill Schmidt void PPCVSXSwapRemoval::insertSwap(MachineInstr *MI,
7752be8054bSBill Schmidt                                    MachineBasicBlock::iterator InsertPoint,
7762be8054bSBill Schmidt                                    unsigned DstReg, unsigned SrcReg) {
7772be8054bSBill Schmidt   BuildMI(*MI->getParent(), InsertPoint, MI->getDebugLoc(),
7782be8054bSBill Schmidt           TII->get(PPC::XXPERMDI), DstReg)
7792be8054bSBill Schmidt     .addReg(SrcReg)
7802be8054bSBill Schmidt     .addReg(SrcReg)
7812be8054bSBill Schmidt     .addImm(2);
7822be8054bSBill Schmidt }
7832be8054bSBill Schmidt 
784fe723b9aSBill Schmidt // The identified swap entry requires special handling to allow its
785fe723b9aSBill Schmidt // containing computation to be optimized.  Perform that handling
786fe723b9aSBill Schmidt // here.
78715deb803SBill Schmidt // FIXME: Additional opportunities will be phased in with subsequent
78815deb803SBill Schmidt // patches.
789fe723b9aSBill Schmidt void PPCVSXSwapRemoval::handleSpecialSwappables(int EntryIdx) {
7905fe2e25fSBill Schmidt   switch (SwapVector[EntryIdx].SpecialHandling) {
7915fe2e25fSBill Schmidt 
7925fe2e25fSBill Schmidt   default:
7938ceb323bSBenjamin Kramer     llvm_unreachable("Unexpected special handling type");
7945fe2e25fSBill Schmidt 
7955fe2e25fSBill Schmidt   // For splats based on an index into a vector, add N/2 modulo N
7965fe2e25fSBill Schmidt   // to the index, where N is the number of vector elements.
7975fe2e25fSBill Schmidt   case SHValues::SH_SPLAT: {
7985fe2e25fSBill Schmidt     MachineInstr *MI = SwapVector[EntryIdx].VSEMI;
7995fe2e25fSBill Schmidt     unsigned NElts;
8005fe2e25fSBill Schmidt 
8015fe2e25fSBill Schmidt     DEBUG(dbgs() << "Changing splat: ");
8025fe2e25fSBill Schmidt     DEBUG(MI->dump());
8035fe2e25fSBill Schmidt 
8045fe2e25fSBill Schmidt     switch (MI->getOpcode()) {
8055fe2e25fSBill Schmidt     default:
8068ceb323bSBenjamin Kramer       llvm_unreachable("Unexpected splat opcode");
8075fe2e25fSBill Schmidt     case PPC::VSPLTB: NElts = 16; break;
8085fe2e25fSBill Schmidt     case PPC::VSPLTH: NElts = 8;  break;
8095fe2e25fSBill Schmidt     case PPC::VSPLTW: NElts = 4;  break;
8105fe2e25fSBill Schmidt     }
8115fe2e25fSBill Schmidt 
8125fe2e25fSBill Schmidt     unsigned EltNo = MI->getOperand(1).getImm();
8135fe2e25fSBill Schmidt     EltNo = (EltNo + NElts / 2) % NElts;
8145fe2e25fSBill Schmidt     MI->getOperand(1).setImm(EltNo);
8155fe2e25fSBill Schmidt 
8165fe2e25fSBill Schmidt     DEBUG(dbgs() << "  Into: ");
8175fe2e25fSBill Schmidt     DEBUG(MI->dump());
8185fe2e25fSBill Schmidt     break;
8195fe2e25fSBill Schmidt   }
8205fe2e25fSBill Schmidt 
82115deb803SBill Schmidt   // For an XXPERMDI that isn't handled otherwise, we need to
82215deb803SBill Schmidt   // reverse the order of the operands.  If the selector operand
82315deb803SBill Schmidt   // has a value of 0 or 3, we need to change it to 3 or 0,
82415deb803SBill Schmidt   // respectively.  Otherwise we should leave it alone.  (This
82515deb803SBill Schmidt   // is equivalent to reversing the two bits of the selector
82615deb803SBill Schmidt   // operand and complementing the result.)
82715deb803SBill Schmidt   case SHValues::SH_XXPERMDI: {
82815deb803SBill Schmidt     MachineInstr *MI = SwapVector[EntryIdx].VSEMI;
82915deb803SBill Schmidt 
83015deb803SBill Schmidt     DEBUG(dbgs() << "Changing XXPERMDI: ");
83115deb803SBill Schmidt     DEBUG(MI->dump());
83215deb803SBill Schmidt 
83315deb803SBill Schmidt     unsigned Selector = MI->getOperand(3).getImm();
83415deb803SBill Schmidt     if (Selector == 0 || Selector == 3)
83515deb803SBill Schmidt       Selector = 3 - Selector;
83615deb803SBill Schmidt     MI->getOperand(3).setImm(Selector);
83715deb803SBill Schmidt 
83815deb803SBill Schmidt     unsigned Reg1 = MI->getOperand(1).getReg();
83915deb803SBill Schmidt     unsigned Reg2 = MI->getOperand(2).getReg();
84015deb803SBill Schmidt     MI->getOperand(1).setReg(Reg2);
84115deb803SBill Schmidt     MI->getOperand(2).setReg(Reg1);
84215deb803SBill Schmidt 
84315deb803SBill Schmidt     DEBUG(dbgs() << "  Into: ");
84415deb803SBill Schmidt     DEBUG(MI->dump());
84515deb803SBill Schmidt     break;
84615deb803SBill Schmidt   }
84715deb803SBill Schmidt 
84815deb803SBill Schmidt   // For a copy from a scalar floating-point register to a vector
84915deb803SBill Schmidt   // register, removing swaps will leave the copied value in the
85015deb803SBill Schmidt   // wrong lane.  Insert a swap following the copy to fix this.
8512be8054bSBill Schmidt   case SHValues::SH_COPYWIDEN: {
85215deb803SBill Schmidt     MachineInstr *MI = SwapVector[EntryIdx].VSEMI;
85315deb803SBill Schmidt 
85415deb803SBill Schmidt     DEBUG(dbgs() << "Changing SUBREG_TO_REG: ");
85515deb803SBill Schmidt     DEBUG(MI->dump());
85615deb803SBill Schmidt 
85715deb803SBill Schmidt     unsigned DstReg = MI->getOperand(0).getReg();
85815deb803SBill Schmidt     const TargetRegisterClass *DstRC = MRI->getRegClass(DstReg);
85915deb803SBill Schmidt     unsigned NewVReg = MRI->createVirtualRegister(DstRC);
86015deb803SBill Schmidt 
86115deb803SBill Schmidt     MI->getOperand(0).setReg(NewVReg);
86215deb803SBill Schmidt     DEBUG(dbgs() << "  Into: ");
86315deb803SBill Schmidt     DEBUG(MI->dump());
86415deb803SBill Schmidt 
865a3da4488SDuncan P. N. Exon Smith     auto InsertPoint = ++MachineBasicBlock::iterator(MI);
86615deb803SBill Schmidt 
86715deb803SBill Schmidt     // Note that an XXPERMDI requires a VSRC, so if the SUBREG_TO_REG
86815deb803SBill Schmidt     // is copying to a VRRC, we need to be careful to avoid a register
86915deb803SBill Schmidt     // assignment problem.  In this case we must copy from VRRC to VSRC
87015deb803SBill Schmidt     // prior to the swap, and from VSRC to VRRC following the swap.
87115deb803SBill Schmidt     // Coalescing will usually remove all this mess.
87215deb803SBill Schmidt     if (DstRC == &PPC::VRRCRegClass) {
87315deb803SBill Schmidt       unsigned VSRCTmp1 = MRI->createVirtualRegister(&PPC::VSRCRegClass);
87415deb803SBill Schmidt       unsigned VSRCTmp2 = MRI->createVirtualRegister(&PPC::VSRCRegClass);
87515deb803SBill Schmidt 
87615deb803SBill Schmidt       BuildMI(*MI->getParent(), InsertPoint, MI->getDebugLoc(),
87715deb803SBill Schmidt               TII->get(PPC::COPY), VSRCTmp1)
87815deb803SBill Schmidt         .addReg(NewVReg);
879a3da4488SDuncan P. N. Exon Smith       DEBUG(std::prev(InsertPoint)->dump());
88015deb803SBill Schmidt 
8812be8054bSBill Schmidt       insertSwap(MI, InsertPoint, VSRCTmp2, VSRCTmp1);
882a3da4488SDuncan P. N. Exon Smith       DEBUG(std::prev(InsertPoint)->dump());
88315deb803SBill Schmidt 
88415deb803SBill Schmidt       BuildMI(*MI->getParent(), InsertPoint, MI->getDebugLoc(),
88515deb803SBill Schmidt               TII->get(PPC::COPY), DstReg)
88615deb803SBill Schmidt         .addReg(VSRCTmp2);
887a3da4488SDuncan P. N. Exon Smith       DEBUG(std::prev(InsertPoint)->dump());
88815deb803SBill Schmidt 
88915deb803SBill Schmidt     } else {
8902be8054bSBill Schmidt       insertSwap(MI, InsertPoint, DstReg, NewVReg);
891a3da4488SDuncan P. N. Exon Smith       DEBUG(std::prev(InsertPoint)->dump());
89215deb803SBill Schmidt     }
89315deb803SBill Schmidt     break;
89415deb803SBill Schmidt   }
8955fe2e25fSBill Schmidt   }
896fe723b9aSBill Schmidt }
897fe723b9aSBill Schmidt 
898fe723b9aSBill Schmidt // Walk the swap vector and replace each entry marked for removal with
899fe723b9aSBill Schmidt // a copy operation.
900fe723b9aSBill Schmidt bool PPCVSXSwapRemoval::removeSwaps() {
901fe723b9aSBill Schmidt 
902fe723b9aSBill Schmidt   DEBUG(dbgs() << "\n*** Removing swaps ***\n\n");
903fe723b9aSBill Schmidt 
904fe723b9aSBill Schmidt   bool Changed = false;
905fe723b9aSBill Schmidt 
906fe723b9aSBill Schmidt   for (unsigned EntryIdx = 0; EntryIdx < SwapVector.size(); ++EntryIdx) {
907fe723b9aSBill Schmidt     if (SwapVector[EntryIdx].WillRemove) {
908fe723b9aSBill Schmidt       Changed = true;
909fe723b9aSBill Schmidt       MachineInstr *MI = SwapVector[EntryIdx].VSEMI;
910fe723b9aSBill Schmidt       MachineBasicBlock *MBB = MI->getParent();
911fe723b9aSBill Schmidt       BuildMI(*MBB, MI, MI->getDebugLoc(),
912fe723b9aSBill Schmidt               TII->get(TargetOpcode::COPY), MI->getOperand(0).getReg())
913fe723b9aSBill Schmidt         .addOperand(MI->getOperand(1));
914fe723b9aSBill Schmidt 
915fe723b9aSBill Schmidt       DEBUG(dbgs() << format("Replaced %d with copy: ",
916fe723b9aSBill Schmidt                              SwapVector[EntryIdx].VSEId));
917fe723b9aSBill Schmidt       DEBUG(MI->dump());
918fe723b9aSBill Schmidt 
919fe723b9aSBill Schmidt       MI->eraseFromParent();
920fe723b9aSBill Schmidt     }
921fe723b9aSBill Schmidt   }
922fe723b9aSBill Schmidt 
923fe723b9aSBill Schmidt   return Changed;
924fe723b9aSBill Schmidt }
925fe723b9aSBill Schmidt 
926fe723b9aSBill Schmidt // For debug purposes, dump the contents of the swap vector.
927fe723b9aSBill Schmidt void PPCVSXSwapRemoval::dumpSwapVector() {
928fe723b9aSBill Schmidt 
929fe723b9aSBill Schmidt   for (unsigned EntryIdx = 0; EntryIdx < SwapVector.size(); ++EntryIdx) {
930fe723b9aSBill Schmidt 
931fe723b9aSBill Schmidt     MachineInstr *MI = SwapVector[EntryIdx].VSEMI;
932fe723b9aSBill Schmidt     int ID = SwapVector[EntryIdx].VSEId;
933fe723b9aSBill Schmidt 
934fe723b9aSBill Schmidt     DEBUG(dbgs() << format("%6d", ID));
935fe723b9aSBill Schmidt     DEBUG(dbgs() << format("%6d", EC->getLeaderValue(ID)));
936fe723b9aSBill Schmidt     DEBUG(dbgs() << format(" BB#%3d", MI->getParent()->getNumber()));
937fe723b9aSBill Schmidt     DEBUG(dbgs() << format("  %14s  ", TII->getName(MI->getOpcode())));
938fe723b9aSBill Schmidt 
939fe723b9aSBill Schmidt     if (SwapVector[EntryIdx].IsLoad)
940fe723b9aSBill Schmidt       DEBUG(dbgs() << "load ");
941fe723b9aSBill Schmidt     if (SwapVector[EntryIdx].IsStore)
942fe723b9aSBill Schmidt       DEBUG(dbgs() << "store ");
943fe723b9aSBill Schmidt     if (SwapVector[EntryIdx].IsSwap)
944fe723b9aSBill Schmidt       DEBUG(dbgs() << "swap ");
945fe723b9aSBill Schmidt     if (SwapVector[EntryIdx].MentionsPhysVR)
946fe723b9aSBill Schmidt       DEBUG(dbgs() << "physreg ");
94715deb803SBill Schmidt     if (SwapVector[EntryIdx].MentionsPartialVR)
94815deb803SBill Schmidt       DEBUG(dbgs() << "partialreg ");
949fe723b9aSBill Schmidt 
950fe723b9aSBill Schmidt     if (SwapVector[EntryIdx].IsSwappable) {
951fe723b9aSBill Schmidt       DEBUG(dbgs() << "swappable ");
952fe723b9aSBill Schmidt       switch(SwapVector[EntryIdx].SpecialHandling) {
953fe723b9aSBill Schmidt       default:
954fe723b9aSBill Schmidt         DEBUG(dbgs() << "special:**unknown**");
955fe723b9aSBill Schmidt         break;
956fe723b9aSBill Schmidt       case SH_NONE:
957fe723b9aSBill Schmidt         break;
958fe723b9aSBill Schmidt       case SH_EXTRACT:
959fe723b9aSBill Schmidt         DEBUG(dbgs() << "special:extract ");
960fe723b9aSBill Schmidt         break;
961fe723b9aSBill Schmidt       case SH_INSERT:
962fe723b9aSBill Schmidt         DEBUG(dbgs() << "special:insert ");
963fe723b9aSBill Schmidt         break;
964fe723b9aSBill Schmidt       case SH_NOSWAP_LD:
965fe723b9aSBill Schmidt         DEBUG(dbgs() << "special:load ");
966fe723b9aSBill Schmidt         break;
967fe723b9aSBill Schmidt       case SH_NOSWAP_ST:
968fe723b9aSBill Schmidt         DEBUG(dbgs() << "special:store ");
969fe723b9aSBill Schmidt         break;
970fe723b9aSBill Schmidt       case SH_SPLAT:
971fe723b9aSBill Schmidt         DEBUG(dbgs() << "special:splat ");
972fe723b9aSBill Schmidt         break;
97315deb803SBill Schmidt       case SH_XXPERMDI:
97415deb803SBill Schmidt         DEBUG(dbgs() << "special:xxpermdi ");
97515deb803SBill Schmidt         break;
9762be8054bSBill Schmidt       case SH_COPYWIDEN:
9772be8054bSBill Schmidt         DEBUG(dbgs() << "special:copywiden ");
97815deb803SBill Schmidt         break;
979fe723b9aSBill Schmidt       }
980fe723b9aSBill Schmidt     }
981fe723b9aSBill Schmidt 
982fe723b9aSBill Schmidt     if (SwapVector[EntryIdx].WebRejected)
983fe723b9aSBill Schmidt       DEBUG(dbgs() << "rejected ");
984fe723b9aSBill Schmidt     if (SwapVector[EntryIdx].WillRemove)
985fe723b9aSBill Schmidt       DEBUG(dbgs() << "remove ");
986fe723b9aSBill Schmidt 
987fe723b9aSBill Schmidt     DEBUG(dbgs() << "\n");
988e71db85bSBill Schmidt 
989e71db85bSBill Schmidt     // For no-asserts builds.
990e71db85bSBill Schmidt     (void)MI;
991e71db85bSBill Schmidt     (void)ID;
992fe723b9aSBill Schmidt   }
993fe723b9aSBill Schmidt 
994fe723b9aSBill Schmidt   DEBUG(dbgs() << "\n");
995fe723b9aSBill Schmidt }
996fe723b9aSBill Schmidt 
997f00654e3SAlexander Kornienko } // end default namespace
998fe723b9aSBill Schmidt 
999fe723b9aSBill Schmidt INITIALIZE_PASS_BEGIN(PPCVSXSwapRemoval, DEBUG_TYPE,
1000fe723b9aSBill Schmidt                       "PowerPC VSX Swap Removal", false, false)
1001fe723b9aSBill Schmidt INITIALIZE_PASS_END(PPCVSXSwapRemoval, DEBUG_TYPE,
1002fe723b9aSBill Schmidt                     "PowerPC VSX Swap Removal", false, false)
1003fe723b9aSBill Schmidt 
1004fe723b9aSBill Schmidt char PPCVSXSwapRemoval::ID = 0;
1005fe723b9aSBill Schmidt FunctionPass*
1006fe723b9aSBill Schmidt llvm::createPPCVSXSwapRemovalPass() { return new PPCVSXSwapRemoval(); }
1007