/// aliasesPointer - Return true if the specified pointer "may" (or must) /// alias one of the members in the set. /// bool AliasSet::aliasesPointer(const Value *Ptr, uint64_t Size, const MDNode *TBAAInfo, AliasAnalysis &AA) const { if (AliasTy == MustAlias) { assert(UnknownInsts.empty() && "Illegal must alias set!"); // If this is a set of MustAliases, only check to see if the pointer aliases // SOME value in the set. PointerRec *SomePtr = getSomePointer(); assert(SomePtr && "Empty must-alias set??"); return AA.alias(AliasAnalysis::Location(SomePtr->getValue(), SomePtr->getSize(), SomePtr->getTBAAInfo()), AliasAnalysis::Location(Ptr, Size, TBAAInfo)); } // If this is a may-alias set, we have to check all of the pointers in the set // to be sure it doesn't alias the set... for (iterator I = begin(), E = end(); I != E; ++I) if (AA.alias(AliasAnalysis::Location(Ptr, Size, TBAAInfo), AliasAnalysis::Location(I.getPointer(), I.getSize(), I.getTBAAInfo()))) return true; // Check the unknown instructions... if (!UnknownInsts.empty()) { for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) if (AA.getModRefInfo(UnknownInsts[i], AliasAnalysis::Location(Ptr, Size, TBAAInfo)) != AliasAnalysis::NoModRef) return true; } return false; }
/// aliasesPointer - Return true if the specified pointer "may" (or must) /// alias one of the members in the set. /// bool AliasSet::aliasesPointer(const Value *Ptr, unsigned Size, AliasAnalysis &AA) const { if (AliasTy == MustAlias) { assert(CallSites.empty() && "Illegal must alias set!"); // If this is a set of MustAliases, only check to see if the pointer aliases // SOME value in the set... HashNodePair *SomePtr = getSomePointer(); assert(SomePtr && "Empty must-alias set??"); return AA.alias(SomePtr->first, SomePtr->second.getSize(), Ptr, Size); } // If this is a may-alias set, we have to check all of the pointers in the set // to be sure it doesn't alias the set... for (iterator I = begin(), E = end(); I != E; ++I) if (AA.alias(Ptr, Size, I.getPointer(), I.getSize())) return true; // Check the call sites list and invoke list... if (!CallSites.empty()) { if (AA.hasNoModRefInfoForCalls()) return true; for (unsigned i = 0, e = CallSites.size(); i != e; ++i) if (AA.getModRefInfo(CallSites[i], const_cast<Value*>(Ptr), Size) != AliasAnalysis::NoModRef) return true; } return false; }
int Transformer4Trace::getValueIndex(Module* module, Value* v, AliasAnalysis & AA) { v = v->stripPointerCastsNoFollowAliases(); while(isa<GlobalAlias>(v)){ // aliase can be either global or bitcast of global v = ((GlobalAlias*)v)->getAliasee()->stripPointerCastsNoFollowAliases(); } if(isa<GlobalVariable>(v) && ((GlobalVariable*)v)->isConstant()){ return -1; } set<Value*>::iterator it = sharedVariables.begin(); while (it != sharedVariables.end()) { Value * rep = *it; if (AA.alias(v, rep) != AliasAnalysis::NoAlias) { if(sv_idx_map.count(rep)){ return sv_idx_map[rep]; } else { int idx = sv_idx_map.size(); sv_idx_map.insert(pair<Value*, int>(rep, idx)); return idx; } } it++; } return -1; }
/// aliasesPointer - If the specified pointer "may" (or must) alias one of the /// members in the set return the appropriate AliasResult. Otherwise return /// NoAlias. /// AliasResult AliasSet::aliasesPointer(const Value *Ptr, LocationSize Size, const AAMDNodes &AAInfo, AliasAnalysis &AA) const { if (AliasAny) return MayAlias; if (Alias == SetMustAlias) { assert(UnknownInsts.empty() && "Illegal must alias set!"); // If this is a set of MustAliases, only check to see if the pointer aliases // SOME value in the set. PointerRec *SomePtr = getSomePointer(); assert(SomePtr && "Empty must-alias set??"); return AA.alias(MemoryLocation(SomePtr->getValue(), SomePtr->getSize(), SomePtr->getAAInfo()), MemoryLocation(Ptr, Size, AAInfo)); } // If this is a may-alias set, we have to check all of the pointers in the set // to be sure it doesn't alias the set... for (iterator I = begin(), E = end(); I != E; ++I) if (AliasResult AR = AA.alias( MemoryLocation(Ptr, Size, AAInfo), MemoryLocation(I.getPointer(), I.getSize(), I.getAAInfo()))) return AR; // Check the unknown instructions... if (!UnknownInsts.empty()) { for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) if (auto *Inst = getUnknownInst(i)) if (isModOrRefSet( AA.getModRefInfo(Inst, MemoryLocation(Ptr, Size, AAInfo)))) return MayAlias; } return NoAlias; }
bool runOnFunction(Function &F) override { AliasAnalysis AA = getAnalysis<AliasAnalysis>(); DependenceAnalysis *DA = &(getAnalysis<DependenceAnalysis>()); // iterate over basic blocks Function *func = &F; unsigned bb_num = 0; for (Function::iterator BB = func->begin(), BE = func->end(); BB != BE; ++BB) { errs() << "BB-" << bb_num << "\n"; bb_num++; // iterator over instructions unsigned inst_num = 0; for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;++I) { Instruction *Ins = dyn_cast<Instruction>(I); if (!Ins) return false; LoadInst *Ld = dyn_cast<LoadInst>(I); StoreInst *St = dyn_cast<StoreInst>(I); if (!St && !Ld) continue; if (Ld && !Ld->isSimple()) return false; if (St && !St->isSimple()) return false; inst_num++; MemInstr.push_back(&*I); errs() << "MemInst-" << inst_num << ":" << *I << "\n"; } ValueVector::iterator I, IE, J, JE; for (I = MemInstr.begin(), IE = MemInstr.end(); I != IE; ++I) { for (J = I, JE = MemInstr.end(); J != JE; ++J) { std::vector<char> Dep; Instruction *Src = dyn_cast<Instruction>(*I); Instruction *Des = dyn_cast<Instruction>(*J); if (Src == Des) continue; if (isa<LoadInst>(Src) && isa<LoadInst>(Des)) continue; if (auto D = DA->depends(Src, Des, true)) { errs() << "Found Dependency between:\nSrc:" << *Src << "\nDes:" << *Des << "\n"; if (D->isFlow()) { errs () << "Flow dependence not handled"; return false; } if (D->isAnti()) { errs() << "Found Anti dependence \n"; AliasAnalysis::AliasResult AA_dep = AA.alias(Src, Des); AliasAnalysis::AliasResult AA_dep_1 = AA.alias(Des, Src); errs() << "The Ld->St alias result is " << AA_dep << "\n"; errs() << "The St->Ld alias result is " << AA_dep_1 << "\n"; unsigned Levels = D->getLevels(); errs() << "levels = " << Levels << "\n"; char Direction; for (unsigned II = 1; II <= Levels; ++II) { const SCEV *Distance = D->getDistance(II); const SCEVConstant *SCEVConst = dyn_cast_or_null<SCEVConstant>(Distance); if (SCEVConst) { const ConstantInt *CI = SCEVConst->getValue(); //int64_t it_dist = CI->getUniqueInteger().getSExtValue(); //int it_dist = CI->getUniqueInteger().getSExtValue(); unsigned it_dist = abs(CI->getUniqueInteger().getSExtValue()); errs() << "distance is not null\n"; //errs() << "distance = "<< *CI << "\n"; errs() << "distance = "<< it_dist << "\n"; if (CI->isNegative()) Direction = '<'; else if (CI->isZero()) Direction = '='; else Direction = '>'; Dep.push_back(Direction); } else if (D->isScalar(II)) { Direction = 'S'; Dep.push_back(Direction); } else { unsigned Dir = D->getDirection(II); if (Dir == Dependence::DVEntry::LT || Dir == Dependence::DVEntry::LE) Direction = '<'; else if (Dir == Dependence::DVEntry::GT || Dir == Dependence::DVEntry::GE) Direction = '>'; else if (Dir == Dependence::DVEntry::EQ) Direction = '='; else Direction = '*'; Dep.push_back(Direction); } } } } } } } errs() << "------Hello World!--------\n"; return false; }