X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fpic%2Fpcode.h;h=8e4dd51acb5c49fc9a77d119074ce43f0a6062d4;hb=2c02e0d7cccdf186aea6a2cda046afe06aa094a3;hp=8a8df94f63ca552140e0bc5ca3527a6603ffacb1;hpb=e33c24b4e792f1136531ed4108dcfc7e67871d65;p=fw%2Fsdcc diff --git a/src/pic/pcode.h b/src/pic/pcode.h index 8a8df94f..8e4dd51a 100644 --- a/src/pic/pcode.h +++ b/src/pic/pcode.h @@ -76,7 +76,7 @@ struct regs; * The double parenthesis (()) are necessary * ***********************************************************************/ -#define PCODE_DEBUG +//#define PCODE_DEBUG #ifdef PCODE_DEBUG #define DFPRINTF(args) (fprintf args) @@ -228,18 +228,21 @@ 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; /************************************************/ /*************** Structures ********************/ /************************************************/ struct pCode; +struct pCodeWildBlock; /************************************************* pBranch @@ -303,7 +306,10 @@ typedef struct pCodeOpLit typedef struct pCodeOpImmd { pCodeOp pcop; - int offset; + int offset; /* low,med, or high byte of immediat value */ + int index; /* add this to the immediate value */ + unsigned _const:1; /* is in code space */ + } pCodeOpImmd; typedef struct pCodeOpLabel @@ -331,6 +337,22 @@ typedef struct pCodeOpRegBit } pCodeOpRegBit; +typedef struct pCodeOpWild +{ + pCodeOp pcop; + + struct pCodeWildBlock *pcwb; + + int id; /* index into an array of char *'s that will match + * the wild card. The array is in *pcp. */ + pCodeOp *subtype; /* Pointer to the Operand type into which this wild + * card will be expanded */ + pCodeOp *matched; /* When a wild matches, we'll store a pointer to the + * opcode we matched */ + +} pCodeOpWild; + + /************************************************* pCode @@ -376,6 +398,22 @@ typedef struct pCodeComment } pCodeComment; +/************************************************* + pCodeComment +**************************************************/ + +typedef struct pCodeCSource +{ + + pCode pc; + + int line_number; + char *line; + char *file_name; + +} pCodeCSource; + + /************************************************* pCodeFlow @@ -407,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 @@ -430,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 */ @@ -440,6 +505,7 @@ typedef struct pCodeInstruction unsigned int isBranch: 1; /* True if this is a branching instruction */ unsigned int isSkip: 1; /* True if this is a skip instruction */ + PIC_OPCODE inverted_op; /* Opcode of instruction that's the opposite of this one */ unsigned int inCond; // Input conditions for this instruction unsigned int outCond; // Output conditions for this instruction @@ -479,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; @@ -495,6 +563,10 @@ typedef struct pCodeWild * - this wild card will get expanded into that pCode * that is stored at this index */ + /* Conditions on wild pcode instruction */ + int mustBeBitSkipInst:1; + int mustNotBeBitSkipInst:1; + int invertBitSkipInst:1; pCodeOp *operand; // Optional operand pCodeOp *label; // Optional label @@ -555,6 +627,28 @@ typedef struct pFile +/************************************************* + pCodeWildBlock + + The pCodeWildBlock object keeps track of the wild + variables, operands, and opcodes that exist in + a pBlock. +**************************************************/ +typedef struct pCodeWildBlock { + pBlock *pb; + struct pCodePeep *pcp; // pointer back to ... I don't like this... + + int nvars; // Number of wildcard registers in target. + char **vars; // array of pointers to them + + int nops; // Number of wildcard operands in target. + pCodeOp **wildpCodeOps; // array of pointers to the pCodeOp's. + + int nwildpCodes; // Number of wildcard pCodes in target/replace + pCode **wildpCodes; // array of pointers to the pCode's. + +} pCodeWildBlock; + /************************************************* pCodePeep @@ -567,17 +661,12 @@ typedef struct pFile pCode chain. **************************************************/ typedef struct pCodePeep { + pCodeWildBlock target; // code we'd like to optimize + pCodeWildBlock replace; // and this is what we'll optimize it with. - pBlock *target; // code we'd like to optimize - pBlock *replace; // and this is what we'll optimize it with. + //pBlock *target; + //pBlock replace; // and this is what we'll optimize it with. - int nvars; // Number of wildcard registers in target. - char **vars; // array of pointers to them - int nops; // Number of wildcard operands in target. - pCodeOp **wildpCodeOps; // array of pointers to the pCodeOp's. - - int nwildpCodes; // Number of wildcard pCodes in target/replace - pCode **wildpCodes; // array of pointers to the pCode's. /* (Note: a wildcard register is a place holder. Any register @@ -595,19 +684,32 @@ typedef struct pCodePeep { } pCodePeep; -typedef struct pCodeOpWild -{ - pCodeOp pcop; - //PIC_OPTYPE subtype; Wild get's expanded to this by the optimizer - pCodePeep *pcp; // pointer to the parent peep block - int id; /* index into an array of char *'s that will match - * the wild card. The array is in *pcp. */ - pCodeOp *subtype; /* Pointer to the Operand type into which this wild - * card will be expanded */ - pCodeOp *matched; /* When a wild matches, we'll store a pointer to the - * opcode we matched */ +/************************************************* + + pCode peep command definitions + + Here are some special commands that control the +way the peep hole optimizer behaves + +**************************************************/ + +enum peepCommandTypes{ + NOTBITSKIP = 0, + BITSKIP, + INVERTBITSKIP, + _LAST_PEEP_COMMAND_ +}; + +/************************************************* + peepCommand structure stores the peep commands. + +**************************************************/ + +typedef struct peepCommand { + int id; + char *cmd; +} peepCommand; -} pCodeOpWild; /************************************************* pCode Macros @@ -617,8 +719,9 @@ typedef struct pCodeOpWild #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)) @@ -631,14 +734,18 @@ typedef struct pCodeOpWild #define PBR(x) ((pBranch *)(x)) +#define PCWB(x) ((pCodeWildBlock *)(x)) + /*-----------------------------------------------------------------* * pCode functions. *-----------------------------------------------------------------*/ 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 @@ -647,17 +754,19 @@ 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); pCodeOp *newpCodeOpLabel(char *name, int key); -pCodeOp *newpCodeOpImmd(char *name, int offset); +pCodeOp *newpCodeOpImmd(char *name, int offset, int index, int code_space); pCodeOp *newpCodeOpLit(int lit); pCodeOp *newpCodeOpBit(char *name, int bit,int inBitSpace); pCodeOp *newpCodeOpRegFromStr(char *name); pCodeOp *newpCodeOp(char *name, PIC_OPTYPE p); +pCodeOp *pCodeOpCopy(pCodeOp *pcop); + extern void pcode_test(void); /*-----------------------------------------------------------------*