// // This pass only makes sense when the underlying chip has floating point but // we are compiling as mips16. // For all mips16 functions (that are not stubs we have already generated), or // declared via attributes as nomips16, we must: // 1) fixup all returns of float, double, single and double complex // by calling a helper function before the actual return. // 2) generate helper functions (stubs) that can be called by mips32 functions // that will move parameters passed normally passed in floating point // registers the soft float equivalents. // 3) in the case of static relocation, generate helper functions so that // mips16 functions can call extern functions of unknown type (mips16 or // mips32). // 4) TBD. For pic, calls to extern functions of unknown type are handled by // predefined helper functions in libc but this work is currently done // during call lowering but it should be moved here in the future. // bool Mips16HardFloat::runOnModule(Module &M) { DEBUG(errs() << "Run on Module Mips16HardFloat\n"); bool Modified = false; for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) { if (F->isDeclaration() || F->hasFnAttribute("mips16_fp_stub") || F->hasFnAttribute("nomips16")) continue; Modified |= fixupFPReturnAndCall(*F, &M, Subtarget); FPParamVariant V = whichFPParamVariantNeeded(*F); if (V != NoSig) { Modified = true; createFPFnStub(F, &M, V, Subtarget); } } return Modified; }
// // Make sure that we know we already need a stub for this function. // Having called needsFPHelperFromSig // static void assureFPCallStub(Function &F, Module *M, const MipsSubtarget &Subtarget){ // for now we only need them for static relocation if (Subtarget.getRelocationModel() == Reloc::PIC_) return; LLVMContext &Context = M->getContext(); bool LE = Subtarget.isLittle(); std::string Name = F.getName(); std::string SectionName = ".mips16.call.fp." + Name; std::string StubName = "__call_stub_fp_" + Name; // // see if we already have the stub // Function *FStub = M->getFunction(StubName); if (FStub && !FStub->isDeclaration()) return; FStub = Function::Create(F.getFunctionType(), Function::InternalLinkage, StubName, M); FStub->addFnAttr("mips16_fp_stub"); FStub->addFnAttr(llvm::Attribute::Naked); FStub->addFnAttr(llvm::Attribute::NoInline); FStub->addFnAttr(llvm::Attribute::NoUnwind); FStub->addFnAttr("nomips16"); FStub->setSection(SectionName); BasicBlock *BB = BasicBlock::Create(Context, "entry", FStub); InlineAsmHelper IAH(Context, BB); IAH.Out(".set reorder"); FPReturnVariant RV = whichFPReturnVariant(FStub->getReturnType()); FPParamVariant PV = whichFPParamVariantNeeded(F); swapFPIntParams(PV, M, IAH, LE, true); if (RV != NoFPRet) { IAH.Out("move $$18, $$31"); IAH.Out("jal " + Name); } else { IAH.Out("lui $$25,%hi(" + Name + ")"); IAH.Out("addiu $$25,$$25,%lo(" + Name + ")" ); } switch (RV) { case FRet: IAH.Out("mfc1 $$2,$$f0"); break; case DRet: if (LE) { IAH.Out("mfc1 $$2,$$f0"); IAH.Out("mfc1 $$3,$$f1"); } else { IAH.Out("mfc1 $$3,$$f0"); IAH.Out("mfc1 $$2,$$f1"); } break; case CFRet: if (LE) { IAH.Out("mfc1 $$2,$$f0"); IAH.Out("mfc1 $$3,$$f2"); } else { IAH.Out("mfc1 $$3,$$f0"); IAH.Out("mfc1 $$3,$$f2"); } break; case CDRet: if (LE) { IAH.Out("mfc1 $$4,$$f2"); IAH.Out("mfc1 $$5,$$f3"); IAH.Out("mfc1 $$2,$$f0"); IAH.Out("mfc1 $$3,$$f1"); } else { IAH.Out("mfc1 $$5,$$f2"); IAH.Out("mfc1 $$4,$$f3"); IAH.Out("mfc1 $$3,$$f0"); IAH.Out("mfc1 $$2,$$f1"); } break; case NoFPRet: break; } if (RV != NoFPRet) IAH.Out("jr $$18"); else IAH.Out("jr $$25"); new UnreachableInst(Context, BB); }