I've added a subtarget feature (FeatureUseDivTraps) to help achieve this.
Details
Diff Detail
Event Timeline
Mostly a few style and spelling nits.
Regarding the magic numbers for branch targets: I definitely want to eliminate these (they are unlikely to be correct for microMIPS) but I can't think of a way to do so in the current implementation for macros. The problem is that we need to drop private labels at a future point in the instruction stream but we can't arrange this since we are buffering the instructions before emitting them all at once. We need to move to a mechanism where we emit the instructions directly as we build them. For now, could you make them named constants and mark them with a FIXME?
lib/Target/Mips/AsmParser/MipsAsmParser.cpp | ||
---|---|---|
2773 | The '|| hasMips64r6()' is redundant. The predicates are cumulative. | |
2805–2809 | Style nit: if (UseTraps) { emitRRI(...); return false; } emitII(...); return false; | |
2811 | Style nit: Avoid else after return | |
2820–2824 | Style nit: if (UseTraps) { emitRRI(...); return false; } emitII(...); return false; | |
2831 | Magic number for offset: 2*4 | |
2849 | Magic number for offset: 3*4 | |
2853 | Magic number for offset: 2*4 | |
2860 | Magic number for offset: 2*4 | |
lib/Target/Mips/Mips.td | ||
166–168 | The names and strings here are a little confusing. In both cases, the div macros trap division by zero. We're only picking between the conditional trap instructions ('teq' and similar) and the unconditional 'break' instruction (with a conditional branch over it), both of which are kinds of trap. I'm not sure what to suggest for the spelling since most names fall into the same problem. Maybe 'use-tcc-in-div'? |
Ignoring the magic number issue (see below): LGTM with some formatting nits.
Regarding the magic number issue: I still don't have a good solution to eliminate these hard coded offsets so we should go ahead for now and eliminate them when we refactor the way expansions are handled (which we need to do so sort out other relocation-related issues).
lib/Target/Mips/AsmParser/MipsAsmParser.cpp | ||
---|---|---|
2811 | I know why you've skipped this comment because we spoke face to face but you should also mention it on list. The reason is that it isn't an else after return. Only two of the three paths in the if-statements true case end in a return. | |
2832 | Nit: Space after // | |
2838–2841 | Nit: Use ternary operator | |
2844–2847 | Nit: Use ternary operator | |
2849 | Nit: 80cols? and space after //. | |
2868 | Nit: 80cols? and space after //. | |
2872 | Nit: 80cols? and space after //. | |
2879 | Nit: 80cols? and space after //. | |
lib/Target/Mips/Mips.td | ||
166–168 | Nit: First argument should be hanging too. The same is true of FeatureCnMips above but that's not for this patch. | |
lib/Target/Mips/MipsInstrInfo.td | ||
1738 | Nit: Indentation. Likewise for the other 3. |
Responded to reviewer comments. Made a few minor changes to emit functions to account for changes on the trunk. Also fixed last upload which accidentally removed a significant amount of code.
The '|| hasMips64r6()' is redundant. The predicates are cumulative.