* [PATCH 1/2] sparse, llvm: Pointer cast code generation
@ 2011-11-22 15:27 Pekka Enberg
2011-11-22 15:27 ` [PATCH 2/2] sparse, llvm: OP_SET_B and OP_SET_A " Pekka Enberg
0 siblings, 1 reply; 2+ messages in thread
From: Pekka Enberg @ 2011-11-22 15:27 UTC (permalink / raw)
To: linux-sparse; +Cc: Pekka Enberg, Christopher Li, Jeff Garzik, Linus Torvalds
This patch implement code generation for OP_PTRCAST using LLVMBuildBitCast().
Cc: Christopher Li <sparse@chrisli.org>
Cc: Jeff Garzik <jgarzik@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
---
sparse-llvm.c | 20 +++++++++++++++++++-
validation/backend/ptrcast.c | 9 +++++++++
2 files changed, 28 insertions(+), 1 deletions(-)
create mode 100644 validation/backend/ptrcast.c
diff --git a/sparse-llvm.c b/sparse-llvm.c
index 1a2a34d..e3d8883 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -812,6 +812,24 @@ static void output_op_phi(struct function *fn, struct instruction *insn)
insn->target->priv = target;
}
+static void output_op_ptrcast(struct function *fn, struct instruction *insn)
+{
+ LLVMValueRef src, target;
+ char target_name[64];
+
+ src = insn->src->priv;
+ if (!src)
+ src = pseudo_to_value(fn, insn, insn->src);
+
+ pseudo_name(insn->target, target_name);
+
+ assert(!symbol_is_fp_type(insn->type));
+
+ target = LLVMBuildBitCast(fn->builder, src, insn_symbol_type(fn->module, insn), target_name);
+
+ insn->target->priv = target;
+}
+
static void output_op_cast(struct function *fn, struct instruction *insn, LLVMOpcode op)
{
LLVMValueRef src, target;
@@ -917,7 +935,7 @@ static void output_insn(struct function *fn, struct instruction *insn)
assert(0);
break;
case OP_PTRCAST:
- assert(0);
+ output_op_ptrcast(fn, insn);
break;
case OP_BINARY ... OP_BINARY_END:
case OP_BINCMP ... OP_BINCMP_END:
diff --git a/validation/backend/ptrcast.c b/validation/backend/ptrcast.c
new file mode 100644
index 0000000..46f8add
--- /dev/null
+++ b/validation/backend/ptrcast.c
@@ -0,0 +1,9 @@
+static char *ptrcast(unsigned long *x)
+{
+ return (unsigned char *) x;
+}
+
+/*
+ * check-name: Pointer cast code generation
+ * check-command: ./sparsec -c $file -o tmp.o
+ */
--
1.7.6.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] sparse, llvm: OP_SET_B and OP_SET_A code generation
2011-11-22 15:27 [PATCH 1/2] sparse, llvm: Pointer cast code generation Pekka Enberg
@ 2011-11-22 15:27 ` Pekka Enberg
0 siblings, 0 replies; 2+ messages in thread
From: Pekka Enberg @ 2011-11-22 15:27 UTC (permalink / raw)
To: linux-sparse; +Cc: Pekka Enberg, Christopher Li, Jeff Garzik, Linus Torvalds
This patch implement unsigned less than and greater than comparison operator
LLVM code generation.
Cc: Christopher Li <sparse@chrisli.org>
Cc: Jeff Garzik <jgarzik@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
---
sparse-llvm.c | 4 ++--
validation/backend/cmp-ops.c | 10 ++++++++++
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/sparse-llvm.c b/sparse-llvm.c
index e3d8883..6402666 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -516,10 +516,10 @@ static void output_op_binary(struct function *fn, struct instruction *insn)
target = LLVMBuildICmp(fn->builder, LLVMIntSGT, lhs, rhs, target_name);
break;
case OP_SET_B:
- assert(0);
+ target = LLVMBuildICmp(fn->builder, LLVMIntULT, lhs, rhs, target_name);
break;
case OP_SET_A:
- assert(0);
+ target = LLVMBuildICmp(fn->builder, LLVMIntUGT, lhs, rhs, target_name);
break;
case OP_SET_BE:
assert(0);
diff --git a/validation/backend/cmp-ops.c b/validation/backend/cmp-ops.c
index 5a89bee..b1ad227 100644
--- a/validation/backend/cmp-ops.c
+++ b/validation/backend/cmp-ops.c
@@ -18,6 +18,16 @@ static int setg(int x, int y)
return x > y;
}
+static int setb(unsigned int x, unsigned int y)
+{
+ return x < y;
+}
+
+static int seta(unsigned int x, unsigned int y)
+{
+ return x > y;
+}
+
/*
* check-name: Comparison operator code generation
* check-command: ./sparsec -c $file -o tmp.o
--
1.7.6.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-11-22 15:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-22 15:27 [PATCH 1/2] sparse, llvm: Pointer cast code generation Pekka Enberg
2011-11-22 15:27 ` [PATCH 2/2] sparse, llvm: OP_SET_B and OP_SET_A " Pekka Enberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).