1 //==-- SystemZISelDAGToDAG.cpp - A dag to dag inst selector for SystemZ ---===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines an instruction selector for the SystemZ target.
12 //===----------------------------------------------------------------------===//
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"
33 /// SystemZDAGToDAGISel - SystemZ specific code to select SystemZ machine
34 /// instructions for SelectionDAG operations.
37 class SystemZDAGToDAGISel : public SelectionDAGISel {
38 SystemZTargetLowering &Lowering;
39 const SystemZSubtarget &Subtarget;
42 SystemZDAGToDAGISel(SystemZTargetMachine &TM, CodeGenOpt::Level OptLevel)
43 : SelectionDAGISel(TM, OptLevel),
44 Lowering(*TM.getTargetLowering()),
45 Subtarget(*TM.getSubtargetImpl()) { }
47 virtual void InstructionSelect();
49 virtual const char *getPassName() const {
50 return "SystemZ DAG->DAG Pattern Instruction Selection";
53 /// getI16Imm - Return a target constant with the specified value, of type
55 inline SDValue getI16Imm(uint64_t Imm) {
56 return CurDAG->getTargetConstant(Imm, MVT::i16);
59 // Include the pieces autogenerated from the target description.
60 #include "SystemZGenDAGISel.inc"
63 SDNode *Select(SDValue Op);
69 } // end anonymous namespace
71 /// createSystemZISelDag - This pass converts a legalized DAG into a
72 /// SystemZ-specific DAG, ready for instruction scheduling.
74 FunctionPass *llvm::createSystemZISelDag(SystemZTargetMachine &TM,
75 CodeGenOpt::Level OptLevel) {
76 return new SystemZDAGToDAGISel(TM, OptLevel);
80 /// InstructionSelect - This callback is invoked by
81 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
82 void SystemZDAGToDAGISel::InstructionSelect() {
85 // Codegen the basic block.
87 DOUT << "===== Instruction selection begins:\n";
92 DOUT << "===== Instruction selection ends:\n";
95 CurDAG->RemoveDeadNodes();
98 SDNode *SystemZDAGToDAGISel::Select(SDValue Op) {
99 SDNode *Node = Op.getNode();
100 DebugLoc dl = Op.getDebugLoc();
102 // Dump information about the Node being selected
104 DOUT << std::string(Indent, ' ') << "Selecting: ";
105 DEBUG(Node->dump(CurDAG));
110 // If we have a custom node, we already have selected!
111 if (Node->isMachineOpcode()) {
113 DOUT << std::string(Indent-2, ' ') << "== ";
114 DEBUG(Node->dump(CurDAG));
121 // Select the default instruction
122 SDNode *ResNode = SelectCode(Op);
125 DOUT << std::string(Indent-2, ' ') << "=> ";
126 if (ResNode == NULL || ResNode == Op.getNode())
127 DEBUG(Op.getNode()->dump(CurDAG));
129 DEBUG(ResNode->dump(CurDAG));