Hi! First of all, sorry for the delay. This about fixing the issue with having a the BB ending with a non-terminating instruction when compiling with segmented stacks. I'm not sure if having an isel pseudo instruction which is lowered into a RET and then a MOV would work better. LLVMTargetMachine::addCommonCodeGenPasses adds the ExpandISelPseudosPass before the PEI pass (so it boils down to the same thing, I think -- the verifier will still complain). This is, of course, assuming I understood Duncan correctly. The only fix I can think of is splitting the thing into two separate basic blocks. I already have sent Duncan patches which does this. Of course, then I'll have a BB that ends with a RET, but has successors. As it was pointed out, this may not be desirable. Is there some third way, better way? I think the best solution would involve delaying the addition of this extra bit of code till the very last moment. How about adding something to X86TargetMachine::addPreEmitPass? Will that work? Thanks! -- Sanjoy Das http://playingwithpointers.com
On Oct 18, 2011, at 2:02 PM, Sanjoy Das wrote:> This about fixing the issue with having a the BB ending with a > non-terminating instruction when compiling with segmented stacks. I'm > not sure if having an isel pseudo instruction which is lowered into a > RET and then a MOV would work better. > LLVMTargetMachine::addCommonCodeGenPasses adds the > ExpandISelPseudosPass before the PEI pass (so it boils down to the > same thing, I think -- the verifier will still complain). This is, of > course, assuming I understood Duncan correctly. > > The only fix I can think of is splitting the thing into two separate > basic blocks. I already have sent Duncan patches which does this. Of > course, then I'll have a BB that ends with a RET, but has successors. > As it was pointed out, this may not be desirable. > > Is there some third way, better way? I think the best solution would > involve delaying the addition of this extra bit of code till the very > last moment. How about adding something to > X86TargetMachine::addPreEmitPass? Will that work?If I understand correctly, you need to insert: call _morestack ret in the middle of a basic block. There are two problems: 1. RET is a terminator, and can only appear at the end of a basic block. 2. The CALL and RET instructions must be adjacent. The best way to handle this is to create a pseudo-instruction representing the call+ret pair. Since the two instructions must stay together, it should be expanded late: In lib/Target/X86/X86MCInstLower.cpp. /jakob
> it should be expanded late: In lib/Target/X86/X86MCInstLower.cpp.This is exactly what I was missing. Thanks a ton! :) -- Sanjoy Das http://playingwithpointers.com
> The best way to handle this is to create a pseudo-instruction representing the call+ret pair.There is already and example of somehow similar pseudo. One should look for "eh_return". -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University