lowRISC / riscv-llvm

RISC-V support for LLVM projects (LLVM, Clang, ...)
http://www.lowrisc.org/llvm/status/
249 stars 52 forks source link

Make decision on splitting instruction definitions from patterns #42

Closed asb closed 7 years ago

asb commented 7 years ago

This idea seems to have a lot of support, going by the mailing list discussion. As Daniel Sanders points out, there is a potential gotcha due to the fact properties will no longer be inferred from the pattern. Setting guessInstructionProperties=0 seems promising.

dvc94ch commented 7 years ago

I like the separation too, since it would make it more clear (to me) how to support this case:

// NOTE: no corresponding llvm ir instruction def MULHSU : ALU_rr<0b0000001, 0b010, "mulhsu", mulhs>;

On the inference: I prefer to be explicit when in doubt and avoid "magic" in general, but I don't understand enough about this particular case.

I have a question about the gp register and it's use. Looking at the code I can't see it being used anywhere. Also the "complete" llvm backend doesn't make use of it. Is it useful for optimizations later on? Or why are we reserving it? Or is it reserved for the OS/libc? It seems that it's main purpose is saving an instruction or so when accessing global variables? Does that justify having this register (reserved) in the first place? I'm currently not initializing it in my rust startup code, is something bad going to happen if I don't?

For anyone else looking for this information: Linker's job. Frontend can help by putting commonly used globals in an sdata section making sure that the right globals are optimized.

The gp (Global Pointer) register is a solution to further optimise memory accesses within a single 4KB region.

The linker uses the __global_pointer$ symbol definition to compare the memory addresses and, if within range, it replaces absolute/pc-relative addressing with gp-relative addressing, which makes the code more efficient. This process is also called relaxing, and can be disabled by -Wl,--no-relax.

[0] https://groups.google.com/a/groups.riscv.org/forum/#!msg/sw-dev/60IdaZj27dY/xypNjAPTAQAJ [1] https://gnu-mcu-eclipse.github.io/arch/riscv/programmer/#the-gp-global-pointer-register

asb commented 7 years ago

I've gone ahead and done this. The patches in this repo have been refreshed, as has the upstream patches awaiting review https://reviews.llvm.org/differential/?authors=asb&order=updated