Hi Than,

I got another question for you. For indirect parameters, arm-aapcs abi 
requires to do a copy of the parameter on stack, and then pass the address  
of the copied parameter to callee. I tried to do a memcpy of the indirect 
parameter in function Llvm_backend::genCallMarshallArgs, but failed to 
build. The code are as follow:

git diff
diff --git a/bridge/go-llvm-materialize.cpp b/bridge/go-llvm-materialize.cpp
index 3985153..bc8c147 100644
--- a/bridge/go-llvm-materialize.cpp
+++ b/bridge/go-llvm-materialize.cpp
@@ -1194,7 +1194,22 @@ Llvm_backend::genCallMarshallArgs(const 
std::vector<Bexpression *> &fn_args,
         llvm::Type *pt = 
llvm::PointerType::get(vt->getPointerElementType(), 0);
         val = builder.CreateAddrSpaceCast(val, pt, castname);
       }
-      state.llargs.push_back(val);
+
+//      BlockLIRBuilder bbuilder(state.callerFcn->function(), this);
+      TypeManager *tm = state.oracle->tm();
+      Btype *bty = fnarg->btype();
+      uint64_t sz = tm->typeSize(bty);
+      uint64_t algn = tm->typeAlignment(bty);
+      std::string tname(namegen("arm64indtpara.actual"));
+      llvm::Value *tmpV = state.callerFcn->createTemporary(bty, tname);
+      llvm::CallInst *cpyVal = builder.CreateMemCpy(tmpV, algn, val, algn, 
sz);
+      state.llargs.push_back(cpyVal);
+//      llvm::CallInst *cpyVal = builder.CreateMemCpy(tmpV, algn, val, 
algn, sz);
+//           std::vector<llvm::Instruction *> instructions = 
bbuilder.instructions();
+//           for (auto i : instructions)
+//             state.llargs.push_back(i);
+
+//      state.llargs.push_back(val);
       continue;
     }

Any suggestions on how and where to implement this situation? I found that 
here we need to know a little bit about the LLVM backend, but I almost knew 
nothing about it.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/e57b56e7-9dd0-4939-a15f-bde319bdf036%40googlegroups.com.

Reply via email to