Skip to content

Commit

Permalink
Restructure libclambcc directory to fix unit tests
Browse files Browse the repository at this point in the history
The unit tests rely on all of the opt pass libraries being located in
the same directory as libclambccommon.so, as specified using
LD_LIBRARY_PATH.

One solution would have been to specify a path for each opt pass library
in LD_LIBRARY_PATH and then search for each library in each of those
LD_LIBRARY_PATH paths. However this felt very clunky.

Instead, this commit solves the problem by placing the source for all
opt passes in the same directory, which will mean that the .so's created
in the build directory will also be co-located and thus using a single
path for LD_LIBRARY_PATH will suffice.

To make present and future copy-pasting easy, I also renamed the
libraries to be camel-case.
  • Loading branch information
micahsnyder committed Feb 13, 2024
1 parent e629523 commit 0ffd5b6
Show file tree
Hide file tree
Showing 63 changed files with 421 additions and 1,157 deletions.
55 changes: 0 additions & 55 deletions Dockerfile

This file was deleted.

56 changes: 26 additions & 30 deletions clambcc/clambc-compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,16 @@

SHARED_OBJ_DIR = Path(__file__).parent / '..' / 'lib'
if (SHARED_OBJ_DIR / 'libclambccommon.so').exists():
#SHARED_OBJ_FILE = SHARED_OBJ_DIR / 'libclambcc.so'
FOUND_SHARED_OBJ = True

elif 'LD_LIBRARY_PATH' in os.environ:
# Use LD_LIBRARY_PATH to try to find it.
ld_library_paths = os.environ['LD_LIBRARY_PATH'].strip(' :').split(':')
print(f"Looking for libs in {ld_library_paths}")
for lib_path in ld_library_paths:
if (Path(lib_path) / 'libclambcccommon.so').exists():
#SHARED_OBJ_FILE = Path(lib_path) / 'libclambcccommon.so'
if (Path(lib_path) / 'libClamBCCommon.so').exists():
SHARED_OBJ_DIR = Path(lib_path)
FOUND_SHARED_OBJ = True

break

VERBOSE=False
Expand Down Expand Up @@ -516,7 +514,7 @@ def createInputSourceFile(clangLLVM: ClangLLVM, name: str, args: list, options:
, "__clambc_match_counts"
, "__clambc_match_offsets"
, "__clambc_pedata"
, "__Copyright"
, "__Copyright"
]

OPTIMIZE_OPTIONS = ["-S"
Expand Down Expand Up @@ -600,34 +598,32 @@ def createInputSourceFile(clangLLVM: ClangLLVM, name: str, args: list, options:
, 'verify'
]

OPTIMIZE_LOADS=[ f"--load {SHARED_OBJ_DIR}/libclambccommon.so"
OPTIMIZE_LOADS=[ f"--load {SHARED_OBJ_DIR}/libClamBCCommon.so"
# , f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcremoveundefs.so" #Not needed, since clambc-remove-undefs is not being used.
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcpreserveabis.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcremoveunsupportedicmpintrinsics.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcremoveusub.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcremovefshl.so"
# , f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcremovepointerphis.so" #Not needed, since clambc-remove-pointer-phis is not being used.
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcloweringnf.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcremoveicmpsle.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcverifier.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcremovefreezeinsts.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcloweringf.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambclogicalcompilerhelper.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambclogicalcompiler.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcrebuild.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambctrace.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcoutlineendiannesscalls.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcchangemallocargsize.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcextendphisto64bit.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcconvertintrinsicsto32bit.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcpreparegepsforwriter.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcanalyzer.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcregalloc.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcwriter.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libClamBCPreserveABIs.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libClamBCRemoveUnsupportedICMPIntrinsics.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libClamBCRemoveUSUB.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libClamBCRemoveFSHL.so"
# , f"--load-pass-plugin {SHARED_OBJ_DIR}/libClamBCRemovePointerPHIs.so" #Not needed, since clambc-remove-pointer-phis is not being used.
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libClamBCLoweringNF.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libClamBCRemoveICMPSLE.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libClamBCVerifier.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libClamBCRemoveFreezeInsts.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libClamBCLoweringF.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libClamBCLogicalCompilerHelper.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libClamBCLogicalCompiler.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libClamBCRebuild.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libClamBCTrace.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libClamBCOutlineEndiannessCalls.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libClamBCChangeMallocArgSize.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libClamBCExtendPHIsTo64Bit.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libClamBCConvertIntrinsicsTo32Bit.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libClamBCPrepareGEPsForWriter.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libClamBCAnalyzer.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libClamBCRegAlloc.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libClamBCWriter.so"
]



def optimize(clangLLVM: ClangLLVM, inFile: str, outFile: str, sigFile: str, inputSourceFile: str, standardCompiler: bool) -> int:

cmd = []
Expand Down
Loading

0 comments on commit 0ffd5b6

Please sign in to comment.