[Exegesis] Implemented strategy for load operation
This fix helps to map operand memory to destination registers. If instruction is load, we can self-alias it in case when instruction overrides whole address register. For that we use provided scratch memory.
@llvm/pr-subscribers-tools-llvm-exegesis
Author: None (AnastasiyaChernikova)
Changes
This fix helps to map operand memory to destination registers. If instruction is load, we can self-alias it in case when instruction overrides whole address register. For that we use provided scratch memory.
Full diff: https://github.com/llvm/llvm-project/pull/113458.diff
1 Files Affected:
- (modified) llvm/tools/llvm-exegesis/lib/SerialSnippetGenerator.cpp (+45-1)
diff --git a/llvm/tools/llvm-exegesis/lib/SerialSnippetGenerator.cpp b/llvm/tools/llvm-exegesis/lib/SerialSnippetGenerator.cpp
index 7100b51bbb7298..ac4881f298618d 100644
--- a/llvm/tools/llvm-exegesis/lib/SerialSnippetGenerator.cpp
+++ b/llvm/tools/llvm-exegesis/lib/SerialSnippetGenerator.cpp
@@ -113,7 +113,51 @@ static void appendCodeTemplates(const LLVMState &State,
}
case ExecutionMode::SERIAL_VIA_MEMORY_INSTR: {
// Select back-to-back memory instruction.
- // TODO: Implement me.
+
+ auto &I = Variant.getInstr();
+ if (I.Description.mayLoad()) {
+ // If instruction is load, we can self-alias it in case when instruction
+ // overrides whole address register. For that we use provided scratch
+ // memory.
+
+ // TODO: now it is not checked if load writes the whole register.
+
+ auto DefOpIt = find_if(I.Operands, [](Operand const &op) {
+ return op.isDef() && op.isReg();
+ });
+
+ if (DefOpIt == I.Operands.end())
+ return;
+
+ const Operand &DefOp = *DefOpIt;
+ auto &ET = State.getExegesisTarget();
+ auto ScratchMemoryRegister = ET.getScratchMemoryRegister(
+ State.getTargetMachine().getTargetTriple());
+ auto &RegClass =
+ State.getTargetMachine().getMCRegisterInfo()->getRegClass(
+ DefOp.getExplicitOperandInfo().RegClass);
+
+ // Register classes of def operand and memory operand must be the same
+ // to perform aliasing.
+ if (!RegClass.contains(ScratchMemoryRegister))
+ return;
+
+ ET.fillMemoryOperands(Variant, ScratchMemoryRegister, 0);
+ Variant.getValueFor(DefOp) = MCOperand::createReg(ScratchMemoryRegister);
+
+ CodeTemplate CT;
+ CT.Execution = ExecutionModeBit;
+ if (CT.ScratchSpacePointerInReg == 0)
+ CT.ScratchSpacePointerInReg = ScratchMemoryRegister;
+
+ CT.Info = std::string(ExecutionClassDescription);
+ CT.Instructions.push_back(std::move(Variant));
+ CT.PreinitScratchMemory.emplace_back(ScratchMemoryRegister,
+ /* Offset */ 0);
+ CodeTemplates.push_back(std::move(CT));
+ }
+
+ // TODO: implement more cases
return;
}
case ExecutionMode::SERIAL_VIA_EXPLICIT_REGS: {
@legrosbuffle @mshockwave @topperc @boomanaiden154 Please take a look
Yes, this is part of #89047, which was asked to be discussed in this comment (https://github.com/llvm/llvm-project/pull/89047#discussion_r1731617185). This only affects boot support for riscv, it doesn't change anything on other platforms (I looked at the --opcode-index=-1 entries in the add code for all supported architectures). Since the commit with riscv support hasn't been pushed yet, I can't add tests here.
Yes, this is part of #89047, which was asked to be discussed in this comment (#89047 (comment)). This only affects boot support for riscv, it doesn't change anything on other platforms (I looked at the --opcode-index=-1 entries in the add code for all supported architectures). Since the commit with riscv support hasn't been pushed yet, I can't add tests here.
Is it possible to write test with other platforms, like ARM? If not, could you add a line in the PR description that this PR is stacked on top of #89047 ?
@mshockwave @legrosbuffle @topperc @boomanaiden154 I answered all the comments, please take a look
@mshockwave @legrosbuffle @topperc @boomanaiden154 I look forward to further review
@mshockwave @legrosbuffle @topperc @boomanaiden154 Please take a look
@mshockwave, do you have any objections for this?
It's been a month and there was no objections and this patch is LGTM, so I would say that it is good to merge. I'll wait till the end of this week though, so original reviews may take a look once more @mshockwave @legrosbuffle @topperc @boomanaiden154