1 //===-- CSKYISelDAGToDAG.cpp - A dag to dag inst selector for CSKY---------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file defines an instruction selector for the CSKY target. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "CSKY.h" 14 #include "CSKYSubtarget.h" 15 #include "CSKYTargetMachine.h" 16 #include "MCTargetDesc/CSKYMCTargetDesc.h" 17 #include "llvm/CodeGen/SelectionDAG.h" 18 #include "llvm/CodeGen/SelectionDAGISel.h" 19 20 using namespace llvm; 21 22 #define DEBUG_TYPE "csky-isel" 23 24 namespace { 25 class CSKYDAGToDAGISel : public SelectionDAGISel { 26 const CSKYSubtarget *Subtarget; 27 28 public: 29 explicit CSKYDAGToDAGISel(CSKYTargetMachine &TM) : SelectionDAGISel(TM) {} 30 31 StringRef getPassName() const override { 32 return "CSKY DAG->DAG Pattern Instruction Selection"; 33 } 34 35 bool runOnMachineFunction(MachineFunction &MF) override { 36 // Reset the subtarget each time through. 37 Subtarget = &MF.getSubtarget<CSKYSubtarget>(); 38 SelectionDAGISel::runOnMachineFunction(MF); 39 return true; 40 } 41 42 void Select(SDNode *N) override; 43 44 #include "CSKYGenDAGISel.inc" 45 }; 46 } // namespace 47 48 void CSKYDAGToDAGISel::Select(SDNode *N) { 49 // If we have a custom node, we have already selected 50 if (N->isMachineOpcode()) { 51 LLVM_DEBUG(dbgs() << "== "; N->dump(CurDAG); dbgs() << "\n"); 52 N->setNodeId(-1); 53 return; 54 } 55 56 SDLoc Dl(N); 57 unsigned Opcode = N->getOpcode(); 58 bool IsSelected = false; 59 60 switch (Opcode) { 61 default: 62 break; 63 // FIXME: Add selection nodes needed later. 64 } 65 66 if (IsSelected) 67 return; 68 69 // Select the default instruction. 70 SelectCode(N); 71 } 72 73 FunctionPass *llvm::createCSKYISelDag(CSKYTargetMachine &TM) { 74 return new CSKYDAGToDAGISel(TM); 75 } 76