Skip to content

Commit 2939249

Browse files
CodaFizmodem
authored andcommitted
[LLVM-C] Turn a ShuffleVector Constant Into a Getter.
It is not a good idea to expose raw constants in the LLVM C API. Replace this with an explicit getter. Differential Revision: https://reviews.llvm.org/D88367 (cherry picked from commit 55f7273)
1 parent 9e367bd commit 2939249

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

llvm/include/llvm-c/Core.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3942,13 +3942,20 @@ LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef Ptr,
39423942
*/
39433943
unsigned LLVMGetNumMaskElements(LLVMValueRef ShuffleVectorInst);
39443944

3945+
/**
3946+
* \returns a constant that specifies that the result of a \c ShuffleVectorInst
3947+
* is undefined.
3948+
*/
3949+
int LLVMGetUndefMaskElem(void);
3950+
39453951
/**
39463952
* Get the mask value at position Elt in the mask of a ShuffleVector
3947-
* instruction. Return LLVMUndefMaskElem if the mask value is undef at that
3948-
* position.
3953+
* instruction.
3954+
*
3955+
* \Returns the result of \c LLVMGetUndefMaskElem() if the mask value is undef
3956+
* at that position.
39493957
*/
39503958
int LLVMGetMaskValue(LLVMValueRef ShuffleVectorInst, unsigned Elt);
3951-
extern const int LLVMUndefMaskElem;
39523959

39533960
LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst);
39543961
void LLVMSetAtomicSingleThread(LLVMValueRef AtomicInst, LLVMBool SingleThread);

llvm/lib/IR/Core.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3963,9 +3963,8 @@ int LLVMGetMaskValue(LLVMValueRef SVInst, unsigned Elt) {
39633963
ShuffleVectorInst *I = cast<ShuffleVectorInst>(P);
39643964
return I->getMaskValue(Elt);
39653965
}
3966-
const int LLVMUndefMaskElem =
3967-
-1; // not actually accessible as ShuffleVectorInst::UndefMaskElem, so we
3968-
// hardcode it here
3966+
3967+
int LLVMGetUndefMaskElem(void) { return UndefMaskElem; }
39693968

39703969
LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst) {
39713970
Value *P = unwrap<Value>(AtomicInst);

llvm/tools/llvm-c-test/echo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ struct FunCloner {
809809
unsigned NumMaskElts = LLVMGetNumMaskElements(Src);
810810
for (unsigned i = 0; i < NumMaskElts; i++) {
811811
int Val = LLVMGetMaskValue(Src, i);
812-
if (Val == LLVMUndefMaskElem) {
812+
if (Val == LLVMGetUndefMaskElem()) {
813813
MaskElts.push_back(LLVMGetUndef(LLVMInt64Type()));
814814
} else {
815815
MaskElts.push_back(LLVMConstInt(LLVMInt64Type(), Val, true));

0 commit comments

Comments
 (0)