gollvm: improve comments for CABIOracle::canPassDirectly

Add a better header comment for the method CABIOracle::canPassDirectly,
which has some code that is relying on a very specific set of
frontend/backend assumptions.

Change-Id: I0720183fd5be346923ffa76a839cad3cbd4aa87a
Reviewed-on: https://go-review.googlesource.com/c/gollvm/+/190900
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
diff --git a/bridge/go-llvm-cabi-oracle.cpp b/bridge/go-llvm-cabi-oracle.cpp
index d339cf7..95b9b10 100644
--- a/bridge/go-llvm-cabi-oracle.cpp
+++ b/bridge/go-llvm-cabi-oracle.cpp
@@ -619,11 +619,34 @@
   return CABIParamInfo(abiTyp, ParmDirect, AttrNone, -1);
 }
 
+// Given the number of registers that we think a param is going to consume, and
+// a state object storing the registers used so far, canPassDirectly() makes a
+// decision as to whether a given param can be passed directly in registers vs
+// in memory.
+//
+// Note the first clause, "if (regsInt + regsSSE == 1) return true". This may
+// seem counter-intuitive (why no check against the state object?), but this way
+// of doing things is the convention used by other front ends (e.g. clang). What
+// is happening here is that for larger aggregate/array params (things that
+// don't fit into a single register), we'll make the pass-through-memory
+// semantics explicit in the function signature and generate the explict code to
+// copy things into memory. For params that do fit into a single register,
+// however, we just leave them all as by-value parameters and then assume that
+// the back end will do the right thing (e.g. pass the first few in registers
+// and then the remaining ones in memory).
+//
+// Doing things this way has performance advantages in that the middle-end
+// (all of the machine-independent LLVM optimization passes) won't have
+// to deal with the additional chunks of stack memory and code to copy
+// things onto and off of the stack (not to mention the aliasing concerns
+// when a local variable's address is taken and then passed in a function
+// call).
+
 bool CABIOracle::canPassDirectly(unsigned regsInt,
                                  unsigned regsSSE,
                                  ABIState &state)
 {
-  if (regsInt + regsSSE == 1)
+  if (regsInt + regsSSE == 1) // see comment above
     return true;
   if (regsInt <= state.availIntRegs() && regsSSE <= state.availSSERegs())
     return true;