dmd.backend.cod3

Code generation 3

Includes: - generating a function prolog (pushing return address, loading paramters) - generating a function epilog (restoring registers, returning) - generation / peephole optimizations of jump / branch instructions

Compiler implementation of the D programming language.

Members

Enums

M
anonymousenum M

Size in bytes of each instruction. 0 means illegal instruction. bit M: if there is a modregrm field (EV1 is reserved for modregrm) bit T: if there is a second operand (EV2) bit E: if second operand is only 8 bits bit A: a short version exists for the AX reg bit R: a short version exists for regs bits 2..0: size of instruction (excluding optional bytes)

Functions

CF_print
void CF_print(uint cf)

Pretty-print a CF mask.

REGSAVE_restore
void REGSAVE_restore(REGSAVE regsave, CodeBuilder cdb, reg_t reg, uint idx)

Restore reg from regsave area. Complement REGSAVE_save().

REGSAVE_save
void REGSAVE_save(REGSAVE regsave, CodeBuilder cdb, reg_t reg, uint idx)

Generate code to save reg in regsave stack area.

WRcodlst
void WRcodlst(code* c)

Debug code to dump code structure.

allocretregs
regm_t allocretregs(tym_t ty, type* t, tym_t tyf, reg_t reg1, reg_t reg2)

Allocate registers for function return values.

assignaddr
void assignaddr(block* bl)

Take symbol info in union ev and replace it with a real address in Vpointer.

branch
int branch(block* bl, int flag)

Replace JMPs in Bgotocode with JMP SHORTs whereever possible. This routine depends on FLcode jumps to only be forward referenced. BFLjmpoptdone is set to true if nothing more can be done with this block. Input: flag !=0 means don't have correct Boffsets yet

calcblksize
uint calcblksize(code* c)

Calculate bl.Bsize.

calccodsize
uint calccodsize(code* c)

Calculate and return code size of a code. Note that NOPs are sometimes used as markers, but are never output. LINNUMs are never output. Note: This routine must be fast. Profiling shows it is significant.

cdframeptr
void cdframeptr(CodeBuilder cdb, elem* e, regm_t* pretregs)

Gen code for OPframeptr

cdgot
void cdgot(CodeBuilder cdb, elem* e, regm_t* pretregs)

Gen code for load of _GLOBAL_OFFSET_TABLE_. This value gets cached in the local variable 'localgot'.

cgreg_dst_regs
void cgreg_dst_regs(reg_t* dst_integer_reg, reg_t* dst_float_reg)

setup register allocator parameters with platform specific data

cod3_adjSymOffsets
void cod3_adjSymOffsets()

Adjust all Soffset's of stack variables so they are all relative to the frame pointer.

cod3_align
void cod3_align(int seg)

Align start of function.

cod3_align_bytes
void cod3_align_bytes(int seg, size_t nbytes)

Word or dword align start of function.

cod3_bpoffset
targ_size_t cod3_bpoffset(Symbol* s)

Return offset from BP of symbol s.

cod3_initregs
void cod3_initregs()

setup ALLREGS and BYTEREGS called by: codgen

cod3_ptrchk
void cod3_ptrchk(CodeBuilder cdb, code* pcs, regm_t keepmsk)

Append code to cdb which validates pointer described by addressing mode in *pcs. Modify addressing mode in *pcs.

cod3_set32
void cod3_set32()

Fix global variables for 386.

cod3_set64
void cod3_set64()

Fix global variables for I64.

cod3_setdefault
void cod3_setdefault()

set initial global variable values

cod3_spoff
targ_size_t cod3_spoff()

Return offset of SP from BP.

cod3_stackadj
void cod3_stackadj(CodeBuilder cdb, int nbytes)

Generate code to adjust the stack pointer by nbytes

cod3_stackalign
void cod3_stackalign(CodeBuilder cdb, int nbytes)

Generate code to align the stack pointer at nbytes

cod3_thunk
void cod3_thunk(Symbol* sthunk, Symbol* sfunc, uint p, tym_t thisty, uint d, int i, uint d2)

Generate code for, and output a thunk.

cod3_useBP
regm_t cod3_useBP()

Determine if BP can be used as a general purpose register. Note parallels between this routine and prolog().

code_match
int code_match(code* c1, code* c2)

Return !=0 if codes match.

codout
uint codout(int seg, code* c, Barray!ubyte* disasmBuf)

Convert instructions to object code and write them to objmod.

cse_simple
bool cse_simple(code* c, elem* e)

Generate code segment to be used later to restore a cse

doswitch
void doswitch(CodeBuilder cdb, block* b)

Generate code for blocks ending in a switch statement. Take BCswitch and decide on BCifthen use if - then code BCjmptab index into jump table BCswitch search table for match

epilog
void epilog(block* b)

Generate and return function epilog. Output: retsize Size of function epilog

gen_storecse
void gen_storecse(CodeBuilder cdb, tym_t tym, reg_t reg, size_t slot)

Store reg to the common subexpression save area in index slot.

genjmp
void genjmp(CodeBuilder cdb, opcode_t op, uint fltarg, block* targ)

Generate a jump instruction.

genmovreg
code* genmovreg(uint to, uint from)

Generate a MOV to,from register instruction. Smart enough to dump redundant register moves, and segment register moves.

genmulimm
void genmulimm(CodeBuilder cdb, uint r1, uint r2, targ_int imm)

Generate immediate multiply instruction for r1=r2*imm. Optimize it into LEA's if we can.

genshift
void genshift(CodeBuilder cdb)

Load CX with the value of _AHSHIFT.

hasModregrm
bool hasModregrm(code* c)

Determine if there is a modregrm byte for instruction.

jmpaddr
void jmpaddr(code* c)

Compute jump addresses for FLcode. Note: only works for forward referenced code. only direct jumps and branches are detected. LOOP instructions only work for backward refs.

jmpopcode
int jmpopcode(elem* e)

Return a jump opcode relevant to the elem for a JMP true.

load_localgot
void load_localgot(CodeBuilder cdb)

Load contents of localgot into EBX.

makeitextern
void makeitextern(Symbol* s)

Assume symbol s is extern.

movregconst
void movregconst(CodeBuilder cdb, reg_t reg, targ_size_t value, regm_t flags)

Move constant value into reg. Take advantage of existing values in registers. If flags & mPSW set flags based on result Else if flags & 8 do not disturb flags Else don't care about flags If flags & 1 then byte move If flags & 2 then short move (for I32 and I64) If flags & 4 then don't disturb unused portion of register If flags & 16 then reg is a byte register AL..BH If flags & 64 (0x40) then 64 bit move (I64 only)

obj_namestring
int obj_namestring(char* p, const(char)* name)
outblkexitcode
void outblkexitcode(CodeBuilder cdb, block* bl, int anyspill, const(char)* sflsave, Symbol** retsym, regm_t mfuncregsave)

Generate block exit code

outjmptab
void outjmptab(block* b)

Output data block for a jump table (BCjmptab). The 'holes' in the table get filled with the default label.

outswitab
void outswitab(block* b)

Output data block for a switch table. Two consecutive tables, the first is the case value table, the second is the address table.

pinholeopt
void pinholeopt(code* c, block* b)

Find shorter versions of the same instructions. Does these optimizations: replaces jmps to the next instruction with NOPs sign extension of modregrm displacement sign extension of immediate data (can't do it for OR, AND, XOR as the opcodes are not defined) short versions for AX EA short versions for reg EA Code is neither removed nor added.

prolog_frame
void prolog_frame(CodeBuilder cdb, bool farfunc, uint xlocalsize, bool enter, int cfa_offset)

Set up frame register.

prolog_genva_start
elem* prolog_genva_start(Symbol* sv, Symbol* parmn)

Generate elems for va_start()

prolog_genvarargs
void prolog_genvarargs(CodeBuilder cdb, Symbol* sv)

Generate special varargs prolog for Posix 64 bit systems.

prolog_ifunc
void prolog_ifunc(CodeBuilder cdb, tym_t* tyf)

Generate first part of prolog for interrupt function.

prolog_loadparams
void prolog_loadparams(CodeBuilder cdb, tym_t tyf, bool pushalloc)
prolog_namedArgs
regm_t prolog_namedArgs()

Get mask of registers that named parameters (not ... variadic arguments) were passed in.

prolog_saveregs
void prolog_saveregs(CodeBuilder cdb, regm_t topush, int cfa_offset)

Save registers that the function destroys, but that the ABI says should be preserved across function calls.

prolog_stackalign
void prolog_stackalign(CodeBuilder cdb)

Enforce stack alignment. Input: cdb code builder.

regmask
regm_t regmask(tym_t tym, tym_t tyf)

Given a type, return a mask of registers to hold that type. Input: tyf function type

vex_inssize
ubyte vex_inssize(code* c)

Size for vex encoded instruction.

Meta