Improved the Register Banking algorithm.
[fw/sdcc] / src / pic / pcode.h
index 007b9a50d5dd1a367e6c2a5415609eeefa0f55bd..8e4dd51acb5c49fc9a77d119074ce43f0a6062d4 100644 (file)
@@ -228,12 +228,14 @@ typedef enum
 typedef enum
 {
   PC_COMMENT=0,   /* pCode is a comment     */
+  PC_INLINE,      /* user's inline code     */
   PC_OPCODE,      /* PORT dependent opcode  */
   PC_LABEL,       /* assembly label         */
   PC_FLOW,        /* flow analysis          */
   PC_FUNCTION,    /* Function start or end  */
-  PC_WILD         /* wildcard - an opcode place holder used 
+  PC_WILD,        /* wildcard - an opcode place holder used 
                   * in the pCode peep hole optimizer */
+  PC_CSOURCE      /* C-Source Line  */
 } PC_TYPE;
 
 /************************************************/
@@ -396,6 +398,22 @@ typedef struct pCodeComment
 
 } pCodeComment;
 
+/*************************************************
+    pCodeComment
+**************************************************/
+
+typedef struct pCodeCSource
+{
+
+  pCode  pc;
+
+  int  line_number;
+  char *line;
+  char *file_name;
+
+} pCodeCSource;
+
+
 /*************************************************
     pCodeFlow
 
@@ -427,8 +445,35 @@ typedef struct pCodeFlow
   int inCond;   /* Input conditions - stuff assumed defined at entry */
   int outCond;  /* Output conditions - stuff modified by flow block */
 
+  int firstBank; /* The first and last bank flags are the first and last */
+  int lastBank;  /* register banks used within one flow object */
+
+  int FromConflicts;
+  int ToConflicts;
+
 } pCodeFlow;
 
+/*************************************************
+  pCodeFlowLink
+
+  The Flow Link object is used to record information
+ about how consecutive excutive Flow objects are related.
+ The pCodeFlow objects demarcate the pCodeInstructions
+ into contiguous chunks. The FlowLink records conflicts
+ in the discontinuities. For example, if one Flow object
+ references a register in bank 0 and the next Flow object
+ references a register in bank 1, then there is a discontinuity
+ in the banking registers.
+
+*/
+typedef struct pCodeFlowLink
+{
+  pCodeFlow  *pcflow;   /* pointer to linked pCodeFlow object */
+
+  int bank_conflict;    /* records bank conflicts */
+
+} pCodeFlowLink;
+
 /*************************************************
     pCodeInstruction
 
@@ -450,9 +495,9 @@ typedef struct pCodeInstruction
   pBranch *to;         // pCodes that execute after
   pBranch *label;      // pCode instructions that have labels
 
-  pCodeOp *pcop;              /* Operand, if this instruction has one */
-
-  pCodeFlow *pcflow;   /* flow block to which this instruction belongs */
+  pCodeOp *pcop;               /* Operand, if this instruction has one */
+  pCodeFlow *pcflow;           /* flow block to which this instruction belongs */
+  pCodeCSource *cline;         /* C Source from which this instruction was derived */
 
   unsigned int num_ops;        /* Number of operands (0,1,2 for mid range pics) */
   unsigned int isModReg:  1;   /* If destination is W or F, then 1==F */
@@ -500,6 +545,8 @@ typedef struct pCodeFunction
   pBranch *to;         // pCodes that execute after
   pBranch *label;      // pCode instructions that have labels
 
+  int  ncalled;    /* Number of times function is called */
+
 } pCodeFunction;
 
 
@@ -672,8 +719,9 @@ typedef struct peepCommand {
 #define PCI(x)    ((pCodeInstruction *)(x))
 #define PCL(x)    ((pCodeLabel *)(x))
 #define PCF(x)    ((pCodeFunction *)(x))
-#define PCFL(x)    ((pCodeFlow *)(x))
+#define PCFL(x)   ((pCodeFlow *)(x))
 #define PCW(x)    ((pCodeWild *)(x))
+#define PCCS(x)   ((pCodeCSource *)(x))
 
 #define PCOP(x)   ((pCodeOp *)(x))
 //#define PCOB(x)   ((pCodeOpBit *)(x))
@@ -694,8 +742,10 @@ typedef struct peepCommand {
 
 pCode *newpCode (PIC_OPCODE op, pCodeOp *pcop); // Create a new pCode given an operand
 pCode *newpCodeCharP(char *cP);              // Create a new pCode given a char *
+pCode *newpCodeInlineP(char *cP);            // Create a new pCode given a char *
 pCode *newpCodeFunction(char *g, char *f);   // Create a new function
 pCode *newpCodeLabel(char *name,int key);    // Create a new label given a key
+pCode *newpCodeCSource(int ln, char *f, char *l); // Create a new symbol line 
 pBlock *newpCodeChain(memmap *cm,char c, pCode *pc); // Create a new pBlock
 void printpBlock(FILE *of, pBlock *pb);      // Write a pBlock to a file
 void printpCode(FILE *of, pCode *pc);        // Write a pCode to a file
@@ -704,7 +754,7 @@ void addpBlock(pBlock *pb);                  // Add a pBlock to a pFile
 void copypCode(FILE *of, char dbName);       // Write all pBlocks with dbName to *of
 void movepBlock2Head(char dbName);           // move pBlocks around
 void AnalyzepCode(char dbName);
-void OptimizepCode(char dbName);
+int OptimizepCode(char dbName);
 void printCallTree(FILE *of);
 void pCodePeepInit(void);
 void pBlockConvert2ISR(pBlock *pb);