Git Product home page Git Product logo

Comments (6)

mchalupa avatar mchalupa commented on June 2, 2024 1

Further, I wonder if it's possible to control the "strength" or "degree" of both forward and backward slicing. Sometimes I want %c to be replaced with an arbitrary argument, and sometimes I want %add to be eliminated or even ret i32 %add to be replaced with ret i32 %call. In this way we can control the complexity and specificity of a certain sliced IR. If not, could you provide an appropriate place to hack it?

What you describe is not slicing, so no, the slicer does not support this. I would suggest you just create a pass/new tool that uses DG to do this. I would start with llvm-slicer, after this point in the code: https://github.com/mchalupa/dg/blob/master/tools/llvm-slicer.cpp#L267C22-L267C22, you can go through the dependence graph and unmark nodes that should be in the slice but you want to preserve them. In this step you can also remember instructions that you want to replace and after slicing itself (https://github.com/mchalupa/dg/blob/master/tools/llvm-slicer.cpp#L285), you can replace them with different instructions.

It seems to require emitting debug instructions, but now I only have IR. I prefer to taking the name of Value/Instruction as a type of slicing criterion. If there is not such option, where can I hack?

Instructions in LLVM do not have names by default, so this is not reliable and not implemented, but you can hack it here: https://github.com/mchalupa/dg/blob/master/tools/llvm-slicer-crit.cpp#L1113

from dg.

mchalupa avatar mchalupa commented on June 2, 2024

Hi,

I slice it based on other_func(ret1), and want store of b to be sliced:

I'm not sure I understand. other_func(ret1) is not part of the code, what do you mean exactly by this slicing criterion? If you slice the code w.r.t calls to other_func then the slice you posted looks correct.

Apart from this, it's there any easy way to hack dg so that any type of instructions (not only call-sites/ret) can be the slicing criterions?

Any instruction can be a slicing criterion: https://github.com/mchalupa/dg/blob/master/doc/llvm-slicer.md#slicing-criteria-the--sc-option

from dg.

mchalupa avatar mchalupa commented on June 2, 2024

I slice it based on other_func(ret1), and want store of b to be sliced

Oh, you want forward slicing?

from dg.

XChy avatar XChy commented on June 2, 2024

I may not clarify it well, what I really want is to control the "strength" of forward/backward slicing. Take a llvm-ir as example (because I work only on llvm-ir, instead of C now)

declare i32 @dummy(i32)
define i32 @foo(i32 %a, ptr %b) {
entry:
  %c = sub i32 0, %a 
  %call = call i32 @dummy(i32 %c)
  store i32 666, ptr %b, align 4
  %add = add i32 %call, 1
  ret i32 %add
}

Firstly, we take dummy as the slicing criterion, and then the store of b doesn't influence dummy and isn't influenced by dummy. So store b should be eliminated unconditionally.

%add depends on dummy, so it should not be eliminated unconditionally for me. But without -forward option, dg produces:

define i32 @foo(i32 %a, ptr %b) {
entry:
  %c = sub i32 0, %a
  %call = call i32 @dummy(i32 %c)
  br label %safe_return

safe_return:                                      ; preds = %entry
  ret i32 undef
}

And thanks for your reminder, with -forward as you say, it produces what I want now:

define i32 @foo(i32 %a, ptr %b) {
entry:
  %c = sub i32 0, %a
  %call = call i32 @dummy(i32 %c)
  %add = add i32 %call, 1
  ret i32 %add
}

Further, I wonder if it's possible to control the "strength" or "degree" of both forward and backward slicing. Sometimes I want %c to be replaced with an arbitrary argument, and sometimes I want %add to be eliminated or even ret i32 %add to be replaced with ret i32 %call. In this way we can control the complexity and specificity of a certain sliced IR. If not, could you provide an appropriate place to hack it?

from dg.

XChy avatar XChy commented on June 2, 2024

Any instruction can be a slicing criterion: https://github.com/mchalupa/dg/blob/master/doc/llvm-slicer.md#slicing-criteria-the--sc-option

It seems to require emitting debug instructions, but now I only have IR. I prefer to taking the name of Value/Instruction as a type of slicing criterion. If there is not such option, where can I hack?

from dg.

XChy avatar XChy commented on June 2, 2024

Thanks for your explanation and assistance. That's really helpful to me, your guide on where to hack it is highly appreciated!

from dg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.