2007-02-27 04:43:02 +00:00
|
|
|
//===-- llvm/CallingConvLower.h - Calling Conventions -----------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-02-27 04:43:02 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file declares the CCState and CCValAssign classes, used for lowering
|
|
|
|
// and implementing calling conventions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_CALLINGCONVLOWER_H
|
|
|
|
#define LLVM_CODEGEN_CALLINGCONVLOWER_H
|
|
|
|
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/CodeGen/ValueTypes.h"
|
2008-03-10 02:17:22 +00:00
|
|
|
#include "llvm/CodeGen/SelectionDAGNodes.h"
|
2007-02-27 04:43:02 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2008-02-10 18:45:23 +00:00
|
|
|
class TargetRegisterInfo;
|
2007-02-27 05:13:54 +00:00
|
|
|
class TargetMachine;
|
2007-02-28 06:56:37 +00:00
|
|
|
class CCState;
|
|
|
|
class SDNode;
|
|
|
|
|
2007-02-27 04:43:02 +00:00
|
|
|
/// CCValAssign - Represent assignment of one arg/retval to a location.
|
|
|
|
class CCValAssign {
|
|
|
|
public:
|
|
|
|
enum LocInfo {
|
|
|
|
Full, // The value fills the full location.
|
|
|
|
SExt, // The value is sign extended in the location.
|
|
|
|
ZExt, // The value is zero extended in the location.
|
2009-04-17 19:07:39 +00:00
|
|
|
AExt, // The value is extended with undefined upper bits.
|
2009-04-17 20:35:10 +00:00
|
|
|
BCvt // The value is bit-converted in the location.
|
2007-02-27 04:43:02 +00:00
|
|
|
// TODO: a subset of the value is in the location.
|
|
|
|
};
|
|
|
|
private:
|
|
|
|
/// ValNo - This is the value number begin assigned (e.g. an argument number).
|
|
|
|
unsigned ValNo;
|
|
|
|
|
|
|
|
/// Loc is either a stack offset or a register number.
|
|
|
|
unsigned Loc;
|
|
|
|
|
|
|
|
/// isMem - True if this is a memory loc, false if it is a register loc.
|
|
|
|
bool isMem : 1;
|
|
|
|
|
2009-04-17 20:35:10 +00:00
|
|
|
/// isCustom - True if this arg/retval requires special handling.
|
2009-04-17 19:07:39 +00:00
|
|
|
bool isCustom : 1;
|
2009-04-17 20:35:10 +00:00
|
|
|
|
2007-02-27 04:43:02 +00:00
|
|
|
/// Information about how the value is assigned.
|
2009-04-17 19:07:39 +00:00
|
|
|
LocInfo HTP : 6;
|
2007-02-27 04:43:02 +00:00
|
|
|
|
|
|
|
/// ValVT - The type of the value being assigned.
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT ValVT;
|
2007-02-27 04:43:02 +00:00
|
|
|
|
|
|
|
/// LocVT - The type of the location being assigned to.
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT LocVT;
|
2007-02-27 04:43:02 +00:00
|
|
|
public:
|
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
static CCValAssign getReg(unsigned ValNo, MVT ValVT,
|
|
|
|
unsigned RegNo, MVT LocVT,
|
2007-02-27 04:43:02 +00:00
|
|
|
LocInfo HTP) {
|
|
|
|
CCValAssign Ret;
|
|
|
|
Ret.ValNo = ValNo;
|
|
|
|
Ret.Loc = RegNo;
|
|
|
|
Ret.isMem = false;
|
2009-04-17 19:07:39 +00:00
|
|
|
Ret.isCustom = false;
|
2007-02-27 04:43:02 +00:00
|
|
|
Ret.HTP = HTP;
|
|
|
|
Ret.ValVT = ValVT;
|
|
|
|
Ret.LocVT = LocVT;
|
|
|
|
return Ret;
|
|
|
|
}
|
2009-04-17 20:35:10 +00:00
|
|
|
|
2009-04-17 19:07:39 +00:00
|
|
|
static CCValAssign getCustomReg(unsigned ValNo, MVT ValVT,
|
|
|
|
unsigned RegNo, MVT LocVT,
|
|
|
|
LocInfo HTP) {
|
|
|
|
CCValAssign Ret;
|
|
|
|
Ret = getReg(ValNo, ValVT, RegNo, LocVT, HTP);
|
|
|
|
Ret.isCustom = true;
|
|
|
|
return Ret;
|
|
|
|
}
|
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
static CCValAssign getMem(unsigned ValNo, MVT ValVT,
|
|
|
|
unsigned Offset, MVT LocVT,
|
2007-02-27 04:43:02 +00:00
|
|
|
LocInfo HTP) {
|
|
|
|
CCValAssign Ret;
|
|
|
|
Ret.ValNo = ValNo;
|
|
|
|
Ret.Loc = Offset;
|
|
|
|
Ret.isMem = true;
|
2009-04-17 19:07:39 +00:00
|
|
|
Ret.isCustom = false;
|
2007-02-27 04:43:02 +00:00
|
|
|
Ret.HTP = HTP;
|
|
|
|
Ret.ValVT = ValVT;
|
|
|
|
Ret.LocVT = LocVT;
|
|
|
|
return Ret;
|
|
|
|
}
|
|
|
|
|
2009-04-17 19:07:39 +00:00
|
|
|
static CCValAssign getCustomMem(unsigned ValNo, MVT ValVT,
|
|
|
|
unsigned Offset, MVT LocVT,
|
|
|
|
LocInfo HTP) {
|
|
|
|
CCValAssign Ret;
|
|
|
|
Ret = getMem(ValNo, ValVT, Offset, LocVT, HTP);
|
|
|
|
Ret.isCustom = true;
|
|
|
|
return Ret;
|
|
|
|
}
|
2009-04-17 20:35:10 +00:00
|
|
|
|
2007-02-27 04:43:02 +00:00
|
|
|
unsigned getValNo() const { return ValNo; }
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT getValVT() const { return ValVT; }
|
2007-02-27 04:43:02 +00:00
|
|
|
|
|
|
|
bool isRegLoc() const { return !isMem; }
|
|
|
|
bool isMemLoc() const { return isMem; }
|
|
|
|
|
2009-04-17 19:07:39 +00:00
|
|
|
bool needsCustom() const { return isCustom; }
|
2009-04-17 20:35:10 +00:00
|
|
|
|
2007-02-27 04:43:02 +00:00
|
|
|
unsigned getLocReg() const { assert(isRegLoc()); return Loc; }
|
|
|
|
unsigned getLocMemOffset() const { assert(isMemLoc()); return Loc; }
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT getLocVT() const { return LocVT; }
|
2007-02-27 04:43:02 +00:00
|
|
|
|
|
|
|
LocInfo getLocInfo() const { return HTP; }
|
|
|
|
};
|
|
|
|
|
2007-02-28 06:56:37 +00:00
|
|
|
/// CCAssignFn - This function assigns a location for Val, updating State to
|
|
|
|
/// reflect the change.
|
2008-06-06 12:08:01 +00:00
|
|
|
typedef bool CCAssignFn(unsigned ValNo, MVT ValVT,
|
|
|
|
MVT LocVT, CCValAssign::LocInfo LocInfo,
|
2008-03-21 09:14:45 +00:00
|
|
|
ISD::ArgFlagsTy ArgFlags, CCState &State);
|
2007-02-28 06:56:37 +00:00
|
|
|
|
2009-04-17 19:07:39 +00:00
|
|
|
/// CCCustomFn - This function assigns a location for Val, possibly updating
|
|
|
|
/// all args to reflect changes and indicates if it handled it. It must set
|
|
|
|
/// isCustom if it handles the arg and returns true.
|
|
|
|
typedef bool CCCustomFn(unsigned &ValNo, MVT &ValVT,
|
|
|
|
MVT &LocVT, CCValAssign::LocInfo &LocInfo,
|
|
|
|
ISD::ArgFlagsTy &ArgFlags, CCState &State);
|
|
|
|
|
2007-02-27 05:13:54 +00:00
|
|
|
/// CCState - This class holds information needed while lowering arguments and
|
|
|
|
/// return values. It captures which registers are already assigned and which
|
|
|
|
/// stack slots are used. It provides accessors to allocate these values.
|
|
|
|
class CCState {
|
|
|
|
unsigned CallingConv;
|
2007-06-19 00:10:25 +00:00
|
|
|
bool IsVarArg;
|
2007-02-27 05:13:54 +00:00
|
|
|
const TargetMachine &TM;
|
2008-02-10 18:45:23 +00:00
|
|
|
const TargetRegisterInfo &TRI;
|
2007-02-27 05:13:54 +00:00
|
|
|
SmallVector<CCValAssign, 16> &Locs;
|
2009-07-09 17:57:24 +00:00
|
|
|
LLVMContext *Context;
|
2007-02-27 05:13:54 +00:00
|
|
|
|
|
|
|
unsigned StackOffset;
|
|
|
|
SmallVector<uint32_t, 16> UsedRegs;
|
|
|
|
public:
|
2007-06-19 00:10:25 +00:00
|
|
|
CCState(unsigned CC, bool isVarArg, const TargetMachine &TM,
|
2009-07-09 17:57:24 +00:00
|
|
|
SmallVector<CCValAssign, 16> &locs, LLVMContext *C);
|
2007-02-27 05:13:54 +00:00
|
|
|
|
|
|
|
void addLoc(const CCValAssign &V) {
|
|
|
|
Locs.push_back(V);
|
|
|
|
}
|
|
|
|
|
2009-07-09 17:57:24 +00:00
|
|
|
LLVMContext *getContext() const { return Context; }
|
2007-02-27 05:13:54 +00:00
|
|
|
const TargetMachine &getTarget() const { return TM; }
|
|
|
|
unsigned getCallingConv() const { return CallingConv; }
|
2007-06-19 00:10:25 +00:00
|
|
|
bool isVarArg() const { return IsVarArg; }
|
2007-02-27 05:13:54 +00:00
|
|
|
|
|
|
|
unsigned getNextStackOffset() const { return StackOffset; }
|
|
|
|
|
|
|
|
/// isAllocated - Return true if the specified register (or an alias) is
|
|
|
|
/// allocated.
|
|
|
|
bool isAllocated(unsigned Reg) const {
|
|
|
|
return UsedRegs[Reg/32] & (1 << (Reg&31));
|
|
|
|
}
|
2007-02-28 06:56:37 +00:00
|
|
|
|
2007-02-28 07:09:40 +00:00
|
|
|
/// AnalyzeFormalArguments - Analyze an ISD::FORMAL_ARGUMENTS node,
|
|
|
|
/// incorporating info about the formals into this state.
|
|
|
|
void AnalyzeFormalArguments(SDNode *TheArgs, CCAssignFn Fn);
|
|
|
|
|
|
|
|
/// AnalyzeReturn - Analyze the returned values of an ISD::RET node,
|
|
|
|
/// incorporating info about the result values into this state.
|
|
|
|
void AnalyzeReturn(SDNode *TheRet, CCAssignFn Fn);
|
|
|
|
|
2007-02-28 06:56:37 +00:00
|
|
|
/// AnalyzeCallOperands - Analyze an ISD::CALL node, incorporating info
|
|
|
|
/// about the passed values into this state.
|
2008-09-13 01:54:27 +00:00
|
|
|
void AnalyzeCallOperands(CallSDNode *TheCall, CCAssignFn Fn);
|
2007-02-28 06:56:37 +00:00
|
|
|
|
2008-09-05 16:59:26 +00:00
|
|
|
/// AnalyzeCallOperands - Same as above except it takes vectors of types
|
|
|
|
/// and argument flags.
|
2008-09-07 09:02:18 +00:00
|
|
|
void AnalyzeCallOperands(SmallVectorImpl<MVT> &ArgVTs,
|
2008-09-05 16:59:26 +00:00
|
|
|
SmallVectorImpl<ISD::ArgFlagsTy> &Flags,
|
|
|
|
CCAssignFn Fn);
|
|
|
|
|
2007-02-28 07:09:40 +00:00
|
|
|
/// AnalyzeCallResult - Analyze the return values of an ISD::CALL node,
|
|
|
|
/// incorporating info about the passed values into this state.
|
2008-09-13 01:54:27 +00:00
|
|
|
void AnalyzeCallResult(CallSDNode *TheCall, CCAssignFn Fn);
|
2007-02-28 06:56:37 +00:00
|
|
|
|
2008-09-07 09:02:18 +00:00
|
|
|
/// AnalyzeCallResult - Same as above except it's specialized for calls which
|
|
|
|
/// produce a single value.
|
|
|
|
void AnalyzeCallResult(MVT VT, CCAssignFn Fn);
|
2007-02-27 05:13:54 +00:00
|
|
|
|
|
|
|
/// getFirstUnallocated - Return the first unallocated register in the set, or
|
|
|
|
/// NumRegs if they are all allocated.
|
|
|
|
unsigned getFirstUnallocated(const unsigned *Regs, unsigned NumRegs) const {
|
|
|
|
for (unsigned i = 0; i != NumRegs; ++i)
|
|
|
|
if (!isAllocated(Regs[i]))
|
|
|
|
return i;
|
|
|
|
return NumRegs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// AllocateReg - Attempt to allocate one register. If it is not available,
|
|
|
|
/// return zero. Otherwise, return the register, marking it and any aliases
|
|
|
|
/// as allocated.
|
|
|
|
unsigned AllocateReg(unsigned Reg) {
|
|
|
|
if (isAllocated(Reg)) return 0;
|
|
|
|
MarkAllocated(Reg);
|
|
|
|
return Reg;
|
|
|
|
}
|
2008-04-02 05:23:57 +00:00
|
|
|
|
|
|
|
/// Version of AllocateReg with extra register to be shadowed.
|
|
|
|
unsigned AllocateReg(unsigned Reg, unsigned ShadowReg) {
|
|
|
|
if (isAllocated(Reg)) return 0;
|
|
|
|
MarkAllocated(Reg);
|
|
|
|
MarkAllocated(ShadowReg);
|
|
|
|
return Reg;
|
|
|
|
}
|
|
|
|
|
2007-02-27 05:13:54 +00:00
|
|
|
/// AllocateReg - Attempt to allocate one of the specified registers. If none
|
|
|
|
/// are available, return zero. Otherwise, return the first one available,
|
|
|
|
/// marking it and any aliases as allocated.
|
|
|
|
unsigned AllocateReg(const unsigned *Regs, unsigned NumRegs) {
|
|
|
|
unsigned FirstUnalloc = getFirstUnallocated(Regs, NumRegs);
|
|
|
|
if (FirstUnalloc == NumRegs)
|
|
|
|
return 0; // Didn't find the reg.
|
2008-04-02 05:23:57 +00:00
|
|
|
|
2007-02-27 05:13:54 +00:00
|
|
|
// Mark the register and any aliases as allocated.
|
|
|
|
unsigned Reg = Regs[FirstUnalloc];
|
|
|
|
MarkAllocated(Reg);
|
|
|
|
return Reg;
|
|
|
|
}
|
2008-04-02 05:23:57 +00:00
|
|
|
|
|
|
|
/// Version of AllocateReg with list of registers to be shadowed.
|
|
|
|
unsigned AllocateReg(const unsigned *Regs, const unsigned *ShadowRegs,
|
|
|
|
unsigned NumRegs) {
|
|
|
|
unsigned FirstUnalloc = getFirstUnallocated(Regs, NumRegs);
|
|
|
|
if (FirstUnalloc == NumRegs)
|
|
|
|
return 0; // Didn't find the reg.
|
|
|
|
|
|
|
|
// Mark the register and any aliases as allocated.
|
|
|
|
unsigned Reg = Regs[FirstUnalloc], ShadowReg = ShadowRegs[FirstUnalloc];
|
|
|
|
MarkAllocated(Reg);
|
|
|
|
MarkAllocated(ShadowReg);
|
|
|
|
return Reg;
|
|
|
|
}
|
|
|
|
|
2007-02-27 05:13:54 +00:00
|
|
|
/// AllocateStack - Allocate a chunk of stack space with the specified size
|
|
|
|
/// and alignment.
|
|
|
|
unsigned AllocateStack(unsigned Size, unsigned Align) {
|
|
|
|
assert(Align && ((Align-1) & Align) == 0); // Align is power of 2.
|
|
|
|
StackOffset = ((StackOffset + Align-1) & ~(Align-1));
|
|
|
|
unsigned Result = StackOffset;
|
|
|
|
StackOffset += Size;
|
|
|
|
return Result;
|
|
|
|
}
|
2007-08-10 14:44:42 +00:00
|
|
|
|
2008-01-15 07:49:54 +00:00
|
|
|
// HandleByVal - Allocate a stack slot large enough to pass an argument by
|
|
|
|
// value. The size and alignment information of the argument is encoded in its
|
|
|
|
// parameter attribute.
|
2008-06-06 12:08:01 +00:00
|
|
|
void HandleByVal(unsigned ValNo, MVT ValVT,
|
|
|
|
MVT LocVT, CCValAssign::LocInfo LocInfo,
|
2008-03-21 09:14:45 +00:00
|
|
|
int MinSize, int MinAlign, ISD::ArgFlagsTy ArgFlags);
|
2008-01-15 07:49:54 +00:00
|
|
|
|
2007-02-27 05:13:54 +00:00
|
|
|
private:
|
|
|
|
/// MarkAllocated - Mark a register and all of its aliases as allocated.
|
|
|
|
void MarkAllocated(unsigned Reg);
|
|
|
|
};
|
|
|
|
|
2007-02-28 06:56:37 +00:00
|
|
|
|
|
|
|
|
2007-02-27 04:43:02 +00:00
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|