Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
858be15
Remove returnRecordsByRefArguments and all autodestroy calls.
Dec 13, 2014
5164bc1
Make returnStarTuplesByRefArgs() put the return variable write-back i…
Dec 13, 2014
147ac58
Disable the removeUnnecessaryAutoCopyCalls pass.
Dec 18, 2014
18485e9
Add TODOs related to inserted chpl__autoCopy calls.
Dec 22, 2014
e109fdc
Add binary operators to BitVec implementation.
Dec 24, 2014
0ce0527
Initial implementation of flow-based destructor call insertion.
Dec 24, 2014
4b18111
Runs hello.chpl.
Dec 27, 2014
607986c
Rework alias merge. Down to 449 regressions.
Dec 28, 2014
71521e2
Handle some special cases in alias tracking.
Dec 29, 2014
20512c5
Move insertAutoCopyAutoDestroy pass after lowerIterators.
Dec 29, 2014
188ec9e
Add typedefs to the head of bb.h.
Dec 31, 2014
7a592ec
Added operator synonyms for conjunction (&=) and disjunction (|=).
Dec 31, 2014
8dfa029
Added back "insert auto copy" flags in resolution.
Dec 31, 2014
0b28ae8
Moved insertAutoCopyAutoDestroy pass to start of parallel.
Dec 31, 2014
948ac19
Now actually adding autoDestroy calls.
Dec 31, 2014
13416fa
Add autoCopy on const temps; mark return of PRIM_DEREF as unowned.
Jan 1, 2015
ab0d5df
Add insertion of autoCopy calls.
Jan 5, 2015
739d2a7
Update return-record.chpl with initCopy function.
Jan 6, 2015
627d5c7
Added a few more cases to isConsumed(), so that more autoCopy calls a…
Jan 6, 2015
0b21d04
Comment out the clause that prevents insertion of autoCopy calls for …
Jan 6, 2015
7096e71
Strengthened the test in isBitwiseCopy(), so it returns false if the …
Jan 7, 2015
b5ad55a
Remove returnRecordsByRefArguments and all autodestroy calls.
Dec 13, 2014
3f63491
Make returnStarTuplesByRefArgs() put the return variable write-back i…
Dec 13, 2014
10089be
Disable the removeUnnecessaryAutoCopyCalls pass.
Dec 18, 2014
b17fb45
Add TODOs related to inserted chpl__autoCopy calls.
Dec 22, 2014
77ab550
Initial implementation of flow-based destructor call insertion.
Dec 24, 2014
85edee4
Runs hello.chpl.
Dec 27, 2014
ae8a4f3
Rework alias merge. Down to 449 regressions.
Dec 28, 2014
54dd49e
Handle some special cases in alias tracking.
Dec 29, 2014
414406c
Move insertAutoCopyAutoDestroy pass after lowerIterators.
Dec 29, 2014
235452b
Add typedefs to the head of bb.h.
Dec 31, 2014
2aaad47
Added operator synonyms for conjunction (&=) and disjunction (|=).
Dec 31, 2014
e99b6a4
Added back "insert auto copy" flags in resolution.
Dec 31, 2014
7c773b2
Moved insertAutoCopyAutoDestroy pass to start of parallel.
Dec 31, 2014
1864ef8
Now actually adding autoDestroy calls.
Dec 31, 2014
20b76c5
Add autoCopy on const temps; mark return of PRIM_DEREF as unowned.
Jan 1, 2015
ce37533
Add insertion of autoCopy calls.
Jan 5, 2015
085fa0a
Update return-record.chpl with initCopy function.
Jan 6, 2015
e1f28e2
Added a few more cases to isConsumed(), so that more autoCopy calls a…
Jan 6, 2015
1c31169
Comment out the clause that prevents insertion of autoCopy calls for …
Jan 6, 2015
a78e183
Strengthened the test in isBitwiseCopy(), so it returns false if the …
Jan 7, 2015
491c4a9
Set initial OUT values to all ones for flow analysis.
Jan 8, 2015
ac230f7
Changes to support PGI compiler and new bitVec interface.
Jan 8, 2015
53eeb26
Update type/records/const-checking/constructors.good for increase aut…
Jan 8, 2015
d1aa837
Merge branch 'MMRework' of github.com:hildeth/chapel into MMRework
Jan 8, 2015
68784a7
Insert autoDestroy calls ahead of _downEndCount calls.
Jan 9, 2015
287745a
Added PRIM_GET_MEMBER_VALUE to list of primitives excluded from those…
Jan 9, 2015
2beaa5f
Output of types/records/sungeun/destructor3 changed due to tuple fiel…
Jan 9, 2015
3cbf489
Fix BB analysis bug: Empty blocks with no predecessors
Jan 11, 2015
d7a2f18
Add code to avoid copying a domain record if the domain class it cont…
Jan 12, 2015
14de65c
Update test/classes/figueroa/RecordConstructor2.good due to increased…
Jan 12, 2015
e9c9445
Add an explicit default constructor for record channel in IO.chpl.
Jan 13, 2015
005933c
Disabled initializeClass.
Jan 13, 2015
72bfb0e
Fix a bug in the insertion of autoDestroy calls
Jan 14, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 60 additions & 2 deletions compiler/AST/bb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ void BasicBlock::buildBasicBlocks(FnSymbol* fn) {

fn->basicBlocks->push_back(BasicBlock::steal());

INT_ASSERT(verifyBasicBlocks(fn));
removeEmptyBlocks(fn);

if (fVerify)
INT_ASSERT(verifyBasicBlocks(fn));
}

BasicBlock* BasicBlock::steal() {
Expand Down Expand Up @@ -202,9 +205,11 @@ void BasicBlock::buildBasicBlocks(FnSymbol* fn, Expr* stmt, bool mark) {
LabelSymbol* label = toLabelSymbol(toSymExpr(s->label)->var);

if (BasicBlock* bb = labelMaps.get(label)) {
// Thread this block to its destination label.
thread(basicBlock, bb);

} else {
// Set up goto map, so this block's successor can be back-patched later.
std::vector<BasicBlock*>* vbb = gotoMaps.get(label);

if (!vbb)
Expand All @@ -216,6 +221,10 @@ void BasicBlock::buildBasicBlocks(FnSymbol* fn, Expr* stmt, bool mark) {
}

append(s, mark); // Put the goto at the end of its block.

// We need a new block, so we can not thread the one containing the goto to
// this new one. There is a break in the flow. If the new block does not
// begin with a label, it is unreachable and can be removed.
restart(fn);

} else {
Expand Down Expand Up @@ -291,9 +300,49 @@ void BasicBlock::thread(BasicBlock* src, BasicBlock* dst) {
src->outs.push_back(dst);
}

// Look for and remove empty blocks with no predecessor and whose successor is
// the next block in sequence. These blocks get created when a block ends in a
// goto statement and the enclosing construct calls restart immediately.
// We have to wait until basic block analysis is done, because we don't know if
// a block has predecessors until after threading is performed, and this is
// sometimes delayed.
void BasicBlock::removeEmptyBlocks(FnSymbol* fn)
{
// Create a new vector that contains just the items we want to preserve.
int new_id = 0;
BasicBlockVector* new_blocks = new BasicBlockVector();
for_vector(BasicBlock, bb, *fn->basicBlocks)
{
// Skip empty blocks with no predecessors.
if (bb->ins.size() == 0 &&
bb->exprs.size() == 0)
{
// This block will be removed. It is no longer a predecessor of anyone,
// so we must update the back links.
for_vector(BasicBlock, succ, bb->outs)
{
BasicBlockVector::iterator i;
for (i = succ->ins.begin(); i != succ->ins.end(); ++i)
if (*i == bb)
break;

INT_ASSERT(i != succ->ins.end());
succ->ins.erase(i);
}
}
else
{
bb->id = new_id++;
new_blocks->push_back(bb);
}
}
delete fn->basicBlocks; fn->basicBlocks = new_blocks;
}

// Returns true if the basic block structure is OK, false otherwise.
bool BasicBlock::verifyBasicBlocks(FnSymbol* fn) {
for_vector(BasicBlock, bb, *fn->basicBlocks) {
for_vector(BasicBlock, bb, *fn->basicBlocks)
{
if (bb->isOK() == false)
return false;
}
Expand All @@ -307,6 +356,15 @@ bool BasicBlock::isOK() {
if (exprs.size() != marks.size())
return false;

// Every empty interior block must have a predecessor.
// Non-empty blocks with no predecessors are dead code, which may be
// removed by a client of BB analysis. These dead blocks cannot be
// identified without BB analysis, so non-empty blocks with no
// predecessors are valid.
if (ins.size() == 0 &&
exprs.size() == 0)
return false;

// Expressions must be live (non-NULL);
for_vector(Expr, expr, exprs)
if (expr == 0)
Expand Down
9 changes: 9 additions & 0 deletions compiler/AST/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,13 +585,17 @@ destructureIndices(BlockStmt* block,
var->addFlag(FLAG_INDEX_VAR);
if (coforall)
var->addFlag(FLAG_COFORALL_INDEX_VAR);
#ifndef HILDE_MM
var->addFlag(FLAG_INSERT_AUTO_DESTROY);
#endif
} else if (SymExpr* sym = toSymExpr(indices)) {
block->insertAtHead(new CallExpr(PRIM_MOVE, sym->var, init));
sym->var->addFlag(FLAG_INDEX_VAR);
if (coforall)
sym->var->addFlag(FLAG_COFORALL_INDEX_VAR);
#ifndef HILDE_MM
sym->var->addFlag(FLAG_INSERT_AUTO_DESTROY);
#endif
}
}

Expand Down Expand Up @@ -660,6 +664,7 @@ handleArrayTypeCase(FnSymbol* fn, Expr* indices, Expr* iteratorExpr, Expr* expr)
thenStmt->insertAtTail(new DefExpr(domain));
// note that we need the below autoCopy until we start reference
// counting domains within runtime array types
// TODO AMM: Check if the explicit insertion of an autoCopy is necessary here.
thenStmt->insertAtTail(new CallExpr(PRIM_MOVE, domain,
new CallExpr("chpl__autoCopy",
new CallExpr("chpl__ensureDomainExpr",
Expand Down Expand Up @@ -1058,7 +1063,9 @@ buildForallLoopStmt(Expr* indices,
followIdx->addFlag(FLAG_INDEX_OF_INTEREST);

leadIdxCopy->addFlag(FLAG_INDEX_VAR);
#ifndef HILDE_MM
leadIdxCopy->addFlag(FLAG_INSERT_AUTO_DESTROY);
#endif
followIdx->addFlag(FLAG_INDEX_OF_INTEREST);

// ForallLeaderArgs: stash references so we know where things are.
Expand Down Expand Up @@ -1456,7 +1463,9 @@ CallExpr* buildReduceExpr(Expr* opExpr, Expr* dataExpr, bool zippered) {
VarSymbol* localOp = newTemp();

leadIdxCopy->addFlag(FLAG_INDEX_VAR);
#ifndef HILDE_MM
leadIdxCopy->addFlag(FLAG_INSERT_AUTO_DESTROY);
#endif

ForLoop* followBody = new ForLoop(followIdx, followIter, NULL);

Expand Down
26 changes: 10 additions & 16 deletions compiler/adt/bitVec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,38 +58,30 @@ void BitVec::clear() {


bool BitVec::get(size_t i) const {
#if DEBUG
if (i >= in_size)
INT_FATAL("BitVec::get -- operand out of range.");
#endif
INT_ASSERT(i < in_size);
size_t j = i / (sizeof(TYPE)<<3);
size_t k = i - j*(sizeof(TYPE)<<3);
return data[j] & (1 << k);
}


void BitVec::unset(size_t i) {
INT_ASSERT(i < in_size);
size_t j = i / (sizeof(TYPE)<<3);
size_t k = i - j*(sizeof(TYPE)<<3);
data[j] &= ((TYPE)-1) - (1 << k);
}


void BitVec::disjunction(const BitVec& other) {
#if DEBUG
if (other.in_size != in_size)
INT_FATAL("BitVec::disjunction -- operand lengths must be equal.");
#endif
INT_ASSERT(other.in_size == in_size);
for (size_t i = 0; i < ndata; i++)
data[i] |= other.data[i];
}


void BitVec::intersection(const BitVec& other) {
#if DEBUG
if (other.in_size != in_size)
INT_FATAL("BitVec::intersection -- operand lengths must be equal.");
#endif
INT_ASSERT(other.in_size == in_size);
for (size_t i = 0; i < ndata; i++)
data[i] &= other.data[i];
}
Expand All @@ -106,10 +98,7 @@ void BitVec::intersection(const BitVec& other) {


bool BitVec::equals(const BitVec& other) const {
#if DEBUG
if (other.in_size != in_size)
INT_FATAL("BitVec::disjunction -- operand lengths must be equal.");
#endif
INT_ASSERT(other.in_size == in_size);
for(size_t i = 0; i < ndata; i++) {
if(data[i] != other.data[i]) {
return false;
Expand All @@ -126,6 +115,7 @@ void BitVec::set() {


void BitVec::set(size_t i) {
INT_ASSERT(i < in_size);
size_t j = i / (sizeof(TYPE)<<3);
size_t k = i - j*(sizeof(TYPE)<<3);
data[j] |= 1 << k;
Expand All @@ -139,19 +129,22 @@ void BitVec::reset() {


void BitVec::reset(size_t i) {
INT_ASSERT(i < in_size);
size_t j = i / (sizeof(TYPE)<<3);
size_t k = i - j*(sizeof(TYPE)<<3);
data[j] &= ((size_t)-1) - (1 << k);
}


void BitVec::copy(const BitVec& other) {
INT_ASSERT(other.in_size == in_size);
for (size_t i = 0; i < ndata; ++i)
data[i] = other.data[i];
}


void BitVec::copy(size_t i, bool value) {
INT_ASSERT(i < in_size);
size_t j = i / (sizeof(TYPE)<<3);
size_t k = i - j*(sizeof(TYPE)<<3);
data[j] &= ~(1 << k);
Expand All @@ -167,6 +160,7 @@ void BitVec::flip() {


void BitVec::flip(size_t i) {
INT_ASSERT(i < in_size);
size_t j = i / (sizeof(TYPE)<<3);
size_t k = i - j*(sizeof(TYPE)<<3);
data[j] ^= 1 << k;
Expand Down
34 changes: 21 additions & 13 deletions compiler/include/bb.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ class SymExpr;
// The goto and label maps persist only between calls to buildBasicBlocks.
class BasicBlock
{
//
// Typedefs
//
public:
typedef std::vector<BasicBlock*> BasicBlockVector;
typedef std::vector<BitVec*> BitVecVector;

//
// Class methods/variables
//
Expand All @@ -51,16 +58,16 @@ class BasicBlock
Map<Symbol*,int>& localMap);

static void backwardFlowAnalysis(FnSymbol* fn,
std::vector<BitVec*>& GEN,
std::vector<BitVec*>& KILL,
std::vector<BitVec*>& IN,
std::vector<BitVec*>& OUT);
BitVecVector& GEN,
BitVecVector& KILL,
BitVecVector& IN,
BitVecVector& OUT);

static void forwardFlowAnalysis (FnSymbol* fn,
std::vector<BitVec*>& GEN,
std::vector<BitVec*>& KILL,
std::vector<BitVec*>& IN,
std::vector<BitVec*>& OUT,
BitVecVector& GEN,
BitVecVector& KILL,
BitVecVector& IN,
BitVecVector& OUT,
bool intersect = true);

static void printLocalsVector(Vec<Symbol*> locals,
Expand All @@ -69,18 +76,18 @@ class BasicBlock
static void printDefsVector(std::vector<SymExpr*> defs,
Map<SymExpr*, int>& defMap);

static void printLocalsVectorSets(std::vector<BitVec*>& sets,
static void printLocalsVectorSets(BitVecVector& sets,
Vec<Symbol*> locals);

static void printBitVectorSets(std::vector<BitVec*>& sets);
static void printBitVectorSets(BitVecVector& sets);

static BasicBlock* basicBlock;

static Map<LabelSymbol*,
BasicBlock*> labelMaps;

static Map<LabelSymbol*,
std::vector<BasicBlock*>*> gotoMaps;
BasicBlockVector*> gotoMaps;

private:
static void buildBasicBlocks(FnSymbol* fn,
Expand All @@ -94,6 +101,7 @@ class BasicBlock

static BasicBlock* steal();

static void removeEmptyBlocks(FnSymbol* fn);
static bool verifyBasicBlocks(FnSymbol* fn);

static int nextID;
Expand All @@ -109,8 +117,8 @@ class BasicBlock
std::vector<Expr*> exprs;
std::vector<bool> marks;

std::vector<BasicBlock*> ins;
std::vector<BasicBlock*> outs;
BasicBlockVector ins;
BasicBlockVector outs;

private:
bool isOK();
Expand Down
5 changes: 4 additions & 1 deletion compiler/include/bitVec.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ class BitVec {
void disjunction(const BitVec& other);
void intersection(const BitVec& other);


// Synonyms for disjunction (union) and (conjunction) intersection above.
void operator|=(BitVec& other) { this->disjunction(other); }
void operator&=(BitVec& other) { this->intersection(other); }

// Added functionality to make this compatible with std::bitset and thus
// boosts dynamic bitset if that gets into the STL, or we start using boost
bool equals(const BitVec& other) const;
Expand Down
1 change: 1 addition & 0 deletions compiler/include/passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void expandExternArrayCalls();
void flattenClasses();
void flattenFunctions();
void inlineFunctions();
void insertAutoCopyAutoDestroy();
void insertLineNumbers();
void insertWideReferences();
void narrowWideReferences();
Expand Down
2 changes: 1 addition & 1 deletion compiler/make/Makefile.compiler.head
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ endif
include $(CHPL_MAKE_HOME)/make/Makefile.base

INCL_CFLAGS = -I. -I$(COMPILER_ROOT)/include/$(CHPL_MAKE_HOST_PLATFORM) -I$(COMPILER_ROOT)/include $(LLVM_INCLUDES)
COMP_CFLAGS += $(INCL_CFLAGS)
COMP_CFLAGS += $(INCL_CFLAGS) -DHILDE_MM=1

#
# add gc-related stuff
Expand Down
4 changes: 3 additions & 1 deletion compiler/optimizations/copyPropagation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -992,8 +992,10 @@ static void initCopySets(std::vector<BitVec*>& COPY, std::vector<size_t>& ends,
// When these are corrected and the test becomes true, then we can drop back
// to the simpler form given here:
#ifdef INLINING_DOES_NOT_LEAVE_INTERNAL_BASIC_BLOCKS_WITHOUT_PREDECESSORS
static void initInSets(std::vector<BitVec*>& IN, size_t nbbs)
static void initInSets(std::vector<BitVec*>& IN, FnSymbol* fn)
{
size_t nbbs = fn->basicBlocks->size();

// Note that we start with i = 1, so that IN[0] is left as all zeroes.
for (size_t i = 1; i < nbbs; i++)
IN[i]->set();
Expand Down
2 changes: 1 addition & 1 deletion compiler/optimizations/removeUnnecessaryAutoCopyCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ static void removePODinitDestroy()


void removeUnnecessaryAutoCopyCalls() {
if (fNoRemoveCopyCalls)
if (fNoRemoveCopyCalls || 1) // Disable this pass for a test.
return;

//
Expand Down
1 change: 1 addition & 0 deletions compiler/passes/Makefile.share
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ PASSES_SRCS = \
filesToAST.cpp \
flattenClasses.cpp \
flattenFunctions.cpp \
insertAutoCopyAutoDestroy.cpp \
insertLineNumbers.cpp \
insertWideReferences.cpp \
normalize.cpp \
Expand Down
Loading