All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] llvm: improve default/zero initialization
@ 2017-12-28 22:30 Luc Van Oostenryck
  2017-12-28 22:30 ` [PATCH 1/2] llvm: simplify emit of null pointers Luc Van Oostenryck
  2017-12-28 22:30 ` [PATCH 2/2] llvm: default init of arrays & structs Luc Van Oostenryck
  0 siblings, 2 replies; 3+ messages in thread
From: Luc Van Oostenryck @ 2017-12-28 22:30 UTC (permalink / raw)
  To: linux-sparse; +Cc: Dibyendu Majumdar, Luc Van Oostenryck

This series contains:
- a fix for the default initialization of arrays and structures
- a small simplification for the initialization of null-pointers

This series is available in the Git repository at:
  git://github.com/lucvoo/sparse-dev.git llvm-zero-init

Luc Van Oostenryck (2):
  llvm: simplify emit of null pointers
  llvm: default init of arrays & structs

 sparse-llvm.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

-- 
2.15.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] llvm: simplify emit of null pointers
  2017-12-28 22:30 [PATCH 0/2] llvm: improve default/zero initialization Luc Van Oostenryck
@ 2017-12-28 22:30 ` Luc Van Oostenryck
  2017-12-28 22:30 ` [PATCH 2/2] llvm: default init of arrays & structs Luc Van Oostenryck
  1 sibling, 0 replies; 3+ messages in thread
From: Luc Van Oostenryck @ 2017-12-28 22:30 UTC (permalink / raw)
  To: linux-sparse; +Cc: Dibyendu Majumdar, Luc Van Oostenryck

Most pointers with a constant value are simply null-pointers.
The only exception is when a known address is casted to pointer.

The current code only handle code for the general case:
emit code for a constant integer and then cast this to a pointer.
This obfuscate a bit the ouput, making it hard to read.

Change this by special handling the normal case of null-pointers
by directly using LLVM's LLVMConstPointerNull().

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 sparse-llvm.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/sparse-llvm.c b/sparse-llvm.c
index a8186df5b..4c64f1aaa 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -340,14 +340,16 @@ static LLVMValueRef get_sym_value(struct function *fn, struct symbol *sym)
 
 static LLVMValueRef constant_value(unsigned long long val, LLVMTypeRef dtype)
 {
-	LLVMTypeRef itype;
 	LLVMValueRef result;
 
 	switch (LLVMGetTypeKind(dtype)) {
 	case LLVMPointerTypeKind:
-		itype = LLVMIntType(bits_in_pointer);
-		result = LLVMConstInt(itype, val, 1);
-		result = LLVMConstIntToPtr(result, dtype);
+		if (val != 0) {	 // for example: ... = (void*) 0x123;
+			LLVMTypeRef itype = LLVMIntType(bits_in_pointer);
+			result = LLVMConstInt(itype, val, 1);
+			result = LLVMConstIntToPtr(result, dtype);
+		}
+		result = LLVMConstPointerNull(dtype);
 		break;
 	case LLVMIntegerTypeKind:
 		result = LLVMConstInt(dtype, val, 1);
-- 
2.15.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] llvm: default init of arrays & structs
  2017-12-28 22:30 [PATCH 0/2] llvm: improve default/zero initialization Luc Van Oostenryck
  2017-12-28 22:30 ` [PATCH 1/2] llvm: simplify emit of null pointers Luc Van Oostenryck
@ 2017-12-28 22:30 ` Luc Van Oostenryck
  1 sibling, 0 replies; 3+ messages in thread
From: Luc Van Oostenryck @ 2017-12-28 22:30 UTC (permalink / raw)
  To: linux-sparse; +Cc: Dibyendu Majumdar, Luc Van Oostenryck

Linearization of arrays & structs default initialization is done
as if these objects would be an integer as large as the object.
This integer is then simply zero-initialized.
(This may be objectionable and will be done differently).

However, sparse-llvm is not ready to handle this situation where
a non-scalar is initialized with a scalar value.

Workaround this by using LLVMConstNull() when possible.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 sparse-llvm.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/sparse-llvm.c b/sparse-llvm.c
index 4c64f1aaa..a1a48fd0f 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -354,6 +354,12 @@ static LLVMValueRef constant_value(unsigned long long val, LLVMTypeRef dtype)
 	case LLVMIntegerTypeKind:
 		result = LLVMConstInt(dtype, val, 1);
 		break;
+	case LLVMArrayTypeKind:
+	case LLVMStructTypeKind:
+		if (val != 0)
+			return NULL;
+		result = LLVMConstNull(dtype);
+		break;
 	default:
 		return NULL;
 	}
-- 
2.15.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-12-28 22:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-28 22:30 [PATCH 0/2] llvm: improve default/zero initialization Luc Van Oostenryck
2017-12-28 22:30 ` [PATCH 1/2] llvm: simplify emit of null pointers Luc Van Oostenryck
2017-12-28 22:30 ` [PATCH 2/2] llvm: default init of arrays & structs Luc Van Oostenryck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.