Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander.nutz committed Nov 26, 2024
1 parent 14b6613 commit 859ed8d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 33 deletions.
5 changes: 4 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ function prepare() {
else
SERIAL_ARGS="-lpthread"
fi
$BUILD_CC build.c $SERIAL_ARGS $CFLAGS -DVERBOSE=1 -DCC="\"$CC\"" -DCC_ARGS="\"$CFLAGS\"" -DLD_ARGS="\"$EX_LDFLAGS $SERIAL_ARGS\"" -DAR="\"$AR\"" -o build.exe
cd build_c/slowdb
./build.sh
cd ../../
$BUILD_CC build.c build_c/slowdb/build/slowdb.a $SERIAL_ARGS $CFLAGS -DVERBOSE=1 -DCC="\"$CC\"" -DCC_ARGS="\"$CFLAGS\"" -DLD_ARGS="\"$EX_LDFLAGS $SERIAL_ARGS\"" -DAR="\"$AR\"" -o build.exe
echo "# build.exe compiled"
echo "# gen cdef files"
./build.exe gen
Expand Down
2 changes: 1 addition & 1 deletion build_c
Submodule build_c updated 2 files
+1 −1 build.h
+1 −1 slowdb
2 changes: 1 addition & 1 deletion targets/etca/etca.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static bool etca_need_move_ret_to_arg(vx_CU* cu, vx_IrBlock* block, size_t ret_i
return ret_id >= 1;
}

void vx_Target_X86__info(vx_TargetInfo* dest, vx_Target const* target)
void vx_Target_ETCA__info(vx_TargetInfo* dest, vx_Target const* target)
{
set_tg(etca);
dest->cmov_opt = target->flags.etca[vx_Target_ETCA_condExec];
Expand Down
2 changes: 1 addition & 1 deletion targets/targets.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ TARGET_FLAGS_GEN(X86)

#undef TARGET_FLAGS_GEN

#include "x86/cg.h"
#include "x86/x86.h"
// add target

void vx_llir_emit_asm(vx_CU* cu, vx_IrBlock* llirblock, FILE* out)
Expand Down
35 changes: 6 additions & 29 deletions targets/x86/cg.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,6 @@ static size_t XMM_SCRATCH_REG2;
typedef struct {
vx_IrType* type;
Location* location;
size_t heat; // if heat == 2 then one producer and one consumer
} VarData;

VarData* varData = NULL;
Expand Down Expand Up @@ -1439,43 +1438,21 @@ void vx_cg_x86stupid_gen(vx_CU* _cu, vx_IrBlock* _block, FILE* out) {
availableRegistersCount += extraAv;
}

// TODO: count heat in SSA instead (bc of loops)

varData = block->as_root.vars_len == 0 ? NULL : calloc(block->as_root.vars_len, sizeof(VarData));
for (size_t i = 0; i < block->ins_len; i ++) {
assert(varData);
varData[block->ins[i].var].type = block->ins[i].type;
}
for (vx_IrOp *op = block->first; op != NULL; op = op->next) {
for (size_t i = 0; i < op->outs_len; i ++) {
assert(varData);
vx_IrVar v = op->outs[i].var;
varData[v].type = op->outs[i].type;
varData[v].heat ++;
}
for (size_t i = 0; i < op->args_len; i ++) {
vx_IrValue val = op->args[i];
if (val.type == VX_IR_VAL_VAR) {
assert(varData);
varData[val.var].heat ++;
}
}
for (size_t i = 0; i < op->params_len; i ++) {
vx_IrValue val = op->params[i].val;
if (val.type == VX_IR_VAL_VAR) {
assert(varData);
varData[val.var].heat ++;
}
}
}

size_t stackOff = 0;

/* ======================== VAR ALLOC ===================== */
signed long long highestHeat = 0;
for (vx_IrVar var = 0; var < block->as_root.vars_len; var ++) {
assert(varData);
size_t heat = varData[var].heat;
size_t heat = block->as_root.vars[var].heat;
if (heat == 0)
fprintf(stderr, "warning: variable %%%zu has no heat\n", var);
if (heat > highestHeat) {
highestHeat = heat;
}
Expand All @@ -1496,7 +1473,7 @@ void vx_cg_x86stupid_gen(vx_CU* _cu, vx_IrBlock* _block, FILE* out) {
for (vx_IrVar var = 0; var < block->as_root.vars_len; var ++) {
if (varsSorted[var]) continue;

if (varData[var].heat == highestHeat) {
if (block->as_root.vars[var].heat == highestHeat) {
varsHotFirst[varsHotFirstLen ++] = var;
varsSorted[var] = true;
}
Expand All @@ -1514,7 +1491,7 @@ void vx_cg_x86stupid_gen(vx_CU* _cu, vx_IrBlock* _block, FILE* out) {
vx_IrVar var = varsHotFirst[varId];

assert(varData);
if (varData[var].heat == 0) {
if (block->as_root.vars[var].heat == 0) {
varData[var].location = NULL;
continue;
}
Expand Down Expand Up @@ -1632,7 +1609,7 @@ void vx_cg_x86stupid_gen(vx_CU* _cu, vx_IrBlock* _block, FILE* out) {
free(varsHotFirst);

for (vx_IrVar var = 0; var < block->as_root.vars_len; var ++) {
if (varData[var].heat == 0) {
if (block->as_root.vars[var].heat == 0) {
varData[var].location = NULL;
continue;
}
Expand Down

0 comments on commit 859ed8d

Please sign in to comment.