[PATCH] D21612: Work-in-Progress compiler-rt prototype for XRay runtime.

Dean Michael Berris via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 7 23:49:24 PDT 2016


dberris added inline comments.

================
Comment at: lib/xray/xray_interface.cc:34-53
@@ +33,22 @@
+void __xray_FunctionEntry() {
+  // First thing we do is save the caller provided registers before doing any
+  // actual work.
+  uint64_t Rrdi, Rrax, Rrdx, Rrsi, Rrcx, Rr8, Rr9, Rrbp;
+  __asm__ __volatile__("mov %%rbp, %0" : "=m"(Rrbp));
+  __asm__ __volatile__("mov %%rdi, %0" : "=m"(Rrdi));
+  __asm__ __volatile__("mov %%rax, %0" : "=m"(Rrax));
+  __asm__ __volatile__("mov %%rdx, %0" : "=m"(Rrdx));
+  __asm__ __volatile__("mov %%rsi, %0" : "=m"(Rrsi));
+  __asm__ __volatile__("mov %%rcx, %0" : "=m"(Rrcx));
+  __asm__ __volatile__("mov %%r8, %0" : "=m"(Rr8));
+  __asm__ __volatile__("mov %%r9, %0" : "=m"(Rr9));
+
+  // FIXME: Handle async signal safety, and prevent recursive calls.
+  auto Fn = __xray::XRayPatchedFunction.load(std::memory_order_acquire);
+  if (Fn != nullptr) {
+    int32_t FunctionID;
+    __asm__("mov %%r10d, %0" : "=g"(FunctionID) : : "%r10");
+    (*Fn)(FunctionID, XRayEntryType::ENTRY);
+  }
+
+  // Then restore the registers before returning.
----------------
Sorry, I forgot to address this one.

I'll need to have a look at how this is done in other places, but did you mean using the assembler to also generate the call to the function pointer? Or having this whole routine be implemented in assembly?


http://reviews.llvm.org/D21612





More information about the llvm-commits mailing list