Checkin in of first of several patches to finish implementation of
mips16/mips32 floating point interoperability.
This patch fixes returns from mips16 functions so that if the function
was in fact called by a mips32 hard float routine, then values
that would have been returned in floating point registers are so returned.
Mips16 mode has no floating point instructions so there is no way to
load values into floating point registers.
This is needed when returning float, double, single complex, double complex
in the Mips ABI.
Helper functions in libc for mips16 are available to do this.
For efficiency purposes, these helper functions have a different calling
convention from normal Mips calls.
Registers v0,v1,a0,a1 are used to pass parameters instead of
a0,a1,a2,a3.
This is because v0,v1,a0,a1 are the natural registers used to return
floating point values in soft float. These values can then be moved
to the appropriate floating point registers with no extra cost.
The only register that is modified is ra in this call.
The helper functions make sure that the return values are in the floating
point registers that they would be in if soft float was not in effect
(which it is for mips16, though the soft float is implemented using a mips32
library that uses hard float).
llvm-svn: 181641
2013-05-11 06:25:39 +08:00
|
|
|
//===---- Mips16HardFloat.cpp for Mips16 Hard Float --------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines a pass needed for Mips16 Hard Float
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-03-24 02:07:13 +08:00
|
|
|
#include "MipsTargetMachine.h"
|
Checkin in of first of several patches to finish implementation of
mips16/mips32 floating point interoperability.
This patch fixes returns from mips16 functions so that if the function
was in fact called by a mips32 hard float routine, then values
that would have been returned in floating point registers are so returned.
Mips16 mode has no floating point instructions so there is no way to
load values into floating point registers.
This is needed when returning float, double, single complex, double complex
in the Mips ABI.
Helper functions in libc for mips16 are available to do this.
For efficiency purposes, these helper functions have a different calling
convention from normal Mips calls.
Registers v0,v1,a0,a1 are used to pass parameters instead of
a0,a1,a2,a3.
This is because v0,v1,a0,a1 are the natural registers used to return
floating point values in soft float. These values can then be moved
to the appropriate floating point registers with no extra cost.
The only register that is modified is ra in this call.
The helper functions make sure that the return values are in the floating
point registers that they would be in if soft float was not in effect
(which it is for mips16, though the soft float is implemented using a mips32
library that uses hard float).
llvm-svn: 181641
2013-05-11 06:25:39 +08:00
|
|
|
#include "llvm/IR/Module.h"
|
2014-01-07 19:48:04 +08:00
|
|
|
#include "llvm/IR/Value.h"
|
Checkin in of first of several patches to finish implementation of
mips16/mips32 floating point interoperability.
This patch fixes returns from mips16 functions so that if the function
was in fact called by a mips32 hard float routine, then values
that would have been returned in floating point registers are so returned.
Mips16 mode has no floating point instructions so there is no way to
load values into floating point registers.
This is needed when returning float, double, single complex, double complex
in the Mips ABI.
Helper functions in libc for mips16 are available to do this.
For efficiency purposes, these helper functions have a different calling
convention from normal Mips calls.
Registers v0,v1,a0,a1 are used to pass parameters instead of
a0,a1,a2,a3.
This is because v0,v1,a0,a1 are the natural registers used to return
floating point values in soft float. These values can then be moved
to the appropriate floating point registers with no extra cost.
The only register that is modified is ra in this call.
The helper functions make sure that the return values are in the floating
point registers that they would be in if soft float was not in effect
(which it is for mips16, though the soft float is implemented using a mips32
library that uses hard float).
llvm-svn: 181641
2013-05-11 06:25:39 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2015-03-24 02:07:13 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2013-08-12 05:30:27 +08:00
|
|
|
#include <algorithm>
|
Checkin in of first of several patches to finish implementation of
mips16/mips32 floating point interoperability.
This patch fixes returns from mips16 functions so that if the function
was in fact called by a mips32 hard float routine, then values
that would have been returned in floating point registers are so returned.
Mips16 mode has no floating point instructions so there is no way to
load values into floating point registers.
This is needed when returning float, double, single complex, double complex
in the Mips ABI.
Helper functions in libc for mips16 are available to do this.
For efficiency purposes, these helper functions have a different calling
convention from normal Mips calls.
Registers v0,v1,a0,a1 are used to pass parameters instead of
a0,a1,a2,a3.
This is because v0,v1,a0,a1 are the natural registers used to return
floating point values in soft float. These values can then be moved
to the appropriate floating point registers with no extra cost.
The only register that is modified is ra in this call.
The helper functions make sure that the return values are in the floating
point registers that they would be in if soft float was not in effect
(which it is for mips16, though the soft float is implemented using a mips32
library that uses hard float).
llvm-svn: 181641
2013-05-11 06:25:39 +08:00
|
|
|
#include <string>
|
2015-03-14 17:02:23 +08:00
|
|
|
|
2015-03-09 23:50:58 +08:00
|
|
|
using namespace llvm;
|
Checkin in of first of several patches to finish implementation of
mips16/mips32 floating point interoperability.
This patch fixes returns from mips16 functions so that if the function
was in fact called by a mips32 hard float routine, then values
that would have been returned in floating point registers are so returned.
Mips16 mode has no floating point instructions so there is no way to
load values into floating point registers.
This is needed when returning float, double, single complex, double complex
in the Mips ABI.
Helper functions in libc for mips16 are available to do this.
For efficiency purposes, these helper functions have a different calling
convention from normal Mips calls.
Registers v0,v1,a0,a1 are used to pass parameters instead of
a0,a1,a2,a3.
This is because v0,v1,a0,a1 are the natural registers used to return
floating point values in soft float. These values can then be moved
to the appropriate floating point registers with no extra cost.
The only register that is modified is ra in this call.
The helper functions make sure that the return values are in the floating
point registers that they would be in if soft float was not in effect
(which it is for mips16, though the soft float is implemented using a mips32
library that uses hard float).
llvm-svn: 181641
2013-05-11 06:25:39 +08:00
|
|
|
|
2014-04-22 10:41:26 +08:00
|
|
|
#define DEBUG_TYPE "mips16-hard-float"
|
|
|
|
|
2013-05-14 10:00:24 +08:00
|
|
|
namespace {
|
2015-03-14 17:02:23 +08:00
|
|
|
class Mips16HardFloat : public ModulePass {
|
|
|
|
public:
|
|
|
|
static char ID;
|
2013-05-14 10:00:24 +08:00
|
|
|
|
2015-03-14 17:02:23 +08:00
|
|
|
Mips16HardFloat(MipsTargetMachine &TM_) : ModulePass(ID), TM(TM_) {}
|
2013-05-14 10:00:24 +08:00
|
|
|
|
2015-03-14 17:02:23 +08:00
|
|
|
const char *getPassName() const override {
|
|
|
|
return "MIPS16 Hard Float Pass";
|
|
|
|
}
|
2013-05-14 10:00:24 +08:00
|
|
|
|
2015-03-14 17:02:23 +08:00
|
|
|
bool runOnModule(Module &M) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const MipsTargetMachine &TM;
|
|
|
|
};
|
|
|
|
|
2015-10-21 20:44:14 +08:00
|
|
|
static void EmitInlineAsm(LLVMContext &C, BasicBlock *BB, StringRef AsmText) {
|
|
|
|
std::vector<llvm::Type *> AsmArgTypes;
|
|
|
|
std::vector<llvm::Value *> AsmArgs;
|
2015-03-14 17:02:23 +08:00
|
|
|
|
2015-10-21 20:44:14 +08:00
|
|
|
llvm::FunctionType *AsmFTy =
|
|
|
|
llvm::FunctionType::get(Type::getVoidTy(C), AsmArgTypes, false);
|
|
|
|
llvm::InlineAsm *IA =
|
|
|
|
llvm::InlineAsm::get(AsmFTy, AsmText, "", true,
|
|
|
|
/* IsAlignStack */ false, llvm::InlineAsm::AD_ATT);
|
|
|
|
CallInst::Create(IA, AsmArgs, "", BB);
|
|
|
|
}
|
2015-03-14 17:02:23 +08:00
|
|
|
|
|
|
|
char Mips16HardFloat::ID = 0;
|
2015-06-23 17:49:53 +08:00
|
|
|
}
|
2015-03-14 17:02:23 +08:00
|
|
|
|
Checkin in of first of several patches to finish implementation of
mips16/mips32 floating point interoperability.
This patch fixes returns from mips16 functions so that if the function
was in fact called by a mips32 hard float routine, then values
that would have been returned in floating point registers are so returned.
Mips16 mode has no floating point instructions so there is no way to
load values into floating point registers.
This is needed when returning float, double, single complex, double complex
in the Mips ABI.
Helper functions in libc for mips16 are available to do this.
For efficiency purposes, these helper functions have a different calling
convention from normal Mips calls.
Registers v0,v1,a0,a1 are used to pass parameters instead of
a0,a1,a2,a3.
This is because v0,v1,a0,a1 are the natural registers used to return
floating point values in soft float. These values can then be moved
to the appropriate floating point registers with no extra cost.
The only register that is modified is ra in this call.
The helper functions make sure that the return values are in the floating
point registers that they would be in if soft float was not in effect
(which it is for mips16, though the soft float is implemented using a mips32
library that uses hard float).
llvm-svn: 181641
2013-05-11 06:25:39 +08:00
|
|
|
//
|
|
|
|
// Return types that matter for hard float are:
|
|
|
|
// float, double, complex float, and complex double
|
|
|
|
//
|
|
|
|
enum FPReturnVariant {
|
|
|
|
FRet, DRet, CFRet, CDRet, NoFPRet
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// Determine which FP return type this function has
|
|
|
|
//
|
|
|
|
static FPReturnVariant whichFPReturnVariant(Type *T) {
|
|
|
|
switch (T->getTypeID()) {
|
|
|
|
case Type::FloatTyID:
|
|
|
|
return FRet;
|
|
|
|
case Type::DoubleTyID:
|
|
|
|
return DRet;
|
|
|
|
case Type::StructTyID:
|
|
|
|
if (T->getStructNumElements() != 2)
|
|
|
|
break;
|
|
|
|
if ((T->getContainedType(0)->isFloatTy()) &&
|
|
|
|
(T->getContainedType(1)->isFloatTy()))
|
|
|
|
return CFRet;
|
|
|
|
if ((T->getContainedType(0)->isDoubleTy()) &&
|
|
|
|
(T->getContainedType(1)->isDoubleTy()))
|
|
|
|
return CDRet;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NoFPRet;
|
|
|
|
}
|
|
|
|
|
2013-05-14 10:00:24 +08:00
|
|
|
//
|
|
|
|
// Parameter type that matter are float, (float, float), (float, double),
|
|
|
|
// double, (double, double), (double, float)
|
|
|
|
//
|
|
|
|
enum FPParamVariant {
|
|
|
|
FSig, FFSig, FDSig,
|
|
|
|
DSig, DDSig, DFSig, NoSig
|
|
|
|
};
|
|
|
|
|
|
|
|
// which floating point parameter signature variant we are dealing with
|
|
|
|
//
|
|
|
|
typedef Type::TypeID TypeID;
|
|
|
|
const Type::TypeID FloatTyID = Type::FloatTyID;
|
|
|
|
const Type::TypeID DoubleTyID = Type::DoubleTyID;
|
|
|
|
|
|
|
|
static FPParamVariant whichFPParamVariantNeeded(Function &F) {
|
|
|
|
switch (F.arg_size()) {
|
|
|
|
case 0:
|
|
|
|
return NoSig;
|
|
|
|
case 1:{
|
|
|
|
TypeID ArgTypeID = F.getFunctionType()->getParamType(0)->getTypeID();
|
|
|
|
switch (ArgTypeID) {
|
|
|
|
case FloatTyID:
|
|
|
|
return FSig;
|
|
|
|
case DoubleTyID:
|
|
|
|
return DSig;
|
|
|
|
default:
|
|
|
|
return NoSig;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
TypeID ArgTypeID0 = F.getFunctionType()->getParamType(0)->getTypeID();
|
|
|
|
TypeID ArgTypeID1 = F.getFunctionType()->getParamType(1)->getTypeID();
|
|
|
|
switch(ArgTypeID0) {
|
|
|
|
case FloatTyID: {
|
|
|
|
switch (ArgTypeID1) {
|
|
|
|
case FloatTyID:
|
|
|
|
return FFSig;
|
|
|
|
case DoubleTyID:
|
|
|
|
return FDSig;
|
|
|
|
default:
|
|
|
|
return FSig;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case DoubleTyID: {
|
|
|
|
switch (ArgTypeID1) {
|
|
|
|
case FloatTyID:
|
|
|
|
return DFSig;
|
|
|
|
case DoubleTyID:
|
|
|
|
return DDSig;
|
|
|
|
default:
|
|
|
|
return DSig;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return NoSig;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
llvm_unreachable("can't get here");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Figure out if we need float point based on the function parameters.
|
|
|
|
// We need to move variables in and/or out of floating point
|
|
|
|
// registers because of the ABI
|
|
|
|
//
|
|
|
|
static bool needsFPStubFromParams(Function &F) {
|
|
|
|
if (F.arg_size() >=1) {
|
|
|
|
Type *ArgType = F.getFunctionType()->getParamType(0);
|
|
|
|
switch (ArgType->getTypeID()) {
|
2015-03-14 17:02:23 +08:00
|
|
|
case Type::FloatTyID:
|
|
|
|
case Type::DoubleTyID:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
break;
|
2013-05-14 10:00:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool needsFPReturnHelper(Function &F) {
|
|
|
|
Type* RetType = F.getReturnType();
|
|
|
|
return whichFPReturnVariant(RetType) != NoFPRet;
|
|
|
|
}
|
|
|
|
|
2015-08-02 06:20:21 +08:00
|
|
|
static bool needsFPReturnHelper(FunctionType &FT) {
|
2013-12-19 07:57:48 +08:00
|
|
|
Type* RetType = FT.getReturnType();
|
|
|
|
return whichFPReturnVariant(RetType) != NoFPRet;
|
|
|
|
}
|
|
|
|
|
2013-05-14 10:00:24 +08:00
|
|
|
static bool needsFPHelperFromSig(Function &F) {
|
|
|
|
return needsFPStubFromParams(F) || needsFPReturnHelper(F);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// We swap between FP and Integer registers to allow Mips16 and Mips32 to
|
|
|
|
// interoperate
|
|
|
|
//
|
2015-10-21 20:44:14 +08:00
|
|
|
static std::string swapFPIntParams(FPParamVariant PV, Module *M, bool LE,
|
|
|
|
bool ToFP) {
|
|
|
|
std::string MI = ToFP ? "mtc1 ": "mfc1 ";
|
|
|
|
std::string AsmText;
|
|
|
|
|
2013-05-14 10:00:24 +08:00
|
|
|
switch (PV) {
|
|
|
|
case FSig:
|
2015-10-21 20:44:14 +08:00
|
|
|
AsmText += MI + "$$4, $$f12\n";
|
2013-05-14 10:00:24 +08:00
|
|
|
break;
|
2015-10-21 20:44:14 +08:00
|
|
|
|
2013-05-14 10:00:24 +08:00
|
|
|
case FFSig:
|
2015-10-21 20:44:14 +08:00
|
|
|
AsmText += MI + "$$4, $$f12\n";
|
|
|
|
AsmText += MI + "$$5, $$f14\n";
|
2013-05-14 10:00:24 +08:00
|
|
|
break;
|
2015-10-21 20:44:14 +08:00
|
|
|
|
2013-05-14 10:00:24 +08:00
|
|
|
case FDSig:
|
2015-10-21 20:44:14 +08:00
|
|
|
AsmText += MI + "$$4, $$f12\n";
|
2013-05-14 10:00:24 +08:00
|
|
|
if (LE) {
|
2015-10-21 20:44:14 +08:00
|
|
|
AsmText += MI + "$$6, $$f14\n";
|
|
|
|
AsmText += MI + "$$7, $$f15\n";
|
2013-05-14 10:00:24 +08:00
|
|
|
} else {
|
2015-10-21 20:44:14 +08:00
|
|
|
AsmText += MI + "$$7, $$f14\n";
|
|
|
|
AsmText += MI + "$$6, $$f15\n";
|
2013-05-14 10:00:24 +08:00
|
|
|
}
|
|
|
|
break;
|
2015-10-21 20:44:14 +08:00
|
|
|
|
2013-05-14 10:00:24 +08:00
|
|
|
case DSig:
|
|
|
|
if (LE) {
|
2015-10-21 20:44:14 +08:00
|
|
|
AsmText += MI + "$$4, $$f12\n";
|
|
|
|
AsmText += MI + "$$5, $$f13\n";
|
2013-05-14 10:00:24 +08:00
|
|
|
} else {
|
2015-10-21 20:44:14 +08:00
|
|
|
AsmText += MI + "$$5, $$f12\n";
|
|
|
|
AsmText += MI + "$$4, $$f13\n";
|
2013-05-14 10:00:24 +08:00
|
|
|
}
|
|
|
|
break;
|
2015-10-21 20:44:14 +08:00
|
|
|
|
2013-05-14 10:00:24 +08:00
|
|
|
case DDSig:
|
|
|
|
if (LE) {
|
2015-10-21 20:44:14 +08:00
|
|
|
AsmText += MI + "$$4, $$f12\n";
|
|
|
|
AsmText += MI + "$$5, $$f13\n";
|
|
|
|
AsmText += MI + "$$6, $$f14\n";
|
|
|
|
AsmText += MI + "$$7, $$f15\n";
|
2013-05-14 10:00:24 +08:00
|
|
|
} else {
|
2015-10-21 20:44:14 +08:00
|
|
|
AsmText += MI + "$$5, $$f12\n";
|
|
|
|
AsmText += MI + "$$4, $$f13\n";
|
|
|
|
AsmText += MI + "$$7, $$f14\n";
|
|
|
|
AsmText += MI + "$$6, $$f15\n";
|
2013-05-14 10:00:24 +08:00
|
|
|
}
|
|
|
|
break;
|
2015-10-21 20:44:14 +08:00
|
|
|
|
2013-05-14 10:00:24 +08:00
|
|
|
case DFSig:
|
|
|
|
if (LE) {
|
2015-10-21 20:44:14 +08:00
|
|
|
AsmText += MI + "$$4, $$f12\n";
|
|
|
|
AsmText += MI + "$$5, $$f13\n";
|
2013-05-14 10:00:24 +08:00
|
|
|
} else {
|
2015-10-21 20:44:14 +08:00
|
|
|
AsmText += MI + "$$5, $$f12\n";
|
|
|
|
AsmText += MI + "$$4, $$f13\n";
|
2013-05-14 10:00:24 +08:00
|
|
|
}
|
2015-10-21 20:44:14 +08:00
|
|
|
AsmText += MI + "$$6, $$f14\n";
|
2013-05-14 10:00:24 +08:00
|
|
|
break;
|
2015-10-21 20:44:14 +08:00
|
|
|
|
2013-05-14 10:00:24 +08:00
|
|
|
case NoSig:
|
2015-10-21 20:44:14 +08:00
|
|
|
break;
|
2013-05-14 10:00:24 +08:00
|
|
|
}
|
2015-10-21 20:44:14 +08:00
|
|
|
|
|
|
|
return AsmText;
|
2013-05-14 10:00:24 +08:00
|
|
|
}
|
2015-03-14 17:02:23 +08:00
|
|
|
|
2013-05-14 10:00:24 +08:00
|
|
|
//
|
|
|
|
// Make sure that we know we already need a stub for this function.
|
|
|
|
// Having called needsFPHelperFromSig
|
|
|
|
//
|
2014-02-15 03:16:39 +08:00
|
|
|
static void assureFPCallStub(Function &F, Module *M,
|
2015-01-06 09:12:30 +08:00
|
|
|
const MipsTargetMachine &TM) {
|
2013-05-14 10:00:24 +08:00
|
|
|
// for now we only need them for static relocation
|
2015-01-06 09:12:30 +08:00
|
|
|
if (TM.getRelocationModel() == Reloc::PIC_)
|
2013-05-14 10:00:24 +08:00
|
|
|
return;
|
|
|
|
LLVMContext &Context = M->getContext();
|
2015-01-06 09:12:30 +08:00
|
|
|
bool LE = TM.isLittleEndian();
|
2013-05-14 10:00:24 +08:00
|
|
|
std::string Name = F.getName();
|
|
|
|
std::string SectionName = ".mips16.call.fp." + Name;
|
2013-08-01 10:26:31 +08:00
|
|
|
std::string StubName = "__call_stub_fp_" + Name;
|
2013-05-14 10:00:24 +08:00
|
|
|
//
|
|
|
|
// 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);
|
2013-08-01 10:26:31 +08:00
|
|
|
FStub->addFnAttr(llvm::Attribute::NoInline);
|
2013-05-14 10:00:24 +08:00
|
|
|
FStub->addFnAttr(llvm::Attribute::NoUnwind);
|
|
|
|
FStub->addFnAttr("nomips16");
|
|
|
|
FStub->setSection(SectionName);
|
|
|
|
BasicBlock *BB = BasicBlock::Create(Context, "entry", FStub);
|
|
|
|
FPReturnVariant RV = whichFPReturnVariant(FStub->getReturnType());
|
|
|
|
FPParamVariant PV = whichFPParamVariantNeeded(F);
|
2015-10-21 20:44:14 +08:00
|
|
|
|
|
|
|
std::string AsmText;
|
|
|
|
AsmText += ".set reorder\n";
|
|
|
|
AsmText += swapFPIntParams(PV, M, LE, true);
|
2013-05-14 10:00:24 +08:00
|
|
|
if (RV != NoFPRet) {
|
2015-10-21 20:44:14 +08:00
|
|
|
AsmText += "move $$18, $$31\n";
|
|
|
|
AsmText += "jal " + Name + "\n";
|
2013-05-14 10:00:24 +08:00
|
|
|
} else {
|
2015-10-21 20:44:14 +08:00
|
|
|
AsmText += "lui $$25, %hi(" + Name + ")\n";
|
|
|
|
AsmText += "addiu $$25, $$25, %lo(" + Name + ")\n";
|
2013-05-14 10:00:24 +08:00
|
|
|
}
|
2015-10-21 20:44:14 +08:00
|
|
|
|
2013-05-14 10:00:24 +08:00
|
|
|
switch (RV) {
|
|
|
|
case FRet:
|
2015-10-21 20:44:14 +08:00
|
|
|
AsmText += "mfc1 $$2, $$f0\n";
|
2013-05-14 10:00:24 +08:00
|
|
|
break;
|
2015-10-21 20:44:14 +08:00
|
|
|
|
2013-05-14 10:00:24 +08:00
|
|
|
case DRet:
|
|
|
|
if (LE) {
|
2015-10-21 20:44:14 +08:00
|
|
|
AsmText += "mfc1 $$2, $$f0\n";
|
|
|
|
AsmText += "mfc1 $$3, $$f1\n";
|
2013-05-14 10:00:24 +08:00
|
|
|
} else {
|
2015-10-21 20:44:14 +08:00
|
|
|
AsmText += "mfc1 $$3, $$f0\n";
|
|
|
|
AsmText += "mfc1 $$2, $$f1\n";
|
2013-05-14 10:00:24 +08:00
|
|
|
}
|
|
|
|
break;
|
2015-10-21 20:44:14 +08:00
|
|
|
|
2013-05-14 10:00:24 +08:00
|
|
|
case CFRet:
|
|
|
|
if (LE) {
|
2015-10-21 20:44:14 +08:00
|
|
|
AsmText += "mfc1 $$2, $$f0\n";
|
|
|
|
AsmText += "mfc1 $$3, $$f2\n";
|
2013-05-14 10:00:24 +08:00
|
|
|
} else {
|
2015-10-21 20:44:14 +08:00
|
|
|
AsmText += "mfc1 $$3, $$f0\n";
|
|
|
|
AsmText += "mfc1 $$3, $$f2\n";
|
2013-05-14 10:00:24 +08:00
|
|
|
}
|
|
|
|
break;
|
2015-10-21 20:44:14 +08:00
|
|
|
|
2013-05-14 10:00:24 +08:00
|
|
|
case CDRet:
|
|
|
|
if (LE) {
|
2015-10-21 20:44:14 +08:00
|
|
|
AsmText += "mfc1 $$4, $$f2\n";
|
|
|
|
AsmText += "mfc1 $$5, $$f3\n";
|
|
|
|
AsmText += "mfc1 $$2, $$f0\n";
|
|
|
|
AsmText += "mfc1 $$3, $$f1\n";
|
2013-05-14 10:00:24 +08:00
|
|
|
|
|
|
|
} else {
|
2015-10-21 20:44:14 +08:00
|
|
|
AsmText += "mfc1 $$5, $$f2\n";
|
|
|
|
AsmText += "mfc1 $$4, $$f3\n";
|
|
|
|
AsmText += "mfc1 $$3, $$f0\n";
|
|
|
|
AsmText += "mfc1 $$2, $$f1\n";
|
2013-05-14 10:00:24 +08:00
|
|
|
}
|
|
|
|
break;
|
2015-10-21 20:44:14 +08:00
|
|
|
|
2013-05-14 10:00:24 +08:00
|
|
|
case NoFPRet:
|
|
|
|
break;
|
|
|
|
}
|
2015-10-21 20:44:14 +08:00
|
|
|
|
2013-05-14 10:00:24 +08:00
|
|
|
if (RV != NoFPRet)
|
2015-10-21 20:44:14 +08:00
|
|
|
AsmText += "jr $$18\n";
|
2013-05-14 10:00:24 +08:00
|
|
|
else
|
2015-10-21 20:44:14 +08:00
|
|
|
AsmText += "jr $$25\n";
|
|
|
|
EmitInlineAsm(Context, BB, AsmText);
|
|
|
|
|
2013-05-14 10:00:24 +08:00
|
|
|
new UnreachableInst(Context, BB);
|
|
|
|
}
|
|
|
|
|
2013-08-12 05:30:27 +08:00
|
|
|
//
|
2013-09-01 12:12:59 +08:00
|
|
|
// Functions that are llvm intrinsics and don't need helpers.
|
2013-08-12 05:30:27 +08:00
|
|
|
//
|
2015-10-18 13:15:34 +08:00
|
|
|
static const char *const IntrinsicInline[] = {
|
2015-03-14 17:02:23 +08:00
|
|
|
"fabs", "fabsf",
|
|
|
|
"llvm.ceil.f32", "llvm.ceil.f64",
|
|
|
|
"llvm.copysign.f32", "llvm.copysign.f64",
|
|
|
|
"llvm.cos.f32", "llvm.cos.f64",
|
|
|
|
"llvm.exp.f32", "llvm.exp.f64",
|
|
|
|
"llvm.exp2.f32", "llvm.exp2.f64",
|
|
|
|
"llvm.fabs.f32", "llvm.fabs.f64",
|
|
|
|
"llvm.floor.f32", "llvm.floor.f64",
|
|
|
|
"llvm.fma.f32", "llvm.fma.f64",
|
|
|
|
"llvm.log.f32", "llvm.log.f64",
|
|
|
|
"llvm.log10.f32", "llvm.log10.f64",
|
|
|
|
"llvm.nearbyint.f32", "llvm.nearbyint.f64",
|
|
|
|
"llvm.pow.f32", "llvm.pow.f64",
|
|
|
|
"llvm.powi.f32", "llvm.powi.f64",
|
|
|
|
"llvm.rint.f32", "llvm.rint.f64",
|
|
|
|
"llvm.round.f32", "llvm.round.f64",
|
|
|
|
"llvm.sin.f32", "llvm.sin.f64",
|
|
|
|
"llvm.sqrt.f32", "llvm.sqrt.f64",
|
|
|
|
"llvm.trunc.f32", "llvm.trunc.f64",
|
|
|
|
};
|
2013-08-12 05:30:27 +08:00
|
|
|
|
2013-08-12 17:37:29 +08:00
|
|
|
static bool isIntrinsicInline(Function *F) {
|
2014-04-13 00:15:53 +08:00
|
|
|
return std::binary_search(std::begin(IntrinsicInline),
|
|
|
|
std::end(IntrinsicInline), F->getName());
|
2013-08-12 05:30:27 +08:00
|
|
|
}
|
Checkin in of first of several patches to finish implementation of
mips16/mips32 floating point interoperability.
This patch fixes returns from mips16 functions so that if the function
was in fact called by a mips32 hard float routine, then values
that would have been returned in floating point registers are so returned.
Mips16 mode has no floating point instructions so there is no way to
load values into floating point registers.
This is needed when returning float, double, single complex, double complex
in the Mips ABI.
Helper functions in libc for mips16 are available to do this.
For efficiency purposes, these helper functions have a different calling
convention from normal Mips calls.
Registers v0,v1,a0,a1 are used to pass parameters instead of
a0,a1,a2,a3.
This is because v0,v1,a0,a1 are the natural registers used to return
floating point values in soft float. These values can then be moved
to the appropriate floating point registers with no extra cost.
The only register that is modified is ra in this call.
The helper functions make sure that the return values are in the floating
point registers that they would be in if soft float was not in effect
(which it is for mips16, though the soft float is implemented using a mips32
library that uses hard float).
llvm-svn: 181641
2013-05-11 06:25:39 +08:00
|
|
|
//
|
|
|
|
// Returns of float, double and complex need to be handled with a helper
|
2013-05-16 10:17:42 +08:00
|
|
|
// function.
|
Checkin in of first of several patches to finish implementation of
mips16/mips32 floating point interoperability.
This patch fixes returns from mips16 functions so that if the function
was in fact called by a mips32 hard float routine, then values
that would have been returned in floating point registers are so returned.
Mips16 mode has no floating point instructions so there is no way to
load values into floating point registers.
This is needed when returning float, double, single complex, double complex
in the Mips ABI.
Helper functions in libc for mips16 are available to do this.
For efficiency purposes, these helper functions have a different calling
convention from normal Mips calls.
Registers v0,v1,a0,a1 are used to pass parameters instead of
a0,a1,a2,a3.
This is because v0,v1,a0,a1 are the natural registers used to return
floating point values in soft float. These values can then be moved
to the appropriate floating point registers with no extra cost.
The only register that is modified is ra in this call.
The helper functions make sure that the return values are in the floating
point registers that they would be in if soft float was not in effect
(which it is for mips16, though the soft float is implemented using a mips32
library that uses hard float).
llvm-svn: 181641
2013-05-11 06:25:39 +08:00
|
|
|
//
|
2015-01-06 09:12:30 +08:00
|
|
|
static bool fixupFPReturnAndCall(Function &F, Module *M,
|
|
|
|
const MipsTargetMachine &TM) {
|
Checkin in of first of several patches to finish implementation of
mips16/mips32 floating point interoperability.
This patch fixes returns from mips16 functions so that if the function
was in fact called by a mips32 hard float routine, then values
that would have been returned in floating point registers are so returned.
Mips16 mode has no floating point instructions so there is no way to
load values into floating point registers.
This is needed when returning float, double, single complex, double complex
in the Mips ABI.
Helper functions in libc for mips16 are available to do this.
For efficiency purposes, these helper functions have a different calling
convention from normal Mips calls.
Registers v0,v1,a0,a1 are used to pass parameters instead of
a0,a1,a2,a3.
This is because v0,v1,a0,a1 are the natural registers used to return
floating point values in soft float. These values can then be moved
to the appropriate floating point registers with no extra cost.
The only register that is modified is ra in this call.
The helper functions make sure that the return values are in the floating
point registers that they would be in if soft float was not in effect
(which it is for mips16, though the soft float is implemented using a mips32
library that uses hard float).
llvm-svn: 181641
2013-05-11 06:25:39 +08:00
|
|
|
bool Modified = false;
|
|
|
|
LLVMContext &C = M->getContext();
|
|
|
|
Type *MyVoid = Type::getVoidTy(C);
|
|
|
|
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
|
|
|
|
for (BasicBlock::iterator I = BB->begin(), E = BB->end();
|
|
|
|
I != E; ++I) {
|
|
|
|
Instruction &Inst = *I;
|
|
|
|
if (const ReturnInst *RI = dyn_cast<ReturnInst>(I)) {
|
|
|
|
Value *RVal = RI->getReturnValue();
|
|
|
|
if (!RVal) continue;
|
|
|
|
//
|
|
|
|
// If there is a return value and it needs a helper function,
|
|
|
|
// figure out which one and add a call before the actual
|
|
|
|
// return to this helper. The purpose of the helper is to move
|
|
|
|
// floating point values from their soft float return mapping to
|
|
|
|
// where they would have been mapped to in floating point registers.
|
|
|
|
//
|
|
|
|
Type *T = RVal->getType();
|
|
|
|
FPReturnVariant RV = whichFPReturnVariant(T);
|
|
|
|
if (RV == NoFPRet) continue;
|
2015-10-18 13:15:34 +08:00
|
|
|
static const char *const Helper[NoFPRet] = {
|
2015-03-14 17:02:23 +08:00
|
|
|
"__mips16_ret_sf", "__mips16_ret_df", "__mips16_ret_sc",
|
|
|
|
"__mips16_ret_dc"
|
|
|
|
};
|
Checkin in of first of several patches to finish implementation of
mips16/mips32 floating point interoperability.
This patch fixes returns from mips16 functions so that if the function
was in fact called by a mips32 hard float routine, then values
that would have been returned in floating point registers are so returned.
Mips16 mode has no floating point instructions so there is no way to
load values into floating point registers.
This is needed when returning float, double, single complex, double complex
in the Mips ABI.
Helper functions in libc for mips16 are available to do this.
For efficiency purposes, these helper functions have a different calling
convention from normal Mips calls.
Registers v0,v1,a0,a1 are used to pass parameters instead of
a0,a1,a2,a3.
This is because v0,v1,a0,a1 are the natural registers used to return
floating point values in soft float. These values can then be moved
to the appropriate floating point registers with no extra cost.
The only register that is modified is ra in this call.
The helper functions make sure that the return values are in the floating
point registers that they would be in if soft float was not in effect
(which it is for mips16, though the soft float is implemented using a mips32
library that uses hard float).
llvm-svn: 181641
2013-05-11 06:25:39 +08:00
|
|
|
const char *Name = Helper[RV];
|
|
|
|
AttributeSet A;
|
|
|
|
Value *Params[] = {RVal};
|
|
|
|
Modified = true;
|
|
|
|
//
|
|
|
|
// These helper functions have a different calling ABI so
|
|
|
|
// this __Mips16RetHelper indicates that so that later
|
|
|
|
// during call setup, the proper call lowering to the helper
|
|
|
|
// functions will take place.
|
|
|
|
//
|
|
|
|
A = A.addAttribute(C, AttributeSet::FunctionIndex,
|
|
|
|
"__Mips16RetHelper");
|
|
|
|
A = A.addAttribute(C, AttributeSet::FunctionIndex,
|
|
|
|
Attribute::ReadNone);
|
2013-08-01 10:26:31 +08:00
|
|
|
A = A.addAttribute(C, AttributeSet::FunctionIndex,
|
|
|
|
Attribute::NoInline);
|
2014-11-21 07:51:47 +08:00
|
|
|
Value *F = (M->getOrInsertFunction(Name, A, MyVoid, T, nullptr));
|
Checkin in of first of several patches to finish implementation of
mips16/mips32 floating point interoperability.
This patch fixes returns from mips16 functions so that if the function
was in fact called by a mips32 hard float routine, then values
that would have been returned in floating point registers are so returned.
Mips16 mode has no floating point instructions so there is no way to
load values into floating point registers.
This is needed when returning float, double, single complex, double complex
in the Mips ABI.
Helper functions in libc for mips16 are available to do this.
For efficiency purposes, these helper functions have a different calling
convention from normal Mips calls.
Registers v0,v1,a0,a1 are used to pass parameters instead of
a0,a1,a2,a3.
This is because v0,v1,a0,a1 are the natural registers used to return
floating point values in soft float. These values can then be moved
to the appropriate floating point registers with no extra cost.
The only register that is modified is ra in this call.
The helper functions make sure that the return values are in the floating
point registers that they would be in if soft float was not in effect
(which it is for mips16, though the soft float is implemented using a mips32
library that uses hard float).
llvm-svn: 181641
2013-05-11 06:25:39 +08:00
|
|
|
CallInst::Create(F, Params, "", &Inst );
|
2013-05-14 10:00:24 +08:00
|
|
|
} else if (const CallInst *CI = dyn_cast<CallInst>(I)) {
|
2016-01-18 06:37:39 +08:00
|
|
|
FunctionType *FT = CI->getFunctionType();
|
2015-03-14 17:02:23 +08:00
|
|
|
Function *F_ = CI->getCalledFunction();
|
2016-01-18 06:37:39 +08:00
|
|
|
if (needsFPReturnHelper(*FT) &&
|
2015-03-14 17:02:23 +08:00
|
|
|
!(F_ && isIntrinsicInline(F_))) {
|
|
|
|
Modified=true;
|
|
|
|
F.addFnAttr("saveS2");
|
|
|
|
}
|
|
|
|
if (F_ && !isIntrinsicInline(F_)) {
|
|
|
|
// pic mode calls are handled by already defined
|
|
|
|
// helper functions
|
|
|
|
if (needsFPReturnHelper(*F_)) {
|
2013-12-19 07:57:48 +08:00
|
|
|
Modified=true;
|
|
|
|
F.addFnAttr("saveS2");
|
|
|
|
}
|
2015-03-14 17:02:23 +08:00
|
|
|
if (TM.getRelocationModel() != Reloc::PIC_ ) {
|
|
|
|
if (needsFPHelperFromSig(*F_)) {
|
|
|
|
assureFPCallStub(*F_, M, TM);
|
2013-05-14 10:00:24 +08:00
|
|
|
Modified=true;
|
|
|
|
}
|
|
|
|
}
|
2015-03-14 17:02:23 +08:00
|
|
|
}
|
Checkin in of first of several patches to finish implementation of
mips16/mips32 floating point interoperability.
This patch fixes returns from mips16 functions so that if the function
was in fact called by a mips32 hard float routine, then values
that would have been returned in floating point registers are so returned.
Mips16 mode has no floating point instructions so there is no way to
load values into floating point registers.
This is needed when returning float, double, single complex, double complex
in the Mips ABI.
Helper functions in libc for mips16 are available to do this.
For efficiency purposes, these helper functions have a different calling
convention from normal Mips calls.
Registers v0,v1,a0,a1 are used to pass parameters instead of
a0,a1,a2,a3.
This is because v0,v1,a0,a1 are the natural registers used to return
floating point values in soft float. These values can then be moved
to the appropriate floating point registers with no extra cost.
The only register that is modified is ra in this call.
The helper functions make sure that the return values are in the floating
point registers that they would be in if soft float was not in effect
(which it is for mips16, though the soft float is implemented using a mips32
library that uses hard float).
llvm-svn: 181641
2013-05-11 06:25:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return Modified;
|
|
|
|
}
|
|
|
|
|
2013-05-16 10:17:42 +08:00
|
|
|
static void createFPFnStub(Function *F, Module *M, FPParamVariant PV,
|
2015-01-06 09:12:30 +08:00
|
|
|
const MipsTargetMachine &TM) {
|
|
|
|
bool PicMode = TM.getRelocationModel() == Reloc::PIC_;
|
|
|
|
bool LE = TM.isLittleEndian();
|
2013-05-16 10:17:42 +08:00
|
|
|
LLVMContext &Context = M->getContext();
|
|
|
|
std::string Name = F->getName();
|
|
|
|
std::string SectionName = ".mips16.fn." + Name;
|
|
|
|
std::string StubName = "__fn_stub_" + Name;
|
2013-09-26 04:58:50 +08:00
|
|
|
std::string LocalName = "$$__fn_local_" + Name;
|
2013-05-16 10:17:42 +08:00
|
|
|
Function *FStub = Function::Create
|
|
|
|
(F->getFunctionType(),
|
2013-08-01 10:26:31 +08:00
|
|
|
Function::InternalLinkage, StubName, M);
|
2013-05-16 10:17:42 +08:00
|
|
|
FStub->addFnAttr("mips16_fp_stub");
|
|
|
|
FStub->addFnAttr(llvm::Attribute::Naked);
|
|
|
|
FStub->addFnAttr(llvm::Attribute::NoUnwind);
|
2013-08-01 10:26:31 +08:00
|
|
|
FStub->addFnAttr(llvm::Attribute::NoInline);
|
2013-05-16 10:17:42 +08:00
|
|
|
FStub->addFnAttr("nomips16");
|
|
|
|
FStub->setSection(SectionName);
|
|
|
|
BasicBlock *BB = BasicBlock::Create(Context, "entry", FStub);
|
2015-10-21 20:44:14 +08:00
|
|
|
|
|
|
|
std::string AsmText;
|
2013-05-16 10:17:42 +08:00
|
|
|
if (PicMode) {
|
2015-10-21 20:44:14 +08:00
|
|
|
AsmText += ".set noreorder\n";
|
|
|
|
AsmText += ".cpload $$25\n";
|
|
|
|
AsmText += ".set reorder\n";
|
|
|
|
AsmText += ".reloc 0, R_MIPS_NONE, " + Name + "\n";
|
|
|
|
AsmText += "la $$25, " + LocalName + "\n";
|
|
|
|
} else
|
|
|
|
AsmText += "la $$25, " + Name + "\n";
|
|
|
|
AsmText += swapFPIntParams(PV, M, LE, false);
|
|
|
|
AsmText += "jr $$25\n";
|
|
|
|
AsmText += LocalName + " = " + Name + "\n";
|
|
|
|
EmitInlineAsm(Context, BB, AsmText);
|
|
|
|
|
2013-05-16 10:17:42 +08:00
|
|
|
new UnreachableInst(FStub->getContext(), BB);
|
|
|
|
}
|
|
|
|
|
2013-08-31 03:40:56 +08:00
|
|
|
//
|
|
|
|
// remove the use-soft-float attribute
|
|
|
|
//
|
|
|
|
static void removeUseSoftFloat(Function &F) {
|
|
|
|
AttributeSet A;
|
|
|
|
DEBUG(errs() << "removing -use-soft-float\n");
|
|
|
|
A = A.addAttribute(F.getContext(), AttributeSet::FunctionIndex,
|
|
|
|
"use-soft-float", "false");
|
|
|
|
F.removeAttributes(AttributeSet::FunctionIndex, A);
|
|
|
|
if (F.hasFnAttribute("use-soft-float")) {
|
|
|
|
DEBUG(errs() << "still has -use-soft-float\n");
|
|
|
|
}
|
|
|
|
F.addAttributes(AttributeSet::FunctionIndex, A);
|
|
|
|
}
|
|
|
|
|
Checkin in of first of several patches to finish implementation of
mips16/mips32 floating point interoperability.
This patch fixes returns from mips16 functions so that if the function
was in fact called by a mips32 hard float routine, then values
that would have been returned in floating point registers are so returned.
Mips16 mode has no floating point instructions so there is no way to
load values into floating point registers.
This is needed when returning float, double, single complex, double complex
in the Mips ABI.
Helper functions in libc for mips16 are available to do this.
For efficiency purposes, these helper functions have a different calling
convention from normal Mips calls.
Registers v0,v1,a0,a1 are used to pass parameters instead of
a0,a1,a2,a3.
This is because v0,v1,a0,a1 are the natural registers used to return
floating point values in soft float. These values can then be moved
to the appropriate floating point registers with no extra cost.
The only register that is modified is ra in this call.
The helper functions make sure that the return values are in the floating
point registers that they would be in if soft float was not in effect
(which it is for mips16, though the soft float is implemented using a mips32
library that uses hard float).
llvm-svn: 181641
2013-05-11 06:25:39 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// 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.
|
2014-02-15 03:16:39 +08:00
|
|
|
// 2) generate helper functions (stubs) that can be called by mips32
|
|
|
|
// functions that will move parameters passed normally passed in
|
|
|
|
// floating point
|
2013-05-16 10:17:42 +08:00
|
|
|
// registers the soft float equivalents.
|
Checkin in of first of several patches to finish implementation of
mips16/mips32 floating point interoperability.
This patch fixes returns from mips16 functions so that if the function
was in fact called by a mips32 hard float routine, then values
that would have been returned in floating point registers are so returned.
Mips16 mode has no floating point instructions so there is no way to
load values into floating point registers.
This is needed when returning float, double, single complex, double complex
in the Mips ABI.
Helper functions in libc for mips16 are available to do this.
For efficiency purposes, these helper functions have a different calling
convention from normal Mips calls.
Registers v0,v1,a0,a1 are used to pass parameters instead of
a0,a1,a2,a3.
This is because v0,v1,a0,a1 are the natural registers used to return
floating point values in soft float. These values can then be moved
to the appropriate floating point registers with no extra cost.
The only register that is modified is ra in this call.
The helper functions make sure that the return values are in the floating
point registers that they would be in if soft float was not in effect
(which it is for mips16, though the soft float is implemented using a mips32
library that uses hard float).
llvm-svn: 181641
2013-05-11 06:25:39 +08:00
|
|
|
// 3) in the case of static relocation, generate helper functions so that
|
|
|
|
// mips16 functions can call extern functions of unknown type (mips16 or
|
2013-05-16 10:17:42 +08:00
|
|
|
// mips32).
|
Checkin in of first of several patches to finish implementation of
mips16/mips32 floating point interoperability.
This patch fixes returns from mips16 functions so that if the function
was in fact called by a mips32 hard float routine, then values
that would have been returned in floating point registers are so returned.
Mips16 mode has no floating point instructions so there is no way to
load values into floating point registers.
This is needed when returning float, double, single complex, double complex
in the Mips ABI.
Helper functions in libc for mips16 are available to do this.
For efficiency purposes, these helper functions have a different calling
convention from normal Mips calls.
Registers v0,v1,a0,a1 are used to pass parameters instead of
a0,a1,a2,a3.
This is because v0,v1,a0,a1 are the natural registers used to return
floating point values in soft float. These values can then be moved
to the appropriate floating point registers with no extra cost.
The only register that is modified is ra in this call.
The helper functions make sure that the return values are in the floating
point registers that they would be in if soft float was not in effect
(which it is for mips16, though the soft float is implemented using a mips32
library that uses hard float).
llvm-svn: 181641
2013-05-11 06:25:39 +08:00
|
|
|
// 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) {
|
2013-08-31 03:40:56 +08:00
|
|
|
if (F->hasFnAttribute("nomips16") &&
|
|
|
|
F->hasFnAttribute("use-soft-float")) {
|
|
|
|
removeUseSoftFloat(*F);
|
|
|
|
continue;
|
|
|
|
}
|
Checkin in of first of several patches to finish implementation of
mips16/mips32 floating point interoperability.
This patch fixes returns from mips16 functions so that if the function
was in fact called by a mips32 hard float routine, then values
that would have been returned in floating point registers are so returned.
Mips16 mode has no floating point instructions so there is no way to
load values into floating point registers.
This is needed when returning float, double, single complex, double complex
in the Mips ABI.
Helper functions in libc for mips16 are available to do this.
For efficiency purposes, these helper functions have a different calling
convention from normal Mips calls.
Registers v0,v1,a0,a1 are used to pass parameters instead of
a0,a1,a2,a3.
This is because v0,v1,a0,a1 are the natural registers used to return
floating point values in soft float. These values can then be moved
to the appropriate floating point registers with no extra cost.
The only register that is modified is ra in this call.
The helper functions make sure that the return values are in the floating
point registers that they would be in if soft float was not in effect
(which it is for mips16, though the soft float is implemented using a mips32
library that uses hard float).
llvm-svn: 181641
2013-05-11 06:25:39 +08:00
|
|
|
if (F->isDeclaration() || F->hasFnAttribute("mips16_fp_stub") ||
|
|
|
|
F->hasFnAttribute("nomips16")) continue;
|
2015-01-06 09:12:30 +08:00
|
|
|
Modified |= fixupFPReturnAndCall(*F, &M, TM);
|
2013-05-16 10:17:42 +08:00
|
|
|
FPParamVariant V = whichFPParamVariantNeeded(*F);
|
|
|
|
if (V != NoSig) {
|
|
|
|
Modified = true;
|
2015-10-20 08:15:20 +08:00
|
|
|
createFPFnStub(&*F, &M, V, TM);
|
2013-05-16 10:17:42 +08:00
|
|
|
}
|
Checkin in of first of several patches to finish implementation of
mips16/mips32 floating point interoperability.
This patch fixes returns from mips16 functions so that if the function
was in fact called by a mips32 hard float routine, then values
that would have been returned in floating point registers are so returned.
Mips16 mode has no floating point instructions so there is no way to
load values into floating point registers.
This is needed when returning float, double, single complex, double complex
in the Mips ABI.
Helper functions in libc for mips16 are available to do this.
For efficiency purposes, these helper functions have a different calling
convention from normal Mips calls.
Registers v0,v1,a0,a1 are used to pass parameters instead of
a0,a1,a2,a3.
This is because v0,v1,a0,a1 are the natural registers used to return
floating point values in soft float. These values can then be moved
to the appropriate floating point registers with no extra cost.
The only register that is modified is ra in this call.
The helper functions make sure that the return values are in the floating
point registers that they would be in if soft float was not in effect
(which it is for mips16, though the soft float is implemented using a mips32
library that uses hard float).
llvm-svn: 181641
2013-05-11 06:25:39 +08:00
|
|
|
}
|
|
|
|
return Modified;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-14 17:02:23 +08:00
|
|
|
ModulePass *llvm::createMips16HardFloatPass(MipsTargetMachine &TM) {
|
Checkin in of first of several patches to finish implementation of
mips16/mips32 floating point interoperability.
This patch fixes returns from mips16 functions so that if the function
was in fact called by a mips32 hard float routine, then values
that would have been returned in floating point registers are so returned.
Mips16 mode has no floating point instructions so there is no way to
load values into floating point registers.
This is needed when returning float, double, single complex, double complex
in the Mips ABI.
Helper functions in libc for mips16 are available to do this.
For efficiency purposes, these helper functions have a different calling
convention from normal Mips calls.
Registers v0,v1,a0,a1 are used to pass parameters instead of
a0,a1,a2,a3.
This is because v0,v1,a0,a1 are the natural registers used to return
floating point values in soft float. These values can then be moved
to the appropriate floating point registers with no extra cost.
The only register that is modified is ra in this call.
The helper functions make sure that the return values are in the floating
point registers that they would be in if soft float was not in effect
(which it is for mips16, though the soft float is implemented using a mips32
library that uses hard float).
llvm-svn: 181641
2013-05-11 06:25:39 +08:00
|
|
|
return new Mips16HardFloat(TM);
|
|
|
|
}
|