1 //===-- Nios2ISelDAGToDAG.cpp - A Dag to Dag Inst Selector for Nios2 ------===//
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 NIOS2 target.
12 //===----------------------------------------------------------------------===//
15 #include "Nios2TargetMachine.h"
16 #include "llvm/CodeGen/SelectionDAGISel.h"
17 #include "llvm/Support/Debug.h"
20 #define DEBUG_TYPE "nios2-isel"
22 //===----------------------------------------------------------------------===//
23 // Instruction Selector Implementation
24 //===----------------------------------------------------------------------===//
26 //===----------------------------------------------------------------------===//
27 // Nios2DAGToDAGISel - NIOS2 specific code to select NIOS2 machine
28 // instructions for SelectionDAG operations.
29 //===----------------------------------------------------------------------===//
33 class Nios2DAGToDAGISel : public SelectionDAGISel {
34 /// Subtarget - Keep a pointer to the Nios2 Subtarget around so that we can
35 /// make the right decision when generating code for different targets.
36 const Nios2Subtarget *Subtarget;
39 explicit Nios2DAGToDAGISel(Nios2TargetMachine &TM, CodeGenOpt::Level OL)
40 : SelectionDAGISel(TM, OL) {}
42 bool runOnMachineFunction(MachineFunction &MF) override {
43 Subtarget = &MF.getSubtarget<Nios2Subtarget>();
44 return SelectionDAGISel::runOnMachineFunction(MF);
47 void Select(SDNode *N) override;
50 StringRef getPassName() const override {
51 return "NIOS2 DAG->DAG Pattern Instruction Selection";
54 #include "Nios2GenDAGISel.inc"
58 // Select instructions not customized! Used for
59 // expanded, promoted and normal instructions
60 void Nios2DAGToDAGISel::Select(SDNode *Node) {
62 // If we have a custom node, we already have selected!
63 if (Node->isMachineOpcode()) {
64 LLVM_DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n");
69 // Select the default instruction
73 FunctionPass *llvm::createNios2ISelDag(Nios2TargetMachine &TM,
74 CodeGenOpt::Level OptLevel) {
75 return new Nios2DAGToDAGISel(TM, OptLevel);