diff --git a/lib/Bitcode/Writer/ValueEnumerator.cpp b/lib/Bitcode/Writer/ValueEnumerator.cpp index 75710d6c93c..6177202bcce 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -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()); } diff --git a/lib/IR/LLVMContextImpl.cpp b/lib/IR/LLVMContextImpl.cpp index e998138ec3c..99819602c54 100644 --- a/lib/IR/LLVMContextImpl.cpp +++ b/lib/IR/LLVMContextImpl.cpp @@ -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 #include using namespace llvm; +static cl::opt + ForceOpaquePointersCL("force-opaque-pointers", + cl::desc("Force all pointers to be opaque pointers"), + cl::init(false)); + LLVMContextImpl::LLVMContextImpl(LLVMContext &C) - : DiagHandler(std::make_unique()), - 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()), + 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 diff --git a/lib/IR/LLVMContextImpl.h b/lib/IR/LLVMContextImpl.h index f257901c12c..2ae23fdc95a 100644 --- a/lib/IR/LLVMContextImpl.h +++ b/lib/IR/LLVMContextImpl.h @@ -1447,6 +1447,7 @@ public: DenseMap, VectorType*> VectorTypes; // TODO: clean up the following after we no longer support non-opaque pointer // types. + bool ForceOpaquePointers; DenseMap PointerTypes; // Pointers in AddrSpace = 0 DenseMap, PointerType*> ASPointerTypes; diff --git a/lib/IR/Type.cpp b/lib/IR/Type.cpp index 8c960f614af..e7716cd445e 100644 --- a/lib/IR/Type.cpp +++ b/lib/IR/Type.cpp @@ -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 #include @@ -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)]; diff --git a/test/Other/force-opaque-ptrs.ll b/test/Other/force-opaque-ptrs.ll new file mode 100644 index 00000000000..fa1d9e0237b --- /dev/null +++ b/test/Other/force-opaque-ptrs.ll @@ -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 +} diff --git a/tools/llvm-as/llvm-as.cpp b/tools/llvm-as/llvm-as.cpp index f2b52890a7f..307a7f9b799 100644 --- a/tools/llvm-as/llvm-as.cpp +++ b/tools/llvm-as/llvm-as.cpp @@ -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; diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp index 9bf45978db4..b0103f75bb6 100644 --- a/tools/llvm-dis/llvm-dis.cpp +++ b/tools/llvm-dis/llvm-dis.cpp @@ -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(argv[0])); - cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n"); if (InputFilenames.size() < 1) { InputFilenames.push_back("-"); diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index ee0b05d7702..c34b10ce799 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -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;