This patch changes ARMSubtarget::restrictIT to use the function attribute "arm-restrict-it" to decide whether ARMv7 or v8 style IT blocks should be generated.
IThe corresponding clang patch is here: http://reviews.llvm.org/D10414
Differential D10416
Use function attribute "arm-restrict-it" ahatanak on Jun 12 2015, 11:52 AM. Authored by
Details
This patch changes ARMSubtarget::restrictIT to use the function attribute "arm-restrict-it" to decide whether ARMv7 or v8 style IT blocks should be generated. IThe corresponding clang patch is here: http://reviews.llvm.org/D10414
Diff Detail Event TimelineComment Actions I'm confused. You removed the back-end option in Clang, but it remains here (IT), meaning you now have two identical command line options that do things slightly different. The function attributes set IT behaviour on every function and the backend option that sets it in a module level. This will create a confusing environment on which to develop things and I don't want to extend this pattern. If the option needs to be on a function basis, than we need to make sure that whatever generates IR does that on a function level, and free the backend from having to ponder about module level options. In summary, IT options must go. :) cheers, Comment Actions Hi Renato, We've always had two options for this sort of thing, just much more Basically the backend developers want to be able to override (largely for I've delayed on reviewing this patch because I'm not quite sure how I want -eric Comment Actions I see. It is hidden, and it has the exact same behaviour (tri-state, isARMv8() on default, implemented in the same function), so I guess it's ok. The chances that people will abuse of this relationship or will change one and not the other is indeed, minimal. cheers,
Comment Actions Since this is intended to be used only by tools such as llc and opt, we can move the IT option to CodeGen/CommandFlags.h and let setFunctionAttributes rewrite the function attribute in the IR. The downside of this is that we'll be moving a target-specific option into a file that is supposed to be target-independent. Comment Actions Add checks in test case to ensure the instructions within the IT blocks are exactly what we expect.
Comment Actions Following the discussion on cfe-commits (http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20150622/thread.html#131397), I've made changes to define a new ARM subtarget feature and use it to determine if IT blocks should be restricted. Previously, ARMSubtarget would check if the target supports armv8 instructions to make this decision. This is no longer needed as that decision is made in the front-end (see the corresponding clang patch: http://reviews.llvm.org/D10414). Comment Actions I think you want to turn on restrict-it here: def HasV8Ops : SubtargetFeature<"v8", "HasV8Ops", "true", "Support ARM v8 instructions", [HasV7Ops, FeatureVirtualization, FeatureMP]>; by default yes? -eric Comment Actions Are you suggesting adding FeatureRestrictedIT to the implied feature list of HasV8Ops? I thought about doing so but found out it would make it impossible to disable restrict-it when we target v8. Try compiling the following IR with -mattr=-restrict-it after adding FeatureRestrictedIT to the implied feature list: $ cat f1.ll define void @test_inlineasm() { tail call void asm sideeffect "hlt #64", ""() ret void } $ llc f1.ll -o - -mattr=-restrict-it hlt #64 ^ LLVM ERROR: Error parsing inline asm This fails because disabling restrict-it transitively disables HasV8Ops too (see function ClearImpliedBits in SubtargetFeature.cpp). If I compile the IR with trunk's llc with command line option -arm-no-restrict-it, it compiles without any errors. $ llc f1.ll -o - -arm-no-restrict-it Do we need the capability to turn off disable restrict-it when targeting armv8? I was assuming we do need it although I wasn't sure why users would want to do that. Comment Actions Fascinating.
Right.
I don't know. I wouldn't think so tbh which is why I just suggested putting it as a feature on the subarchitecture. Jim? -eric Comment Actions r194592's commit log seems to suggest that both options were added to make llvm compatible with gcc. http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20131111/194792.html I guess we shouldn't disallow users to use "-mno-restrict-it" for ARMv8 even if it doesn't make much sense? Comment Actions That was my thought. Let's have Jim weigh in because I like throwing him under this bus :) -eric Comment Actions For the backend attribute, having -arm-restrict-it (or equivalent) transitively disable HasV8Ops is really, really bad. Those should be completely independent selections. The former is about tuning instruction selection (via if-conversion in this case) based on the microarchitecture. The latter is about which instructions are available in the first place. The former does not imply the latter. I don't think there's much point to disabling restrict-it when targeting v8 from an end-user POV, but it's pretty useful for the backend. We want to be able to write test cases that make sure it's working, for example. Do I understand right there's a frontend option, too? That's the only context in which gcc compatibility makes much sense. I don't see any value other than slavishly following gcc's option list to having this be exposed to end users in clang. I'd much rather it be entirely in the backend. Comment Actions I think we want to discuss whether the latter (HasV8Ops) implies the former (restrict-it). If it makes no sense from the user's POV to not restrict IT blocks when targeting armv8, then we can conclude armv8 implies restrict-it and add FeatureRestrictedIT to the implied features list of HasV8Ops. If we do this, disabling restrict-it would transitively disable HasV8Ops. Does that make sense?
That said, if we want to allow llvm developers to turn off restrict-it when targeting v8 for debugging purposes, we shouldn't add FeatureRestrictedIT to the implied features list of HasV8Ops.
The front-end options are -mrestrict-it and -mno-restrict-it, which were committed in r194593. The clang-side patch that I submitted for review is here: http://reviews.llvm.org/D10414. I agree that the option to disable restrict-it when targeting armv8 should be a backend option only available to llvm developers. If we all agree on that, I'll update the clang patch (D10414) accordingly. No changes are needed to the llvm patch (this patch) to allow disabling restrict-it when targeting armv8. If -mattr=+restrict-it is not on the tool's (llc's) command line, restrict-it is disabled. Comment Actions It makes sense right up until you say, "If we do this, disabling restrict-it would transitively disable HasV8Ops." That may be the current implementation, but it's not what we want.
Right. We want it to be the case by default for armv8, but not inextricably tied to it. It's a default, not a requirement.
Comment Actions Perhaps I should ask Weiming who committed the original patch to add these options just to be sure. Is there a use case in which an end user wants to disable restrict-it when targeting armv8? Would there be problems if we stopped exposing option -mno-restrict-it to the end user as suggested by Jim? I'm considering making changes to clang so that -mno-restrict-it has no effect on the backend code generation (end-users can use the option but it'll have no effect). Comment Actions Hi Akira, Yes, the option "-mno-restrict-it " was added for GCC compatibility. I don't find a actual use case :) Comment Actions OK, I'll make changes to clang to stop exposing it to the end-user as a front-end option. Comment Actions Rebase to r247192 and remove a RUN line in test/CodeGen/Thumb2/restict-it-fnattr.ll that is no longer needed. |
Bikeshedding: I think that restrictedIT might be a better name. IIRC, the ARM ARM refers to this as Restricted IT Blocks.