[sil-cloner] Always call doPreProcess when visiting SILInstructions.

It is important to call doPreProcess to correctly setup the available opened archetypes which were referenced from the original instruction being copied.

This fixes a concrete bug in LoopRotate optimization and potential bugs related to cloning.

rdar://27659420
This commit is contained in:
Roman Levenstein
2016-08-03 15:01:19 -07:00
parent 02d2517866
commit d92c4cc379
3 changed files with 62 additions and 3 deletions

View File

@@ -66,6 +66,14 @@ public:
SILBuilder &getBuilder() { return Builder; }
protected:
void beforeVisit(ValueBase *V) {
if (auto I = dyn_cast<SILInstruction>(V)) {
// Update the set of available opened archetypes with the opened
// archetypes used by the current instruction.
doPreProcess(I);
}
}
#define VALUE(CLASS, PARENT) \
void visit##CLASS(CLASS *I) { \
llvm_unreachable("SILCloner visiting non-instruction?"); \
@@ -380,9 +388,6 @@ SILCloner<ImplClass>::visitSILBasicBlock(SILBasicBlock* BB) {
SILFunction &F = getBuilder().getFunction();
// Iterate over and visit all instructions other than the terminator to clone.
for (auto I = BB->begin(), E = --BB->end(); I != E; ++I) {
// Update the set of available opened archetypes with the opened archetypes
// used by the current instruction.
doPreProcess(&*I);
asImpl().visit(&*I);
}
// Iterate over successors to do the depth-first search.