2012-02-18 12:03:15 +00:00
|
|
|
//=== ARMCallingConv.h - ARM Custom Calling Convention Routines -*- C++ -*-===//
|
2010-09-10 22:42:06 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the custom routines for the ARM Calling Convention that
|
|
|
|
// aren't done by tablegen.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef ARMCALLINGCONV_H
|
|
|
|
#define ARMCALLINGCONV_H
|
|
|
|
|
2012-03-17 07:33:42 +00:00
|
|
|
#include "ARM.h"
|
2010-09-10 22:42:06 +00:00
|
|
|
#include "ARMBaseInstrInfo.h"
|
|
|
|
#include "ARMSubtarget.h"
|
2012-03-17 07:33:42 +00:00
|
|
|
#include "llvm/CodeGen/CallingConvLower.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/CallingConv.h"
|
2012-03-17 07:33:42 +00:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2010-09-10 22:42:06 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
// APCS f64 is in register pairs, possibly split to stack
|
2010-11-04 10:49:57 +00:00
|
|
|
static bool f64AssignAPCS(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
|
2010-09-10 22:42:06 +00:00
|
|
|
CCValAssign::LocInfo &LocInfo,
|
|
|
|
CCState &State, bool CanFail) {
|
2012-03-11 07:57:25 +00:00
|
|
|
static const uint16_t RegList[] = { ARM::R0, ARM::R1, ARM::R2, ARM::R3 };
|
2010-09-10 22:42:06 +00:00
|
|
|
|
|
|
|
// Try to get the first register.
|
|
|
|
if (unsigned Reg = State.AllocateReg(RegList, 4))
|
|
|
|
State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
|
|
|
|
else {
|
|
|
|
// For the 2nd half of a v2f64, do not fail.
|
|
|
|
if (CanFail)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Put the whole thing on the stack.
|
|
|
|
State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT,
|
|
|
|
State.AllocateStack(8, 4),
|
|
|
|
LocVT, LocInfo));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to get the second register.
|
|
|
|
if (unsigned Reg = State.AllocateReg(RegList, 4))
|
|
|
|
State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
|
|
|
|
else
|
|
|
|
State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT,
|
|
|
|
State.AllocateStack(4, 4),
|
|
|
|
LocVT, LocInfo));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-04 10:49:57 +00:00
|
|
|
static bool CC_ARM_APCS_Custom_f64(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
|
2010-09-10 22:42:06 +00:00
|
|
|
CCValAssign::LocInfo &LocInfo,
|
|
|
|
ISD::ArgFlagsTy &ArgFlags,
|
|
|
|
CCState &State) {
|
|
|
|
if (!f64AssignAPCS(ValNo, ValVT, LocVT, LocInfo, State, true))
|
|
|
|
return false;
|
|
|
|
if (LocVT == MVT::v2f64 &&
|
|
|
|
!f64AssignAPCS(ValNo, ValVT, LocVT, LocInfo, State, false))
|
|
|
|
return false;
|
|
|
|
return true; // we handled it
|
|
|
|
}
|
|
|
|
|
|
|
|
// AAPCS f64 is in aligned register pairs
|
2010-11-04 10:49:57 +00:00
|
|
|
static bool f64AssignAAPCS(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
|
2010-09-10 22:42:06 +00:00
|
|
|
CCValAssign::LocInfo &LocInfo,
|
|
|
|
CCState &State, bool CanFail) {
|
2012-03-11 07:57:25 +00:00
|
|
|
static const uint16_t HiRegList[] = { ARM::R0, ARM::R2 };
|
|
|
|
static const uint16_t LoRegList[] = { ARM::R1, ARM::R3 };
|
|
|
|
static const uint16_t ShadowRegList[] = { ARM::R0, ARM::R1 };
|
2013-04-22 13:06:52 +00:00
|
|
|
static const uint16_t GPRArgRegs[] = { ARM::R0, ARM::R1, ARM::R2, ARM::R3 };
|
2010-09-10 22:42:06 +00:00
|
|
|
|
|
|
|
unsigned Reg = State.AllocateReg(HiRegList, ShadowRegList, 2);
|
|
|
|
if (Reg == 0) {
|
2013-04-22 13:06:52 +00:00
|
|
|
|
|
|
|
// If we had R3 unallocated only, now we still must to waste it.
|
|
|
|
Reg = State.AllocateReg(GPRArgRegs, 4);
|
|
|
|
assert((!Reg || Reg == ARM::R3) && "Wrong GPRs usage for f64");
|
|
|
|
|
2010-09-10 22:42:06 +00:00
|
|
|
// For the 2nd half of a v2f64, do not just fail.
|
|
|
|
if (CanFail)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Put the whole thing on the stack.
|
|
|
|
State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT,
|
|
|
|
State.AllocateStack(8, 8),
|
|
|
|
LocVT, LocInfo));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i < 2; ++i)
|
|
|
|
if (HiRegList[i] == Reg)
|
|
|
|
break;
|
|
|
|
|
|
|
|
unsigned T = State.AllocateReg(LoRegList[i]);
|
|
|
|
(void)T;
|
|
|
|
assert(T == LoRegList[i] && "Could not allocate register");
|
|
|
|
|
|
|
|
State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
|
|
|
|
State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, LoRegList[i],
|
|
|
|
LocVT, LocInfo));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-04 10:49:57 +00:00
|
|
|
static bool CC_ARM_AAPCS_Custom_f64(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
|
2010-09-10 22:42:06 +00:00
|
|
|
CCValAssign::LocInfo &LocInfo,
|
|
|
|
ISD::ArgFlagsTy &ArgFlags,
|
|
|
|
CCState &State) {
|
|
|
|
if (!f64AssignAAPCS(ValNo, ValVT, LocVT, LocInfo, State, true))
|
|
|
|
return false;
|
|
|
|
if (LocVT == MVT::v2f64 &&
|
|
|
|
!f64AssignAAPCS(ValNo, ValVT, LocVT, LocInfo, State, false))
|
|
|
|
return false;
|
|
|
|
return true; // we handled it
|
|
|
|
}
|
|
|
|
|
2010-11-04 10:49:57 +00:00
|
|
|
static bool f64RetAssign(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
|
2010-09-10 22:42:06 +00:00
|
|
|
CCValAssign::LocInfo &LocInfo, CCState &State) {
|
2012-03-11 07:57:25 +00:00
|
|
|
static const uint16_t HiRegList[] = { ARM::R0, ARM::R2 };
|
|
|
|
static const uint16_t LoRegList[] = { ARM::R1, ARM::R3 };
|
2010-09-10 22:42:06 +00:00
|
|
|
|
|
|
|
unsigned Reg = State.AllocateReg(HiRegList, LoRegList, 2);
|
|
|
|
if (Reg == 0)
|
|
|
|
return false; // we didn't handle it
|
|
|
|
|
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i < 2; ++i)
|
|
|
|
if (HiRegList[i] == Reg)
|
|
|
|
break;
|
|
|
|
|
|
|
|
State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
|
|
|
|
State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, LoRegList[i],
|
|
|
|
LocVT, LocInfo));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-04 10:49:57 +00:00
|
|
|
static bool RetCC_ARM_APCS_Custom_f64(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
|
2010-09-10 22:42:06 +00:00
|
|
|
CCValAssign::LocInfo &LocInfo,
|
|
|
|
ISD::ArgFlagsTy &ArgFlags,
|
|
|
|
CCState &State) {
|
|
|
|
if (!f64RetAssign(ValNo, ValVT, LocVT, LocInfo, State))
|
|
|
|
return false;
|
|
|
|
if (LocVT == MVT::v2f64 && !f64RetAssign(ValNo, ValVT, LocVT, LocInfo, State))
|
|
|
|
return false;
|
|
|
|
return true; // we handled it
|
|
|
|
}
|
|
|
|
|
2010-11-04 10:49:57 +00:00
|
|
|
static bool RetCC_ARM_AAPCS_Custom_f64(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
|
2010-09-10 22:42:06 +00:00
|
|
|
CCValAssign::LocInfo &LocInfo,
|
|
|
|
ISD::ArgFlagsTy &ArgFlags,
|
|
|
|
CCState &State) {
|
|
|
|
return RetCC_ARM_APCS_Custom_f64(ValNo, ValVT, LocVT, LocInfo, ArgFlags,
|
|
|
|
State);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
2010-09-10 22:46:03 +00:00
|
|
|
#endif
|