• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- Nios2ISelDAGToDAG.cpp - A Dag to Dag Inst Selector for Nios2 ------===//
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 NIOS2 target.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "Nios2.h"
15 #include "Nios2TargetMachine.h"
16 #include "llvm/CodeGen/SelectionDAGISel.h"
17 #include "llvm/Support/Debug.h"
18 using namespace llvm;
19 
20 #define DEBUG_TYPE "nios2-isel"
21 
22 //===----------------------------------------------------------------------===//
23 // Instruction Selector Implementation
24 //===----------------------------------------------------------------------===//
25 
26 //===----------------------------------------------------------------------===//
27 // Nios2DAGToDAGISel - NIOS2 specific code to select NIOS2 machine
28 // instructions for SelectionDAG operations.
29 //===----------------------------------------------------------------------===//
30 
31 namespace {
32 
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;
37 
38 public:
Nios2DAGToDAGISel(Nios2TargetMachine & TM,CodeGenOpt::Level OL)39   explicit Nios2DAGToDAGISel(Nios2TargetMachine &TM, CodeGenOpt::Level OL)
40       : SelectionDAGISel(TM, OL) {}
41 
runOnMachineFunction(MachineFunction & MF)42   bool runOnMachineFunction(MachineFunction &MF) override {
43     Subtarget = &MF.getSubtarget<Nios2Subtarget>();
44     return SelectionDAGISel::runOnMachineFunction(MF);
45   }
46 
47   void Select(SDNode *N) override;
48 
49   // Pass Name
getPassName() const50   StringRef getPassName() const override {
51     return "NIOS2 DAG->DAG Pattern Instruction Selection";
52   }
53 
54 #include "Nios2GenDAGISel.inc"
55 };
56 } // namespace
57 
58 // Select instructions not customized! Used for
59 // expanded, promoted and normal instructions
Select(SDNode * Node)60 void Nios2DAGToDAGISel::Select(SDNode *Node) {
61 
62   // If we have a custom node, we already have selected!
63   if (Node->isMachineOpcode()) {
64     LLVM_DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n");
65     Node->setNodeId(-1);
66     return;
67   }
68 
69   // Select the default instruction
70   SelectCode(Node);
71 }
72 
createNios2ISelDag(Nios2TargetMachine & TM,CodeGenOpt::Level OptLevel)73 FunctionPass *llvm::createNios2ISelDag(Nios2TargetMachine &TM,
74                                        CodeGenOpt::Level OptLevel) {
75   return new Nios2DAGToDAGISel(TM, OptLevel);
76 }
77