Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 1 | //===-- PIC16ISelDAGToDAG.cpp - A dag to dag inst selector for PIC16 ------===// |
| 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 PIC16 target. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #define DEBUG_TYPE "pic16-isel" |
| 15 | |
Torok Edwin | dac237e | 2009-07-08 20:53:28 +0000 | [diff] [blame] | 16 | #include "llvm/Support/ErrorHandling.h" |
| 17 | #include "llvm/Support/raw_ostream.h" |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 18 | #include "PIC16ISelDAGToDAG.h" |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 19 | #include "llvm/Support/Debug.h" |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 20 | |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 21 | using namespace llvm; |
| 22 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 23 | /// createPIC16ISelDag - This pass converts a legalized DAG into a |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 24 | /// PIC16-specific DAG, ready for instruction scheduling. |
| 25 | FunctionPass *llvm::createPIC16ISelDag(PIC16TargetMachine &TM) { |
| 26 | return new PIC16DAGToDAGISel(TM); |
| 27 | } |
| 28 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 29 | |
| 30 | /// InstructionSelect - This callback is invoked by |
| 31 | /// SelectionDAGISel when it has created a SelectionDAG for us to codegen. |
| 32 | void PIC16DAGToDAGISel::InstructionSelect() { |
| 33 | DEBUG(BB->dump()); |
| 34 | SelectRoot(*CurDAG); |
| 35 | CurDAG->RemoveDeadNodes(); |
| 36 | } |
| 37 | |
| 38 | /// Select - Select instructions not customized! Used for |
| 39 | /// expanded, promoted and normal instructions. |
| 40 | SDNode* PIC16DAGToDAGISel::Select(SDValue N) { |
| 41 | |
| 42 | // Select the default instruction. |
| 43 | SDNode *ResNode = SelectCode(N); |
| 44 | |
| 45 | return ResNode; |
| 46 | } |
| 47 | |
| 48 | |
| 49 | // SelectDirectAddr - Match a direct address for DAG. |
| 50 | // A direct address could be a globaladdress or externalsymbol. |
| 51 | bool PIC16DAGToDAGISel::SelectDirectAddr(SDValue Op, SDValue N, |
| 52 | SDValue &Address) { |
| 53 | // Return true if TGA or ES. |
| 54 | if (N.getOpcode() == ISD::TargetGlobalAddress |
| 55 | || N.getOpcode() == ISD::TargetExternalSymbol) { |
| 56 | Address = N; |
| 57 | return true; |
| 58 | } |
| 59 | |
| 60 | return false; |
| 61 | } |