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 /// getI32Imm - Return a target constant with the specified value, of type
61 inline SDValue getI32Imm(uint64_t Imm) {
62 return CurDAG->getTargetConstant(Imm, MVT::i32);
65 // Include the pieces autogenerated from the target description.
66 #include "SystemZGenDAGISel.inc"
69 SDNode *Select(SDValue Op);
75 } // end anonymous namespace
77 /// createSystemZISelDag - This pass converts a legalized DAG into a
78 /// SystemZ-specific DAG, ready for instruction scheduling.
80 FunctionPass *llvm::createSystemZISelDag(SystemZTargetMachine &TM,
81 CodeGenOpt::Level OptLevel) {
82 return new SystemZDAGToDAGISel(TM, OptLevel);
86 /// InstructionSelect - This callback is invoked by
87 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
88 void SystemZDAGToDAGISel::InstructionSelect() {
91 // Codegen the basic block.
93 DOUT << "===== Instruction selection begins:\n";
98 DOUT << "===== Instruction selection ends:\n";
101 CurDAG->RemoveDeadNodes();
104 SDNode *SystemZDAGToDAGISel::Select(SDValue Op) {
105 SDNode *Node = Op.getNode();
106 DebugLoc dl = Op.getDebugLoc();
108 // Dump information about the Node being selected
110 DOUT << std::string(Indent, ' ') << "Selecting: ";
111 DEBUG(Node->dump(CurDAG));
116 // If we have a custom node, we already have selected!
117 if (Node->isMachineOpcode()) {
119 DOUT << std::string(Indent-2, ' ') << "== ";
120 DEBUG(Node->dump(CurDAG));
127 // Select the default instruction
128 SDNode *ResNode = SelectCode(Op);
131 DOUT << std::string(Indent-2, ' ') << "=> ";
132 if (ResNode == NULL || ResNode == Op.getNode())
133 DEBUG(Op.getNode()->dump(CurDAG));
135 DEBUG(ResNode->dump(CurDAG));