[PATCH] D103503: [OpaquePtr] Introduce option to force all pointers to be opaque pointers

Arthur Eubanks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 1 21:38:44 PDT 2021


aeubanks created this revision.
aeubanks added a reviewer: dblaikie.
Herald added subscribers: dexonsmith, hiraditya.
aeubanks requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Previously ValueEnumerator would visit the value types of global values
via the pointer type, but with opaque pointers we have to manually visit
the value type.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103503

Files:
  llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
  llvm/lib/IR/Type.cpp
  llvm/test/Other/force-opaque-ptrs.ll


Index: llvm/test/Other/force-opaque-ptrs.ll
===================================================================
--- /dev/null
+++ llvm/test/Other/force-opaque-ptrs.ll
@@ -0,0 +1,7 @@
+; RUN: llvm-as --force-opaque-pointers < %s | llvm-dis | FileCheck %s
+
+; CHECK: define ptr @f(ptr %a)
+; CHECK:   ret ptr %a
+define i32* @f(i32* %a) {
+  ret i32* %a
+}
Index: llvm/lib/IR/Type.cpp
===================================================================
--- llvm/lib/IR/Type.cpp
+++ llvm/lib/IR/Type.cpp
@@ -24,14 +24,20 @@
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Value.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/MathExtras.h"
-#include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/TypeSize.h"
+#include "llvm/Support/raw_ostream.h"
 #include <cassert>
 #include <utility>
 
 using namespace llvm;
 
+static cl::opt<bool>
+    ForceOpaquePointers("force-opaque-pointers",
+                        cl::desc("Force all pointers to be opaque pointers"),
+                        cl::init(false));
+
 //===----------------------------------------------------------------------===//
 //                         Type Class Implementation
 //===----------------------------------------------------------------------===//
@@ -685,6 +691,9 @@
 //===----------------------------------------------------------------------===//
 
 PointerType *PointerType::get(Type *EltTy, unsigned AddressSpace) {
+  if (ForceOpaquePointers)
+    return get(EltTy->getContext(), AddressSpace);
+
   assert(EltTy && "Can't get a pointer to <null> type!");
   assert(isValidElementType(EltTy) && "Invalid type for pointer element!");
 
Index: llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
===================================================================
--- llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
+++ llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
@@ -364,22 +364,29 @@
     UseListOrders = predictUseListOrder(M);
 
   // Enumerate the global variables.
-  for (const GlobalVariable &GV : M.globals())
+  for (const GlobalVariable &GV : M.globals()) {
     EnumerateValue(&GV);
+    EnumerateType(GV.getValueType());
+  }
 
   // Enumerate the functions.
   for (const Function & F : M) {
     EnumerateValue(&F);
+    EnumerateType(F.getValueType());
     EnumerateAttributes(F.getAttributes());
   }
 
   // Enumerate the aliases.
-  for (const GlobalAlias &GA : M.aliases())
+  for (const GlobalAlias &GA : M.aliases()) {
     EnumerateValue(&GA);
+    EnumerateType(GA.getValueType());
+  }
 
   // Enumerate the ifuncs.
-  for (const GlobalIFunc &GIF : M.ifuncs())
+  for (const GlobalIFunc &GIF : M.ifuncs()) {
     EnumerateValue(&GIF);
+    EnumerateType(GIF.getValueType());
+  }
 
   // Remember what is the cutoff between globalvalue's and other constants.
   unsigned FirstConstant = Values.size();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103503.349171.patch
Type: text/x-patch
Size: 2858 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210602/eedf6df3/attachment.bin>


More information about the llvm-commits mailing list