[Mesa-dev] [PATCH 2/2] radeonsi: Allow dumping LLVM IR before optimization passes

Michel Dänzer michel at daenzer.net
Fri Feb 5 01:24:56 UTC 2016


On 05.02.2016 03:52, Tom Stellard wrote:
> On Thu, Feb 04, 2016 at 09:15:26AM +0100, Nicolai Hähnle wrote:
>> From: Nicolai Hähnle <nicolai.haehnle at amd.com>
>>
>> Set R600_DEBUG=preoptir to dump the LLVM IR before optimization passes,
>> to allow diagnosing problems caused by optimization passes.
>>
>> Note that in order to compile the resulting IR with llc, you will first
>> have to run at least the mem2reg pass, e.g.
>>
>> opt -mem2reg -S < shader.ll | llc -march=amdgcn -mcpu=bonaire
>>
>> Signed-off-by: Michel Dänzer <michel.daenzer at amd.com> (original patch)
>> Signed-off-by: Nicolai Hähnle <nicolai.haehnle at amd.com> (w/ debug flag)
>> ---
>> Having the option is a good idea, but I prefer to have a separate debug
>> flag for it so that when you try to analyze bugs in codegen (which in
>> my experience happens more often) you don't have to worry about
>> replicating the exact same sequence of optimizations manually via the
>> command line to reproduce the problem there.

[...]

>> @@ -4385,9 +4391,15 @@ int si_shader_create(struct si_screen *sscreen, LLVMTargetMachineRef tm,
>>  	}
>>  
>>  	LLVMBuildRetVoid(bld_base->base.gallivm->builder);
>> +	mod = bld_base->base.gallivm->module;
>> +
>> +	/* Dump LLVM IR before any optimization passes */
>> +	if (sscreen->b.debug_flags & DBG_PREOPT_IR &&
>> +	    r600_can_dump_shader(&sscreen->b, si_shader_ctx.type))
>> +		LLVMDumpModule(mod);
>> +
> 
> Is there any reason not to add the dump in  radeon_llvm_finalize_module()
> after PromoteMem2Reg has run?  This would make the output readable by llc
> and then you would only need to add the dump call in one place.

FWIW, Mem2Reg doesn't seem to be the only pass necessary for llc. E.g.
on https://secure.freedesktop.org/~daenzer/The-Spirit.txt it was choking
on one of the control flow lines with a label and comment for me.


-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer


More information about the mesa-dev mailing list