Skip to content

Commit

Permalink
clam-format
Browse files Browse the repository at this point in the history
  • Loading branch information
ragusaa committed May 3, 2024
1 parent 135927c commit f427bd8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion libclambcc/ClamBCChangeMallocArgSize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class ChangeMallocArgSize : public PassInfoMixin<ChangeMallocArgSize>

virtual PreservedAnalyses run(Module& m, ModuleAnalysisManager& MAM)
{
pMod = &m;
pMod = &m;
dstType = Type::getInt64Ty(pMod->getContext());

findSizes();
Expand Down
13 changes: 7 additions & 6 deletions libclambcc/ClamBCRebuild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,10 @@ class ClamBCRebuild : public PassInfoMixin<ClamBCRebuild>, public InstVisitor<Cl
* In addition to being inefficient, the excessive casting was causing
* issues in 0.103 and 0.105.
*/
Value * findDuplicateType(Value * v, Type * t){
if (BitCastInst * bci = llvm::dyn_cast<BitCastInst>(v)){
if (bci->getSrcTy() == t){
Value *findDuplicateType(Value *v, Type *t)
{
if (BitCastInst *bci = llvm::dyn_cast<BitCastInst>(v)) {
if (bci->getSrcTy() == t) {
return bci->getOperand(0);
}

Expand All @@ -327,8 +328,8 @@ class ClamBCRebuild : public PassInfoMixin<ClamBCRebuild>, public InstVisitor<Cl
Value *makeCast(Value *V, Type *Ty)
{

Value * v = findDuplicateType(V, Ty);
if (v){
Value *v = findDuplicateType(V, Ty);
if (v) {
return v;
}

Expand Down Expand Up @@ -541,7 +542,7 @@ class ClamBCRebuild : public PassInfoMixin<ClamBCRebuild>, public InstVisitor<Cl
} else if (Ty->isPointerTy()) { // A CompositeType

/*This appears to be necessary for 0.103 on windows.*/
if (Ty != i8pTy){
if (Ty != i8pTy) {
V = Builder->CreatePointerCast(V, i8pTy, "ClamBCRebuild");
}

Expand Down
43 changes: 21 additions & 22 deletions libclambcc/ClamBCRemovePointerPHIs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ using namespace llvm;

#include <set>


/*
* This Pass is only needed for 0.103 on Windows, so when we no longer need to support 0.103, it can be removed.
*/
Expand Down Expand Up @@ -231,7 +230,7 @@ class ClamBCRemovePointerPHIs : public PassInfoMixin<ClamBCRemovePointerPHIs>
std::vector<Instruction *> newInsts;
Instruction *insPt = findFirstNonPHI(pn->getParent());

if (pBasePtr->getType() != pn->getType()){
if (pBasePtr->getType() != pn->getType()) {
pBasePtr = CastInst::CreatePointerCast(pBasePtr, pn->getType(), "ClamBCRemovePointerPHIs_cast_", insPt);
}

Expand All @@ -256,8 +255,8 @@ class ClamBCRemovePointerPHIs : public PassInfoMixin<ClamBCRemovePointerPHIs>
assert(2 == pgepi->getNumOperands() && "Handle the case of more than 2 operands");

Value *incVal = pgepi->getOperand(1);
if (incVal->getType() != pType){

if (incVal->getType() != pType) {
incVal = CastInst::CreateIntegerCast(incVal, pType, false, "ClamBCRemovePointerPHIs_cast_", pgepi);
}

Expand Down Expand Up @@ -303,16 +302,17 @@ class ClamBCRemovePointerPHIs : public PassInfoMixin<ClamBCRemovePointerPHIs>

/*The idea here is that we get the insertion point for where our calculated value
* will be saved. pInst is the value we want to save, so it will have to be*/
Instruction * getInsertionPoint(Instruction * pInst){
BasicBlock * pBB = pInst->getParent();
bool canBreak = false;
Instruction * pRet = nullptr;
for (auto i = pBB->begin(), e = pBB->end(); i != e; i++){
Instruction *getInsertionPoint(Instruction *pInst)
{
BasicBlock *pBB = pInst->getParent();
bool canBreak = false;
Instruction *pRet = nullptr;
for (auto i = pBB->begin(), e = pBB->end(); i != e; i++) {
pRet = llvm::cast<Instruction>(i);
if (canBreak && (not llvm::isa<PHINode>(pRet))){
if (canBreak && (not llvm::isa<PHINode>(pRet))) {
break;
}
if (pRet == pInst){
if (pRet == pInst) {
canBreak = true;
}
}
Expand All @@ -321,7 +321,8 @@ class ClamBCRemovePointerPHIs : public PassInfoMixin<ClamBCRemovePointerPHIs>

/* Load the value from our AllocaInst, and
* replace the PHINode everywhere it is used.*/
virtual void replaceUses(PHINode * pn, AllocaInst * pai){
virtual void replaceUses(PHINode *pn, AllocaInst *pai)
{
std::vector<Instruction *> users;
for (auto i = pn->user_begin(), e = pn->user_end(); i != e; i++) {
if (Instruction *pUser = llvm::dyn_cast<Instruction>(*i)) {
Expand All @@ -331,11 +332,11 @@ class ClamBCRemovePointerPHIs : public PassInfoMixin<ClamBCRemovePointerPHIs>

for (size_t i = 0; i < users.size(); i++) {
Instruction *pUser = users[i];
Instruction * insPt = nullptr;
Instruction *insPt = nullptr;

if (PHINode * pnUser = llvm::dyn_cast<PHINode>(pUser)){
for (size_t j = 0; j < pnUser->getNumIncomingValues(); j++){
if (pn == pnUser->getIncomingValue(j)){
if (PHINode *pnUser = llvm::dyn_cast<PHINode>(pUser)) {
for (size_t j = 0; j < pnUser->getNumIncomingValues(); j++) {
if (pn == pnUser->getIncomingValue(j)) {
insPt = pnUser->getIncomingBlock(j)->getTerminator();
break;
}
Expand All @@ -344,17 +345,15 @@ class ClamBCRemovePointerPHIs : public PassInfoMixin<ClamBCRemovePointerPHIs>
insPt = pUser;
}

LoadInst * pli = new LoadInst(pn->getType(), pai, "ClamBCRemovePointerPHIs_load_", insPt);
for (size_t j = 0; j < pUser->getNumOperands(); j++){
if (pn == pUser->getOperand(j)){
LoadInst *pli = new LoadInst(pn->getType(), pai, "ClamBCRemovePointerPHIs_load_", insPt);
for (size_t j = 0; j < pUser->getNumOperands(); j++) {
if (pn == pUser->getOperand(j)) {
pUser->setOperand(j, pli);
break;
}
}

}

}
}

public:
ClamBCRemovePointerPHIs() {}
Expand Down
10 changes: 5 additions & 5 deletions libclambcc/ClamBCVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,15 @@ class ClamBCVerifier : public PassInfoMixin<ClamBCVerifier>,
Function *getCalledFunctionFromCallInst(CallInst *pci)
{

Value * pCalledOperand = pci->getCalledOperand();
Function * ret = llvm::dyn_cast<Function>(pCalledOperand);
if (nullptr == ret){
if (BitCastOperator * bco = llvm::dyn_cast<BitCastOperator>(pCalledOperand)){
Value *pCalledOperand = pci->getCalledOperand();
Function *ret = llvm::dyn_cast<Function>(pCalledOperand);
if (nullptr == ret) {
if (BitCastOperator *bco = llvm::dyn_cast<BitCastOperator>(pCalledOperand)) {
ret = llvm::dyn_cast<Function>(bco->getOperand(0));
}
}

if (nullptr == ret){
if (nullptr == ret) {
ClamBCStop("Verifier unable to get called function from call instruction", pci);
}

Expand Down

0 comments on commit f427bd8

Please sign in to comment.