* [PATCH 0/5] extra fixes for LLVM
@ 2017-09-18 9:30 Luc Van Oostenryck
2017-09-18 9:30 ` [PATCH 1/5] llvm: warn instead of assert on global inits Luc Van Oostenryck
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2017-09-18 9:30 UTC (permalink / raw)
To: linux-sparse; +Cc: Christopher Li, Luc Van Oostenryck
This series contains a few more fixes for sparse-llvm.
This series is also available for review in the git repository at:
git://github.com/lucvoo/sparse.git llvm-fixes-extras
----------------------------------------------------------------
Luc Van Oostenryck (5):
llvm: warn instead of assert on global inits
llvm: gracefully catch impossible type/value
llvm: add support for float initializer
llvm: give names easier to debug
llvm: only compare void pointers
sparse-llvm.c | 31 +++++++++++++++++++++++++------
1 file changed, 25 insertions(+), 6 deletions(-)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/5] llvm: warn instead of assert on global inits
2017-09-18 9:30 [PATCH 0/5] extra fixes for LLVM Luc Van Oostenryck
@ 2017-09-18 9:30 ` Luc Van Oostenryck
2017-09-18 9:30 ` [PATCH 2/5] llvm: gracefully catch impossible type/value Luc Van Oostenryck
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2017-09-18 9:30 UTC (permalink / raw)
To: linux-sparse; +Cc: Christopher Li, Luc Van Oostenryck
Currently, sparse-llvm can't emit the needed code for
all initializers and when it's the case it stop abruptly
with an assert(0).
This is kinda useless.
Somehow fix this by issuing a warning instead and try to
continue gracefully.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
sparse-llvm.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/sparse-llvm.c b/sparse-llvm.c
index 3a68d09d9..9a32efe36 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -1212,7 +1212,9 @@ static LLVMValueRef output_data(LLVMModuleRef module, struct symbol *sym)
break;
}
default:
- assert(0);
+ warning(initializer->pos, "can't initialize type: %s", show_typename(sym));
+ initial_value = NULL;
+ break;
}
} else {
LLVMTypeRef type = symbol_type(sym);
@@ -1220,6 +1222,9 @@ static LLVMValueRef output_data(LLVMModuleRef module, struct symbol *sym)
initial_value = LLVMConstNull(type);
}
+ if (!initial_value)
+ return NULL;
+
name = sym->ident ? show_ident(sym->ident) : "" ;
data = LLVMAddGlobal(module, LLVMTypeOf(initial_value), name);
--
2.14.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/5] llvm: gracefully catch impossible type/value
2017-09-18 9:30 [PATCH 0/5] extra fixes for LLVM Luc Van Oostenryck
2017-09-18 9:30 ` [PATCH 1/5] llvm: warn instead of assert on global inits Luc Van Oostenryck
@ 2017-09-18 9:30 ` Luc Van Oostenryck
2017-09-18 9:30 ` [PATCH 3/5] llvm: add support for float initializer Luc Van Oostenryck
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2017-09-18 9:30 UTC (permalink / raw)
To: linux-sparse; +Cc: Christopher Li, Luc Van Oostenryck
Until now, in sparse-llvm, an assert(0) was used each time
something which was not yet handled was encountered.
This is doubly annoying because:
- the assert gave no info about the cause
- it also hide possible further issuses.
Fix this by:
- removing the asserts
- use a warnng explaining what's at hand
- try to continue with the following instructions.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
sparse-llvm.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/sparse-llvm.c b/sparse-llvm.c
index 3a68d09d9..9855ae403 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -353,18 +353,23 @@ static LLVMValueRef constant_value(unsigned long long val, LLVMTypeRef dtype)
result = LLVMConstInt(dtype, val, 1);
break;
default:
- assert(0);
+ return NULL;
}
return result;
}
static LLVMValueRef val_to_value(unsigned long long val, struct symbol *ctype)
{
+ LLVMValueRef result;
LLVMTypeRef dtype;
assert(ctype);
dtype = symbol_type(ctype);
- return constant_value(val, dtype);
+ result = constant_value(val, dtype);
+ if (result)
+ return result;
+ sparse_error(ctype->pos, "no value possible for %s", show_typename(ctype));
+ return LLVMGetUndef(symbol_type(ctype));
}
static LLVMValueRef pseudo_to_value(struct function *fn, struct symbol *ctype, pseudo_t pseudo)
@@ -647,6 +652,8 @@ static void output_op_compare(struct function *fn, struct instruction *insn)
rhs = constant_value(insn->src2->value, LLVMTypeOf(lhs));
else
rhs = pseudo_to_value(fn, NULL, insn->src2);
+ if (!rhs)
+ rhs = LLVMGetUndef(symbol_type(insn->type));
pseudo_name(insn->target, target_name);
--
2.14.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/5] llvm: add support for float initializer
2017-09-18 9:30 [PATCH 0/5] extra fixes for LLVM Luc Van Oostenryck
2017-09-18 9:30 ` [PATCH 1/5] llvm: warn instead of assert on global inits Luc Van Oostenryck
2017-09-18 9:30 ` [PATCH 2/5] llvm: gracefully catch impossible type/value Luc Van Oostenryck
@ 2017-09-18 9:30 ` Luc Van Oostenryck
2017-09-18 9:30 ` [PATCH 4/5] llvm: give names easier to debug Luc Van Oostenryck
2017-09-18 9:30 ` [PATCH 5/5] llvm: only compare void pointers Luc Van Oostenryck
4 siblings, 0 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2017-09-18 9:30 UTC (permalink / raw)
To: linux-sparse; +Cc: Christopher Li, Luc Van Oostenryck
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
sparse-llvm.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/sparse-llvm.c b/sparse-llvm.c
index 9a32efe36..206fac227 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -1197,6 +1197,9 @@ static LLVMValueRef output_data(LLVMModuleRef module, struct symbol *sym)
case EXPR_VALUE:
initial_value = LLVMConstInt(symbol_type(sym), initializer->value, 1);
break;
+ case EXPR_FVALUE:
+ initial_value = LLVMConstReal(symbol_type(sym), initializer->fvalue);
+ break;
case EXPR_SYMBOL: {
struct symbol *sym = initializer->symbol;
--
2.14.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/5] llvm: give names easier to debug
2017-09-18 9:30 [PATCH 0/5] extra fixes for LLVM Luc Van Oostenryck
` (2 preceding siblings ...)
2017-09-18 9:30 ` [PATCH 3/5] llvm: add support for float initializer Luc Van Oostenryck
@ 2017-09-18 9:30 ` Luc Van Oostenryck
2017-09-18 9:30 ` [PATCH 5/5] llvm: only compare void pointers Luc Van Oostenryck
4 siblings, 0 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2017-09-18 9:30 UTC (permalink / raw)
To: linux-sparse; +Cc: Christopher Li, Luc Van Oostenryck
LLVM automatically add an numeric suffix for names
automatically created. So, if intermediate names must
be created for a pseudo whose name was, for example, "%R4",
these new names will be "%R41", "%R42".
This is quite annoying because we can't make the distinction
between these names and the original names, (maybe of some other
pseudos whose names were "%R41" & "%R42).
Change this by adding a "." at the end of each name, as this will
then allow to see what the original name was.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
sparse-llvm.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/sparse-llvm.c b/sparse-llvm.c
index 3a68d09d9..3fcc88686 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -277,10 +277,10 @@ static const char *pseudo_name(pseudo_t pseudo, char *buf)
{
switch (pseudo->type) {
case PSEUDO_REG:
- snprintf(buf, MAX_PSEUDO_NAME, "R%d", pseudo->nr);
+ snprintf(buf, MAX_PSEUDO_NAME, "R%d.", pseudo->nr);
break;
case PSEUDO_PHI:
- snprintf(buf, MAX_PSEUDO_NAME, "PHI%d", pseudo->nr);
+ snprintf(buf, MAX_PSEUDO_NAME, "PHI%d.", pseudo->nr);
break;
case PSEUDO_SYM:
case PSEUDO_VAL:
@@ -1141,7 +1141,7 @@ static void output_fn(LLVMModuleRef module, struct entrypoint *ep)
LLVMValueRef arg;
arg = LLVMGetParam(function.fn, i);
- snprintf(name, sizeof(name), "ARG%d", i+1);
+ snprintf(name, sizeof(name), "ARG%d.", i+1);
LLVMSetValueName(arg, name);
}
--
2.14.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 5/5] llvm: only compare void pointers
2017-09-18 9:30 [PATCH 0/5] extra fixes for LLVM Luc Van Oostenryck
` (3 preceding siblings ...)
2017-09-18 9:30 ` [PATCH 4/5] llvm: give names easier to debug Luc Van Oostenryck
@ 2017-09-18 9:30 ` Luc Van Oostenryck
4 siblings, 0 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2017-09-18 9:30 UTC (permalink / raw)
To: linux-sparse; +Cc: Christopher Li, Luc Van Oostenryck
LLVM use a stricter type system fro it's IR than sparse does.
In the present case, sparse allow to compare pointers regardless
of their types.
This create LLVM errors if we try to simply translate, instruction
by instruction, spasre compare instructions to LLVM compares.
Fix this by casting all pointers to void *, before comparing them.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
sparse-llvm.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/sparse-llvm.c b/sparse-llvm.c
index 3a68d09d9..9a0a76096 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -654,6 +654,10 @@ static void output_op_compare(struct function *fn, struct instruction *insn)
switch (LLVMGetTypeKind(LLVMTypeOf(lhs))) {
case LLVMPointerTypeKind:
+ lhs = value_to_pvalue(fn, &ptr_ctype, lhs);
+ rhs = value_to_pvalue(fn, &ptr_ctype, rhs);
+ /* fall through */
+
case LLVMIntegerTypeKind: {
LLVMIntPredicate op = translate_op(insn->opcode);
--
2.14.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-09-18 9:30 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-18 9:30 [PATCH 0/5] extra fixes for LLVM Luc Van Oostenryck
2017-09-18 9:30 ` [PATCH 1/5] llvm: warn instead of assert on global inits Luc Van Oostenryck
2017-09-18 9:30 ` [PATCH 2/5] llvm: gracefully catch impossible type/value Luc Van Oostenryck
2017-09-18 9:30 ` [PATCH 3/5] llvm: add support for float initializer Luc Van Oostenryck
2017-09-18 9:30 ` [PATCH 4/5] llvm: give names easier to debug Luc Van Oostenryck
2017-09-18 9:30 ` [PATCH 5/5] llvm: only compare void pointers Luc Van Oostenryck
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).