Skip to content

Commit

Permalink
Clean up a bunch of data races reported by Cilkscreen and add per-blo…
Browse files Browse the repository at this point in the history
…ck locks (probably bad for space, but we'll do the big redesign if we need it).
  • Loading branch information
wrwilliams committed Jul 10, 2017
1 parent cec8fc8 commit 24f7a40
Show file tree
Hide file tree
Showing 23 changed files with 218 additions and 205 deletions.
1 change: 0 additions & 1 deletion common/src/string-regex.C
Expand Up @@ -38,7 +38,6 @@
#include <regex.h>
#endif

#include <boost/functional/hash.hpp>

/* This doesn't actually belong here. */
void dedemangle( char * demangled, char * result )
Expand Down
2 changes: 2 additions & 0 deletions dataflowAPI/src/liveness.C
Expand Up @@ -101,6 +101,7 @@ const bitArray& LivenessAnalyzer::getLivenessOut(Block *block, bitArray &allRegs


// OUT(X) = UNION(IN(Y)) for all successors Y of X
boost::lock_guard<Block> g(*block);
const Block::edgelist & target_edges = block -> targets();

liveness_cerr << "getLivenessOut for block [" << hex << block->start() << "," << block->end() << "]" << dec << endl;
Expand Down Expand Up @@ -587,6 +588,7 @@ void *LivenessAnalyzer::getPtrToInstruction(Block *block, Address addr) const{
}
bool LivenessAnalyzer::isExitBlock(Block *block)
{
boost::lock_guard<Block> g(*block);
const Block::edgelist & trgs = block->targets();

bool interprocEdge = false;
Expand Down
10 changes: 9 additions & 1 deletion dataflowAPI/src/slicing.C
Expand Up @@ -671,6 +671,7 @@ Slicer::getSuccessors(
// case may produce multiple new frames, but it
// will not transform any of them (besides changing
// the location)
boost::lock_guard<Block> g(*cand.loc.block);

const Block::edgelist & targets = cand.loc.block->targets();
Block::edgelist::const_iterator eit = targets.begin();
Expand Down Expand Up @@ -806,6 +807,8 @@ Slicer::getPredecessors(
// We force finalizing if necessary
//cand.loc.func->num_blocks();
SingleContextOrInterproc epred(cand.loc.func, true, true);
boost::lock_guard<Block> g(*cand.loc.block);

const Block::edgelist & sources = cand.loc.block->sources();
std::for_each(boost::make_filter_iterator(epred, sources.begin(), sources.end()),
boost::make_filter_iterator(epred, sources.end(), sources.end()),
Expand Down Expand Up @@ -836,6 +839,7 @@ Slicer::handleCall(
ParseAPI::Block * callee = NULL;
ParseAPI::Edge * funlink = NULL;
bool widen = false;
boost::lock_guard<Block> g(*cur.loc.block);

const Block::edgelist & targets = cur.loc.block->targets();
Block::edgelist::const_iterator eit = targets.begin();
Expand Down Expand Up @@ -1029,7 +1033,8 @@ Slicer::handleReturn(

// Find successor
ParseAPI::Block * retBlock = NULL;

boost::lock_guard<Block> g(*cur.loc.block);

const Block::edgelist & targets = cur.loc.block->targets();
Block::edgelist::const_iterator eit = targets.begin();
for(; eit != targets.end(); ++eit) {
Expand Down Expand Up @@ -1079,6 +1084,7 @@ Slicer::handleReturnDetails(

static bool EndsWithConditionalJump(ParseAPI::Block *b) {
bool cond = false;
boost::lock_guard<Block> g(*b);
for (auto eit = b->targets().begin(); eit != b->targets().end(); ++eit)
if ((*eit)->type() == COND_TAKEN) cond = true;
return cond;
Expand Down Expand Up @@ -1323,6 +1329,7 @@ Address SliceNode::addr() const {
bool containsCall(ParseAPI::Block *block) {
// We contain a call if the out-edges include
// either a CALL or a CALL_FT edge
boost::lock_guard<Block> g(*block);
const Block::edgelist &targets = block->targets();
Block::edgelist::const_iterator eit = targets.begin();
for (; eit != targets.end(); ++eit) {
Expand All @@ -1335,6 +1342,7 @@ bool containsCall(ParseAPI::Block *block) {
bool containsRet(ParseAPI::Block *block) {
// We contain a call if the out-edges include
// either a CALL or a CALL_FT edge
boost::lock_guard<Block> g(*block);
const Block::edgelist &targets = block->targets();
Block::edgelist::const_iterator eit = targets.begin();
for (; eit != targets.end(); ++eit) {
Expand Down
9 changes: 9 additions & 0 deletions dataflowAPI/src/stackanalysis.C
Expand Up @@ -264,6 +264,7 @@ void StackAnalysis::summarizeBlocks(bool verbose) {
}

// Add blocks reachable from this one to the work stack
boost::lock_guard<Block> g(*block);
const Block::edgelist &targs = block->targets();
std::for_each(
boost::make_filter_iterator(epred, targs.begin(), targs.end()),
Expand Down Expand Up @@ -338,6 +339,7 @@ void StackAnalysis::fixpoint(bool verbose) {
}

// Step 4: push all children on the worklist.
boost::lock_guard<Block> g(*block);
const Block::edgelist &outEdges = block->targets();
std::for_each(
boost::make_filter_iterator(epred2, outEdges.begin(), outEdges.end()),
Expand Down Expand Up @@ -365,6 +367,7 @@ void getRetAndTailCallBlocks(Function *func, std::set<Block *> &retBlocks) {
Block *currBlock = workstack.top();
workstack.pop();

boost::lock_guard<Block> g(*currBlock);
const Block::edgelist &targs = currBlock->targets();
for (auto iter = targs.begin(); iter != targs.end(); iter++) {
Edge *currEdge = *iter;
Expand Down Expand Up @@ -492,6 +495,7 @@ void StackAnalysis::summaryFixpoint() {
(*blockEffects)[block].accumulate(input, blockSummaryOutputs[block]);

// Step 4: push all children on the worklist.
boost::lock_guard<Block> g(*block);
const Block::edgelist &outEdges = block->targets();
std::for_each(
boost::make_filter_iterator(epred2, outEdges.begin(), outEdges.end()),
Expand Down Expand Up @@ -2453,6 +2457,7 @@ bool StackAnalysis::handleNormalCall(Instruction::Ptr insn, Block *block,
if (off != block->lastInsnAddr()) return false;

Address calledAddr = 0;
boost::lock_guard<Block> g(*block);
const Block::edgelist &outs = block->targets();
for (auto eit = outs.begin(); eit != outs.end(); eit++) {
Edge *edge = *eit;
Expand Down Expand Up @@ -2623,6 +2628,7 @@ bool StackAnalysis::handleNormalCall(Instruction::Ptr insn, Block *block,
bool StackAnalysis::handleJump(Instruction::Ptr insn, Block *block, Offset off,
TransferFuncs &xferFuncs, TransferSet &funcSummary) {
Address calledAddr = 0;
boost::lock_guard<Block> g(*block);
const Block::edgelist &outs = block->targets();
for (auto eit = outs.begin(); eit != outs.end(); eit++) {
Edge *edge = *eit;
Expand Down Expand Up @@ -2876,6 +2882,8 @@ void StackAnalysis::meetInputs(Block *block, AbslocState &blockInput,
intra_nosink_nocatch epred2;

stackanalysis_printf("\t ... In edges: ");
boost::lock_guard<Block> g(*block);

const Block::edgelist & inEdges = block->sources();
std::for_each(
boost::make_filter_iterator(epred2, inEdges.begin(), inEdges.end()),
Expand All @@ -2893,6 +2901,7 @@ void StackAnalysis::meetSummaryInputs(Block *block, TransferSet &blockInput,
TransferSet &input) {
input.clear();
intra_nosink_nocatch epred2;
boost::lock_guard<Block> g(*block);

const Block::edgelist & inEdges = block->sources();
std::for_each(
Expand Down
16 changes: 1 addition & 15 deletions instructionAPI/src/InstructionDecoderImpl.C
Expand Up @@ -74,23 +74,9 @@ namespace Dyninst
case Arch_aarch64:
return Ptr(new InstructionDecoder_aarch64(a));
default:
assert(0);
return Ptr();
}
// static TLS_VAR std::map<Architecture, InstructionDecoderImpl::Ptr> impls;
// if(impls.empty())
// {
// impls[Arch_x86] = Ptr(new InstructionDecoder_x86(Arch_x86));
// impls[Arch_x86_64] = Ptr(new InstructionDecoder_x86(Arch_x86_64));
// impls[Arch_ppc32] = Ptr(new InstructionDecoder_power(Arch_ppc32));
// impls[Arch_ppc64] = Ptr(new InstructionDecoder_power(Arch_ppc64));
// impls[Arch_aarch64] = Ptr(new InstructionDecoder_aarch64(Arch_aarch64));
// }
// std::map<Architecture, Ptr>::const_iterator foundImpl = impls.find(a);
// if(foundImpl == impls.end())
// {
// return Ptr();
// }
// return foundImpl->second;
}
Expression::Ptr InstructionDecoderImpl::makeAddExpression(Expression::Ptr lhs,
Expression::Ptr rhs, Result_Type resultType)
Expand Down
11 changes: 9 additions & 2 deletions parseAPI/h/CFG.h
Expand Up @@ -285,9 +285,11 @@ class Function;
};

class CodeRegion;

class PARSER_EXPORT Block :
public Dyninst::SimpleInterval<Address, int>,
public allocatable {
public Dyninst::SimpleInterval<Address, int>,
public allocatable,
public boost::lockable_adapter<boost::recursive_mutex> {
friend class CFGModifier;
friend class Parser;
public:
Expand Down Expand Up @@ -381,16 +383,19 @@ class PARSER_EXPORT Block :

inline void Block::addSource(Edge * e)
{
boost::lock_guard<Block> g(*this);
_srclist.push_back(e);
}

inline void Block::addTarget(Edge * e)
{
boost::lock_guard<Block> g(*this);
_trglist.push_back(e);
}

inline void Block::removeTarget(Edge * e)
{
boost::lock_guard<Block> g(*this);
for(unsigned i=0;i<_trglist.size();++i) {
if(_trglist[i] == e) {
_trglist[i] = _trglist.back();
Expand All @@ -401,6 +406,8 @@ inline void Block::removeTarget(Edge * e)
}

inline void Block::removeSource(Edge * e) {

boost::lock_guard<Block> g(*this);
for(unsigned i=0;i<_srclist.size();++i) {
if(_srclist[i] == e) {
_srclist[i] = _srclist.back();
Expand Down
2 changes: 1 addition & 1 deletion parseAPI/h/CodeSource.h
Expand Up @@ -244,7 +244,7 @@ class PARSER_EXPORT SymtabCodeRegion : public CodeRegion {
SymtabAPI::Region * symRegion() const { return _region; }
};

class PARSER_EXPORT SymtabCodeSource : public CodeSource {
class PARSER_EXPORT SymtabCodeSource : public CodeSource, public boost::lockable_adapter<boost::recursive_mutex> {
private:
SymtabAPI::Symtab * _symtab;
bool owns_symtab;
Expand Down
1 change: 1 addition & 0 deletions parseAPI/src/BoundFactCalculator.C
Expand Up @@ -48,6 +48,7 @@ static void BuildEdgeFromVirtualEntry(SliceNode::Ptr virtualEntry,
}
if (visit.find(curBlock) != visit.end()) return;
visit.insert(curBlock);
boost::lock_guard<Block> g(*curBlock);
for (auto eit = curBlock->targets().begin(); eit != curBlock->targets().end(); ++eit)
if ((*eit)->type() != CALL && (*eit)->type() != RET) {
BuildEdgeFromVirtualEntry(virtualEntry, (*eit)->trg(), targetMap, visit, slice);
Expand Down
1 change: 1 addition & 0 deletions parseAPI/src/CFGModifier.C
Expand Up @@ -66,6 +66,7 @@ bool CFGModifier::redirect(Edge *edge, Block *target) {
// if the source block has a sink edge of the same type, remove this edge
bool hasSink = false;
if (linkToSink) {
boost::lock_guard<Block> g(*edge->src());
const Block::edgelist & trgs = edge->src()->targets();
for (Block::edgelist::const_iterator titer = trgs.begin(); titer != trgs.end(); titer++) {
if ((*titer)->sinkEdge() && (*titer)->type() == edge->type()) {
Expand Down
2 changes: 2 additions & 0 deletions parseAPI/src/CodeObject.C
Expand Up @@ -229,6 +229,7 @@ CodeObject::parseNewEdges( vector<NewEdgeToParse> & worklist )
// don't add edges that already exist
// (this could happen because of shared code)
bool edgeExists = false;
boost::lock_guard<Block> g(*worklist[idx].source);
const Block::edgelist & existingTs = worklist[idx].source->targets();
for (Block::edgelist::const_iterator tit = existingTs.begin();
tit != existingTs.end();
Expand All @@ -251,6 +252,7 @@ CodeObject::parseNewEdges( vector<NewEdgeToParse> & worklist )
fit != funcs.end();
fit++)
{
boost::lock_guard<Block> g(*worklist[idx].source);
const Block::edgelist & tedges = worklist[idx].source->targets();
for(Block::edgelist::const_iterator eit = tedges.begin();
eit != tedges.end();
Expand Down

0 comments on commit 24f7a40

Please sign in to comment.