From 27756ab3de0f736fe9a6771d6cc55f4d250d056f Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Fri, 15 Dec 2023 12:29:29 -0800 Subject: [PATCH] blah --- clambcc/clambc-compiler.py | 2 - libclambcc/CMakeLists.txt | 2 +- .../ClamBCRemovePointerPHIs.cpp | 22 +--- .../ClamBCRemoveSelectInsts.cpp | 116 ------------------ .../ClamBCRemoveUndefs/ClamBCRemoveUndefs.cpp | 17 +++ 5 files changed, 20 insertions(+), 139 deletions(-) delete mode 100644 libclambcc/ClamBCRemoveSelectInsts/ClamBCRemoveSelectInsts.cpp diff --git a/clambcc/clambc-compiler.py b/clambcc/clambc-compiler.py index 23e3240a6d..ac45b6dd60 100755 --- a/clambcc/clambc-compiler.py +++ b/clambcc/clambc-compiler.py @@ -553,8 +553,6 @@ def createInputSourceFile(clangLLVM: ClangLLVM, name: str, args: list, options: , 'verify' , 'clambc-remove-fshl' , 'verify' - , 'clambc-remove-pointer-phis' - , 'verify' , 'clambc-lowering-notfinal' # perform lowering pass , 'verify' , 'lowerswitch' diff --git a/libclambcc/CMakeLists.txt b/libclambcc/CMakeLists.txt index 04f7cf2182..6ce9fdd8aa 100644 --- a/libclambcc/CMakeLists.txt +++ b/libclambcc/CMakeLists.txt @@ -8,7 +8,7 @@ add_subdirectory(ClamBCPreserveABIs) add_subdirectory(ClamBCAnalyzer) add_subdirectory(Common) add_subdirectory(ClamBCVerifier) -add_subdirectory(ClamBCRemovePointerPHIs) +#add_subdirectory(ClamBCRemovePointerPHIs) add_subdirectory(ClamBCLowering) add_subdirectory(ClamBCRemoveFreezeInsts) add_subdirectory(ClamBCWriter) diff --git a/libclambcc/ClamBCRemovePointerPHIs/ClamBCRemovePointerPHIs.cpp b/libclambcc/ClamBCRemovePointerPHIs/ClamBCRemovePointerPHIs.cpp index 27164d489f..bef2c7ac82 100644 --- a/libclambcc/ClamBCRemovePointerPHIs/ClamBCRemovePointerPHIs.cpp +++ b/libclambcc/ClamBCRemovePointerPHIs/ClamBCRemovePointerPHIs.cpp @@ -22,11 +22,9 @@ using namespace llvm; namespace { -//class ClambcRemovePointerPHIs : public FunctionPass class ClamBCRemovePointerPHIs : public PassInfoMixin { protected: - //Function *pFunc = nullptr; llvm::Module * pMod = nullptr; std::vector gatherPHIs(llvm::Function * pFunc) @@ -182,7 +180,6 @@ class ClamBCRemovePointerPHIs : public PassInfoMixin if (not pn->getType()->isPointerTy()) { return false; } - //std::vector delLst; Value *pBasePtr = findBasePointer(pn); if (nullptr == pBasePtr) { /*No unique base pointer.*/ @@ -293,17 +290,12 @@ class ClamBCRemovePointerPHIs : public PassInfoMixin } public: -// static char ID; - ClamBCRemovePointerPHIs() - /*: FunctionPass(ID)*/ {} + ClamBCRemovePointerPHIs() {} -#if 0 - bool runOnFunction(Function &F) override -#else virtual PreservedAnalyses run(Module & m, ModuleAnalysisManager & mam) -#endif { + /*Currently unused. Will remove after the RC phase.*/ DEBUGERR << "TODO: EVALUATE WHETHER OR NOT I NEED THIS" << "\n"; return PreservedAnalyses::all(); pMod = &m; @@ -334,14 +326,6 @@ class ClamBCRemovePointerPHIs : public PassInfoMixin } // end of anonymous namespace -#if 0 -char ClambcRemovePointerPHIs::ID = 0; -static RegisterPass X("clambc-remove-pointer-phis", "Remove PHI Nodes with pointers", - false /* Only looks at CFG */, - false /* Analysis Pass */); -#else - - // This part is the new way of registering your pass extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK llvmGetPassPluginInfo() { @@ -365,6 +349,4 @@ llvmGetPassPluginInfo() { -#endif - diff --git a/libclambcc/ClamBCRemoveSelectInsts/ClamBCRemoveSelectInsts.cpp b/libclambcc/ClamBCRemoveSelectInsts/ClamBCRemoveSelectInsts.cpp deleted file mode 100644 index 012c91773b..0000000000 --- a/libclambcc/ClamBCRemoveSelectInsts/ClamBCRemoveSelectInsts.cpp +++ /dev/null @@ -1,116 +0,0 @@ - -#include -#include "llvm/IR/Function.h" -#include "llvm/IR/Module.h" -#include "llvm/IR/Instructions.h" -#include "llvm/Support/raw_ostream.h" - -#include "llvm/IR/LegacyPassManager.h" -#include "llvm/Transforms/IPO/PassManagerBuilder.h" - -#include "Common/clambc.h" - -using namespace llvm; - -namespace -{ -class RemoveSelectInsts : public ModulePass -{ - protected: - bool bChanged = false; - Module* pMod = nullptr; - - void processBasicBlock(BasicBlock* pBB, std::vector& selects) - { - for (auto i = pBB->begin(), e = pBB->end(); i != e; i++) { - SelectInst* pSelect = llvm::dyn_cast(i); - if (pSelect) { - selects.push_back(pSelect); - } - } - } - - void processFunction(Function* pFunc, std::vector& selects) - { - for (auto i = pFunc->begin(), e = pFunc->end(); i != e; i++) { - BasicBlock* pBB = llvm::cast(i); - processBasicBlock(pBB, selects); - } - } - - std::vector gatherSelects() - { - std::vector selects; - for (auto i = pMod->begin(), e = pMod->end(); i != e; i++) { - Function* pFunc = llvm::cast(i); - - processFunction(pFunc, selects); - } - - return selects; - } - - Instruction* getAllocaInsertPoint(SelectInst* pSelect) - { - BasicBlock* entryBlock = llvm::cast(pSelect->getParent()->getParent()->begin()); - for (auto i = entryBlock->begin(), e = entryBlock->end(); i != e; i++) { - Instruction* pInst = llvm::cast(i); - if (not llvm::isa(pInst)) { - return pInst; - } - } - - assert(0 && "MALFORMED BASIC BLOCK"); - return nullptr; - } - - void replaceSelectInst(SelectInst* pSelect) - { - - Instruction* insertBefore = getAllocaInsertPoint(pSelect); - AllocaInst* pAlloca = new AllocaInst(pSelect->getType(), - pMod->getDataLayout().getProgramAddressSpace(), - "ClamBCRemoveSelectInst", insertBefore); - - BasicBlock* pBB = llvm::cast(pSelect->getParent()); - - BasicBlock* pSplit = pBB->splitBasicBlock(pSelect, "ClamBCRemoveSelectInst"); - new StoreInst(pSelect->getFalseValue(), pAlloca, pBB->getTerminator()); - - new StoreInst(pSelect->getTrueValue(), pAlloca, pSelect); - - BasicBlock* pSplit2 = pSplit->splitBasicBlock(pSelect, "ClamBCRemoveSelectInst"); - BranchInst::Create(pSplit, pSplit2, pSelect->getCondition(), pBB->getTerminator()); - - LoadInst* pLoad = new LoadInst(pAlloca->getType()->getPointerElementType(), pAlloca, "ClamBCRemoveSelectInst", pSelect); - pSelect->replaceAllUsesWith(pLoad); - - pBB->getTerminator()->eraseFromParent(); - pSelect->eraseFromParent(); - } - - public: - static char ID; - RemoveSelectInsts() - : ModulePass(ID) {} - - virtual bool runOnModule(Module& m) override - { - pMod = &m; - - std::vector selects = gatherSelects(); - for (size_t i = 0; i < selects.size(); i++) { - SelectInst* pSelect = selects[i]; - - replaceSelectInst(pSelect); - } - - return bChanged; - } -}; // end of struct RemoveSelectInsts -} // end of anonymous namespace - -char RemoveSelectInsts::ID = 0; -static RegisterPass X("remove-selects", "RemoveSelectInsts Pass", - false /* Only looks at CFG */, - false /* Analysis Pass */); diff --git a/libclambcc/ClamBCRemoveUndefs/ClamBCRemoveUndefs.cpp b/libclambcc/ClamBCRemoveUndefs/ClamBCRemoveUndefs.cpp index c75fc74479..4d6a717268 100644 --- a/libclambcc/ClamBCRemoveUndefs/ClamBCRemoveUndefs.cpp +++ b/libclambcc/ClamBCRemoveUndefs/ClamBCRemoveUndefs.cpp @@ -16,6 +16,23 @@ #include "Common/ClamBCUtilities.h" using namespace llvm; + + +#if 0 + + +THIS APPEARS TO NO LONGER BE NEEDED. LEAVING IN PLACE DURING THE RC PHASE, JUST IN CASE. + + + +#endif + + + + + + + namespace { /*