@@ -90,10 +90,13 @@ static cl::list<std::string> ExtractBlocks(
90
90
" Each pair will create a function.\n "
91
91
" If multiple basic blocks are specified in one pair,\n "
92
92
" the first block in the sequence should dominate the rest.\n "
93
+ " If an unnamed basic block is to be extracted,\n "
94
+ " '%' should be added before the basic block variable names.\n "
93
95
" eg:\n "
94
96
" --bb=f:bb1;bb2 will extract one function with both bb1 and bb2;\n "
95
97
" --bb=f:bb1 --bb=f:bb2 will extract two functions, one with bb1, one "
96
- " with bb2." ),
98
+ " with bb2.\n "
99
+ " --bb=f:%1 will extract one function with basic block 1;" ),
97
100
cl::value_desc(" function:bb1[;bb2...]" ), cl::cat(ExtractCat));
98
101
99
102
// ExtractAlias - The alias to extract from the module.
@@ -355,9 +358,25 @@ int main(int argc, char **argv) {
355
358
for (StringRef BBName : P.second ) {
356
359
// The function has been materialized, so add its matching basic blocks
357
360
// to the block extractor list, or fail if a name is not found.
361
+ #ifndef NDEBUG
358
362
auto Res = llvm::find_if (*P.first , [&](const BasicBlock &BB) {
359
- return BB.getName () == BBName;
363
+ return BB.getNameOrAsOperand () == BBName;
360
364
});
365
+ #else
366
+ llvm::Function::iterator Res;
367
+ if (BBName.substr (0 , 1 ) == " %" ) {
368
+ Res = llvm::find_if (*P.first , [&](const BasicBlock &BB) {
369
+ std::string tmpName;
370
+ raw_string_ostream OS (tmpName);
371
+ BB.printAsOperand (OS, false );
372
+ return OS.str () == BBName;
373
+ });
374
+ } else {
375
+ Res = llvm::find_if (*P.first , [&](const BasicBlock &BB) {
376
+ return BB.getName () == BBName;
377
+ });
378
+ }
379
+ #endif
361
380
if (Res == P.first ->end ()) {
362
381
errs () << argv[0 ] << " : function " << P.first ->getName ()
363
382
<< " doesn't contain a basic block named '" << BBName
0 commit comments