diff --git a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp --- a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -90,12 +90,8 @@ #define DEBUG_TYPE "argpromotion" -<<<<<<< HEAD //opt flag to capture user supplied value for GV: GL_NUMPROMARGS cl::opt argmax("numargspromoted", cl::desc("Specify number of args to promote"), cl::value_desc("numargs"), cl::location(llvm::GL_NUMPROMARGS)); -======= -cl::opt argmax("maxar", cl::Required, cl::desc("Specify number of args to promote"), cl::value_desc("maxargs"), cl::location(llvm::GL_MAXARGS)); ->>>>>>> df0f0e791671d16f15d67c1f265b75f5a35a7624 STATISTIC(NumArgumentsPromoted, "Number of pointer arguments promoted"); STATISTIC(NumAggregatesPromoted, "Number of aggregate arguments promoted"); @@ -1076,7 +1072,7 @@ // Pass identification, replacement for typeid static char ID; - explicit ArgPromotion(unsigned MaxElements = 3) + explicit ArgPromotion(unsigned MaxElements = GL_NUMPROMARGS) : CallGraphSCCPass(ID), MaxElements(MaxElements) { initializeArgPromotionPass(*PassRegistry::getPassRegistry()); } @@ -1115,11 +1111,7 @@ "Promote 'by reference' arguments to scalars", false, false) Pass *llvm::createArgumentPromotionPass(unsigned MaxElements) { -<<<<<<< HEAD return new ArgPromotion(GL_NUMPROMARGS); -======= - return new ArgPromotion(GL_MAXARGS); ->>>>>>> df0f0e791671d16f15d67c1f265b75f5a35a7624 } bool ArgPromotion::runOnSCC(CallGraphSCC &SCC) { diff --git a/llvm/test/Transforms/ArgumentPromotion/args-aggregates-mix-promote.ll b/llvm/test/Transforms/ArgumentPromotion/args-aggregates-mix-promote.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/ArgumentPromotion/args-aggregates-mix-promote.ll @@ -0,0 +1,114 @@ +; ModuleID = '/Users/shivamacpro/Desktop/EducationandProjects/GSOC2020/testprograms/mixed-args.cpp' +source_filename = "/Users/shivamacpro/Desktop/EducationandProjects/GSOC2020/testprograms/mixed-args.cpp" +target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.15.0" + +%struct.twomem = type { i32, i32 } +%struct.threemem = type { i32, i32, i32 } +%struct.fourmem = type { i32, i32, i32, i32 } + +; Function Attrs: noinline norecurse ssp uwtable +define i32 @main() #0 { +entry: + %retval = alloca i32, align 4 + %tw = alloca %struct.twomem, align 4 + %th = alloca %struct.threemem, align 4 + %fo = alloca %struct.fourmem, align 4 + %one = alloca i32, align 4 + %two = alloca i32, align 4 + %T = alloca i32, align 4 + store i32 0, i32* %retval, align 4 + %a = getelementptr inbounds %struct.twomem, %struct.twomem* %tw, i32 0, i32 0 + store i32 1, i32* %a, align 4 + %b = getelementptr inbounds %struct.twomem, %struct.twomem* %tw, i32 0, i32 1 + store i32 2, i32* %b, align 4 + %a1 = getelementptr inbounds %struct.threemem, %struct.threemem* %th, i32 0, i32 0 + store i32 3, i32* %a1, align 4 + %b2 = getelementptr inbounds %struct.threemem, %struct.threemem* %th, i32 0, i32 1 + store i32 4, i32* %b2, align 4 + %c = getelementptr inbounds %struct.threemem, %struct.threemem* %th, i32 0, i32 2 + store i32 5, i32* %c, align 4 + %a3 = getelementptr inbounds %struct.fourmem, %struct.fourmem* %fo, i32 0, i32 0 + store i32 6, i32* %a3, align 4 + %b4 = getelementptr inbounds %struct.fourmem, %struct.fourmem* %fo, i32 0, i32 1 + store i32 7, i32* %b4, align 4 + %c5 = getelementptr inbounds %struct.fourmem, %struct.fourmem* %fo, i32 0, i32 2 + store i32 8, i32* %c5, align 4 + %c6 = getelementptr inbounds %struct.fourmem, %struct.fourmem* %fo, i32 0, i32 2 + store i32 9, i32* %c6, align 4 + store i32 8, i32* %one, align 4 + store i32 9, i32* %two, align 4 + %call = call i32 @_ZL6calleePiS_P6twomemP8threememP7fourmem(i32* %one, i32* %two, %struct.twomem* %tw, %struct.threemem* %th, %struct.fourmem* %fo) + store i32 %call, i32* %T, align 4 + ret i32 0 +} + +; Function Attrs: noinline nounwind ssp uwtable +define internal i32 @_ZL6calleePiS_P6twomemP8threememP7fourmem(i32* %A, i32* %B, %struct.twomem* %TW, %struct.threemem* %TH, %struct.fourmem* %FO) #1 { +entry: + %A.addr = alloca i32*, align 8 + %B.addr = alloca i32*, align 8 + %TW.addr = alloca %struct.twomem*, align 8 + %TH.addr = alloca %struct.threemem*, align 8 + %FO.addr = alloca %struct.fourmem*, align 8 + %S = alloca i32, align 4 + store i32* %A, i32** %A.addr, align 8 + store i32* %B, i32** %B.addr, align 8 + store %struct.twomem* %TW, %struct.twomem** %TW.addr, align 8 + store %struct.threemem* %TH, %struct.threemem** %TH.addr, align 8 + store %struct.fourmem* %FO, %struct.fourmem** %FO.addr, align 8 + %0 = load i32*, i32** %A.addr, align 8 + %1 = load i32, i32* %0, align 4 + %2 = load i32*, i32** %B.addr, align 8 + %3 = load i32, i32* %2, align 4 + %add = add nsw i32 %1, %3 + %4 = load %struct.twomem*, %struct.twomem** %TW.addr, align 8 + %a = getelementptr inbounds %struct.twomem, %struct.twomem* %4, i32 0, i32 0 + %5 = load i32, i32* %a, align 4 + %add1 = add nsw i32 %add, %5 + %6 = load %struct.twomem*, %struct.twomem** %TW.addr, align 8 + %b = getelementptr inbounds %struct.twomem, %struct.twomem* %6, i32 0, i32 1 + %7 = load i32, i32* %b, align 4 + %add2 = add nsw i32 %add1, %7 + %8 = load %struct.threemem*, %struct.threemem** %TH.addr, align 8 + %a3 = getelementptr inbounds %struct.threemem, %struct.threemem* %8, i32 0, i32 0 + %9 = load i32, i32* %a3, align 4 + %add4 = add nsw i32 %add2, %9 + %10 = load %struct.threemem*, %struct.threemem** %TH.addr, align 8 + %b5 = getelementptr inbounds %struct.threemem, %struct.threemem* %10, i32 0, i32 1 + %11 = load i32, i32* %b5, align 4 + %add6 = add nsw i32 %add4, %11 + %12 = load %struct.threemem*, %struct.threemem** %TH.addr, align 8 + %c = getelementptr inbounds %struct.threemem, %struct.threemem* %12, i32 0, i32 2 + %13 = load i32, i32* %c, align 4 + %add7 = add nsw i32 %add6, %13 + %14 = load %struct.fourmem*, %struct.fourmem** %FO.addr, align 8 + %a8 = getelementptr inbounds %struct.fourmem, %struct.fourmem* %14, i32 0, i32 0 + %15 = load i32, i32* %a8, align 4 + %add9 = add nsw i32 %add7, %15 + %16 = load %struct.fourmem*, %struct.fourmem** %FO.addr, align 8 + %b10 = getelementptr inbounds %struct.fourmem, %struct.fourmem* %16, i32 0, i32 1 + %17 = load i32, i32* %b10, align 4 + %add11 = add nsw i32 %add9, %17 + %18 = load %struct.fourmem*, %struct.fourmem** %FO.addr, align 8 + %c12 = getelementptr inbounds %struct.fourmem, %struct.fourmem* %18, i32 0, i32 2 + %19 = load i32, i32* %c12, align 4 + %add13 = add nsw i32 %add11, %19 + %20 = load %struct.fourmem*, %struct.fourmem** %FO.addr, align 8 + %d = getelementptr inbounds %struct.fourmem, %struct.fourmem* %20, i32 0, i32 3 + %21 = load i32, i32* %d, align 4 + %add14 = add nsw i32 %add13, %21 + store i32 %add14, i32* %S, align 4 + %22 = load i32, i32* %S, align 4 + ret i32 %22 +} + +attributes #0 = { noinline norecurse ssp uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { noinline nounwind ssp uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.module.flags = !{!0, !1} +!llvm.ident = !{!2} + +!0 = !{i32 1, !"wchar_size", i32 4} +!1 = !{i32 7, !"PIC Level", i32 2} +!2 = !{!"clang version 11.0.0 (https://github.com/teamiceberg/llvm-project.git 1fb9041df0182c3e582bfcb5875e6af743eab0a1)"} diff --git a/llvm/test/Transforms/ArgumentPromotion/fourmember-struct-promote.ll b/llvm/test/Transforms/ArgumentPromotion/fourmember-struct-promote.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/ArgumentPromotion/fourmember-struct-promote.ll @@ -0,0 +1,62 @@ +; ModuleID = '/Users/shivamacpro/Desktop/EducationandProjects/GSOC2020/testprograms/fourmem-struct.cpp' +source_filename = "/Users/shivamacpro/Desktop/EducationandProjects/GSOC2020/testprograms/fourmem-struct.cpp" +target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.15.0" + +%struct.fourmem = type { i32, i32, i32, i32 } + +; Function Attrs: noinline norecurse ssp uwtable +define i32 @main() #0 { +entry: + %retval = alloca i32, align 4 + %four = alloca %struct.fourmem, align 4 + %T = alloca i32, align 4 + store i32 0, i32* %retval, align 4 + %a = getelementptr inbounds %struct.fourmem, %struct.fourmem* %four, i32 0, i32 0 + store i32 1, i32* %a, align 4 + %b = getelementptr inbounds %struct.fourmem, %struct.fourmem* %four, i32 0, i32 1 + store i32 2, i32* %b, align 4 + %c = getelementptr inbounds %struct.fourmem, %struct.fourmem* %four, i32 0, i32 2 + store i32 3, i32* %c, align 4 + %d = getelementptr inbounds %struct.fourmem, %struct.fourmem* %four, i32 0, i32 3 + store i32 4, i32* %d, align 4 + %call = call i32 @_ZL6calleeP7fourmem(%struct.fourmem* %four) + store i32 %call, i32* %T, align 4 + ret i32 0 +} + +; Function Attrs: noinline nounwind ssp uwtable +define internal i32 @_ZL6calleeP7fourmem(%struct.fourmem* %t) #1 { +entry: + %t.addr = alloca %struct.fourmem*, align 8 + %S = alloca i32, align 4 + store %struct.fourmem* %t, %struct.fourmem** %t.addr, align 8 + %0 = load %struct.fourmem*, %struct.fourmem** %t.addr, align 8 + %a = getelementptr inbounds %struct.fourmem, %struct.fourmem* %0, i32 0, i32 0 + %1 = load i32, i32* %a, align 4 + %2 = load %struct.fourmem*, %struct.fourmem** %t.addr, align 8 + %b = getelementptr inbounds %struct.fourmem, %struct.fourmem* %2, i32 0, i32 1 + %3 = load i32, i32* %b, align 4 + %add = add nsw i32 %1, %3 + %4 = load %struct.fourmem*, %struct.fourmem** %t.addr, align 8 + %c = getelementptr inbounds %struct.fourmem, %struct.fourmem* %4, i32 0, i32 2 + %5 = load i32, i32* %c, align 4 + %add1 = add nsw i32 %add, %5 + %6 = load %struct.fourmem*, %struct.fourmem** %t.addr, align 8 + %d = getelementptr inbounds %struct.fourmem, %struct.fourmem* %6, i32 0, i32 3 + %7 = load i32, i32* %d, align 4 + %add2 = add nsw i32 %add1, %7 + store i32 %add2, i32* %S, align 4 + %8 = load i32, i32* %S, align 4 + ret i32 %8 +} + +attributes #0 = { noinline norecurse ssp uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { noinline nounwind ssp uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.module.flags = !{!0, !1} +!llvm.ident = !{!2} + +!0 = !{i32 1, !"wchar_size", i32 4} +!1 = !{i32 7, !"PIC Level", i32 2} +!2 = !{!"clang version 11.0.0 (https://github.com/teamiceberg/llvm-project.git 1fb9041df0182c3e582bfcb5875e6af743eab0a1)"}