Skip to content

Commit

Permalink
renaming; CI
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-s168 committed Apr 16, 2024
1 parent 34b09c3 commit b7fe440
Show file tree
Hide file tree
Showing 32 changed files with 793 additions and 760 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/analyze.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Analyze code

on: [push]

jobs:
run_tests:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Run script file
run: |
chmod +x build.sh
./build.sh analyze
shell: bash
44 changes: 23 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,30 @@ project(vxcc_v3 C)
set(CMAKE_C_STANDARD 99)

add_executable(vxcc_v3 main.c
ir_ssa/ssa.h
ir_ssa/ssa.c
ir_ssa/opt.h
ir_ssa/opt/loop_simplify.c
ir_ssa/opt/comparisions.c
ir_ssa/opt/constant_eval.c
ir_ssa/opt/inline_vars.c
ir_ssa/opt/remove_vars.c
ir_ssa/opt/join_compute.c
ir_ssa/dump.c
ir_ssa/verify_ssa.c
ir/ir.h
ir/ir.c
ir/opt.h
ir/opt/loop_simplify.c
ir/opt/comparisions.c
ir/opt/constant_eval.c
ir/opt/inline_vars.c
ir/opt/remove_vars.c
ir/opt/join_compute.c
ir/dump.c
ir/verify_ssa.c
utils.h
ir_ssa/builder.c
ir_ssa/eval.c
ir/builder.c
ir/eval.c
common.h
common/verify.c
ir_ssa/transform/normalize.c
ir_ssa/opt/reduce_if.c
ir_ssa/transform/single_assign.c
ir_ssa/transform/single_assign_conditional.c
ir_ssa/opt/reduce_loops.c
ir_ssa/cir.h
ir_ssa/verify_cir.c
ir_ssa/transform/flatten.c
ir/transform/normalize.c
ir/opt/reduce_if.c
ir/transform/single_assign.c
ir/transform/single_assign_conditional.c
ir/opt/reduce_loops.c
ir/cir.h
ir/verify_cir.c
ir/transform/flatten.c
ir/analysis.c
ir/transform.c
)
15 changes: 14 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
#!/bin/sh
clang -g -ggdb -O3 -Wall -Wextra -Wno-unused -Wpedantic -Werror *.c ir_ssa/opt/*.c ir_ssa/*.c common/*.c ir_ssa/transform/*.c -o vxcc
FILES="main.c ir/opt/*.c ir/*.c common/*.c ir/transform/*.c"
CFLAGS="-Wall -Wextra -Wno-unused -Wpedantic -Werror -std=c11"

# shellcheck disable=SC2086

if [ "$1" == "analyze" ]; then
echo "analyzing..."
clang --analyze -Xclang -analyzer-werror $CFLAGS $FILES
else
echo "compile DebugOpt"
clang -g -ggdb -O3 $CFLAGS $FILES -o vxcc
fi

# shellcheck enable=SC2086
138 changes: 138 additions & 0 deletions ir/analysis.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#include "ir.h"

bool irview_find(SsaView *view, const SsaOpType type) {
for (size_t i = view->start; i < view->end; i ++) {
if (view->block->ops[i].id == type) {
view->start = i;
return true;
}
}

return false;
}

/** You should use `irblock_root(block)->as_root.vars[id].decl` instead! */
SsaOp *irblock_finddecl_var(const SsaBlock *block, const SsaVar var) {
for (size_t i = 0; i < block->ops_len; i ++) {
SsaOp *op = &block->ops[i];

for (size_t j = 0; j < op->outs_len; j ++)
if (op->outs[j].var == var)
return op;

for (size_t j = 0; j < op->params_len; j ++) {
const SsaValue param = op->params[j].val;

if (param.type == SSA_VAL_BLOCK) {
for (size_t k = 0; k < param.block->ins_len; k ++)
if (param.block->ins[k] == var)
return op;

SsaOp *res = irblock_finddecl_var(param.block, var);
if (res != NULL)
return res;
}
}
}

return NULL;
}


bool irblock_var_used(const SsaBlock *block, const SsaVar var) {
for (size_t i = 0; i < block->outs_len; i++)
if (block->outs[i] == var)
return true;

for (long int i = block->ops_len - 1; i >= 0; i--) {
const SsaOp *op = &block->ops[i];
for (size_t j = 0; j < op->params_len; j++) {
if (op->params[j].val.type == SSA_VAL_BLOCK) {
if (irblock_var_used(op->params[j].val.block, var)) {
return true;
}
} else if (op->params[j].val.type == SSA_VAL_VAR) {
if (op->params[j].val.var == var) {
return true;
}
}
}
}

return false;
}

// TODO: search more paths
bool irop_anyparam_hasvar(SsaOp *op, SsaVar var) {
for (size_t i = 0; i < op->params_len; i ++)
if (op->params[i].val.type == SSA_VAL_VAR && op->params[i].val.var == var)
return true;
return false;
}

SsaOp *irblock_inside_out_vardecl_before(const SsaBlock *block, const SsaVar var, size_t before) {
while (before --> 0) {
SsaOp *op = &block->ops[before];

for (size_t i = 0; i < op->outs_len; i ++)
if (op->outs[i].var == var)
return op;
}

if (block->parent == NULL)
return NULL;

return irblock_inside_out_vardecl_before(block->parent, var, block->parent_index);
}

bool irop_is_pure(SsaOp *op) {
switch (op->id) {
case SSA_OP_NOP:
case SSA_OP_IMM:
case SSA_OP_REINTERPRET:
case SSA_OP_ZEROEXT:
case SSA_OP_SIGNEXT:
case SSA_OP_TOFLT:
case SSA_OP_FROMFLT:
case SSA_OP_BITCAST:
case SSA_OP_ADD:
case SSA_OP_SUB:
case SSA_OP_MUL:
case SSA_OP_DIV:
case SSA_OP_MOD:
case SSA_OP_GT:
case SSA_OP_GTE:
case SSA_OP_LT:
case SSA_OP_LTE:
case SSA_OP_EQ:
case SSA_OP_NEQ:
case SSA_OP_NOT:
case SSA_OP_AND:
case SSA_OP_OR:
case SSA_OP_BITWISE_NOT:
case SSA_OP_BITWISE_AND:
case SSA_OP_BITIWSE_OR:
case SSA_OP_SHL:
case SSA_OP_SHR:
case SSA_OP_FOR:
return true;

case SSA_OP_REPEAT:
case CIR_OP_CFOR:
case SSA_OP_IF:
case SSA_OP_FLATTEN_PLEASE:
case SSA_OP_INFINITE:
case SSA_OP_WHILE:
case SSA_OP_FOREACH:
case SSA_OP_FOREACH_UNTIL:
for (size_t i = 0; i < op->params_len; i ++)
if (op->params[i].val.type == SSA_VAL_BLOCK)
for (size_t j = 0; j < op->params[i].val.block->ops_len; j ++)
if (!irop_is_pure(&op->params[i].val.block->ops[j]))
return false;
return true;

default:
return false;
}
}
Loading

0 comments on commit b7fe440

Please sign in to comment.