This patch adds MSA branch instruction emulation for MIPS64.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp | ||
---|---|---|
3117 | This should be pc + 8. If branch is not taken then we need to skip the delay slot. |
You added 10 new function to the emulator where the first 8 functions and the last 2 functions are almost identical. I know that the rest of the MIPS64 instruction emulator is having the same issue but I would like to see these functions to be merged into a smaller number of functions to remove code duplication.
I see 2 different approach to do it and I am not sure which one is better in this case, but both of them improves the situation by a lot.
- Write only 2 function (first 8, last 2) and that function then reads out the condition and the sizes from the MCInst object. I would prefer this approach, but I am not sure how difficult it is to read out data from an MCInst
- Keep the 10 function for the 10 different instruction, but make these functions to call a function (one for the first 8 and one for the last 2) with passing in the constants required by the specific instruction.
Both approach would reduce the amount of code in this class and help a lot in reducing the maintenance cost with removing a lot of duplicated code.
I will defer to MIPS experts here. You might thing about adding tberghammer as a reviewer.
I don't know too much about mips so I haven't checked if the emulation is actually correct but the general concept looks good to me. I added a few comments inline but they are mostly suggestions what you might want to consider.
source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp | ||
---|---|---|
553–562 | (nit): Indentation | |
3138–3140 | Please initialize these variables | |
3160 | You can possibly write it in the following way, but I am not sure which one is the cleaner: if((*ptr == 0) == bnz) break; | |
3187 | Using eContextInvalid as context type is fine for single stepping but if you want these instructions to be handled correctly during emulation based stack unwinding then you have to use eContextAbsoluteBranchRegister or eContextRelativeBranchImmediate with the correct data (it is used by the branch following code in the unwinder) | |
3211–3213 | Please initialize these variables | |
3230 | You can possibly write it in the following way, but I am not sure which one is the cleaner: if(llvm::APInt::isSameValue(zero_value, wr_val) != bnz) ... | |
3236 | Using eContextInvalid as context type is fine for single stepping but if you want these instructions to be handled correctly during emulation based stack unwinding then you have to use eContextAbsoluteBranchRegister or eContextRelativeBranchImmediate with the correct data (it is used by the branch following code in the unwinder) |
source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp | ||
---|---|---|
3160 | The former one is more readable. | |
3187 | I have set the type to eContextRelativeBranchImmediate for now we are using these instructions for single stepping only. | |
3230 | The former one is more readable. | |
3236 | I have set the type to eContextRelativeBranchImmediate for now we are using these instructions for single stepping only. |
(nit): Indentation