bridge: add support of __builtin_dwarf_cfa

__builtin_dwarf_cfa will be used for runtime.getcallersp.

Change-Id: I59402ccd322c36f2220459a425a0f8ab7b450558
Reviewed-on: https://go-review.googlesource.com/c/162906
Reviewed-by: Than McIntosh <thanm@google.com>
diff --git a/bridge/go-llvm-builtins.cpp b/bridge/go-llvm-builtins.cpp
index 58c7db7..f3a177e 100644
--- a/bridge/go-llvm-builtins.cpp
+++ b/bridge/go-llvm-builtins.cpp
@@ -124,6 +124,9 @@
   defineIntrinsicBuiltin("__builtin_frame_address", nullptr,
                          llvm::Intrinsic::frameaddress, ptrType,
                          uint32Type, nullptr);
+  defineIntrinsicBuiltin("__builtin_dwarf_cfa", nullptr,
+                         llvm::Intrinsic::eh_dwarf_cfa, ptrType,
+                         uint32Type, nullptr);
 
   defineIntrinsicBuiltin("__builtin_prefetch", nullptr, llvm::Intrinsic::prefetch,
                          ptrType, int32Type, int32Type, nullptr);
diff --git a/bridge/go-llvm-materialize.cpp b/bridge/go-llvm-materialize.cpp
index 920bae5..3d6a4c7 100644
--- a/bridge/go-llvm-materialize.cpp
+++ b/bridge/go-llvm-materialize.cpp
@@ -1415,6 +1415,14 @@
         fn_args.push_back(conexpr);
         break;
       }
+      case llvm::Intrinsic::eh_dwarf_cfa: {
+        // llvm.eh.dwarf.cfa takes an additional arg 0.
+        Btype *buint32t = integerType(true, 32);
+        llvm::Constant *c1 = llvm::ConstantInt::get(llvmInt32Type(), 0);
+        Bexpression *conexpr = nbuilder_.mkConst(buint32t, c1);
+        fn_args.push_back(conexpr);
+        break;
+      }
       default: {
         // at the moment no other instrinsics need special handling
       }