1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 10:32:48 +02:00

[OpaquePtr] Introduce option to force all pointers to be opaque pointers

We don't want to start updating tests to use opaque pointers until we're
close to the opaque pointer transition. However, before the transition
we want to run tests as if pointers are opaque pointers to see if there
are any crashes.

At some point when we have a flag to only create opaque pointers in the
bitcode and textual IR readers, and when we have fixed all places that
try to read a pointee type, this flag will be useless. However, until
then, this can help us find issues more easily.

Since the cl::opt is read into LLVMContext, we need to make sure
LLVMContext is created after cl::ParseCommandLineOptions().

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.

Reviewed By: nikic, dexonsmith

Differential Revision: https://reviews.llvm.org/D103503
This commit is contained in:
Arthur Eubanks 2021-06-24 08:21:24 -07:00
parent c31c3a54f4
commit 5cfe2f65b5
8 changed files with 36 additions and 25 deletions

View File

@ -371,6 +371,7 @@ ValueEnumerator::ValueEnumerator(const Module &M,
// Enumerate the functions.
for (const Function & F : M) {
EnumerateValue(&F);
EnumerateType(F.getValueType());
EnumerateAttributes(F.getAttributes());
}

View File

@ -15,33 +15,29 @@
#include "llvm/IR/Module.h"
#include "llvm/IR/OptBisect.h"
#include "llvm/IR/Type.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
#include <cassert>
#include <utility>
using namespace llvm;
static cl::opt<bool>
ForceOpaquePointersCL("force-opaque-pointers",
cl::desc("Force all pointers to be opaque pointers"),
cl::init(false));
LLVMContextImpl::LLVMContextImpl(LLVMContext &C)
: DiagHandler(std::make_unique<DiagnosticHandler>()),
VoidTy(C, Type::VoidTyID),
LabelTy(C, Type::LabelTyID),
HalfTy(C, Type::HalfTyID),
BFloatTy(C, Type::BFloatTyID),
FloatTy(C, Type::FloatTyID),
DoubleTy(C, Type::DoubleTyID),
MetadataTy(C, Type::MetadataTyID),
TokenTy(C, Type::TokenTyID),
X86_FP80Ty(C, Type::X86_FP80TyID),
FP128Ty(C, Type::FP128TyID),
PPC_FP128Ty(C, Type::PPC_FP128TyID),
X86_MMXTy(C, Type::X86_MMXTyID),
X86_AMXTy(C, Type::X86_AMXTyID),
Int1Ty(C, 1),
Int8Ty(C, 8),
Int16Ty(C, 16),
Int32Ty(C, 32),
Int64Ty(C, 64),
Int128Ty(C, 128) {}
: DiagHandler(std::make_unique<DiagnosticHandler>()),
VoidTy(C, Type::VoidTyID), LabelTy(C, Type::LabelTyID),
HalfTy(C, Type::HalfTyID), BFloatTy(C, Type::BFloatTyID),
FloatTy(C, Type::FloatTyID), DoubleTy(C, Type::DoubleTyID),
MetadataTy(C, Type::MetadataTyID), TokenTy(C, Type::TokenTyID),
X86_FP80Ty(C, Type::X86_FP80TyID), FP128Ty(C, Type::FP128TyID),
PPC_FP128Ty(C, Type::PPC_FP128TyID), X86_MMXTy(C, Type::X86_MMXTyID),
X86_AMXTy(C, Type::X86_AMXTyID), Int1Ty(C, 1), Int8Ty(C, 8),
Int16Ty(C, 16), Int32Ty(C, 32), Int64Ty(C, 64), Int128Ty(C, 128),
ForceOpaquePointers(ForceOpaquePointersCL) {}
LLVMContextImpl::~LLVMContextImpl() {
// NOTE: We need to delete the contents of OwnedModules, but Module's dtor

View File

@ -1447,6 +1447,7 @@ public:
DenseMap<std::pair<Type *, ElementCount>, VectorType*> VectorTypes;
// TODO: clean up the following after we no longer support non-opaque pointer
// types.
bool ForceOpaquePointers;
DenseMap<Type*, PointerType*> PointerTypes; // Pointers in AddrSpace = 0
DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes;

View File

@ -25,8 +25,8 @@
#include "llvm/IR/Value.h"
#include "llvm/Support/Casting.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>
@ -690,6 +690,9 @@ PointerType *PointerType::get(Type *EltTy, unsigned AddressSpace) {
LLVMContextImpl *CImpl = EltTy->getContext().pImpl;
if (CImpl->ForceOpaquePointers)
return get(EltTy->getContext(), AddressSpace);
// Since AddressSpace #0 is the common case, we special case it.
PointerType *&Entry = AddressSpace == 0 ? CImpl->PointerTypes[EltTy]
: CImpl->ASPointerTypes[std::make_pair(EltTy, AddressSpace)];

View File

@ -0,0 +1,9 @@
; RUN: llvm-as --force-opaque-pointers < %s | llvm-dis | FileCheck %s
; RUN: llvm-as < %s | llvm-dis --force-opaque-pointers | FileCheck %s
; RUN: opt --force-opaque-pointers < %s -S | FileCheck %s
; CHECK: define void @f(ptr %p)
; CHECK: ret void
define void @f(i32* %p) {
ret void
}

View File

@ -115,9 +115,9 @@ static void WriteOutputFile(const Module *M, const ModuleSummaryIndex *Index) {
int main(int argc, char **argv) {
InitLLVM X(argc, argv);
LLVMContext Context;
cl::HideUnrelatedOptions(AsCat);
cl::ParseCommandLineOptions(argc, argv, "llvm .ll -> .bc assembler\n");
LLVMContext Context;
// Parse the file now...
SMDiagnostic Err;

View File

@ -151,10 +151,11 @@ int main(int argc, char **argv) {
ExitOnErr.setBanner(std::string(argv[0]) + ": error: ");
cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n");
LLVMContext Context;
Context.setDiagnosticHandler(
std::make_unique<LLVMDisDiagnosticHandler>(argv[0]));
cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n");
if (InputFilenames.size() < 1) {
InputFilenames.push_back("-");

View File

@ -552,8 +552,6 @@ int main(int argc, char **argv) {
// Enable debug stream buffering.
EnableDebugBuffering = true;
LLVMContext Context;
InitializeAllTargets();
InitializeAllTargetMCs();
InitializeAllAsmPrinters();
@ -607,6 +605,8 @@ int main(int argc, char **argv) {
cl::ParseCommandLineOptions(argc, argv,
"llvm .bc -> .bc modular optimizer and analysis printer\n");
LLVMContext Context;
if (AnalyzeOnly && NoOutput) {
errs() << argv[0] << ": analyze mode conflicts with no-output mode.\n";
return 1;