diff options
author | Alexander Richardson <arichardson.kde@gmail.com> | 2018-08-23 09:25:17 +0000 |
---|---|---|
committer | Alexander Richardson <arichardson.kde@gmail.com> | 2018-08-23 09:25:17 +0000 |
commit | 6bcf2ba2f0fff179602fd60b5e0127cd20fc907e (patch) | |
tree | e75d5473ea23982ba49e0c6ee1b24fd35b57dd8f /llvm/lib/IR/Module.cpp | |
parent | ba9eee5fadf1114d5ed422ce80dca50099057933 (diff) | |
download | bcm5719-llvm-6bcf2ba2f0fff179602fd60b5e0127cd20fc907e.tar.gz bcm5719-llvm-6bcf2ba2f0fff179602fd60b5e0127cd20fc907e.zip |
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
Diffstat (limited to 'llvm/lib/IR/Module.cpp')
-rw-r--r-- | llvm/lib/IR/Module.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp index f1802406353..882ab106a37 100644 --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -145,7 +145,8 @@ Constant *Module::getOrInsertFunction(StringRef Name, FunctionType *Ty, GlobalValue *F = getNamedValue(Name); if (!F) { // Nope, add it - Function *New = Function::Create(Ty, GlobalVariable::ExternalLinkage, Name); + Function *New = Function::Create(Ty, GlobalVariable::ExternalLinkage, + DL.getProgramAddressSpace(), Name); if (!New->isIntrinsic()) // Intrinsics get attrs set on construction New->setAttributes(AttributeList); FunctionList.push_back(New); @@ -154,8 +155,9 @@ Constant *Module::getOrInsertFunction(StringRef Name, FunctionType *Ty, // If the function exists but has the wrong type, return a bitcast to the // right type. - if (F->getType() != PointerType::getUnqual(Ty)) - return ConstantExpr::getBitCast(F, PointerType::getUnqual(Ty)); + auto *PTy = PointerType::get(Ty, F->getAddressSpace()); + if (F->getType() != PTy) + return ConstantExpr::getBitCast(F, PTy); // Otherwise, we just found the existing function or a prototype. return F; |