From 55774d8e473f64a6532a76dfc92b796ced44617a Mon Sep 17 00:00:00 2001 From: Pei Mu Date: Tue, 9 May 2023 11:14:12 +0100 Subject: [PATCH] restore the branchElimination and ConstantSubstitution passes, since the overloadFunction should perform immediately after the optimization passes but cannot work by Addresses #653. --- ...2995cdca9486a8fccd8528ffa11b22db6e322c.txt | 46 +++++++++++ .../newton-irPass-LLVMIR-optimizeByRange.cpp | 79 +++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 analysis/statistics/a12995cdca9486a8fccd8528ffa11b22db6e322c.txt diff --git a/analysis/statistics/a12995cdca9486a8fccd8528ffa11b22db6e322c.txt b/analysis/statistics/a12995cdca9486a8fccd8528ffa11b22db6e322c.txt new file mode 100644 index 000000000..9c49b538f --- /dev/null +++ b/analysis/statistics/a12995cdca9486a8fccd8528ffa11b22db6e322c.txt @@ -0,0 +1,46 @@ + +changeset: 1485:a12995cdca9486a8fccd8528ffa11b22db6e322c +char kNewtonVersion[] = "0.3-alpha-1485 (a12995cdca9486a8fccd8528ffa11b22db6e322c) (build 05-07-2023-15:09-pei@pei-G5-5500-Linux-5.19.0-41-generic-x86_64)"; +\n./src/noisy/noisy-linux-EN -O0 applications/noisy/helloWorld.n -s +\n./src/newton/newton-linux-EN -v 0 -eP applications/newton/invariants/ViolinWithTemperatureDependence-pigroups.nt + +Informational Report: +--------------------- +Invariant "ViolinWithTemperatureDependenceForPiGroups" has 2 unique kernels, each with 2 column(s)... + + Kernel 0 is a valid kernel: + + 1 1 + -0.5 -0 + 1 0 + 0.5 0 + 0 -1 + -0 -1 + + + The ordering of parameters is: P1 P0 P3 P2 P4 P5 + + Pi group 0, Pi 0 is: P0^(-0.5) P1^( 1) P2^(0.5) P3^( 1) P4^( 0) P5^(-0) + + Pi group 0, Pi 1 is: P0^(-0) P1^( 1) P2^( 0) P3^( 0) P4^(-1) P5^(-1) + + + Kernel 1 is a valid kernel: + + 1 0 + -0.5 1 + 1 -2 + 0.5 -1 + -0 -2 + 0 -2 + + + The ordering of parameters is: P1 P0 P3 P2 P4 P5 + + Pi group 1, Pi 0 is: P0^(-0.5) P1^( 1) P2^(0.5) P3^( 1) P4^(-0) P5^( 0) + + Pi group 1, Pi 1 is: P0^( 1) P1^( 0) P2^(-1) P3^(-2) P4^(-2) P5^(-2) + + + + diff --git a/src/newton/newton-irPass-LLVMIR-optimizeByRange.cpp b/src/newton/newton-irPass-LLVMIR-optimizeByRange.cpp index 44dca19c4..3ca96f985 100644 --- a/src/newton/newton-irPass-LLVMIR-optimizeByRange.cpp +++ b/src/newton/newton-irPass-LLVMIR-optimizeByRange.cpp @@ -379,6 +379,85 @@ irPassLLVMIROptimizeByRange(State * N) collectCalleeInfo(calleeNames, funcBoundInfo, boundInfo); } + /* + * simplify the condition of each branch + * */ + flexprint(N->Fe, N->Fm, N->Fpinfo, "simplify control flow by range\n"); + for (auto & mi : *Mod) + { + auto boundInfoIt = funcBoundInfo.find(mi.getName().str()); + if (boundInfoIt != funcBoundInfo.end()) + { + simplifyControlFlow(N, boundInfoIt->second, mi); + } + // else + // { + // assert(false); + // } + } + + legacy::PassManager passManager; + passManager.add(createCFGSimplificationPass()); + passManager.add(createInstSimplifyLegacyPass()); + passManager.add(createGlobalDCEPass()); + passManager.run(*Mod); + + /* + * remove the functions that are optimized by passes. + * */ + if (useOverLoad) + cleanFunctionMap(Mod, callerMap); + + if (useOverLoad) + overloadFunc(Mod, callerMap); + + flexprint(N->Fe, N->Fm, N->Fpinfo, "infer bound\n"); + callerMap.clear(); + funcBoundInfo.clear(); + useOverLoad = false; + for (auto & mi : *Mod) + { + auto boundInfo = new BoundInfo(); + mergeBoundInfo(boundInfo, globalBoundInfo); + rangeAnalysis(N, mi, boundInfo, callerMap, typeRange, virtualRegisterVectorRange, useOverLoad); + funcBoundInfo.emplace(mi.getName().str(), boundInfo); + std::vector calleeNames; + collectCalleeInfo(calleeNames, funcBoundInfo, boundInfo); + } + + flexprint(N->Fe, N->Fm, N->Fpinfo, "constant substitution\n"); + for (auto & mi : *Mod) + { + auto boundInfoIt = funcBoundInfo.find(mi.getName().str()); + if (boundInfoIt != funcBoundInfo.end()) + { + constantSubstitution(N, boundInfoIt->second, mi); + } + // else + // { + // assert(false); + // } + } + + /* + * remove the functions that are optimized by passes. + * */ + if (useOverLoad) + cleanFunctionMap(Mod, callerMap); + + if (useOverLoad) + overloadFunc(Mod, callerMap); + + for (auto & mi : *Mod) + { + auto boundInfo = new BoundInfo(); + mergeBoundInfo(boundInfo, globalBoundInfo); + rangeAnalysis(N, mi, boundInfo, callerMap, typeRange, virtualRegisterVectorRange, useOverLoad); + funcBoundInfo.emplace(mi.getName().str(), boundInfo); + std::vector calleeNames; + collectCalleeInfo(calleeNames, funcBoundInfo, boundInfo); + } + flexprint(N->Fe, N->Fm, N->Fpinfo, "emit builtin_assume intrinsic\n"); for (auto & mi : *Mod) {