llvmpipe: Disassemble generated x86 code.

This commit is contained in:
José Fonseca 2009-08-16 11:50:17 +01:00
parent a7f9b915ae
commit 818d444e12
9 changed files with 145 additions and 2 deletions

View File

@ -6,11 +6,19 @@ Requirements
- Linux
- udis86, http://udis86.sourceforge.net/
git clone git://udis86.git.sourceforge.net/gitroot/udis86
cd udis86
./configure --with-pic
make
sudo make install
- LLVM. On Debian based distributions do:
aptitude install llvm-dev
There is a type in one of the llvm-dev 2.5 headers, that causes compilation
There is a typo in one of the llvm-dev 2.5 headers, that causes compilation
errors in the debug build:
--- /usr/include/llvm-c/Core.h.orig 2009-08-10 15:38:54.000000000 +0100

View File

@ -12,6 +12,7 @@ llvmpipe = env.ConvenienceLibrary(
'lp_bld_blend_soa.c',
'lp_bld_const.c',
'lp_bld_conv.c',
'lp_bld_debug.c',
'lp_bld_intr.c',
'lp_bld_pack.c',
'lp_bld_unpack.c',
@ -55,6 +56,7 @@ llvmpipe = env.ConvenienceLibrary(
env = env.Clone()
env.Prepend(LIBS = 'udis86')
env['LINK'] = env['CXX']
env.ParseConfig('llvm-config --libs jit interpreter nativecodegen bitwriter')
env.Prepend(LIBS = [llvmpipe] + auxiliaries)

View File

@ -0,0 +1,70 @@
/**************************************************************************
*
* Copyright 2009 VMware, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#include <udis86.h>
#include "util/u_debug.h"
#include "lp_bld_debug.h"
void
lp_disassemble(const void* func)
{
ud_t ud_obj;
ud_init(&ud_obj);
ud_set_input_buffer(&ud_obj, (void*)func, 0xffff);
ud_set_pc(&ud_obj, (uint64_t) (uintptr_t) func);
#ifdef PIPE_ARCH_X86
ud_set_mode(&ud_obj, 32);
#endif
#ifdef PIPE_ARCH_X86_64
ud_set_mode(&ud_obj, 64);
#endif
ud_set_syntax(&ud_obj, UD_SYN_ATT);
while (ud_disassemble(&ud_obj)) {
#ifdef PIPE_ARCH_X86
debug_printf("%08lx:\t%s\n",
(unsigned long)ud_insn_off(&ud_obj),
ud_insn_asm(&ud_obj));
#endif
#ifdef PIPE_ARCH_X86_64
debug_printf("%016llx:\t%s\n",
(unsigned long long)ud_insn_off(&ud_obj),
ud_insn_asm(&ud_obj));
#endif
if (ud_obj.mnemonic == UD_Iret)
break;
}
debug_printf("\n");
}

View File

@ -0,0 +1,37 @@
/**************************************************************************
*
* Copyright 2009 VMware, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#ifndef LP_BLD_DEBUG_H
#define LP_BLD_DEBUG_H
void
lp_disassemble(const void* func);
#endif /* !LP_BLD_DEBUG_H */

View File

@ -41,6 +41,7 @@
#include "lp_bld_type.h"
#include "lp_bld_arit.h"
#include "lp_bld_blend.h"
#include "lp_bld_debug.h"
static void
@ -127,7 +128,7 @@ llvmpipe_create_blend_state(struct pipe_context *pipe,
LLVMRunFunctionPassManager(screen->pass, blend->function);
#if 1
#ifdef DEBUG
debug_printf("%s=%s %s=%s %s=%s %s=%s %s=%s %s=%s\n",
"rgb_func", debug_dump_blend_func (blend->base.rgb_func, TRUE),
"rgb_src_factor", debug_dump_blend_factor(blend->base.rgb_src_factor, TRUE),
@ -146,6 +147,10 @@ llvmpipe_create_blend_state(struct pipe_context *pipe,
blend->jit_function = (lp_blend_func)LLVMGetPointerToGlobal(screen->engine, blend->function);
#ifdef DEBUG
lp_disassemble(blend->jit_function);
#endif
return blend;
}

View File

@ -36,6 +36,7 @@
#include "tgsi/tgsi_parse.h"
#include "lp_bld_type.h"
#include "lp_bld_tgsi.h"
#include "lp_bld_debug.h"
#include "lp_screen.h"
#include "lp_context.h"
#include "lp_state.h"
@ -188,6 +189,10 @@ llvmpipe_create_fs_state(struct pipe_context *pipe,
shader->jit_function = (lp_shader_fs_func)LLVMGetPointerToGlobal(screen->engine, shader->function);
#ifdef DEBUG
lp_disassemble(shader->jit_function);
#endif
return shader;
}

View File

@ -40,6 +40,7 @@
#include "lp_bld_type.h"
#include "lp_bld_arit.h"
#include "lp_bld_blend.h"
#include "lp_bld_debug.h"
#include "lp_test.h"
@ -526,6 +527,9 @@ test_one(unsigned verbose,
blend_test_ptr = (blend_test_ptr_t)LLVMGetPointerToGlobal(engine, func);
if(verbose >= 2)
lp_disassemble(blend_test_ptr);
success = TRUE;
for(i = 0; i < n && success; ++i) {
if(mode == AoS) {

View File

@ -36,6 +36,7 @@
#include "lp_bld_type.h"
#include "lp_bld_conv.h"
#include "lp_bld_debug.h"
#include "lp_test.h"
@ -217,6 +218,9 @@ test_one(unsigned verbose,
conv_test_ptr = (conv_test_ptr_t)LLVMGetPointerToGlobal(engine, func);
if(verbose >= 2)
lp_disassemble(conv_test_ptr);
success = TRUE;
for(i = 0; i < n && success; ++i) {
unsigned src_stride = src_type.length*src_type.width/8;

View File

@ -29,6 +29,14 @@ if env['platform'] == 'linux' \
sources += ['xlib_softpipe.c']
drivers += [softpipe]
if 'llvmpipe' in env['drivers']:
env.Append(CPPDEFINES = 'GALLIUM_LLVMPIPE')
env.Prepend(LIBS = 'udis86')
env.ParseConfig('llvm-config --libs jit interpreter nativecodegen')
env['LINK'] = env['CXX']
sources += ['xlib_llvmpipe.c']
drivers += [llvmpipe]
if 'i965simple' in env['drivers']:
env.Append(CPPDEFINES = 'GALLIUM_I965SIMPLE')
sources += [