question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A way to discover the label of a block (in ValueRef)

See original GitHub issue

br instructions have an argument telling what label(s) they are branching to, and phi instructions have arguments telling what labels they might have arrived from, but there is no way to match up these labels with the blocks they belong to.

I am trying to do control-flow analysis, including determining how many different paths are possible through any given block, and which blocks are located inside loops. Code sample:

int sample(int arg) {
   for(int i=0; i<10; i++) {
      arg = (2*arg + 3*i) % 71;
   }
   return arg;
}

Compile this with -O1 and generate LL output, then use llvm.parse_assembly(). In the i32 @sample(i32) function there will be at least three blocks and a phi statement that “comes from” two of the blocks. Task: write a Python program that uses llvmlite to answer the question: “Which two blocks are the ones that might branch to that phi statement?”

Disclaimer: I don’t know how to do this within the “real” LLVM API, and I am a new to Python3 programming. I don’t see the answer in the (rather limited) documentation of the ValueRef class.

I am using Python 3.6.8, llvmlite 0.33.0, and clang 9.0.1 on a CentOS system. I built the clang from source but I don’t know how to build python3 or llvmlite.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
esccommented, Jun 30, 2020

@mrob27 thanks for submitting this! I have labelled it as a question for now.

0reactions
lwerdnacommented, Jul 5, 2022

I also want this feature.

Until then, you can parse the first line of the string representation of a block:

def get_block_label(block):
    lines = str(block).split('\n')
    try:
        i = 1 if lines[0] == '' else 0
        if m := re.match(r'^(\d+):', lines[i]):
            return m.group(1)
    except:
        return None
Read more comments on GitHub >

github_iconTop Results From Across the Web

llvm: How to get the label of Basic Blocks - Stack Overflow
While BasicBlocks may be with no name (as indicated by hasName() method) one may print unique BasicBlock identifier by using ...
Read more >
AWS CloudFormation VPC template - AWS CodeBuild
An AWS CloudFormation template to create and provision a VPC to use AWS CodeBuild.
Read more >
Cocoon Forms Block Implementation - A Simple Example
In this example we will show how to create a simple registration form using ... value-ref="org.apache.cocoon.forms.impl.servlet"/> </servlet:connections> ...
Read more >
llvmlite Documentation
Since the Numba/llvmlite maintainers may not know how the package was compiled ... If name is not empty, it names the block's entry...
Read more >
Create a private AWS VPC with CloudFormation
Parameters: Tag: Type: String Resources: VPC: Type: "AWS::EC2::VPC" Properties: CidrBlock: "10.0.0.0/16" Tags: - Key: "Name" Value: !Ref ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found