2 * Copyright 2014 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
15 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18 * USE OR OTHER DEALINGS IN THE SOFTWARE.
20 * The above copyright notice and this permission notice (including the
21 * next paragraph) shall be included in all copies or substantial portions
25 /* based on pieces from si_pipe.c and radeon_llvm_emit.c */
26 #include "ac_llvm_util.h"
28 #include <llvm-c/Core.h>
30 #include "c11/threads.h"
35 static void ac_init_llvm_target()
37 #if HAVE_LLVM < 0x0307
38 LLVMInitializeR600TargetInfo();
39 LLVMInitializeR600Target();
40 LLVMInitializeR600TargetMC();
41 LLVMInitializeR600AsmPrinter();
43 LLVMInitializeAMDGPUTargetInfo();
44 LLVMInitializeAMDGPUTarget();
45 LLVMInitializeAMDGPUTargetMC();
46 LLVMInitializeAMDGPUAsmPrinter();
50 static once_flag ac_init_llvm_target_once_flag
= ONCE_FLAG_INIT
;
52 static LLVMTargetRef
ac_get_llvm_target(const char *triple
)
54 LLVMTargetRef target
= NULL
;
55 char *err_message
= NULL
;
57 call_once(&ac_init_llvm_target_once_flag
, ac_init_llvm_target
);
59 if (LLVMGetTargetFromTriple(triple
, &target
, &err_message
)) {
60 fprintf(stderr
, "Cannot find target for triple %s ", triple
);
62 fprintf(stderr
, "%s\n", err_message
);
64 LLVMDisposeMessage(err_message
);
70 static const char *ac_get_llvm_processor_name(enum radeon_family family
)
99 #if HAVE_LLVM <= 0x0307
110 #if HAVE_LLVM <= 0x0308
126 LLVMTargetMachineRef
ac_create_target_machine(enum radeon_family family
)
128 assert(family
>= CHIP_TAHITI
);
130 const char *triple
= "amdgcn--";
131 LLVMTargetRef target
= ac_get_llvm_target(triple
);
132 LLVMTargetMachineRef tm
= LLVMCreateTargetMachine(
135 ac_get_llvm_processor_name(family
),
136 "+DumpCode,+vgpr-spilling",
137 LLVMCodeGenLevelDefault
,
139 LLVMCodeModelDefault
);