Skip to content

Commit

Permalink
[LLVM-C] Turn a ShuffleVector Constant Into a Getter.
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
CodaFi authored and zmodem committed Sep 28, 2020
1 parent 9e367bd commit 2939249
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
13 changes: 10 additions & 3 deletions llvm/include/llvm-c/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -3942,13 +3942,20 @@ LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef Ptr,
*/
unsigned LLVMGetNumMaskElements(LLVMValueRef ShuffleVectorInst);

/**
* \returns a constant that specifies that the result of a \c ShuffleVectorInst
* is undefined.
*/
int LLVMGetUndefMaskElem(void);

/**
* Get the mask value at position Elt in the mask of a ShuffleVector
* instruction. Return LLVMUndefMaskElem if the mask value is undef at that
* position.
* instruction.
*
* \Returns the result of \c LLVMGetUndefMaskElem() if the mask value is undef
* at that position.
*/
int LLVMGetMaskValue(LLVMValueRef ShuffleVectorInst, unsigned Elt);
extern const int LLVMUndefMaskElem;

LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst);
void LLVMSetAtomicSingleThread(LLVMValueRef AtomicInst, LLVMBool SingleThread);
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/IR/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3963,9 +3963,8 @@ int LLVMGetMaskValue(LLVMValueRef SVInst, unsigned Elt) {
ShuffleVectorInst *I = cast<ShuffleVectorInst>(P);
return I->getMaskValue(Elt);
}
const int LLVMUndefMaskElem =
-1; // not actually accessible as ShuffleVectorInst::UndefMaskElem, so we
// hardcode it here

int LLVMGetUndefMaskElem(void) { return UndefMaskElem; }

LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst) {
Value *P = unwrap<Value>(AtomicInst);
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-c-test/echo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ struct FunCloner {
unsigned NumMaskElts = LLVMGetNumMaskElements(Src);
for (unsigned i = 0; i < NumMaskElts; i++) {
int Val = LLVMGetMaskValue(Src, i);
if (Val == LLVMUndefMaskElem) {
if (Val == LLVMGetUndefMaskElem()) {
MaskElts.push_back(LLVMGetUndef(LLVMInt64Type()));
} else {
MaskElts.push_back(LLVMConstInt(LLVMInt64Type(), Val, true));
Expand Down

0 comments on commit 2939249

Please sign in to comment.