From 6bcf2ba2f0fff179602fd60b5e0127cd20fc907e Mon Sep 17 00:00:00 2001 From: Alexander Richardson Date: Thu, 23 Aug 2018 09:25:17 +0000 Subject: Allow creating llvm::Function in non-zero address spaces Most users won't have to worry about this as all of the 'getOrInsertFunction' functions on Module will default to the program address space. An overload has been added to Function::Create to abstract away the details for most callers. This is based on https://reviews.llvm.org/D37054 but without the changes to make passing a Module to Function::Create() mandatory. I have also added some more tests and fixed the LLParser to accept call instructions for types in the program address space. Reviewed By: bjope Differential Revision: https://reviews.llvm.org/D47541 llvm-svn: 340519 --- llvm/lib/Transforms/Utils/CloneFunction.cpp | 4 ++-- llvm/lib/Transforms/Utils/CloneModule.cpp | 9 +++++---- llvm/lib/Transforms/Utils/CodeExtractor.cpp | 7 +++---- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'llvm/lib/Transforms/Utils') diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp index 80736034005..5dbe6e9ac76 100644 --- a/llvm/lib/Transforms/Utils/CloneFunction.cpp +++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp @@ -235,8 +235,8 @@ Function *llvm::CloneFunction(Function *F, ValueToValueMapTy &VMap, ArgTypes, F->getFunctionType()->isVarArg()); // Create the new function... - Function *NewF = - Function::Create(FTy, F->getLinkage(), F->getName(), F->getParent()); + Function *NewF = Function::Create(FTy, F->getLinkage(), F->getAddressSpace(), + F->getName(), F->getParent()); // Loop over the arguments, copying the names of the mapped arguments over... Function::arg_iterator DestI = NewF->arg_begin(); diff --git a/llvm/lib/Transforms/Utils/CloneModule.cpp b/llvm/lib/Transforms/Utils/CloneModule.cpp index c7d68bab817..659993aa547 100644 --- a/llvm/lib/Transforms/Utils/CloneModule.cpp +++ b/llvm/lib/Transforms/Utils/CloneModule.cpp @@ -74,8 +74,9 @@ std::unique_ptr llvm::CloneModule( // Loop over the functions in the module, making external functions as before for (const Function &I : M) { - Function *NF = Function::Create(cast(I.getValueType()), - I.getLinkage(), I.getName(), New.get()); + Function *NF = + Function::Create(cast(I.getValueType()), I.getLinkage(), + I.getAddressSpace(), I.getName(), New.get()); NF->copyAttributesFrom(&I); VMap[&I] = NF; } @@ -91,8 +92,8 @@ std::unique_ptr llvm::CloneModule( GlobalValue *GV; if (I->getValueType()->isFunctionTy()) GV = Function::Create(cast(I->getValueType()), - GlobalValue::ExternalLinkage, I->getName(), - New.get()); + GlobalValue::ExternalLinkage, + I->getAddressSpace(), I->getName(), New.get()); else GV = new GlobalVariable( *New, I->getValueType(), false, GlobalValue::ExternalLinkage, diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp index eeb5d2bf5eb..d9f39bd1749 100644 --- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp +++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp @@ -670,10 +670,9 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs, AllowVarArgs && oldFunction->isVarArg()); // Create the new function - Function *newFunction = Function::Create(funcType, - GlobalValue::InternalLinkage, - oldFunction->getName() + "_" + - header->getName(), M); + Function *newFunction = Function::Create( + funcType, GlobalValue::InternalLinkage, oldFunction->getAddressSpace(), + oldFunction->getName() + "_" + header->getName(), M); // If the old function is no-throw, so is the new one. if (oldFunction->doesNotThrow()) newFunction->setDoesNotThrow(); -- cgit v1.2.3