aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/sparse-llvm.c
diff options
authorJeff Garzik <jeff@garzik.org>2011-08-30 23:01:59 -0400
committerJeff Garzik <jgarzik@redhat.com>2011-08-30 23:01:59 -0400
commit85c19bf76ed7a4ce82790bdb1526d8b45f9cb454 (patch)
treefc1f84e89558191c6d2c9dfee6c54e45c3451f72 /sparse-llvm.c
parent0c8f7c8757d13a8116832d083ed2d71b6b679d89 (diff)
downloadsparse-dev-85c19bf76ed7a4ce82790bdb1526d8b45f9cb454.tar.gz
sparse, llvm: move OP_COPY support to separate function. Add FP support.
Diffstat (limited to 'sparse-llvm.c')
-rw-r--r--sparse-llvm.c42
1 files changed, 30 insertions, 12 deletions
diff --git a/sparse-llvm.c b/sparse-llvm.c
index d3cb4f2e..41563833 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -637,6 +637,34 @@ static void output_op_cast(struct function *fn, struct instruction *insn, LLVMOp
insn->target->priv = target;
}
+static void output_op_copy(struct function *fn, struct instruction *insn,
+ pseudo_t pseudo)
+{
+ LLVMValueRef src, target;
+ LLVMTypeRef const_type;
+ char target_name[64];
+
+ pseudo_name(insn->target, target_name);
+ src = pseudo_to_value(fn, insn, pseudo);
+ const_type = insn_symbol_type(insn);
+
+ /*
+ * This is nothing more than 'target = src'
+ *
+ * TODO: find a better way to provide an identity function,
+ * than using "X + 0" simply to produce a new LLVM pseudo
+ */
+
+ if (symbol_is_fp_type(insn->type))
+ target = LLVMBuildFAdd(fn->builder, src,
+ LLVMConstReal(const_type, 0.0), target_name);
+ else
+ target = LLVMBuildAdd(fn->builder, src,
+ LLVMConstInt(const_type, 0, 0), target_name);
+
+ insn->target->priv = target;
+}
+
static void output_insn(struct function *fn, struct instruction *insn)
{
switch (insn->opcode) {
@@ -733,19 +761,9 @@ static void output_insn(struct function *fn, struct instruction *insn)
case OP_ASM:
assert(0);
break;
- case OP_COPY: {
- LLVMValueRef src, target;
- char target_name[64];
-
- pseudo_name(insn->target, target_name);
- src = pseudo_to_value(fn, insn, insn->src);
-
- target = LLVMBuildAdd(fn->builder, src,
- LLVMConstInt(LLVMInt32Type(), 0, 0), target_name);
-
- insn->target->priv = target;
+ case OP_COPY:
+ output_op_copy(fn, insn, insn->src);
break;
- }
default:
break;
}