2673425e7557cef1a82353d54c7a80d682bcb764
[oota-llvm.git] / lib / Target / Hexagon / HexagonSplitTFRCondSets.cpp
1 //===-- HexagonSplitTFRCondSets.cpp - split TFR condsets into xfers -------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //
9 //===----------------------------------------------------------------------===//
10 // This pass tries to provide opportunities for better optimization of muxes.
11 // The default code generated for something like: flag = (a == b) ? 1 : 3;
12 // would be:
13 //
14 //   {p0 = cmp.eq(r0,r1)}
15 //   {r3 = mux(p0,#1,#3)}
16 //
17 // This requires two packets.  If we use .new predicated immediate transfers,
18 // then we can do this in a single packet, e.g.:
19 //
20 //   {p0 = cmp.eq(r0,r1)
21 //    if (p0.new) r3 = #1
22 //    if (!p0.new) r3 = #3}
23 //
24 // Note that the conditional assignments are not generated in .new form here.
25 // We assume opptimisically that they will be formed later.
26 //
27 //===----------------------------------------------------------------------===//
28
29 #include "Hexagon.h"
30 #include "HexagonMachineFunctionInfo.h"
31 #include "HexagonSubtarget.h"
32 #include "HexagonTargetMachine.h"
33 #include "llvm/CodeGen/LatencyPriorityQueue.h"
34 #include "llvm/CodeGen/MachineDominators.h"
35 #include "llvm/CodeGen/MachineFunctionPass.h"
36 #include "llvm/CodeGen/MachineInstrBuilder.h"
37 #include "llvm/CodeGen/MachineLoopInfo.h"
38 #include "llvm/CodeGen/MachineRegisterInfo.h"
39 #include "llvm/CodeGen/Passes.h"
40 #include "llvm/CodeGen/ScheduleHazardRecognizer.h"
41 #include "llvm/CodeGen/SchedulerRegistry.h"
42 #include "llvm/Support/Compiler.h"
43 #include "llvm/Support/Debug.h"
44 #include "llvm/Support/MathExtras.h"
45 #include "llvm/Target/TargetInstrInfo.h"
46 #include "llvm/Target/TargetMachine.h"
47 #include "llvm/Target/TargetRegisterInfo.h"
48
49 using namespace llvm;
50
51 #define DEBUG_TYPE "xfer"
52
53 namespace llvm {
54   void initializeHexagonSplitTFRCondSetsPass(PassRegistry&);
55 }
56
57
58 namespace {
59
60 class HexagonSplitTFRCondSets : public MachineFunctionPass {
61  public:
62     static char ID;
63     HexagonSplitTFRCondSets() : MachineFunctionPass(ID) {
64       initializeHexagonSplitTFRCondSetsPass(*PassRegistry::getPassRegistry());
65     }
66
67     const char *getPassName() const override {
68       return "Hexagon Split TFRCondSets";
69     }
70     bool runOnMachineFunction(MachineFunction &Fn) override;
71 };
72
73
74 char HexagonSplitTFRCondSets::ID = 0;
75
76
77 bool HexagonSplitTFRCondSets::runOnMachineFunction(MachineFunction &Fn) {
78
79
80   // Loop over all of the basic blocks.
81   for (MachineFunction::iterator MBBb = Fn.begin(), MBBe = Fn.end();
82        MBBb != MBBe; ++MBBb) {
83     MachineBasicBlock* MBB = MBBb;
84     // Traverse the basic block.
85     for (MachineBasicBlock::iterator MII = MBB->begin(); MII != MBB->end();
86          ++MII) {
87       MachineInstr *MI = MII;
88       switch(MI->getOpcode()) {
89       }
90     }
91   }
92   return true;
93 }
94
95 }
96
97 //===----------------------------------------------------------------------===//
98 //                         Public Constructor Functions
99 //===----------------------------------------------------------------------===//
100
101 static void initializePassOnce(PassRegistry &Registry) {
102   const char *Name = "Hexagon Split TFRCondSets";
103   PassInfo *PI = new PassInfo(Name, "hexagon-split-tfr",
104                               &HexagonSplitTFRCondSets::ID, nullptr, false,
105                               false);
106   Registry.registerPass(*PI, true);
107 }
108
109 void llvm::initializeHexagonSplitTFRCondSetsPass(PassRegistry &Registry) {
110   CALL_ONCE_INITIALIZATION(initializePassOnce)
111 }
112
113 FunctionPass *llvm::createHexagonSplitTFRCondSets() {
114   return new HexagonSplitTFRCondSets();
115 }