[cfe-dev] pass-by-value aggregates - using the callee's frame

Robert Lytton robert at xmos.com
Wed Jul 3 08:52:43 PDT 2013


Hi David,

yes, simple bit copyable structures.
I am new to llvm and clang so appologise for asking the obvious.

If I run using the -emit-llvm, I can clearly see the 'byval' attributes - all correct and sensible.

By using -emit-llvm am I seeinf what the clang front end is creating to be passed to the llvm target backend?
OR is this an intermediate IR within clang stages?
may be I am over simplifying where clang fits in (e.g. front and back).

>From my fiddling it seems the '-emit-llvm' is then passed through the CodeGen stage in clang, and particularly the CodeGenFunction::EmitFunctionProlog() function.
I'm left pondering what the relationship between the llvm codegen and the clang codegen is? - not taken a close look yet - Tomorrow!


I hacked the EmitFunctionProlog() to see if I could get what I needed - and I can (hack below).
but am I on the right track or way off?
I took a look in the target backend briefly and will look again.
(Also tried -debug to dump the stages)

robert

--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -1290,6 +1290,14 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
                                false);
           V = AlignedTemp;
         }
+        else if (ArgI.getIndirectByVal()) {
+          llvm::AllocaInst *ByValue
+                              = CreateMemTemp(Ty, V->getName() + "agg.tmp");
+          llvm::ConstantInt * size = llvm::ConstantInt::get(IntPtrTy,
+                        getContext().getTypeSizeInChars(Ty).getQuantity());
+          Builder.CreateMemCpy(ByValue, V, size, 4 ); // where do we get alignment from?
+          V = ByValue;
+        }
       } else {
         // Load scalar value from indirect argument.
         CharUnits Alignment = getContext().getTypeAlignInChars(Ty);


________________________________
From: David Blaikie [dblaikie at gmail.com]
Sent: 03 July 2013 15:51
To: Robert Lytton
Cc: cfe-dev Developers
Subject: Re: [cfe-dev] pass-by-value aggregates - using the callee's frame


I believe (assuming you're talking about bit-copiable aggregates (not C++ types with non-trivial copy)) this is handled in Clang's irgen by using the 'byval' llvm ir attribute. I don't recall the specifics, but if shouldn't be too hard to find some handling of that in there.

On Jul 3, 2013 12:44 AM, "Robert Lytton" <robert at xmos.com<mailto:robert at xmos.com>> wrote:
Hi,

I'm adding an XCore target front end.
The XCore ABI is the same as the DefaultABIInfo ... almost.

One outstanding issue is the need to copy pass-by-value aggregates into the callee's stack-frame during the prolog.
Any advise, suggestions or direction as to where to look (CodeGenFunction::EmitFunctionProlog()? ) most welcome.

robert


_______________________________________________
cfe-dev mailing list
cfe-dev at cs.uiuc.edu<mailto:cfe-dev at cs.uiuc.edu>
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130703/683fa61b/attachment.html>


More information about the cfe-dev mailing list