// // For a given BasicBlock, compute which variables are used. // Assignments DataFlowUtil::uses(const BasicBlock& block) { Assignments useSet; for (BasicBlock::const_reverse_iterator it = block.rbegin(); it != block.rend(); ++it) { const Instruction& instr = *it; const User* user = &instr; // iterate through all operands User::const_op_iterator OI, OE; for(OI = user->op_begin(), OE = user->op_end(); OI != OE; ++OI) { Value* val = *OI; // check if the operand is used if ((isa<Instruction>(val) || isa<Argument>(val)) && (!isa<PHINode>(val))) { useSet.insert(Assignment(val)); } } useSet.erase(Assignment(&instr)); } return useSet; }
// // The following functions perform basic set operations in O(n*log(m)) time, // where m and n are the sizes of the sets. For our purposes, this is fast // enough. // // The result of these operations is stored back into the 1st argument. // void DataFlowUtil::setSubtract(Assignments& dest, const Assignments& src) { for (Assignments::const_iterator i = src.begin(); i != src.end(); ++i) { const Assignment& sub = *i; dest.erase(sub); } }