On Dec 15, 2009, at 5:08 PM, David Greene wrote:> On Tuesday 15 December 2009 18:01, Jim Grosbach wrote: > >> For a usage example, I've included in the patch the modification to >> use the constraint for the STREX ARM instruction. > > Your example is: > > constraints = "@early $success" > > Why not spell it as: > > constraints = "$success != $src", "$success != $ptr" >This was my first thought as well; however, I decided against it. I think it's best, at least for now, to expose an interface in tablegen to express the early-clobber semantics that the back-end already supports rather than adding something completely new. Doing more would require significantly surgery on both tablegen and the register allocation framework to support. The handling of early- clobber register definitions is already in place in the allocator, and this approach simply provides a means of specifying it in the tablegen files. I think that's likely something we'd want separately from a more general purpose solution in any case, as it's analogous to the inline assembler '&' constraint, for example. Do you have specific examples in mind that would be expressible with something more complicated that aren't handleable via an early-clobber constraint?> The grammar would change to something like: > > constraint: operand '!=' operand > | operand '=' operand > > This seems more intuitive and more generally applicable. I could > see a use > for this in other architectures. From reading your example, without > the > background I wouldn't know what "@early" means.Perhaps spelling it out more fully with "earlyclobber" rather than "early" would help? Thanks for the feedback! -Jim -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091215/b5ad25f8/attachment.html>
On Tuesday 15 December 2009 19:52, Jim Grosbach wrote:> Do you have specific examples in mind that would be expressible with > something more complicated that aren't handleable via an early-clobber > constraint?Not offhand, no. I'm mostly concerned about the readability of .td files.> Perhaps spelling it out more fully with "earlyclobber" rather than > "early" would help?That's better. Is there any way you could convince TableGen to recognize that 'constraints = "$success != $src", "$success != $ptr"' is semantically equivalent to earlyclobber? Maybe check that the common operand in both contraints is declared to interfere with all other operands and if that's so, mark it earlyclobber. When I'm writing .td files I really don't want to be concerned with the nitty-gritty details of how the backend is implemented. I just want to express the semantics I want. I think that was the motivation for the switch from isThreeAddress to "$src = $dst." I have no objection going with "earlyclobber" initially but we should think about ways to abstract codegen semantics whenever we can. If we can replace "earlyclobber" with something clearer later on, all the better. "earlycloibber" is a really bad name, though. Perhaps spell it "uniquereg" or something else that gets at what it actually means? It seems to me the root problem here is that the instruction has two outputs and we don't want the output to be allocated to the same register as the inputs. We have no way to express multiple outputs in TableGen. As it happens, AVX has similar problems with its semantics for VSQRTSS/SD. In fact the semantics there are even worse, to the point where I'm not going to think any more about it. :) -Dave
On Dec 15, 2009, at 6:26 PM, David Greene wrote:> On Tuesday 15 December 2009 19:52, Jim Grosbach wrote: > >> Do you have specific examples in mind that would be expressible with >> something more complicated that aren't handleable via an early- >> clobber >> constraint? > > Not offhand, no. I'm mostly concerned about the readability of .td > files. > >> Perhaps spelling it out more fully with "earlyclobber" rather than >> "early" would help? > > That's better. Is there any way you could convince TableGen to > recognize > that 'constraints = "$success != $src", "$success != $ptr"' is > semantically > equivalent to earlyclobber? Maybe check that the common operand in > both > contraints is declared to interfere with all other operands and if > that's > so, mark it earlyclobber.It would be possible, yes. I'm concerned that would imply that one could specify a constraint that the output register couldn't overlap with one input register, but could with another, which isn't expressible. Thus my preference for specifying the constraint solely as an attribute of the output register rather than referencing the other operands explicitly.> When I'm writing .td files I really don't want to be concerned with > the > nitty-gritty details of how the backend is implemented. I just want > to > express the semantics I want. I think that was the motivation for the > switch from isThreeAddress to "$src = $dst."I agree. We're definitely on the same page about what the goals are.> I have no objection going with "earlyclobber" initially but we > should think > about ways to abstract codegen semantics whenever we can. If we can > replace > "earlyclobber" with something clearer later on, all the better. > "earlycloibber" is a really bad name, though. Perhaps spell it > "uniquereg" > or something else that gets at what it actually means?I'm not hugely tied to the name. I chose it because it matches the usage in GCC documentation for inline assembly with the same concepts and how the concept is expressed elsewhere in the compiler. If I'm not mistaken, due to the GCC nomenclature, the linux kernel also refers to this sort of thing as an early-clobber.> It seems to me the root problem here is that the instruction has two > outputs > and we don't want the output to be allocated to the same register as > the > inputs. We have no way to express multiple outputs in TableGen.Close, but not precisely. The issue is that the values in the input registers may still be needed in the hardware at the instruction stage where the output register needs to be written, or some other such timing issue that if the registers are the same the hardware can't guarantee proper access ordering for correct behavior. From LLVM's perspective, the instruction has only one output (the success value), and also has a side-effect (the store to memory). Another example of this issue is the ARM integer multiply instruction (MUL) on pre-v6 architectures, where if the destination register and the first source register are the same, the behaviour is undefined. The name is trying to capture the idea that the hardware may clobber the value in the destination register early enough in the execution of the instruction that it could conflict with reading the value from the source register if they are the same. I think you're right that it's best to go ahead with this for now and then if a better solution is arrived at later, we can update things to use that. Regards, -Jim