Add various binary operations in the LLVM C API echo test

Summary: This diff increase the tested surface of the C API.

Reviewers: bogner, chandlerc, echristo, dblaikie, joker.eph, Wallbraker

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D16910

llvm-svn: 259863
This commit is contained in:
Amaury Sechet 2016-02-05 01:27:11 +00:00
parent 1681091991
commit b6df435db9
2 changed files with 87 additions and 3 deletions

View File

@ -21,12 +21,24 @@ define void @types() {
ret void
}
define i32 @add(i32 %a, i32 %b) {
define i32 @iops(i32 %a, i32 %b) {
%1 = add i32 %a, %b
ret i32 %1
%2 = mul i32 %a, %1
%3 = sub i32 %2, %1
%4 = udiv i32 %3, %b
%5 = sdiv i32 %2, %4
%6 = urem i32 %3, %5
%7 = srem i32 %2, %6
%8 = shl i32 %1, %b
%9 = lshr i32 %a, %7
%10 = ashr i32 %b, %8
%11 = and i32 %9, %10
%12 = or i32 %2, %11
%13 = xor i32 %12, %4
ret i32 %13
}
define i32 @call() {
%1 = call i32 @add(i32 23, i32 19)
%1 = call i32 @iops(i32 23, i32 19)
ret i32 %1
}

View File

@ -215,6 +215,78 @@ static LLVMValueRef clone_value(LLVMValueRef Src, LLVMBuilderRef Builder, ValueM
Dst = LLVMBuildAdd(Builder, LHS, RHS, Name);
break;
}
case LLVMSub: {
LLVMValueRef LHS = clone_value(LLVMGetOperand(Src, 0), Builder, VMap);
LLVMValueRef RHS = clone_value(LLVMGetOperand(Src, 1), Builder, VMap);
Dst = LLVMBuildSub(Builder, LHS, RHS, Name);
break;
}
case LLVMMul: {
LLVMValueRef LHS = clone_value(LLVMGetOperand(Src, 0), Builder, VMap);
LLVMValueRef RHS = clone_value(LLVMGetOperand(Src, 1), Builder, VMap);
Dst = LLVMBuildMul(Builder, LHS, RHS, Name);
break;
}
case LLVMUDiv: {
LLVMValueRef LHS = clone_value(LLVMGetOperand(Src, 0), Builder, VMap);
LLVMValueRef RHS = clone_value(LLVMGetOperand(Src, 1), Builder, VMap);
Dst = LLVMBuildUDiv(Builder, LHS, RHS, Name);
break;
}
case LLVMSDiv: {
LLVMValueRef LHS = clone_value(LLVMGetOperand(Src, 0), Builder, VMap);
LLVMValueRef RHS = clone_value(LLVMGetOperand(Src, 1), Builder, VMap);
Dst = LLVMBuildSDiv(Builder, LHS, RHS, Name);
break;
}
case LLVMURem: {
LLVMValueRef LHS = clone_value(LLVMGetOperand(Src, 0), Builder, VMap);
LLVMValueRef RHS = clone_value(LLVMGetOperand(Src, 1), Builder, VMap);
Dst = LLVMBuildURem(Builder, LHS, RHS, Name);
break;
}
case LLVMSRem: {
LLVMValueRef LHS = clone_value(LLVMGetOperand(Src, 0), Builder, VMap);
LLVMValueRef RHS = clone_value(LLVMGetOperand(Src, 1), Builder, VMap);
Dst = LLVMBuildSRem(Builder, LHS, RHS, Name);
break;
}
case LLVMShl: {
LLVMValueRef LHS = clone_value(LLVMGetOperand(Src, 0), Builder, VMap);
LLVMValueRef RHS = clone_value(LLVMGetOperand(Src, 1), Builder, VMap);
Dst = LLVMBuildShl(Builder, LHS, RHS, Name);
break;
}
case LLVMLShr: {
LLVMValueRef LHS = clone_value(LLVMGetOperand(Src, 0), Builder, VMap);
LLVMValueRef RHS = clone_value(LLVMGetOperand(Src, 1), Builder, VMap);
Dst = LLVMBuildLShr(Builder, LHS, RHS, Name);
break;
}
case LLVMAShr: {
LLVMValueRef LHS = clone_value(LLVMGetOperand(Src, 0), Builder, VMap);
LLVMValueRef RHS = clone_value(LLVMGetOperand(Src, 1), Builder, VMap);
Dst = LLVMBuildAShr(Builder, LHS, RHS, Name);
break;
}
case LLVMAnd: {
LLVMValueRef LHS = clone_value(LLVMGetOperand(Src, 0), Builder, VMap);
LLVMValueRef RHS = clone_value(LLVMGetOperand(Src, 1), Builder, VMap);
Dst = LLVMBuildAnd(Builder, LHS, RHS, Name);
break;
}
case LLVMOr: {
LLVMValueRef LHS = clone_value(LLVMGetOperand(Src, 0), Builder, VMap);
LLVMValueRef RHS = clone_value(LLVMGetOperand(Src, 1), Builder, VMap);
Dst = LLVMBuildOr(Builder, LHS, RHS, Name);
break;
}
case LLVMXor: {
LLVMValueRef LHS = clone_value(LLVMGetOperand(Src, 0), Builder, VMap);
LLVMValueRef RHS = clone_value(LLVMGetOperand(Src, 1), Builder, VMap);
Dst = LLVMBuildXor(Builder, LHS, RHS, Name);
break;
}
case LLVMAlloca: {
LLVMTypeRef Ty = LLVMGetElementType(LLVMTypeOf(Src));
Dst = LLVMBuildAlloca(Builder, Ty, Name);