diff options
author | Nikita Popov <npopov@redhat.com> | 2021-12-16 09:36:42 +0100 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2021-12-17 08:54:18 +0100 |
commit | 65777addbd397f537d0e17595b5efea2db9e90a8 (patch) | |
tree | 36457b8496a7105bc00b89c26e66280c048bf5aa /llvm/tools/llvm-c-test/echo.cpp | |
parent | aa27bab5a1a17e9c4168a741a6298ecaa92c1ecb (diff) | |
download | llvm-65777addbd397f537d0e17595b5efea2db9e90a8.zip llvm-65777addbd397f537d0e17595b5efea2db9e90a8.tar.gz llvm-65777addbd397f537d0e17595b5efea2db9e90a8.tar.bz2 |
[llvm-c] Accept GEP operators in some APIs
As requested in D115787, I've added a test for LLVMConstGEP2 and
LLVMConstInBoundsGEP2. However, to make this work in the echo test,
I also had to change a couple of APIs to work on GEP operators,
rather than only GEP instructions.
Differential Revision: https://reviews.llvm.org/D115858
Diffstat (limited to 'llvm/tools/llvm-c-test/echo.cpp')
-rw-r--r-- | llvm/tools/llvm-c-test/echo.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/tools/llvm-c-test/echo.cpp b/llvm/tools/llvm-c-test/echo.cpp index 61b7158..4a9b915 100644 --- a/llvm/tools/llvm-c-test/echo.cpp +++ b/llvm/tools/llvm-c-test/echo.cpp @@ -402,6 +402,19 @@ static LLVMValueRef clone_constant_impl(LLVMValueRef Cst, LLVMModuleRef M) { case LLVMBitCast: return LLVMConstBitCast(clone_constant(LLVMGetOperand(Cst, 0), M), TypeCloner(M).Clone(Cst)); + case LLVMGetElementPtr: { + LLVMTypeRef ElemTy = + TypeCloner(M).Clone(LLVMGetGEPSourceElementType(Cst)); + LLVMValueRef Ptr = clone_constant(LLVMGetOperand(Cst, 0), M); + int NumIdx = LLVMGetNumIndices(Cst); + SmallVector<LLVMValueRef, 8> Idx; + for (int i = 1; i <= NumIdx; i++) + Idx.push_back(clone_constant(LLVMGetOperand(Cst, i), M)); + if (LLVMIsInBounds(Cst)) + return LLVMConstInBoundsGEP2(ElemTy, Ptr, Idx.data(), NumIdx); + else + return LLVMConstGEP2(ElemTy, Ptr, Idx.data(), NumIdx); + } default: fprintf(stderr, "%d is not a supported opcode for constant expressions\n", Op); |