Skip to content

Commit 62dd49a

Browse files
committed
CODE CLEANUP, IF ANYTHING IS BROKEN, START HERE
1 parent 5744d8b commit 62dd49a

File tree

1 file changed

+4
-105
lines changed

1 file changed

+4
-105
lines changed

libclambcc/ClamBCRemovePointerPHIs.cpp

Lines changed: 4 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ using namespace llvm;
2020
#include <set>
2121

2222

23+
/*
24+
* This Pass is only needed for 0.103 on Windows, so when we no longer need to support 0.103, it can be removed.
25+
*/
26+
2327
namespace
2428
{
2529
class ClamBCRemovePointerPHIs : public PassInfoMixin<ClamBCRemovePointerPHIs>
@@ -352,103 +356,6 @@ class ClamBCRemovePointerPHIs : public PassInfoMixin<ClamBCRemovePointerPHIs>
352356

353357
}
354358

355-
FunctionType * getSaveFunctionType(){
356-
static FunctionType * pRet = nullptr;
357-
358-
if (nullptr == pRet){
359-
360-
Type * vt = Type::getVoidTy(pMod->getContext());
361-
Type * pt = Type::getInt8Ty(pMod->getContext())->getPointerTo();
362-
Type * it = Type::getInt32Ty(pMod->getContext());
363-
pRet = FunctionType::get(vt, {pt, it, pt, it}, false);
364-
365-
}
366-
367-
return pRet;
368-
369-
}
370-
Function * getSaveFunction(){
371-
static Function * pRet = nullptr;
372-
if (nullptr == pRet){
373-
FunctionType * ft = getSaveFunctionType();
374-
pRet = Function::Create(ft, GlobalValue::InternalLinkage, "__save_pointer", pMod);
375-
pRet->addFnAttr(Attribute::OptimizeNone);
376-
pRet->addFnAttr(Attribute::NoInline);
377-
378-
BasicBlock * pEntry = BasicBlock::Create(pMod->getContext(), "entry", pRet, nullptr);
379-
CastInst * pCast = CastInst::CreatePointerCast(pRet->getArg(0), pRet->getArg(0)->getType()->getPointerTo(), "ClamBCRemovePointerPHIs_pointerCast_", pEntry);
380-
new StoreInst(pRet->getArg(2), pCast, pEntry);
381-
ReturnInst::Create(pMod->getContext(), nullptr, pEntry);
382-
383-
DEBUG_VALUE(pRet);
384-
385-
}
386-
return pRet;
387-
}
388-
389-
void savePointer(Value * src, Value * dst, Instruction * insPt){
390-
Function * saveFunction = getSaveFunction();
391-
ConstantInt * pci = ConstantInt::get(Type::getInt32Ty(pMod->getContext()), 8);
392-
CastInst * pCast = CastInst::CreatePointerCast(dst, src->getType(), "ClamBCRemovePointerPHIs_pointerCast_", insPt);
393-
CallInst::Create(getSaveFunctionType(), saveFunction, {pCast, pci, src, pci}, "", insPt);
394-
}
395-
396-
bool handlePHI2(PHINode *pn)
397-
{
398-
if (not pn->getType()->isPointerTy()) {
399-
return false;
400-
}
401-
402-
Value *pBasePtr = findBasePointer(pn);
403-
if (nullptr == pBasePtr) { /*No unique base pointer.*/
404-
return false;
405-
}
406-
407-
/* Create our storage variable in the first basic block,
408-
* right before the branch instruction.*/
409-
Function * pFunc = pn->getParent()->getParent();
410-
BasicBlock * pEntry = llvm::cast<BasicBlock>(pFunc->begin());
411-
Instruction * insPt = pEntry->getTerminator();
412-
AllocaInst * pai = new AllocaInst(pn->getType(),
413-
pFunc->getAddressSpace(), "ClamBCRemovePointerPHIs_", insPt);
414-
415-
DEBUG_VALUE(pn);
416-
/* Go to all the locations that are incoming to our phi block, and store
417-
* the value the phi is using as input in our alloca instruction.
418-
*/
419-
for (size_t i = 0; i < pn->getNumIncomingValues(); i++) {
420-
BasicBlock * pBB = pn->getIncomingBlock(i);
421-
#if 0
422-
Instruction *incoming = llvm::dyn_cast<Instruction>(pn->getIncomingValue(i));
423-
if (nullptr == incoming){
424-
DEBUG_VALUE(pn);
425-
DEBUG_VALUE(pn->getIncomingValue(i));
426-
assert (0 && "HOW DID THIS HAPPEN?");
427-
}
428-
429-
insPt = getInsertionPoint(incoming);
430-
new StoreInst(incoming, pai, insPt);
431-
#else
432-
insPt = pBB->getTerminator();
433-
#if 1
434-
new StoreInst(pn->getIncomingValue(i), pai, insPt);
435-
#else
436-
savePointer(pn->getIncomingValue(i), pai, insPt);
437-
#endif
438-
#endif
439-
}
440-
441-
replaceUses(pn, pai);
442-
pn->eraseFromParent();
443-
444-
445-
446-
return true;
447-
448-
}
449-
450-
451-
452359
public:
453360
ClamBCRemovePointerPHIs() {}
454361

@@ -458,8 +365,6 @@ return pRet;
458365
pMod = &m;
459366
bool ret = false;
460367

461-
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" << "<END>\n";
462-
463368
for (auto i = pMod->begin(), e = pMod->end(); i != e; i++) {
464369
llvm::Function *pFunc = llvm::dyn_cast<Function>(i);
465370
if (nullptr == pFunc) {
@@ -469,15 +374,9 @@ return pRet;
469374
for (size_t i = 0; i < phis.size(); i++) {
470375
PHINode *pn = phis[i];
471376

472-
#if 1
473377
if (handlePHI(pn)) {
474378
ret = true;
475379
}
476-
#else
477-
if (handlePHI2(pn)) {
478-
ret = true;
479-
}
480-
#endif
481380
}
482381
}
483382

0 commit comments

Comments
 (0)