From 1355191221b504c90f5ee9c9370ca4d5bd683845 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Wed, 24 Apr 2024 14:32:36 -0700 Subject: [PATCH] blah --- clambcc/clambc-compiler.py | 6 +++++- libclambcc/CMakeLists.txt | 30 +++++++++++++------------- libclambcc/ClamBCRemovePointerPHIs.cpp | 14 ++++++------ libclambcc/ClamBCWriter.cpp | 3 +++ 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/clambcc/clambc-compiler.py b/clambcc/clambc-compiler.py index 3b4028a9fb..fa630f4c87 100755 --- a/clambcc/clambc-compiler.py +++ b/clambcc/clambc-compiler.py @@ -548,6 +548,8 @@ def createInputSourceFile(clangLLVM: ClangLLVM, name: str, args: list, options: , 'globalopt' , 'clambc-preserve-abis' #remove fake function calls because O3 has already run , 'verify' + , 'clambc-remove-pointer-phis' + , 'verify' , 'clambc-remove-unsupported-icmp-intrinsics' , 'verify' , 'clambc-remove-usub' @@ -574,6 +576,8 @@ def createInputSourceFile(clangLLVM: ClangLLVM, name: str, args: list, options: , 'verify' , 'clambc-rebuild' , 'verify' +# , 'clambc-remove-pointer-phis' + , 'verify' , 'clambc-trace' , 'verify' , 'clambc-outline-endianness-calls' @@ -603,7 +607,7 @@ def createInputSourceFile(clangLLVM: ClangLLVM, name: str, args: list, options: , 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}/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" diff --git a/libclambcc/CMakeLists.txt b/libclambcc/CMakeLists.txt index dd09b2560b..340caeda6c 100644 --- a/libclambcc/CMakeLists.txt +++ b/libclambcc/CMakeLists.txt @@ -277,21 +277,21 @@ target_link_directories(ClamBCRemoveICMPSLE PRIVATE ${LLVM_LIBRARY_DIRS}) target_link_libraries(ClamBCRemoveICMPSLE PUBLIC ${LLVM_LIBS}) install(TARGETS ClamBCRemoveICMPSLE DESTINATION ${CMAKE_INSTALL_LIBDIR}) -# # -# # The ClamBCRemovePointerPHIs shared library. -# # -# add_library(ClamBCRemovePointerPHIs SHARED -# ClamBCRemovePointerPHIs.cpp) -# target_include_directories(ClamBCRemovePointerPHIs PRIVATE -# ${LLVM_INCLUDE_DIRS}) -# set_target_properties(ClamBCRemovePointerPHIs PROPERTIES -# COMPILE_FLAGS "${WARNCXXFLAGS}" -# VERSION ${LIBCLAMBC_VERSION} -# SOVERSION ${LIBCLAMBC_SOVERSION}) -# #target_compile_definitions(ClamBCRemovePointerPHIs -DLOG_BEFORE_AFTER=1) # For testing -# target_link_directories(ClamBCRemovePointerPHIs PRIVATE ${LLVM_LIBRARY_DIRS}) -# target_link_libraries(ClamBCRemovePointerPHIs PUBLIC ${LLVM_LIBS}) -# install(TARGETS ClamBCRemovePointerPHIs DESTINATION ${CMAKE_INSTALL_LIBDIR}) +# +# The ClamBCRemovePointerPHIs shared library. +# +add_library(ClamBCRemovePointerPHIs SHARED +ClamBCRemovePointerPHIs.cpp) +target_include_directories(ClamBCRemovePointerPHIs PRIVATE +${LLVM_INCLUDE_DIRS}) +set_target_properties(ClamBCRemovePointerPHIs PROPERTIES +COMPILE_FLAGS "${WARNCXXFLAGS}" +VERSION ${LIBCLAMBC_VERSION} +SOVERSION ${LIBCLAMBC_SOVERSION}) +#target_compile_definitions(ClamBCRemovePointerPHIs -DLOG_BEFORE_AFTER=1) # For testing +target_link_directories(ClamBCRemovePointerPHIs PRIVATE ${LLVM_LIBRARY_DIRS}) +target_link_libraries(ClamBCRemovePointerPHIs PUBLIC ${LLVM_LIBS}) +install(TARGETS ClamBCRemovePointerPHIs DESTINATION ${CMAKE_INSTALL_LIBDIR}) # # # # The ClamBCRemoveUndefs shared library. diff --git a/libclambcc/ClamBCRemovePointerPHIs.cpp b/libclambcc/ClamBCRemovePointerPHIs.cpp index b84e7bf4ed..05c398f7e1 100644 --- a/libclambcc/ClamBCRemovePointerPHIs.cpp +++ b/libclambcc/ClamBCRemovePointerPHIs.cpp @@ -247,6 +247,11 @@ class ClamBCRemovePointerPHIs : public PassInfoMixin assert(2 == pgepi->getNumOperands() && "Handle the case of more than 2 operands"); Value *incVal = pgepi->getOperand(1); + + if (incVal->getType() != pType){ + DEBUG_NONPOINTER("SHOULD PROBABLY CHANGE THIS TO CREATE THE INDEX TO BE THE SAME TYPE AS THE incVal"); + incVal = CastInst::CreateIntegerCast(incVal, pType, false, "ClamBCRemovePointerPHIs_cast_", pgepi); + } Instruction *add = BinaryOperator::Create(Instruction::Add, idxNode, incVal, "ClamBCRemovePointerPHIs_add_", pgepi); BasicBlock *pred = findPredecessor(idxNode->getParent(), pgepi->getParent(), omitNodes); @@ -291,17 +296,14 @@ class ClamBCRemovePointerPHIs : public PassInfoMixin public: ClamBCRemovePointerPHIs() {} + /*This is only necessary for 0.103 on windows.*/ virtual PreservedAnalyses run(Module &m, ModuleAnalysisManager &mam) { - - /*Currently unused. Will remove after the RC phase.*/ - DEBUGERR << "TODO: EVALUATE WHETHER OR NOT I NEED THIS" - << "\n"; - return PreservedAnalyses::all(); - pMod = &m; bool ret = false; + llvm::errs() << "<" << __FUNCTION__ << "::" << __LINE__ << ">" << "HAVING ISSUES WITH POINTER PHIS ON 0.103 windows, keep changes isolated to this pass so that we can remove it when we no longer have to support 0.103" << "\n"; + for (auto i = pMod->begin(), e = pMod->end(); i != e; i++) { llvm::Function *pFunc = llvm::dyn_cast(i); if (nullptr == pFunc) { diff --git a/libclambcc/ClamBCWriter.cpp b/libclambcc/ClamBCWriter.cpp index 0a1f4d20d9..dae961dcb6 100644 --- a/libclambcc/ClamBCWriter.cpp +++ b/libclambcc/ClamBCWriter.cpp @@ -811,6 +811,9 @@ class ClamBCWriter : public PassInfoMixin, public InstVisitorgetPointerElementType(); if (not pType->isIntegerTy()) { + DEBUG_VALUE(pGep); + llvm::errs() << "<" << __FUNCTION__ << "::" << __LINE__ << ">" << "EXITING\n"; + exit(11); assert(0 && "ONLY INTEGER TYPES ARE CURRENTLY IMPLEMENTED"); }