diff options
author | Ash Wolf <ninji@wuffs.org> | 2023-01-13 01:38:15 +0000 |
---|---|---|
committer | Ash Wolf <ninji@wuffs.org> | 2023-01-13 01:38:15 +0000 |
commit | 08d21a052b9afc37292ec3fad390502610e2cb32 (patch) | |
tree | 270737c790f5d1bb05f68498f8233640ada6a0c5 /compiler_and_linker/unsorted/PCodeInfo.c | |
parent | 54628993e0038c7bea9c064491974985b6699502 (diff) | |
parent | 9d985413ce2b60a1a8cf001913ee8dac81c03aac (diff) | |
download | MWCC-08d21a052b9afc37292ec3fad390502610e2cb32.tar.gz MWCC-08d21a052b9afc37292ec3fad390502610e2cb32.zip |
Merge remote-tracking branch 'origin/main'
Diffstat (limited to 'compiler_and_linker/unsorted/PCodeInfo.c')
-rw-r--r-- | compiler_and_linker/unsorted/PCodeInfo.c | 86 |
1 files changed, 83 insertions, 3 deletions
diff --git a/compiler_and_linker/unsorted/PCodeInfo.c b/compiler_and_linker/unsorted/PCodeInfo.c index b11288b..fdfa71e 100644 --- a/compiler_and_linker/unsorted/PCodeInfo.c +++ b/compiler_and_linker/unsorted/PCodeInfo.c @@ -433,7 +433,7 @@ PCode *vformatpcode(short opcode, va_list argList) { CError_ASSERT(476, obj->otype == OT_OBJECT); arg->data.mem.obj = obj; arg->data.mem.offset = 0; - arg->arg = 1; + arg->arg = RefType_4; } break; @@ -769,7 +769,7 @@ int expectandformatoperand(PCodeArg *operand, PCOpKind expectedKind, char a3, in tmp = sprintf(buf, "%sB<unknown>-B%ld+%ld", refis1 ? "-" : "", operand->data.labeldiff.labelB->block->blockIndex, operand->data.labeldiff.offset); } else { if (b_null) - tmp = sprintf(buf, "%sB%ld-%B<unknown>+%ld", refis1 ? "-" : "", operand->data.labeldiff.labelA->block->blockIndex, operand->data.labeldiff.offset); + tmp = sprintf(buf, "%sB%ld-B<unknown>+%ld", refis1 ? "-" : "", operand->data.labeldiff.labelA->block->blockIndex, operand->data.labeldiff.offset); else tmp = sprintf(buf, "%sB%ld-B%ld+%ld", refis1 ? "-" : "", operand->data.labeldiff.labelA->block->blockIndex, operand->data.labeldiff.labelB->block->blockIndex, operand->data.labeldiff.offset); } @@ -786,7 +786,12 @@ int expectandformatoperand(PCodeArg *operand, PCOpKind expectedKind, char a3, in } int formatoperand(PCodeArg *operand, char *buf) { - + return expectandformatoperand( + operand, + operand->kind, + (operand->kind == PCOp_REGISTER) ? operand->arg : 'x', + -1, + buf); } void formatoperands(PCode *pcode, char *buf, int showBasicBlocks) { @@ -1146,15 +1151,83 @@ void formatoperands(PCode *pcode, char *buf, int showBasicBlocks) { } PCode *makecopyinstruction(PCodeArg *a, PCodeArg *b) { + if (b->kind == PCOp_REGISTER) { + switch (b->arg) { + case RegClass_GPR: + return makepcode(PC_MR, b->data.reg.reg, a->data.reg.reg); + case RegClass_FPR: + return makepcode(PC_FMR, b->data.reg.reg, a->data.reg.reg); + case RegClass_VR: + return makepcode(PC_VMR, b->data.reg.reg, a->data.reg.reg); + case RegClass_CRFIELD: + return makepcode(PC_MCRF, b->data.reg.reg, a->data.reg.reg); + } + } + CError_FATAL(1622); + return NULL; } int is_location_independent(PCode *pcode) { + switch (pcode->op) { + case PC_LI: + case PC_LIS: + case PC_VSPLTISB: + case PC_VSPLTISH: + case PC_VSPLTISW: + return 1; + case PC_ADDI: + case PC_ADDIS: + case PC_ORI: + case PC_ORIS: + return pcode->args[1].data.reg.reg == _FP_; + case PC_LWZ: + if ( + pcode->args[1].data.reg.reg == 1 && + pcode->args[2].kind == PCOp_IMMEDIATE && + pcode->args[2].data.imm.value == 0 + ) + return 1; + } + return 0; } int can_reuse_stored_value(PCode *a, PCode *b) { + switch (b->op) { + case PC_LWZ: + case PC_LWZU: + case PC_LWZX: + case PC_LWZUX: + switch (a->op) { + case PC_STW: + case PC_STWU: + case PC_STWX: + case PC_STWUX: + return 1; + } + break; + + case PC_LFD: + case PC_LFDU: + case PC_LFDX: + case PC_LFDUX: + switch (a->op) { + case PC_STFD: + case PC_STFDU: + case PC_STFDX: + case PC_STFDUX: + return 1; + } + break; + + case PC_LVX: + if (a->op == PC_STVX) + return 1; + break; + } + return 0; } int nbytes_loaded_or_stored_by(PCode *pcode) { @@ -1261,7 +1334,14 @@ int nbytes_loaded_or_stored_by(PCode *pcode) { } void change_num_operands(PCode *pcode, int newNum) { + int i; + + CError_ASSERT(2026, ((pcode->argCount > 5) ? pcode->argCount : 5) >= newNum); + + for (i = pcode->argCount - 1; i >= newNum; i--) + pcode->args[i].kind = PCOp_PLACEHOLDEROPERAND; + pcode->argCount = newNum; } void change_opcode(PCode *pcode, short opcode) { |