public abstract class CallingConvention extends IRTools
TODO: Much of this code could still be factored out as architecture-independent.
Modifier and Type | Field and Description |
---|---|
private static int |
WORDSIZE
Size of a word, in bytes
|
private static TypeReference |
wordType |
Constructor and Description |
---|
CallingConvention() |
Modifier and Type | Method and Description |
---|---|
static void |
allocateSpaceForSysCall(IR ir)
We have to save/restore the non-volatile registers around syscalls,
to protect ourselves from malicious C compilers and Linux kernels.
|
private static void |
callExpand(Instruction call,
IR ir)
Expands the calling convention for a particular call instruction.
|
private static int |
countFPRParams(Instruction call) |
private static int |
countFPRParamsInPrologue(Instruction p) |
static void |
expandCallingConventions(IR ir)
Expands calling conventions to make physical registers explicit in the
IR when required for calls, returns, and the prologue.
|
private static int |
expandParametersToCall(Instruction call,
IR ir)
Explicitly copy parameters to a call into the appropriate physical
registers as defined by the calling convention.
|
private static int |
expandParametersToSysCall(Instruction call,
IR ir)
Explicitly copy parameters to a system call into the appropriate physical
registers as defined by the calling convention.
|
private static void |
expandPrologue(IR ir) |
private static void |
expandResultOfCall(Instruction call,
boolean isSysCall,
IR ir)
Explicitly copy the result of a call instruction from the result
register to the appropriate symbolic register,
as defined by the calling convention.
|
static void |
expandSysCall(Instruction s,
IR ir)
Calling convention to implement calls to native (C) routines
using the Linux linkage conventions.
|
private static boolean |
paramIsNativeLongOn64Bit(Operand param) |
(package private) static void |
restoreNonvolatilesAfterSysCall(Instruction call,
IR ir)
Restore all nonvolatile registers after a syscall.
|
private static void |
returnExpand(Instruction ret,
IR ir)
Expands the calling convention for a particular return instruction.
|
static void |
saveNonvolatilesAroundSysCall(Instruction call,
IR ir)
Save and restore all nonvolatile registers around a syscall.
|
(package private) static void |
saveNonvolatilesBeforeSysCall(Instruction call,
IR ir)
Save all nonvolatile registers before a syscall.
|
A, AC, AC, CPOS, CR, D, DC, defDoublesAsUse, definedIn, F, FC, getCondMoveOp, getDefaultOperand, getLoadOp, getLoadOp, getMoveOp, getStoreOp, getStoreOp, I, IC, insertInstructionsAfter, L, LC, makeBlockOnEdge, mayBeVolatileFieldLoad, moveInstruction, moveIntoRegister, moveIntoRegister, nonPEIGC, offsetOperand, TG, usedIn, useDoublesAsDef
private static final int WORDSIZE
private static final TypeReference wordType
public CallingConvention()
public static void expandCallingConventions(IR ir)
ir
- the governing IRprivate static void callExpand(Instruction call, IR ir)
call
- the call instructionir
- the IR that contains the call instructionprivate static void returnExpand(Instruction ret, IR ir)
ret
- the return instructionir
- the IR that contains the return instructionprivate static void expandResultOfCall(Instruction call, boolean isSysCall, IR ir)
call
- the call instructionisSysCall
- whether the call is a SysCallir
- the IR that contains the callprivate static int expandParametersToCall(Instruction call, IR ir)
Note: Assumes that ESP points to the word before the slot where the first parameter should be stored.
call
- the call instructionir
- the IR that contains the callprivate static boolean paramIsNativeLongOn64Bit(Operand param)
public static void saveNonvolatilesAroundSysCall(Instruction call, IR ir)
We save/restore all nonvolatiles and the PR, whether or not this routine uses them. This may be a tad inefficient, but if you're making a system call, you probably don't care.
Side effect: changes the operator of the call instruction to IA32_CALL.
call
- the sys callir
- the IR that contains the callstatic void saveNonvolatilesBeforeSysCall(Instruction call, IR ir)
We save/restore all nonvolatiles and the PR, whether or not this routine uses them. This may be a tad inefficient, but if you're making a system call, you probably don't care.
call
- the sys callir
- the IR that contains the callstatic void restoreNonvolatilesAfterSysCall(Instruction call, IR ir)
We save/restore all nonvolatiles and the PR, whether or not this routine uses them. This may be a tad inefficient, but if you're making a system call, you probably don't care.
call
- the sys callir
- the IR that contains the callprivate static int expandParametersToSysCall(Instruction call, IR ir)
Note: Assumes that ESP points to the word before the slot where the first parameter should be stored.
TODO: much of this code is exactly the same as in expandParametersToCall(). factor out the common code.
call
- the call instructionir
- the IR that contains the callpublic static void allocateSpaceForSysCall(IR ir)
Although the register allocator is not yet ready to insert these spills, allocate space on the stack in preparation.
For now, we naively save/restore all nonvolatiles.
ir
- the governing IRpublic static void expandSysCall(Instruction s, IR ir)
s
- the call instructionir
- the IR that contains the callprivate static int countFPRParams(Instruction call)
private static int countFPRParamsInPrologue(Instruction p)
private static void expandPrologue(IR ir)