llvm:如何获取基本块的标签 [英] llvm: How to get the label of Basic Blocks

查看:398
本文介绍了llvm:如何获取基本块的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个遍历来检测和打印函数中基本块的标签,因为我想进一步使用splitBasicBlock().我这样写:

I have written a pass to detect and print the label of basicblocks in a function, for I want to use splitBasicBlock() further. I wrote that like this:

virtual bool runOnModule(Module &M)
{
    for(Module::iterator F = M.begin(), E = M.end(); F!= E; ++F)
    {
        errs()<<"Function:"<<F->getName()<<"\n";
        //for(Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
        for (iplist<BasicBlock>::iterator iter = F->getBasicBlockList().begin();
                    iter != F->getBasicBlockList().end();
                    iter++)
        {
          BasicBlock* currBB = iter;
          errs() << "BasicBlock: "  << currBB->getName() << "\n";   
        }
    }
    return true;
}

IR文件如下:

; <label>:63                                      ; preds = %43
  %64 = load i32* %j, align 4
  %65 = sext i32 %64 to i64
  %66 = load i8** %tempdst, align 8
  %67 = getelementptr inbounds i8* %66, i64 %65
  store i8 -1, i8* %67, align 1
  br label %73

; <label>:68                                      ; preds = %43
  %69 = load i32* %j, align 4
  %70 = sext i32 %69 to i64
  %71 = load i8** %tempdst, align 8
  %72 = getelementptr inbounds i8* %71, i64 %70
  store i8 0, i8* %72, align 1
  br label %73

; <label>:73                                      ; preds = %68, %63
  br label %74

但是,我对标签一无所知:

However, I got nothing about the label:

Function:main
BasicBlock:
BasicBlock:
BasicBlock:

这些未命名"的基本块有什么问题?我该怎么办?

What's wrong with these "unnamed" basic block? What should I do?

推荐答案

LLVM IR中的值不需要具有名称.的确,这些基本块没有名称,这就是为什么您从currBB->getName()中获得一个空字符串的原因.

Values in LLVM IR are not required to have a name; and indeed, those basic blocks don't have names, which is why you get an empty string from currBB->getName().

它们在LLVM IR打印输出中具有名称的原因是因为当您以LLVM IR的文本格式(如.ll文件中显示的那样)打印时,必须为它们分配一个名称以使其可被引用,因此打印机将顺序数字名称分配给基本块(和其他值).这些数字名称仅由打印机创建,实际上在模块中不存在.

The reason that they have names in the LLVM IR printout is because when you print to the textual format of LLVM IR (as it appears in .ll files), you have to assign a name to them to make them referable, so the printer assigns sequential numeric names to basic blocks (and other values). Those numeric names are only created by the printer, though, and don't actually exist in the module.

这篇关于llvm:如何获取基本块的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆