Index: docs/LangRef.rst =================================================================== --- docs/LangRef.rst +++ docs/LangRef.rst @@ -719,7 +719,7 @@ :ref:`parameter attribute ` for the return type, a function name, a (possibly empty) argument list (each with optional :ref:`parameter attributes `), optional :ref:`function attributes `, -an optional section, an optional alignment, +an optional address space, an optional section, an optional alignment, an optional :ref:`comdat `, an optional :ref:`garbage collector name `, an optional :ref:`prefix `, an optional :ref:`prologue `, @@ -731,8 +731,8 @@ optional :ref:`linkage type `, an optional :ref:`visibility style `, an optional :ref:`DLL storage class `, an optional :ref:`calling convention `, an optional ``unnamed_addr`` -or ``local_unnamed_addr`` attribute, a return type, an optional :ref:`parameter -attribute ` for the return type, a function name, a possibly +or ``local_unnamed_addr`` attribute, an optional address space, a return type, +an optional :ref:`parameter attribute ` for the return type, a function name, a possibly empty list of arguments, an optional alignment, an optional :ref:`garbage collector name `, an optional :ref:`prefix `, and an optional :ref:`prologue `. @@ -769,13 +769,15 @@ If the ``local_unnamed_addr`` attribute is given, the address is known to not be significant within the module. +If an explicit address space is not given, it will default to zero. + Syntax:: define [linkage] [PreemptionSpecifier] [visibility] [DLLStorageClass] [cconv] [ret attrs] @ ([argument list]) - [(unnamed_addr|local_unnamed_addr)] [fn Attrs] [section "name"] - [comdat [($name)]] [align N] [gc] [prefix Constant] + [(unnamed_addr|local_unnamed_addr)] [AddrSpace] [fn Attrs] + [section "name"] [comdat [($name)]] [align N] [gc] [prefix Constant] [prologue Constant] [personality Constant] (!name !N)* { ... } The argument list is a comma separated sequence of arguments where each Index: include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h =================================================================== --- include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h +++ include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h @@ -609,7 +609,7 @@ if (Ty->isFunctionTy()) return Function::Create(cast(Ty), GlobalValue::ExternalLinkage, A->getName(), - M.get()); + *M.get()); return new GlobalVariable(*M, Ty, false, GlobalValue::ExternalLinkage, nullptr, A->getName(), nullptr, Index: include/llvm/IR/Function.h =================================================================== --- include/llvm/IR/Function.h +++ include/llvm/IR/Function.h @@ -120,7 +120,7 @@ /// function is automatically inserted into the end of the function list for /// the module. /// - Function(FunctionType *Ty, LinkageTypes Linkage, + Function(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N = "", Module *M = nullptr); public: @@ -134,10 +134,21 @@ const Function &getFunction() const { return *this; } static Function *Create(FunctionType *Ty, LinkageTypes Linkage, - const Twine &N = "", Module *M = nullptr) { - return new Function(Ty, Linkage, N, M); + unsigned AddrSpace, const Twine &N = "", + Module *M = nullptr) { + return new Function(Ty, Linkage, AddrSpace, N, M); } + /// Creates a new function and attaches it to a module. + /// + /// Places the function in the program address space as specified + /// by the module's data layout. + static Function *Create(FunctionType *Ty, LinkageTypes Linkage, + const Twine &N, Module &M); + + static Function *CreateBefore(Function &InsertBefore, FunctionType *Ty, + LinkageTypes Linkage, const Twine &N = ""); + // Provide fast operand accessors. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); Index: include/llvm/IR/GlobalValue.h =================================================================== --- include/llvm/IR/GlobalValue.h +++ include/llvm/IR/GlobalValue.h @@ -189,6 +189,7 @@ GlobalValue(const GlobalValue &) = delete; unsigned getAlignment() const; + unsigned getAddressSpace() const; enum class UnnamedAddr { None, Index: include/llvm/LinkAllPasses.h =================================================================== --- include/llvm/LinkAllPasses.h +++ include/llvm/LinkAllPasses.h @@ -213,7 +213,7 @@ (void)new llvm::IntervalPartition(); (void)new llvm::ScalarEvolutionWrapperPass(); - llvm::Function::Create(nullptr, llvm::GlobalValue::ExternalLinkage)->viewCFGOnly(); + llvm::Function::Create(nullptr, llvm::GlobalValue::ExternalLinkage, 0)->viewCFGOnly(); llvm::RGPassManager RGM; llvm::TargetLibraryInfoImpl TLII; llvm::TargetLibraryInfo TLI(TLII); Index: lib/AsmParser/LLParser.cpp =================================================================== --- lib/AsmParser/LLParser.cpp +++ lib/AsmParser/LLParser.cpp @@ -1194,7 +1194,8 @@ static inline GlobalValue *createGlobalFwdRef(Module *M, PointerType *PTy, const std::string &Name) { if (auto *FT = dyn_cast(PTy->getElementType())) - return Function::Create(FT, GlobalValue::ExternalWeakLinkage, Name, M); + return Function::Create(FT, GlobalValue::ExternalWeakLinkage, + PTy->getAddressSpace(), Name, M); else return new GlobalVariable(*M, PTy->getElementType(), false, GlobalValue::ExternalWeakLinkage, nullptr, Name, @@ -1227,6 +1228,17 @@ // If we have the value in the symbol table or fwd-ref table, return it. if (Val) { + // If we have two pointers that differ only by address space, + // we should still be able to resolve the value. + // + // For example, you always should be able to call a function by name + // without worrying about the address space it was declared with. + PointerType *ValPTy, *PTy; + if ((ValPTy = dyn_cast(Val->getType())) && + (PTy = dyn_cast(Ty))) { + return Val; + } + if (Val->getType() == Ty) return Val; Error(Loc, "'@" + Name + "' defined with type '" + getTypeString(Val->getType()) + "'"); @@ -4975,6 +4987,7 @@ unsigned Alignment; std::string GC; GlobalValue::UnnamedAddr UnnamedAddr = GlobalValue::UnnamedAddr::None; + unsigned AddrSpace = 0; Constant *Prefix = nullptr; Constant *Prologue = nullptr; Constant *PersonalityFn = nullptr; @@ -4982,6 +4995,7 @@ if (ParseArgumentList(ArgList, isVarArg) || ParseOptionalUnnamedAddr(UnnamedAddr) || + ParseOptionalAddrSpace(AddrSpace) || ParseFnAttributeValuePairs(FuncAttrs, FwdRefAttrGrps, false, BuiltinLoc) || (EatIfPresent(lltok::kw_section) && @@ -5065,7 +5079,8 @@ } if (!Fn) - Fn = Function::Create(FT, GlobalValue::ExternalLinkage, FunctionName, M); + Fn = Function::Create(FT, GlobalValue::ExternalLinkage, AddrSpace, + FunctionName, M); else // Move the forward-reference to the correct spot in the module. M->getFunctionList().splice(M->end(), M->getFunctionList(), Fn); Index: lib/Bitcode/Reader/BitcodeReader.cpp =================================================================== --- lib/Bitcode/Reader/BitcodeReader.cpp +++ lib/Bitcode/Reader/BitcodeReader.cpp @@ -2917,7 +2917,7 @@ Error BitcodeReader::parseFunctionRecord(ArrayRef Record) { // v1: [type, callingconv, isproto, linkage, paramattr, alignment, section, // visibility, gc, unnamed_addr, prologuedata, dllstorageclass, comdat, - // prefixdata, personalityfn, preemption specifier] (name in VST) + // prefixdata, personalityfn, preemption specifier, addrspace] (name in VST) // v2: [strtab_offset, strtab_size, v1] StringRef Name; std::tie(Name, Record) = readNameFromStrtab(Record); @@ -2936,8 +2936,13 @@ if (CC & ~CallingConv::MaxID) return error("Invalid calling convention ID"); + unsigned AddrSpace = TheModule->getDataLayout().getProgramAddressSpace(); + if (Record.size() > 16) + AddrSpace = Record[16]; + Function *Func = - Function::Create(FTy, GlobalValue::ExternalLinkage, Name, TheModule); + Function::Create(FTy, GlobalValue::ExternalLinkage, AddrSpace, Name, + TheModule); Func->setCallingConv(CC); bool isProto = Record[2]; Index: lib/Bitcode/Writer/BitcodeWriter.cpp =================================================================== --- lib/Bitcode/Writer/BitcodeWriter.cpp +++ lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1252,7 +1252,7 @@ // FUNCTION: [strtab offset, strtab size, type, callingconv, isproto, // linkage, paramattrs, alignment, section, visibility, gc, // unnamed_addr, prologuedata, dllstorageclass, comdat, - // prefixdata, personalityfn, DSO_Local] + // prefixdata, personalityfn, DSO_Local, addrspace] Vals.push_back(addToStrtab(F.getName())); Vals.push_back(F.getName().size()); Vals.push_back(VE.getTypeID(F.getFunctionType())); @@ -1275,6 +1275,8 @@ F.hasPersonalityFn() ? (VE.getValueID(F.getPersonalityFn()) + 1) : 0); Vals.push_back(F.isDSOLocal()); + Vals.push_back(F.getAddressSpace()); + unsigned AbbrevToUse = 0; Stream.EmitRecord(bitc::MODULE_CODE_FUNCTION, Vals, AbbrevToUse); Vals.clear(); Index: lib/ExecutionEngine/Orc/IndirectionUtils.cpp =================================================================== --- lib/ExecutionEngine/Orc/IndirectionUtils.cpp +++ lib/ExecutionEngine/Orc/IndirectionUtils.cpp @@ -179,7 +179,7 @@ assert(F.getParent() != &Dst && "Can't copy decl over existing function."); Function *NewF = Function::Create(cast(F.getValueType()), - F.getLinkage(), F.getName(), &Dst); + F.getLinkage(), F.getName(), Dst); NewF->copyAttributesFrom(&F); if (VMap) { Index: lib/FuzzMutate/IRMutator.cpp =================================================================== --- lib/FuzzMutate/IRMutator.cpp +++ lib/FuzzMutate/IRMutator.cpp @@ -28,7 +28,7 @@ LLVMContext &Context = M.getContext(); Function *F = Function::Create(FunctionType::get(Type::getVoidTy(Context), {}, /*isVarArg=*/false), - GlobalValue::ExternalLinkage, "f", &M); + GlobalValue::ExternalLinkage, "f", M); BasicBlock *BB = BasicBlock::Create(Context, "BB", F); ReturnInst::Create(Context, BB); } Index: lib/IR/AsmWriter.cpp =================================================================== --- lib/IR/AsmWriter.cpp +++ lib/IR/AsmWriter.cpp @@ -2791,6 +2791,8 @@ StringRef UA = getUnnamedAddrEncoding(F->getUnnamedAddr()); if (!UA.empty()) Out << ' ' << UA; + if (F->getAddressSpace() != 0) + Out << " addrspace(" << F->getAddressSpace() << ")"; if (Attrs.hasAttributes(AttributeList::FunctionIndex)) Out << " #" << Machine.getAttributeGroupSlot(Attrs.getFnAttributes()); if (F->hasSection()) { Index: lib/IR/AutoUpgrade.cpp =================================================================== --- lib/IR/AutoUpgrade.cpp +++ lib/IR/AutoUpgrade.cpp @@ -420,7 +420,7 @@ // the end of the name. Change name from llvm.arm.neon.vclz.* to // llvm.ctlz.* FunctionType* fType = FunctionType::get(F->getReturnType(), args, false); - NewFn = Function::Create(fType, F->getLinkage(), + NewFn = Function::Create(fType, F->getLinkage(), F->getAddressSpace(), "llvm.ctlz." + Name.substr(14), F->getParent()); return true; } @@ -436,7 +436,7 @@ // Can't use Intrinsic::getDeclaration here as the return types might // then only be structurally equal. FunctionType* fType = FunctionType::get(F->getReturnType(), Tys, false); - NewFn = Function::Create(fType, F->getLinkage(), + NewFn = Function::Create(fType, F->getLinkage(), F->getAddressSpace(), "llvm." + Name + ".p0i8", F->getParent()); return true; } Index: lib/IR/Core.cpp =================================================================== --- lib/IR/Core.cpp +++ lib/IR/Core.cpp @@ -1794,8 +1794,9 @@ LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name, LLVMTypeRef FunctionTy) { + auto &Mod = *unwrap(M); return wrap(Function::Create(unwrap(FunctionTy), - GlobalValue::ExternalLinkage, Name, unwrap(M))); + GlobalValue::ExternalLinkage, Name, Mod)); } LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name) { Index: lib/IR/Function.cpp =================================================================== --- lib/IR/Function.cpp +++ lib/IR/Function.cpp @@ -195,6 +195,22 @@ return getType()->getContext(); } +Function *Function::Create(FunctionType *Ty, LinkageTypes Linkage, + const Twine &N, Module &M) { + return Create(Ty, Linkage, M.getDataLayout().getProgramAddressSpace(), + N, &M); +} + +Function *Function::CreateBefore(Function &InsertBefore, FunctionType *Ty, + LinkageTypes Linkage, const Twine &N) { + auto &M = *InsertBefore.getParent(); + unsigned AddrSpace = M.getDataLayout().getProgramAddressSpace(); + Function *F = Create(Ty, Linkage, AddrSpace, N); + + M.getFunctionList().insert(InsertBefore.getIterator(), F); + return F; +} + void Function::removeFromParent() { getParent()->getFunctionList().remove(getIterator()); } @@ -207,10 +223,11 @@ // Function Implementation //===----------------------------------------------------------------------===// -Function::Function(FunctionType *Ty, LinkageTypes Linkage, const Twine &name, - Module *ParentModule) +Function::Function(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, + const Twine &name, Module *ParentModule) : GlobalObject(Ty, Value::FunctionVal, - OperandTraits::op_begin(this), 0, Linkage, name), + OperandTraits::op_begin(this), 0, Linkage, name, + AddrSpace), NumArgs(Ty->getNumParams()) { assert(FunctionType::isValidReturnType(getReturnType()) && "invalid return type"); Index: lib/IR/Globals.cpp =================================================================== --- lib/IR/Globals.cpp +++ lib/IR/Globals.cpp @@ -108,6 +108,11 @@ return cast(this)->getAlignment(); } +unsigned GlobalValue::getAddressSpace() const { + PointerType *PtrTy = getType(); + return PtrTy->getAddressSpace(); +} + void GlobalObject::setAlignment(unsigned Align) { assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!"); assert(Align <= MaximumAlignment && Index: lib/IR/Module.cpp =================================================================== --- lib/IR/Module.cpp +++ lib/IR/Module.cpp @@ -145,7 +145,8 @@ GlobalValue *F = getNamedValue(Name); if (!F) { // Nope, add it - Function *New = Function::Create(Ty, GlobalVariable::ExternalLinkage, Name); + Function *New = Function::Create(Ty, GlobalVariable::ExternalLinkage, + DL.getProgramAddressSpace(), Name); if (!New->isIntrinsic()) // Intrinsics get attrs set on construction New->setAttributes(AttributeList); FunctionList.push_back(New); @@ -154,8 +155,9 @@ // If the function exists but has the wrong type, return a bitcast to the // right type. - if (F->getType() != PointerType::getUnqual(Ty)) - return ConstantExpr::getBitCast(F, PointerType::getUnqual(Ty)); + auto *PTy = PointerType::get(Ty, F->getAddressSpace()); + if (F->getType() != PTy) + return ConstantExpr::getBitCast(F, PTy); // Otherwise, we just found the existing function or a prototype. return F; Index: lib/Linker/IRMover.cpp =================================================================== --- lib/Linker/IRMover.cpp +++ lib/Linker/IRMover.cpp @@ -619,7 +619,7 @@ // bring SF over. auto *F = Function::Create(TypeMap.get(SF->getFunctionType()), - GlobalValue::ExternalLinkage, SF->getName(), &DstM); + GlobalValue::ExternalLinkage, SF->getName(), DstM); F->copyAttributesFrom(SF); return F; } @@ -649,7 +649,7 @@ else if (SGV->getValueType()->isFunctionTy()) NewGV = Function::Create(cast(TypeMap.get(SGV->getValueType())), - GlobalValue::ExternalLinkage, SGV->getName(), &DstM); + GlobalValue::ExternalLinkage, SGV->getName(), DstM); else NewGV = new GlobalVariable( DstM, TypeMap.get(SGV->getValueType()), Index: lib/Linker/LinkModules.cpp =================================================================== --- lib/Linker/LinkModules.cpp +++ lib/Linker/LinkModules.cpp @@ -441,7 +441,7 @@ PointerType &Ty = *cast(Alias.getType()); GlobalValue *Declaration; if (auto *FTy = dyn_cast(Alias.getValueType())) { - Declaration = Function::Create(FTy, GlobalValue::ExternalLinkage, "", &M); + Declaration = Function::Create(FTy, GlobalValue::ExternalLinkage, "", M); } else { Declaration = new GlobalVariable(M, Ty.getElementType(), /*isConstant*/ false, Index: lib/Target/AMDGPU/AMDGPUOpenCLImageTypeLoweringPass.cpp =================================================================== --- lib/Target/AMDGPU/AMDGPUOpenCLImageTypeLoweringPass.cpp +++ lib/Target/AMDGPU/AMDGPUOpenCLImageTypeLoweringPass.cpp @@ -304,7 +304,8 @@ // Create function with new signature and clone the old body into it. auto NewFT = FunctionType::get(FT->getReturnType(), ArgTypes, false); - auto NewF = Function::Create(NewFT, F->getLinkage(), F->getName()); + auto NewF = Function::Create(NewFT, F->getLinkage(), F->getAddressSpace(), + F->getName()); ValueToValueMapTy VMap; auto NewFArgIt = NewF->arg_begin(); for (auto &Arg: F->args()) { Index: lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp =================================================================== --- lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp +++ lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp @@ -360,9 +360,9 @@ DEBUG(dbgs() << "Computed new return type: " << *NewRetTy << '\n'); - Function *NewFunc = Function::Create(NewFuncTy, Function::PrivateLinkage, - F.getName() + ".body"); - F.getParent()->getFunctionList().insert(F.getIterator(), NewFunc); + Function *NewFunc = Function::CreateBefore(F, NewFuncTy, + Function::PrivateLinkage, + F.getName() + ".body"); NewFunc->copyAttributesFrom(&F); NewFunc->setComdat(F.getComdat()); Index: lib/Target/Mips/Mips16HardFloat.cpp =================================================================== --- lib/Target/Mips/Mips16HardFloat.cpp +++ lib/Target/Mips/Mips16HardFloat.cpp @@ -268,7 +268,7 @@ Function *FStub = M->getFunction(StubName); if (FStub && !FStub->isDeclaration()) return; FStub = Function::Create(F.getFunctionType(), - Function::InternalLinkage, StubName, M); + Function::InternalLinkage, StubName, *M); FStub->addFnAttr("mips16_fp_stub"); FStub->addFnAttr(Attribute::Naked); FStub->addFnAttr(Attribute::NoInline); @@ -453,7 +453,7 @@ std::string LocalName = "$$__fn_local_" + Name; Function *FStub = Function::Create (F->getFunctionType(), - Function::InternalLinkage, StubName, M); + Function::InternalLinkage, StubName, *M); FStub->addFnAttr("mips16_fp_stub"); FStub->addFnAttr(Attribute::Naked); FStub->addFnAttr(Attribute::NoUnwind); Index: lib/Target/X86/X86RetpolineThunks.cpp =================================================================== --- lib/Target/X86/X86RetpolineThunks.cpp +++ lib/Target/X86/X86RetpolineThunks.cpp @@ -198,7 +198,7 @@ LLVMContext &Ctx = M.getContext(); auto Type = FunctionType::get(Type::getVoidTy(Ctx), false); Function *F = - Function::Create(Type, GlobalValue::LinkOnceODRLinkage, Name, &M); + Function::Create(Type, GlobalValue::LinkOnceODRLinkage, Name, M); F->setVisibility(GlobalValue::HiddenVisibility); F->setComdat(M.getOrInsertComdat(Name)); Index: lib/Target/X86/X86WinEHState.cpp =================================================================== --- lib/Target/X86/X86WinEHState.cpp +++ lib/Target/X86/X86WinEHState.cpp @@ -406,9 +406,10 @@ Function::Create(TrampolineTy, GlobalValue::InternalLinkage, Twine("__ehhandler$") + GlobalValue::dropLLVMManglingEscape( ParentFunc->getName()), - TheModule); + *TheModule); if (auto *C = ParentFunc->getComdat()) Trampoline->setComdat(C); + BasicBlock *EntryBB = BasicBlock::Create(Context, "entry", Trampoline); IRBuilder<> Builder(EntryBB); Value *LSDA = emitEHLSDA(Builder, ParentFunc); Index: lib/Transforms/Coroutines/CoroSplit.cpp =================================================================== --- lib/Transforms/Coroutines/CoroSplit.cpp +++ lib/Transforms/Coroutines/CoroSplit.cpp @@ -251,7 +251,7 @@ Function *NewF = Function::Create(FnTy, GlobalValue::LinkageTypes::InternalLinkage, - F.getName() + Suffix, M); + F.getName() + Suffix, *M); NewF->addParamAttr(0, Attribute::NonNull); NewF->addParamAttr(0, Attribute::NoAlias); @@ -796,7 +796,7 @@ /*IsVarArgs=*/false); Function *DevirtFn = Function::Create(FnTy, GlobalValue::LinkageTypes::PrivateLinkage, - CORO_DEVIRT_TRIGGER_FN, &M); + CORO_DEVIRT_TRIGGER_FN, M); DevirtFn->addFnAttr(Attribute::AlwaysInline); auto *Entry = BasicBlock::Create(C, "entry", DevirtFn); ReturnInst::Create(C, Entry); Index: lib/Transforms/IPO/ArgumentPromotion.cpp =================================================================== --- lib/Transforms/IPO/ArgumentPromotion.cpp +++ lib/Transforms/IPO/ArgumentPromotion.cpp @@ -213,7 +213,8 @@ FunctionType *NFTy = FunctionType::get(RetTy, Params, FTy->isVarArg()); // Create the new function body and insert it into the module. - Function *NF = Function::Create(NFTy, F->getLinkage(), F->getName()); + Function *NF = Function::CreateBefore(*F, NFTy, F->getLinkage(), + F->getName()); NF->copyAttributesFrom(F); // Patch the pointer to LLVM function in debug info descriptor. @@ -229,7 +230,6 @@ PAL.getRetAttributes(), ArgAttrVec)); ArgAttrVec.clear(); - F->getParent()->getFunctionList().insert(F->getIterator(), NF); NF->takeName(F); // Loop over all of the callers of the function, transforming the call sites Index: lib/Transforms/IPO/DeadArgumentElimination.cpp =================================================================== --- lib/Transforms/IPO/DeadArgumentElimination.cpp +++ lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -165,10 +165,9 @@ unsigned NumArgs = Params.size(); // Create the new function body and insert it into the module... - Function *NF = Function::Create(NFTy, Fn.getLinkage()); + Function *NF = Function::CreateBefore(Fn, NFTy, Fn.getLinkage()); NF->copyAttributesFrom(&Fn); NF->setComdat(Fn.getComdat()); - Fn.getParent()->getFunctionList().insert(Fn.getIterator(), NF); NF->takeName(&Fn); // Loop over all of the callers of the function, transforming the call sites @@ -815,14 +814,13 @@ if (NFTy == FTy) return false; - // Create the new function body and insert it into the module... - Function *NF = Function::Create(NFTy, F->getLinkage()); + // Create the new function body. + // Insert the new function before the old function, so we won't be processing + // it again. + Function *NF = Function::CreateBefore(*F, NFTy, F->getLinkage()); NF->copyAttributesFrom(F); NF->setComdat(F->getComdat()); NF->setAttributes(NewPAL); - // Insert the new function before the old function, so we won't be processing - // it again. - F->getParent()->getFunctionList().insert(F->getIterator(), NF); NF->takeName(F); // Patch the pointer to LLVM function in debug info descriptor. Index: lib/Transforms/IPO/ExtractGV.cpp =================================================================== --- lib/Transforms/IPO/ExtractGV.cpp +++ lib/Transforms/IPO/ExtractGV.cpp @@ -135,7 +135,7 @@ llvm::Value *Declaration; if (FunctionType *FTy = dyn_cast(Ty)) { Declaration = Function::Create(FTy, GlobalValue::ExternalLinkage, - CurI->getName(), &M); + CurI->getName(), M); } else { Declaration = Index: lib/Transforms/IPO/FunctionImport.cpp =================================================================== --- lib/Transforms/IPO/FunctionImport.cpp +++ lib/Transforms/IPO/FunctionImport.cpp @@ -696,7 +696,7 @@ if (GV.getValueType()->isFunctionTy()) NewGV = Function::Create(cast(GV.getValueType()), - GlobalValue::ExternalLinkage, "", GV.getParent()); + GlobalValue::ExternalLinkage, "", *GV.getParent()); else NewGV = new GlobalVariable(*GV.getParent(), GV.getValueType(), Index: lib/Transforms/IPO/LowerTypeTests.cpp =================================================================== --- lib/Transforms/IPO/LowerTypeTests.cpp +++ lib/Transforms/IPO/LowerTypeTests.cpp @@ -947,14 +947,14 @@ if (F->isDeclarationForLinker() && !isDefinition) { // Declaration of an external function. FDecl = Function::Create(F->getFunctionType(), GlobalValue::ExternalLinkage, - Name + ".cfi_jt", &M); + Name + ".cfi_jt", M); FDecl->setVisibility(GlobalValue::HiddenVisibility); } else if (isDefinition) { F->setName(Name + ".cfi"); F->setLinkage(GlobalValue::ExternalLinkage); F->setVisibility(GlobalValue::HiddenVisibility); FDecl = Function::Create(F->getFunctionType(), GlobalValue::ExternalLinkage, - Name, &M); + Name, M); FDecl->setVisibility(Visibility); // Delete aliases pointing to this function, they'll be re-created in the @@ -963,7 +963,7 @@ for (auto &U : F->uses()) { if (auto *A = dyn_cast(U.getUser())) { Function *AliasDecl = Function::Create( - F->getFunctionType(), GlobalValue::ExternalLinkage, "", &M); + F->getFunctionType(), GlobalValue::ExternalLinkage, "", M); AliasDecl->takeName(A); A->replaceAllUsesWith(AliasDecl); ToErase.push_back(A); @@ -1134,7 +1134,7 @@ WeakInitializerFn = Function::Create( FunctionType::get(Type::getVoidTy(M.getContext()), /* IsVarArg */ false), - GlobalValue::InternalLinkage, "__cfi_global_var_init", &M); + GlobalValue::InternalLinkage, "__cfi_global_var_init", M); BasicBlock *BB = BasicBlock::Create(M.getContext(), "entry", WeakInitializerFn); ReturnInst::Create(M.getContext(), BB); @@ -1177,7 +1177,7 @@ // placeholder first. Function *PlaceholderFn = Function::Create(cast(F->getValueType()), - GlobalValue::ExternalWeakLinkage, "", &M); + GlobalValue::ExternalWeakLinkage, "", M); F->replaceAllUsesWith(PlaceholderFn); Constant *Target = ConstantExpr::getSelect( @@ -1371,7 +1371,7 @@ Function *JumpTableFn = Function::Create(FunctionType::get(Type::getVoidTy(M.getContext()), /* IsVarArg */ false), - GlobalValue::PrivateLinkage, ".cfi.jumptable", &M); + GlobalValue::PrivateLinkage, ".cfi.jumptable", M); ArrayType *JumpTableType = ArrayType::get(getJumpTableEntryType(), Functions.size()); auto JumpTable = @@ -1657,7 +1657,7 @@ if (!F) F = Function::Create( FunctionType::get(Type::getVoidTy(M.getContext()), false), - GlobalVariable::ExternalLinkage, FunctionName, &M); + GlobalVariable::ExternalLinkage, FunctionName, M); // If the function is available_externally, remove its definition so // that it is handled the same way as a declaration. Later we will try Index: lib/Transforms/IPO/MergeFunctions.cpp =================================================================== --- lib/Transforms/IPO/MergeFunctions.cpp +++ lib/Transforms/IPO/MergeFunctions.cpp @@ -697,7 +697,7 @@ BB = GEntryBlock; } else { NewG = Function::Create(G->getFunctionType(), G->getLinkage(), "", - G->getParent()); + *G->getParent()); BB = BasicBlock::Create(F->getContext(), "", NewG); } @@ -756,7 +756,7 @@ // Make them both thunks to the same internal function. Function *H = Function::Create(F->getFunctionType(), F->getLinkage(), "", - F->getParent()); + *F->getParent()); H->copyAttributesFrom(F); H->takeName(F); removeUsers(F); Index: lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp =================================================================== --- lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp +++ lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp @@ -154,7 +154,7 @@ continue; Function *NewF = - Function::Create(EmptyFT, GlobalValue::ExternalLinkage, "", &M); + Function::Create(EmptyFT, GlobalValue::ExternalLinkage, "", M); NewF->setVisibility(F.getVisibility()); NewF->takeName(&F); F.replaceAllUsesWith(ConstantExpr::getBitCast(NewF, F.getType())); Index: lib/Transforms/Instrumentation/AddressSanitizer.cpp =================================================================== --- lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -1820,7 +1820,7 @@ IRBuilder<> AddressSanitizerModule::CreateAsanModuleDtor(Module &M) { AsanDtorFunction = Function::Create(FunctionType::get(Type::getVoidTy(*C), false), - GlobalValue::InternalLinkage, kAsanModuleDtorName, &M); + GlobalValue::InternalLinkage, kAsanModuleDtorName, M); BasicBlock *AsanDtorBB = BasicBlock::Create(*C, "", AsanDtorFunction); return IRBuilder<>(ReturnInst::Create(*C, AsanDtorBB)); Index: lib/Transforms/Instrumentation/DataFlowSanitizer.cpp =================================================================== --- lib/Transforms/Instrumentation/DataFlowSanitizer.cpp +++ lib/Transforms/Instrumentation/DataFlowSanitizer.cpp @@ -646,8 +646,8 @@ GlobalValue::LinkageTypes NewFLink, FunctionType *NewFT) { FunctionType *FT = F->getFunctionType(); - Function *NewF = Function::Create(NewFT, NewFLink, NewFName, - F->getParent()); + Function *NewF = Function::Create(NewFT, NewFLink, F->getAddressSpace(), + NewFName, F->getParent()); NewF->copyAttributesFrom(F); NewF->removeAttributes( AttributeList::ReturnIndex, @@ -820,7 +820,8 @@ // easily identify cases of mismatching ABIs. if (getInstrumentedABI() == IA_Args && !IsZeroArgsVoidRet) { FunctionType *NewFT = getArgsFunctionType(FT); - Function *NewF = Function::Create(NewFT, F.getLinkage(), "", &M); + Function *NewF = Function::Create(NewFT, F.getLinkage(), + F.getAddressSpace(), "", &M); NewF->copyAttributesFrom(&F); NewF->removeAttributes( AttributeList::ReturnIndex, Index: lib/Transforms/Instrumentation/EfficiencySanitizer.cpp =================================================================== --- lib/Transforms/Instrumentation/EfficiencySanitizer.cpp +++ lib/Transforms/Instrumentation/EfficiencySanitizer.cpp @@ -523,7 +523,7 @@ EsanDtorFunction = Function::Create(FunctionType::get(Type::getVoidTy(*Ctx), false), GlobalValue::InternalLinkage, - EsanModuleDtorName, &M); + EsanModuleDtorName, M); ReturnInst::Create(*Ctx, BasicBlock::Create(*Ctx, "", EsanDtorFunction)); IRBuilder<> IRB_Dtor(EsanDtorFunction->getEntryBlock().getTerminator()); Function *EsanExit = checkSanitizerInterfaceFunction( Index: lib/Transforms/Instrumentation/GCOVProfiling.cpp =================================================================== --- lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -720,7 +720,7 @@ // when "__gcov_flush" is called. FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), false); Function *F = Function::Create(FTy, GlobalValue::InternalLinkage, - "__llvm_gcov_init", M); + "__llvm_gcov_init", *M); F->setUnnamedAddr(GlobalValue::UnnamedAddr::Global); F->setLinkage(GlobalValue::InternalLinkage); F->addFnAttr(Attribute::NoInline); @@ -871,7 +871,7 @@ Function *WriteoutF = M->getFunction("__llvm_gcov_writeout"); if (!WriteoutF) WriteoutF = Function::Create(WriteoutFTy, GlobalValue::InternalLinkage, - "__llvm_gcov_writeout", M); + "__llvm_gcov_writeout", *M); WriteoutF->setUnnamedAddr(GlobalValue::UnnamedAddr::Global); WriteoutF->addFnAttr(Attribute::NoInline); if (Options.NoRedZone) @@ -986,7 +986,7 @@ Function *FlushF = M->getFunction("__llvm_gcov_flush"); if (!FlushF) FlushF = Function::Create(FTy, GlobalValue::InternalLinkage, - "__llvm_gcov_flush", M); + "__llvm_gcov_flush", *M); else FlushF->setLinkage(GlobalValue::InternalLinkage); FlushF->setUnnamedAddr(GlobalValue::UnnamedAddr::Global); Index: lib/Transforms/Instrumentation/InstrProfiling.cpp =================================================================== --- lib/Transforms/Instrumentation/InstrProfiling.cpp +++ lib/Transforms/Instrumentation/InstrProfiling.cpp @@ -885,7 +885,7 @@ auto *Int64Ty = Type::getInt64Ty(M->getContext()); auto *RegisterFTy = FunctionType::get(VoidTy, false); auto *RegisterF = Function::Create(RegisterFTy, GlobalValue::InternalLinkage, - getInstrProfRegFuncsName(), M); + getInstrProfRegFuncsName(), *M); RegisterF->setUnnamedAddr(GlobalValue::UnnamedAddr::Global); if (Options.NoRedZone) RegisterF->addFnAttr(Attribute::NoRedZone); @@ -893,7 +893,7 @@ auto *RuntimeRegisterTy = FunctionType::get(VoidTy, VoidPtrTy, false); auto *RuntimeRegisterF = Function::Create(RuntimeRegisterTy, GlobalVariable::ExternalLinkage, - getInstrProfRegFuncName(), M); + getInstrProfRegFuncName(), *M); IRBuilder<> IRB(BasicBlock::Create(M->getContext(), "", RegisterF)); for (Value *Data : UsedVars) @@ -906,7 +906,7 @@ FunctionType::get(VoidTy, makeArrayRef(ParamTypes), false); auto *NamesRegisterF = Function::Create(NamesRegisterTy, GlobalVariable::ExternalLinkage, - getInstrProfNamesRegFuncName(), M); + getInstrProfNamesRegFuncName(), *M); IRB.CreateCall(NamesRegisterF, {IRB.CreateBitCast(NamesVar, VoidPtrTy), IRB.getInt64(NamesSize)}); } @@ -933,7 +933,7 @@ // Make a function that uses it. auto *User = Function::Create(FunctionType::get(Int32Ty, false), GlobalValue::LinkOnceODRLinkage, - getInstrProfRuntimeHookVarUseFuncName(), M); + getInstrProfRuntimeHookVarUseFuncName(), *M); User->addFnAttr(Attribute::NoInline); if (Options.NoRedZone) User->addFnAttr(Attribute::NoRedZone); @@ -979,7 +979,7 @@ auto *VoidTy = Type::getVoidTy(M->getContext()); auto *F = Function::Create(FunctionType::get(VoidTy, false), GlobalValue::InternalLinkage, - getInstrProfInitFuncName(), M); + getInstrProfInitFuncName(), *M); F->setUnnamedAddr(GlobalValue::UnnamedAddr::Global); F->addFnAttr(Attribute::NoInline); if (Options.NoRedZone) Index: lib/Transforms/Utils/CloneFunction.cpp =================================================================== --- lib/Transforms/Utils/CloneFunction.cpp +++ lib/Transforms/Utils/CloneFunction.cpp @@ -244,7 +244,8 @@ // Create the new function... Function *NewF = - Function::Create(FTy, F->getLinkage(), F->getName(), F->getParent()); + Function::Create(FTy, F->getLinkage(), F->getAddressSpace(), + F->getName(), F->getParent()); // Loop over the arguments, copying the names of the mapped arguments over... Function::arg_iterator DestI = NewF->arg_begin(); Index: lib/Transforms/Utils/CloneModule.cpp =================================================================== --- lib/Transforms/Utils/CloneModule.cpp +++ lib/Transforms/Utils/CloneModule.cpp @@ -74,7 +74,8 @@ // Loop over the functions in the module, making external functions as before for (const Function &I : M) { Function *NF = Function::Create(cast(I.getValueType()), - I.getLinkage(), I.getName(), New.get()); + I.getLinkage(), I.getAddressSpace(), + I.getName(), New.get()); NF->copyAttributesFrom(&I); VMap[&I] = NF; } @@ -90,7 +91,8 @@ GlobalValue *GV; if (I->getValueType()->isFunctionTy()) GV = Function::Create(cast(I->getValueType()), - GlobalValue::ExternalLinkage, I->getName(), + GlobalValue::ExternalLinkage, + I->getAddressSpace(), I->getName(), New.get()); else GV = new GlobalVariable( Index: lib/Transforms/Utils/CodeExtractor.cpp =================================================================== --- lib/Transforms/Utils/CodeExtractor.cpp +++ lib/Transforms/Utils/CodeExtractor.cpp @@ -611,6 +611,7 @@ // Create the new function Function *newFunction = Function::Create(funcType, GlobalValue::InternalLinkage, + oldFunction->getAddressSpace(), oldFunction->getName() + "_" + header->getName(), M); // If the old function is no-throw, so is the new one. Index: lib/Transforms/Utils/ModuleUtils.cpp =================================================================== --- lib/Transforms/Utils/ModuleUtils.cpp +++ lib/Transforms/Utils/ModuleUtils.cpp @@ -160,7 +160,8 @@ declareSanitizerInitFunction(M, InitName, InitArgTypes); Function *Ctor = Function::Create( FunctionType::get(Type::getVoidTy(M.getContext()), false), - GlobalValue::InternalLinkage, CtorName, &M); + GlobalValue::InternalLinkage, + CtorName, M); BasicBlock *CtorBB = BasicBlock::Create(M.getContext(), "", Ctor); IRBuilder<> IRB(ReturnInst::Create(M.getContext(), CtorBB)); IRB.CreateCall(InitFunction, InitArgs); Index: lib/Transforms/Utils/SanitizerStats.cpp =================================================================== --- lib/Transforms/Utils/SanitizerStats.cpp +++ lib/Transforms/Utils/SanitizerStats.cpp @@ -93,7 +93,7 @@ // Create a global constructor to register NewModuleStatsGV. auto F = Function::Create(FunctionType::get(VoidTy, false), - GlobalValue::InternalLinkage, "", M); + GlobalValue::InternalLinkage, "", *M); auto BB = BasicBlock::Create(M->getContext(), "", F); IRBuilder<> B(BB); Index: lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- lib/Transforms/Vectorize/LoopVectorize.cpp +++ lib/Transforms/Vectorize/LoopVectorize.cpp @@ -4739,7 +4739,7 @@ // Generate a declaration FunctionType *FTy = FunctionType::get(RetTy, Tys, false); VectorF = - Function::Create(FTy, Function::ExternalLinkage, VFnName, M); + Function::Create(FTy, Function::ExternalLinkage, VFnName, *M); VectorF->copyAttributesFrom(F); } } Index: test/Bitcode/function-nonzero-address-spaces.ll =================================================================== --- /dev/null +++ test/Bitcode/function-nonzero-address-spaces.ll @@ -0,0 +1,7 @@ +; RUN: llvm-as < %s | llvm-dis | FileCheck %s + +; CHECK: define void @main() addrspace(3) +define void @main() addrspace(3) { + ret void +} + Index: tools/bugpoint/Miscompilation.cpp =================================================================== --- tools/bugpoint/Miscompilation.cpp +++ tools/bugpoint/Miscompilation.cpp @@ -796,12 +796,12 @@ // Create a NEW `main' function with same type in the test module. Function *newMain = Function::Create(oldMain->getFunctionType(), - GlobalValue::ExternalLinkage, "main", Test.get()); + GlobalValue::ExternalLinkage, "main", *Test.get()); // Create an `oldmain' prototype in the test module, which will // corresponds to the real main function in the same module. Function *oldMainProto = Function::Create(oldMain->getFunctionType(), GlobalValue::ExternalLinkage, - oldMain->getName(), Test.get()); + oldMain->getName(), *Test.get()); // Set up and remember the argument list for the main function. std::vector args; for (Function::arg_iterator I = newMain->arg_begin(), @@ -870,7 +870,7 @@ FunctionType *FuncTy = F->getFunctionType(); Function *FuncWrapper = Function::Create(FuncTy, GlobalValue::InternalLinkage, - F->getName() + "_wrapper", F->getParent()); + F->getName() + "_wrapper", *F->getParent()); BasicBlock *EntryBB = BasicBlock::Create(F->getContext(), "entry", FuncWrapper); BasicBlock *DoCallBB = Index: tools/lli/lli.cpp =================================================================== --- tools/lli/lli.cpp +++ tools/lli/lli.cpp @@ -273,11 +273,11 @@ if (TargetTriple.isArch64Bit()) { Result = Function::Create( TypeBuilder::get(Context), - GlobalValue::ExternalLinkage, "__main", M.get()); + GlobalValue::ExternalLinkage, "__main", *M.get()); } else { Result = Function::Create( TypeBuilder::get(Context), - GlobalValue::ExternalLinkage, "__main", M.get()); + GlobalValue::ExternalLinkage, "__main", *M.get()); } BasicBlock *BB = BasicBlock::Create(Context, "__main", Result); Builder.SetInsertPoint(BB); Index: tools/llvm-stress/llvm-stress.cpp =================================================================== --- tools/llvm-stress/llvm-stress.cpp +++ tools/llvm-stress/llvm-stress.cpp @@ -167,7 +167,7 @@ auto *FuncTy = FunctionType::get(Type::getVoidTy(Context), ArgsTy, false); // Pick a unique name to describe the input parameters Twine Name = "autogen_SD" + Twine{SeedCL}; - auto *Func = Function::Create(FuncTy, GlobalValue::ExternalLinkage, Name, M); + auto *Func = Function::Create(FuncTy, GlobalValue::ExternalLinkage, Name, *M); Func->setCallingConv(CallingConv::C); return Func; } Index: unittests/Analysis/LazyCallGraphTest.cpp =================================================================== --- unittests/Analysis/LazyCallGraphTest.cpp +++ unittests/Analysis/LazyCallGraphTest.cpp @@ -2038,8 +2038,7 @@ // Now we need to build a new function 'e' with the same signature as 'd'. Function &D = DN.getFunction(); - Function &E = *Function::Create(D.getFunctionType(), D.getLinkage(), "e"); - D.getParent()->getFunctionList().insert(D.getIterator(), &E); + Function &E = *Function::CreateBefore(D, D.getFunctionType(), D.getLinkage(), "e"); // Change each use of 'd' to use 'e'. This is particularly easy as they have // the same type. Index: unittests/Analysis/MemoryBuiltinsTest.cpp =================================================================== --- unittests/Analysis/MemoryBuiltinsTest.cpp +++ unittests/Analysis/MemoryBuiltinsTest.cpp @@ -28,7 +28,7 @@ Function *AllocSizeFn = Function::Create( FunctionType::get(Type::getInt8PtrTy(Context), {ArgTy}, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); AllocSizeFn->addFnAttr(Attribute::getWithAllocSizeArgs(Context, 1, None)); Index: unittests/Analysis/MemorySSA.cpp =================================================================== --- unittests/Analysis/MemorySSA.cpp +++ unittests/Analysis/MemorySSA.cpp @@ -75,7 +75,7 @@ // updating by creating an access for the load. F = Function::Create( FunctionType::get(B.getVoidTy(), {B.getInt8PtrTy()}, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); BasicBlock *Entry(BasicBlock::Create(C, "", F)); BasicBlock *Left(BasicBlock::Create(C, "", F)); BasicBlock *Right(BasicBlock::Create(C, "", F)); @@ -113,7 +113,7 @@ // and then a store in the entry. F = Function::Create( FunctionType::get(B.getVoidTy(), {B.getInt8PtrTy()}, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); BasicBlock *Entry(BasicBlock::Create(C, "", F)); BasicBlock *Left(BasicBlock::Create(C, "", F)); BasicBlock *Right(BasicBlock::Create(C, "", F)); @@ -203,7 +203,7 @@ // load in the merge point F = Function::Create( FunctionType::get(B.getVoidTy(), {B.getInt8PtrTy()}, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); BasicBlock *Entry(BasicBlock::Create(C, "", F)); BasicBlock *Left(BasicBlock::Create(C, "", F)); BasicBlock *Right(BasicBlock::Create(C, "", F)); @@ -247,7 +247,7 @@ TEST_F(MemorySSATest, SinkLoad) { F = Function::Create( FunctionType::get(B.getVoidTy(), {B.getInt8PtrTy()}, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); BasicBlock *Entry(BasicBlock::Create(C, "", F)); BasicBlock *Left(BasicBlock::Create(C, "", F)); BasicBlock *Right(BasicBlock::Create(C, "", F)); @@ -297,7 +297,7 @@ // access. F = Function::Create( FunctionType::get(B.getVoidTy(), {B.getInt8PtrTy()}, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); BasicBlock *Entry(BasicBlock::Create(C, "", F)); BasicBlock *Left(BasicBlock::Create(C, "", F)); BasicBlock *Right(BasicBlock::Create(C, "", F)); @@ -333,7 +333,7 @@ // access. F = Function::Create( FunctionType::get(B.getVoidTy(), {B.getInt8PtrTy()}, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); BasicBlock *Entry(BasicBlock::Create(C, "", F)); BasicBlock *Left(BasicBlock::Create(C, "", F)); BasicBlock *Right(BasicBlock::Create(C, "", F)); @@ -379,7 +379,7 @@ // the old access. F = Function::Create( FunctionType::get(B.getVoidTy(), {B.getInt8PtrTy()}, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); BasicBlock *Entry(BasicBlock::Create(C, "", F)); BasicBlock *Left(BasicBlock::Create(C, "", F)); BasicBlock *Right(BasicBlock::Create(C, "", F)); @@ -423,7 +423,7 @@ // block, then to before the load. This does not destroy the old access. F = Function::Create( FunctionType::get(B.getVoidTy(), {B.getInt8PtrTy()}, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); BasicBlock *Entry(BasicBlock::Create(C, "", F)); BasicBlock *Left(BasicBlock::Create(C, "", F)); BasicBlock *Right(BasicBlock::Create(C, "", F)); @@ -478,7 +478,7 @@ // removal cases. F = Function::Create( FunctionType::get(B.getVoidTy(), {B.getInt8PtrTy()}, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); BasicBlock *Entry(BasicBlock::Create(C, "", F)); BasicBlock *Left(BasicBlock::Create(C, "", F)); BasicBlock *Right(BasicBlock::Create(C, "", F)); @@ -523,7 +523,7 @@ // removal cases. F = Function::Create( FunctionType::get(B.getVoidTy(), {B.getInt8PtrTy()}, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); BasicBlock *Entry(BasicBlock::Create(C, "", F)); BasicBlock *Left(BasicBlock::Create(C, "", F)); BasicBlock *Right(BasicBlock::Create(C, "", F)); @@ -596,7 +596,7 @@ // } TEST_F(MemorySSATest, TestTripleStore) { F = Function::Create(FunctionType::get(B.getVoidTy(), {}, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); B.SetInsertPoint(BasicBlock::Create(C, "", F)); Type *Int8 = Type::getInt8Ty(C); Value *Alloca = B.CreateAlloca(Int8, ConstantInt::get(Int8, 1), "A"); @@ -627,7 +627,7 @@ // query. In that case, we'd cache that the node clobbered itself. TEST_F(MemorySSATest, TestStoreAndLoad) { F = Function::Create(FunctionType::get(B.getVoidTy(), {}, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); B.SetInsertPoint(BasicBlock::Create(C, "", F)); Type *Int8 = Type::getInt8Ty(C); Value *Alloca = B.CreateAlloca(Int8, ConstantInt::get(Int8, 1), "A"); @@ -657,7 +657,7 @@ // meant to. TEST_F(MemorySSATest, TestStoreDoubleQuery) { F = Function::Create(FunctionType::get(B.getVoidTy(), {}, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); B.SetInsertPoint(BasicBlock::Create(C, "", F)); Type *Int8 = Type::getInt8Ty(C); Value *Alloca = B.CreateAlloca(Int8, ConstantInt::get(Int8, 1), "A"); @@ -701,7 +701,7 @@ // walking* 'B'. TEST_F(MemorySSATest, PartialWalkerCacheWithPhis) { F = Function::Create(FunctionType::get(B.getVoidTy(), {}, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); B.SetInsertPoint(BasicBlock::Create(C, "A", F)); Type *Int8 = Type::getInt8Ty(C); Constant *One = ConstantInt::get(Int8, 1); @@ -765,7 +765,7 @@ // FIXME: It may be easier/cleaner to just add an 'optimize uses?' flag to MSSA. TEST_F(MemorySSATest, WalkerInvariantLoadOpt) { F = Function::Create(FunctionType::get(B.getVoidTy(), {}, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); B.SetInsertPoint(BasicBlock::Create(C, "", F)); Type *Int8 = Type::getInt8Ty(C); Constant *One = ConstantInt::get(Int8, 1); @@ -794,7 +794,7 @@ // Test loads get reoptimized properly by the walker. TEST_F(MemorySSATest, WalkerReopt) { F = Function::Create(FunctionType::get(B.getVoidTy(), {}, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); B.SetInsertPoint(BasicBlock::Create(C, "", F)); Type *Int8 = Type::getInt8Ty(C); Value *AllocaA = B.CreateAlloca(Int8, ConstantInt::get(Int8, 1), "A"); @@ -825,7 +825,7 @@ // Test out MemorySSAUpdater::moveBefore TEST_F(MemorySSATest, MoveAboveMemoryDef) { F = Function::Create(FunctionType::get(B.getVoidTy(), {}, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); B.SetInsertPoint(BasicBlock::Create(C, "", F)); Type *Int8 = Type::getInt8Ty(C); @@ -884,7 +884,7 @@ IRBuilder<> B(C); F = Function::Create( FunctionType::get(B.getVoidTy(), {B.getInt8PtrTy()}, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); // Make blocks BasicBlock *IfBB = BasicBlock::Create(C, "if", F); Index: unittests/Analysis/SparsePropagation.cpp =================================================================== --- unittests/Analysis/SparsePropagation.cpp +++ unittests/Analysis/SparsePropagation.cpp @@ -256,9 +256,9 @@ /// already executable. Doing so would put the solver into an infinite loop. TEST_F(SparsePropagationTest, MarkBlockExecutable) { Function *F = Function::Create(FunctionType::get(Builder.getVoidTy(), false), - GlobalValue::InternalLinkage, "f", &M); + GlobalValue::InternalLinkage, "f", M); Function *G = Function::Create(FunctionType::get(Builder.getVoidTy(), false), - GlobalValue::InternalLinkage, "g", &M); + GlobalValue::InternalLinkage, "g", M); BasicBlock *FEntry = BasicBlock::Create(Context, "", F); BasicBlock *GEntry = BasicBlock::Create(Context, "", G); Builder.SetInsertPoint(FEntry); @@ -292,9 +292,9 @@ /// solver computes the lattice state of the global variable as constant. TEST_F(SparsePropagationTest, GlobalVariableConstant) { Function *F = Function::Create(FunctionType::get(Builder.getVoidTy(), false), - GlobalValue::InternalLinkage, "f", &M); + GlobalValue::InternalLinkage, "f", M); Function *G = Function::Create(FunctionType::get(Builder.getVoidTy(), false), - GlobalValue::InternalLinkage, "g", &M); + GlobalValue::InternalLinkage, "g", M); GlobalVariable *GV = new GlobalVariable(M, Builder.getInt64Ty(), false, GlobalValue::InternalLinkage, nullptr, "gv"); @@ -333,9 +333,9 @@ /// solver computes the lattice state of the global variable as overdefined. TEST_F(SparsePropagationTest, GlobalVariableOverDefined) { Function *F = Function::Create(FunctionType::get(Builder.getVoidTy(), false), - GlobalValue::InternalLinkage, "f", &M); + GlobalValue::InternalLinkage, "f", M); Function *G = Function::Create(FunctionType::get(Builder.getVoidTy(), false), - GlobalValue::InternalLinkage, "g", &M); + GlobalValue::InternalLinkage, "g", M); GlobalVariable *GV = new GlobalVariable(M, Builder.getInt64Ty(), false, GlobalValue::InternalLinkage, nullptr, "gv"); @@ -376,7 +376,7 @@ Function *F = Function::Create(FunctionType::get(Builder.getInt64Ty(), {Type::getInt1PtrTy(Context)}, false), - GlobalValue::InternalLinkage, "f", &M); + GlobalValue::InternalLinkage, "f", M); BasicBlock *If = BasicBlock::Create(Context, "if", F); BasicBlock *Then = BasicBlock::Create(Context, "then", F); BasicBlock *Else = BasicBlock::Create(Context, "else", F); @@ -416,7 +416,7 @@ Function *F = Function::Create(FunctionType::get(Builder.getInt64Ty(), {Type::getInt1PtrTy(Context)}, false), - GlobalValue::InternalLinkage, "f", &M); + GlobalValue::InternalLinkage, "f", M); BasicBlock *If = BasicBlock::Create(Context, "if", F); BasicBlock *Then = BasicBlock::Create(Context, "then", F); BasicBlock *Else = BasicBlock::Create(Context, "else", F); @@ -458,11 +458,11 @@ /// the state of arguments "a" and "b". TEST_F(SparsePropagationTest, ComputeInstructionState) { Function *F = Function::Create(FunctionType::get(Builder.getVoidTy(), false), - GlobalValue::InternalLinkage, "f", &M); + GlobalValue::InternalLinkage, "f", M); Function *G = Function::Create( FunctionType::get(Builder.getVoidTy(), {Builder.getInt64Ty(), Builder.getInt64Ty()}, false), - GlobalValue::InternalLinkage, "g", &M); + GlobalValue::InternalLinkage, "g", M); Argument *A = G->arg_begin(); Argument *B = std::next(G->arg_begin()); A->setName("a"); @@ -511,11 +511,11 @@ /// then discovers the rest of the blocks in the function are executable. TEST_F(SparsePropagationTest, ExceptionalTerminatorInsts) { Function *P = Function::Create(FunctionType::get(Builder.getVoidTy(), false), - GlobalValue::InternalLinkage, "p", &M); + GlobalValue::InternalLinkage, "p", M); Function *G = Function::Create(FunctionType::get(Builder.getVoidTy(), false), - GlobalValue::InternalLinkage, "g", &M); + GlobalValue::InternalLinkage, "g", M); Function *F = Function::Create(FunctionType::get(Builder.getVoidTy(), false), - GlobalValue::InternalLinkage, "f", &M); + GlobalValue::InternalLinkage, "f", M); Constant *C = ConstantExpr::getCast(Instruction::BitCast, P, Builder.getInt8PtrTy()); F->setPersonalityFn(C); Index: unittests/CodeGen/MachineInstrTest.cpp =================================================================== --- unittests/CodeGen/MachineInstrTest.cpp +++ unittests/CodeGen/MachineInstrTest.cpp @@ -88,7 +88,7 @@ LLVMContext Ctx; Module M("Module", Ctx); auto Type = FunctionType::get(Type::getVoidTy(Ctx), false); - auto F = Function::Create(Type, GlobalValue::ExternalLinkage, "Test", &M); + auto F = Function::Create(Type, GlobalValue::ExternalLinkage, "Test", M); auto TM = createTargetMachine(); unsigned FunctionNum = 42; Index: unittests/ExecutionEngine/MCJIT/MCJITTestBase.h =================================================================== --- unittests/ExecutionEngine/MCJIT/MCJITTestBase.h +++ unittests/ExecutionEngine/MCJIT/MCJITTestBase.h @@ -49,7 +49,7 @@ Function *startFunction(Module *M, StringRef Name) { Function *Result = Function::Create( TypeBuilder::get(Context), - GlobalValue::ExternalLinkage, Name, M); + GlobalValue::ExternalLinkage, Name, *M); BasicBlock *BB = BasicBlock::Create(Context, Name, Result); Builder.SetInsertPoint(BB); @@ -110,7 +110,7 @@ Function *insertExternalReferenceToFunction(Module *M, StringRef Name) { Function *Result = Function::Create( TypeBuilder::get(Context), - GlobalValue::ExternalLinkage, Name, M); + GlobalValue::ExternalLinkage, Name, *M); return Result; } @@ -119,7 +119,7 @@ FunctionType *FuncTy) { Function *Result = Function::Create(FuncTy, GlobalValue::ExternalLinkage, - Name, M); + Name, *M); return Result; } @@ -127,7 +127,7 @@ Function *insertExternalReferenceToFunction(Module *M, Function *Func) { Function *Result = Function::Create(Func->getFunctionType(), GlobalValue::ExternalLinkage, - Func->getName(), M); + Func->getName(), *M); return Result; } Index: unittests/ExecutionEngine/Orc/OrcTestCommon.h =================================================================== --- unittests/ExecutionEngine/Orc/OrcTestCommon.h +++ unittests/ExecutionEngine/Orc/OrcTestCommon.h @@ -79,7 +79,7 @@ Function* createFunctionDecl(StringRef Name) { return Function::Create( TypeBuilder::get(M->getContext()), - GlobalValue::ExternalLinkage, Name, M.get()); + GlobalValue::ExternalLinkage, Name, *M.get()); } Module* getModule() { return M.get(); } Index: unittests/FuzzMutate/OperationsTest.cpp =================================================================== --- unittests/FuzzMutate/OperationsTest.cpp +++ unittests/FuzzMutate/OperationsTest.cpp @@ -178,7 +178,7 @@ Module M("M", Ctx); Function *F = Function::Create(FunctionType::get(Type::getVoidTy(Ctx), {}, /*isVarArg=*/false), - GlobalValue::ExternalLinkage, "f", &M); + GlobalValue::ExternalLinkage, "f", M); auto SBOp = fuzzerop::splitBlockDescriptor(1); // Create a block with only a return and split it on the return. @@ -248,7 +248,7 @@ Module M("M", Ctx); Function *F = Function::Create(FunctionType::get(Type::getVoidTy(Ctx), {}, /*isVarArg=*/false), - GlobalValue::ExternalLinkage, "f", &M); + GlobalValue::ExternalLinkage, "f", M); auto SBOp = fuzzerop::splitBlockDescriptor(1); // Create 3 blocks with an if-then branch. @@ -286,7 +286,7 @@ Module M("M", Ctx); Function *F = Function::Create(FunctionType::get(Type::getVoidTy(Ctx), {}, /*isVarArg=*/false), - GlobalValue::ExternalLinkage, "f", &M); + GlobalValue::ExternalLinkage, "f", M); auto *BB = BasicBlock::Create(Ctx, "BB", F); auto *RI = ReturnInst::Create(Ctx, BB); Index: unittests/IR/FunctionTest.cpp =================================================================== --- unittests/IR/FunctionTest.cpp +++ unittests/IR/FunctionTest.cpp @@ -22,7 +22,7 @@ // Functions start out with lazy arguments. std::unique_ptr F( - Function::Create(FTy, GlobalValue::ExternalLinkage, "F")); + Function::Create(FTy, GlobalValue::ExternalLinkage, /*AddrSpace=*/0, "F")); EXPECT_TRUE(F->hasLazyArguments()); // Checking for empty or size shouldn't force arguments to be instantiated. @@ -42,9 +42,9 @@ Type *ArgTypes[] = {Type::getInt8Ty(C), Type::getInt32Ty(C)}; FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), ArgTypes, false); std::unique_ptr F1( - Function::Create(FTy, GlobalValue::ExternalLinkage, "F1")); + Function::Create(FTy, GlobalValue::ExternalLinkage, /*AddrSpace=*/0, "F1")); std::unique_ptr F2( - Function::Create(FTy, GlobalValue::ExternalLinkage, "F1")); + Function::Create(FTy, GlobalValue::ExternalLinkage, /*AddrSpace=*/0, "F1")); EXPECT_TRUE(F1->hasLazyArguments()); EXPECT_TRUE(F2->hasLazyArguments()); @@ -117,7 +117,7 @@ llvm::Function *F = Function::Create(llvm::FunctionType::get(llvm::Type::getVoidTy(C), false), - llvm::GlobalValue::ExternalLinkage, "F", &M); + llvm::GlobalValue::ExternalLinkage, "F", M); F->setSection(".text.test"); EXPECT_TRUE(F->getSection() == ".text.test"); Index: unittests/IR/IRBuilderTest.cpp =================================================================== --- unittests/IR/IRBuilderTest.cpp +++ unittests/IR/IRBuilderTest.cpp @@ -30,7 +30,7 @@ M.reset(new Module("MyModule", Ctx)); FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx), /*isVarArg=*/false); - F = Function::Create(FTy, Function::ExternalLinkage, "", M.get()); + F = Function::Create(FTy, Function::ExternalLinkage, "", *M.get()); BB = BasicBlock::Create(Ctx, "", F); GV = new GlobalVariable(*M, Type::getFloatTy(Ctx), true, GlobalValue::ExternalLinkage, nullptr); @@ -291,13 +291,13 @@ auto CalleeTy = FunctionType::get(Type::getFloatTy(Ctx), /*isVarArg=*/false); auto Callee = - Function::Create(CalleeTy, Function::ExternalLinkage, "", M.get()); + Function::Create(CalleeTy, Function::ExternalLinkage, "", *M.get()); FCall = Builder.CreateCall(Callee, None); EXPECT_FALSE(FCall->hasNoNaNs()); Value *V = - Function::Create(CalleeTy, Function::ExternalLinkage, "", M.get()); + Function::Create(CalleeTy, Function::ExternalLinkage, "", *M.get()); FCall = Builder.CreateCall(V, None); EXPECT_FALSE(FCall->hasNoNaNs()); @@ -488,7 +488,7 @@ auto CalleeTy = FunctionType::get(Type::getVoidTy(Ctx), /*isVarArg=*/false); auto Callee = - Function::Create(CalleeTy, Function::ExternalLinkage, "", M.get()); + Function::Create(CalleeTy, Function::ExternalLinkage, "", *M.get()); DIBuilder DIB(*M); auto File = DIB.createFile("tmp.cpp", "/"); Index: unittests/IR/InstructionsTest.cpp =================================================================== --- unittests/IR/InstructionsTest.cpp +++ unittests/IR/InstructionsTest.cpp @@ -62,7 +62,7 @@ FArgTypes.push_back(Type::getInt64Ty(Ctx)); FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx), FArgTypes, false); - F = Function::Create(FTy, Function::ExternalLinkage, "", M.get()); + F = Function::Create(FTy, Function::ExternalLinkage, "", *M.get()); } LLVMContext Ctx; Index: unittests/IR/LegacyPassManagerTest.cpp =================================================================== --- unittests/IR/LegacyPassManagerTest.cpp +++ unittests/IR/LegacyPassManagerTest.cpp @@ -423,7 +423,7 @@ Function* func_test1 = Function::Create( /*Type=*/FuncTy_0, /*Linkage=*/GlobalValue::ExternalLinkage, - /*Name=*/"test1", mod); + /*Name=*/"test1", *mod); func_test1->setCallingConv(CallingConv::C); AttributeList func_test1_PAL; func_test1->setAttributes(func_test1_PAL); @@ -431,7 +431,7 @@ Function* func_test2 = Function::Create( /*Type=*/FuncTy_0, /*Linkage=*/GlobalValue::ExternalLinkage, - /*Name=*/"test2", mod); + /*Name=*/"test2", *mod); func_test2->setCallingConv(CallingConv::C); AttributeList func_test2_PAL; func_test2->setAttributes(func_test2_PAL); @@ -439,7 +439,7 @@ Function* func_test3 = Function::Create( /*Type=*/FuncTy_0, /*Linkage=*/GlobalValue::ExternalLinkage, - /*Name=*/"test3", mod); + /*Name=*/"test3", *mod); func_test3->setCallingConv(CallingConv::C); AttributeList func_test3_PAL; func_test3->setAttributes(func_test3_PAL); @@ -447,7 +447,7 @@ Function* func_test4 = Function::Create( /*Type=*/FuncTy_2, /*Linkage=*/GlobalValue::ExternalLinkage, - /*Name=*/"test4", mod); + /*Name=*/"test4", *mod); func_test4->setCallingConv(CallingConv::C); AttributeList func_test4_PAL; func_test4->setAttributes(func_test4_PAL); Index: unittests/IR/MetadataTest.cpp =================================================================== --- unittests/IR/MetadataTest.cpp +++ unittests/IR/MetadataTest.cpp @@ -347,8 +347,8 @@ TEST_F(MDNodeTest, PrintFromFunction) { Module M("test", Context); auto *FTy = FunctionType::get(Type::getVoidTy(Context), false); - auto *F0 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F0", &M); - auto *F1 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F1", &M); + auto *F0 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F0", M); + auto *F1 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F1", M); auto *BB0 = BasicBlock::Create(Context, "entry", F0); auto *BB1 = BasicBlock::Create(Context, "entry", F1); auto *R0 = ReturnInst::Create(Context, BB0); @@ -372,11 +372,11 @@ auto *Intrinsic = Function::Create(FunctionType::get(Type::getVoidTy(Context), Type::getMetadataTy(Context), false), - GlobalValue::ExternalLinkage, "llvm.intrinsic", &M); + GlobalValue::ExternalLinkage, "llvm.intrinsic", M); auto *FTy = FunctionType::get(Type::getVoidTy(Context), false); - auto *F0 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F0", &M); - auto *F1 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F1", &M); + auto *F0 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F0", M); + auto *F1 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F1", M); auto *BB0 = BasicBlock::Create(Context, "entry", F0); auto *BB1 = BasicBlock::Create(Context, "entry", F1); auto *N0 = MDNode::getDistinct(Context, None); Index: unittests/IR/PatternMatch.cpp =================================================================== --- unittests/IR/PatternMatch.cpp +++ unittests/IR/PatternMatch.cpp @@ -41,7 +41,7 @@ : M(new Module("PatternMatchTestModule", Ctx)), F(Function::Create( FunctionType::get(Type::getVoidTy(Ctx), /* IsVarArg */ false), - Function::ExternalLinkage, "f", M.get())), + Function::ExternalLinkage, "f", *M.get())), BB(BasicBlock::Create(Ctx, "entry", F)), IRB(BB) {} }; Index: unittests/IR/UserTest.cpp =================================================================== --- unittests/IR/UserTest.cpp +++ unittests/IR/UserTest.cpp @@ -123,9 +123,9 @@ Module M("", Context); FunctionType *RetVoidTy = FunctionType::get(Type::getVoidTy(Context), false); Function *PersonalityF = Function::Create( - RetVoidTy, GlobalValue::ExternalLinkage, "PersonalityFn", &M); + RetVoidTy, GlobalValue::ExternalLinkage, "PersonalityFn", M); Function *TestF = - Function::Create(RetVoidTy, GlobalValue::ExternalLinkage, "TestFn", &M); + Function::Create(RetVoidTy, GlobalValue::ExternalLinkage, "TestFn", M); // Set up the personality function TestF->setPersonalityFn(PersonalityF); Index: unittests/IR/VerifierTest.cpp =================================================================== --- unittests/IR/VerifierTest.cpp +++ unittests/IR/VerifierTest.cpp @@ -139,7 +139,7 @@ Module M("M", C); FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), /*isVarArg=*/false); - Function::Create(FTy, GlobalValue::LinkOnceODRLinkage, "foo", &M); + Function::Create(FTy, GlobalValue::LinkOnceODRLinkage, "foo", M); std::string Error; raw_string_ostream ErrorOS(Error); EXPECT_TRUE(verifyModule(M, &ErrorOS)); Index: unittests/IR/WaymarkTest.cpp =================================================================== --- unittests/IR/WaymarkTest.cpp +++ unittests/IR/WaymarkTest.cpp @@ -28,7 +28,7 @@ }); FunctionType *FT = FunctionType::get(Type::getVoidTy(Context), true); std::unique_ptr F( - Function::Create(FT, GlobalValue::ExternalLinkage)); + Function::Create(FT, GlobalValue::ExternalLinkage, /*AddrSpace=*/0)); const CallInst *A = CallInst::Create(F.get(), makeArrayRef(values)); ASSERT_NE(A, (const CallInst*)nullptr); ASSERT_EQ(1U + 22, A->getNumOperands()); Index: unittests/Linker/LinkModulesTest.cpp =================================================================== --- unittests/Linker/LinkModulesTest.cpp +++ unittests/Linker/LinkModulesTest.cpp @@ -30,7 +30,7 @@ M.reset(new Module("MyModule", Ctx)); FunctionType *FTy = FunctionType::get( Type::getInt8PtrTy(Ctx), Type::getInt32Ty(Ctx), false /*=isVarArg*/); - F = Function::Create(FTy, Function::ExternalLinkage, "ba_func", M.get()); + F = Function::Create(FTy, Function::ExternalLinkage, "ba_func", *M.get()); F->setCallingConv(CallingConv::C); EntryBB = BasicBlock::Create(Ctx, "entry", F); @@ -137,7 +137,7 @@ Type::getVoidTy(Ctx), Type::getInt8PtrTy(Ctx), false /*=isVarArgs*/); Function *F = - Function::Create(FTy, Function::ExternalLinkage, FuncName, M); + Function::Create(FTy, Function::ExternalLinkage, FuncName, *M); F->setCallingConv(CallingConv::C); BasicBlock *BB = BasicBlock::Create(Ctx, "", F); @@ -152,7 +152,7 @@ Type::getVoidTy(Ctx), Type::getInt8PtrTy(Ctx), false /*=isVarArgs*/); Function *F = - Function::Create(FTy, Function::InternalLinkage, "bar", InternalM); + Function::Create(FTy, Function::InternalLinkage, "bar", *InternalM); F->setCallingConv(CallingConv::C); BasicBlock *BB = BasicBlock::Create(Ctx, "", F); Index: unittests/ProfileData/InstrProfTest.cpp =================================================================== --- unittests/ProfileData/InstrProfTest.cpp +++ unittests/ProfileData/InstrProfTest.cpp @@ -288,7 +288,7 @@ FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx), /*isVarArg=*/false); Function *F = - Function::Create(FTy, Function::ExternalLinkage, "caller", M.get()); + Function::Create(FTy, Function::ExternalLinkage, "caller", *M.get()); BasicBlock *BB = BasicBlock::Create(Ctx, "", F); IRBuilder<> Builder(BB); @@ -894,18 +894,18 @@ std::unique_ptr M = llvm::make_unique("MyModule.cpp", Ctx); FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx), /*isVarArg=*/false); - Function::Create(FTy, Function::ExternalLinkage, "Gfoo", M.get()); - Function::Create(FTy, Function::ExternalLinkage, "Gblah", M.get()); - Function::Create(FTy, Function::ExternalLinkage, "Gbar", M.get()); - Function::Create(FTy, Function::InternalLinkage, "Ifoo", M.get()); - Function::Create(FTy, Function::InternalLinkage, "Iblah", M.get()); - Function::Create(FTy, Function::InternalLinkage, "Ibar", M.get()); - Function::Create(FTy, Function::PrivateLinkage, "Pfoo", M.get()); - Function::Create(FTy, Function::PrivateLinkage, "Pblah", M.get()); - Function::Create(FTy, Function::PrivateLinkage, "Pbar", M.get()); - Function::Create(FTy, Function::WeakODRLinkage, "Wfoo", M.get()); - Function::Create(FTy, Function::WeakODRLinkage, "Wblah", M.get()); - Function::Create(FTy, Function::WeakODRLinkage, "Wbar", M.get()); + Function::Create(FTy, Function::ExternalLinkage, "Gfoo", *M.get()); + Function::Create(FTy, Function::ExternalLinkage, "Gblah", *M.get()); + Function::Create(FTy, Function::ExternalLinkage, "Gbar", *M.get()); + Function::Create(FTy, Function::InternalLinkage, "Ifoo", *M.get()); + Function::Create(FTy, Function::InternalLinkage, "Iblah", *M.get()); + Function::Create(FTy, Function::InternalLinkage, "Ibar", *M.get()); + Function::Create(FTy, Function::PrivateLinkage, "Pfoo", *M.get()); + Function::Create(FTy, Function::PrivateLinkage, "Pblah", *M.get()); + Function::Create(FTy, Function::PrivateLinkage, "Pbar", *M.get()); + Function::Create(FTy, Function::WeakODRLinkage, "Wfoo", *M.get()); + Function::Create(FTy, Function::WeakODRLinkage, "Wblah", *M.get()); + Function::Create(FTy, Function::WeakODRLinkage, "Wbar", *M.get()); InstrProfSymtab ProfSymtab; EXPECT_THAT_ERROR(ProfSymtab.create(*M), Succeeded()); Index: unittests/Transforms/Utils/Cloning.cpp =================================================================== --- unittests/Transforms/Utils/Cloning.cpp +++ unittests/Transforms/Utils/Cloning.cpp @@ -160,12 +160,14 @@ Type *ArgTy1[] = { Type::getInt32PtrTy(context) }; FunctionType *FT1 = FunctionType::get(Type::getVoidTy(context), ArgTy1, false); - Function *F1 = Function::Create(FT1, Function::ExternalLinkage); + Function *F1 = Function::Create(FT1, Function::ExternalLinkage, + /*AddrSpace=*/0); BasicBlock *BB = BasicBlock::Create(context, "", F1); IRBuilder<> Builder(BB); Builder.CreateRetVoid(); - Function *F2 = Function::Create(FT1, Function::ExternalLinkage); + Function *F2 = Function::Create(FT1, Function::ExternalLinkage, + /*AddrSpace=*/0); Argument *A = &*F1->arg_begin(); A->addAttr(Attribute::NoCapture); @@ -185,13 +187,15 @@ Type *ArgTy1[] = { Type::getInt32PtrTy(context) }; FunctionType *FT1 = FunctionType::get(Type::getVoidTy(context), ArgTy1, false); - Function *F1 = Function::Create(FT1, Function::ExternalLinkage); + Function *F1 = Function::Create(FT1, Function::ExternalLinkage, + /*AddrSpace=*/0); F1->setCallingConv(CallingConv::Cold); BasicBlock *BB = BasicBlock::Create(context, "", F1); IRBuilder<> Builder(BB); Builder.CreateRetVoid(); - Function *F2 = Function::Create(FT1, Function::ExternalLinkage); + Function *F2 = Function::Create(FT1, Function::ExternalLinkage, + /*AddrSpace=*/0); SmallVector Returns; ValueToValueMapTy VMap; @@ -209,7 +213,8 @@ FunctionType *FT = FunctionType::get(Type::getVoidTy(context), ArgTy1, false); V = new Argument(Type::getInt32Ty(context)); - Function *F = Function::Create(FT, Function::ExternalLinkage); + Function *F = Function::Create(FT, Function::ExternalLinkage, + /*AddrSpace=*/0); BasicBlock *BB1 = BasicBlock::Create(context, "", F); IRBuilder<> Builder1(BB1); @@ -268,7 +273,7 @@ void CreateOldFunc() { FunctionType* FuncType = FunctionType::get(Type::getVoidTy(C), false); - OldFunc = Function::Create(FuncType, GlobalValue::PrivateLinkage, "f", M); + OldFunc = Function::Create(FuncType, GlobalValue::PrivateLinkage, "f", *M); CreateOldFunctionBodyAndDI(); } @@ -486,9 +491,9 @@ auto *FuncType = FunctionType::get(Type::getVoidTy(C), false); auto *PersFn = Function::Create(FuncType, GlobalValue::ExternalLinkage, - "persfn", OldM); + "persfn", *OldM); auto *F = - Function::Create(FuncType, GlobalValue::PrivateLinkage, "f", OldM); + Function::Create(FuncType, GlobalValue::PrivateLinkage, "f", *OldM); F->setPersonalityFn(PersFn); F->setComdat(CD); Index: unittests/Transforms/Utils/FunctionComparator.cpp =================================================================== --- unittests/Transforms/Utils/FunctionComparator.cpp +++ unittests/Transforms/Utils/FunctionComparator.cpp @@ -28,7 +28,7 @@ IRBuilder<> B(Ctx); T = B.getInt8Ty(); F = Function::Create(FunctionType::get(T, {B.getInt8PtrTy()}, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); BB = BasicBlock::Create(Ctx, "", F); B.SetInsertPoint(BB); Argument *PointerArg = &*F->arg_begin(); Index: unittests/Transforms/Utils/IntegerDivision.cpp =================================================================== --- unittests/Transforms/Utils/IntegerDivision.cpp +++ unittests/Transforms/Utils/IntegerDivision.cpp @@ -28,7 +28,7 @@ SmallVector ArgTys(2, Builder.getInt32Ty()); Function *F = Function::Create(FunctionType::get(Builder.getInt32Ty(), ArgTys, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); assert(F->arg_size() == 2); BasicBlock *BB = BasicBlock::Create(C, "", F); @@ -58,7 +58,7 @@ SmallVector ArgTys(2, Builder.getInt32Ty()); Function *F = Function::Create(FunctionType::get(Builder.getInt32Ty(), ArgTys, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); assert(F->arg_size() == 2); BasicBlock *BB = BasicBlock::Create(C, "", F); @@ -88,7 +88,7 @@ SmallVector ArgTys(2, Builder.getInt32Ty()); Function *F = Function::Create(FunctionType::get(Builder.getInt32Ty(), ArgTys, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); assert(F->arg_size() == 2); BasicBlock *BB = BasicBlock::Create(C, "", F); @@ -118,7 +118,7 @@ SmallVector ArgTys(2, Builder.getInt32Ty()); Function *F = Function::Create(FunctionType::get(Builder.getInt32Ty(), ArgTys, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); assert(F->arg_size() == 2); BasicBlock *BB = BasicBlock::Create(C, "", F); @@ -149,7 +149,7 @@ SmallVector ArgTys(2, Builder.getInt64Ty()); Function *F = Function::Create(FunctionType::get(Builder.getInt64Ty(), ArgTys, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); assert(F->arg_size() == 2); BasicBlock *BB = BasicBlock::Create(C, "", F); @@ -179,7 +179,7 @@ SmallVector ArgTys(2, Builder.getInt64Ty()); Function *F = Function::Create(FunctionType::get(Builder.getInt64Ty(), ArgTys, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); assert(F->arg_size() == 2); BasicBlock *BB = BasicBlock::Create(C, "", F); @@ -209,7 +209,7 @@ SmallVector ArgTys(2, Builder.getInt64Ty()); Function *F = Function::Create(FunctionType::get(Builder.getInt64Ty(), ArgTys, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); assert(F->arg_size() == 2); BasicBlock *BB = BasicBlock::Create(C, "", F); @@ -239,7 +239,7 @@ SmallVector ArgTys(2, Builder.getInt64Ty()); Function *F = Function::Create(FunctionType::get(Builder.getInt64Ty(), ArgTys, false), - GlobalValue::ExternalLinkage, "F", &M); + GlobalValue::ExternalLinkage, "F", M); assert(F->arg_size() == 2); BasicBlock *BB = BasicBlock::Create(C, "", F); Index: unittests/Transforms/Utils/Local.cpp =================================================================== --- unittests/Transforms/Utils/Local.cpp +++ unittests/Transforms/Utils/Local.cpp @@ -69,7 +69,7 @@ std::unique_ptr F( Function::Create(FunctionType::get(B.getVoidTy(), false), - GlobalValue::ExternalLinkage, "F")); + GlobalValue::ExternalLinkage, /*AddrSpace=*/0, "F")); BasicBlock *Entry(BasicBlock::Create(C, "", F.get())); BasicBlock *BB(BasicBlock::Create(C, "", F.get())); BranchInst::Create(BB, Entry); Index: unittests/Transforms/Utils/ValueMapperTest.cpp =================================================================== --- unittests/Transforms/Utils/ValueMapperTest.cpp +++ unittests/Transforms/Utils/ValueMapperTest.cpp @@ -175,7 +175,8 @@ FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), Type::getInt8Ty(C), false); std::unique_ptr F( - Function::Create(FTy, GlobalValue::ExternalLinkage, "F")); + Function::Create(FTy, GlobalValue::ExternalLinkage, /*AddrSpace=*/0, + "F")); ValueToValueMapTy VM; RemapFlags Flags = RF_IgnoreMissingLocals | RF_NullMapMissingGlobalValues; @@ -234,7 +235,8 @@ FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), Type::getInt8Ty(C), false); std::unique_ptr F( - Function::Create(FTy, GlobalValue::ExternalLinkage, "F")); + Function::Create(FTy, GlobalValue::ExternalLinkage, /*AddrSpace=*/0, + "F")); auto *CAM = ConstantAsMetadata::get(F.get()); { @@ -253,7 +255,8 @@ } std::unique_ptr F2( - Function::Create(FTy, GlobalValue::ExternalLinkage, "F2")); + Function::Create(FTy, GlobalValue::ExternalLinkage, /*AddrSpace=*/0, + "F2")); ValueToValueMapTy VM; VM[F.get()] = F2.get(); auto *F2MD = ValueMapper(VM).mapMetadata(*CAM); @@ -269,7 +272,8 @@ FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), Type::getInt8Ty(C), false); std::unique_ptr F( - Function::Create(FTy, GlobalValue::ExternalLinkage, "F")); + Function::Create(FTy, GlobalValue::ExternalLinkage, /*AddrSpace=*/0, + "F")); Argument &A = *F->arg_begin(); // mapMetadata doesn't support LocalAsMetadata. The only valid container for @@ -288,7 +292,8 @@ FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), Type::getInt8Ty(C), false); std::unique_ptr F( - Function::Create(FTy, GlobalValue::ExternalLinkage, "F")); + Function::Create(FTy, GlobalValue::ExternalLinkage, /*AddrSpace=*/0, + "F")); Argument &A = *F->arg_begin(); auto *LAM = LocalAsMetadata::get(&A); @@ -330,7 +335,8 @@ auto *Int8 = Type::getInt8Ty(Context); FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), Int8, false); std::unique_ptr F( - Function::Create(FTy, GlobalValue::ExternalLinkage, "F")); + Function::Create(FTy, GlobalValue::ExternalLinkage, /*AddrSpace=*/0, + "F")); // Map a local value to a constant. Argument &A = *F->arg_begin();