Skip to content

Commit

Permalink
blah
Browse files Browse the repository at this point in the history
  • Loading branch information
ragusaa committed Dec 15, 2023
1 parent b677c77 commit a3e1666
Show file tree
Hide file tree
Showing 12 changed files with 5 additions and 1,183 deletions.
4 changes: 0 additions & 4 deletions libclambcc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ add_subdirectory(ClamBCChangeMallocArgSize)
add_subdirectory(ClamBCExtendPHIsTo64Bit)
add_subdirectory(ClamBCRebuild)
add_subdirectory(ClamBCRegAlloc)
#add_subdirectory(ClamBCTypeAnalyzer)
add_subdirectory(ClamBCConvertMemsetsTo32Bit)
add_subdirectory(ClamBCPrepareGEPsForWriter)
add_subdirectory(ClamBCRemoveICMPSLE)
#add_subdirectory(ClamBCRemoveUMIN)
#add_subdirectory(ClamBCRemoveUMAX)
#add_subdirectory(ClamBCRemoveSMAX)
add_subdirectory(ClamBCRemoveUSUB)
add_subdirectory(ClamBCRemoveUnsupportedICMPIntrinsics)
add_subdirectory(ClamBCRemoveFSHL)
67 changes: 1 addition & 66 deletions libclambcc/ClamBCRegAlloc/ClamBCRegAlloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,7 @@ void ClamBCRegAllocAnalysis::handlePHI(PHINode *PN)
++It;
} while (isa<PHINode>(It));
builder.SetInsertPoint(&*It);
#if 0
LoadInst *LI = builder.CreateLoad(AI, ".phiload");
#else
//llvm::errs() << "<" << __LINE__ << ">" << "There is a chance I'll have to do something like getPoinerOperand->getType or something like that, so leave this in here as a reminder to go look\n" << "<END>\n";
LoadInst *LI = builder.CreateLoad(AI->getAllocatedType(), AI, ".phiload");
#endif
builder.SetInstDebugLocation(LI);
PN->replaceAllUsesWith(LI);
PN->eraseFromParent();
Expand All @@ -96,9 +91,6 @@ bool ClamBCRegAllocAnalysis::runOnFunction(Function &F)
{
ValueMap.clear();
RevValueMap.clear();
#if 0
DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
#endif
bool Changed = false;
for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
BasicBlock &BB = *I;
Expand All @@ -119,8 +111,6 @@ bool ClamBCRegAllocAnalysis::runOnFunction(Function &F)
ValueMap[A] = id;
if (RevValueMap.size() == id) {
RevValueMap.push_back(A);
} else {
errs() << id << " " << __FILE__ << ":" << __LINE__ << "\n";
}
++id;
}
Expand All @@ -142,63 +132,26 @@ bool ClamBCRegAllocAnalysis::runOnFunction(Function &F)
{
static int first = 1;
if (first){
DEBUGERR << "TODO: Move these checks to the verifier" << "<END>\n";
first = 0;
first = 0;
}
}
if (CastInst *BC = dyn_cast<CastInst>(II)) {
if (BitCastInst *BCI = dyn_cast<BitCastInst>(BC)) {
if (!BCI->isLosslessCast()) {
ClamBCStop("Non lossless bitcast is not supported", BCI);
}
#if 0
const Type *SrcTy = BC->getOperand(0)->getType();
const Type *DstTy = BC->getType();
const PointerType *SPTy, *DPTy;
while ((SPTy = dyn_cast<PointerType>(SrcTy))) {
DPTy = dyn_cast<PointerType>(DstTy);
if (!DPTy) {
ClamBCStop("Cast from pointer to non-pointer element",
BCI);
}
#if 0
SrcTy = SPTy->getElementType();
DstTy = DPTy->getElementType();
#else

llvm::errs() << "\n\n\n";
DEBUG_VALUE(BCI);
DEBUG_VALUE(BCI->getOperand(0));
DEBUG_NONPOINTER(llvm::isa<TypedPointerType>(SrcTy));
DEBUG_NONPOINTER(llvm::isa<TypedPointerType>(DstTy));


DEBUGERR << "EXITING" << "<END>\n";
exit(1);


/*Don't expect any issues with this change.*/
SrcTy = SPTy->getPointerElementType();
DstTy = DPTy->getPointerElementType();

#endif
}
#else
if (BCI->getSrcTy()->isPointerTy() and (not BCI->getDestTy()->isPointerTy())){
ClamBCStop("Cast from pointer to non-pointer element",
BCI);
}

#endif

if (AllocaInst *AI = dyn_cast<AllocaInst>(BCI->getOperand(0))) {
if (!AI->isArrayAllocation()) {
// we need to use a GEP 0,0 for bitcast here
ValueMap[II] = id;
if (RevValueMap.size() == id) {
RevValueMap.push_back(II);
} else {
errs() << id << " " << __FILE__ << ":" << __LINE__ << "\n";
}
++id;
continue;
Expand Down Expand Up @@ -230,14 +183,6 @@ bool ClamBCRegAllocAnalysis::runOnFunction(Function &F)
}
}
// single-use of load from alloca -> use directly value id of alloca
//TODO: we must check for intervening stores here, better use memdep!
/* if (LoadInst *LI = dyn_cast<LoadInst>(II)) {
if (AllocaInst *AI = dyn_cast<AllocaInst>(LI->getPointerOperand())) {
ValueMap[LI] = getValueID(AI);
SkipMap.insert(LI);
continue;
}
}*/
}
ValueMap[II] = id;
if (RevValueMap.size() == id) {
Expand Down Expand Up @@ -313,15 +258,6 @@ void ClamBCRegAllocAnalysis::getAnalysisUsage(AnalysisUsage &AU) const



#if 0
char ClamBCRegAllocAnalysis::ID = 0;
static RegisterPass<ClamBCRegAlloc> X("clambc-ra",
"ClamAV bytecode register allocator");

const PassInfo *const ClamBCRegAllocID = &X;
#else


// This part is the new way of registering your pass
extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
llvmGetPassPluginInfo() {
Expand All @@ -339,4 +275,3 @@ llvmGetPassPluginInfo() {



#endif
3 changes: 1 addition & 2 deletions libclambcc/ClamBCRegAlloc/ClamBCRegAlloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class ClamBCRegAllocAnalysis
{
public:
static char ID;
explicit ClamBCRegAllocAnalysis()
/* : FunctionPass(ID) */ {}
explicit ClamBCRegAllocAnalysis() {}

unsigned buildReverseMap(std::vector<const llvm::Value *> &);
bool skipInstruction(const llvm::Instruction *I) const
Expand Down
6 changes: 3 additions & 3 deletions libclambcc/ClamBCRemoveFSHL/ClamBCRemoveFSHL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace
}

virtual llvm::Function * addFunction64(IntegerType * functionArgType, const char * const functionName){
/*Will determine if this is necessary during the rc phase.*/
#if 0
This is an example function, needs to be converted to IR
static uint8_t fshl8_noshifts(uint8_t left, uint8_t right, uint8_t shift){
Expand Down Expand Up @@ -137,6 +138,8 @@ static uint8_t fshl8_noshifts(uint8_t left, uint8_t right, uint8_t shift){

virtual ~ClamBCRemoveFSHL() {}

/*TODO:
* Add this to validator.*/
PreservedAnalyses run(Module & m, ModuleAnalysisManager & MAM)
{
pMod = &m;
Expand All @@ -145,9 +148,6 @@ static uint8_t fshl8_noshifts(uint8_t left, uint8_t right, uint8_t shift){
bRet |= replaceCalls("llvm.fshl.i16", ".fshl.i16", Type::getInt16Ty(pMod->getContext()));
bRet |= replaceCalls("llvm.fshl.i8", ".fshl.i8", Type::getInt16Ty(pMod->getContext()));


DEBUGERR << "TODO: ADD fshl detection to the validator" << "<END>\n";

if (bRet){
return PreservedAnalyses::none();
}
Expand Down
72 changes: 0 additions & 72 deletions libclambcc/ClamBCRemoveSMAX/CMakeLists.txt

This file was deleted.

140 changes: 0 additions & 140 deletions libclambcc/ClamBCRemoveSMAX/ClamBCRemoveSMAX.cpp

This file was deleted.

Loading

0 comments on commit a3e1666

Please sign in to comment.