[LLVMdev] can i avoid saving CSRs for functions with noreturn

Liu Xin navy.xliu at gmail.com
Wed Jul 31 20:51:41 PDT 2013


hi, list,

i am making a llvm compiler for shader-like programs. as we known, shader
programs are short and have less function calls. i found that i have to
save/restore callee-saved register(CSR) in prolog and epilog.  because I
can violate ABI from driver(c code) and shader, i plan to append the
attribute 'noreturn' to all shader functions.

in PrologEpilogInserter.cpp, you can find that it actually honor an
attribute 'naked' which avoid saving CSR. however, it also skips generating
stack-pointer adjustment, which i need. my patch is as follows. i am
targeting RISC processor. can anyone tell me this patch is generic ?

diff --git a/lib/CodeGen/PrologEpilogInserter.cpp
b/lib/CodeGen/PrologEpilogInserter.cpp
index c791ffb..f19b47a 100644
--- a/lib/CodeGen/PrologEpilogInserter.cpp
+++ b/lib/CodeGen/PrologEpilogInserter.cpp
@@ -96,7 +96,7 @@ bool PEI::runOnMachineFunction(MachineFunction &Fn) {
   placeCSRSpillsAndRestores(Fn);

   // Add the code to save and restore the callee saved registers
-  if (!F->hasFnAttr(Attribute::Naked))
+  if (!F->hasFnAttr(Attribute::Naked) &&
!F->hasFnAttr(Attribute::NoReturn))
     insertCSRSpillsAndRestores(Fn);

   // Allow the target machine to make final modifications to the function


thanks,
--lx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130801/e2a7b414/attachment.html>


More information about the llvm-dev mailing list