2008-05-13 09:02:57 +00:00
|
|
|
//===-- PIC16ISelLowering.h - PIC16 DAG Lowering Interface ------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the interfaces that PIC16 uses to lower LLVM code into a
|
|
|
|
// selection DAG.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef PIC16ISELLOWERING_H
|
|
|
|
#define PIC16ISELLOWERING_H
|
|
|
|
|
|
|
|
#include "PIC16.h"
|
|
|
|
#include "PIC16Subtarget.h"
|
2008-05-14 11:31:39 +00:00
|
|
|
#include "llvm/CodeGen/SelectionDAG.h"
|
|
|
|
#include "llvm/Target/TargetLowering.h"
|
2008-05-13 09:02:57 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace PIC16ISD {
|
|
|
|
enum NodeType {
|
|
|
|
// Start the numbering from where ISD NodeType finishes.
|
2008-09-23 18:42:32 +00:00
|
|
|
FIRST_NUMBER = ISD::BUILTIN_OP_END,
|
2008-05-13 09:02:57 +00:00
|
|
|
|
2008-11-19 11:00:54 +00:00
|
|
|
Lo, // Low 8-bits of GlobalAddress.
|
|
|
|
Hi, // High 8-bits of GlobalAddress.
|
|
|
|
PIC16Load,
|
2009-01-13 19:18:47 +00:00
|
|
|
PIC16LdWF,
|
2008-11-19 11:00:54 +00:00
|
|
|
PIC16Store,
|
2009-01-13 19:18:47 +00:00
|
|
|
PIC16StWF,
|
2008-11-19 11:00:54 +00:00
|
|
|
Banksel,
|
|
|
|
MTLO,
|
|
|
|
MTHI,
|
|
|
|
BCF,
|
|
|
|
LSLF, // PIC16 Logical shift left
|
|
|
|
LRLF, // PIC16 Logical shift right
|
|
|
|
RLF, // Rotate left through carry
|
|
|
|
RRF, // Rotate right through carry
|
2009-01-13 19:18:47 +00:00
|
|
|
CALL, // PIC16 Call instruction
|
|
|
|
SUBCC, // Compare for equality or inequality.
|
|
|
|
SELECT_ICC, // Psuedo to be caught in schedular and expanded to brcond.
|
|
|
|
BRCOND, // Conditional branch.
|
2008-11-19 11:00:54 +00:00
|
|
|
Dummy
|
|
|
|
};
|
|
|
|
|
|
|
|
// Keep track of different address spaces.
|
|
|
|
enum AddressSpace {
|
|
|
|
RAM_SPACE = 0, // RAM address space
|
|
|
|
ROM_SPACE = 1 // ROM address space number is 1
|
2008-05-13 09:02:57 +00:00
|
|
|
};
|
2009-01-21 05:44:05 +00:00
|
|
|
enum PIC16Libcall {
|
|
|
|
MUL_I8,
|
2009-01-13 19:18:47 +00:00
|
|
|
SRA_I8,
|
|
|
|
SLL_I8,
|
|
|
|
SRL_I8,
|
|
|
|
PIC16UnknownCall
|
|
|
|
};
|
2008-05-13 09:02:57 +00:00
|
|
|
}
|
|
|
|
|
2009-01-13 19:18:47 +00:00
|
|
|
|
2008-05-13 09:02:57 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// TargetLowering Implementation
|
|
|
|
//===--------------------------------------------------------------------===//
|
2008-11-19 11:00:54 +00:00
|
|
|
class PIC16TargetLowering : public TargetLowering {
|
2008-05-13 09:02:57 +00:00
|
|
|
public:
|
|
|
|
explicit PIC16TargetLowering(PIC16TargetMachine &TM);
|
|
|
|
|
2008-11-19 11:00:54 +00:00
|
|
|
/// getTargetNodeName - This method returns the name of a target specific
|
|
|
|
/// DAG node.
|
2008-05-13 09:02:57 +00:00
|
|
|
virtual const char *getTargetNodeName(unsigned Opcode) const;
|
2009-01-13 19:18:47 +00:00
|
|
|
/// getSetCCResultType - Return the ISD::SETCC ValueType
|
|
|
|
virtual MVT getSetCCResultType(MVT ValType) const;
|
2008-11-19 11:00:54 +00:00
|
|
|
SDValue LowerFORMAL_ARGUMENTS(SDValue Op, SelectionDAG &DAG);
|
2009-01-21 05:44:05 +00:00
|
|
|
SDValue LowerShift(SDValue Op, SelectionDAG &DAG);
|
2009-01-13 19:18:47 +00:00
|
|
|
SDValue LowerADD(SDValue Op, SelectionDAG &DAG);
|
|
|
|
SDValue LowerSUB(SDValue Op, SelectionDAG &DAG);
|
2008-11-26 10:53:50 +00:00
|
|
|
SDValue LowerBinOp(SDValue Op, SelectionDAG &DAG);
|
2009-01-13 19:18:47 +00:00
|
|
|
SDValue LowerCALL(SDValue Op, SelectionDAG &DAG);
|
|
|
|
SDValue LowerRET(SDValue Op, SelectionDAG &DAG);
|
|
|
|
SDValue LowerCallReturn(SDValue Op, SDValue Chain, SDValue FrameAddress,
|
|
|
|
SDValue InFlag, SelectionDAG &DAG);
|
|
|
|
SDValue LowerCallArguments(SDValue Op, SDValue Chain, SDValue FrameAddress,
|
|
|
|
SDValue InFlag, SelectionDAG &DAG);
|
|
|
|
SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG);
|
|
|
|
SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG);
|
|
|
|
SDValue getPIC16Cmp(SDValue LHS, SDValue RHS, unsigned OrigCC, SDValue &CC,
|
|
|
|
SelectionDAG &DAG);
|
|
|
|
virtual MachineBasicBlock *EmitInstrWithCustomInserter(MachineInstr *MI,
|
|
|
|
MachineBasicBlock *MBB);
|
|
|
|
|
|
|
|
|
2009-01-21 05:44:05 +00:00
|
|
|
virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG);
|
2009-01-13 19:18:47 +00:00
|
|
|
virtual void ReplaceNodeResults(SDNode *N,
|
|
|
|
SmallVectorImpl<SDValue> &Results,
|
2008-12-01 11:39:25 +00:00
|
|
|
SelectionDAG &DAG);
|
2009-01-21 09:00:29 +00:00
|
|
|
virtual void LowerOperationWrapper(SDNode *N,
|
|
|
|
SmallVectorImpl<SDValue> &Results,
|
|
|
|
SelectionDAG &DAG);
|
2009-01-21 05:44:05 +00:00
|
|
|
|
2008-12-01 11:39:25 +00:00
|
|
|
SDValue ExpandStore(SDNode *N, SelectionDAG &DAG);
|
|
|
|
SDValue ExpandLoad(SDNode *N, SelectionDAG &DAG);
|
2009-01-13 19:18:47 +00:00
|
|
|
//SDValue ExpandAdd(SDNode *N, SelectionDAG &DAG);
|
2008-12-01 11:39:25 +00:00
|
|
|
SDValue ExpandGlobalAddress(SDNode *N, SelectionDAG &DAG);
|
2009-01-13 19:18:47 +00:00
|
|
|
SDValue ExpandExternalSymbol(SDNode *N, SelectionDAG &DAG);
|
|
|
|
SDValue ExpandFrameIndex(SDNode *N, SelectionDAG &DAG);
|
2008-11-19 11:00:54 +00:00
|
|
|
|
|
|
|
SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
|
|
|
|
SDValue PerformPIC16LoadCombine(SDNode *N, DAGCombinerInfo &DCI) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// If the Node is a BUILD_PAIR representing representing an Address
|
|
|
|
// then this function will return true
|
|
|
|
bool isDirectAddress(const SDValue &Op);
|
|
|
|
|
|
|
|
// If the Node is a DirectAddress in ROM_SPACE then this
|
|
|
|
// function will return true
|
|
|
|
bool isRomAddress(const SDValue &Op);
|
|
|
|
|
|
|
|
// To extract chain value from the SDValue Nodes
|
|
|
|
// This function will help to maintain the chain extracting
|
|
|
|
// code at one place. In case of any change in future it will
|
|
|
|
// help maintain the code
|
|
|
|
SDValue getChain(SDValue &Op);
|
2009-01-13 19:18:47 +00:00
|
|
|
|
|
|
|
SDValue getOutFlag(SDValue &Op);
|
2008-11-19 11:00:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Extract the Lo and Hi component of Op.
|
|
|
|
void GetExpandedParts(SDValue Op, SelectionDAG &DAG, SDValue &Lo,
|
|
|
|
SDValue &Hi);
|
|
|
|
|
|
|
|
|
|
|
|
// Load pointer can be a direct or indirect address. In PIC16 direct
|
|
|
|
// addresses need Banksel and Indirect addresses need to be loaded to
|
|
|
|
// FSR first. Handle address specific cases here.
|
|
|
|
void LegalizeAddress(SDValue Ptr, SelectionDAG &DAG, SDValue &Chain,
|
|
|
|
SDValue &NewPtr, unsigned &Offset);
|
|
|
|
|
2009-01-13 19:18:47 +00:00
|
|
|
// FrameIndex should be broken down into ExternalSymbol and FrameOffset.
|
|
|
|
void LegalizeFrameIndex(SDValue Op, SelectionDAG &DAG, SDValue &ES,
|
|
|
|
int &Offset);
|
|
|
|
|
2008-11-19 11:00:54 +00:00
|
|
|
// We can not have both operands of a binary operation in W.
|
|
|
|
// This function is used to put one operand on stack and generate a load.
|
|
|
|
SDValue ConvertToMemOperand(SDValue Op, SelectionDAG &DAG);
|
|
|
|
|
2009-01-13 19:18:47 +00:00
|
|
|
// This function checks if we need to put an operand of an operation on
|
|
|
|
// stack and generate a load or not.
|
|
|
|
bool NeedToConvertToMemOp(SDValue Op, unsigned &MemOp);
|
|
|
|
|
2008-11-19 11:00:54 +00:00
|
|
|
/// Subtarget - Keep a pointer to the PIC16Subtarget around so that we can
|
|
|
|
/// make the right decision when generating code for different targets.
|
|
|
|
const PIC16Subtarget *Subtarget;
|
2009-01-13 19:18:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Extending the LIB Call framework of LLVM
|
2009-01-21 05:44:05 +00:00
|
|
|
// To hold the names of PIC16Libcalls
|
|
|
|
const char *PIC16LibcallNames[PIC16ISD::PIC16UnknownCall];
|
2009-01-13 19:18:47 +00:00
|
|
|
|
|
|
|
// To set and retrieve the lib call names
|
2009-01-21 05:44:05 +00:00
|
|
|
void setPIC16LibcallName(PIC16ISD::PIC16Libcall Call, const char *Name);
|
|
|
|
const char *getPIC16LibcallName(PIC16ISD::PIC16Libcall Call);
|
2009-01-13 19:18:47 +00:00
|
|
|
|
2009-01-21 05:44:05 +00:00
|
|
|
// Make PIC16 Libcall
|
|
|
|
SDValue MakePIC16Libcall(PIC16ISD::PIC16Libcall Call, MVT RetVT,
|
2009-01-13 19:18:47 +00:00
|
|
|
const SDValue *Ops, unsigned NumOps, bool isSigned,
|
2009-01-30 23:10:59 +00:00
|
|
|
SelectionDAG &DAG, DebugLoc dl);
|
2009-01-13 19:18:47 +00:00
|
|
|
|
|
|
|
// Check if operation has a direct load operand.
|
|
|
|
inline bool isDirectLoad(const SDValue Op);
|
|
|
|
|
|
|
|
// Create the symbol and index for function frame
|
|
|
|
void getCurrentFrameIndex(SelectionDAG &DAG, SDValue &ES,
|
|
|
|
unsigned SlotSize, int &FI);
|
|
|
|
|
|
|
|
SDValue getCurrentFrame(SelectionDAG &DAG);
|
2008-05-13 09:02:57 +00:00
|
|
|
};
|
|
|
|
} // namespace llvm
|
|
|
|
|
|
|
|
#endif // PIC16ISELLOWERING_H
|