summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/AutoUpgrade.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/IR/AutoUpgrade.cpp')
-rw-r--r--llvm/lib/IR/AutoUpgrade.cpp39
1 files changed, 29 insertions, 10 deletions
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index a44f6af4162f..0f8c984d5e3c 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -983,7 +983,8 @@ static Intrinsic::ID shouldUpgradeNVPTXBF16Intrinsic(StringRef Name) {
return Intrinsic::not_intrinsic;
}
-static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
+static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
+ bool CanUpgradeDebugIntrinsicsToRecords) {
assert(F && "Illegal to upgrade a non-existent Function.");
StringRef Name = F->getName();
@@ -1057,7 +1058,8 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
case 'd':
if (Name.consume_front("dbg.")) {
// Mark debug intrinsics for upgrade to new debug format.
- if (F->getParent()->IsNewDbgInfoFormat) {
+ if (CanUpgradeDebugIntrinsicsToRecords &&
+ F->getParent()->IsNewDbgInfoFormat) {
if (Name == "addr" || Name == "value" || Name == "assign" ||
Name == "declare" || Name == "label") {
// There's no function to replace these with.
@@ -1413,9 +1415,11 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
return false;
}
-bool llvm::UpgradeIntrinsicFunction(Function *F, Function *&NewFn) {
+bool llvm::UpgradeIntrinsicFunction(Function *F, Function *&NewFn,
+ bool CanUpgradeDebugIntrinsicsToRecords) {
NewFn = nullptr;
- bool Upgraded = upgradeIntrinsicFunction1(F, NewFn);
+ bool Upgraded =
+ upgradeIntrinsicFunction1(F, NewFn, CanUpgradeDebugIntrinsicsToRecords);
assert(F != NewFn && "Intrinsic function upgraded to the same function");
// Upgrade intrinsic attributes. This does not change the function.
@@ -2412,6 +2416,7 @@ void llvm::UpgradeIntrinsicCall(CallBase *CI, Function *NewFn) {
Builder.SetInsertPoint(CI->getParent(), CI->getIterator());
if (!NewFn) {
+ bool FallthroughToDefaultUpgrade = false;
// Get the Function's name.
StringRef Name = F->getName();
@@ -4262,16 +4267,30 @@ void llvm::UpgradeIntrinsicCall(CallBase *CI, Function *NewFn) {
Rep = upgradeARMIntrinsicCall(Name, CI, F, Builder);
} else if (IsAMDGCN) {
Rep = upgradeAMDGCNIntrinsicCall(Name, CI, F, Builder);
- } else if (IsDbg && CI->getModule()->IsNewDbgInfoFormat) {
- upgradeDbgIntrinsicToDbgRecord(Name, CI);
+ } else if (IsDbg) {
+ // We might have decided we don't want the new format after all between
+ // first requesting the upgrade and now; skip the conversion if that is
+ // the case, and check here to see if the intrinsic needs to be upgraded
+ // normally.
+ if (!CI->getModule()->IsNewDbgInfoFormat) {
+ bool NeedsUpgrade =
+ upgradeIntrinsicFunction1(CI->getCalledFunction(), NewFn, false);
+ if (!NeedsUpgrade)
+ return;
+ FallthroughToDefaultUpgrade = true;
+ } else {
+ upgradeDbgIntrinsicToDbgRecord(Name, CI);
+ }
} else {
llvm_unreachable("Unknown function for CallBase upgrade.");
}
- if (Rep)
- CI->replaceAllUsesWith(Rep);
- CI->eraseFromParent();
- return;
+ if (!FallthroughToDefaultUpgrade) {
+ if (Rep)
+ CI->replaceAllUsesWith(Rep);
+ CI->eraseFromParent();
+ return;
+ }
}
const auto &DefaultCase = [&]() -> void {