Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Threads with function call generate incorrect hcode #385

Open
zhuanhao-wu opened this issue Feb 13, 2023 · 3 comments
Open

Threads with function call generate incorrect hcode #385

zhuanhao-wu opened this issue Feb 13, 2023 · 3 comments
Labels

Comments

@zhuanhao-wu
Copy link
Collaborator

File: https://github.com/intel/systemc-compiler/blob/main/designs/tests/cthread/test_cthread_read_defined_ref.cpp

    template<class T>
    void const_ref(const T& par) {
        auto i = par;
    }
    // Assign through reference
    template<class T>
    void ref_assign(T& par) {
        par = 0;
    }
    void fcall_ref_assign()
    {
        int i;
        sc_uint<2> k = 0;
        wait();

        while (1)
        {
            ref_assign(i);
            ref_assign(k);
            const_ref(i);
            const_ref(k ? 1 : 2);
//             sct_assert_defined(i);
//             sct_assert_defined(k);
//             sct_assert_register(i, false);
//             sct_assert_register(k, false);

            sc_uint<2> m;
            ref_assign(m);
            auto j = m / 2;
//             sct_assert_defined(m);
//             sct_assert_register(m, false);

            wait();
        }
    }

Currently the generated code looks as follows:

                hSwitchCase  NONAME [
                  hLiteral 1 NOLIST
                  hIfStmt  NONAME [
                    hLiteral 1 NOLIST
                  ]
                  hLiteral 1 NOLIST
                  hMethodCall A__const_ref_func_0 [
                    hCondop  NONAME [
                      hVarref k_fcall_ref_assign_thread_1 NOLIST
                      hLiteral 1 NOLIST
                      hLiteral 2 NOLIST
                    ]
                  ]
                  hMethodCall A__ref_assign_func_0 [
                    hVarref m_fcall_ref_assign_thread_2 NOLIST
                  ]
                  hVarAssign  NONAME [
                    hVarref j_fcall_ref_assign_thread_3 NOLIST
                    hBinop / [
                      hVarref m_fcall_ref_assign_thread_2 NOLIST
                      hLiteral 2 NOLIST
                    ]
                  ]
                  hBinop = [
                    hVarref _next_state_fcall_ref_assign# NOLIST
                    hLiteral 2 NOLIST
                  ]
                  hReturnStmt  NONAME NOLIST // the return statement is generated here, but we still have more statemetns
                  hLiteral 2 NOLIST
                  hMethodCall A__const_ref_func_0 [
                    hCondop  NONAME [
                      hVarref k_fcall_ref_assign_thread_1 NOLIST
                      hLiteral 1 NOLIST
                      hLiteral 2 NOLIST
                    ]
                  ]
                  hVarAssign  NONAME [  // here, we have a dangling assignment
                    hVarref m_fcall_ref_assign_thread_2 NOLIST
                  ]
                  hMethodCall A__ref_assign_func_1 [
                    hVarref m_fcall_ref_assign_thread_2 NOLIST
                  ]
                  hVarAssign  NONAME [
                    hVarref j_fcall_ref_assign_thread_3 NOLIST
                    hBinop / [
                      hVarref m_fcall_ref_assign_thread_2 NOLIST
                      hLiteral 2 NOLIST
                    ]
                  ]
                  hBinop = [
                    hVarref _next_state_fcall_ref_assign# NOLIST
                    hLiteral 2 NOLIST
                  ]
                  hReturnStmt  NONAME NOLIST
                ]
@zhuanhao-wu
Copy link
Collaborator Author

  • Confirm SystemVerilog has support for inlining functions/pass-by-reference
  • Check if the function is not pass-by-reference, the binary is still generating incorrect hcode

@zhuanhao-wu
Copy link
Collaborator Author

The code that is causing the issue is const_ref(k ? 1 : 2);.

  1. Removing this line allows the tool to pass through
  2. Changing const_ref to be not pass-by-reference does not help
    template<class T>
    void const_ref(T par) {
        auto i = par;
    }

@zhuanhao-wu
Copy link
Collaborator Author

SystemVerilog has support for pass-by-reference with the following form

    function automatic logic pipe(ref logic[31:0] ip);
        ip = ip + 1;
        return ip;
    endfunction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant