[LLVMdev] [PATCH] Fix nondeterministic behaviour in the CodeExtractor
Julien Lerouge
jlerouge at apple.com
Sat Jan 9 16:11:14 PST 2010
On Fri, Jan 08, 2010 at 05:04:17PM -0800, Chris Lattner wrote:
> On Jan 8, 2010, at 5:01 PM, Julien Lerouge wrote:
> >Hello,
> >
> >The CodeExtractor contains a std::set<BasicBlock*> to keep track
> >of the
> >blocks to extract. Iterators on this set are not deterministic, and so
> >the functions that are generated are not (the order of the
> >inputs/outputs can change).
> >
> >The attached patch uses a SetVector instead. Ok to apply ?
> Nice catch, please apply,
> -Chris
Thanks for the quick review. There is actually more, is it ok to apply
this one as well (avoid std:vector<Value*> being sorted) ?
Thanks,
Julien
--
Julien Lerouge
PGP Key Id: 0xB1964A62
PGP Fingerprint: 392D 4BAD DB8B CE7F 4E5F FA3C 62DB 4AA7 B196 4A62
PGP Public Key from: keyserver.pgp.com
-------------- next part --------------
Index: lib/Transforms/Utils/CodeExtractor.cpp
===================================================================
--- lib/Transforms/Utils/CodeExtractor.cpp (revision 93080)
+++ lib/Transforms/Utils/CodeExtractor.cpp (working copy)
@@ -%ld,%ld +%ld,%ld @@
namespace {
class CodeExtractor {
- typedef std::vector<Value*> Values;
+ typedef SetVector<Value*> Values;
SetVector<BasicBlock*> BlocksToExtract;
DominatorTree* DT;
bool AggregateArgs;
@@ -%ld,%ld +%ld,%ld @@
// instruction is used outside the region, it's an output.
for (User::op_iterator O = I->op_begin(), E = I->op_end(); O != E; ++O)
if (definedInCaller(*O))
- inputs.push_back(*O);
+ inputs.insert(*O);
// Consider uses of this instruction (outputs).
for (Value::use_iterator UI = I->use_begin(), E = I->use_end();
UI != E; ++UI)
if (!definedInRegion(*UI)) {
- outputs.push_back(I);
+ outputs.insert(I);
break;
}
} // for: insts
@@ -%ld,%ld +%ld,%ld @@
} // for: basic blocks
NumExitBlocks = ExitBlocks.size();
-
- // Eliminate duplicates.
- std::sort(inputs.begin(), inputs.end());
- inputs.erase(std::unique(inputs.begin(), inputs.end()), inputs.end());
- std::sort(outputs.begin(), outputs.end());
- outputs.erase(std::unique(outputs.begin(), outputs.end()), outputs.end());
}
/// constructFunction - make a function based on inputs and outputs, as follows:
More information about the llvm-dev
mailing list