Fixed PR1629.

Make lli interpreter correctly call external functions sin()/cos(),
__cxa_guard_acquire() and __cxa_guard_release().


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44910 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Zhou Sheng 2007-12-12 04:55:43 +00:00
parent 7f135cc802
commit 6a7951ce9b
2 changed files with 94 additions and 0 deletions

View File

@ -29,6 +29,7 @@
#include <csignal>
#include <map>
#include <cmath>
#include <cxxabi.h>
using std::vector;
using namespace llvm;
@ -200,6 +201,22 @@ GenericValue lle_X_pow(FunctionType *FT, const vector<GenericValue> &Args) {
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 @@ GenericValue lle_X_fprintf(FunctionType *FT, const vector<GenericValue> &Args) {
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 @@ void Interpreter::initializeExternalFunctions() {
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 @@ void Interpreter::initializeExternalFunctions() {
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;
}

View File

@ -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 }
@_ZGVZ4mainE1a = internal global i64 0, align 8 ; <i64*> [#uses=3]
@_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