[Mesa-dev] [PATCH 2/2] radeon/llvm: Use amdgcn triple for SI+ on LLVM >= 3.6

Tom Stellard thomas.stellard at amd.com
Tue Dec 23 09:49:12 PST 2014


---
 src/gallium/drivers/radeon/r600_pipe_common.c | 11 +++++++++--
 src/gallium/drivers/radeon/radeon_llvm_emit.c | 21 ++++++++++-----------
 src/gallium/drivers/radeon/radeon_llvm_emit.h |  2 +-
 src/gallium/drivers/radeonsi/si_pipe.c        |  9 +++++++--
 4 files changed, 27 insertions(+), 16 deletions(-)

diff --git a/src/gallium/drivers/radeon/r600_pipe_common.c b/src/gallium/drivers/radeon/r600_pipe_common.c
index cb17e54..37d8d89 100644
--- a/src/gallium/drivers/radeon/r600_pipe_common.c
+++ b/src/gallium/drivers/radeon/r600_pipe_common.c
@@ -499,6 +499,12 @@ static int r600_get_compute_param(struct pipe_screen *screen,
 	switch (param) {
 	case PIPE_COMPUTE_CAP_IR_TARGET: {
 		const char *gpu;
+		const char *triple;
+		if (rscreen->family <= CHIP_ARUBA || HAVE_LLVM < 0x0306) {
+			triple = "r600--";
+		} else {
+			triple = "amdgcn--";
+		}
 		switch(rscreen->family) {
 		/* Clang < 3.6 is missing Hainan in its list of
 		 * GPUs, so we need to use the name of a similar GPU.
@@ -513,9 +519,10 @@ static int r600_get_compute_param(struct pipe_screen *screen,
 			break;
 		}
 		if (ret) {
-			sprintf(ret, "%s-r600--", gpu);
+			sprintf(ret, "%s-%s", gpu, triple);
+
 		}
-		return (8 + strlen(gpu)) * sizeof(char);
+		return (strlen(triple) + strlen(gpu)) * sizeof(char);
 	}
 	case PIPE_COMPUTE_CAP_GRID_DIMENSION:
 		if (ret) {
diff --git a/src/gallium/drivers/radeon/radeon_llvm_emit.c b/src/gallium/drivers/radeon/radeon_llvm_emit.c
index 4f288e4..b98afb2 100644
--- a/src/gallium/drivers/radeon/radeon_llvm_emit.c
+++ b/src/gallium/drivers/radeon/radeon_llvm_emit.c
@@ -98,20 +98,19 @@ static void init_r600_target()
 	}
 }
 
-LLVMTargetRef radeon_llvm_get_r600_target()
+LLVMTargetRef radeon_llvm_get_r600_target(const char *triple)
 {
 	LLVMTargetRef target = NULL;
+	char *err_message = NULL;
+
 	init_r600_target();
 
-	for (target = LLVMGetFirstTarget(); target;
-					target = LLVMGetNextTarget(target)) {
-		if (!strncmp(LLVMGetTargetName(target), "r600", 4)) {
-			break;
+	if (LLVMGetTargetFromTriple(triple, &target, &err_message)) {
+		fprintf(stderr, "Cannot find target for triple %s ", triple);
+		if (err_message) {
+			fprintf(stderr, "%s\n", err_message);
 		}
-	}
-
-	if (!target) {
-		fprintf(stderr, "Can't find target r600\n");
+		LLVMDisposeMessage(err_message);
 		return NULL;
 	}
 	return target;
@@ -155,7 +154,8 @@ unsigned radeon_llvm_compile(LLVMModuleRef M, struct radeon_shader_binary *binar
 	LLVMBool mem_err;
 
 	if (!tm) {
-		LLVMTargetRef target = radeon_llvm_get_r600_target();
+		strncpy(triple, "r600--", TRIPLE_STRING_LEN);
+		LLVMTargetRef target = radeon_llvm_get_r600_target(triple);
 		if (!target) {
 			return 1;
 		}
@@ -165,7 +165,6 @@ unsigned radeon_llvm_compile(LLVMModuleRef M, struct radeon_shader_binary *binar
 			LLVMDumpModule(M);
 			strncpy(fs, "+DumpCode", FS_STRING_LEN);
 		}
-		strncpy(triple, "r600--", TRIPLE_STRING_LEN);
 		tm = LLVMCreateTargetMachine(target, triple, cpu, fs,
 				  LLVMCodeGenLevelDefault, LLVMRelocDefault,
 						  LLVMCodeModelDefault);
diff --git a/src/gallium/drivers/radeon/radeon_llvm_emit.h b/src/gallium/drivers/radeon/radeon_llvm_emit.h
index 66217b5..3ccef78 100644
--- a/src/gallium/drivers/radeon/radeon_llvm_emit.h
+++ b/src/gallium/drivers/radeon/radeon_llvm_emit.h
@@ -34,7 +34,7 @@ struct radeon_shader_binary;
 
 void radeon_llvm_shader_type(LLVMValueRef F, unsigned type);
 
-LLVMTargetRef radeon_llvm_get_r600_target(void);
+LLVMTargetRef radeon_llvm_get_r600_target(const char *triple);
 
 unsigned  radeon_llvm_compile(
 	LLVMModuleRef M,
diff --git a/src/gallium/drivers/radeonsi/si_pipe.c b/src/gallium/drivers/radeonsi/si_pipe.c
index b3d1fb0..9daf282 100644
--- a/src/gallium/drivers/radeonsi/si_pipe.c
+++ b/src/gallium/drivers/radeonsi/si_pipe.c
@@ -483,6 +483,11 @@ struct pipe_screen *radeonsi_screen_create(struct radeon_winsys *ws)
 {
 	struct si_screen *sscreen = CALLOC_STRUCT(si_screen);
 	LLVMTargetRef r600_target;
+#if HAVE_LLVM >= 0x0306
+	const char *triple = "amdgcn--";
+#else
+	const char *triple = "r600--";
+#endif
 	if (sscreen == NULL) {
 		return NULL;
 	}
@@ -511,8 +516,8 @@ struct pipe_screen *radeonsi_screen_create(struct radeon_winsys *ws)
 	sscreen->b.aux_context = sscreen->b.b.context_create(&sscreen->b.b, NULL);
 
 	/* Initialize LLVM TargetMachine */
-	r600_target = radeon_llvm_get_r600_target();
-	sscreen->tm = LLVMCreateTargetMachine(r600_target, "r600--",
+	r600_target = radeon_llvm_get_r600_target(triple);
+	sscreen->tm = LLVMCreateTargetMachine(r600_target, triple,
 				r600_get_llvm_processor_name(sscreen->b.family),
 				"+DumpCode", LLVMCodeGenLevelDefault, LLVMRelocDefault,
 				LLVMCodeModelDefault);
-- 
1.8.5.5



More information about the mesa-dev mailing list