Can llvm support a target backend without function call ?

Hi all,

I am writing a llvm backend for a small stream processor. Because of its special application field, the processor does not support function. When I built the llvm backend for the new target, I leave the calling convention and frame lowering part blank. It compilered correctly, but I encountered execution errors, like

[xxx@localhost ex]$ llc test.ll -march=SSP -o test.s
0 llc 0x08f7ee49
1 llc 0x08f7f41a
2 0x003b1420 __kernel_sigreturn + 0
3 llc 0x08de0d52 llvm::TargetData::getAlignment(llvm::Type const*, bool) const + 44
4 llc 0x08de108a llvm::TargetData::getABITypeAlignment(llvm::Type const*) const + 44
5 llc 0x0863e289 llvm::TargetData::getTypeAllocSize(llvm::Type const*) const + 37
6 llc 0x08a707ed llvm::GetReturnInfo(llvm::Type const*, unsigned int, llvm::SmallVectorImplllvm::ISD::OutputArg&, llvm::TargetLowering const&, llvm::SmallVectorImpl*) + 573
7 llc 0x089b59be llvm::FunctionLoweringInfo::set(llvm::Function const&, llvm::MachineFunction&) + 156
8 llc 0x08a4ec8a llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) + 280
9 llc 0x08b7c191 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 89
10 llc 0x08eb92f1 llvm::FPPassManager::runOnFunction(llvm::Function&) + 315
11 llc 0x08eb94bb llvm::FPPassManager::runOnModule(llvm::Module&) + 121
12 llc 0x08eb8fbf llvm::MPPassManager::runOnModule(llvm::Module&) + 413
13 llc 0x08eba3b0 llvm::PassManagerImpl::run(llvm::Module&) + 124
14 llc 0x08eba415 llvm::PassManager::run(llvm::Module&) + 39
15 llc 0x0859a610 main + 2470
16 libc.so.6 0x0097de9c __libc_start_main + 220
17 llc 0x08598b61
Stack dump:
0. Program arguments: llc test.ll -march=SSP -o test.s
1. Running pass ‘Function Pass Manager’ on module ‘test.ll’.
2. Running pass ‘SSP DAG->DAG Pattern Instruction Selection’ on function ‘@add
Segmentation fault

I think the error comes from the lacking support of function call. Should I write some fake codes to walk around, or I have some ways to tell LLVM that I do not want function call?

Actually, I tried to write LLVM IR without the function form of define @main(…, but with function body directly. Unfortunately, everything seems must work with a function call, otherwise llc will not work.

Best wishes!

Hi all,

I am writing a llvm backend for a small stream processor. Because of its special application field, the processor does not support function. When I built the llvm backend for the new target, I leave the calling convention and frame lowering part blank. It compilered correctly, but I encountered execution errors, like

[xxx@localhost ex]$ llc test.ll -march=SSP -o test.s
0 llc 0x08f7ee49
1 llc 0x08f7f41a
2 0x003b1420 __kernel_sigreturn + 0
3 llc 0x08de0d52 llvm::TargetData::getAlignment(llvm::Type const*, bool) const + 44
4 llc 0x08de108a llvm::TargetData::getABITypeAlignment(llvm::Type const*) const + 44
5 llc 0x0863e289 llvm::TargetData::getTypeAllocSize(llvm::Type const*) const + 37
6 llc 0x08a707ed llvm::GetReturnInfo(llvm::Type const*, unsigned int, llvm::SmallVectorImplllvm::ISD::OutputArg&, llvm::TargetLowering const&, llvm::SmallVectorImpl*) + 573
7 llc 0x089b59be llvm::FunctionLoweringInfo::set(llvm::Function const&, llvm::MachineFunction&) + 156
8 llc 0x08a4ec8a llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) + 280
9 llc 0x08b7c191 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 89
10 llc 0x08eb92f1 llvm::FPPassManager::runOnFunction(llvm::Function&) + 315
11 llc 0x08eb94bb llvm::FPPassManager::runOnModule(llvm::Module&) + 121
12 llc 0x08eb8fbf llvm::MPPassManager::runOnModule(llvm::Module&) + 413
13 llc 0x08eba3b0 llvm::PassManagerImpl::run(llvm::Module&) + 124
14 llc 0x08eba415 llvm::PassManager::run(llvm::Module&) + 39
15 llc 0x0859a610 main + 2470
16 libc.so.6 0x0097de9c __libc_start_main + 220
17 llc 0x08598b61
Stack dump:
0. Program arguments: llc test.ll -march=SSP -o test.s
1. Running pass ‘Function Pass Manager’ on module ‘test.ll’.
2. Running pass ‘SSP DAG->DAG Pattern Instruction Selection’ on function ‘@add
Segmentation fault

This error seems to suggest there is something wrong with how you implement your TargetData field in your TargetMachine subclass.

I think the error comes from the lacking support of function call. Should I write some fake codes to walk around, or I have some ways to tell LLVM that I do not want function call?

You do not need to handle call instructions, but you do need to handle parameter passing. A function is the basic unit of compilation in LLVM, and a function can have zero or more parameters, and an output parameter. You need to specify how to lower these parameters. If you always have a function that takes no arguments, and returns nothing, then you can just omit the implementation.

Actually, I tried to write LLVM IR without the function form of define @main(…, but with function body directly. Unfortunately, everything seems must work with a function call, otherwise llc will not work.

Yes, LLVM requires all instructions to be within a block within a function.