Skip to content

Commit ff8a15a

Browse files
Yilin LiAllinLeeYL
authored andcommitted
[llvm-extract] support unnamed bbs.
1 parent 6de1537 commit ff8a15a

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

llvm/include/llvm/IR/Value.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,7 @@ class Value {
290290
/// \note It is an error to call V->takeName(V).
291291
void takeName(Value *V);
292292

293-
#ifndef NDEBUG
294293
std::string getNameOrAsOperand() const;
295-
#endif
296294

297295
/// Change all uses of this to point to a new Value.
298296
///

llvm/lib/IR/Value.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,6 @@ void Value::takeName(Value *V) {
440440
ST->reinsertValue(this);
441441
}
442442

443-
#ifndef NDEBUG
444443
std::string Value::getNameOrAsOperand() const {
445444
if (!getName().empty())
446445
return std::string(getName());
@@ -450,7 +449,6 @@ std::string Value::getNameOrAsOperand() const {
450449
printAsOperand(OS, false);
451450
return OS.str();
452451
}
453-
#endif
454452

455453
void Value::assertModuleIsMaterializedImpl() const {
456454
#ifndef NDEBUG

llvm/tools/llvm-extract/llvm-extract.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,13 @@ static cl::list<std::string> ExtractBlocks(
9090
"Each pair will create a function.\n"
9191
"If multiple basic blocks are specified in one pair,\n"
9292
"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"
9395
"eg:\n"
9496
" --bb=f:bb1;bb2 will extract one function with both bb1 and bb2;\n"
9597
" --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;"),
97100
cl::value_desc("function:bb1[;bb2...]"), cl::cat(ExtractCat));
98101

99102
// ExtractAlias - The alias to extract from the module.
@@ -356,7 +359,7 @@ int main(int argc, char **argv) {
356359
// The function has been materialized, so add its matching basic blocks
357360
// to the block extractor list, or fail if a name is not found.
358361
auto Res = llvm::find_if(*P.first, [&](const BasicBlock &BB) {
359-
return BB.getName() == BBName;
362+
return BB.getNameOrAsOperand() == BBName;
360363
});
361364
if (Res == P.first->end()) {
362365
errs() << argv[0] << ": function " << P.first->getName()

0 commit comments

Comments
 (0)