Skip to content

Commit

Permalink
Reimplemented Value-Range Propagation.
Browse files Browse the repository at this point in the history
This should have fixed Bug 3147. The changes are:
 - VRP is applied on all integer arithmetic operators, i.e. + - * / % << >> >>> & | ^, and the unary ~ -.
 - Range with signed numbers is properly supported by using a 65-bit number internally.
 - The algorithm for & | ^ are rewritten to produce a much tighter range than before.
 - Several unlisted bugs producing a wrong range regarding << >> >>> are fixed
  • Loading branch information
kennytm committed Jun 12, 2011
1 parent d5fbd53 commit 672d101
Show file tree
Hide file tree
Showing 11 changed files with 1,761 additions and 182 deletions.
381 changes: 232 additions & 149 deletions src/cast.c

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions src/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "identifier.h"
#include "lexer.h"
#include "arraytypes.h"
#include "intrange.h"

struct Type;
struct Scope;
Expand Down Expand Up @@ -83,11 +84,6 @@ enum CtfeGoal
ctfeNeedNothing // The return value is not required
};

struct IntRange
{ uinteger_t imin;
uinteger_t imax;
};

struct Expression : Object
{
Loc loc; // file location
Expand Down Expand Up @@ -1002,6 +998,7 @@ struct NegExp : UnaExp
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
Expression *buildArrayLoop(Parameters *fparams);
IntRange getIntRange();

// For operator overloading
Identifier *opId();
Expand All @@ -1026,6 +1023,7 @@ struct ComExp : UnaExp
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
Expression *buildArrayLoop(Parameters *fparams);
IntRange getIntRange();

// For operator overloading
Identifier *opId();
Expand Down Expand Up @@ -1294,6 +1292,7 @@ struct AddExp : BinExp
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
Expression *buildArrayLoop(Parameters *fparams);
IntRange getIntRange();

// For operator overloading
int isCommutative();
Expand All @@ -1311,6 +1310,7 @@ struct MinExp : BinExp
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
Expression *buildArrayLoop(Parameters *fparams);
IntRange getIntRange();

// For operator overloading
Identifier *opId();
Expand Down Expand Up @@ -1341,6 +1341,7 @@ struct MulExp : BinExp
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
Expression *buildArrayLoop(Parameters *fparams);
IntRange getIntRange();

// For operator overloading
int isCommutative();
Expand Down Expand Up @@ -1375,6 +1376,7 @@ struct ModExp : BinExp
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
Expression *buildArrayLoop(Parameters *fparams);
IntRange getIntRange();

// For operator overloading
Identifier *opId();
Expand Down
14 changes: 9 additions & 5 deletions src/freebsd.mak
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ DMD_OBJS = \
type.o typinf.o util.o var.o version.o strtold.o utf.o staticassert.o \
unialpha.o toobj.o toctype.o toelfdebug.o entity.o doc.o macro.o \
hdrgen.o delegatize.o aa.o ti_achar.o toir.o interpret.o traits.o \
builtin.o clone.o aliasthis.o \
builtin.o clone.o aliasthis.o intrange.o \
man.o arrayop.o port.o response.o async.o json.o speller.o aav.o unittests.o \
imphint.o argtypes.o ti_pvoid.o \
libelf.o elfobj.o
Expand All @@ -53,7 +53,7 @@ SRC = win32.mak linux.mak osx.mak freebsd.mak solaris.mak openbsd.mak \
inifile.c iasm.c module.c scope.c dump.c init.h init.c attrib.h \
attrib.c opover.c class.c mangle.c bit.c tocsym.c func.c inline.c \
access.c complex_t.h irstate.h irstate.c glue.c msc.c ph.c tk.c \
s2ir.c todt.c e2ir.c util.c identifier.h parse.h \
s2ir.c todt.c e2ir.c util.c identifier.h parse.h intrange.h \
scope.h enum.h import.h mars.h module.h mtype.h dsymbol.h \
declaration.h lexer.h expression.h irstate.h statement.h eh.c \
utf.h utf.c staticassert.h staticassert.c unialpha.c \
Expand All @@ -62,7 +62,7 @@ SRC = win32.mak linux.mak osx.mak freebsd.mak solaris.mak openbsd.mak \
delegatize.c toir.h toir.c interpret.c traits.c cppmangle.c \
builtin.c clone.c lib.h libomf.c libelf.c libmach.c arrayop.c \
aliasthis.h aliasthis.c json.h json.c unittests.c imphint.c \
argtypes.c \
argtypes.c intrange.c \
$C/cdef.h $C/cc.h $C/oper.h $C/ty.h $C/optabgen.c \
$C/global.h $C/parser.h $C/code.h $C/type.h $C/dt.h $C/cgcv.h \
$C/el.h $C/iasm.h $C/rtlsym.h $C/html.h \
Expand Down Expand Up @@ -296,8 +296,8 @@ enum.o: enum.c
evalu8.o: $C/evalu8.c
$(CC) -c $(MFLAGS) $<

expression.o: expression.c
$(CC) -c $(CFLAGS) $<
expression.o: expression.c expression.h
$(CC) -c $(CFLAGS) expression.c

func.o: func.c
$(CC) -c $(CFLAGS) $<
Expand Down Expand Up @@ -365,6 +365,9 @@ inline.o: inline.c
interpret.o: interpret.c
$(CC) -c $(CFLAGS) $<

intrange.o: intrange.h intrange.c
$(CC) -c $(CFLAGS) intrange.c

json.o: json.c
$(CC) -c $(CFLAGS) $<

Expand Down Expand Up @@ -596,6 +599,7 @@ gcov:
gcov utf.c
gcov util.c
gcov version.c
gcov intrange.c

# gcov hdrgen.c
# gcov tocvdebug.c
Expand Down
Loading

0 comments on commit 672d101

Please sign in to comment.