Skip to content

Commit

Permalink
formatting cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ragusaa committed Jan 10, 2024
1 parent b1b029e commit 5698a79
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 264 deletions.
2 changes: 1 addition & 1 deletion clambcc/clambc-compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ def createInputSourceFile(clangLLVM: ClangLLVM, name: str, args: list, options:
]

OPTIMIZE_LOADS=[ f"--load {SHARED_OBJ_DIR}/libclambccommon.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcremoveundefs.so"
# , f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcremoveundefs.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcpreserveabis.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcremoveunsupportedicmpintrinsics.so"
, f"--load-pass-plugin {SHARED_OBJ_DIR}/libclambcremoveusub.so"
Expand Down
2 changes: 1 addition & 1 deletion libclambcc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

add_subdirectory(ClamBCLogicalCompiler)
add_subdirectory(ClamBCLogicalCompilerHelper)
add_subdirectory(ClamBCRemoveUndefs)
#add_subdirectory(ClamBCRemoveUndefs)
add_subdirectory(ClamBCPreserveABIs)
add_subdirectory(ClamBCAnalyzer)
add_subdirectory(Common)
Expand Down
95 changes: 1 addition & 94 deletions libclambcc/ClamBCLogicalCompiler/ClamBCLogicalCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,24 +937,6 @@ class LogicalCompiler
}

Instruction *pInst = llvm::cast<Instruction>(I);
#if 0
/*Look through all operands of the instruction and add the
* constants to the logical map, so that we won't fail to create
* the siganture if O3 changes a logical expression to a constant
* at compile time.
*/
for (size_t i = 0; i < pInst->getNumOperands(); i++){
if (ConstantInt * pci = llvm::dyn_cast<ConstantInt>(pInst->getOperand(i))){
if (pci->isOne()){
LogicalNode * ln = LogicalNode::getTrue(allNodes) ;
Map[pci] = ln;
} else if (pci->isZero()){
LogicalNode * ln = LogicalNode::getTrue(allNodes) ;
Map[pci] = ln;
}
}
}
#endif

switch (I->getOpcode()) {
case Instruction::Load:
Expand Down Expand Up @@ -992,30 +974,6 @@ class LogicalCompiler
LogicalMap::iterator FalseNode = Map.find(SI->getFalseValue());


#if 0
if (Map.end() == TrueNode){
Value * pv = SI->getTrueValue();
if (ConstantInt * pci = llvm::dyn_cast<ConstantInt>(pv)){
if (pci->isOne()){
LogicalNode * ln = LogicalNode::getTrue(allNodes) ;
Map[SI->getTrueValue()] = ln;
TrueNode = Map.find(SI->getTrueValue());
}
}
}

#endif


#if 0
if (CondNode == Map.end() || TrueNode == Map.end() || FalseNode == Map.end()) {
assert (0 && "FTT");
printDiagnostic("Logical signature: select operands must be logical"
" expressions",
SI);
return false;
}
#else
/*O3 creates blocks that look like the following, which are legitimate blocks.
* This is essentially an AND of all the %cmp.i<number> instructions.
* Since the cmp instructions all have false at the end, comparisons will be skipped
Expand Down Expand Up @@ -1058,7 +1016,7 @@ class LogicalCompiler
SI);
return false;
}
#endif

// select cond, trueval, falseval -> cond && trueval || !cond && falseval
LogicalNode *N = nullptr;
LogicalNode *NotCond = nullptr;
Expand Down Expand Up @@ -1770,21 +1728,6 @@ bool ClamBCLogicalCompiler::compileVirusNames(Module &M, unsigned kind)
bool Valid = true;

for (auto I : F->users()) {
#if 0
Value *pv = nullptr;
pv = llvm::cast<Value>(I);
CallSite CS(pv);
if (!CS.getInstruction()) {
continue;
}
if (CS.getCalledFunction() != F) {
printDiagnostic("setvirusname can only be directly called",
CS.getInstruction());
Valid = false;
continue;
}
assert(CS.arg_size() == 2 && "setvirusname has 2 args");
#else
CallInst * pCallInst = llvm::cast<CallInst>(I);
if (nullptr == pCallInst){
assert (0 && "NOT sure how this is possible");
Expand All @@ -1801,7 +1744,6 @@ bool ClamBCLogicalCompiler::compileVirusNames(Module &M, unsigned kind)
Valid = false;
continue;
}
#endif

if (2 != pCallInst->arg_size()){
printDiagnostic("setvirusname has 2 args", pCallInst);
Expand All @@ -1811,10 +1753,6 @@ bool ClamBCLogicalCompiler::compileVirusNames(Module &M, unsigned kind)

std::string param;
llvm::StringRef sr;
#if 0
Value *V = CS.getArgument(0);
#else
#endif
Value * V = llvm::cast<Value>(pCallInst->arg_begin());
if (nullptr == V){
printDiagnostic("Invalid argument passed to setvirusname", pCallInst);
Expand Down Expand Up @@ -1846,30 +1784,19 @@ bool ClamBCLogicalCompiler::compileVirusNames(Module &M, unsigned kind)
Value *C = builder.CreateGlobalStringPtr(fullname.c_str());

IntegerType *I32Ty = Type::getInt32Ty(M.getContext());
#if 0
CS.setArgument(0, C);
CS.setArgument(1, ConstantInt::get(I32Ty, fullname.size()));
#else
pCallInst->setArgOperand(0, C);
pCallInst->setArgOperand(1, ConstantInt::get(I32Ty, fullname.size()));
#endif
}
return Valid;
}

#if 0
bool ClamBCLogicalCompiler::runOnModule(Module &M)
#else
PreservedAnalyses ClamBCLogicalCompiler::run(Module & M, ModuleAnalysisManager & MAM)
#endif
{
bool Valid = true;
LogicalSignature = "";
virusnames = "";
pMod = &M;

//dumpPHIGraphs();

// Handle virusname
unsigned kind = 0;
GlobalVariable *GVKind = M.getGlobalVariable("__clambc_kind");
Expand All @@ -1896,12 +1823,8 @@ bool ClamBCLogicalCompiler::runOnModule(Module &M)
}

if (F) {
#if 0
LoopInfo &li = getAnalysis<LoopInfoWrapperPass>(*F).getLoopInfo();
#else
FunctionAnalysisManager &fam = MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
LoopInfo * li = &fam.getResult<LoopAnalysis>(*F);
#endif
if (functionHasLoop(F, *li)) {
printDiagnostic("Logical signature: loop/recursion not supported", F);
Valid = false;
Expand Down Expand Up @@ -2035,20 +1958,6 @@ bool ClamBCLogicalCompiler::runOnModule(Module &M)
return PreservedAnalyses::none();
}

#if 0
const PassInfo *const ClamBCLogicalCompilerID = &X; llvm::ModulePass *createClamBCLogicalCompiler()
{
return new ClamBCLogicalCompiler();
}
#endif


#if 0
char ClamBCLogicalCompiler::ID = 0;
RegisterPass<ClamBCLogicalCompiler> X("clambc-lcompiler",
"ClamAV Logical Compiler");
#else

// This part is the new way of registering your pass
extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
llvmGetPassPluginInfo() {
Expand All @@ -2068,8 +1977,6 @@ llvmGetPassPluginInfo() {
}
};
}
#endif


} // namespace

Expand Down
44 changes: 21 additions & 23 deletions libclambcc/ClamBCRemoveFSHL/ClamBCRemoveFSHL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,28 @@ 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){
uint8_t ret = 0;
uint8_t bitwidth = 8;
uint8_t bitIdx = (2 * bitwidth) - (shift % bitwidth) - 1;
uint8_t bit;

for (size_t i = 0; i < bitwidth; i++){
if (bitIdx >= bitwidth) {
bit = (left & (1 << (bitIdx - bitwidth))) ? 1 : 0;
ret |= (bit << ((bitwidth - 1) - i));
} else {
bit = right & (1 << bitIdx);
ret |= (bit << ((bitwidth - 1) - i));
}
bitIdx-- ;
}

return ret;
}
static uint8_t fshl8_noshifts(uint8_t left, uint8_t right, uint8_t shift){
uint8_t ret = 0;
uint8_t bitwidth = 8;
uint8_t bitIdx = (2 * bitwidth) - (shift % bitwidth) - 1;
uint8_t bit;
for (size_t i = 0; i < bitwidth; i++){
if (bitIdx >= bitwidth) {
bit = (left & (1 << (bitIdx - bitwidth))) ? 1 : 0;
ret |= (bit << ((bitwidth - 1) - i));
} else {
bit = right & (1 << bitIdx);
ret |= (bit << ((bitwidth - 1) - i));
}
bitIdx-- ;
}
#endif
return ret;
}
*/
assert (0 && "Unimplemented");
}

Expand Down Expand Up @@ -138,8 +137,7 @@ static uint8_t fshl8_noshifts(uint8_t left, uint8_t right, uint8_t shift){

virtual ~ClamBCRemoveFSHL() {}

/*TODO:
* Add this to validator.*/
/*TODO: Add this to validator.*/
PreservedAnalyses run(Module & m, ModuleAnalysisManager & MAM)
{
pMod = &m;
Expand Down
88 changes: 0 additions & 88 deletions libclambcc/ClamBCRemoveFSHL/test.c.txt

This file was deleted.

Loading

0 comments on commit 5698a79

Please sign in to comment.