This is an archive of the discontinued LLVM Phabricator instance.

[FuzzMutate] New strategy `ShuffleBlockStrategy`
ClosedPublic

Authored by Peter on Nov 18 2022, 4:17 PM.

Details

Summary

ShuffleBlockStrategy will shuffle the instructions in a basic block without breaking the dependency of instructions.
It is implemented as a topological sort, only we randomly select instructions with no dependency.

Diff Detail

Event Timeline

Peter created this revision.Nov 18 2022, 4:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 18 2022, 4:17 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
Peter requested review of this revision.Nov 18 2022, 4:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 18 2022, 4:17 PM
arsenm added inline comments.Nov 18 2022, 4:49 PM
llvm/include/llvm/FuzzMutate/IRMutator.h
130

Why do you need this?

llvm/lib/FuzzMutate/IRMutator.cpp
310

You can do this in the first loop, and use a range loop with make_early_inc_range(BB.getFirstInsertionPt(), BB.getTerminator())

314

The only 2 users I see of this set immediately discard the result and see if it's empty. You can just check the predicate directly without the set

318

Don't need != 0

318

Probably should avoid inserting null into the set

327

Avoid inserting null, don't need != 0

335

.empty

339

!Roots.empty

348

.empty

arsenm requested changes to this revision.Nov 18 2022, 4:49 PM
This revision now requires changes to proceed.Nov 18 2022, 4:49 PM
Peter updated this revision to Diff 476655.Nov 18 2022, 8:36 PM
Peter marked 9 inline comments as done.

Improve the code readablility and performance.

llvm/lib/FuzzMutate/IRMutator.cpp
310

I didn't know this API, Thanks for pointing that out!

314

You are right, I thought I might need Parents but turns out I don't. I have made this so it return a bool, whether there are alive parents or not.

arsenm requested changes to this revision.Nov 22 2022, 7:10 AM
arsenm added inline comments.
llvm/lib/FuzzMutate/IRMutator.cpp
315

Add a comment for the function

318–321

The return values look backwards to me?

323

Comment the function

llvm/unittests/FuzzMutate/StrategiesTest.cpp
313

I think you need an additional test with some loops

368

Module *M

375

Use C++11 random functions?

380

EXPECT_EQ

382

Probably should be ASSERT_FALSE(verifyModule())

This revision now requires changes to proceed.Nov 22 2022, 7:10 AM
Peter updated this revision to Diff 477252.Nov 22 2022, 10:52 AM
Peter marked 8 inline comments as done.

Amend comments. Adding a loop test.

Peter marked an inline comment as not done.Nov 22 2022, 10:52 AM
Peter added inline comments.
llvm/lib/FuzzMutate/IRMutator.cpp
318–321

Thanks for pointing that out. It is backwards.

llvm/unittests/FuzzMutate/StrategiesTest.cpp
368

parseAssembly returns a unique pointer so we don't have to explicitly free the memory.
I think we are better off with auto. Besides, every other test did the same.

arsenm added inline comments.Nov 22 2022, 2:29 PM
llvm/unittests/FuzzMutate/StrategiesTest.cpp
368

That makes things worse. I think auto is harmful here

Peter updated this revision to Diff 477310.Nov 22 2022, 2:52 PM
Peter marked an inline comment as not done.

clearify type of Module

Peter marked 2 inline comments as done.Nov 22 2022, 2:54 PM
Peter added inline comments.
llvm/unittests/FuzzMutate/StrategiesTest.cpp
368

I understand the ambiguity can be harmful here now. I have made the change. I will change other uses in this file in another diff once this is accepted. Thanks for pointing it out.

arsenm added inline comments.Nov 28 2022, 1:57 PM
llvm/lib/FuzzMutate/IRMutator.cpp
325

I don't see anything about the same block here

327

SmallPtrSet

335

SmallPtrSet

llvm/unittests/FuzzMutate/StrategiesTest.cpp
396

Use opaque pointers

401–402

Use named values in tests

arsenm requested changes to this revision.Nov 28 2022, 1:57 PM
This revision now requires changes to proceed.Nov 28 2022, 1:57 PM
Peter updated this revision to Diff 478413.Nov 28 2022, 4:17 PM
Peter marked 5 inline comments as done.
  1. SmallSet -> SmallPtrSet
  2. Use named values in unit testing.
llvm/unittests/FuzzMutate/StrategiesTest.cpp
396

No unit testing in this folder is supporting opaque pointers yet.
I guess we have to change how the unit tests are run to support that.
I can do it in another patch if you can enlighten me how.

arsenm added inline comments.Nov 28 2022, 4:19 PM
llvm/unittests/FuzzMutate/StrategiesTest.cpp
396

Shouldn't need to change anything other than the pointer next. s/i32*/ptr/

Peter added inline comments.Nov 28 2022, 4:32 PM
llvm/unittests/FuzzMutate/StrategiesTest.cpp
396

directly changing i32* into ptr will get an error when running parser and abort the unit test. ("warning: ptr type is only supported in -opaque-pointers mode")

arsenm added inline comments.Nov 28 2022, 4:39 PM
llvm/unittests/FuzzMutate/StrategiesTest.cpp
396

You have more than i32*, also i64*. You need to get all the pointer types

Peter updated this revision to Diff 478417.Nov 28 2022, 4:45 PM

using opaque pointer

Peter marked 3 inline comments as done.Nov 28 2022, 4:45 PM
Peter added inline comments.
llvm/unittests/FuzzMutate/StrategiesTest.cpp
396

Ah, seems my understanding of opaque pointer is not 100% correct.
I have fixed that, thanks for pointing out.

arsenm accepted this revision.Nov 28 2022, 4:49 PM
arsenm added inline comments.
llvm/lib/FuzzMutate/IRMutator.cpp
325

s/depends/depend/

llvm/unittests/FuzzMutate/StrategiesTest.cpp
313

static?

This revision is now accepted and ready to land.Nov 28 2022, 4:49 PM
Peter updated this revision to Diff 478422.Nov 28 2022, 5:12 PM
Peter marked an inline comment as done.

typo change. using static for unit testing helper function

Peter marked 2 inline comments as done.Nov 28 2022, 5:17 PM
This revision was landed with ongoing or failed builds.Nov 28 2022, 5:57 PM
This revision was automatically updated to reflect the committed changes.