<div dir="ltr">Would you know how I could recognize which opcodes are kernel mode vs user mode?</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jan 28, 2022 at 1:43 PM Alex Bradbury <<a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Fri, 28 Jan 2022 at 18:31, Kenneth Adam Miller via llvm-dev<br>
<<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
> Hello all,<br>
><br>
> I'm perusing the LLVM source, and I need to know where the ISA mappings are kept in source for the semantics of a given architecture. Like, say I'm compiling to arm, I would like to know for the compiler to pick an opcode, say 0x1, that 0x1 corresponds to xyz operations that the compiler knows about. Where or what file tells the compiler this? Is there any convention for targets, where this can be regularly expected to be for a given target?<br>
<br>
Hi Kenneth,<br>
<br>
I'd recommend taking a look through<br>
<a href="https://llvm.org/docs/CodeGenerator.html" rel="noreferrer" target="_blank">https://llvm.org/docs/CodeGenerator.html</a> for an overview of how code<br>
generation works in LLVM. In the common case, you'll find pattern<br>
fragments matching target-independent SelectionDAG opcodes to native<br>
instructions in the *InstrInfo.td files in lib/Target/<Foo>/. These<br>
are specified using the TableGen domain-specific language. You'll find<br>
cases that can't be handled by these patterns covered in the<br>
<Foo>DAGToDAGIsel::Select method. See also GlobalISel<br>
<a href="https://llvm.org/docs/GlobalISel/index.html" rel="noreferrer" target="_blank">https://llvm.org/docs/GlobalISel/index.html</a> (and talks on it at recent<br>
LLVM Dev meetings) for an alternative instruction selection approach.<br>
Perhaps my talk from a few years ago is also helpful<br>
<<a href="https://speakerdeck.com/asb/llvm-backend-development-by-example-risc-v" rel="noreferrer" target="_blank">https://speakerdeck.com/asb/llvm-backend-development-by-example-risc-v</a>>.<br>
It works from the MC layer up, but slide 20 onwards cover instruction<br>
selection and gives examples with some of the helper classes we use in<br>
the RISC-V backend stripped away. For an add, it's as simple as:<br>
def : Pat<(add GPR:$rs1, GPR:$rs2),<br>
        (ADD GPR:$rs1, GPR:$rs2)>;<br>
def : Pat<(add GPR:$rs1, simm12:$imm12),<br>
        (ADDI GPR:$rs1, simm12:$imm12)>;<br>
<br>
Hope that helps.<br>
<br>
Best,<br>
<br>
Alex<br>
</blockquote></div>