|
20 | 20 | #include "swift/SIL/PatternMatch.h" |
21 | 21 | #include "swift/SIL/SILBuilder.h" |
22 | 22 | #include "swift/SILOptimizer/Utils/CastOptimizer.h" |
| 23 | +#include "swift/SILOptimizer/Utils/DebugOptUtils.h" |
23 | 24 | #include "swift/SILOptimizer/Utils/InstOptUtils.h" |
24 | 25 | #include "swift/SILOptimizer/Utils/InstructionDeleter.h" |
25 | 26 | #include "llvm/ADT/APFloat.h" |
@@ -1232,8 +1233,8 @@ static SILValue constantFoldIsConcrete(BuiltinInst *BI) { |
1232 | 1233 | return inst; |
1233 | 1234 | } |
1234 | 1235 |
|
1235 | | -SILValue swift::constantFoldBuiltin(BuiltinInst *BI, |
1236 | | - std::optional<bool> &ResultsInError) { |
| 1236 | +static SILValue constantFoldBuiltinWithoutSalvagingDebugInfo(BuiltinInst *BI, |
| 1237 | + std::optional<bool> &ResultsInError) { |
1237 | 1238 | const IntrinsicInfo &Intrinsic = BI->getIntrinsicInfo(); |
1238 | 1239 | SILModule &M = BI->getModule(); |
1239 | 1240 |
|
@@ -1444,6 +1445,20 @@ case BuiltinValueKind::id: |
1444 | 1445 | return nullptr; |
1445 | 1446 | } |
1446 | 1447 |
|
| 1448 | +SILValue swift::constantFoldBuiltin(BuiltinInst *BI, |
| 1449 | + std::optional<bool> &ResultsInError) { |
| 1450 | + const auto value = |
| 1451 | + constantFoldBuiltinWithoutSalvagingDebugInfo(BI, ResultsInError); |
| 1452 | + // Salvage debug info of BI arguments if it was successfully folded. |
| 1453 | + if (value) { |
| 1454 | + for (auto arg : BI->getArguments()) { |
| 1455 | + if (auto *argInst = arg.getDefiningInstruction()) |
| 1456 | + swift::salvageDebugInfo(argInst); |
| 1457 | + } |
| 1458 | + } |
| 1459 | + return value; |
| 1460 | +} |
| 1461 | + |
1447 | 1462 | /// On success this places a new value for each result of Op->getUser() into |
1448 | 1463 | /// Results. Results is guaranteed on success to have the same number of entries |
1449 | 1464 | /// as results of User. If we could only simplify /some/ of an instruction's |
|
0 commit comments