Skip to contentSkip to conversation

sparse, llvm: Pointer cast code generation

PATCH New Pekka Enberg 1 participant 2 messages Nov 22, 2011 Sparse checker

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 sparse, llvm: Pointer cast code generation

This patch implement code generation for OP_PTRCAST using LLVMBuildBitCast().

Cc Christopher Li <[email protected]>
Cc Jeff Garzik <[email protected]>
Cc Linus Torvalds <[email protected]>
---
 sparse-llvm.c                |   20 +++++++++++++++++++-
 validation/backend/ptrcast.c |    9 +++++++++
 2 files changed, 28 insertions(+), 1 deletions(-)
 create mode 100644 validation/backend/ptrcast.c
sparse-llvm.c +19 -1
index 1a2a34d..e3d8883 100644
@@ -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:
validation/backend/ptrcast.c new file +9 -0
new file mode 100644
index 0000000..46f8add
@@ -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
+ */
Signature · 1 line
1.7.6.4
#1 lore raw

PATCH 2/2 sparse, llvm: OP_SET_B and OP_SET_A code generation

This patch implement unsigned less than and greater than comparison operator LLVM code generation.

Cc Christopher Li <[email protected]>
Cc Jeff Garzik <[email protected]>
Cc Linus Torvalds <[email protected]>
---
 sparse-llvm.c                |    4 ++--
 validation/backend/cmp-ops.c |   10 ++++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)
sparse-llvm.c +2 -2
index e3d8883..6402666 100644
@@ -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);
validation/backend/cmp-ops.c +10 -0
index 5a89bee..b1ad227 100644
@@ -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
Signature · 1 line
1.7.6.4