implement pseudo->ctype
cover implement pseudo->ctype
This patchset tries to implement Chris's `counter RFC': adding ->ctype to pseudo, while removing ->type and ->size from instruction. In this way, it provides easy access to type information for backend.
The first patch adds ->ctype to struct pseudo and doesn't touch struct instruction. It could be applied alone if we really want backward compatibility.
The second patch does more destructive work. It removes ->type and ->size from struct instruction and updates client uses.
The third patch updates sparse-llvm in a naive way, which should have been much simpler with the new ->ctype in pseudo. I guess in some cases ->ctype is even necessary. Consider the example below.
void foo(int x, ...);foo(1, 2, 3LL);
Is it possible to get the types of the 2nd and 3rd arguments in current code, which are simply PSEUDO_VAL?
Xi Wang (3):
add ->ctype to struct pseudo
remove ->type and ->size from struct instruction sparse, llvm: sync with new struct instruction
cse.c | 6 +-- example.c | 12 ++--- flow.c | 12 ++--- linearize.c | 147 +++++++++++++++++++++++++-------------------------------- linearize.h | 17 ++++--- memops.c | 4 +- simplify.c | 24 +++++----- sparse-llvm.c | 50 ++++++++++---------- sparse.c | 2 +- unssa.c | 3 +- 10 files changed, 131 insertions(+), 146 deletions(-)
Signature · 1 line
1.7.9.5
RFC PATCH 1/3 add ->ctype to struct pseudo
This patch implements Chris's `counter RFC' by adding ->ctype to struct pseduo so that we have easy access to type information.
--- flow.c | 2 +- linearize.c | 57 +++++++++++++++++++++++++++++++-------------------------- linearize.h | 5 +++-- memops.c | 2 +- simplify.c | 10 +++++----- unssa.c | 2 +- 6 files changed, 42 insertions(+), 36 deletions(-)
flow.c +1 -1
@@ -462,7 +462,7 @@ found:if (!local)return 0 ;check_access (insn); -convert_load_instruction (insn,value_pseudo (0 )); +convert_load_instruction (insn,value_pseudo (insn->target->ctype,0 ));return 1 ; }
linearize.c +31 -26
224 lines not on this page · raw message
linearize.h +3 -2
@@ -33,6 +33,7 @@ struct pseudo {enum pseudo_type type;struct pseudo_user_list *users;struct ident *ident; +struct symbol *ctype;union {struct symbol *sym;struct instruction *def;
@@ -335,8 +336,8 @@ extern void insert_select(struct basic_block *bb, struct instruction *br, structextern void insert_branch (struct basic_block *bb,struct instruction *br,struct basic_block *target);pseudo_t alloc_phi (struct basic_block *source,pseudo_t pseudo,int size); -pseudo_t alloc_pseudo (struct instruction *def); -pseudo_t value_pseudo (long long val); +pseudo_t alloc_pseudo (struct symbol *ctype,struct instruction *def); +pseudo_t value_pseudo (struct symbol *ctype,long long val);struct entrypoint *linearize_symbol (struct symbol *sym);int unssa (struct entrypoint *ep);
memops.c +1 -1
@@ -126,7 +126,7 @@ static void simplify_loads(struct basic_block *bb)if (!dominators) {if (local) {assert (pseudo->type !=PSEUDO_ARG ); -convert_load_instruction (insn,value_pseudo (0 )); +convert_load_instruction (insn,value_pseudo (insn->target->ctype,0 )); } goto next_load; }
simplify.c +5 -5
@@ -303,7 +303,7 @@ static int simplify_asr(struct instruction *insn, pseudo_t pseudo, long long valif (value >= size) {warning (insn->pos,"right shift by bigger than source value" ); -return replace_with_pseudo (insn,value_pseudo (0 )); +return replace_with_pseudo (insn,value_pseudo (pseudo->ctype,0 )); }if (!value)return replace_with_pseudo (insn, pseudo);
@@ -318,7 +318,7 @@ static int simplify_constant_rightside(struct instruction *insn)case OP_SUB :if (value) { insn->opcode =OP_ADD ; - insn->src2 =value_pseudo (-value); + insn->src2 =value_pseudo (insn->src2->ctype, -value);return REPEAT_CSE ; }/* Fall through */
@@ -480,7 +480,7 @@ static int simplify_constant_binop(struct instruction *insn) } res &= bits; -replace_with_pseudo (insn,value_pseudo (res)); +replace_with_pseudo (insn,value_pseudo (insn->target->ctype, res));return REPEAT_CSE ; }
@@ -574,7 +574,7 @@ static int simplify_constant_unop(struct instruction *insn) mask =1ULL << (insn->size-1 ); res &= mask | (mask-1 ); -replace_with_pseudo (insn,value_pseudo (res)); +replace_with_pseudo (insn,value_pseudo (insn->target->ctype, res));return REPEAT_CSE ; }
@@ -681,7 +681,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 (val); + src =value_pseudo (src->ctype, val); goto simplify; }
unssa.c +1 -1
@@ -44,7 +44,7 @@ static void replace_phi_node(struct instruction *phi) {pseudo_t tmp; - tmp =alloc_pseudo (NULL ); + tmp =alloc_pseudo (phi->target->ctype,NULL ); tmp->type = phi->target->type; tmp->ident = phi->target->ident; tmp->def =NULL ;// defined by all the phisrc
Signature · 1 line
1.7.9.5
RFC PATCH 2/3 remove ->type and ->size from struct instruction
In reply to Xi WangOne can use insn->target->ctype and further ->bit_size to get ->type and ->size of an instruction, respectively.
--- cse.c | 6 ++-- example.c | 12 +++---- flow.c | 10 +++--- linearize.c | 110 +++++++++++++++++++++++------------------------------------ linearize.h | 12 ++++--- memops.c | 2 +- simplify.c | 14 ++++---- sparse.c | 2 +- unssa.c | 1 - 9 files changed, 74 insertions(+), 95 deletions(-)
cse.c +3 -3
@@ -43,7 +43,7 @@ static void clean_up_one_instruction(struct basic_block *bb, struct instructionreturn ;assert (insn->bb == bb); repeat_phase |=simplify_instruction (insn); - hash = (insn->opcode <<3 ) + (insn->size >>3 ); + hash = (insn->opcode <<3 ) + (instruction_size (insn) >>3 );switch (insn->opcode) {case OP_SEL : hash +=hashval (insn->src3);
@@ -237,8 +237,8 @@ static int insn_compare(const void *_i1, const void *_i2)default :warning (i1->pos,"bad instruction on hash chain" ); } -if (i1->size != i2->size) -return i1->size < i2->size ?-1 :1 ; +if (instruction_size (i1) !=instruction_size (i2)) +return instruction_size (i1) <instruction_size (i2) ?-1 :1 ;return 0 ; }
example.c +6 -6
@@ -896,7 +896,7 @@ static void do_binop(struct bb_state *state, struct instruction *insn, pseudo_tstruct hardreg *dst; dst =target_copy_reg (state, src->reg, insn->target); -output_insn (state,"%s.%d %s,%s" , op, insn->size,show_op (state, src2), dst->name); +output_insn (state,"%s.%d %s,%s" , op,instruction_size (insn),show_op (state, src2), dst->name);put_operand (state, src);put_operand (state, src2);add_pseudo_reg (state, insn->target, dst);
@@ -983,7 +983,7 @@ static void kill_dead_pseudos(struct bb_state *state)static void generate_store (struct instruction *insn,struct bb_state *state) { -output_insn (state,"mov.%d %s,%s" , insn->size,reg_or_imm (state, insn->target),address (state, insn)); +output_insn (state,"mov.%d %s,%s" ,instruction_size (insn),reg_or_imm (state, insn->target),address (state, insn)); }static void generate_load (struct instruction *insn,struct bb_state *state)
@@ -993,7 +993,7 @@ static void generate_load(struct instruction *insn, struct bb_state *state)kill_dead_pseudos (state); dst =target_reg (state, insn->target,NULL ); -output_insn (state,"mov.%d %s,%s" , insn->size, input, dst->name); +output_insn (state,"mov.%d %s,%s" ,instruction_size (insn), input, dst->name); }static void kill_pseudo (struct bb_state *state,pseudo_t pseudo)
@@ -1031,7 +1031,7 @@ static void generate_cast(struct bb_state *state, struct instruction *insn)struct hardreg *src =getreg (state, insn->src, insn->target);struct hardreg *dst;unsigned int old = insn->orig_type ? insn->orig_type->bit_size :0 ; -unsigned int new = insn->size; +unsigned int new =instruction_size (insn);/* * Cast to smaller type? Ignore the high bits, we
@@ -1050,7 +1050,7 @@ static void generate_cast(struct bb_state *state, struct instruction *insn)unsigned long long mask; mask = ~(~0ULL << old); mask &= ~(~0ULL << new); -output_insn (state,"andl.%d $%#llx,%s" , insn->size, mask, dst->name); +output_insn (state,"andl.%d $%#llx,%s" ,instruction_size (insn), mask, dst->name); }add_pseudo_reg (state, insn->target, dst); }
@@ -1358,7 +1358,7 @@ static void generate_compare(struct bb_state *state, struct instruction *insn) src =getreg (state, insn->src1, insn->target); src2 =generic (state, insn->src2); -output_insn (state,"cmp.%d %s,%s" , insn->size, src2, src->name); +output_insn (state,"cmp.%d %s,%s" ,instruction_size (insn), src2, src->name);add_cc_cache (state, opcode, insn->target); }
flow.c +5 -5
@@ -268,8 +268,8 @@ static int overlapping_memop(struct instruction *a, struct instruction *b) {unsigned int a_start =bytes_to_bits (a->offset);unsigned int b_start =bytes_to_bits (b->offset); -unsigned int a_size = a->size; -unsigned int b_size = b->size; +unsigned int a_size =instruction_size (a); +unsigned int b_size =instruction_size (b);if (a_size + a_start <= b_start)return 0 ;
@@ -280,7 +280,7 @@ static int overlapping_memop(struct instruction *a, struct instruction *b)static inline int same_memop (struct instruction *a,struct instruction *b) { -return a->offset == b->offset && a->size == b->size; +return a->offset == b->offset &&instruction_size (a) ==instruction_size (b); }/*
@@ -359,7 +359,7 @@ no_dominance: found_dominator: br =delete_last_instruction (&parent->insns); - phi =alloc_phi (parent, one->target, one->size); + phi =alloc_phi (parent, one->target); phi->ident = phi->ident ? : pseudo->ident;add_instruction (&parent->insns, br);use_pseudo (insn, phi,add_pseudo (dominators, phi));
@@ -582,7 +582,7 @@ void check_access(struct instruction *insn)pseudo_t pseudo = insn->src;if (insn->bb && pseudo->type ==PSEUDO_SYM ) { -int offset = insn->offset, bit =bytes_to_bits (offset) + insn->size; +int offset = insn->offset, bit =bytes_to_bits (offset) +instruction_size (insn);struct symbol *sym = pseudo->sym;if (sym->bit_size >0 && (offset <0 || bit > sym->bit_size))
linearize.c +43 -67
374 lines not on this page · raw message
linearize.h +8 -4
@@ -69,11 +69,9 @@ struct asm_rules {DECLARE_ALLOCATOR (asm_rules); struct instruction { - unsigned opcode:8, - size:24; + unsigned opcode; struct basic_block *bb; struct position pos; - struct symbol *type; union { pseudo_t target; pseudo_t cond; /* for branch and switch */
@@ -237,6 +235,12 @@ struct basic_block {void *priv; }; +static inline int instruction_size (const struct instruction *insn) +{ +struct symbol *type = insn->target ? insn->target->ctype :NULL ; +return type ? type->bit_size >0 ? type->bit_size :0 :0 ; +} +static inline int is_branch_goto (struct instruction *br) {return br && br->opcode==OP_BR && (!br->bb_true || !br->bb_false);
@@ -335,7 +339,7 @@ struct entrypoint {extern void insert_select (struct basic_block *bb,struct instruction *br,struct instruction *phi,pseudo_t if_true,pseudo_t if_false);extern void insert_branch (struct basic_block *bb,struct instruction *br,struct basic_block *target); -pseudo_t alloc_phi (struct basic_block *source,pseudo_t pseudo,int size); +pseudo_t alloc_phi (struct basic_block *source,pseudo_t pseudo);pseudo_t alloc_pseudo (struct symbol *ctype,struct instruction *def);pseudo_t value_pseudo (struct symbol *ctype,long long val);
memops.c +1 -1
@@ -56,7 +56,7 @@ no_dominance: found_dominator: br =delete_last_instruction (&parent->insns); - phi =alloc_phi (parent, one->target, one->size); + phi =alloc_phi (parent, one->target); phi->ident = phi->ident ? : one->target->ident;add_instruction (&parent->insns, br);use_pseudo (insn, phi,add_pseudo (dominators, phi));
simplify.c +7 -7
@@ -279,7 +279,7 @@ static unsigned int value_size(long long value)*/ static unsigned int operand_size (struct instruction *insn,pseudo_t pseudo) { -unsigned int size = insn->size; +unsigned int size =instruction_size (insn);if (pseudo->type ==PSEUDO_REG ) {struct instruction *src = pseudo->def;
@@ -375,7 +375,7 @@ static int simplify_constant_binop(struct instruction *insn)unsigned long long ul, ur;long long res, mask, bits; - mask =1ULL << (insn->size-1 ); + mask =1ULL << (instruction_size (insn)-1 ); bits = mask | (mask-1 );if (left & mask)
@@ -571,7 +571,7 @@ static int simplify_constant_unop(struct instruction *insn)default :return 0 ; } - mask =1ULL << (insn->size-1 ); + mask =1ULL << (instruction_size (insn)-1 ); res &= mask | (mask-1 );replace_with_pseudo (insn,value_pseudo (insn->target->ctype, res));
@@ -670,11 +670,11 @@ static int simplify_cast(struct instruction *insn)return 0 ;/* Keep casts with pointer on either side (not only case of OP_PTRCAST) */ -if (is_ptr_type (orig_type) ||is_ptr_type (insn->type)) +if (is_ptr_type (orig_type) ||is_ptr_type (insn->target->ctype))return 0 ; orig_size = orig_type->bit_size; - size = insn->size; + size =instruction_size (insn); src = insn->src;/* A cast of a constant? */
@@ -688,7 +688,7 @@ static int simplify_cast(struct instruction *insn)/* A cast of a "and" might be a no-op.. */ if (src->type ==PSEUDO_REG ) {struct instruction *def = src->def; -if (def->opcode ==OP_AND && def->size >= size) { +if (def->opcode ==OP_AND &&instruction_size (def) >= size) {pseudo_t val = def->src2;if (val->type ==PSEUDO_VAL ) {unsigned long long value = val->value;
@@ -854,7 +854,7 @@ static int simplify_branch(struct instruction *insn) }if (def->opcode ==OP_CAST || def->opcode ==OP_SCAST ) {int orig_size = def->orig_type ? def->orig_type->bit_size :0 ; -if (def->size > orig_size) { +if (instruction_size (def) > orig_size) {use_pseudo (insn, def->src, &insn->cond);remove_usage (cond, &insn->cond);return REPEAT_CSE ;
sparse.c +1 -1
@@ -102,7 +102,7 @@ static void check_cast_instruction(struct instruction *insn)struct symbol *orig_type = insn->orig_type;if (orig_type) {int old = orig_type->bit_size; -int new = insn->size; +int new =instruction_size (insn);int oldsigned = (orig_type->ctype.modifiers &MOD_SIGNED ) !=0 ;int newsigned = insn->opcode ==OP_SCAST ;
unssa.c +0 -1
@@ -105,7 +105,6 @@ static void rewrite_phisrc_bb(struct basic_block *bb) copy->bb = bb; copy->opcode =OP_COPY ; - copy->size = insn->size; copy->pos = insn->pos; copy->target = tmp; copy->src = src;
Signature · 1 line
1.7.9.5
RFC PATCH 3/3 sparse, llvm: sync with new struct instruction
In reply to Xi WangThis patch is basically substitutes insn->type and insn->size with insn->target->ctype and instruction_size(insn), respectively. With the new ->ctype in struct pseudo, generating LLVM IR should be much simpler.
--- sparse-llvm.c | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-)
sparse-llvm.c +25 -25
@@ -236,17 +236,17 @@ static LLVMTypeRef symbol_type(LLVMModuleRef module, struct symbol *sym)static LLVMTypeRef insn_symbol_type (LLVMModuleRef module,struct instruction *insn) { -if (insn->type) -return symbol_type (module, insn->type); +if (insn->target && insn->target->ctype) +return symbol_type (module, insn->target->ctype); -switch (insn->size) { +switch (instruction_size (insn)) {case 8 :return LLVMInt8Type ();case 16 :return LLVMInt16Type ();case 32 :return LLVMInt32Type ();case 64 :return LLVMInt64Type ();default : -die ("invalid bit size %d" , insn->size); +die ("invalid bit size %d" ,instruction_size (insn));break ; }
@@ -364,7 +364,7 @@ static LLVMTypeRef pseudo_type(struct function *fn, struct instruction *insn, psswitch (pseudo->type) {case PSEUDO_REG : - result =symbol_type (fn->module, pseudo->def->type); + result =symbol_type (fn->module, pseudo->def->target->ctype);break ;case PSEUDO_SYM : {struct symbol *sym = pseudo->sym;
@@ -455,75 +455,75 @@ static void output_op_binary(struct function *fn, struct instruction *insn)switch (insn->opcode) {/* Binary */ case OP_ADD : -if (symbol_is_fp_type (insn->type)) +if (symbol_is_fp_type (insn->target->ctype)) target =LLVMBuildFAdd (fn->builder, lhs, rhs, target_name);else target =LLVMBuildAdd (fn->builder, lhs, rhs, target_name);break ;case OP_SUB : -if (symbol_is_fp_type (insn->type)) +if (symbol_is_fp_type (insn->target->ctype)) target =LLVMBuildFSub (fn->builder, lhs, rhs, target_name);else target =LLVMBuildSub (fn->builder, lhs, rhs, target_name);break ;case OP_MULU : -if (symbol_is_fp_type (insn->type)) +if (symbol_is_fp_type (insn->target->ctype)) target =LLVMBuildFMul (fn->builder, lhs, rhs, target_name);else target =LLVMBuildMul (fn->builder, lhs, rhs, target_name);break ;case OP_MULS : -assert (!symbol_is_fp_type (insn->type)); +assert (!symbol_is_fp_type (insn->target->ctype)); target =LLVMBuildMul (fn->builder, lhs, rhs, target_name);break ;case OP_DIVU : -if (symbol_is_fp_type (insn->type)) +if (symbol_is_fp_type (insn->target->ctype)) target =LLVMBuildFDiv (fn->builder, lhs, rhs, target_name);else target =LLVMBuildUDiv (fn->builder, lhs, rhs, target_name);break ;case OP_DIVS : -assert (!symbol_is_fp_type (insn->type)); +assert (!symbol_is_fp_type (insn->target->ctype)); target =LLVMBuildSDiv (fn->builder, lhs, rhs, target_name);break ;case OP_MODU : -assert (!symbol_is_fp_type (insn->type)); +assert (!symbol_is_fp_type (insn->target->ctype)); target =LLVMBuildURem (fn->builder, lhs, rhs, target_name);break ;case OP_MODS : -assert (!symbol_is_fp_type (insn->type)); +assert (!symbol_is_fp_type (insn->target->ctype)); target =LLVMBuildSRem (fn->builder, lhs, rhs, target_name);break ;case OP_SHL : -assert (!symbol_is_fp_type (insn->type)); +assert (!symbol_is_fp_type (insn->target->ctype)); target =LLVMBuildShl (fn->builder, lhs, rhs, target_name);break ;case OP_LSR : -assert (!symbol_is_fp_type (insn->type)); +assert (!symbol_is_fp_type (insn->target->ctype)); target =LLVMBuildLShr (fn->builder, lhs, rhs, target_name);break ;case OP_ASR : -assert (!symbol_is_fp_type (insn->type)); +assert (!symbol_is_fp_type (insn->target->ctype)); target =LLVMBuildAShr (fn->builder, lhs, rhs, target_name);break ;/* Logical */ case OP_AND : -assert (!symbol_is_fp_type (insn->type)); +assert (!symbol_is_fp_type (insn->target->ctype)); target =LLVMBuildAnd (fn->builder, lhs, rhs, target_name);break ;case OP_OR : -assert (!symbol_is_fp_type (insn->type)); +assert (!symbol_is_fp_type (insn->target->ctype)); target =LLVMBuildOr (fn->builder, lhs, rhs, target_name);break ;case OP_XOR : -assert (!symbol_is_fp_type (insn->type)); +assert (!symbol_is_fp_type (insn->target->ctype)); target =LLVMBuildXor (fn->builder, lhs, rhs, target_name);break ;case OP_AND_BOOL : {LLVMValueRef x, y; -assert (!symbol_is_fp_type (insn->type)); +assert (!symbol_is_fp_type (insn->target->ctype)); y =LLVMBuildICmp (fn->builder, LLVMIntNE, lhs,LLVMConstInt (LLVMTypeOf (lhs),0 ,0 ),"y" ); x =LLVMBuildICmp (fn->builder, LLVMIntNE, rhs,LLVMConstInt (LLVMTypeOf (rhs),0 ,0 ),"x" );
@@ -534,7 +534,7 @@ static void output_op_binary(struct function *fn, struct instruction *insn)case OP_OR_BOOL : {LLVMValueRef tmp; -assert (!symbol_is_fp_type (insn->type)); +assert (!symbol_is_fp_type (insn->target->ctype)); tmp =LLVMBuildOr (fn->builder, rhs, lhs,"tmp" );
@@ -914,7 +914,7 @@ static void output_op_ptrcast(struct function *fn, struct instruction *insn)pseudo_name (insn->target, target_name); -assert (!symbol_is_fp_type (insn->type)); +assert (!symbol_is_fp_type (insn->target->ctype)); target =LLVMBuildBitCast (fn->builder, src,insn_symbol_type (fn->module, insn), target_name);
@@ -932,9 +932,9 @@ static void output_op_cast(struct function *fn, struct instruction *insn, LLVMOppseudo_name (insn->target, target_name); -assert (!symbol_is_fp_type (insn->type)); +assert (!symbol_is_fp_type (insn->target->ctype)); -if (insn->size <LLVMGetIntTypeWidth (LLVMTypeOf (src))) +if (instruction_size (insn) <LLVMGetIntTypeWidth (LLVMTypeOf (src))) target =LLVMBuildTrunc (fn->builder, src,insn_symbol_type (fn->module, insn), target_name);else target =LLVMBuildCast (fn->builder, op, src,insn_symbol_type (fn->module, insn), target_name);
@@ -960,7 +960,7 @@ static void output_op_copy(struct function *fn, struct instruction *insn,* than using "X + 0" simply to produce a new LLVM pseudo */ -if (symbol_is_fp_type (insn->type)) +if (symbol_is_fp_type (insn->target->ctype)) target =LLVMBuildFAdd (fn->builder, src,LLVMConstReal (const_type,0.0 ), target_name);else
Signature · 1 line
1.7.9.5
Quoted 3 lines · Xi Wang
This patchset tries to implement Chris's `counter RFC': adding ->ctype to pseudo, while removing ->type and ->size from instruction. In this way, it provides easy access to type information for backend.
Could you please CC me on patches that touch Sparse/LLVM in the future?
The LLVM parts look good to me:
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
I should have done that. Sorry.
Thanks for reviewing!
- xi
Quoted 6 lines · Pekka Enberg
Could you please CC me on patches that touch Sparse/LLVM in the future?
The LLVM parts look good to me:
Acked-by Pekka Enberg <[email protected]>
I played with the new ->ctype in pseudo a little bit to generate LLVM IR. It seems much easier to emit correct type at backend using ->ctype.
The code is available at:
git clone --recursive https://github.com/xiw/splay.git
Try make' and make check' if you have LLVM.
See example inputs in `test'. Currently the generator works for simple programs like md5.c (with -D_FORTIFY_SOURCE=0).
You can also find patches to sparse at:
https://github.com/xiw/sparse/compare/splay
- xi
Quoted 41 lines · Xi Wang
This patchset tries to implement Chris's `counter RFC': adding ->ctype to pseudo, while removing ->type and ->size from instruction. In this way, it provides easy access to type information for backend.
The first patch adds ->ctype to struct pseudo and doesn't touch struct instruction. It could be applied alone if we really want backward compatibility.
The second patch does more destructive work. It removes ->type and ->size from struct instruction and updates client uses.
The third patch updates sparse-llvm in a naive way, which should have been much simpler with the new ->ctype in pseudo. I guess in some cases ->ctype is even necessary. Consider the example below.
void
foo(int x, ...);foo(1, 2, 3LL);Is it possible to get the types of the 2nd and 3rd arguments in current code, which are simply
PSEUDO_VAL?Xi Wang (3):
add ->ctype to struct pseudo
remove ->type and ->size from struct instruction
sparse, llvm: sync with new struct instructioncse.c | 6 +-- example.c | 12 ++--- flow.c | 12 ++--- linearize.c | 147 +++++++++++++++++++++++++-------------------------------- linearize.h | 17 ++++--- memops.c | 4 +- simplify.c | 24 +++++----- sparse-llvm.c | 50 ++++++++++---------- sparse.c | 2 +- unssa.c | 3 +- 10 files changed, 131 insertions(+), 146 deletions(-)Signature · 1 line
1.7.9.5
Quoted 7 lines · Xi Wang
I played with the new ->ctype in pseudo a little bit to generate LLVM IR. It seems much easier to emit correct type at backend using ->ctype.
The code is available at:
git clone --recursive https://github.com/xiw/splay.git
Quoted 8 lines
Try
make' andmake check' if you have LLVM.See example inputs in `test'. Currently the generator works for simple programs like
md5.c(with -D_FORTIFY_SOURCE=0).You can also find patches to sparse at:
Interesting. What are you planning to do with "splay"? Is there something that prevents fixing the current LLVM backend in master? --
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 2 lines · Pekka Enberg
Interesting. What are you planning to do with "splay"? Is there something that prevents fixing the current LLVM backend in master?
Just did this to try the new ->ctype in pseudo. I don't want to maintain another llvm backend for sparse. :-)
BTW, I feel like LLVM's C interface is very incomplete. I had to wrap some code in C++.
Besides, the phi nodes in sparse and LLVM are different. LLVM's phi 1) requires one entry for each predecessor, and 2) must stay at the beginning of a block. I didn't find an easy way to translate sparse's phi to LLVM's, so instead generated load/store for phi nodes.
- xi
Quoted 5 lines · Xi Wang
Besides, the phi nodes in sparse and LLVM are different. LLVM's phi 1) requires one entry for each predecessor, and 2) must stay at the beginning of a block. I didn't find an easy way to translate sparse's phi to LLVM's, so instead generated load/store for phi nodes.
That is reasonable.
Jeff
Quoted 2 lines · Xi Wang
BTW, I feel like LLVM's C interface is very incomplete. I had to wrap some code in C++.
It'd probably be best to try to get the LLVM C API fixed upstream. I've seen with the libcpu project what happens when you write your core code in C but use the LLVM C++ APIs, and it's not pretty... ;-) --
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Christopher Li
maintainerQuoted 3 lines · Xi Wang
This patchset tries to implement Chris's `counter RFC': adding ->ctype to pseudo, while removing ->type and ->size from instruction. In this way, it provides easy access to type information for backend.
I like this series a lot. Do you have an update version of the patch?
Thanks
Chris
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 2 lines · Christopher Li
I like this series a lot. Do you have an update version of the patch?
I will resend a revised version of these patches.
With ->ctype in pseudo, we might have to disable several simplifications in simplify.c and cse.c for type consistency. One such example is:
unsigned int foo(unsigned long long x)
{
unsigned int tmp = x & 0x1fffffff;
return tmp;
}sparse emits:
and.64 %r2 <- %arg1, $0x1fffffff ret.32 %r2
%r2 seems to be interpreted as both 64 and 32 bits, which will also trouble backends.
To fix the inconsistency, we may need to disable some simplification:
https://github.com/xiw/sparse/commit/7072002
Then we have:
and.64 %r2 <- %arg1, $0x1fffffff cast.32 %r3 <- (64) %r2 ret.32 %r3
Does this make sense? Or should we just provide an option to turn off all sparse simplifications, since backends usually have their own optimization passes?
- xi
Christopher Li
maintainerQuoted 5 lines · Xi Wang
On Jun 21, 2012, at 6:00 PM, Christopher Li wrote:
https://github.com/xiw/sparse/commit/7072002Then we have:
Quoted 7 lines
and.64 %r2 <- %arg1, $0x1fffffff
cast.32 %r3 <- (64) %r2
ret.32 %r3Does this make sense? Or should we just provide an option to turn off all sparse simplifications, since backends usually have their own optimization passes?
Adding the cast from 64 to 32 bit make sense.
The sparse checker can still benefit from the simplifications. I think it is OK we turn off those simplifications for sparse-llvm back end.
I want to have this module that, the back end can pick to chose what kind of simplification/optimization done to the linearized instructions.
I think the sparse-llvm back end need a different code path in the front end for things like GEP any way.
Chris
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html