From: Pekka Enberg <penberg@kernel.org>
To: linux-sparse@vger.kernel.org
Cc: Pekka Enberg <penberg@kernel.org>,
Christopher Li <sparse@chrisli.org>,
Jeff Garzik <jgarzik@redhat.com>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH 1/2] sparse, llvm: Pointer cast code generation
Date: Tue, 22 Nov 2011 17:27:40 +0200 [thread overview]
Message-ID: <1321975661-1692-1-git-send-email-penberg@kernel.org> (raw)
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
next reply other threads:[~2011-11-22 15:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-22 15:27 Pekka Enberg [this message]
2011-11-22 15:27 ` [PATCH 2/2] sparse, llvm: OP_SET_B and OP_SET_A code generation Pekka Enberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1321975661-1692-1-git-send-email-penberg@kernel.org \
--to=penberg@kernel.org \
--cc=jgarzik@redhat.com \
--cc=linux-sparse@vger.kernel.org \
--cc=sparse@chrisli.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).