1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-08 03:22:21 +03:00

Expression code generator takes advantage of recent opcode changes. (CVS 4685)

FossilOrigin-Name: 6c78d2a49a3e6ee8bc31f16488a430cba9eda59d
This commit is contained in:
drh
2008-01-05 06:51:30 +00:00
parent 41c2bf0388
commit 9de221dff5
4 changed files with 62 additions and 50 deletions

View File

@@ -1,5 +1,5 @@
C Register-ify\sthe\sOP_ForceInt\sopcode.\s(CVS\s4684)
D 2008-01-05T05:38:21
C Expression\scode\sgenerator\stakes\sadvantage\sof\srecent\sopcode\schanges.\s(CVS\s4685)
D 2008-01-05T06:51:30
F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
F Makefile.in 30789bf70614bad659351660d76b8e533f3340e9
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -92,7 +92,7 @@ F src/complete.c 4cf68fd75d60257524cbe74f87351b9848399131
F src/date.c 49c5a6d2de6c12000905b4d36868b07d3011bbf6
F src/delete.c cb1d5be17c99e41d1675763a57848bb5dd45191c
F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b
F src/expr.c 743e8f1da26816cf0767fb7cfb442a2d8996154d
F src/expr.c 991ae77f4e78584553d8d6c8b10537bec021b0a9
F src/func.c 996071cf0af9d967e58b69fce1909555059ebc7d
F src/hash.c 45a7005aac044b6c86bd7e49c44bc15d30006d6c
F src/hash.h 031cd9f915aff27e12262cb9eb570ac1b8326b53
@@ -168,7 +168,7 @@ F src/update.c ac6cdfebf88340fd68550b1d7fd6a15ad7144fd8
F src/utf.c ef4b7d83bae533b76c3e1bf635b113fdad86a736
F src/util.c 05f31144bbd3f1a24f4139ae029c42545cb72624
F src/vacuum.c 3f34f278809bf3eb0b62ec46ff779e9c385b28f0
F src/vdbe.c d96c341f070f7f683fd1a34114c19dbecdf49647
F src/vdbe.c 5174adfb84a5db3881b53096da32d8329cb121d3
F src/vdbe.h bb128757b84280504a1243c450fd13ead248ede5
F src/vdbeInt.h 31bd686595356284d5484592e2dc6e58025aa346
F src/vdbeapi.c f14174843bf4be2c9afdf2ef48b61e7c3ac62d7c
@@ -603,7 +603,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P 3e8a07dd3cc9921ad39e379576abb0b485a42202
R 5fa8eccc6a1d8f273459b71d7e4508a7
P 32380dcabcd3839e79f91430b0c250d6e02d9243
R 23d7fd092a9617107d94aa7f01f63d28
U drh
Z 54cf213cacf40b4b6524baf65c0d27ec
Z 806d577e383a52170c44489fe3b3b0e5

View File

@@ -1 +1 @@
32380dcabcd3839e79f91430b0c250d6e02d9243
6c78d2a49a3e6ee8bc31f16488a430cba9eda59d

View File

@@ -12,7 +12,7 @@
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.332 2008/01/05 05:20:10 drh Exp $
** $Id: expr.c,v 1.333 2008/01/05 06:51:30 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -1850,7 +1850,7 @@ static char *dup8bytes(Vdbe *v, const char *in){
** z[n] character is guaranteed to be something that does not look
** like the continuation of the number.
*/
static void codeReal(Vdbe *v, const char *z, int n, int negateFlag){
static void codeReal(Vdbe *v, const char *z, int n, int negateFlag, int iMem){
assert( z || v==0 || sqlite3VdbeDb(v)->mallocFailed );
if( z ){
double value;
@@ -1859,7 +1859,7 @@ static void codeReal(Vdbe *v, const char *z, int n, int negateFlag){
sqlite3AtoF(z, &value);
if( negateFlag ) value = -value;
zV = dup8bytes(v, (char*)&value);
sqlite3VdbeAddOp4(v, OP_Real, 0, 0, 0, zV, P4_REAL);
sqlite3VdbeAddOp4(v, OP_Real, 0, iMem, 0, zV, P4_REAL);
}
}
@@ -1872,23 +1872,23 @@ static void codeReal(Vdbe *v, const char *z, int n, int negateFlag){
** z[n] character is guaranteed to be something that does not look
** like the continuation of the number.
*/
static void codeInteger(Vdbe *v, const char *z, int n, int negateFlag){
static void codeInteger(Vdbe *v, const char *z, int n, int negFlag, int iMem){
assert( z || v==0 || sqlite3VdbeDb(v)->mallocFailed );
if( z ){
int i;
assert( !isdigit(z[n]) );
if( sqlite3GetInt32(z, &i) ){
if( negateFlag ) i = -i;
sqlite3VdbeAddOp1(v, OP_Integer, i);
}else if( sqlite3FitsIn64Bits(z, negateFlag) ){
if( negFlag ) i = -i;
sqlite3VdbeAddOp2(v, OP_Integer, i, iMem);
}else if( sqlite3FitsIn64Bits(z, negFlag) ){
i64 value;
char *zV;
sqlite3Atoi64(z, &value);
if( negateFlag ) value = -value;
if( negFlag ) value = -value;
zV = dup8bytes(v, (char*)&value);
sqlite3VdbeAddOp4(v, OP_Int64, 0, 0, 0, zV, P4_INT64);
sqlite3VdbeAddOp4(v, OP_Int64, 0, iMem, 0, zV, P4_INT64);
}else{
codeReal(v, z, n, negateFlag);
codeReal(v, z, n, negFlag, iMem);
}
}
}
@@ -1944,7 +1944,7 @@ int sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
int op;
int inReg = 0;
int stackChng = 0;
int subtarget = -1;
int origTarget = target;
assert( v!=0 || pParse->db->mallocFailed );
if( v==0 ) return 0;
@@ -1952,7 +1952,6 @@ int sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
target = ++pParse->nMem;
}else if( target==0 ){
stackChng = 1;
subtarget = 0;
}
if( pExpr==0 ){
@@ -1965,12 +1964,13 @@ int sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
AggInfo *pAggInfo = pExpr->pAggInfo;
struct AggInfo_col *pCol = &pAggInfo->aCol[pExpr->iAgg];
if( !pAggInfo->directMode ){
sqlite3VdbeAddOp1(v, OP_SCopy, pCol->iMem);
assert( pCol->iMem>0 );
inReg = pCol->iMem;
break;
}else if( pAggInfo->useSortingIdx ){
sqlite3VdbeAddOp3(v, OP_Column, pAggInfo->sortingIdx,
pCol->iSorterColumn, target);
inReg = 1;
inReg = target;
break;
}
/* Otherwise, fall thru into the TK_COLUMN case */
@@ -1980,29 +1980,34 @@ int sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
/* This only happens when coding check constraints */
assert( pParse->ckOffset>0 );
sqlite3VdbeAddOp1(v, OP_SCopy, -(pParse->ckOffset-pExpr->iColumn-1));
/* inReg = -(pParse->ckOffset-pExpr->iColumn-1); */
}else{
sqlite3ExprCodeGetColumn(v, pExpr->pTab,
pExpr->iColumn, pExpr->iTable, target);
inReg = 1;
inReg = target;
}
break;
}
case TK_INTEGER: {
codeInteger(v, (char*)pExpr->token.z, pExpr->token.n, 0);
codeInteger(v, (char*)pExpr->token.z, pExpr->token.n, 0, target);
inReg = target;
break;
}
case TK_FLOAT: {
codeReal(v, (char*)pExpr->token.z, pExpr->token.n, 0);
codeReal(v, (char*)pExpr->token.z, pExpr->token.n, 0, target);
inReg = target;
break;
}
case TK_STRING: {
sqlite3DequoteExpr(pParse->db, pExpr);
sqlite3VdbeAddOp4(v,OP_String8, 0, 0, 0,
sqlite3VdbeAddOp4(v,OP_String8, 0, target, 0,
(char*)pExpr->token.z, pExpr->token.n);
inReg = target;
break;
}
case TK_NULL: {
sqlite3VdbeAddOp0(v, OP_Null);
sqlite3VdbeAddOp2(v, OP_Null, 0, target);
inReg = target;
break;
}
#ifndef SQLITE_OMIT_BLOB_LITERAL
@@ -2016,26 +2021,28 @@ int sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
if( n==0 ){
z = "";
}
sqlite3VdbeAddOp4(v, op, 0, 0, 0, z, n);
sqlite3VdbeAddOp4(v, op, 0, target, 0, z, n);
inReg = target;
break;
}
#endif
case TK_VARIABLE: {
sqlite3VdbeAddOp1(v, OP_Variable, pExpr->iTable);
sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iTable, target);
if( pExpr->token.n>1 ){
sqlite3VdbeChangeP4(v, -1, (char*)pExpr->token.z, pExpr->token.n);
}
inReg = target;
break;
}
case TK_REGISTER: {
sqlite3VdbeAddOp1(v, OP_SCopy, pExpr->iTable);
inReg = pExpr->iTable;
break;
}
#ifndef SQLITE_OMIT_CAST
case TK_CAST: {
/* Expressions of the form: CAST(pLeft AS token) */
int aff, to_op;
sqlite3ExprCode(pParse, pExpr->pLeft, 0);
sqlite3ExprCode(pParse, pExpr->pLeft, target);
aff = sqlite3AffinityType(&pExpr->token);
to_op = aff - SQLITE_AFF_TEXT + OP_ToText;
assert( to_op==OP_ToText || aff!=SQLITE_AFF_TEXT );
@@ -2043,8 +2050,9 @@ int sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
assert( to_op==OP_ToNumeric || aff!=SQLITE_AFF_NUMERIC );
assert( to_op==OP_ToInt || aff!=SQLITE_AFF_INTEGER );
assert( to_op==OP_ToReal || aff!=SQLITE_AFF_REAL );
sqlite3VdbeAddOp0(v, to_op);
sqlite3VdbeAddOp1(v, to_op, target);
stackChng = 0;
inReg = target;
break;
}
#endif /* SQLITE_OMIT_CAST */
@@ -2101,10 +2109,11 @@ int sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
if( pLeft->op==TK_FLOAT || pLeft->op==TK_INTEGER ){
Token *p = &pLeft->token;
if( pLeft->op==TK_FLOAT ){
codeReal(v, (char*)p->z, p->n, 1);
codeReal(v, (char*)p->z, p->n, 1, target);
}else{
codeInteger(v, (char*)p->z, p->n, 1);
codeInteger(v, (char*)p->z, p->n, 1, target);
}
inReg = target;
break;
}
/* Fall through into TK_NOT */
@@ -2123,12 +2132,13 @@ int sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
int dest;
assert( TK_ISNULL==OP_IsNull );
assert( TK_NOTNULL==OP_NotNull );
sqlite3VdbeAddOp1(v, OP_Integer, 1);
sqlite3VdbeAddOp2(v, OP_Integer, 1, target);
sqlite3ExprCode(pParse, pExpr->pLeft, 0);
dest = sqlite3VdbeCurrentAddr(v) + 2;
sqlite3VdbeAddOp2(v, op, 1, dest);
sqlite3VdbeAddOp2(v, OP_AddImm, 0, -1);
sqlite3VdbeAddOp2(v, OP_AddImm, target, -1);
stackChng = 0;
inReg = target;
break;
}
case TK_AGG_FUNCTION: {
@@ -2137,7 +2147,7 @@ int sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
sqlite3ErrorMsg(pParse, "misuse of aggregate: %T",
&pExpr->span);
}else{
sqlite3VdbeAddOp1(v, OP_SCopy, pInfo->aFunc[pExpr->iAgg].iMem);
inReg = pInfo->aFunc[pExpr->iAgg].iMem;
}
break;
}
@@ -2201,8 +2211,9 @@ int sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
if( pExpr->iColumn==0 ){
sqlite3CodeSubselect(pParse, pExpr);
}
sqlite3VdbeAddOp1(v, OP_SCopy, pExpr->iColumn);
VdbeComment((v, "load subquery result"));
inReg = pExpr->iColumn;
/* sqlite3VdbeAddOp1(v, OP_SCopy, pExpr->iColumn);
VdbeComment((v, "load subquery result")); */
break;
}
case TK_IN: {
@@ -2265,7 +2276,7 @@ int sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
break;
}
case TK_UPLUS: {
sqlite3ExprCode(pParse, pExpr->pLeft, 0);
inReg = sqlite3ExprCode(pParse, pExpr->pLeft, origTarget);
stackChng = 0;
break;
}
@@ -2297,7 +2308,7 @@ int sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
}else{
jumpInst = sqlite3VdbeAddOp2(v, OP_IfNot, 1, 0);
}
sqlite3ExprCode(pParse, aListelem[i+1].pExpr, 0);
sqlite3ExprCode(pParse, aListelem[i+1].pExpr, target);
sqlite3VdbeAddOp2(v, OP_Goto, 0, expr_end_label);
sqlite3VdbeJumpHere(v, jumpInst);
}
@@ -2305,11 +2316,12 @@ int sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
sqlite3VdbeAddOp2(v, OP_Pop, 1, 0);
}
if( pExpr->pRight ){
sqlite3ExprCode(pParse, pExpr->pRight, 0);
sqlite3ExprCode(pParse, pExpr->pRight, target);
}else{
sqlite3VdbeAddOp2(v, OP_Null, 0, 0);
sqlite3VdbeAddOp2(v, OP_Null, 0, target);
}
sqlite3VdbeResolveLabel(v, expr_end_label);
inReg = target;
break;
}
#ifndef SQLITE_OMIT_TRIGGER
@@ -2337,8 +2349,8 @@ int sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
}
#endif
}
if( target && !inReg ){
sqlite3VdbeAddOp2(v, OP_Move, 0, target);
if( inReg!=target && origTarget!=-1 ){
sqlite3VdbeAddOp2(v, (inReg>0 ? OP_SCopy : OP_Move), inReg, target);
stackChng = 0;
}
if( pParse->ckOffset ){

View File

@@ -43,7 +43,7 @@
** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
** $Id: vdbe.c,v 1.682 2008/01/05 05:38:21 drh Exp $
** $Id: vdbe.c,v 1.683 2008/01/05 06:51:32 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -942,10 +942,10 @@ case OP_HexBlob: { /* same as TK_BLOB, out2-prerelease */
/* Fall through to the next case, OP_Blob. */
}
/* Opcode: Blob P1 * P4
/* Opcode: Blob P1 P2 * P4
**
** P4 points to a blob of data P1 bytes long. Push this
** value onto the stack. This instruction is not coded directly
** P4 points to a blob of data P1 bytes long. Store this
** blob in register P2. This instruction is not coded directly
** by the compiler. Instead, the compiler layer specifies
** an OP_HexBlob opcode, with the hex string representation of
** the blob as P4. This opcode is transformed to an OP_Blob
@@ -954,7 +954,7 @@ case OP_HexBlob: { /* same as TK_BLOB, out2-prerelease */
case OP_Blob: { /* out2-prerelease */
assert( pOp->p1 <= SQLITE_MAX_LENGTH );
sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0);
pTos->enc = encoding;
pOut->enc = encoding;
break;
}
#endif /* SQLITE_OMIT_BLOB_LITERAL */