[llvm-commits] [llvm] r44910 - in /llvm/trunk: lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp test/ExecutionEngine/2007-12-11-APIntExFuncCall.ll

Zhou Sheng zhousheng00 at gmail.com
Tue Dec 11 20:55:43 PST 2007


Author: sheng
Date: Tue Dec 11 22:55:43 2007
New Revision: 44910

URL: http://llvm.org/viewvc/llvm-project?rev=44910&view=rev
Log:
Fixed PR1629.
Make lli interpreter correctly call external functions sin()/cos(),
__cxa_guard_acquire() and __cxa_guard_release().

Added:
    llvm/trunk/test/ExecutionEngine/2007-12-11-APIntExFuncCall.ll
Modified:
    llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp

Modified: llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp?rev=44910&r1=44909&r2=44910&view=diff

==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp Tue Dec 11 22:55:43 2007
@@ -29,6 +29,7 @@
 #include <csignal>
 #include <map>
 #include <cmath>
+#include <cxxabi.h>
 using std::vector;
 
 using namespace llvm;
@@ -200,6 +201,22 @@
   return GV;
 }
 
+// double sin(double)
+GenericValue lle_X_sin(FunctionType *FT, const vector<GenericValue> &Args) {
+  assert(Args.size() == 1);
+  GenericValue GV;
+  GV.DoubleVal = sin(Args[0].DoubleVal);
+  return GV;
+}
+
+// double cos(double)
+GenericValue lle_X_cos(FunctionType *FT, const vector<GenericValue> &Args) {
+  assert(Args.size() == 1);
+  GenericValue GV;
+  GV.DoubleVal = cos(Args[0].DoubleVal);
+  return GV;
+}
+
 // double exp(double)
 GenericValue lle_X_exp(FunctionType *FT, const vector<GenericValue> &Args) {
   assert(Args.size() == 1);
@@ -705,6 +722,24 @@
   return GV;
 }
 
+// int __cxa_guard_acquire (__guard *g);
+GenericValue lle_X___cxa_guard_acquire(FunctionType *FT, 
+                                       const vector<GenericValue> &Args) {
+  assert(Args.size() == 1);
+  GenericValue GV;
+  GV.IntVal = APInt(32, __cxxabiv1::__cxa_guard_acquire (
+                          (__cxxabiv1::__guard*)GVTOP(Args[0])));
+  return GV;
+}
+
+// void __cxa_guard_release (__guard *g);
+GenericValue lle_X___cxa_guard_release(FunctionType *FT, 
+                                       const vector<GenericValue> &Args) {
+  assert(Args.size() == 1);
+  __cxxabiv1::__cxa_guard_release ((__cxxabiv1::__guard*)GVTOP(Args[0]));
+  return GenericValue();
+}
+
 } // End extern "C"
 
 
@@ -719,6 +754,8 @@
   FuncNames["lle_X_free"]         = lle_X_free;
   FuncNames["lle_X_atoi"]         = lle_X_atoi;
   FuncNames["lle_X_pow"]          = lle_X_pow;
+  FuncNames["lle_X_sin"]          = lle_X_sin;
+  FuncNames["lle_X_cos"]          = lle_X_cos;
   FuncNames["lle_X_exp"]          = lle_X_exp;
   FuncNames["lle_X_log"]          = lle_X_log;
   FuncNames["lle_X_floor"]        = lle_X_floor;
@@ -759,5 +796,8 @@
   FuncNames["lle_X_ungetc"]       = lle_X_ungetc;
   FuncNames["lle_X_fprintf"]      = lle_X_fprintf;
   FuncNames["lle_X_freopen"]      = lle_X_freopen;
+
+  FuncNames["lle_X___cxa_guard_acquire"] = lle_X___cxa_guard_acquire;
+  FuncNames["lle_X____cxa_guard_release"] = lle_X___cxa_guard_release;
 }
 

Added: llvm/trunk/test/ExecutionEngine/2007-12-11-APIntExFuncCall.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/2007-12-11-APIntExFuncCall.ll?rev=44910&view=auto

==============================================================================
--- llvm/trunk/test/ExecutionEngine/2007-12-11-APIntExFuncCall.ll (added)
+++ llvm/trunk/test/ExecutionEngine/2007-12-11-APIntExFuncCall.ll Tue Dec 11 22:55:43 2007
@@ -0,0 +1,54 @@
+; RUN: llvm-as < %s -o - | lli -force-interpreter
+; PR1629
+
+; ModuleID = '<stdin>'
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i686-pc-linux-gnu"
+	%struct.X = type { i32 }
+ at _ZGVZ4mainE1a = internal global i64 0, align 8		; <i64*> [#uses=3]
+ at _ZZ4mainE1a = internal global %struct.X zeroinitializer		; <%struct.X*> [#uses=1]
+
+define i32 @main() nounwind  {
+entry:
+	%"alloca point" = bitcast i32 0 to i32		; <i32> [#uses=0]
+	%tmp2 = call double @sin( double 1.999000e+00 ) nounwind readonly 		; <double> [#uses=1]
+	%tmp3 = call double @cos( double 1.990000e+00 ) nounwind readonly 		; <double> [#uses=1]
+	%tmp4 = add double %tmp2, %tmp3		; <double> [#uses=1]
+	%tmp5 = load i8* bitcast (i64* @_ZGVZ4mainE1a to i8*), align 1		; <i8> [#uses=1]
+	%tmp6 = icmp eq i8 %tmp5, 0		; <i1> [#uses=1]
+	%tmp67 = zext i1 %tmp6 to i8		; <i8> [#uses=1]
+	%toBool = icmp ne i8 %tmp67, 0		; <i1> [#uses=1]
+	br i1 %toBool, label %cond_true, label %cond_next14
+
+cond_true:		; preds = %entry
+	%tmp8 = call i32 @__cxa_guard_acquire( i64* @_ZGVZ4mainE1a ) nounwind 		; <i32> [#uses=1]
+	%tmp9 = icmp ne i32 %tmp8, 0		; <i1> [#uses=1]
+	%tmp910 = zext i1 %tmp9 to i8		; <i8> [#uses=1]
+	%toBool12 = icmp ne i8 %tmp910, 0		; <i1> [#uses=1]
+	br i1 %toBool12, label %cond_true13, label %cond_next14
+
+cond_true13:		; preds = %cond_true
+	call void @_ZN1XC1Ei( %struct.X* @_ZZ4mainE1a, i32 0 ) nounwind 
+	call void @__cxa_guard_release( i64* @_ZGVZ4mainE1a ) nounwind 
+	br label %cond_next14
+
+cond_next14:		; preds = %cond_true13, %cond_true, %entry
+	%tmp1516 = fptosi double %tmp4 to i32		; <i32> [#uses=1]
+	ret i32 %tmp1516
+}
+
+define linkonce void @_ZN1XC1Ei(%struct.X* %this, i32 %val) nounwind  {
+entry:
+	%"alloca point" = bitcast i32 0 to i32		; <i32> [#uses=0]
+	%tmp1 = getelementptr %struct.X* %this, i32 0, i32 0		; <i32*> [#uses=1]
+	store i32 %val, i32* %tmp1, align 4
+	ret void
+}
+
+declare double @sin(double) nounwind readonly 
+
+declare double @cos(double) nounwind readonly 
+
+declare i32 @__cxa_guard_acquire(i64*) nounwind 
+
+declare void @__cxa_guard_release(i64*) nounwind 





More information about the llvm-commits mailing list