Index: docs/BitCodeFormat.rst =================================================================== --- docs/BitCodeFormat.rst +++ docs/BitCodeFormat.rst @@ -1140,7 +1140,7 @@ * *address space*: If supplied, the target-specific numbered address space where the pointed-to object resides. Otherwise, the default address space is zero. -TYPE_CODE_FUNCTION_OLD Record +TYPE_CODE_FUNCTION_VERY_OLD Record ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. note:: @@ -1148,9 +1148,9 @@ earlier. It is guaranteed to be understood by the current LLVM version, as specified in the :ref:`IR backwards compatibility` policy. -``[FUNCTION_OLD, vararg, ignored, retty, ...paramty... ]`` +``[FUNCTION_VERY_OLD, vararg, ignored, retty, ...paramty... ]`` -The ``FUNCTION_OLD`` record (code 9) adds a function type to the type table. +The ``FUNCTION_VERY_OLD`` record (code 9) adds a function type to the type table. The operand fields are * *vararg*: Non-zero if the type represents a varargs function @@ -1163,6 +1163,8 @@ * *paramty*: Zero or more type indices representing the parameter types of the function +FIXME: Add docs for new record type + TYPE_CODE_ARRAY Record ^^^^^^^^^^^^^^^^^^^^^^ @@ -1261,12 +1263,14 @@ * *eltty*: Zero or more type indices representing the element types of the structure -TYPE_CODE_FUNCTION Record +TYPE_CODE_FUNCTION_OLD Record ^^^^^^^^^^^^^^^^^^^^^^^^^ -``[FUNCTION, vararg, retty, ...paramty... ]`` +``[FUNCTION_OLD, vararg, retty, ...paramty... ]`` + +FIXME: add a note about legacy -The ``FUNCTION`` record (code 21) adds a function type to the type table. The +The ``FUNCTION_OLD`` record (code 21) adds a function type to the type table. The operand fields are * *vararg*: Non-zero if the type represents a varargs function Index: docs/LangRef.rst =================================================================== --- docs/LangRef.rst +++ docs/LangRef.rst @@ -1869,8 +1869,15 @@ must be a multiple of 8-bits. If omitted, the natural stack alignment defaults to "unspecified", which does not prevent any alignment promotions. +``P
`` + Specifies the address space that corresponds to program memory. + Harvard architectures can use this to specify what space LLVM + should place things such as functions or switch lookup tables + into. If omitted, the program memory space defaults to the + default address space of 0, which corresponds to a Von Neumann + architecture that has code and data in the same space. ``A
`` - Specifies the address space of objects created by '``alloca``'. + Specifies the address space of objects created by '``alloca``'. Defaults to the default address space of 0. ``p[n]:::`` This specifies the *size* of a pointer and its ```` and Index: include/llvm/Bitcode/LLVMBitCodes.h =================================================================== --- include/llvm/Bitcode/LLVMBitCodes.h +++ include/llvm/Bitcode/LLVMBitCodes.h @@ -142,8 +142,8 @@ TYPE_CODE_INTEGER = 7, // INTEGER: [width] TYPE_CODE_POINTER = 8, // POINTER: [pointee type] - TYPE_CODE_FUNCTION_OLD = 9, // FUNCTION: [vararg, attrid, retty, - // paramty x N] + TYPE_CODE_FUNCTION_VERY_OLD = 9, // FUNCTION: [vararg, attrid, retty, + // paramty x N] TYPE_CODE_HALF = 10, // HALF @@ -165,9 +165,10 @@ TYPE_CODE_STRUCT_NAME = 19, // STRUCT_NAME: [strchr x N] TYPE_CODE_STRUCT_NAMED = 20, // STRUCT_NAMED: [ispacked, eltty x N] - TYPE_CODE_FUNCTION = 21, // FUNCTION: [vararg, retty, paramty x N] + TYPE_CODE_FUNCTION_OLD = 21, // FUNCTION: [vararg, retty, paramty x N] - TYPE_CODE_TOKEN = 22 // TOKEN + TYPE_CODE_TOKEN = 22, // TOKEN + TYPE_CODE_FUNCTION = 23 // FUNCTION: [vararg, addrspace, retty, paramty x N] }; enum OperandBundleTagCode { Index: include/llvm/IR/DataLayout.h =================================================================== --- include/llvm/IR/DataLayout.h +++ include/llvm/IR/DataLayout.h @@ -113,6 +113,7 @@ unsigned AllocaAddrSpace; unsigned StackNaturalAlign; + unsigned ProgramAddrSpace; enum ManglingModeT { MM_None, @@ -196,6 +197,7 @@ BigEndian = DL.isBigEndian(); AllocaAddrSpace = DL.AllocaAddrSpace; StackNaturalAlign = DL.StackNaturalAlign; + ProgramAddrSpace = DL.ProgramAddrSpace; ManglingMode = DL.ManglingMode; LegalIntWidths = DL.LegalIntWidths; Alignments = DL.Alignments; @@ -252,6 +254,8 @@ unsigned getStackAlignment() const { return StackNaturalAlign; } unsigned getAllocaAddrSpace() const { return AllocaAddrSpace; } + unsigned getProgramAddressSpace() const { return ProgramAddrSpace; } + bool hasMicrosoftFastStdCallMangling() const { return ManglingMode == MM_WinCOFFX86; } Index: include/llvm/IR/DerivedTypes.h =================================================================== --- include/llvm/IR/DerivedTypes.h +++ include/llvm/IR/DerivedTypes.h @@ -49,10 +49,11 @@ /// This enum is just used to hold constants we need for IntegerType. enum { MIN_INT_BITS = 1, ///< Minimum number of bits that can be specified - MAX_INT_BITS = (1<<24)-1 ///< Maximum number of bits that can be specified - ///< Note that bit width is stored in the Type classes SubclassData field - ///< which has 24 bits. This yields a maximum bit width of 16,777,215 - ///< bits. + /// Maximum number of bits that can be specified + /// Note that bit width is stored in the Type classes SubclassData field + /// which has 24 bits. This yields a maximum bit width of 16,777,215 + /// bits. + MAX_INT_BITS = (1< Params, bool IsVarArgs); + FunctionType(Type *Result, ArrayRef Params, bool IsVarArgs, + unsigned AddrSpace); public: FunctionType(const FunctionType &) = delete; @@ -109,10 +111,11 @@ /// This static method is the primary way of constructing a FunctionType. static FunctionType *get(Type *Result, - ArrayRef Params, bool isVarArg); + ArrayRef Params, bool isVarArg, + unsigned AddrSpace); /// Create a FunctionType taking no parameters. - static FunctionType *get(Type *Result, bool isVarArg); + static FunctionType *get(Type *Result, bool isVarArg, unsigned AddrSpace); /// Return true if the specified type is valid as a return type. static bool isValidReturnType(Type *RetTy); @@ -120,7 +123,15 @@ /// Return true if the specified type is valid as an argument type. static bool isValidArgumentType(Type *ArgTy); - bool isVarArg() const { return getSubclassData()!=0; } + bool isVarArg() const { + return (getSubclassData() & 1) != 0; + } + + unsigned getAddressSpace() const { + unsigned Mask = ~1; + return (getSubclassData() & Mask) >> 1; + } + Type *getReturnType() const { return ContainedTys[0]; } using param_iterator = Type::subtype_iterator; Index: include/llvm/IR/Function.h =================================================================== --- include/llvm/IR/Function.h +++ include/llvm/IR/Function.h @@ -149,6 +149,9 @@ /// arguments. bool isVarArg() const { return getFunctionType()->isVarArg(); } + /// Gets the address space that the function resides in. + unsigned getAddressSpace() const { return getFunctionType()->getAddressSpace(); } + bool isMaterializable() const { return getGlobalObjectSubClassData() & (1 << IsMaterializableBit); } Index: include/llvm/IR/GlobalValue.h =================================================================== --- include/llvm/IR/GlobalValue.h +++ include/llvm/IR/GlobalValue.h @@ -177,6 +177,7 @@ GlobalValue(const GlobalValue &) = delete; unsigned getAlignment() const; + unsigned getAddressSpace() const; enum class UnnamedAddr { None, Index: include/llvm/IR/Module.h =================================================================== --- include/llvm/IR/Module.h +++ include/llvm/IR/Module.h @@ -343,7 +343,8 @@ { SmallVector ArgTys{Args...}; return getOrInsertFunction(Name, - FunctionType::get(RetTy, ArgTys, false), + FunctionType::get(RetTy, ArgTys, false, + DL.getProgramAddressSpace()), AttributeList); } Index: include/llvm/IR/Type.h =================================================================== --- include/llvm/IR/Type.h +++ include/llvm/IR/Type.h @@ -26,6 +26,10 @@ #include #include +// The width of the integer field that type subclasses can +// use for arbitrary information. +#define SUBCLASS_DATA_BITS 24 + namespace llvm { template struct GraphTraits; @@ -80,10 +84,10 @@ /// This refers to the LLVMContext in which this type was uniqued. LLVMContext &Context; - TypeID ID : 8; // The current base type of this type. - unsigned SubclassData : 24; // Space for subclasses to store data. - // Note that this should be synchronized with - // MAX_INT_BITS value in IntegerType class. + // The current base type of this type. + TypeID ID : 8; + // Space for subclasses to store data. + unsigned SubclassData : SUBCLASS_DATA_BITS; protected: friend class LLVMContextImpl; Index: include/llvm/IR/TypeBuilder.h =================================================================== --- include/llvm/IR/TypeBuilder.h +++ include/llvm/IR/TypeBuilder.h @@ -19,6 +19,8 @@ #include "llvm/IR/LLVMContext.h" #include +// FIXME: we probably need to update this for func addr space + namespace llvm { /// TypeBuilder - This provides a uniform API for looking up types @@ -255,7 +257,9 @@ template class TypeBuilder { public: static FunctionType *get(LLVMContext &Context) { - return FunctionType::get(TypeBuilder::get(Context), false); + unsigned AddrSpace = 0; // FIXME: don't assume this + return FunctionType::get(TypeBuilder::get(Context), false, + AddrSpace); } }; template class TypeBuilder { @@ -264,8 +268,9 @@ Type *params[] = { TypeBuilder::get(Context), }; + unsigned AddrSpace = 0; // FIXME: don't assume this return FunctionType::get(TypeBuilder::get(Context), - params, false); + params, false, AddrSpace); } }; template @@ -276,8 +281,9 @@ TypeBuilder::get(Context), TypeBuilder::get(Context), }; + unsigned AddrSpace = 0; // FIXME: don't assume this return FunctionType::get(TypeBuilder::get(Context), - params, false); + params, false, AddrSpace); } }; template @@ -289,8 +295,9 @@ TypeBuilder::get(Context), TypeBuilder::get(Context), }; + unsigned AddrSpace = 0; // FIXME: don't assume this return FunctionType::get(TypeBuilder::get(Context), - params, false); + params, false, AddrSpace); } }; @@ -305,8 +312,9 @@ TypeBuilder::get(Context), TypeBuilder::get(Context), }; + unsigned AddrSpace = 0; // FIXME: don't assume this return FunctionType::get(TypeBuilder::get(Context), - params, false); + params, false, AddrSpace); } }; @@ -322,15 +330,18 @@ TypeBuilder::get(Context), TypeBuilder::get(Context), }; + unsigned AddrSpace = 0; // FIXME: don't assume this return FunctionType::get(TypeBuilder::get(Context), - params, false); + params, false, AddrSpace); } }; template class TypeBuilder { public: static FunctionType *get(LLVMContext &Context) { - return FunctionType::get(TypeBuilder::get(Context), true); + unsigned AddrSpace = 0; // FIXME: don't assume this + return FunctionType::get(TypeBuilder::get(Context), true, + AddrSpace); } }; template @@ -340,7 +351,8 @@ Type *params[] = { TypeBuilder::get(Context), }; - return FunctionType::get(TypeBuilder::get(Context), params, true); + unsigned AddrSpace = 0; // FIXME: don't assume this + return FunctionType::get(TypeBuilder::get(Context), params, true, AddrSpace); } }; template @@ -351,8 +363,9 @@ TypeBuilder::get(Context), TypeBuilder::get(Context), }; + unsigned AddrSpace = 0; // FIXME: don't assume this return FunctionType::get(TypeBuilder::get(Context), - params, true); + params, true, AddrSpace); } }; template @@ -364,8 +377,9 @@ TypeBuilder::get(Context), TypeBuilder::get(Context), }; + unsigned AddrSpace = 0; // FIXME: don't assume this return FunctionType::get(TypeBuilder::get(Context), - params, true); + params, true, AddrSpace); } }; @@ -380,8 +394,9 @@ TypeBuilder::get(Context), TypeBuilder::get(Context), }; + unsigned AddrSpace = 0; // FIXME: don't assume this return FunctionType::get(TypeBuilder::get(Context), - params, true); + params, true, AddrSpace); } }; @@ -397,8 +412,9 @@ TypeBuilder::get(Context), TypeBuilder::get(Context), }; + unsigned AddrSpace = 0; // FIXME: don't assume this return FunctionType::get(TypeBuilder::get(Context), - params, true); + params, true, AddrSpace); } }; Index: lib/AsmParser/LLParser.cpp =================================================================== --- lib/AsmParser/LLParser.cpp +++ lib/AsmParser/LLParser.cpp @@ -2334,10 +2334,12 @@ } /// ParseFunctionType -/// ::= Type ArgumentList OptionalAttrs +/// ::= Type ArgumentList OptionalAddrSpace OptionalAttrs bool LLParser::ParseFunctionType(Type *&Result) { assert(Lex.getKind() == lltok::lparen); + const DataLayout &DL = M->getDataLayout(); + if (!FunctionType::isValidReturnType(Result)) return TokError("invalid function return type"); @@ -2346,6 +2348,10 @@ if (ParseArgumentList(ArgList, isVarArg)) return true; + unsigned AddrSpace = DL.getProgramAddressSpace(); + if (ParseOptionalAddrSpace(AddrSpace)) + return true; + // Reject names on the arguments lists. for (unsigned i = 0, e = ArgList.size(); i != e; ++i) { if (!ArgList[i].Name.empty()) @@ -2359,7 +2365,7 @@ for (unsigned i = 0, e = ArgList.size(); i != e; ++i) ArgListTy.push_back(ArgList[i].Ty); - Result = FunctionType::get(Result, ArgListTy, isVarArg); + Result = FunctionType::get(Result, ArgListTy, isVarArg, AddrSpace); return false; } @@ -4700,6 +4706,9 @@ bool HasLinkage; Type *RetType = nullptr; LocTy RetTypeLoc = Lex.getLoc(); + + const DataLayout &DL = M->getDataLayout(); + if (ParseOptionalLinkage(Linkage, HasLinkage, Visibility, DLLStorageClass) || ParseOptionalCallingConv(CC) || ParseOptionalReturnAttrs(RetAttrs) || ParseType(RetType, RetTypeLoc, true /*void allowed*/)) @@ -4765,6 +4774,7 @@ std::string GC; GlobalValue::UnnamedAddr UnnamedAddr = GlobalValue::UnnamedAddr::None; LocTy UnnamedAddrLoc; + unsigned AddrSpace = DL.getProgramAddressSpace(); Constant *Prefix = nullptr; Constant *Prologue = nullptr; Constant *PersonalityFn = nullptr; @@ -4772,6 +4782,7 @@ if (ParseArgumentList(ArgList, isVarArg) || ParseOptionalUnnamedAddr(UnnamedAddr) || + ParseOptionalAddrSpace(AddrSpace) || ParseFnAttributeValuePairs(FuncAttrs, FwdRefAttrGrps, false, BuiltinLoc) || (EatIfPresent(lltok::kw_section) && @@ -4815,7 +4826,7 @@ return Error(RetTypeLoc, "functions with 'sret' argument must return void"); FunctionType *FT = - FunctionType::get(RetType, ParamTypeList, isVarArg); + FunctionType::get(RetType, ParamTypeList, isVarArg, AddrSpace); PointerType *PFT = PointerType::getUnqual(FT); Fn = nullptr; @@ -5383,6 +5394,9 @@ SmallVector BundleList; BasicBlock *NormalBB, *UnwindBB; + + const DataLayout &DL = M->getDataLayout(); + if (ParseOptionalCallingConv(CC) || ParseOptionalReturnAttrs(RetAttrs) || ParseType(RetType, RetTypeLoc, true /*void allowed*/) || ParseValID(CalleeID) || ParseParameterList(ArgList, PFS) || @@ -5408,7 +5422,8 @@ if (!FunctionType::isValidReturnType(RetType)) return Error(RetTypeLoc, "Invalid result type for LLVM function"); - Ty = FunctionType::get(RetType, ParamTypes, false); + Ty = FunctionType::get(RetType, ParamTypes, false, + DL.getProgramAddressSpace()); } CalleeID.FTy = Ty; @@ -5967,6 +5982,8 @@ SmallVector BundleList; LocTy CallLoc = Lex.getLoc(); + const DataLayout &DL = M->getDataLayout(); + if (TCK != CallInst::TCK_None && ParseToken(lltok::kw_call, "expected 'tail call', 'musttail call', or 'notail call'")) @@ -6000,7 +6017,8 @@ if (!FunctionType::isValidReturnType(RetType)) return Error(RetTypeLoc, "Invalid result type for LLVM function"); - Ty = FunctionType::get(RetType, ParamTypes, false); + Ty = FunctionType::get(RetType, ParamTypes, false, + DL.getProgramAddressSpace()); } CalleeID.FTy = Ty; Index: lib/Bitcode/Reader/BitcodeReader.cpp =================================================================== --- lib/Bitcode/Reader/BitcodeReader.cpp +++ lib/Bitcode/Reader/BitcodeReader.cpp @@ -1578,9 +1578,9 @@ ResultTy = PointerType::get(ResultTy, AddressSpace); break; } - case bitc::TYPE_CODE_FUNCTION_OLD: { + case bitc::TYPE_CODE_FUNCTION_VERY_OLD: { // FIXME: attrid is dead, remove it in LLVM 4.0 - // FUNCTION: [vararg, attrid, retty, paramty x N] + // FUNCTION_VERY_OLD: [vararg, attrid, retty, paramty x N] if (Record.size() < 3) return error("Invalid record"); SmallVector ArgTys; @@ -1595,11 +1595,14 @@ if (!ResultTy || ArgTys.size() < Record.size()-3) return error("Invalid type"); - ResultTy = FunctionType::get(ResultTy, ArgTys, Record[0]); + // We can assume that address space is zero here because no backend + // supported non-default address spaces on functions prior to release 5.0. + unsigned AddrSpace = 0; + ResultTy = FunctionType::get(ResultTy, ArgTys, Record[0], AddrSpace); break; } - case bitc::TYPE_CODE_FUNCTION: { - // FUNCTION: [vararg, retty, paramty x N] + case bitc::TYPE_CODE_FUNCTION_OLD: { + // FUNCTION_OLD: [vararg, retty, paramty x N] if (Record.size() < 2) return error("Invalid record"); SmallVector ArgTys; @@ -1617,7 +1620,33 @@ if (!ResultTy || ArgTys.size() < Record.size()-2) return error("Invalid type"); - ResultTy = FunctionType::get(ResultTy, ArgTys, Record[0]); + // FIXME: I don't think we can add this in a backwards compatible way + // without some digusting hack. + unsigned AddrSpace = 0; + ResultTy = FunctionType::get(ResultTy, ArgTys, Record[0], AddrSpace); + break; + } + case bitc::TYPE_CODE_FUNCTION: { + // FUNCTION: [vararg, addrspace, retty, paramty x N] + if (Record.size() < 3) + return error("Invalid record"); + SmallVector ArgTys; + for (unsigned i = 3, e = Record.size(); i != e; ++i) { + if (Type *T = getTypeByID(Record[i])) { + if (!FunctionType::isValidArgumentType(T)) + return error("Invalid function argument type"); + ArgTys.push_back(T); + } + else + break; + } + + ResultTy = getTypeByID(Record[2]); + if (!ResultTy || ArgTys.size() < Record.size()-3) + return error("Invalid type"); + + unsigned AddrSpace = Record[1]; + ResultTy = FunctionType::get(ResultTy, ArgTys, Record[0], AddrSpace); break; } case bitc::TYPE_CODE_STRUCT_ANON: { // STRUCT: [ispacked, eltty x N] Index: lib/Bitcode/Writer/BitcodeWriter.cpp =================================================================== --- lib/Bitcode/Writer/BitcodeWriter.cpp +++ lib/Bitcode/Writer/BitcodeWriter.cpp @@ -802,9 +802,10 @@ } case Type::FunctionTyID: { FunctionType *FT = cast(T); - // FUNCTION: [isvararg, retty, paramty x N] + // FUNCTION: [isvararg, addrspace, retty, paramty x N] Code = bitc::TYPE_CODE_FUNCTION; TypeVals.push_back(FT->isVarArg()); + TypeVals.push_back(FT->getAddressSpace()); TypeVals.push_back(VE.getTypeID(FT->getReturnType())); for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) TypeVals.push_back(VE.getTypeID(FT->getParamType(i))); Index: lib/CodeGen/AtomicExpandPass.cpp =================================================================== --- lib/CodeGen/AtomicExpandPass.cpp +++ lib/CodeGen/AtomicExpandPass.cpp @@ -1592,7 +1592,8 @@ SmallVector ArgTys; for (Value *Arg : Args) ArgTys.push_back(Arg->getType()); - FunctionType *FnType = FunctionType::get(ResultTy, ArgTys, false); + FunctionType *FnType = FunctionType::get(ResultTy, ArgTys, false, + DL.getProgramAddressSpace()); Constant *LibcallFn = M->getOrInsertFunction(TLI->getLibcallName(RTLibType), FnType, Attr); CallInst *Call = Builder.CreateCall(LibcallFn, Args); Index: lib/CodeGen/IntrinsicLowering.cpp =================================================================== --- lib/CodeGen/IntrinsicLowering.cpp +++ lib/CodeGen/IntrinsicLowering.cpp @@ -28,11 +28,13 @@ static void EnsureFunctionExists(Module &M, const char *Name, ArgIt ArgBegin, ArgIt ArgEnd, Type *RetTy) { + const auto &DL = M.getDataLayout(); // Insert a correctly-typed definition now. std::vector ParamTys; for (ArgIt I = ArgBegin; I != ArgEnd; ++I) ParamTys.push_back(I->getType()); - M.getOrInsertFunction(Name, FunctionType::get(RetTy, ParamTys, false)); + M.getOrInsertFunction(Name, FunctionType::get(RetTy, ParamTys, false, + DL.getProgramAddressSpace())); } static void EnsureFPIntrinsicsExist(Module &M, Function &Fn, @@ -68,12 +70,14 @@ // If we haven't already looked up this function, check to see if the // program already contains a function with this name. Module *M = CI->getModule(); + const auto &DL = M->getDataLayout(); // Get or insert the definition now. std::vector ParamTys; for (ArgIt I = ArgBegin; I != ArgEnd; ++I) ParamTys.push_back((*I)->getType()); Constant* FCache = M->getOrInsertFunction(NewFn, - FunctionType::get(RetTy, ParamTys, false)); + FunctionType::get(RetTy, ParamTys, false, + DL.getProgramAddressSpace())); IRBuilder<> Builder(CI->getParent(), CI->getIterator()); SmallVector Args(ArgBegin, ArgEnd); Index: lib/CodeGen/MIRParser/MIRParser.cpp =================================================================== --- lib/CodeGen/MIRParser/MIRParser.cpp +++ lib/CodeGen/MIRParser/MIRParser.cpp @@ -268,7 +268,8 @@ static Function *createDummyFunction(StringRef Name, Module &M) { auto &Context = M.getContext(); Function *F = cast(M.getOrInsertFunction( - Name, FunctionType::get(Type::getVoidTy(Context), false))); + Name, FunctionType::get(Type::getVoidTy(Context), false, + M.getDataLayout().getProgramAddressSpace()))); BasicBlock *BB = BasicBlock::Create(Context, "entry", F); new UnreachableInst(Context, BB); return F; Index: lib/IR/AsmWriter.cpp =================================================================== --- lib/IR/AsmWriter.cpp +++ lib/IR/AsmWriter.cpp @@ -2747,6 +2747,9 @@ StringRef UA = getUnnamedAddrEncoding(F->getUnnamedAddr()); if (!UA.empty()) Out << ' ' << UA; + unsigned AddrSpace = FT->getAddressSpace(); + if (AddrSpace != 0) + Out << " addrspace(" << AddrSpace << ")"; 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 @@ -363,7 +363,8 @@ // Can't use Intrinsic::getDeclaration here as it adds a ".i1" to // the end of the name. Change name from llvm.arm.neon.vclz.* to // llvm.ctlz.* - FunctionType* fType = FunctionType::get(F->getReturnType(), args, false); + FunctionType* fType = FunctionType::get(F->getReturnType(), args, false, + F->getAddressSpace()); NewFn = Function::Create(fType, F->getLinkage(), "llvm.ctlz." + Name.substr(14), F->getParent()); return true; @@ -379,7 +380,7 @@ SmallVector Tys(fArgs.begin(), fArgs.end()); // Can't use Intrinsic::getDeclaration here as the return types might // then only be structurally equal. - FunctionType* fType = FunctionType::get(F->getReturnType(), Tys, false); + FunctionType* fType = FunctionType::get(F->getReturnType(), Tys, false, F->getAddressSpace()); NewFn = Function::Create(fType, F->getLinkage(), "llvm." + Name + ".p0i8", F->getParent()); return true; Index: lib/IR/Core.cpp =================================================================== --- lib/IR/Core.cpp +++ lib/IR/Core.cpp @@ -483,7 +483,8 @@ LLVMTypeRef *ParamTypes, unsigned ParamCount, LLVMBool IsVarArg) { ArrayRef Tys(unwrap(ParamTypes), ParamCount); - return wrap(FunctionType::get(unwrap(ReturnType), Tys, IsVarArg != 0)); + unsigned AddrSpace = 0; // FIXME + return wrap(FunctionType::get(unwrap(ReturnType), Tys, IsVarArg != 0, AddrSpace)); } LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy) { Index: lib/IR/DataLayout.cpp =================================================================== --- lib/IR/DataLayout.cpp +++ lib/IR/DataLayout.cpp @@ -181,6 +181,7 @@ BigEndian = false; AllocaAddrSpace = 0; StackNaturalAlign = 0; + ProgramAddrSpace = 0; ManglingMode = MM_None; NonIntegralAddressSpaces.clear(); @@ -221,6 +222,14 @@ return Bits / 8; } +/// Gets an unsigned address space integer, including error checks. +static unsigned int getAddrSpace(StringRef R) { + unsigned AddrSpace = getInt(R); + if (!isUInt<24>(AddrSpace)) + report_fatal_error("Invalid address space, must be a 24-bit integer"); + return AddrSpace; +} + void DataLayout::parseSpecifier(StringRef Desc) { StringRepresentation = Desc; while (!Desc.empty()) { @@ -358,10 +367,12 @@ StackNaturalAlign = inBytes(getInt(Tok)); break; } + case 'P': { // Function address space. + ProgramAddrSpace = getAddrSpace(Tok); + break; + } case 'A': { // Default stack/alloca address space. - AllocaAddrSpace = getInt(Tok); - if (!isUInt<24>(AllocaAddrSpace)) - report_fatal_error("Invalid address space, must be a 24bit integer"); + AllocaAddrSpace = getAddrSpace(Tok); break; } case 'm': Index: lib/IR/Function.cpp =================================================================== --- lib/IR/Function.cpp +++ lib/IR/Function.cpp @@ -940,13 +940,15 @@ while (!TableRef.empty()) ArgTys.push_back(DecodeFixedType(TableRef, Tys, Context)); + unsigned AddrSpace = 0; // FIXME: we should grab the progmem space from DL + // DecodeFixedType returns Void for IITDescriptor::Void and IITDescriptor::VarArg // If we see void type as the type of the last argument, it is vararg intrinsic if (!ArgTys.empty() && ArgTys.back()->isVoidTy()) { ArgTys.pop_back(); - return FunctionType::get(ResultTy, ArgTys, true); + return FunctionType::get(ResultTy, ArgTys, true, AddrSpace); } - return FunctionType::get(ResultTy, ArgTys, false); + return FunctionType::get(ResultTy, ArgTys, false, AddrSpace); } bool Intrinsic::isOverloaded(ID id) { Index: lib/IR/Globals.cpp =================================================================== --- lib/IR/Globals.cpp +++ lib/IR/Globals.cpp @@ -107,6 +107,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/Type.cpp =================================================================== --- lib/IR/Type.cpp +++ lib/IR/Type.cpp @@ -275,11 +275,13 @@ //===----------------------------------------------------------------------===// FunctionType::FunctionType(Type *Result, ArrayRef Params, - bool IsVarArgs) + bool IsVarArgs, unsigned AddrSpace) : Type(Result->getContext(), FunctionTyID) { Type **SubTys = reinterpret_cast(this+1); assert(isValidReturnType(Result) && "invalid return type for function"); - setSubclassData(IsVarArgs); + + unsigned SubclassData = (IsVarArgs & 1) | (AddrSpace << 1); + setSubclassData(SubclassData); SubTys[0] = Result; @@ -295,7 +297,7 @@ // This is the factory function for the FunctionType class. FunctionType *FunctionType::get(Type *ReturnType, - ArrayRef Params, bool isVarArg) { + ArrayRef Params, bool isVarArg, unsigned AddrSpace) { LLVMContextImpl *pImpl = ReturnType->getContext().pImpl; FunctionTypeKeyInfo::KeyTy Key(ReturnType, Params, isVarArg); auto I = pImpl->FunctionTypes.find_as(Key); @@ -305,7 +307,7 @@ FT = (FunctionType *)pImpl->TypeAllocator.Allocate( sizeof(FunctionType) + sizeof(Type *) * (Params.size() + 1), alignof(FunctionType)); - new (FT) FunctionType(ReturnType, Params, isVarArg); + new (FT) FunctionType(ReturnType, Params, isVarArg, AddrSpace); pImpl->FunctionTypes.insert(FT); } else { FT = *I; @@ -314,8 +316,8 @@ return FT; } -FunctionType *FunctionType::get(Type *Result, bool isVarArg) { - return get(Result, None, isVarArg); +FunctionType *FunctionType::get(Type *Result, bool isVarArg, unsigned AddrSpace) { + return get(Result, None, isVarArg, AddrSpace); } bool FunctionType::isValidReturnType(Type *RetTy) { Index: lib/IR/Verifier.cpp =================================================================== --- lib/IR/Verifier.cpp +++ lib/IR/Verifier.cpp @@ -611,7 +611,9 @@ if (ArrayType *ATy = dyn_cast(GV.getValueType())) { StructType *STy = dyn_cast(ATy->getElementType()); PointerType *FuncPtrTy = - FunctionType::get(Type::getVoidTy(Context), false)->getPointerTo(); + FunctionType::get(Type::getVoidTy(Context), false, + // FIXME: we might want to grab the AddrSpace from the DL + /*AddrSpace=*/ 0)->getPointerTo(); // FIXME: Reject the 2-field form in LLVM 4.0. Assert(STy && (STy->getNumElements() == 2 || STy->getNumElements() == 3) && Index: lib/Linker/IRMover.cpp =================================================================== --- lib/Linker/IRMover.cpp +++ lib/Linker/IRMover.cpp @@ -296,10 +296,13 @@ case Type::PointerTyID: return *Entry = PointerType::get(ElementTypes[0], cast(Ty)->getAddressSpace()); - case Type::FunctionTyID: + case Type::FunctionTyID: { + auto *FTy = cast(Ty); return *Entry = FunctionType::get(ElementTypes[0], makeArrayRef(ElementTypes).slice(1), - cast(Ty)->isVarArg()); + FTy->isVarArg(), + FTy->getAddressSpace()); + } case Type::StructTyID: { auto *STy = cast(Ty); bool IsPacked = STy->isPacked(); Index: lib/Target/AMDGPU/AMDGPULibFunc.cpp =================================================================== --- lib/Target/AMDGPU/AMDGPULibFunc.cpp +++ lib/Target/AMDGPU/AMDGPULibFunc.cpp @@ -857,7 +857,7 @@ return FunctionType::get( getIntrinsicParamType(C, getRetType(FuncId, Leads), true), - Args, false); + Args, false, M.getDataLayout().getProgramAddressSpace()); } unsigned AMDGPULibFunc::getNumArgs() const { Index: lib/Target/AMDGPU/AMDGPUOpenCLImageTypeLoweringPass.cpp =================================================================== --- lib/Target/AMDGPU/AMDGPUOpenCLImageTypeLoweringPass.cpp +++ lib/Target/AMDGPU/AMDGPUOpenCLImageTypeLoweringPass.cpp @@ -303,7 +303,8 @@ } // Create function with new signature and clone the old body into it. - auto NewFT = FunctionType::get(FT->getReturnType(), ArgTypes, false); + auto NewFT = FunctionType::get(FT->getReturnType(), ArgTypes, false, + FT->getAddressSpace()); auto NewF = Function::Create(NewFT, F->getLinkage(), F->getName()); ValueToValueMapTy VMap; auto NewFArgIt = NewF->arg_begin(); Index: lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp =================================================================== --- lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp +++ lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp @@ -356,7 +356,8 @@ FunctionType *NewFuncTy = FunctionType::get(NewRetTy, F.getFunctionType()->params(), - F.isVarArg()); + F.isVarArg(), + F.getAddressSpace()); DEBUG(dbgs() << "Computed new return type: " << *NewRetTy << '\n'); Index: lib/Target/AVR/AVRTargetMachine.cpp =================================================================== --- lib/Target/AVR/AVRTargetMachine.cpp +++ lib/Target/AVR/AVRTargetMachine.cpp @@ -25,7 +25,7 @@ namespace llvm { -static const char *AVRDataLayout = "e-p:16:16:16-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-n8"; +static const char *AVRDataLayout = "e-p:16:16:16-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-n8-P1"; /// Processes a CPU name. static StringRef getCPU(StringRef CPU) { Index: lib/Target/Mips/Mips16HardFloat.cpp =================================================================== --- lib/Target/Mips/Mips16HardFloat.cpp +++ lib/Target/Mips/Mips16HardFloat.cpp @@ -49,7 +49,8 @@ std::vector AsmArgs; FunctionType *AsmFTy = - FunctionType::get(Type::getVoidTy(C), AsmArgTypes, false); + FunctionType::get(Type::getVoidTy(C), AsmArgTypes, false, + BB->getModule()->getDataLayout().getProgramAddressSpace()); InlineAsm *IA = InlineAsm::get(AsmFTy, AsmText, "", true, /* IsAlignStack */ false, InlineAsm::AD_ATT); CallInst::Create(IA, AsmArgs, "", BB); Index: lib/Target/X86/X86WinEHState.cpp =================================================================== --- lib/Target/X86/X86WinEHState.cpp +++ lib/Target/X86/X86WinEHState.cpp @@ -177,7 +177,8 @@ "_setjmp3", FunctionType::get( Type::getInt32Ty(TheModule->getContext()), {Int8PtrType, Type::getInt32Ty(TheModule->getContext())}, - /*isVarArg=*/true)); + /*isVarArg=*/true, + TheModule->getDataLayout().getProgramAddressSpace())); // Disable frame pointer elimination in this function. // FIXME: Do the nested handlers need to keep the parent ebp in ebp, or can we @@ -301,7 +302,8 @@ CxxLongjmpUnwind = TheModule->getOrInsertFunction( "__CxxLongjmpUnwind", - FunctionType::get(VoidTy, Int8PtrType, /*isVarArg=*/false)); + FunctionType::get(VoidTy, Int8PtrType, /*isVarArg=*/false, + TheModule->getDataLayout().getProgramAddressSpace())); cast(CxxLongjmpUnwind->stripPointerCasts()) ->setCallingConv(CallingConv::X86_StdCall); } else if (Personality == EHPersonality::MSVC_X86SEH) { @@ -386,16 +388,17 @@ /// jmpl ___CxxFrameHandler3 Function *WinEHStatePass::generateLSDAInEAXThunk(Function *ParentFunc) { LLVMContext &Context = ParentFunc->getContext(); + const auto &DL = ParentFunc->getParent()->getDataLayout(); Type *Int32Ty = Type::getInt32Ty(Context); Type *Int8PtrType = Type::getInt8PtrTy(Context); Type *ArgTys[5] = {Int8PtrType, Int8PtrType, Int8PtrType, Int8PtrType, Int8PtrType}; FunctionType *TrampolineTy = FunctionType::get(Int32Ty, makeArrayRef(&ArgTys[0], 4), - /*isVarArg=*/false); + /*isVarArg=*/false, DL.getProgramAddressSpace()); FunctionType *TargetFuncTy = FunctionType::get(Int32Ty, makeArrayRef(&ArgTys[0], 5), - /*isVarArg=*/false); + /*isVarArg=*/false, DL.getProgramAddressSpace()); Function *Trampoline = Function::Create(TrampolineTy, GlobalValue::InternalLinkage, Twine("__ehhandler$") + GlobalValue::dropLLVMManglingEscape( Index: lib/Transforms/IPO/ArgumentPromotion.cpp =================================================================== --- lib/Transforms/IPO/ArgumentPromotion.cpp +++ lib/Transforms/IPO/ArgumentPromotion.cpp @@ -183,7 +183,8 @@ Type *RetTy = FTy->getReturnType(); // Construct the new function type using the new arguments. - FunctionType *NFTy = FunctionType::get(RetTy, Params, FTy->isVarArg()); + FunctionType *NFTy = FunctionType::get(RetTy, Params, FTy->isVarArg(), + FTy->getAddressSpace()); // Create the new function body and insert it into the module. Function *NF = Function::Create(NFTy, F->getLinkage(), F->getName()); Index: lib/Transforms/IPO/DeadArgumentElimination.cpp =================================================================== --- lib/Transforms/IPO/DeadArgumentElimination.cpp +++ lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -142,7 +142,8 @@ std::vector Params(FTy->param_begin(), FTy->param_end()); FunctionType *NFTy = FunctionType::get(FTy->getReturnType(), - Params, false); + Params, false, + FTy->getAddressSpace()); unsigned NumArgs = Params.size(); // Create the new function body and insert it into the module... @@ -790,7 +791,8 @@ F->getContext(), PAL.getFnAttributes(), RetAttrs, ArgAttrVec); // Create the new function type based on the recomputed parameters. - FunctionType *NFTy = FunctionType::get(NRetTy, Params, FTy->isVarArg()); + FunctionType *NFTy = FunctionType::get(NRetTy, Params, FTy->isVarArg(), + FTy->getAddressSpace()); // No change? if (NFTy == FTy) Index: lib/Transforms/IPO/LowerTypeTests.cpp =================================================================== --- lib/Transforms/IPO/LowerTypeTests.cpp +++ lib/Transforms/IPO/LowerTypeTests.cpp @@ -247,6 +247,7 @@ class LowerTypeTestsModule { Module &M; + const DataLayout &DL; ModuleSummaryIndex *ExportSummary; const ModuleSummaryIndex *ImportSummary; @@ -1023,7 +1024,7 @@ if (WeakInitializerFn == nullptr) { WeakInitializerFn = Function::Create( FunctionType::get(Type::getVoidTy(M.getContext()), - /* IsVarArg */ false), + /* IsVarArg */ false, DL.getProgramAddressSpace()), GlobalValue::InternalLinkage, "__cfi_global_var_init", &M); BasicBlock *BB = BasicBlock::Create(M.getContext(), "entry", WeakInitializerFn); @@ -1116,7 +1117,8 @@ for (const auto &Arg : AsmArgs) ArgTypes.push_back(Arg->getType()); InlineAsm *JumpTableAsm = - InlineAsm::get(FunctionType::get(IRB.getVoidTy(), ArgTypes, false), + InlineAsm::get(FunctionType::get(IRB.getVoidTy(), ArgTypes, false, + DL.getProgramAddressSpace()), AsmOS.str(), ConstraintOS.str(), /*hasSideEffects=*/true); @@ -1214,7 +1216,8 @@ Function *JumpTableFn = Function::Create(FunctionType::get(Type::getVoidTy(M.getContext()), - /* IsVarArg */ false), + /* IsVarArg */ false, + DL.getProgramAddressSpace()), GlobalValue::PrivateLinkage, ".cfi.jumptable", &M); ArrayType *JumpTableType = ArrayType::get(getJumpTableEntryType(), Functions.size()); @@ -1377,7 +1380,8 @@ LowerTypeTestsModule::LowerTypeTestsModule( Module &M, ModuleSummaryIndex *ExportSummary, const ModuleSummaryIndex *ImportSummary) - : M(M), ExportSummary(ExportSummary), ImportSummary(ImportSummary) { + : M(M), DL(M.getDataLayout()), ExportSummary(ExportSummary), + ImportSummary(ImportSummary) { assert(!(ExportSummary && ImportSummary)); Triple TargetTriple(M.getTargetTriple()); Arch = TargetTriple.getArch(); @@ -1513,7 +1517,8 @@ Function *F = M.getFunction(FunctionName); if (!F) F = Function::Create( - FunctionType::get(Type::getVoidTy(M.getContext()), false), + FunctionType::get(Type::getVoidTy(M.getContext()), false, + DL.getProgramAddressSpace()), GlobalVariable::ExternalLinkage, FunctionName, &M); // If the function is available_externally, remove its definition so Index: lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp =================================================================== --- lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp +++ lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp @@ -132,7 +132,8 @@ // FIXME: If we made functions typeless then there would be no need to do this. void simplifyExternals(Module &M) { FunctionType *EmptyFT = - FunctionType::get(Type::getVoidTy(M.getContext()), false); + FunctionType::get(Type::getVoidTy(M.getContext()), false, + M.getDataLayout().getProgramAddressSpace()); for (auto I = M.begin(), E = M.end(); I != E;) { Function &F = *I++; Index: lib/Transforms/InstCombine/InstCombineCalls.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineCalls.cpp +++ lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -4419,7 +4419,8 @@ // Replace the trampoline call with a direct call. Let the generic // code sort out any function type mismatches. FunctionType *NewFTy = FunctionType::get(FTy->getReturnType(), NewTypes, - FTy->isVarArg()); + FTy->isVarArg(), + FTy->getAddressSpace()); Constant *NewCallee = NestF->getType() == PointerType::getUnqual(NewFTy) ? NestF : ConstantExpr::getBitCast(NestF, Index: lib/Transforms/Instrumentation/AddressSanitizer.cpp =================================================================== --- lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -1709,8 +1709,10 @@ } IRBuilder<> AddressSanitizerModule::CreateAsanModuleDtor(Module &M) { + unsigned AddrSpace = M.getDataLayout().getProgramAddressSpace(); + AsanDtorFunction = - Function::Create(FunctionType::get(Type::getVoidTy(*C), false), + Function::Create(FunctionType::get(Type::getVoidTy(*C), false, AddrSpace), GlobalValue::InternalLinkage, kAsanModuleDtorName, &M); BasicBlock *AsanDtorBB = BasicBlock::Create(*C, "", AsanDtorFunction); @@ -2118,6 +2120,9 @@ void AddressSanitizer::initializeCallbacks(Module &M) { IRBuilder<> IRB(*C); + + unsigned AddrSpace = M.getDataLayout().getProgramAddressSpace(); + // Create __asan_report* callbacks. // IsWrite, TypeSize and Exp are encoded in the function name. for (int Exp = 0; Exp < 2; Exp++) { @@ -2138,12 +2143,12 @@ checkSanitizerInterfaceFunction(M.getOrInsertFunction( kAsanReportErrorTemplate + ExpStr + TypeStr + SuffixStr + EndingStr, - FunctionType::get(IRB.getVoidTy(), Args2, false))); + FunctionType::get(IRB.getVoidTy(), Args2, false, AddrSpace))); AsanMemoryAccessCallbackSized[AccessIsWrite][Exp] = checkSanitizerInterfaceFunction(M.getOrInsertFunction( ClMemoryAccessCallbackPrefix + ExpStr + TypeStr + "N" + EndingStr, - FunctionType::get(IRB.getVoidTy(), Args2, false))); + FunctionType::get(IRB.getVoidTy(), Args2, false, AddrSpace))); for (size_t AccessSizeIndex = 0; AccessSizeIndex < kNumberOfAccessSizes; AccessSizeIndex++) { @@ -2151,12 +2156,12 @@ AsanErrorCallback[AccessIsWrite][Exp][AccessSizeIndex] = checkSanitizerInterfaceFunction(M.getOrInsertFunction( kAsanReportErrorTemplate + ExpStr + Suffix + EndingStr, - FunctionType::get(IRB.getVoidTy(), Args1, false))); + FunctionType::get(IRB.getVoidTy(), Args1, false, AddrSpace))); AsanMemoryAccessCallback[AccessIsWrite][Exp][AccessSizeIndex] = checkSanitizerInterfaceFunction(M.getOrInsertFunction( ClMemoryAccessCallbackPrefix + ExpStr + Suffix + EndingStr, - FunctionType::get(IRB.getVoidTy(), Args1, false))); + FunctionType::get(IRB.getVoidTy(), Args1, false, AddrSpace))); } } } @@ -2181,7 +2186,7 @@ AsanPtrSubFunction = checkSanitizerInterfaceFunction(M.getOrInsertFunction( kAsanPtrSub, IRB.getVoidTy(), IntptrTy, IntptrTy)); // We insert an empty inline asm after __asan_report* to avoid callback merge. - EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false), + EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false, AddrSpace), StringRef(""), StringRef(""), /*hasSideEffects=*/true); } Index: lib/Transforms/Instrumentation/DataFlowSanitizer.cpp =================================================================== --- lib/Transforms/Instrumentation/DataFlowSanitizer.cpp +++ lib/Transforms/Instrumentation/DataFlowSanitizer.cpp @@ -389,7 +389,8 @@ Type *RetType = T->getReturnType(); if (!RetType->isVoidTy()) RetType = StructType::get(RetType, ShadowTy); - return FunctionType::get(RetType, ArgTypes, T->isVarArg()); + return FunctionType::get(RetType, ArgTypes, T->isVarArg(), + T->getAddressSpace()); } FunctionType *DataFlowSanitizer::getTrampolineFunctionType(FunctionType *T) { @@ -401,7 +402,8 @@ Type *RetType = T->getReturnType(); if (!RetType->isVoidTy()) ArgTypes.push_back(ShadowPtrTy); - return FunctionType::get(T->getReturnType(), ArgTypes, false); + return FunctionType::get(T->getReturnType(), ArgTypes, false, + T->getAddressSpace()); } FunctionType *DataFlowSanitizer::getCustomFunctionType(FunctionType *T) { @@ -424,7 +426,8 @@ Type *RetType = T->getReturnType(); if (!RetType->isVoidTy()) ArgTypes.push_back(ShadowPtrTy); - return FunctionType::get(T->getReturnType(), ArgTypes, T->isVarArg()); + return FunctionType::get(T->getReturnType(), ArgTypes, T->isVarArg(), + T->getAddressSpace()); } bool DataFlowSanitizer::doInitialization(Module &M) { @@ -456,19 +459,25 @@ Type *DFSanUnionArgs[2] = { ShadowTy, ShadowTy }; DFSanUnionFnTy = - FunctionType::get(ShadowTy, DFSanUnionArgs, /*isVarArg=*/ false); + FunctionType::get(ShadowTy, DFSanUnionArgs, /*isVarArg=*/ false, + DL.getProgramAddressSpace()); Type *DFSanUnionLoadArgs[2] = { ShadowPtrTy, IntptrTy }; DFSanUnionLoadFnTy = - FunctionType::get(ShadowTy, DFSanUnionLoadArgs, /*isVarArg=*/ false); + FunctionType::get(ShadowTy, DFSanUnionLoadArgs, /*isVarArg=*/ false, + DL.getProgramAddressSpace()); DFSanUnimplementedFnTy = FunctionType::get( - Type::getVoidTy(*Ctx), Type::getInt8PtrTy(*Ctx), /*isVarArg=*/false); + Type::getVoidTy(*Ctx), Type::getInt8PtrTy(*Ctx), /*isVarArg=*/false, + DL.getProgramAddressSpace()); Type *DFSanSetLabelArgs[3] = { ShadowTy, Type::getInt8PtrTy(*Ctx), IntptrTy }; DFSanSetLabelFnTy = FunctionType::get(Type::getVoidTy(*Ctx), - DFSanSetLabelArgs, /*isVarArg=*/false); + DFSanSetLabelArgs, /*isVarArg=*/false, + DL.getProgramAddressSpace()); DFSanNonzeroLabelFnTy = FunctionType::get( - Type::getVoidTy(*Ctx), None, /*isVarArg=*/false); + Type::getVoidTy(*Ctx), None, /*isVarArg=*/false, + DL.getProgramAddressSpace()); DFSanVarargWrapperFnTy = FunctionType::get( - Type::getVoidTy(*Ctx), Type::getInt8PtrTy(*Ctx), /*isVarArg=*/false); + Type::getVoidTy(*Ctx), Type::getInt8PtrTy(*Ctx), /*isVarArg=*/false, + DL.getProgramAddressSpace()); if (GetArgTLSPtr) { Type *ArgTLSTy = ArrayType::get(ShadowTy, 64); @@ -476,14 +485,16 @@ GetArgTLS = ConstantExpr::getIntToPtr( ConstantInt::get(IntptrTy, uintptr_t(GetArgTLSPtr)), PointerType::getUnqual( - FunctionType::get(PointerType::getUnqual(ArgTLSTy), false))); + FunctionType::get(PointerType::getUnqual(ArgTLSTy), false, + DL.getProgramAddressSpace()))); } if (GetRetvalTLSPtr) { RetvalTLS = nullptr; GetRetvalTLS = ConstantExpr::getIntToPtr( ConstantInt::get(IntptrTy, uintptr_t(GetRetvalTLSPtr)), PointerType::getUnqual( - FunctionType::get(PointerType::getUnqual(ShadowTy), false))); + FunctionType::get(PointerType::getUnqual(ShadowTy), false, + DL.getProgramAddressSpace()))); } ColdCallWeights = MDBuilder(*Ctx).createBranchWeights(1, 1000); Index: lib/Transforms/Instrumentation/EfficiencySanitizer.cpp =================================================================== --- lib/Transforms/Instrumentation/EfficiencySanitizer.cpp +++ lib/Transforms/Instrumentation/EfficiencySanitizer.cpp @@ -519,10 +519,12 @@ } void EfficiencySanitizer::createDestructor(Module &M, Constant *ToolInfoArg) { + const auto &DL = M.getDataLayout(); + PointerType *Int8PtrTy = Type::getInt8PtrTy(*Ctx); - EsanDtorFunction = Function::Create(FunctionType::get(Type::getVoidTy(*Ctx), - false), - GlobalValue::InternalLinkage, + auto *FTy = FunctionType::get(Type::getVoidTy(*Ctx), false, + DL.getProgramAddressSpace()); + EsanDtorFunction = Function::Create(FTy, GlobalValue::InternalLinkage, EsanModuleDtorName, &M); ReturnInst::Create(*Ctx, BasicBlock::Create(*Ctx, "", EsanDtorFunction)); IRBuilder<> IRB_Dtor(EsanDtorFunction->getEntryBlock().getTerminator()); Index: lib/Transforms/Instrumentation/GCOVProfiling.cpp =================================================================== --- lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -129,6 +129,7 @@ SmallVector FileChecksums; Module *M; + const DataLayout *DL; LLVMContext *Ctx; SmallVector, 16> Funcs; }; @@ -462,7 +463,8 @@ bool GCOVProfiler::runOnModule(Module &M) { this->M = &M; - Ctx = &M.getContext(); + this->Ctx = &M.getContext(); + this->DL = &M.getDataLayout(); if (Options.EmitNotes) emitProfileNotes(); if (Options.EmitData) return emitProfileArcs(); @@ -689,7 +691,8 @@ // Create a small bit of code that registers the "__llvm_gcov_writeout" to // be executed at exit and the "__llvm_gcov_flush" function to be executed // when "__gcov_flush" is called. - FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), false); + FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), false, + DL->getProgramAddressSpace()); Function *F = Function::Create(FTy, GlobalValue::InternalLinkage, "__llvm_gcov_init", M); F->setUnnamedAddr(GlobalValue::UnnamedAddr::Global); @@ -701,12 +704,14 @@ BasicBlock *BB = BasicBlock::Create(*Ctx, "entry", F); IRBuilder<> Builder(BB); - FTy = FunctionType::get(Type::getVoidTy(*Ctx), false); + FTy = FunctionType::get(Type::getVoidTy(*Ctx), false, + DL->getProgramAddressSpace()); Type *Params[] = { PointerType::get(FTy, 0), PointerType::get(FTy, 0) }; - FTy = FunctionType::get(Builder.getVoidTy(), Params, false); + FTy = FunctionType::get(Builder.getVoidTy(), Params, false, + DL->getProgramAddressSpace()); // Initialize the environment and register the local writeout and flush // functions. @@ -777,7 +782,8 @@ Type::getInt8PtrTy(*Ctx), // const char version[4] Type::getInt32Ty(*Ctx), // uint32_t checksum }; - FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), Args, false); + FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), Args, false, + DL->getProgramAddressSpace()); return M->getOrInsertFunction("llvm_gcda_start_file", FTy); } @@ -788,7 +794,8 @@ Int32Ty->getPointerTo(), // uint32_t *predecessor Int64Ty->getPointerTo()->getPointerTo() // uint64_t **counters }; - FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), Args, false); + FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), Args, false, + DL->getProgramAddressSpace()); return M->getOrInsertFunction("__llvm_gcov_indirect_counter_increment", FTy); } @@ -800,7 +807,8 @@ Type::getInt8Ty(*Ctx), // uint8_t use_extra_checksum Type::getInt32Ty(*Ctx), // uint32_t cfg_checksum }; - FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), Args, false); + FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), Args, false, + DL->getProgramAddressSpace()); return M->getOrInsertFunction("llvm_gcda_emit_function", FTy); } @@ -809,17 +817,20 @@ Type::getInt32Ty(*Ctx), // uint32_t num_counters Type::getInt64PtrTy(*Ctx), // uint64_t *counters }; - FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), Args, false); + FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), Args, false, + DL->getProgramAddressSpace()); return M->getOrInsertFunction("llvm_gcda_emit_arcs", FTy); } Constant *GCOVProfiler::getSummaryInfoFunc() { - FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), false); + FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), false, + DL->getProgramAddressSpace()); return M->getOrInsertFunction("llvm_gcda_summary_info", FTy); } Constant *GCOVProfiler::getEndFileFunc() { - FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), false); + FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), false, + DL->getProgramAddressSpace()); return M->getOrInsertFunction("llvm_gcda_end_file", FTy); } @@ -838,7 +849,8 @@ Function *GCOVProfiler::insertCounterWriteout( ArrayRef > CountersBySP) { - FunctionType *WriteoutFTy = FunctionType::get(Type::getVoidTy(*Ctx), false); + FunctionType *WriteoutFTy = FunctionType::get(Type::getVoidTy(*Ctx), false, + DL->getProgramAddressSpace()); Function *WriteoutF = M->getFunction("__llvm_gcov_writeout"); if (!WriteoutF) WriteoutF = Function::Create(WriteoutFTy, GlobalValue::InternalLinkage, @@ -953,7 +965,8 @@ Function *GCOVProfiler:: insertFlush(ArrayRef > CountersBySP) { - FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), false); + FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), false, + DL->getProgramAddressSpace()); Function *FlushF = M->getFunction("__llvm_gcov_flush"); if (!FlushF) FlushF = Function::Create(FTy, GlobalValue::InternalLinkage, Index: lib/Transforms/Instrumentation/InstrProfiling.cpp =================================================================== --- lib/Transforms/Instrumentation/InstrProfiling.cpp +++ lib/Transforms/Instrumentation/InstrProfiling.cpp @@ -484,6 +484,7 @@ const TargetLibraryInfo &TLI, bool IsRange = false) { LLVMContext &Ctx = M.getContext(); + const auto &DL = M.getDataLayout(); auto *ReturnTy = Type::getVoidTy(M.getContext()); Constant *Res; @@ -493,7 +494,8 @@ #include "llvm/ProfileData/InstrProfData.inc" }; auto *ValueProfilingCallTy = - FunctionType::get(ReturnTy, makeArrayRef(ParamTypes), false); + FunctionType::get(ReturnTy, makeArrayRef(ParamTypes), false, + DL.getProgramAddressSpace()); Res = M.getOrInsertFunction(getInstrProfValueProfFuncName(), ValueProfilingCallTy); } else { @@ -504,7 +506,8 @@ #undef VALUE_RANGE_PROF }; auto *ValueRangeProfilingCallTy = - FunctionType::get(ReturnTy, makeArrayRef(RangeParamTypes), false); + FunctionType::get(ReturnTy, makeArrayRef(RangeParamTypes), false, + DL.getProgramAddressSpace()); Res = M.getOrInsertFunction(getInstrProfValueRangeProfFuncName(), ValueRangeProfilingCallTy); } @@ -852,6 +855,8 @@ } void InstrProfiling::emitRegistration() { + const auto &DL = M->getDataLayout(); + if (!needsRuntimeRegistrationOfSectionRange(*M)) return; @@ -859,7 +864,8 @@ auto *VoidTy = Type::getVoidTy(M->getContext()); auto *VoidPtrTy = Type::getInt8PtrTy(M->getContext()); auto *Int64Ty = Type::getInt64Ty(M->getContext()); - auto *RegisterFTy = FunctionType::get(VoidTy, false); + auto *RegisterFTy = FunctionType::get(VoidTy, false, + DL.getProgramAddressSpace()); auto *RegisterF = Function::Create(RegisterFTy, GlobalValue::InternalLinkage, getInstrProfRegFuncsName(), M); RegisterF->setUnnamedAddr(GlobalValue::UnnamedAddr::Global); @@ -879,7 +885,8 @@ if (NamesVar) { Type *ParamTypes[] = {VoidPtrTy, Int64Ty}; auto *NamesRegisterTy = - FunctionType::get(VoidTy, makeArrayRef(ParamTypes), false); + FunctionType::get(VoidTy, makeArrayRef(ParamTypes), false, + DL.getProgramAddressSpace()); auto *NamesRegisterF = Function::Create(NamesRegisterTy, GlobalVariable::ExternalLinkage, getInstrProfNamesRegFuncName(), M); @@ -891,6 +898,8 @@ } void InstrProfiling::emitRuntimeHook() { + const auto &DL = M->getDataLayout(); + // We expect the linker to be invoked with -u flag for linux, // for which case there is no need to emit the user function. if (Triple(M->getTargetTriple()).isOSLinux()) @@ -907,7 +916,8 @@ nullptr, getInstrProfRuntimeHookVarName()); // Make a function that uses it. - auto *User = Function::Create(FunctionType::get(Int32Ty, false), + auto *User = Function::Create(FunctionType::get(Int32Ty, false, + DL.getProgramAddressSpace()), GlobalValue::LinkOnceODRLinkage, getInstrProfRuntimeHookVarUseFuncName(), M); User->addFnAttr(Attribute::NoInline); @@ -931,6 +941,7 @@ } void InstrProfiling::emitInitialization() { + const auto &DL = M->getDataLayout(); StringRef InstrProfileOutput = Options.InstrProfileOutput; if (!InstrProfileOutput.empty()) { @@ -953,7 +964,8 @@ // Create the initialization function. auto *VoidTy = Type::getVoidTy(M->getContext()); - auto *F = Function::Create(FunctionType::get(VoidTy, false), + auto *F = Function::Create(FunctionType::get(VoidTy, false, + DL.getProgramAddressSpace()), GlobalValue::InternalLinkage, getInstrProfInitFuncName(), M); F->setUnnamedAddr(GlobalValue::UnnamedAddr::Global); Index: lib/Transforms/Instrumentation/MemorySanitizer.cpp =================================================================== --- lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -415,6 +415,8 @@ /// \brief Insert extern declaration of runtime-provided functions and globals. void MemorySanitizer::initializeCallbacks(Module &M) { + const auto &DL = M.getDataLayout(); + // Only do this once. if (WarningFn) return; @@ -490,7 +492,8 @@ "__msan_origin_tls", nullptr, GlobalVariable::InitialExecTLSModel); // We insert an empty inline asm after __msan_report* to avoid callback merge. - EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false), + EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false, + DL.getProgramAddressSpace()), StringRef(""), StringRef(""), /*hasSideEffects=*/true); } @@ -499,7 +502,7 @@ /// /// inserts a call to __msan_init to the module's constructor list. bool MemorySanitizer::doInitialization(Module &M) { - auto &DL = M.getDataLayout(); + const auto &DL = M.getDataLayout(); Triple TargetTriple(M.getTargetTriple()); switch (TargetTriple.getOS()) { Index: lib/Transforms/Instrumentation/SanitizerCoverage.cpp =================================================================== --- lib/Transforms/Instrumentation/SanitizerCoverage.cpp +++ lib/Transforms/Instrumentation/SanitizerCoverage.cpp @@ -380,7 +380,8 @@ // We insert an empty inline asm after cov callbacks to avoid callback merge. - EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false), + EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false, + DL->getProgramAddressSpace()), StringRef(""), StringRef(""), /*hasSideEffects=*/true); Index: lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h =================================================================== --- lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h +++ lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h @@ -126,11 +126,13 @@ return Decl; LLVMContext &C = TheModule->getContext(); + const auto &DL = TheModule->getDataLayout(); Type *Params[] = { PointerType::getUnqual(Type::getInt8Ty(C)) }; AttributeList Attr = AttributeList().addAttribute( C, AttributeList::FunctionIndex, Attribute::NoUnwind); FunctionType *Fty = FunctionType::get(Type::getVoidTy(C), Params, - /*isVarArg=*/false); + /*isVarArg=*/false, + DL.getProgramAddressSpace()); return Decl = TheModule->getOrInsertFunction(Name, Fty, Attr); } @@ -140,9 +142,11 @@ return Decl; LLVMContext &C = TheModule->getContext(); + const auto &DL = TheModule->getDataLayout(); Type *I8X = PointerType::getUnqual(Type::getInt8Ty(C)); Type *Params[] = { I8X }; - FunctionType *Fty = FunctionType::get(I8X, Params, /*isVarArg=*/false); + FunctionType *Fty = FunctionType::get(I8X, Params, /*isVarArg=*/false, + DL.getProgramAddressSpace()); AttributeList Attr = AttributeList(); if (NoUnwind) @@ -157,6 +161,7 @@ return Decl; LLVMContext &C = TheModule->getContext(); + const auto &DL = TheModule->getDataLayout(); Type *I8X = PointerType::getUnqual(Type::getInt8Ty(C)); Type *I8XX = PointerType::getUnqual(I8X); Type *Params[] = { I8XX, I8X }; @@ -166,7 +171,8 @@ Attr = Attr.addParamAttribute(C, 0, Attribute::NoCapture); FunctionType *Fty = FunctionType::get(Type::getVoidTy(C), Params, - /*isVarArg=*/false); + /*isVarArg=*/false, + DL.getProgramAddressSpace()); return Decl = TheModule->getOrInsertFunction(Name, Fty, Attr); } Index: lib/Transforms/ObjCARC/ObjCARCContract.cpp =================================================================== --- lib/Transforms/ObjCARC/ObjCARCContract.cpp +++ lib/Transforms/ObjCARC/ObjCARCContract.cpp @@ -408,8 +408,10 @@ SmallPtrSetImpl &DependingInsts, SmallPtrSetImpl &Visited, bool &TailOkForStoreStrongs) { - // Only these library routines return their argument. In particular, - // objc_retainBlock does not necessarily return its argument. + const auto &DL = F.getParent()->getDataLayout(); + + // Only these library routines return their argument. In particular, + // objc_retainBlock does not necessarily return its argument. ARCInstKind Class = GetBasicARCInstKind(Inst); switch (Class) { case ARCInstKind::FusedRetainAutorelease: @@ -454,7 +456,7 @@ Changed = true; InlineAsm *IA = InlineAsm::get( FunctionType::get(Type::getVoidTy(Inst->getContext()), - /*isVarArg=*/false), + /*isVarArg=*/false, DL.getProgramAddressSpace()), RVInstMarker->getString(), /*Constraints=*/"", /*hasSideEffects=*/true); CallInst::Create(IA, "", Inst); Index: lib/Transforms/Scalar/PlaceSafepoints.cpp =================================================================== --- lib/Transforms/Scalar/PlaceSafepoints.cpp +++ lib/Transforms/Scalar/PlaceSafepoints.cpp @@ -626,6 +626,8 @@ Module *M = InsertBefore->getModule(); assert(M && "must be part of a module"); + const auto &DL = M->getDataLayout(); + // Inline the safepoint poll implementation - this will get all the branch, // control flow, etc.. Most importantly, it will introduce the actual slow // path call - where we need to insert a safepoint (parsepoint). @@ -633,7 +635,8 @@ auto *F = M->getFunction(GCSafepointPollName); assert(F && "gc.safepoint_poll function is missing"); assert(F->getValueType() == - FunctionType::get(Type::getVoidTy(M->getContext()), false) && + FunctionType::get(Type::getVoidTy(M->getContext()), false, + DL.getProgramAddressSpace()) && "gc.safepoint_poll declared with wrong type"); assert(!F->empty() && "gc.safepoint_poll must be a non-empty function"); CallInst *PollCall = CallInst::Create(F, "", InsertBefore); Index: lib/Transforms/Scalar/RewriteStatepointsForGC.cpp =================================================================== --- lib/Transforms/Scalar/RewriteStatepointsForGC.cpp +++ lib/Transforms/Scalar/RewriteStatepointsForGC.cpp @@ -1320,6 +1320,7 @@ // arguments will be available here. We can't insert afterwards since we may // be replacing a terminator. Instruction *InsertBefore = CS.getInstruction(); + const auto &DL = InsertBefore->getModule()->getDataLayout(); IRBuilder<> Builder(InsertBefore); ArrayRef GCArgs(LiveVariables); @@ -1367,7 +1368,8 @@ for (Value *Arg : CallArgs) DomainTy.push_back(Arg->getType()); auto *FTy = FunctionType::get(Type::getVoidTy(F->getContext()), DomainTy, - /* isVarArg = */ false); + /* isVarArg = */ false, + DL.getProgramAddressSpace()); // Note: CallTarget can be a bitcast instruction of a symbol if there are // calls to @llvm.experimental.deoptimize with different argument types in @@ -1794,9 +1796,11 @@ return; Module *M = CS.getInstruction()->getModule(); + const auto &DL = M->getDataLayout(); // Use a dummy vararg function to actually hold the values live Function *Func = cast(M->getOrInsertFunction( - "__tmp_use", FunctionType::get(Type::getVoidTy(M->getContext()), true))); + "__tmp_use", FunctionType::get(Type::getVoidTy(M->getContext()), true, + DL.getProgramAddressSpace()))); if (CS.isCall()) { // For call safepoints insert dummy calls right after safepoint Holders.push_back(CallInst::Create(Func, Values, "", Index: lib/Transforms/Utils/CloneFunction.cpp =================================================================== --- lib/Transforms/Utils/CloneFunction.cpp +++ lib/Transforms/Utils/CloneFunction.cpp @@ -240,7 +240,8 @@ // Create a new function type... FunctionType *FTy = FunctionType::get(F->getFunctionType()->getReturnType(), - ArgTypes, F->getFunctionType()->isVarArg()); + ArgTypes, F->getFunctionType()->isVarArg(), + F->getFunctionType()->getAddressSpace()); // Create the new function... Function *NewF = Index: lib/Transforms/Utils/CodeExtractor.cpp =================================================================== --- lib/Transforms/Utils/CodeExtractor.cpp +++ lib/Transforms/Utils/CodeExtractor.cpp @@ -575,7 +575,8 @@ paramTy.push_back(PointerType::getUnqual(StructTy)); } FunctionType *funcType = - FunctionType::get(RetTy, paramTy, false); + FunctionType::get(RetTy, paramTy, false, + oldFunction->getAddressSpace()); // Create the new function Function *newFunction = Function::Create(funcType, Index: lib/Transforms/Utils/EscapeEnumerator.cpp =================================================================== --- lib/Transforms/Utils/EscapeEnumerator.cpp +++ lib/Transforms/Utils/EscapeEnumerator.cpp @@ -21,10 +21,13 @@ static Constant *getDefaultPersonalityFn(Module *M) { LLVMContext &C = M->getContext(); + const DataLayout &DL = M->getDataLayout(); Triple T(M->getTargetTriple()); EHPersonality Pers = getDefaultEHPersonality(T); + return M->getOrInsertFunction(getEHPersonalityName(Pers), - FunctionType::get(Type::getInt32Ty(C), true)); + FunctionType::get(Type::getInt32Ty(C), true, + DL.getProgramAddressSpace())); } IRBuilder<> *EscapeEnumerator::Next() { Index: lib/Transforms/Utils/ModuleUtils.cpp =================================================================== --- lib/Transforms/Utils/ModuleUtils.cpp +++ lib/Transforms/Utils/ModuleUtils.cpp @@ -22,8 +22,10 @@ static void appendToGlobalArray(const char *Array, Module &M, Function *F, int Priority, Constant *Data) { + const DataLayout &DL = M.getDataLayout(); IRBuilder<> IRB(M.getContext()); - FunctionType *FnTy = FunctionType::get(IRB.getVoidTy(), false); + FunctionType *FnTy = FunctionType::get(IRB.getVoidTy(), false, + DL.getProgramAddressSpace()); // Get the current set of static global constructors and add the new ctor // to the list. @@ -141,9 +143,11 @@ Function *llvm::declareSanitizerInitFunction(Module &M, StringRef InitName, ArrayRef InitArgTypes) { assert(!InitName.empty() && "Expected init function name"); + const DataLayout &DL = M.getDataLayout(); Function *F = checkSanitizerInterfaceFunction(M.getOrInsertFunction( InitName, - FunctionType::get(Type::getVoidTy(M.getContext()), InitArgTypes, false), + FunctionType::get(Type::getVoidTy(M.getContext()), InitArgTypes, false, + DL.getProgramAddressSpace()), AttributeList())); F->setLinkage(Function::ExternalLinkage); return F; @@ -153,13 +157,15 @@ Module &M, StringRef CtorName, StringRef InitName, ArrayRef InitArgTypes, ArrayRef InitArgs, StringRef VersionCheckName) { + const DataLayout &DL = M.getDataLayout(); assert(!InitName.empty() && "Expected init function name"); assert(InitArgs.size() == InitArgTypes.size() && "Sanitizer's init function expects different number of arguments"); Function *InitFunction = declareSanitizerInitFunction(M, InitName, InitArgTypes); Function *Ctor = Function::Create( - FunctionType::get(Type::getVoidTy(M.getContext()), false), + FunctionType::get(Type::getVoidTy(M.getContext()), false, + DL.getProgramAddressSpace()), GlobalValue::InternalLinkage, CtorName, &M); BasicBlock *CtorBB = BasicBlock::Create(M.getContext(), "", Ctor); IRBuilder<> IRB(ReturnInst::Create(M.getContext(), CtorBB)); Index: lib/Transforms/Utils/SanitizerStats.cpp =================================================================== --- lib/Transforms/Utils/SanitizerStats.cpp +++ lib/Transforms/Utils/SanitizerStats.cpp @@ -75,6 +75,8 @@ return; } + const DataLayout &DL = M->getDataLayout(); + PointerType *Int8PtrTy = Type::getInt8PtrTy(M->getContext()); IntegerType *Int32Ty = Type::getInt32Ty(M->getContext()); Type *VoidTy = Type::getVoidTy(M->getContext()); @@ -92,7 +94,8 @@ ModuleStatsGV->eraseFromParent(); // Create a global constructor to register NewModuleStatsGV. - auto F = Function::Create(FunctionType::get(VoidTy, false), + auto F = Function::Create(FunctionType::get(VoidTy, false, + DL.getProgramAddressSpace()), GlobalValue::InternalLinkage, "", M); auto BB = BasicBlock::Create(M->getContext(), "", F); IRBuilder<> B(BB); Index: lib/Transforms/Utils/SimplifyCFG.cpp =================================================================== --- lib/Transforms/Utils/SimplifyCFG.cpp +++ lib/Transforms/Utils/SimplifyCFG.cpp @@ -4945,7 +4945,10 @@ Array = new GlobalVariable(M, ArrayTy, /*constant=*/true, GlobalVariable::PrivateLinkage, Initializer, - "switch.table." + FuncName); + "switch.table." + FuncName, + /*InsertBefore=*/nullptr, + GlobalValue::NotThreadLocal, + DL.getProgramAddressSpace()); Array->setUnnamedAddr(GlobalValue::UnnamedAddr::Global); Kind = ArrayKind; } Index: lib/Transforms/Utils/ValueMapper.cpp =================================================================== --- lib/Transforms/Utils/ValueMapper.cpp +++ lib/Transforms/Utils/ValueMapper.cpp @@ -881,7 +881,8 @@ for (Type *Ty : FTy->params()) Tys.push_back(TypeMapper->remapType(Ty)); CS.mutateFunctionType(FunctionType::get( - TypeMapper->remapType(I->getType()), Tys, FTy->isVarArg())); + TypeMapper->remapType(I->getType()), Tys, FTy->isVarArg(), + FTy->getAddressSpace())); return; } if (auto *AI = dyn_cast(I)) Index: lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- lib/Transforms/Vectorize/LoopVectorize.cpp +++ lib/Transforms/Vectorize/LoopVectorize.cpp @@ -4758,6 +4758,7 @@ setDebugLocFromInst(Builder, &I); Module *M = I.getParent()->getParent()->getParent(); + const auto &DL = M->getDataLayout(); auto *CI = cast(&I); StringRef FnName = CI->getCalledFunction()->getName(); @@ -4804,7 +4805,8 @@ VectorF = M->getFunction(VFnName); if (!VectorF) { // Generate a declaration - FunctionType *FTy = FunctionType::get(RetTy, Tys, false); + FunctionType *FTy = FunctionType::get(RetTy, Tys, false, + DL.getProgramAddressSpace()); VectorF = 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,6 @@ +; RUN: llvm-as < %s | llvm-dis | FileCheck %s + +; CHECK: define void @main() addrspace(3) +define void @main() addrspace(3) { + ret void +} Index: test/CodeGen/AVR/switch-lookup-table-in-progmem-space.ll =================================================================== --- /dev/null +++ test/CodeGen/AVR/switch-lookup-table-in-progmem-space.ll @@ -0,0 +1,62 @@ +; RUN: opt -S -mtriple=avr -latesimplifycfg < %s | FileCheck %s + +target datalayout = "e-p:16:16:16-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-n8-P1" + +; Switch lookup tables should be placed in program memory (address space 1). + +%MyType = type { i8, [0 x i8], [0 x i8] } + +define i8 @foo(i8 %arg) { +start: + %_0 = alloca %MyType + +; CHECK: @switch.table.foo = {{.*}}addrspace(1) constant {{.*}} + switch i8 %arg, label %bb7 [ + i8 0, label %bb1 + i8 1, label %bb2 + i8 2, label %bb3 + i8 3, label %bb4 + i8 4, label %bb5 + i8 14, label %bb6 + ] + +bb1: ; preds = %start + %tmp = getelementptr inbounds %MyType, %MyType* %_0, i32 0, i32 0 + store i8 1, i8* %tmp + br label %bb8 + +bb2: ; preds = %start + %tmp1 = getelementptr inbounds %MyType, %MyType* %_0, i32 0, i32 0 + store i8 1, i8* %tmp1 + br label %bb8 + +bb3: ; preds = %start + %tmp2 = getelementptr inbounds %MyType, %MyType* %_0, i32 0, i32 0 + store i8 1, i8* %tmp2 + br label %bb8 + +bb4: ; preds = %start + %tmp3 = getelementptr inbounds %MyType, %MyType* %_0, i32 0, i32 0 + store i8 1, i8* %tmp3 + br label %bb8 + +bb5: ; preds = %start + %tmp4 = getelementptr inbounds %MyType, %MyType* %_0, i32 0, i32 0 + store i8 1, i8* %tmp4 + br label %bb8 + +bb6: ; preds = %start + %tmp5 = getelementptr inbounds %MyType, %MyType* %_0, i32 0, i32 0 + store i8 1, i8* %tmp5 + br label %bb8 + +bb7: ; preds = %start + %tmp6 = getelementptr inbounds %MyType, %MyType* %_0, i32 0, i32 0 + store i8 0, i8* %tmp6 + br label %bb8 + +bb8: ; preds = %bb7, %bb6, %bb5, %bb4, %bb3, %bb2, %bb1 + %tmp7 = bitcast %MyType* %_0 to i8* + %tmp8 = load i8, i8* %tmp7, align 1 + ret i8 %tmp8 +} Index: tools/llvm-stress/llvm-stress.cpp =================================================================== --- tools/llvm-stress/llvm-stress.cpp +++ tools/llvm-stress/llvm-stress.cpp @@ -137,7 +137,8 @@ Type::getInt8Ty(Context) }; - auto *FuncTy = FunctionType::get(Type::getVoidTy(Context), ArgsTy, false); + auto *FuncTy = FunctionType::get(Type::getVoidTy(Context), ArgsTy, false, + M->getDataLayout().getProgramAddressSpace()); // Pick a unique name to describe the input parameters Twine Name = "autogen_SD" + Twine{SeedCL}; auto *Func = Function::Create(FuncTy, GlobalValue::ExternalLinkage, Name, M); Index: unittests/Analysis/AliasAnalysisTest.cpp =================================================================== --- unittests/Analysis/AliasAnalysisTest.cpp +++ unittests/Analysis/AliasAnalysisTest.cpp @@ -166,7 +166,7 @@ TEST_F(AliasAnalysisTest, getModRefInfo) { // Setup function. FunctionType *FTy = - FunctionType::get(Type::getVoidTy(C), std::vector(), false); + FunctionType::get(Type::getVoidTy(C), std::vector(), false, 0); auto *F = cast(M.getOrInsertFunction("f", FTy)); auto *BB = BasicBlock::Create(C, "entry", F); auto IntType = Type::getInt32Ty(C); Index: unittests/Analysis/ScalarEvolutionTest.cpp =================================================================== --- unittests/Analysis/ScalarEvolutionTest.cpp +++ unittests/Analysis/ScalarEvolutionTest.cpp @@ -63,7 +63,7 @@ TEST_F(ScalarEvolutionsTest, SCEVUnknownRAUW) { FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), - std::vector(), false); + std::vector(), false, 0); Function *F = cast(M.getOrInsertFunction("f", FTy)); BasicBlock *BB = BasicBlock::Create(Context, "entry", F); ReturnInst::Create(Context, nullptr, BB); @@ -114,7 +114,8 @@ Type *Ty = Type::getInt32Ty(Context); SmallVector Types; Types.append(10, Ty); - FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), Types, false); + FunctionType *FTy = + FunctionType::get(Type::getVoidTy(Context), Types, false, 0); Function *F = cast(M.getOrInsertFunction("f", FTy)); BasicBlock *BB = BasicBlock::Create(Context, "entry", F); ReturnInst::Create(Context, nullptr, BB); @@ -253,7 +254,7 @@ TEST_F(ScalarEvolutionsTest, SimplifiedPHI) { FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), - std::vector(), false); + std::vector(), false, 0); Function *F = cast(M.getOrInsertFunction("f", FTy)); BasicBlock *EntryBB = BasicBlock::Create(Context, "entry", F); BasicBlock *LoopBB = BasicBlock::Create(Context, "loop", F); @@ -286,8 +287,8 @@ auto *I8PtrTy = Type::getInt8PtrTy(Context); auto *I32Ty = Type::getInt32Ty(Context); auto *I32PtrTy = Type::getInt32PtrTy(Context); - FunctionType *FTy = - FunctionType::get(Type::getVoidTy(Context), std::vector(), false); + FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), + std::vector(), false, 0); Function *F = cast(M.getOrInsertFunction("f", FTy)); BasicBlock *EntryBB = BasicBlock::Create(Context, "entry", F); BasicBlock *LoopBB = BasicBlock::Create(Context, "loop", F); @@ -469,8 +470,8 @@ } TEST_F(ScalarEvolutionsTest, CompareSCEVComplexity) { - FunctionType *FTy = - FunctionType::get(Type::getVoidTy(Context), std::vector(), false); + FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), + std::vector(), false, 0); Function *F = cast(M.getOrInsertFunction("f", FTy)); BasicBlock *EntryBB = BasicBlock::Create(Context, "entry", F); BasicBlock *LoopBB = BasicBlock::Create(Context, "bb1", F); @@ -539,8 +540,8 @@ IntegerType *IntPtrTy = M.getDataLayout().getIntPtrType(Context); PointerType *IntPtrPtrTy = IntPtrTy->getPointerTo(); - FunctionType *FTy = - FunctionType::get(Type::getVoidTy(Context), {IntPtrTy, IntPtrTy}, false); + FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), + {IntPtrTy, IntPtrTy}, false, 0); Function *F = cast(M.getOrInsertFunction("f", FTy)); BasicBlock *EntryBB = BasicBlock::Create(Context, "entry", F); @@ -576,7 +577,7 @@ Type *ArgTys[] = {Type::getInt64Ty(Context), Ty32}; FunctionType *FTy = - FunctionType::get(Type::getVoidTy(Context), ArgTys, false); + FunctionType::get(Type::getVoidTy(Context), ArgTys, false, 0); Function *F = cast(M.getOrInsertFunction("f", FTy)); Argument *A1 = &*F->arg_begin(); @@ -810,7 +811,7 @@ // %gep95 = getelementptr i8, i8* %gep91, i64 %dec94 // ret void // } - FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), {}, false); + FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), {}, false, 0); Function *F = cast(M.getOrInsertFunction("foo", FTy)); BasicBlock *EntryBB = BasicBlock::Create(Context, "entry", F); @@ -889,7 +890,7 @@ Type *T_pint64 = T_int64->getPointerTo(10); FunctionType *FTy = - FunctionType::get(Type::getVoidTy(Context), {T_pint64}, false); + FunctionType::get(Type::getVoidTy(Context), {T_pint64}, false, 0); Function *F = cast(NIM.getOrInsertFunction("foo", FTy)); Argument *Arg = &*F->arg_begin(); @@ -962,7 +963,7 @@ Type *T_pint64 = T_int64->getPointerTo(10); FunctionType *FTy = - FunctionType::get(Type::getVoidTy(Context), {T_pint64}, false); + FunctionType::get(Type::getVoidTy(Context), {T_pint64}, false, 0); Function *F = cast(NIM.getOrInsertFunction("foo", FTy)); BasicBlock *Top = BasicBlock::Create(Context, "top", F); @@ -1044,7 +1045,7 @@ Type *T_pint64 = T_int64->getPointerTo(10); FunctionType *FTy = - FunctionType::get(Type::getVoidTy(Context), {T_pint64}, false); + FunctionType::get(Type::getVoidTy(Context), {T_pint64}, false, 0); Function *F = cast(NIM.getOrInsertFunction("foo", FTy)); Argument *Arg = &*F->arg_begin(); Index: unittests/Analysis/TBAATest.cpp =================================================================== --- unittests/Analysis/TBAATest.cpp +++ unittests/Analysis/TBAATest.cpp @@ -33,7 +33,7 @@ static StoreInst *getFunctionWithSingleStore(Module *M, StringRef Name) { auto &C = M->getContext(); - FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), {}); + FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), {}, 0); auto *F = cast(M->getOrInsertFunction(Name, FTy)); auto *BB = BasicBlock::Create(C, "entry", F); auto *IntType = Type::getInt32Ty(C); Index: unittests/Analysis/TargetLibraryInfoTest.cpp =================================================================== --- unittests/Analysis/TargetLibraryInfoTest.cpp +++ unittests/Analysis/TargetLibraryInfoTest.cpp @@ -63,7 +63,8 @@ parseAssembly("%foo = type { %foo }\n"); auto *StructTy = M->getTypeByName("foo"); - auto *InvalidFTy = FunctionType::get(StructTy, /*isVarArg=*/false); + auto *InvalidFTy = FunctionType::get(StructTy, /*isVarArg=*/false, + /*AddrSpace=*/0); for (unsigned FI = 0; FI != LibFunc::NumLibFuncs; ++FI) { LibFunc LF = (LibFunc)FI; Index: unittests/IR/FunctionTest.cpp =================================================================== --- unittests/IR/FunctionTest.cpp +++ unittests/IR/FunctionTest.cpp @@ -18,7 +18,7 @@ LLVMContext C; Type *ArgTypes[] = {Type::getInt8Ty(C), Type::getInt32Ty(C)}; - FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), ArgTypes, false); + FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), ArgTypes, false, 0); // Functions start out with lazy arguments. std::unique_ptr F( @@ -40,7 +40,7 @@ LLVMContext C; Type *ArgTypes[] = {Type::getInt8Ty(C), Type::getInt32Ty(C)}; - FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), ArgTypes, false); + FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), ArgTypes, false, 0); std::unique_ptr F1( Function::Create(FTy, GlobalValue::ExternalLinkage, "F1")); std::unique_ptr F2( @@ -116,7 +116,7 @@ Module M("test", C); llvm::Function *F = - Function::Create(llvm::FunctionType::get(llvm::Type::getVoidTy(C), false), + Function::Create(llvm::FunctionType::get(llvm::Type::getVoidTy(C), false, 0), llvm::GlobalValue::ExternalLinkage, "F", &M); F->setSection(".text.test"); @@ -130,4 +130,18 @@ EXPECT_TRUE(F->hasSection()); } +// Test setting and retrieving fields stored in subclass data bitfield +// through the associated FunctionType +TEST(FunctionTest, subclassData) { + LLVMContext C; + Module M("test", C); + + llvm::Function *F = + Function::Create(llvm::FunctionType::get(llvm::Type::getVoidTy(C), true, + 180), GlobalValue::ExternalLinkage); + + EXPECT_EQ(false, F->isVarArg()); + EXPECT_EQ(180u, F->getAddressSpace()); +} + } // end namespace Index: unittests/IR/IRBuilderTest.cpp =================================================================== --- unittests/IR/IRBuilderTest.cpp +++ unittests/IR/IRBuilderTest.cpp @@ -29,7 +29,7 @@ void SetUp() override { M.reset(new Module("MyModule", Ctx)); FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx), - /*isVarArg=*/false); + /*isVarArg=*/false, /*AddrSpace=*/0); F = Function::Create(FTy, Function::ExternalLinkage, "", M.get()); BB = BasicBlock::Create(Ctx, "", F); GV = new GlobalVariable(*M, Type::getFloatTy(Ctx), true, @@ -229,7 +229,7 @@ // Test a call with FMF. auto CalleeTy = FunctionType::get(Type::getFloatTy(Ctx), - /*isVarArg=*/false); + /*isVarArg=*/false, /*AddrSpace=*/0); auto Callee = Function::Create(CalleeTy, Function::ExternalLinkage, "", M.get()); @@ -426,7 +426,7 @@ TEST_F(IRBuilderTest, DebugLoc) { auto CalleeTy = FunctionType::get(Type::getVoidTy(Ctx), - /*isVarArg=*/false); + /*isVarArg=*/false, /*AddrSpace=*/0); auto Callee = Function::Create(CalleeTy, Function::ExternalLinkage, "", M.get()); Index: unittests/IR/InstructionsTest.cpp =================================================================== --- unittests/IR/InstructionsTest.cpp +++ unittests/IR/InstructionsTest.cpp @@ -61,7 +61,7 @@ FArgTypes.push_back(Type::getInt32Ty(Ctx)); FArgTypes.push_back(Type::getInt64Ty(Ctx)); FunctionType *FTy = - FunctionType::get(Type::getVoidTy(Ctx), FArgTypes, false); + FunctionType::get(Type::getVoidTy(Ctx), FArgTypes, false, 0); F = Function::Create(FTy, Function::ExternalLinkage, "", M.get()); } @@ -495,7 +495,7 @@ LLVMContext C; Type *Int32Ty = Type::getInt32Ty(C); Type *ArgTys[] = {Int32Ty, Int32Ty, Int32Ty}; - Type *FnTy = FunctionType::get(Int32Ty, ArgTys, /*isVarArg=*/false); + Type *FnTy = FunctionType::get(Int32Ty, ArgTys, /*isVarArg=*/false, 0); Value *Callee = Constant::getNullValue(FnTy->getPointerTo()); Value *Args[] = { ConstantInt::get(Int32Ty, 1), @@ -528,7 +528,7 @@ TEST(InstructionsTest, AlterCallBundles) { LLVMContext C; Type *Int32Ty = Type::getInt32Ty(C); - Type *FnTy = FunctionType::get(Int32Ty, Int32Ty, /*isVarArg=*/false); + Type *FnTy = FunctionType::get(Int32Ty, Int32Ty, /*isVarArg=*/false, 0); Value *Callee = Constant::getNullValue(FnTy->getPointerTo()); Value *Args[] = {ConstantInt::get(Int32Ty, 42)}; OperandBundleDef OldBundle("before", UndefValue::get(Int32Ty)); @@ -555,7 +555,7 @@ TEST(InstructionsTest, AlterInvokeBundles) { LLVMContext C; Type *Int32Ty = Type::getInt32Ty(C); - Type *FnTy = FunctionType::get(Int32Ty, Int32Ty, /*isVarArg=*/false); + Type *FnTy = FunctionType::get(Int32Ty, Int32Ty, /*isVarArg=*/false, 0); Value *Callee = Constant::getNullValue(FnTy->getPointerTo()); Value *Args[] = {ConstantInt::get(Int32Ty, 42)}; std::unique_ptr NormalDest(BasicBlock::Create(C)); Index: unittests/IR/LegacyPassManagerTest.cpp =================================================================== --- unittests/IR/LegacyPassManagerTest.cpp +++ unittests/IR/LegacyPassManagerTest.cpp @@ -413,14 +413,16 @@ FunctionType *FuncTy_0 = FunctionType::get( /*Result=*/IntegerType::get(Context, 32), /*Params=*/FuncTy_0_args, - /*isVarArg=*/false); + /*isVarArg=*/false, + /*AddrSpace=*/0); std::vectorFuncTy_2_args; FuncTy_2_args.push_back(IntegerType::get(Context, 1)); FunctionType *FuncTy_2 = FunctionType::get( /*Result=*/Type::getVoidTy(Context), /*Params=*/FuncTy_2_args, - /*isVarArg=*/false); + /*isVarArg=*/false, + /*AddrSpace=*/0); // Function Declarations Index: unittests/IR/MetadataTest.cpp =================================================================== --- unittests/IR/MetadataTest.cpp +++ unittests/IR/MetadataTest.cpp @@ -118,7 +118,7 @@ } Function *getFunction(StringRef Name) { return cast(M.getOrInsertFunction( - Name, FunctionType::get(Type::getVoidTy(Context), None, false))); + Name, FunctionType::get(Type::getVoidTy(Context), None, false, 0))); } }; typedef MetadataTest MDStringTest; @@ -346,7 +346,7 @@ TEST_F(MDNodeTest, PrintFromFunction) { Module M("test", Context); - auto *FTy = FunctionType::get(Type::getVoidTy(Context), false); + auto *FTy = FunctionType::get(Type::getVoidTy(Context), false, 0); 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); @@ -371,10 +371,11 @@ auto *Intrinsic = Function::Create(FunctionType::get(Type::getVoidTy(Context), - Type::getMetadataTy(Context), false), + Type::getMetadataTy(Context), false, + 0), GlobalValue::ExternalLinkage, "llvm.intrinsic", &M); - auto *FTy = FunctionType::get(Type::getVoidTy(Context), false); + auto *FTy = FunctionType::get(Type::getVoidTy(Context), false, 0); 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); Index: unittests/IR/PatternMatch.cpp =================================================================== --- unittests/IR/PatternMatch.cpp +++ unittests/IR/PatternMatch.cpp @@ -40,7 +40,8 @@ PatternMatchTest() : M(new Module("PatternMatchTestModule", Ctx)), F(Function::Create( - FunctionType::get(Type::getVoidTy(Ctx), /* IsVarArg */ false), + FunctionType::get(Type::getVoidTy(Ctx), /*IsVarArg=*/false, + /*AddrSpace=*/0), Function::ExternalLinkage, "f", M.get())), BB(BasicBlock::Create(Ctx, "entry", F)), IRB(BB) {} }; Index: unittests/IR/TypeBuilderTest.cpp =================================================================== --- unittests/IR/TypeBuilderTest.cpp +++ unittests/IR/TypeBuilderTest.cpp @@ -148,41 +148,41 @@ TEST(TypeBuilderTest, Functions) { LLVMContext Context; std::vector params; - EXPECT_EQ(FunctionType::get(Type::getVoidTy(Context), params, false), + EXPECT_EQ(FunctionType::get(Type::getVoidTy(Context), params, false, 0), (TypeBuilder::get(Context))); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(Context), params, true), + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(Context), params, true, 0), (TypeBuilder::get(Context))); params.push_back(TypeBuilder::get(Context)); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(Context), params, false), + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(Context), params, false, 0), (TypeBuilder::get(Context))); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(Context), params, true), + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(Context), params, true, 0), (TypeBuilder::get(Context))); params.push_back(TypeBuilder::get(Context)); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(Context), params, false), + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(Context), params, false, 0), (TypeBuilder::get(Context))); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(Context), params, true), + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(Context), params, true, 0), (TypeBuilder::get(Context))); params.push_back(TypeBuilder::get(Context)); EXPECT_EQ( - FunctionType::get(Type::getInt8Ty(Context), params, false), + FunctionType::get(Type::getInt8Ty(Context), params, false, 0), (TypeBuilder::get(Context))); EXPECT_EQ( - FunctionType::get(Type::getInt8Ty(Context), params, true), + FunctionType::get(Type::getInt8Ty(Context), params, true, 0), (TypeBuilder::get(Context))); params.push_back(TypeBuilder::get(Context)); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(Context), params, false), + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(Context), params, false, 0), (TypeBuilder::get( Context))); EXPECT_EQ( - FunctionType::get(Type::getInt8Ty(Context), params, true), + FunctionType::get(Type::getInt8Ty(Context), params, true, 0), (TypeBuilder::get( Context))); params.push_back(TypeBuilder::get(Context)); EXPECT_EQ( - FunctionType::get(Type::getInt8Ty(Context), params, false), + FunctionType::get(Type::getInt8Ty(Context), params, false, 0), (TypeBuilder::get( Context))); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(Context), params, true), + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(Context), params, true, 0), (TypeBuilder::get(Context))); } Index: unittests/IR/UserTest.cpp =================================================================== --- unittests/IR/UserTest.cpp +++ unittests/IR/UserTest.cpp @@ -121,7 +121,7 @@ TEST(UserTest, PersonalityUser) { LLVMContext Context; Module M("", Context); - FunctionType *RetVoidTy = FunctionType::get(Type::getVoidTy(Context), false); + FunctionType *RetVoidTy = FunctionType::get(Type::getVoidTy(Context), false, 0); Function *PersonalityF = Function::Create( RetVoidTy, GlobalValue::ExternalLinkage, "PersonalityFn", &M); Function *TestF = Index: unittests/IR/VerifierTest.cpp =================================================================== --- unittests/IR/VerifierTest.cpp +++ unittests/IR/VerifierTest.cpp @@ -27,7 +27,8 @@ TEST(VerifierTest, Branch_i1) { LLVMContext C; Module M("M", C); - FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), /*isVarArg=*/false); + FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), /*isVarArg=*/false, + /*AddrSpace=*/0); Function *F = cast(M.getOrInsertFunction("foo", FTy)); BasicBlock *Entry = BasicBlock::Create(C, "entry", F); BasicBlock *Exit = BasicBlock::Create(C, "exit", F); @@ -50,7 +51,8 @@ TEST(VerifierTest, InvalidRetAttribute) { LLVMContext C; Module M("M", C); - FunctionType *FTy = FunctionType::get(Type::getInt32Ty(C), /*isVarArg=*/false); + FunctionType *FTy = FunctionType::get(Type::getInt32Ty(C), /*isVarArg=*/false, + /*AddrSpace=*/0); Function *F = cast(M.getOrInsertFunction("foo", FTy)); AttributeList AS = F->getAttributes(); F->setAttributes( @@ -68,7 +70,8 @@ Module M1("M1", C); Module M2("M2", C); Module M3("M3", C); - FunctionType *FTy = FunctionType::get(Type::getInt32Ty(C), /*isVarArg=*/false); + FunctionType *FTy = FunctionType::get(Type::getInt32Ty(C), /*isVarArg=*/false, + /*AddrSpace=*/0); Function *F1 = cast(M1.getOrInsertFunction("foo1", FTy)); Function *F2 = cast(M2.getOrInsertFunction("foo2", FTy)); Function *F3 = cast(M3.getOrInsertFunction("foo3", FTy)); @@ -139,7 +142,8 @@ LLVMContext C; Module M("M", C); - FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), /*isVarArg=*/false); + FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), /*isVarArg=*/false, + /*AddrSpace=*/0); Function::Create(FTy, GlobalValue::LinkOnceODRLinkage, "foo", &M); std::string Error; raw_string_ostream ErrorOS(Error); @@ -183,7 +187,7 @@ GlobalValue::ExternalLinkage, nullptr, "g"); auto *F = cast(M.getOrInsertFunction( - "f", FunctionType::get(Type::getVoidTy(C), false))); + "f", FunctionType::get(Type::getVoidTy(C), false, 0))); IRBuilder<> Builder(BasicBlock::Create(C, "", F)); Builder.CreateUnreachable(); F->setSubprogram(DIB.createFunction(CU, "f", "f", Index: unittests/IR/WaymarkTest.cpp =================================================================== --- unittests/IR/WaymarkTest.cpp +++ unittests/IR/WaymarkTest.cpp @@ -26,7 +26,7 @@ std::transform(tail, tail + 22, values, [&](char c) { return ConstantInt::get(Type::getInt8Ty(Context), c); }); - FunctionType *FT = FunctionType::get(Type::getVoidTy(Context), true); + FunctionType *FT = FunctionType::get(Type::getVoidTy(Context), true, 0); std::unique_ptr F( Function::Create(FT, GlobalValue::ExternalLinkage)); const CallInst *A = CallInst::Create(F.get(), makeArrayRef(values)); Index: unittests/ProfileData/InstrProfTest.cpp =================================================================== --- unittests/ProfileData/InstrProfTest.cpp +++ unittests/ProfileData/InstrProfTest.cpp @@ -286,7 +286,7 @@ LLVMContext Ctx; std::unique_ptr M(new Module("MyModule", Ctx)); FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx), - /*isVarArg=*/false); + /*isVarArg=*/false, /*AddrSpace=*/0); Function *F = Function::Create(FTy, Function::ExternalLinkage, "caller", M.get()); BasicBlock *BB = BasicBlock::Create(Ctx, "", F); @@ -893,7 +893,7 @@ LLVMContext Ctx; std::unique_ptr M = llvm::make_unique("MyModule.cpp", Ctx); FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx), - /*isVarArg=*/false); + /*isVarArg=*/false, /*AddrSpace=*/0); Function::Create(FTy, Function::ExternalLinkage, "Gfoo", M.get()); Function::Create(FTy, Function::ExternalLinkage, "Gblah", M.get()); Function::Create(FTy, Function::ExternalLinkage, "Gbar", M.get()); Index: unittests/Transforms/Utils/Cloning.cpp =================================================================== --- unittests/Transforms/Utils/Cloning.cpp +++ unittests/Transforms/Utils/Cloning.cpp @@ -158,7 +158,7 @@ TEST_F(CloneInstruction, Attributes) { Type *ArgTy1[] = { Type::getInt32PtrTy(context) }; - FunctionType *FT1 = FunctionType::get(Type::getVoidTy(context), ArgTy1, false); + FunctionType *FT1 = FunctionType::get(Type::getVoidTy(context), ArgTy1, false, 0); Function *F1 = Function::Create(FT1, Function::ExternalLinkage); BasicBlock *BB = BasicBlock::Create(context, "", F1); @@ -183,7 +183,7 @@ TEST_F(CloneInstruction, CallingConvention) { Type *ArgTy1[] = { Type::getInt32PtrTy(context) }; - FunctionType *FT1 = FunctionType::get(Type::getVoidTy(context), ArgTy1, false); + FunctionType *FT1 = FunctionType::get(Type::getVoidTy(context), ArgTy1, false, 0); Function *F1 = Function::Create(FT1, Function::ExternalLinkage); F1->setCallingConv(CallingConv::Cold); @@ -206,7 +206,7 @@ TEST_F(CloneInstruction, DuplicateInstructionsToSplit) { Type *ArgTy1[] = {Type::getInt32PtrTy(context)}; - FunctionType *FT = FunctionType::get(Type::getVoidTy(context), ArgTy1, false); + FunctionType *FT = FunctionType::get(Type::getVoidTy(context), ArgTy1, false, 0); V = new Argument(Type::getInt32Ty(context)); Function *F = Function::Create(FT, Function::ExternalLinkage); @@ -267,7 +267,7 @@ } void CreateOldFunc() { - FunctionType* FuncType = FunctionType::get(Type::getVoidTy(C), false); + FunctionType* FuncType = FunctionType::get(Type::getVoidTy(C), false, 0); OldFunc = Function::Create(FuncType, GlobalValue::PrivateLinkage, "f", M); CreateOldFunctionBodyAndDI(); } @@ -484,7 +484,7 @@ DIBuilder DBuilder(*OldM); IRBuilder<> IBuilder(C); - auto *FuncType = FunctionType::get(Type::getVoidTy(C), false); + auto *FuncType = FunctionType::get(Type::getVoidTy(C), false, 0); auto *PersFn = Function::Create(FuncType, GlobalValue::ExternalLinkage, "persfn", OldM); auto *F = Index: unittests/Transforms/Utils/IntegerDivision.cpp =================================================================== --- unittests/Transforms/Utils/IntegerDivision.cpp +++ unittests/Transforms/Utils/IntegerDivision.cpp @@ -27,7 +27,7 @@ SmallVector ArgTys(2, Builder.getInt32Ty()); Function *F = Function::Create(FunctionType::get(Builder.getInt32Ty(), - ArgTys, false), + ArgTys, false, 0), GlobalValue::ExternalLinkage, "F", &M); assert(F->arg_size() == 2); @@ -57,7 +57,7 @@ SmallVector ArgTys(2, Builder.getInt32Ty()); Function *F = Function::Create(FunctionType::get(Builder.getInt32Ty(), - ArgTys, false), + ArgTys, false, 0), GlobalValue::ExternalLinkage, "F", &M); assert(F->arg_size() == 2); @@ -87,7 +87,7 @@ SmallVector ArgTys(2, Builder.getInt32Ty()); Function *F = Function::Create(FunctionType::get(Builder.getInt32Ty(), - ArgTys, false), + ArgTys, false, 0), GlobalValue::ExternalLinkage, "F", &M); assert(F->arg_size() == 2); @@ -117,7 +117,7 @@ SmallVector ArgTys(2, Builder.getInt32Ty()); Function *F = Function::Create(FunctionType::get(Builder.getInt32Ty(), - ArgTys, false), + ArgTys, false, 0), GlobalValue::ExternalLinkage, "F", &M); assert(F->arg_size() == 2); @@ -148,7 +148,7 @@ SmallVector ArgTys(2, Builder.getInt64Ty()); Function *F = Function::Create(FunctionType::get(Builder.getInt64Ty(), - ArgTys, false), + ArgTys, false, 0), GlobalValue::ExternalLinkage, "F", &M); assert(F->arg_size() == 2); @@ -178,7 +178,7 @@ SmallVector ArgTys(2, Builder.getInt64Ty()); Function *F = Function::Create(FunctionType::get(Builder.getInt64Ty(), - ArgTys, false), + ArgTys, false, 0), GlobalValue::ExternalLinkage, "F", &M); assert(F->arg_size() == 2); @@ -208,7 +208,7 @@ SmallVector ArgTys(2, Builder.getInt64Ty()); Function *F = Function::Create(FunctionType::get(Builder.getInt64Ty(), - ArgTys, false), + ArgTys, false, 0), GlobalValue::ExternalLinkage, "F", &M); assert(F->arg_size() == 2); @@ -238,7 +238,7 @@ SmallVector ArgTys(2, Builder.getInt64Ty()); Function *F = Function::Create(FunctionType::get(Builder.getInt64Ty(), - ArgTys, false), + ArgTys, false, 0), GlobalValue::ExternalLinkage, "F", &M); assert(F->arg_size() == 2); Index: unittests/Transforms/Utils/Local.cpp =================================================================== --- unittests/Transforms/Utils/Local.cpp +++ unittests/Transforms/Utils/Local.cpp @@ -64,7 +64,7 @@ IRBuilder<> B(C); std::unique_ptr F( - Function::Create(FunctionType::get(B.getVoidTy(), false), + Function::Create(FunctionType::get(B.getVoidTy(), false, 0), GlobalValue::ExternalLinkage, "F")); BasicBlock *Entry(BasicBlock::Create(C, "", F.get())); BasicBlock *BB(BasicBlock::Create(C, "", F.get()));