Last active
December 24, 2019 00:35
-
-
Save mewmew/05d625cc101d81e4f7b79469f41105fe to your computer and use it in GitHub Desktop.
Example of use-tracking API with modification of value.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// nopTrunc propagates From values of truncation instructions that have no | |
// effect on type (where From and To type are the same). | |
// | |
// Example: | |
// | |
// before: | |
// %10 = xor i32 %src2, %src1 | |
// %11 = trunc i32 %10 to i32 | |
// %12 = xor i32 %sum, %11 | |
// | |
// after: | |
// %10 = xor i32 %src2, %src1 | |
// %11 = trunc i32 %10 to i32 | |
// ; note use of %10 instead of %11, as trunc was applied from i32 to i32 | |
// %12 = xor i32 %sum, %10 | |
func nopTrunc(f *ir.Func) { | |
uses := irutil.FuncUses(nil, f) | |
for _, use := range uses { | |
truncInst, ok := (*use.Val).(*ir.InstTrunc) | |
if !ok { | |
continue | |
} | |
// Check if types of From and To are equal. | |
if !types.Equal(truncInst.From.Type(), truncInst.To) { | |
continue | |
} | |
// Types of From and To are equal, propagate From and skip trunc | |
// instruction. | |
*use.Val = truncInst.From | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment