jacobly0 / llvm-project

This fork of the canonical git mirror of the LLVM subversion repository adds (e)Z80 targets. Please refer to the wiki for important build instructions.
https://github.com/jacobly0/llvm-project/wiki
120 stars 15 forks source link

Last change breaks RISCV port #4

Closed b-s-a closed 4 years ago

b-s-a commented 4 years ago

FAILED: lib/Target/RISCV/RISCVGenGlobalISel.inc cd /home/bsa/projects/llvm-project/build && /home/bsa/projects/llvm-project/build/bin/llvm-tblgen -gen-global-isel -I /home/bsa/projects/llvm-project/llvm/lib/Target/RISCV -I /home/bsa/projects/llvm-project/llvm/include -I /home/bsa/projects/llvm-project/llvm/lib/Target /home/bsa/projects/llvm-project/llvm/lib/Target/RISCV/RISCV.td --write-if-changed -o lib/Target/RISCV/RISCVGenGlobalISel.inc -d lib/Target/RISCV/RISCVGenGlobalISel.inc.d Failed to lookup instruction ordering UNREACHABLE executed at /home/bsa/projects/llvm-project/llvm/utils/TableGen/GlobalISelEmitter.cpp:3060!

b-s-a commented 4 years ago

Also it breaks Z80 port too. Imho, repository is broken for now.

/home/bsa/projects/llvm-project/llvm/lib/Target/Z80/Z80LegalizerInfo.cpp: In constructor ‘llvm::Z80LegalizerInfo::Z80LegalizerInfo(const llvm::Z80Subtarget&, const llvm::Z80TargetMachine&)’: /home/bsa/projects/llvm-project/llvm/lib/Target/Z80/Z80LegalizerInfo.cpp:53:47: error: no matching function for call to ‘llvm::LegalizeRuleSet::legalForCartesianProduct(const std::initializer_list&, const std::initializer_list&)’ .legalForCartesianProduct(NotMin, NotMax)

adriweb commented 4 years ago

Yeah, for now you can checkout 040b525c8d7f148c892431cc12a85b4e9bdbf6f0 it will compile. But build in Debug mode for this one.

b-s-a commented 4 years ago

My clang and llvm are build in Debug mode (CMAKE_BUILD_TYPE=Debug). Moreover, they was built in Debug mode when I create first issue. I try 040b525 but result was same. My build environment: Ubuntu 18.04.3 LTS (amd64) gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0

adriweb commented 4 years ago

Hmm, this version works fine for me so far:

build/bin/clang --version
clang version 10.0.0 (https://github.com/jacobly0/llvm-project.git 040b525c8d7f148c892431cc12a85b4e9bdbf6f0)

I successfully compiled char foo(_Bool q){return q ? -1 : 0;} with all 4 targets (z80, z180, ez80, ez80-code16) with O3 and Oz. Same with your older example:

build/bin/clang -target z180 -S -Oz -xc - -o - <<<"int main(void) { return 0; }"
    SEGMENT CODE
    .file   "-"
    XDEF    _main
_main:
    call    __frameset0
    ld  hl, 0
    pop ix
    ret

    XREF    __frameset0

Anyway, I'm sure @jacobly0 will soon push something that'll work again.

b-s-a commented 4 years ago

clang --version clang version 10.0.0 (https://github.com/b-s-a/llvm-project.git 040b525c8d7f148c892431cc12a85b4e9bdbf6f0) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /home/bsa/projects/llvm-project/build/bin

clang -target z180 -S -Oz -xc - -o - <<<"int main(void) { return 0; }" SEGMENT CODE .file "-" fatal error: error in backend: unable to legalize instruction: %0:_(s16) = G_CONSTANT i16 0 (in function: main) clang-10: error: clang frontend command failed with exit code 70 (use -v to see invocation) clang version 10.0.0 (https://github.com/b-s-a/llvm-project.git 040b525c8d7f148c892431cc12a85b4e9bdbf6f0) Target: z180 Thread model: posix InstalledDir: /home/bsa/projects/llvm-project/build/bin clang-10: note: diagnostic msg: PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script. clang-10: note: diagnostic msg: Error generating preprocessed source(s) - ignoring input from stdin. clang-10: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.

b-s-a commented 4 years ago

After full recompiling using commands from wiki I have same result as before: "unable to legalize instruction..."

adriweb commented 4 years ago

Yeah i'm not sure why the revision I gave you earlier doesn't work for you. Let's just wait for jacobly to fix it.

adriweb commented 4 years ago

So, I just tried from scratch the latest commit so far and everything builds and runs fine for me (latest macOS), in both Debug and Release.

For instance for the following outputs, I ran cmake with these parameters: -DLLVM_ENABLE_PROJECTS=clang -DLLVM_PARALLEL_LINK_JOBS=4 -DLLVM_TARGETS_TO_BUILD= -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=Z80 -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON.

The build lasted around 25 minutes, then:

$ bin/clang -target ez80 --version
clang version 10.0.0 (https://github.com/jacobly0/llvm-project.git 05c3c2619abc07ddadde0fc9f395f1d8532cca59)
Target: ez80
Thread model: posix
bin/clang -target z180 -S -Oz -xc - -o - <<<"int main(void) { return 0; }"
    SEGMENT CODE
    .file   "-"
    XDEF    _main
_main:
    call    __frameset0
    ld  hl, 0
    pop ix
    ret

    XREF    __frameset0
b-s-a commented 4 years ago

My build options are same, but debug, build jobs 5, link jobs 2, and generator ninja. Also I suggest to use shared libraries, because each linker job eats ~9GB of memory while linking clang and libclang with others static libs. Also, I'm using gcc as build toolchain. Can it cause this bug?

b-s-a commented 4 years ago

I try again on clean environment. I clone repository, checkout 05c3c2619abc07ddadde0fc9f395f1d8532cca59, configure like you (but -G Ninja -DLLVM_PARALLEL_COMPILE_JOBS=9 -DCMAKE_BUILD_TYPE=Debug). Result is: /home/bsa/llvm-project/llvm/lib/Target/Z80/Z80LegalizerInfo.cpp:172:51: error: no matching function for call to ‘llvm::LegalizeRuleSe t::legalForCartesianProduct(, const std::initializer_list&)’ /home/bsa/llvm-project/llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h:521:20: note: candidate expects 3 arguments, 2 provided /home/bsa/llvm-project/llvm/lib/Target/Z80/Z80LegalizerInfo.cpp:172:51: error: no matching function for call to ‘llvm::LegalizeRuleSe t::legalForCartesianProduct(, const std::initializer_list&)’ .legalForCartesianProduct({p0}, LegalScalars)

adriweb commented 4 years ago

Note that I'm compiling with clang 9

b-s-a commented 4 years ago

I confirm, that clang-6.0 builds last commit successfully and it works.

adriweb commented 4 years ago

good to hear, I guess this issue can be closed (though I wonder if the github actions builders can easily be fixed then...)

b-s-a commented 4 years ago

Imho, different build results depending on compiler is more serious issue than syntax error, isn't it?

jacobly0 commented 4 years ago

The syntax error doesn't even happen with newer versions of gcc. The UB causing differences between compilers was already fixed. Closing.

Edit: Oh, this discussion got so off topic I forgot what the original issue was.

  1. This repo already breaks other targets in subtle ways and I don't have the time to track them all down.
  2. If you insist on RISCV compiling, you can always uncomment https://github.com/jacobly0/llvm-project/blob/z80/llvm/utils/TableGen/GlobalISelEmitter.cpp#L4010, but since that hurts our output code quality, I am no longer willing to keep the hack in.
jacobly0 commented 4 years ago

I moved that line elsewhere so that it no longer affects the Z80 backend, so RISCV "compiles" now.