[llvm] 573a9bc - [llvm-c] Avoid deprecated APIs in tests
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 4 09:58:16 PST 2021
Author: Nikita Popov
Date: 2021-12-04T18:58:08+01:00
New Revision: 573a9bc4ad7fed92db5105ea75e0f9573712f973
URL: https://github.com/llvm/llvm-project/commit/573a9bc4ad7fed92db5105ea75e0f9573712f973
DIFF: https://github.com/llvm/llvm-project/commit/573a9bc4ad7fed92db5105ea75e0f9573712f973.diff
LOG: [llvm-c] Avoid deprecated APIs in tests
Avoid the use of deprecated (opaque pointer incompatible) APIs
in C API tests, in preparation for header deprecation. Add a
LLVMGetGEPSourceElementType() to cover a bit of functionality
that is necessary for the echo test.
This change is split out from https://reviews.llvm.org/D114936.
Added:
Modified:
llvm/include/llvm-c/Core.h
llvm/lib/IR/Core.cpp
llvm/tools/llvm-c-test/calc.c
llvm/tools/llvm-c-test/echo.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index f2183ff52bfbe..2efb4d088709e 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -3506,6 +3506,11 @@ LLVMBool LLVMIsInBounds(LLVMValueRef GEP);
*/
void LLVMSetIsInBounds(LLVMValueRef GEP, LLVMBool InBounds);
+/**
+ * Get the source element type of the given GEP instruction.
+ */
+LLVMTypeRef LLVMGetGEPSourceElementType(LLVMValueRef GEP);
+
/**
* @}
*/
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index 2c396ae974995..6104a79e882e3 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -3014,6 +3014,10 @@ void LLVMSetIsInBounds(LLVMValueRef GEP, LLVMBool InBounds) {
return unwrap<GetElementPtrInst>(GEP)->setIsInBounds(InBounds);
}
+LLVMTypeRef LLVMGetGEPSourceElementType(LLVMValueRef GEP) {
+ return wrap(unwrap<GetElementPtrInst>(GEP)->getSourceElementType());
+}
+
/*--.. Operations on phi nodes .............................................--*/
void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
diff --git a/llvm/tools/llvm-c-test/calc.c b/llvm/tools/llvm-c-test/calc.c
index bd7aff41ba4fc..267397a373fbd 100644
--- a/llvm/tools/llvm-c-test/calc.c
+++ b/llvm/tools/llvm-c-test/calc.c
@@ -74,8 +74,9 @@ static LLVMValueRef build_from_tokens(char **tokens, int ntokens,
return NULL;
}
- off = LLVMBuildGEP(builder, param, &stack[depth - 1], 1, "");
- stack[depth - 1] = LLVMBuildLoad(builder, off, "");
+ LLVMTypeRef ty = LLVMInt64Type();
+ off = LLVMBuildGEP2(builder, ty, param, &stack[depth - 1], 1, "");
+ stack[depth - 1] = LLVMBuildLoad2(builder, ty, off, "");
break;
}
diff --git a/llvm/tools/llvm-c-test/echo.cpp b/llvm/tools/llvm-c-test/echo.cpp
index 4475cbedc4147..61b71580a55a0 100644
--- a/llvm/tools/llvm-c-test/echo.cpp
+++ b/llvm/tools/llvm-c-test/echo.cpp
@@ -524,11 +524,12 @@ struct FunCloner {
int ArgCount = LLVMGetNumArgOperands(Src);
for (int i = 0; i < ArgCount; i++)
Args.push_back(CloneValue(LLVMGetOperand(Src, i)));
+ LLVMTypeRef FnTy = CloneType(LLVMGetCalledFunctionType(Src));
LLVMValueRef Fn = CloneValue(LLVMGetCalledValue(Src));
LLVMBasicBlockRef Then = DeclareBB(LLVMGetNormalDest(Src));
LLVMBasicBlockRef Unwind = DeclareBB(LLVMGetUnwindDest(Src));
- Dst = LLVMBuildInvoke(Builder, Fn, Args.data(), ArgCount,
- Then, Unwind, Name);
+ Dst = LLVMBuildInvoke2(Builder, FnTy, Fn, Args.data(), ArgCount,
+ Then, Unwind, Name);
CloneAttrs(Src, Dst);
break;
}
@@ -621,7 +622,7 @@ struct FunCloner {
}
case LLVMLoad: {
LLVMValueRef Ptr = CloneValue(LLVMGetOperand(Src, 0));
- Dst = LLVMBuildLoad(Builder, Ptr, Name);
+ Dst = LLVMBuildLoad2(Builder, CloneType(Src), Ptr, Name);
LLVMSetAlignment(Dst, LLVMGetAlignment(Src));
LLVMSetOrdering(Dst, LLVMGetOrdering(Src));
LLVMSetVolatile(Dst, LLVMGetVolatile(Src));
@@ -637,15 +638,17 @@ struct FunCloner {
break;
}
case LLVMGetElementPtr: {
+ LLVMTypeRef ElemTy = CloneType(LLVMGetGEPSourceElementType(Src));
LLVMValueRef Ptr = CloneValue(LLVMGetOperand(Src, 0));
SmallVector<LLVMValueRef, 8> Idx;
int NumIdx = LLVMGetNumIndices(Src);
for (int i = 1; i <= NumIdx; i++)
Idx.push_back(CloneValue(LLVMGetOperand(Src, i)));
if (LLVMIsInBounds(Src))
- Dst = LLVMBuildInBoundsGEP(Builder, Ptr, Idx.data(), NumIdx, Name);
+ Dst = LLVMBuildInBoundsGEP2(Builder, ElemTy, Ptr, Idx.data(), NumIdx,
+ Name);
else
- Dst = LLVMBuildGEP(Builder, Ptr, Idx.data(), NumIdx, Name);
+ Dst = LLVMBuildGEP2(Builder, ElemTy, Ptr, Idx.data(), NumIdx, Name);
break;
}
case LLVMAtomicRMW: {
@@ -709,8 +712,9 @@ struct FunCloner {
int ArgCount = LLVMGetNumArgOperands(Src);
for (int i = 0; i < ArgCount; i++)
Args.push_back(CloneValue(LLVMGetOperand(Src, i)));
+ LLVMTypeRef FnTy = CloneType(LLVMGetCalledFunctionType(Src));
LLVMValueRef Fn = CloneValue(LLVMGetCalledValue(Src));
- Dst = LLVMBuildCall(Builder, Fn, Args.data(), ArgCount, Name);
+ Dst = LLVMBuildCall2(Builder, FnTy, Fn, Args.data(), ArgCount, Name);
LLVMSetTailCall(Dst, LLVMIsTailCall(Src));
CloneAttrs(Src, Dst);
break;
More information about the llvm-commits
mailing list