[llvm-dev] Can LLVM optimize for a stack machine backend?

225 views
Skip to first unread message

Xiaohui Liu via llvm-dev

unread,
Apr 29, 2021, 2:33:36 AM4/29/21
to llvm...@lists.llvm.org
Hi all,

I am developing a high-level language that compiles to bytecode for a stack-based virtual machine. There are only two stacks similar to Forth.

LLVM IR seems register-machine oriented and most backends target register machines. I have seen several attempts to use it for a stack machine backend, such as this, this, and this. What is the state of the art of using LLVM to optimize for a stack machine? Or LLVM is not a good choice for this job?

Regards,
Xiaohui

Quentin Colombet via llvm-dev

unread,
Apr 29, 2021, 1:06:30 PM4/29/21
to Xiaohui Liu, llvm...@lists.llvm.org
Hi Xiaohui,

I think the situation didn’t really change with respect to what you found.
In particular I believe the advice from Chris that you already found (https://lists.llvm.org/pipermail/llvm-dev/2008-November/018626.html) is the best thing you can do right now.

Cheers,
-Quentin

_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

Petr Penzin via llvm-dev

unread,
Apr 29, 2021, 6:04:31 PM4/29/21
to llvm...@lists.llvm.org
This is a bit out of date, LLVM now has a stack-based target included by default - WebAssembly. It has a "stackifier" implementation (look for files with Stackify in the name inside llvm/lib/Target/WebAssembly). However, stack transformations are in fact somewhat of a pain point, that's one of the reasons Emscripten (C/C++ to Wasm compiler) uses an additional tool after emitting code using Clang/LLVM, though another popular Wasm toolchain does not.

Best,
Petr
Reply all
Reply to author
Forward
0 new messages