1 //===-- HexagonSplitTFRCondSets.cpp - split TFR condsets into xfers -------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
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;
14 // {p0 = cmp.eq(r0,r1)}
15 // {r3 = mux(p0,#1,#3)}
17 // This requires two packets. If we use .new predicated immediate transfers,
18 // then we can do this in a single packet, e.g.:
20 // {p0 = cmp.eq(r0,r1)
21 // if (p0.new) r3 = #1
22 // if (!p0.new) r3 = #3}
24 // Note that the conditional assignments are not generated in .new form here.
25 // We assume opptimisically that they will be formed later.
27 //===----------------------------------------------------------------------===//
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"
51 #define DEBUG_TYPE "xfer"
54 void initializeHexagonSplitTFRCondSetsPass(PassRegistry&);
60 class HexagonSplitTFRCondSets : public MachineFunctionPass {
63 HexagonSplitTFRCondSets() : MachineFunctionPass(ID) {
64 initializeHexagonSplitTFRCondSetsPass(*PassRegistry::getPassRegistry());
67 const char *getPassName() const override {
68 return "Hexagon Split TFRCondSets";
70 bool runOnMachineFunction(MachineFunction &Fn) override;
74 char HexagonSplitTFRCondSets::ID = 0;
77 bool HexagonSplitTFRCondSets::runOnMachineFunction(MachineFunction &Fn) {
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();
87 MachineInstr *MI = MII;
88 switch(MI->getOpcode()) {
97 //===----------------------------------------------------------------------===//
98 // Public Constructor Functions
99 //===----------------------------------------------------------------------===//
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,
106 Registry.registerPass(*PI, true);
109 void llvm::initializeHexagonSplitTFRCondSetsPass(PassRegistry &Registry) {
110 CALL_ONCE_INITIALIZATION(initializePassOnce)
113 FunctionPass *llvm::createHexagonSplitTFRCondSets() {
114 return new HexagonSplitTFRCondSets();