linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Christopher Li <sparse@chrisli.org>,
	Dibyendu Majumdar <mobile@majumdar.org.uk>,
	Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH v3 14/30] llvm: extract get_sym_value() from pseudo_to_value()
Date: Sun, 19 Mar 2017 02:42:11 +0100	[thread overview]
Message-ID: <20170319014227.8833-15-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20170319014227.8833-1-luc.vanoostenryck@gmail.com>

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

diff --git a/sparse-llvm.c b/sparse-llvm.c
index 072cf2638..d7e8ee725 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -305,6 +305,57 @@ static void pseudo_name(pseudo_t pseudo, char *buf)
 	}
 }
 
+static LLVMValueRef get_sym_value(struct function *fn, struct symbol *sym)
+{
+	LLVMValueRef result = NULL;
+	struct expression *expr;
+
+	assert(sym->bb_target == NULL);
+
+	expr = sym->initializer;
+	if (expr) {
+		switch (expr->type) {
+		case EXPR_STRING: {
+			const char *s = expr->string->data;
+			LLVMValueRef indices[] = { LLVMConstInt(LLVMInt64Type(), 0, 0), LLVMConstInt(LLVMInt64Type(), 0, 0) };
+			LLVMValueRef data;
+
+			data = LLVMAddGlobal(fn->module, LLVMArrayType(LLVMInt8Type(), strlen(s) + 1), ".str");
+			LLVMSetLinkage(data, LLVMPrivateLinkage);
+			LLVMSetGlobalConstant(data, 1);
+			LLVMSetInitializer(data, LLVMConstString(strdup(s), strlen(s) + 1, true));
+
+			result = LLVMConstGEP(data, indices, ARRAY_SIZE(indices));
+			break;
+		}
+		case EXPR_SYMBOL: {
+			struct symbol *sym = expr->symbol;
+
+			result = LLVMGetNamedGlobal(fn->module, show_ident(sym->ident));
+			assert(result != NULL);
+			break;
+		}
+		default:
+			assert(0);
+		}
+	} else {
+		const char *name = show_ident(sym->ident);
+		LLVMTypeRef type = symbol_type(sym);
+
+		if (LLVMGetTypeKind(type) == LLVMFunctionTypeKind) {
+			result = LLVMGetNamedFunction(fn->module, name);
+			if (!result)
+				result = LLVMAddFunction(fn->module, name, type);
+		} else {
+			result = LLVMGetNamedGlobal(fn->module, name);
+			if (!result)
+				result = LLVMAddGlobal(fn->module, type, name);
+		}
+	}
+
+	return result;
+}
+
 static LLVMValueRef pseudo_to_value(struct function *fn, struct instruction *insn, pseudo_t pseudo)
 {
 	LLVMValueRef result = NULL;
@@ -313,54 +364,9 @@ static LLVMValueRef pseudo_to_value(struct function *fn, struct instruction *ins
 	case PSEUDO_REG:
 		result = pseudo->priv;
 		break;
-	case PSEUDO_SYM: {
-		struct symbol *sym = pseudo->sym;
-		struct expression *expr;
-
-		assert(sym->bb_target == NULL);
-
-		expr = sym->initializer;
-		if (expr) {
-			switch (expr->type) {
-			case EXPR_STRING: {
-				const char *s = expr->string->data;
-				LLVMValueRef indices[] = { LLVMConstInt(LLVMInt64Type(), 0, 0), LLVMConstInt(LLVMInt64Type(), 0, 0) };
-				LLVMValueRef data;
-
-				data = LLVMAddGlobal(fn->module, LLVMArrayType(LLVMInt8Type(), strlen(s) + 1), ".str");
-				LLVMSetLinkage(data, LLVMPrivateLinkage);
-				LLVMSetGlobalConstant(data, 1);
-				LLVMSetInitializer(data, LLVMConstString(strdup(s), strlen(s) + 1, true));
-
-				result = LLVMConstGEP(data, indices, ARRAY_SIZE(indices));
-				break;
-			}
-			case EXPR_SYMBOL: {
-				struct symbol *sym = expr->symbol;
-
-				result = LLVMGetNamedGlobal(fn->module, show_ident(sym->ident));
-				assert(result != NULL);
-				break;
-			}
-			default:
-				assert(0);
-			}
-		} else {
-			const char *name = show_ident(sym->ident);
-			LLVMTypeRef type = symbol_type(sym);

  parent reply	other threads:[~2017-03-19  1:42 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-19  1:41 [PATCH 00/30] LLVM fixes Luc Van Oostenryck
2017-03-19  1:41 ` [PATCH v3 01/30] fix usage of inlined calls Luc Van Oostenryck
2017-03-19  1:41 ` [PATCH v3 02/30] inlined calls should not block BB packing Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 03/30] give function's arguments a type via OP_PUSH Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 04/30] give a type to OP_PHISOURCE Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 05/30] give a type to OP_SEL, always Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 06/30] llvm: remove unneeded arg 'module' Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 07/30] llvm: remove unneeded 'generation' Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 08/30] llvm: remove unneeded function::type Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 09/30] llvm: reduce scope of 'bb_nr' Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 10/30] llvm: use pseudo_list_size() instead of open coding it Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 11/30] llvm: give arguments a name Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 12/30] llvm: give a name to call's return values Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 13/30] llvm: avoid useless temp variable Luc Van Oostenryck
2017-03-19  1:42 ` Luc Van Oostenryck [this message]
2017-03-19  1:42 ` [PATCH v3 15/30] llvm: fix test of floating-point type Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 16/30] llvm: fix translation of PSEUDO_VALs into a ValueRefs Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 17/30] llvm: fix output_op_store() which modify its operand Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 18/30] llvm: fix output_op_[ptr]cast() Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 19/30] llvm: take care of degenerated rvalues Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 20/30] llvm: add test cases for symbol's address Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 21/30] llvm: add test cases for pointers passed as argument Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 22/30] llvm: add test cases for arrays " Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 23/30] llvm: add test cases for degenerated pointers Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 24/30] llvm: add support for OP_NEG Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 25/30] llvm: fix pointer/float mixup in comparisons Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 26/30] llvm: fix type in comparison with an address constant Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 27/30] llvm: give correct type to binops Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 28/30] llvm: adjust OP_RET's type Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 29/30] llvm: variadic functions are not being marked as such Luc Van Oostenryck
2017-03-19  1:42 ` [PATCH v3 30/30] llvm: fix type of switch constants Luc Van Oostenryck
2017-03-19 16:09 ` [PATCH 00/30] LLVM fixes Dibyendu Majumdar
2017-03-19 18:41   ` Dibyendu Majumdar
2017-03-19 16:28 ` Christopher Li
2017-03-19 16:51   ` Luc Van Oostenryck
2017-03-19 21:02     ` Luc Van Oostenryck

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=20170319014227.8833-15-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=mobile@majumdar.org.uk \
    --cc=sparse@chrisli.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).