Anton Korobeynikov | 4403b93 | 2009-07-16 13:27:25 +0000 | [diff] [blame] | 1 | //==-- SystemZISelDAGToDAG.cpp - A dag to dag inst selector for SystemZ ---===// |
| 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 file defines an instruction selector for the SystemZ target. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "SystemZ.h" |
| 15 | #include "SystemZISelLowering.h" |
| 16 | #include "SystemZTargetMachine.h" |
| 17 | #include "llvm/DerivedTypes.h" |
| 18 | #include "llvm/Function.h" |
| 19 | #include "llvm/Intrinsics.h" |
| 20 | #include "llvm/CallingConv.h" |
| 21 | #include "llvm/Constants.h" |
| 22 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 23 | #include "llvm/CodeGen/MachineFunction.h" |
| 24 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 25 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| 26 | #include "llvm/CodeGen/SelectionDAG.h" |
| 27 | #include "llvm/CodeGen/SelectionDAGISel.h" |
| 28 | #include "llvm/Target/TargetLowering.h" |
| 29 | #include "llvm/Support/Compiler.h" |
| 30 | #include "llvm/Support/Debug.h" |
| 31 | using namespace llvm; |
| 32 | |
| 33 | /// SystemZDAGToDAGISel - SystemZ specific code to select SystemZ machine |
| 34 | /// instructions for SelectionDAG operations. |
| 35 | /// |
| 36 | namespace { |
| 37 | class SystemZDAGToDAGISel : public SelectionDAGISel { |
| 38 | SystemZTargetLowering &Lowering; |
| 39 | const SystemZSubtarget &Subtarget; |
| 40 | |
| 41 | public: |
| 42 | SystemZDAGToDAGISel(SystemZTargetMachine &TM, CodeGenOpt::Level OptLevel) |
| 43 | : SelectionDAGISel(TM, OptLevel), |
| 44 | Lowering(*TM.getTargetLowering()), |
| 45 | Subtarget(*TM.getSubtargetImpl()) { } |
| 46 | |
| 47 | virtual void InstructionSelect(); |
| 48 | |
| 49 | virtual const char *getPassName() const { |
| 50 | return "SystemZ DAG->DAG Pattern Instruction Selection"; |
| 51 | } |
| 52 | |
Anton Korobeynikov | 89edcd0 | 2009-07-16 13:33:57 +0000 | [diff] [blame^] | 53 | /// getI16Imm - Return a target constant with the specified value, of type |
| 54 | /// i16. |
| 55 | inline SDValue getI16Imm(uint64_t Imm) { |
| 56 | return CurDAG->getTargetConstant(Imm, MVT::i16); |
| 57 | } |
| 58 | |
Anton Korobeynikov | 4403b93 | 2009-07-16 13:27:25 +0000 | [diff] [blame] | 59 | // Include the pieces autogenerated from the target description. |
Anton Korobeynikov | 89edcd0 | 2009-07-16 13:33:57 +0000 | [diff] [blame^] | 60 | #include "SystemZGenDAGISel.inc" |
Anton Korobeynikov | 4403b93 | 2009-07-16 13:27:25 +0000 | [diff] [blame] | 61 | |
| 62 | private: |
| 63 | SDNode *Select(SDValue Op); |
| 64 | |
| 65 | #ifndef NDEBUG |
| 66 | unsigned Indent; |
| 67 | #endif |
| 68 | }; |
| 69 | } // end anonymous namespace |
| 70 | |
| 71 | /// createSystemZISelDag - This pass converts a legalized DAG into a |
| 72 | /// SystemZ-specific DAG, ready for instruction scheduling. |
| 73 | /// |
| 74 | FunctionPass *llvm::createSystemZISelDag(SystemZTargetMachine &TM, |
| 75 | CodeGenOpt::Level OptLevel) { |
| 76 | return new SystemZDAGToDAGISel(TM, OptLevel); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | /// InstructionSelect - This callback is invoked by |
| 81 | /// SelectionDAGISel when it has created a SelectionDAG for us to codegen. |
| 82 | void SystemZDAGToDAGISel::InstructionSelect() { |
| 83 | DEBUG(BB->dump()); |
| 84 | |
| 85 | // Codegen the basic block. |
| 86 | #ifndef NDEBUG |
| 87 | DOUT << "===== Instruction selection begins:\n"; |
| 88 | Indent = 0; |
| 89 | #endif |
| 90 | SelectRoot(*CurDAG); |
| 91 | #ifndef NDEBUG |
| 92 | DOUT << "===== Instruction selection ends:\n"; |
| 93 | #endif |
| 94 | |
| 95 | CurDAG->RemoveDeadNodes(); |
| 96 | } |
| 97 | |
| 98 | SDNode *SystemZDAGToDAGISel::Select(SDValue Op) { |
| 99 | SDNode *Node = Op.getNode(); |
| 100 | DebugLoc dl = Op.getDebugLoc(); |
| 101 | |
| 102 | // Dump information about the Node being selected |
| 103 | #ifndef NDEBUG |
| 104 | DOUT << std::string(Indent, ' ') << "Selecting: "; |
| 105 | DEBUG(Node->dump(CurDAG)); |
| 106 | DOUT << "\n"; |
| 107 | Indent += 2; |
| 108 | #endif |
| 109 | |
| 110 | // If we have a custom node, we already have selected! |
| 111 | if (Node->isMachineOpcode()) { |
| 112 | #ifndef NDEBUG |
| 113 | DOUT << std::string(Indent-2, ' ') << "== "; |
| 114 | DEBUG(Node->dump(CurDAG)); |
| 115 | DOUT << "\n"; |
| 116 | Indent -= 2; |
| 117 | #endif |
| 118 | return NULL; |
| 119 | } |
| 120 | |
| 121 | // Select the default instruction |
| 122 | SDNode *ResNode = SelectCode(Op); |
| 123 | |
| 124 | #ifndef NDEBUG |
| 125 | DOUT << std::string(Indent-2, ' ') << "=> "; |
| 126 | if (ResNode == NULL || ResNode == Op.getNode()) |
| 127 | DEBUG(Op.getNode()->dump(CurDAG)); |
| 128 | else |
| 129 | DEBUG(ResNode->dump(CurDAG)); |
| 130 | DOUT << "\n"; |
| 131 | Indent -= 2; |
| 132 | #endif |
| 133 | |
| 134 | return ResNode; |
| 135 | } |