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 | ||
---|---|---|
2581 | The '|| hasMips64r6()' is redundant. The predicates are cumulative. | |
2613–2617 | Style nit: if (UseTraps) { emitRRI(...); return false; } emitII(...); return false; | |
2619 | Style nit: Avoid else after return | |
2628–2632 | Style nit: if (UseTraps) { emitRRI(...); return false; } emitII(...); return false; | |
2639 | Magic number for offset: 2*4 | |
2657 | Magic number for offset: 3*4 | |
2661 | Magic number for offset: 2*4 | |
2668 | 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 | ||
---|---|---|
2619 | 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. | |
2640 | Nit: Space after // | |
2646–2649 | Nit: Use ternary operator | |
2652–2655 | Nit: Use ternary operator | |
2657 | Nit: 80cols? and space after //. | |
2676 | Nit: 80cols? and space after //. | |
2680 | Nit: 80cols? and space after //. | |
2687 | 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 | ||
1728 | 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.