[PATCH] D88367: [LLVM-C] Turn a ShuffleVector Constant Into a Getter.

Robert Widmann via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 26 15:39:21 PDT 2020


CodaFi created this revision.
CodaFi added a reviewer: cdisselkoen.
Herald added a reviewer: deadalnix.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
CodaFi requested review of this revision.

It is not a good idea to expose raw constants in the LLVM C API. Replace this with an explicit getter.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88367

Files:
  llvm/include/llvm-c/Core.h
  llvm/lib/IR/Core.cpp
  llvm/tools/llvm-c-test/echo.cpp


Index: llvm/tools/llvm-c-test/echo.cpp
===================================================================
--- llvm/tools/llvm-c-test/echo.cpp
+++ llvm/tools/llvm-c-test/echo.cpp
@@ -809,7 +809,7 @@
         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));
Index: llvm/lib/IR/Core.cpp
===================================================================
--- llvm/lib/IR/Core.cpp
+++ llvm/lib/IR/Core.cpp
@@ -3963,9 +3963,10 @@
   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 ShuffleVectorInst::UndefMaskElem;
+}
 
 LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst) {
   Value *P = unwrap<Value>(AtomicInst);
Index: llvm/include/llvm-c/Core.h
===================================================================
--- llvm/include/llvm-c/Core.h
+++ llvm/include/llvm-c/Core.h
@@ -3942,13 +3942,19 @@
  */
 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
+ * 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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88367.294519.patch
Type: text/x-patch
Size: 2127 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200926/25e01fc2/attachment.bin>


More information about the llvm-commits mailing list