diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-12 11:38:42 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-12 11:38:42 -0300 |
| commit | f6aab3ec1f111cd8d968bdcb7ca800e93b819d24 (patch) | |
| tree | 4c36c418ecc9062e6d95de73457198b38b0afce9 /lparser.h | |
| parent | be8445d7e4b6122620c428877b51a27d464253d5 (diff) | |
| download | lua-f6aab3ec1f111cd8d968bdcb7ca800e93b819d24.tar.gz lua-f6aab3ec1f111cd8d968bdcb7ca800e93b819d24.tar.bz2 lua-f6aab3ec1f111cd8d968bdcb7ca800e93b819d24.zip | |
First implementation of constant propagation
Local constant variables initialized with compile-time constants
are optimized away from the code.
Diffstat (limited to 'lparser.h')
| -rw-r--r-- | lparser.h | 27 |
1 files changed, 17 insertions, 10 deletions
| @@ -34,8 +34,9 @@ typedef enum { | |||
| 34 | VNONRELOC, /* expression has its value in a fixed register; | 34 | VNONRELOC, /* expression has its value in a fixed register; |
| 35 | info = result register */ | 35 | info = result register */ |
| 36 | VLOCAL, /* local variable; var.ridx = local register; | 36 | VLOCAL, /* local variable; var.ridx = local register; |
| 37 | var.vidx = index in 'actvar.arr' */ | 37 | var.vidx = relative index in 'actvar.arr' */ |
| 38 | VUPVAL, /* upvalue variable; info = index of upvalue in 'upvalues' */ | 38 | VUPVAL, /* upvalue variable; info = index of upvalue in 'upvalues' */ |
| 39 | VCONST, /* compile-time constant; info = absolute index in 'actvar.arr' */ | ||
| 39 | VINDEXED, /* indexed variable; | 40 | VINDEXED, /* indexed variable; |
| 40 | ind.t = table register; | 41 | ind.t = table register; |
| 41 | ind.idx = key's R index */ | 42 | ind.idx = key's R index */ |
| @@ -81,19 +82,25 @@ typedef struct expdesc { | |||
| 81 | } expdesc; | 82 | } expdesc; |
| 82 | 83 | ||
| 83 | 84 | ||
| 85 | /* kinds of variables */ | ||
| 86 | #define VDKREG 0 /* regular */ | ||
| 87 | #define RDKCONST 1 /* constant */ | ||
| 88 | #define RDKTOCLOSE 2 /* to-be-closed */ | ||
| 89 | #define RDKCTC 3 /* compile-time constant */ | ||
| 90 | |||
| 84 | /* description of an active local variable */ | 91 | /* description of an active local variable */ |
| 85 | typedef struct Vardesc { | 92 | typedef union Vardesc { |
| 86 | TValuefields; /* constant value (if it is a compile-time constant) */ | 93 | struct { |
| 87 | lu_byte ro; /* true if variable is 'const' */ | 94 | TValuefields; /* constant value (if it is a compile-time constant) */ |
| 88 | lu_byte sidx; /* index of the variable in the stack */ | 95 | lu_byte kind; |
| 89 | short pidx; /* index of the variable in the Proto's 'locvars' array */ | 96 | lu_byte sidx; /* index of the variable in the stack */ |
| 90 | TString *name; /* variable name */ | 97 | short pidx; /* index of the variable in the Proto's 'locvars' array */ |
| 98 | TString *name; /* variable name */ | ||
| 99 | } vd; | ||
| 100 | TValue k; /* constant value (if any) */ | ||
| 91 | } Vardesc; | 101 | } Vardesc; |
| 92 | 102 | ||
| 93 | 103 | ||
| 94 | /* check whether Vardesc is in the stack (not a compile-time constant) */ | ||
| 95 | #define vdinstack(vd) (ttisnil(vd)) | ||
| 96 | |||
| 97 | 104 | ||
| 98 | /* description of pending goto statements and label statements */ | 105 | /* description of pending goto statements and label statements */ |
| 99 | typedef struct Labeldesc { | 106 | typedef struct Labeldesc { |
