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

rsz: Source StaTclTypes.i and clean up the binding #5277

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

povik
Copy link
Contributor

@povik povik commented Jun 23, 2024

To get all the SWIG type conversion rules around basic STA types, it's best if we can source StaTclTypes.i. Here we make the change in the resizer binding, and use it to clean up some of the binding code. See the commits.

@povik
Copy link
Contributor Author

povik commented Jun 23, 2024

The following STA patch is required, otherwise we get a conflict at linkage time. Please confirm the resizer change is desirable, I can open the OpenSTA PR for it.

diff --git a/tcl/StaTclTypes.i b/tcl/StaTclTypes.i
index 6127dea..abe3ca6 100644
--- a/tcl/StaTclTypes.i
+++ b/tcl/StaTclTypes.i
@@ -154,7 +154,7 @@ tclListNetworkSet(Tcl_Obj *const source,
     return nullptr;
 }
 
-StringSet *
+static StringSet *
 tclListSetConstChar(Tcl_Obj *const source,
 		    Tcl_Interp *interp)
 {
@@ -174,7 +174,7 @@ tclListSetConstChar(Tcl_Obj *const source,
     return nullptr;
 }
 
-StringSeq *
+static StringSeq *
 tclListSeqConstChar(Tcl_Obj *const source,
 		    Tcl_Interp *interp)
 {
@@ -194,7 +194,7 @@ tclListSeqConstChar(Tcl_Obj *const source,
     return nullptr;
 }
 
-StdStringSet *
+static StdStringSet *
 tclListSetStdString(Tcl_Obj *const source,
 		    Tcl_Interp *interp)
 {
@@ -279,7 +279,7 @@ setPtrTclList(SET_TYPE *set,
 
 ////////////////////////////////////////////////////////////////
 
-void
+static void
 tclArgError(Tcl_Interp *interp,
             const char *msg,
             const char *arg)
@@ -292,7 +292,7 @@ tclArgError(Tcl_Interp *interp,
   stringDelete(error);
 }
 
-void
+static void
 objectListNext(const char *list,
 	       const char *type,
 	       // Return values.

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@@ -35,12 +35,22 @@

include("openroad")

swig_lib(NAME rsz
Copy link
Contributor Author

@povik povik Jun 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I decided to split out the binding into a library of its own because we are polluting its include path a lot (see below in this file).

@povik
Copy link
Contributor Author

povik commented Jun 23, 2024

As a result of the new include, and with the static functions STA patch, we get new warnings

[ 97%] Building CXX object src/rsz/src/CMakeFiles/rsz_swig.dir/CMakeFiles/rsz_swig.dir/ResizerTCL_wrap.cxx.o
/Users/pk/repos/openroad/build/src/rsz/src/CMakeFiles/rsz_swig.dir/ResizerTCL_wrap.cxx:1926:1: warning: unused function 'tclListSetConstChar' [-Wunused-function]
tclListSetConstChar(Tcl_Obj *const source,
^
/Users/pk/repos/openroad/build/src/rsz/src/CMakeFiles/rsz_swig.dir/ResizerTCL_wrap.cxx:1946:1: warning: unused function 'tclListSeqConstChar' [-Wunused-function]
tclListSeqConstChar(Tcl_Obj *const source,
^
...

If both openroad/opensta used C++17 we could silence with [[maybe_unused]] but I don't think that's the case.

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@gadfort
Copy link
Collaborator

gadfort commented Jun 23, 2024

@povik is it possible to use %import instead of %include to avoid the need for the sta patch?

@povik
Copy link
Contributor Author

povik commented Jun 23, 2024

is it possible to use %import instead of %include to avoid the need for the sta patch?

@gadfort changing that and reverting the sta patch I get the failures below. I am not familiar with SWIG so it's hard for me to say how much work it would take to make %import work.

/Users/pk/repos/openroad/build/src/rsz/src/CMakeFiles/rsz_swig.dir/ResizerTCL_wrap.cxx:3096:12: error: use of undeclared identifier 'tclListSeqPtr'
    arg2 = tclListSeqPtr<const Instance*>(objv[2], SWIGTYPE_p_Instance, interp);
           ^
/Users/pk/repos/openroad/build/src/rsz/src/CMakeFiles/rsz_swig.dir/ResizerTCL_wrap.cxx:3126:12: error: use of undeclared identifier 'tclListSeqPtr'
    arg1 = tclListSeqPtr<const Instance*>(objv[1], SWIGTYPE_p_Instance, interp);
           ^
/Users/pk/repos/openroad/build/src/rsz/src/CMakeFiles/rsz_swig.dir/ResizerTCL_wrap.cxx:3582:5: error: use of undeclared identifier 'seqPtrTclList'
    seqPtrTclList<NetSeq, Net>(nets, SWIGTYPE_p_Net, interp);
    ^
/Users/pk/repos/openroad/build/src/rsz/src/CMakeFiles/rsz_swig.dir/ResizerTCL_wrap.cxx:3613:5: error: use of undeclared identifier 'setPtrTclList'
    setPtrTclList<PinSet, Pin>(pins, SWIGTYPE_p_Pin, interp);
    ^
/Users/pk/repos/openroad/build/src/rsz/src/CMakeFiles/rsz_swig.dir/ResizerTCL_wrap.cxx:4371:5: error: use of undeclared identifier 'seqPtrTclList'
    seqPtrTclList<NetSeq, Net>(result, SWIGTYPE_p_Net, interp);
    ^
/Users/pk/repos/openroad/build/src/rsz/src/CMakeFiles/rsz_swig.dir/ResizerTCL_wrap.cxx:4657:24: error: use of undeclared identifier 'cmdNetwork'
    Network *network = cmdNetwork();
                       ^
/Users/pk/repos/openroad/build/src/rsz/src/CMakeFiles/rsz_swig.dir/ResizerTCL_wrap.cxx:4658:12: error: use of undeclared identifier 'tclListNetworkSet'
    arg1 = tclListNetworkSet<PinSet, Pin>(objv[1], SWIGTYPE_p_Pin, interp, network);
           ^
/Users/pk/repos/openroad/build/src/rsz/src/CMakeFiles/rsz_swig.dir/ResizerTCL_wrap.cxx:4676:5: error: use of undeclared identifier 'setTclList'
    setTclList<PinSet, Pin>(result, SWIGTYPE_p_Pin, interp);
    ^

@gadfort
Copy link
Collaborator

gadfort commented Jun 23, 2024

@povik thanks for checking, I was hoping that would have solved it.

@maliberty
Copy link
Member

I appears %import doesn't bring the template functions into scope and %include leads to duplication. Using static works at the minor cost of having duplicate instantiations in the program.

A slightly nicer patch would be to pull these helper functions out of the .i into a regular c++ where they could more easily be shared. I believe then %import could be made to work. I'm not sure its worth the bother though.

@povik
Copy link
Contributor Author

povik commented Jun 24, 2024

@maliberty Should I open a PR against OpenROAD's or upstream STA?

@maliberty
Copy link
Member

@maliberty Should I open a PR against OpenROAD's or upstream STA?

upstream (which requires a CLA)

@povik
Copy link
Contributor Author

povik commented Jul 31, 2024

parallaxsw/OpenSTA#62, which was blocking this PR, has now been merged

Signed-off-by: Martin Povišer <[email protected]>
Now that we source `StaTclTypes.i` we can rely on it to supply much of
the type conversion rules. Only keep those which are unique to the
resizer, and for those try to use the generic conversion helpers (e.g.
`setPtrTclList`).

Signed-off-by: Martin Povišer <[email protected]>
Signed-off-by: Martin Povišer <[email protected]>
@povik
Copy link
Contributor Author

povik commented Sep 3, 2024

Rebased and inserted sign-offs, this could be good to go now

Copy link
Contributor

github-actions bot commented Sep 3, 2024

clang-tidy review says "All clean, LGTM! 👍"

@povik
Copy link
Contributor Author

povik commented Sep 3, 2024

The CI failures are due to some of the helpers included from StaTclTypes.i ending up not getting used in Resizer.i (but marked static):

/tmp/workspace/OpenROAD-Public_PR-5277-merge/build/src/rsz/src/CMakeFiles/rsz_swig.dir/ResizerTCL_wrap.cxx:2132:1: error: 'void sta::objectListNext(const char*, const char*, bool&, const char*&)' defined but not used [-Werror=unused-function]
 2132 | objectListNext(const char *list,
      | ^~~~~~~~~~~~~~
/tmp/workspace/OpenROAD-Public_PR-5277-merge/build/src/rsz/src/CMakeFiles/rsz_swig.dir/ResizerTCL_wrap.cxx:2119:1: error: 'void sta::tclArgError(Tcl_Interp*, const char*, const char*)' defined but not used [-Werror=unused-function]
 2119 | tclArgError(Tcl_Interp *interp,
      | ^~~~~~~~~~~
/tmp/workspace/OpenROAD-Public_PR-5277-merge/build/src/rsz/src/CMakeFiles/rsz_swig.dir/ResizerTCL_wrap.cxx:2012:1: error: 'sta::StringSeq* sta::tclListSeqConstChar(Tcl_Obj*, Tcl_Interp*)' defined but not used [-Werror=unused-function]
 2012 | tclListSeqConstChar(Tcl_Obj *const source,
      | ^~~~~~~~~~~~~~~~~~~
/tmp/workspace/OpenROAD-Public_PR-5277-merge/build/src/rsz/src/CMakeFiles/rsz_swig.dir/ResizerTCL_wrap.cxx:1992:1: error: 'sta::StringSet* sta::tclListSetConstChar(Tcl_Obj*, Tcl_Interp*)' defined but not used [-Werror=unused-function]
 1992 | tclListSetConstChar(Tcl_Obj *const source,
      | ^~~~~~~~~~~~~~~~~~~

Should I open another STA patch to have [[maybe_unused]] on those helpers? That sounds the cleanest, though I am not sure OpenSTA is C++17.

@maliberty
Copy link
Member

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

Successfully merging this pull request may close these issues.

3 participants