LLVM  7.0.0
Nios2ISelDAGToDAG.cpp
Go to the documentation of this file.
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"
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:
39  explicit Nios2DAGToDAGISel(Nios2TargetMachine &TM, CodeGenOpt::Level OL)
40  : SelectionDAGISel(TM, OL) {}
41 
42  bool runOnMachineFunction(MachineFunction &MF) override {
43  Subtarget = &MF.getSubtarget<Nios2Subtarget>();
45  }
46 
47  void Select(SDNode *N) override;
48 
49  // Pass Name
50  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
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 
74  CodeGenOpt::Level OptLevel) {
75  return new Nios2DAGToDAGISel(TM, OptLevel);
76 }
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
void setNodeId(int Id)
Set unique node id.
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:285
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode...
void dump() const
Dump this node, for debugging.
FunctionPass * createNios2ISelDag(Nios2TargetMachine &TM, CodeGenOpt::Level OptLevel)
Represents one node in the SelectionDAG.
SelectionDAGISel - This is the common base class used for SelectionDAG-based pattern-matching instruc...
#define N
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
#define LLVM_DEBUG(X)
Definition: Debug.h:119