Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

singlepath: singlepath crashes when divide is used and compiled from bitcode #14

Open
Emoun opened this issue Nov 2, 2018 · 3 comments

Comments

@Emoun
Copy link
Member

Emoun commented Nov 2, 2018

When I compile a program that includes a divide operation to bitcode (using patmos-clang -S) and then try to further compile it to assembly with patmos-llc, using the singlepath flag, it crashes.

Take this minimal code (we will refer to this as main.c):

volatile int _1 = 1;
volatile int _2 = 2;
int main(){
	return _2 / _1;
}

We compile it to LLVM bitcode using the command patmos-clang -S main.c -O2 without issue.
We then try to compile it to assembly using the command patmos-llc main.s -mpatmos-singlepath=main -O2. This fails with the following error:

[Single-path] Cannot rewrite call in main (indirect call?)
0  libLLVMSupport.so       0x00007f2c15841762 llvm::sys::PrintStackTrace(_IO_FILE*) + 50
1  libLLVMSupport.so       0x00007f2c15840f4c
2  libc.so.6               0x00007f2c1503ef20
3  libc.so.6               0x00007f2c1503ee97 gsignal + 199
4  libc.so.6               0x00007f2c15040801 abort + 321
5  libLLVMPatmosCodeGen.so 0x00007f2c175a5875
6  libLLVMCore.so          0x00007f2c15e50d09 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 761
7  patmos-llc              0x00007f2c18008294
8  patmos-llc              0x00007f2c18006ec0
9  libc.so.6               0x00007f2c15021b97 __libc_start_main + 231
10 patmos-llc              0x00007f2c18006f3a
Stack dump:
0.      Program arguments: patmos-llc main.s -mpatmos-singlepath=main -O2
1.      Running pass 'Patmos Single-Path Mark (machine code)' on module 'main.s'.

Note that we are using -O2, but all other optimization levels result in the same issue. The issue is only present with the divide operator, changing it to a multiply makes the code compile successfully.
Additionally, the issue is only present when first compiling to bitcode and then using patmos-llc on it. If we instead use the command patmos-clang main.c the code compiles successfully. So the issue is caused by patmos-llc having to read bitcode.

@schoeberl
Copy link
Member

Divide is different form mul, as there is no divide instruction available on Patmos and a library routine needs to be linked in. Maybe this is a linking issue?

@Emoun
Copy link
Member Author

Emoun commented Nov 17, 2018

I have investigated further, and divide only causes errors if its used in a function that is converted to singlepath. E.g. this code works fine with the command patmos-llc main.s -mpatmos-singlepath=init_func:

volatile int _1 = 1;
volatile int _2 = 2;

int init_func(){
	return _1 + _2;
}

int main(){
	int x = init_func();
	return x / _1;
}

This is because singlepath cannot handle external functions like printf and, apparently, the divide function provided by llvm. I don't know if there are any plans to remedy this in the future, but I am not planning to solve this. I will try to see if a better error message can be thrown instead of the current one.

@schoeberl
Copy link
Member

Agree that you move on with other work. Let's just leave this issue open for now.

However, as a notice: this is not a single path generation issue, but a linking issue, as it works with patmos-clang.

That printf cannot be converted into single-path code is a different issue. Same issue as printf cannot be analyzed for a WCET bound.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants