From 3418d67cbd7125147b3f4a25d24d2b3b266a2f3f Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 29 Apr 2024 09:23:55 -0700 Subject: [PATCH] All new sigs are loaded on windows with 0.103. Testing the rest --- clambcc/clambc-compiler.py | 8 ++--- libclambcc/ClamBCRemovePointerPHIs.cpp | 42 ++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/clambcc/clambc-compiler.py b/clambcc/clambc-compiler.py index f932065cee..cb8b304b55 100755 --- a/clambcc/clambc-compiler.py +++ b/clambcc/clambc-compiler.py @@ -548,8 +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-pointer-phis' +# , 'verify' , 'clambc-remove-unsupported-icmp-intrinsics' , 'verify' , 'clambc-remove-usub' @@ -576,8 +576,8 @@ def createInputSourceFile(clangLLVM: ClangLLVM, name: str, args: list, options: , 'verify' , 'clambc-rebuild' , 'verify' -# , 'clambc-remove-pointer-phis' -# , 'verify' + , 'clambc-remove-pointer-phis' + , 'verify' , 'clambc-trace' , 'verify' , 'clambc-outline-endianness-calls' diff --git a/libclambcc/ClamBCRemovePointerPHIs.cpp b/libclambcc/ClamBCRemovePointerPHIs.cpp index 1dce1c0183..830449dd96 100644 --- a/libclambcc/ClamBCRemovePointerPHIs.cpp +++ b/libclambcc/ClamBCRemovePointerPHIs.cpp @@ -356,6 +356,44 @@ class ClamBCRemovePointerPHIs : public PassInfoMixin } + FunctionType * getSaveFunctionType(){ + static FunctionType * pRet = nullptr; + + if (nullptr == pRet){ + + Type * vt = Type::getVoidTy(pMod->getContext()); + Type * pt = Type::getInt8Ty(pMod->getContext())->getPointerTo(); + pRet = FunctionType::get(vt, {pt->getPointerTo(), pt}, false); + + } + +return pRet; + + } + Function * getSaveFunction(){ + static Function * pRet = nullptr; + if (nullptr == pRet){ + FunctionType * ft = getSaveFunctionType(); + pRet = Function::Create(ft, GlobalValue::PrivateLinkage, "__save_pointer", pMod); + pRet->addFnAttr(Attribute::OptimizeNone); + pRet->addFnAttr(Attribute::NoInline); + + BasicBlock * pEntry = BasicBlock::Create(pMod->getContext(), "entry", pRet, nullptr); + new StoreInst(pRet->getArg(1), pRet->getArg(0), pEntry); + ReturnInst::Create(pMod->getContext(), nullptr, pEntry); + + DEBUG_VALUE(pRet); + + } + return pRet; + } + + void savePointer(Value * src, Value * dst, Instruction * insPt){ + Function * saveFunction = getSaveFunction(); + CallInst::Create(getSaveFunctionType(), saveFunction, {dst, src}, "", insPt); + //CallInst::Create(saveFunction->getType(), saveFunction, {dst, src}, "ClamBCRemovePointerPHIs_", insPt); + } + bool handlePHI2(PHINode *pn) { if (not pn->getType()->isPointerTy()) { @@ -393,7 +431,11 @@ class ClamBCRemovePointerPHIs : public PassInfoMixin new StoreInst(incoming, pai, insPt); #else insPt = pBB->getTerminator(); +#if 0 new StoreInst(pn->getIncomingValue(i), pai, insPt); +#else + savePointer(pn->getIncomingValue(i), pai, insPt); +#endif #endif }