[cfe-dev] CXX ABI, force passing function argument by reference

Diogo Sampaio via cfe-dev cfe-dev at lists.llvm.org
Wed Nov 24 00:37:38 PST 2021


Hi all,

A clang noob question...

In our target C++ ABI aggregates that are not trivially copyable should be passed by reference.
For example, in https://godbolt.org/z/1crdTGeKv

We have the string iii passed by a pointer (from the caller stack main) to function test_it

        addd $r0 = $r12, 64
        call test_it(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)

However our current llvm implementation breaks this abi, passing it by copy in registers:
        ld $r0 = 0[$r12]
        ;;
        ld $r1 = 8[$r12]
        ;;
        ld $r2 = 16[$r12]
        ;;
        ld $r3 = 24[$r12]
        call test_it(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)

Could anyone point me in how to change clang's choice of passing it by copy in register?

I've implemented a target specific CXXABI based in ItaniumCXXABI and overrided getRecordArgABI to return RAA_Indirect or RAA_DirectInMemory if the CXXRecordDecl is not marked as isTriviallyCopyable, and made our target use this CXXABI. However that does not do the trick. Even if I make it always return RAA_DirectInMemory, it does not change a thing in this code.

Thanks in advance,

Diogo Sampaio 
Senior Compiler Engineer • Kalray 
dsampaio at kalrayinc.com • [ https://www.kalrayinc.com/ | www.kalrayinc.com ] 

[ https://www.kalrayinc.com/ |   ] 

Please consider the environment before printing this e-mail. 
This message contains information that may be privileged or confidential and is the property of Kalray S.A. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.






More information about the cfe-dev mailing list