From 0fd170f47ab8837d205690c8a6efc82eb84c888c Mon Sep 17 00:00:00 2001 From: Andrey Guskov Date: Wed, 22 Apr 2015 17:42:13 +0300 Subject: [PATCH] Another version of multitarget return types fix --- module.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/module.cpp b/module.cpp index 95be7352..12c57f87 100644 --- a/module.cpp +++ b/module.cpp @@ -2833,11 +2833,9 @@ lCreateDispatchFunction(llvm::Module *module, llvm::Function *setISAFunc, for (int i = 0; i < Target::NUM_ISAS; ++i) { if (funcs.func[i] == NULL) { - targetFuncs[i] = NULL; ftypes[i] = NULL; continue; } - // Grab the type of the function as well. Note that the various // functions will have different types if they have arguments that // are pointers to structs, due to the fact that we mangle LLVM @@ -2852,16 +2850,27 @@ lCreateDispatchFunction(llvm::Module *module, llvm::Function *setISAFunc, // by i8 *'s. // if (ftype == NULL) ftypes[i] = funcs.func[i]->getFunctionType(); - - targetFuncs[i] = - llvm::Function::Create(ftypes[i], llvm::GlobalValue::ExternalLinkage, - funcs.func[i]->getName(), module); } // New helper function checks to see if we need to rewrite the // type for the dispatch function in case of pointers to varyings llvm::FunctionType *ftype = lGetVaryingDispatchType(funcs); - + + // Now we insert type-punned declarations for dispatched functions. + // This is needed when compiling modules for a set of architectures + // with different vector lengths. Due to restrictions, the return + // type is the same across all architectures, however in different + // modules it may have dissimilar names. The loop below works this + // around. + for (int i = 0; i < Target::NUM_ISAS; ++i) { + if (funcs.func[i]) + targetFuncs[i] = + llvm::Function::Create(ftype, llvm::GlobalValue::ExternalLinkage, + funcs.func[i]->getName(), module); + else + targetFuncs[i] = NULL; + } + bool voidReturn = ftype->getReturnType()->isVoidTy(); // Now we can emit the definition of the dispatch function.. @@ -2919,7 +2928,6 @@ lCreateDispatchFunction(llvm::Module *module, llvm::Function *setISAFunc, "dpatch_arg_bitcast", callBBlock); args.push_back(argCast); } - } if (voidReturn) { llvm::CallInst::Create(targetFuncs[i], args, "", callBBlock);