Evan asked me to review this patch, and I have some questions about it. I apologize for not following the discussion earlier and for hitting you with questions after you’ve already gone through several revisions.
LLVM provides some default behavior for handling jump tables, with the tables emitted separately from the code that uses them. The ARM backend provides its own custom handling of jump tables so that it can emit them in-line with the text. It seems to me that your patch changes the ARM backend to optionally handle jump tables in a way that is at least very similar to the default behavior, but you have implemented it without using the existing code. Did you consider implementing it using the LLVM defaults?
I spend over a day trying to follow your suggestion. In the end I was not successful. Here is what Iearned:
ARMJITInfo::hasCustomJumpTables → true
setOperationAction for ISD::BR_JT → Expand
I needed to add a “brind” definition to ARMInstrInfo.td
I picked “bx” but to do a proper job one would have to take older architectures
The next thing was to to set
setOperationAction for ISD::JumpTable → Custom
and implement the corresponding code.
This code is very similar to my “outline” code as it has to materialize
the table start address.
I never quite got this to work, though.
Presumably what the generic code generator
would to is to use this table start multiple the “switch index” by 4 load the target address and jump there. Not a very big saving in my mind.
And it is offset by having to touch ARMInstrInfo.td.
Also note, that the generic code generator must make some assumptions
about the format of each jumptable entry (e.g. 32bit absolute addresses) so this cannot be changed easily afterwards.
Having the default jumtables and the out of line version diverge too much
and have different code path may also not be such a good idea.
Using TargetAsmInfo::JumpTableDataSection is one piece of that, but there is more. As a start, you could change ARMJITInfo::hasCustomJumpTables and the “Custom” argument to setOperationAction for ISD::BR_JT in the ARMTargetLowering constructor to be conditional on your new flag. I’m sure there is more required than that, but maybe that will get you started.
Otherwise, there are some problems with your custom handling for out-of-line jump tables. The most serious of these is in ARMAsmPrinter::printJTBlockOperand: for out-of-line jump tables, you emit a “.text” directive to switch back to the text section. If the current section is not “.text”, however, this will break. I believe you ought to use SwitchToTextSection instead. Earlier in that same method, I think you should also use SwitchToDataSection and EmitAlignment. But, again, rather than tweaking this code, I would prefer to find a way to use the existing LLVM code for this.
I changed all of these as per your request.
Why did you change the default value for JumpTableDataSection? Jump tables really should not go into .data. That is a security hole. They should be read-only.
I changed that too so the data goes into the default .rodata now.
I am not sure where .rodata lives. if it lives in the text segment
you get better protection but the code wont be PIC if .rodata
goes into the data segment it is the other way round.
When you create global symbols for the jump tables, you specify a “.T” name:
new ARMConstantPoolValue(“.T”, Num, ARMCP::CPDataSegmentJumpTable);
T as in Table, I do not care much about the naming. If you have a better proposal I will go with that.
And, by the way, I noticed that you removed a “blank” comment line in ARMISelLowering.h. I think I have done that myself, but I recently discovered that the extra lines are intentional. Doxygen recognizes C++ comments beginning with 3 slashes but you have to have at least 2 lines of them or doxygen will not recognize them.
- fixed and added artificial line break to keep this from happening again.
patch.2009-07-01 (15.4 KB)