diff --git a/libclambcc/ClamBCRemovePointerPHIs.cpp b/libclambcc/ClamBCRemovePointerPHIs.cpp index f4080c3708..aafda202dd 100644 --- a/libclambcc/ClamBCRemovePointerPHIs.cpp +++ b/libclambcc/ClamBCRemovePointerPHIs.cpp @@ -20,6 +20,10 @@ using namespace llvm; #include +/* + * This Pass is only needed for 0.103 on Windows, so when we no longer need to support 0.103, it can be removed. + */ + namespace { class ClamBCRemovePointerPHIs : public PassInfoMixin @@ -352,103 +356,6 @@ 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(); - Type * it = Type::getInt32Ty(pMod->getContext()); - pRet = FunctionType::get(vt, {pt, it, pt, it}, false); - - } - -return pRet; - - } - Function * getSaveFunction(){ - static Function * pRet = nullptr; - if (nullptr == pRet){ - FunctionType * ft = getSaveFunctionType(); - pRet = Function::Create(ft, GlobalValue::InternalLinkage, "__save_pointer", pMod); - pRet->addFnAttr(Attribute::OptimizeNone); - pRet->addFnAttr(Attribute::NoInline); - - BasicBlock * pEntry = BasicBlock::Create(pMod->getContext(), "entry", pRet, nullptr); - CastInst * pCast = CastInst::CreatePointerCast(pRet->getArg(0), pRet->getArg(0)->getType()->getPointerTo(), "ClamBCRemovePointerPHIs_pointerCast_", pEntry); - new StoreInst(pRet->getArg(2), pCast, pEntry); - ReturnInst::Create(pMod->getContext(), nullptr, pEntry); - - DEBUG_VALUE(pRet); - - } - return pRet; - } - - void savePointer(Value * src, Value * dst, Instruction * insPt){ - Function * saveFunction = getSaveFunction(); - ConstantInt * pci = ConstantInt::get(Type::getInt32Ty(pMod->getContext()), 8); - CastInst * pCast = CastInst::CreatePointerCast(dst, src->getType(), "ClamBCRemovePointerPHIs_pointerCast_", insPt); - CallInst::Create(getSaveFunctionType(), saveFunction, {pCast, pci, src, pci}, "", insPt); - } - - bool handlePHI2(PHINode *pn) - { - if (not pn->getType()->isPointerTy()) { - return false; - } - - Value *pBasePtr = findBasePointer(pn); - if (nullptr == pBasePtr) { /*No unique base pointer.*/ - return false; - } - - /* Create our storage variable in the first basic block, - * right before the branch instruction.*/ - Function * pFunc = pn->getParent()->getParent(); - BasicBlock * pEntry = llvm::cast(pFunc->begin()); - Instruction * insPt = pEntry->getTerminator(); - AllocaInst * pai = new AllocaInst(pn->getType(), - pFunc->getAddressSpace(), "ClamBCRemovePointerPHIs_", insPt); - - DEBUG_VALUE(pn); - /* Go to all the locations that are incoming to our phi block, and store - * the value the phi is using as input in our alloca instruction. - */ - for (size_t i = 0; i < pn->getNumIncomingValues(); i++) { - BasicBlock * pBB = pn->getIncomingBlock(i); -#if 0 - Instruction *incoming = llvm::dyn_cast(pn->getIncomingValue(i)); - if (nullptr == incoming){ - DEBUG_VALUE(pn); - DEBUG_VALUE(pn->getIncomingValue(i)); - assert (0 && "HOW DID THIS HAPPEN?"); - } - - insPt = getInsertionPoint(incoming); - new StoreInst(incoming, pai, insPt); -#else - insPt = pBB->getTerminator(); -#if 1 - new StoreInst(pn->getIncomingValue(i), pai, insPt); -#else - savePointer(pn->getIncomingValue(i), pai, insPt); -#endif -#endif - } - - replaceUses(pn, pai); - pn->eraseFromParent(); - - - - return true; - - } - - - public: ClamBCRemovePointerPHIs() {} @@ -458,8 +365,6 @@ return pRet; 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) { @@ -469,15 +374,9 @@ return pRet; for (size_t i = 0; i < phis.size(); i++) { PHINode *pn = phis[i]; -#if 1 if (handlePHI(pn)) { ret = true; } -#else - if (handlePHI2(pn)) { - ret = true; - } -#endif } }