aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-03-02 18:52:38 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-03-02 19:12:32 +0100
commit1cd5d64b714ec97f2169ce59549ea1ff47da358f (patch)
tree4cb78654614650da9cdffe276275b5d2803d7050
parent9fff86b30747be0a081632269f5aaf6e17bed4a9 (diff)
downloadsparse-dev-1cd5d64b714ec97f2169ce59549ea1ff47da358f.tar.gz
Revert "Give the constant pseudo value a size"
This reverts commit 9fff86b30747be0a081632269f5aaf6e17bed4a9, commit 5e733ee233920149b88698185032b7799b731548, and commit 16d44cca4a36a76af8ce548442b6d541fade5e68. because the corresponding series creates several regressions, its effects are not well understood and it's not well tested. The series can come back once these three points are addressed. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--flow.c2
-rw-r--r--linearize.c23
-rw-r--r--linearize.h6
-rw-r--r--memops.c2
-rw-r--r--simplify.c20
-rw-r--r--sparse-llvm.c21
6 files changed, 32 insertions, 42 deletions
diff --git a/flow.c b/flow.c
index fa5d31c8..6b2c879a 100644
--- a/flow.c
+++ b/flow.c
@@ -517,7 +517,7 @@ found:
if (!local)
return 0;
check_access(insn);
- convert_load_instruction(insn, value_pseudo(insn->type, 0));
+ convert_load_instruction(insn, value_pseudo(0));
return 1;
}
diff --git a/linearize.c b/linearize.c
index 2aa3acb2..ba76397e 100644
--- a/linearize.c
+++ b/linearize.c
@@ -785,25 +785,22 @@ static pseudo_t symbol_pseudo(struct entrypoint *ep, struct symbol *sym)
return pseudo;
}
-pseudo_t value_pseudo(struct symbol *type, long long val)
+pseudo_t value_pseudo(long long val)
{
#define MAX_VAL_HASH 64
static struct pseudo_list *prev[MAX_VAL_HASH];
int hash = val & (MAX_VAL_HASH-1);
struct pseudo_list **list = prev + hash;
- int size = type ? type->bit_size : value_size(val);
pseudo_t pseudo;
-
FOR_EACH_PTR(*list, pseudo) {
- if (pseudo->value == val && pseudo->size == size)
+ if (pseudo->value == val)
return pseudo;
} END_FOR_EACH_PTR(pseudo);
pseudo = __alloc_pseudo(0);
pseudo->type = PSEUDO_VAL;
pseudo->value = val;
- pseudo->size = size;
add_pseudo(list, pseudo);
/* Value pseudos have neither nr, usage nor def */
@@ -957,10 +954,10 @@ static pseudo_t linearize_store_gen(struct entrypoint *ep,
unsigned long long mask = (1ULL << size) - 1;
if (shift) {
- store = add_binary_op(ep, ad->source_type, OP_SHL, value, value_pseudo(ctype, shift));
+ store = add_binary_op(ep, ad->source_type, OP_SHL, value, value_pseudo(shift));
mask <<= shift;
}
- orig = add_binary_op(ep, ad->source_type, OP_AND, orig, value_pseudo(ctype, ~mask));
+ orig = add_binary_op(ep, ad->source_type, OP_AND, orig, value_pseudo(~mask));
store = add_binary_op(ep, ad->source_type, OP_OR, orig, store);
}
add_store(ep, ad, store);
@@ -1005,7 +1002,7 @@ static pseudo_t linearize_load_gen(struct entrypoint *ep, struct access_data *ad
pseudo_t new = add_load(ep, ad);
if (ctype->bit_offset) {
- pseudo_t shift = value_pseudo(ctype, ctype->bit_offset);
+ pseudo_t shift = value_pseudo(ctype->bit_offset);
pseudo_t newval = add_binary_op(ep, ad->source_type, OP_LSR, new, shift);
new = newval;
}
@@ -1037,7 +1034,7 @@ static pseudo_t linearize_inc_dec(struct entrypoint *ep, struct expression *expr
return VOID;
old = linearize_load_gen(ep, &ad);
- one = value_pseudo(expr->ctype, expr->op_value);
+ one = value_pseudo(expr->op_value);
new = add_binary_op(ep, expr->ctype, op, old, one);
linearize_store_gen(ep, new, &ad);
finish_address_gen(ep, &ad);
@@ -1076,7 +1073,7 @@ static pseudo_t linearize_regular_preop(struct entrypoint *ep, struct expression
case '+':
return pre;
case '!': {
- pseudo_t zero = value_pseudo(expr->ctype, 0);
+ pseudo_t zero = value_pseudo(0);
return add_binary_op(ep, expr->ctype, OP_SET_EQ, pre, zero);
}
case '~':
@@ -1168,7 +1165,7 @@ static inline pseudo_t add_convert_to_bool(struct entrypoint *ep, pseudo_t src,
if (is_bool_type(type))
return src;
- zero = value_pseudo(type, 0);
+ zero = value_pseudo(0);
op = OP_SET_NE;
return add_binary_op(ep, &bool_ctype, op, src, zero);
}
@@ -1594,7 +1591,7 @@ pseudo_t linearize_expression(struct entrypoint *ep, struct expression *expr)
return add_symbol_address(ep, expr->symbol);
case EXPR_VALUE:
- return value_pseudo(expr->ctype, expr->value);
+ return value_pseudo(expr->value);
case EXPR_STRING: case EXPR_FVALUE: case EXPR_LABEL:
return add_setval(ep, expr->ctype, expr);
@@ -1684,7 +1681,7 @@ static pseudo_t linearize_one_symbol(struct entrypoint *ep, struct symbol *sym)
ad.result_type = sym;
ad.source_type = base_type(sym);
ad.address = symbol_pseudo(ep, sym);
- linearize_store_gen(ep, value_pseudo(sym, 0), &ad);
+ linearize_store_gen(ep, value_pseudo(0), &ad);
}
value = linearize_initializer(ep, sym->initializer, &ad);
diff --git a/linearize.h b/linearize.h
index f52eade8..bac82d7f 100644
--- a/linearize.h
+++ b/linearize.h
@@ -30,8 +30,7 @@ enum pseudo_type {
struct pseudo {
int nr;
- int size:16; /* OP_SETVAL only */
- enum pseudo_type type:8;
+ enum pseudo_type type;
struct pseudo_user_list *users;
struct ident *ident;
union {
@@ -334,8 +333,7 @@ extern void insert_branch(struct basic_block *bb, struct instruction *br, struct
pseudo_t alloc_phi(struct basic_block *source, pseudo_t pseudo, int size);
pseudo_t alloc_pseudo(struct instruction *def);
-pseudo_t value_pseudo(struct symbol *type, long long val);
-unsigned int value_size(long long value);
+pseudo_t value_pseudo(long long val);
struct entrypoint *linearize_symbol(struct symbol *sym);
int unssa(struct entrypoint *ep);
diff --git a/memops.c b/memops.c
index 6a795c19..aeacdf56 100644
--- a/memops.c
+++ b/memops.c
@@ -127,7 +127,7 @@ static void simplify_loads(struct basic_block *bb)
if (!dominators) {
if (local) {
assert(pseudo->type != PSEUDO_ARG);
- convert_load_instruction(insn, value_pseudo(insn->type, 0));
+ convert_load_instruction(insn, value_pseudo(0));
}
goto next_load;
}
diff --git a/simplify.c b/simplify.c
index 1e926e7d..2bc86f53 100644
--- a/simplify.c
+++ b/simplify.c
@@ -352,7 +352,7 @@ static int replace_with_pseudo(struct instruction *insn, pseudo_t pseudo)
return REPEAT_CSE;
}
-unsigned int value_size(long long value)
+static unsigned int value_size(long long value)
{
value >>= 8;
if (!value)
@@ -398,7 +398,7 @@ static int simplify_asr(struct instruction *insn, pseudo_t pseudo, long long val
if (value >= size) {
warning(insn->pos, "right shift by bigger than source value");
- return replace_with_pseudo(insn, value_pseudo(insn->type, 0));
+ return replace_with_pseudo(insn, value_pseudo(0));
}
if (!value)
return replace_with_pseudo(insn, pseudo);
@@ -508,7 +508,7 @@ static int simplify_constant_rightside(struct instruction *insn)
case OP_SUB:
if (value) {
insn->opcode = OP_ADD;
- insn->src2 = value_pseudo(insn->type, -value);
+ insn->src2 = value_pseudo(-value);
return REPEAT_CSE;
}
/* Fall through */
@@ -525,7 +525,7 @@ static int simplify_constant_rightside(struct instruction *insn)
case OP_MODU: case OP_MODS:
if (value == 1)
- return replace_with_pseudo(insn, value_pseudo(insn->type, 0));
+ return replace_with_pseudo(insn, value_pseudo(0));
return 0;
case OP_DIVU: case OP_DIVS:
@@ -686,7 +686,7 @@ static int simplify_constant_binop(struct instruction *insn)
}
res &= bits;
- replace_with_pseudo(insn, value_pseudo(insn->type, res));
+ replace_with_pseudo(insn, value_pseudo(res));
return REPEAT_CSE;
}
@@ -700,14 +700,14 @@ static int simplify_binop_same_args(struct instruction *insn, pseudo_t arg)
warning(insn->pos, "self-comparison always evaluates to false");
case OP_SUB:
case OP_XOR:
- return replace_with_pseudo(insn, value_pseudo(insn->type, 0));
+ return replace_with_pseudo(insn, value_pseudo(0));
case OP_SET_EQ:
case OP_SET_LE: case OP_SET_GE:
case OP_SET_BE: case OP_SET_AE:
if (Wtautological_compare)
warning(insn->pos, "self-comparison always evaluates to true");
- return replace_with_pseudo(insn, value_pseudo(insn->type, 1));
+ return replace_with_pseudo(insn, value_pseudo(1));
case OP_AND:
case OP_OR:
@@ -716,7 +716,7 @@ static int simplify_binop_same_args(struct instruction *insn, pseudo_t arg)
case OP_AND_BOOL:
case OP_OR_BOOL:
remove_usage(arg, &insn->src2);
- insn->src2 = value_pseudo(insn->type, 0);
+ insn->src2 = value_pseudo(0);
insn->opcode = OP_SET_NE;
return REPEAT_CSE;
@@ -819,7 +819,7 @@ static int simplify_constant_unop(struct instruction *insn)
mask = 1ULL << (insn->size-1);
res &= mask | (mask-1);
- replace_with_pseudo(insn, value_pseudo(insn->type, res));
+ replace_with_pseudo(insn, value_pseudo(res));
return REPEAT_CSE;
}
@@ -952,7 +952,7 @@ static int simplify_cast(struct instruction *insn)
if (constant(src)) {
int sign = orig_type->ctype.modifiers & MOD_SIGNED;
long long val = get_cast_value(src->value, orig_size, size, sign);
- src = value_pseudo(orig_type, val);
+ src = value_pseudo(val);
goto simplify;
}
diff --git a/sparse-llvm.c b/sparse-llvm.c
index 31f87f0b..29fb65f1 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -242,28 +242,23 @@ static LLVMTypeRef symbol_type(LLVMModuleRef module, struct symbol *sym)
return ret;
}
-static LLVMTypeRef int_type_by_size(int size)
+static LLVMTypeRef insn_symbol_type(LLVMModuleRef module, struct instruction *insn)
{
- switch (size) {
- case 1: return LLVMInt1Type();
+ if (insn->type)
+ return symbol_type(module, insn->type);
+
+ switch (insn->size) {
case 8: return LLVMInt8Type();
case 16: return LLVMInt16Type();
case 32: return LLVMInt32Type();
case 64: return LLVMInt64Type();
default:
- die("invalid bit size %d", size);
+ die("invalid bit size %d", insn->size);
break;
}
- return NULL; /* not reached */
-}
-static LLVMTypeRef insn_symbol_type(LLVMModuleRef module, struct instruction *insn)
-{
- if (insn->type)
- return symbol_type(module, insn->type);
-
- return int_type_by_size(insn->size);
+ return NULL; /* not reached */
}
static LLVMLinkage data_linkage(struct symbol *sym)
@@ -365,7 +360,7 @@ static LLVMValueRef pseudo_to_value(struct function *fn, struct instruction *ins
break;
}
case PSEUDO_VAL:
- result = LLVMConstInt(int_type_by_size(pseudo->size), pseudo->value, 1);
+ result = LLVMConstInt(insn_symbol_type(fn->module, insn), pseudo->value, 1);
break;
case PSEUDO_ARG: {
result = LLVMGetParam(fn->fn, pseudo->nr - 1);