aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/TargetInstrInfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen/TargetInstrInfo.cpp')
-rw-r--r--llvm/lib/CodeGen/TargetInstrInfo.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/TargetInstrInfo.cpp b/llvm/lib/CodeGen/TargetInstrInfo.cpp
index 5c5b6a0..9d6c9a6 100644
--- a/llvm/lib/CodeGen/TargetInstrInfo.cpp
+++ b/llvm/lib/CodeGen/TargetInstrInfo.cpp
@@ -1651,10 +1651,25 @@ bool TargetInstrInfo::isMBBSafeToOutlineFrom(MachineBasicBlock &MBB,
// Some instrumentations create special TargetOpcode at the start which
// expands to special code sequences which must be present.
auto First = MBB.getFirstNonDebugInstr();
- if (First != MBB.end() &&
- (First->getOpcode() == TargetOpcode::FENTRY_CALL ||
- First->getOpcode() == TargetOpcode::PATCHABLE_FUNCTION_ENTER))
+ if (First == MBB.end())
+ return true;
+
+ if (First->getOpcode() == TargetOpcode::FENTRY_CALL ||
+ First->getOpcode() == TargetOpcode::PATCHABLE_FUNCTION_ENTER)
+ return false;
+
+ // Some instrumentations create special pseudo-instructions at or just before
+ // the end that must be present.
+ auto Last = MBB.getLastNonDebugInstr();
+ if (Last->getOpcode() == TargetOpcode::PATCHABLE_RET ||
+ Last->getOpcode() == TargetOpcode::PATCHABLE_TAIL_CALL)
return false;
+ if (Last != First && Last->isReturn()) {
+ --Last;
+ if (Last->getOpcode() == TargetOpcode::PATCHABLE_FUNCTION_EXIT ||
+ Last->getOpcode() == TargetOpcode::PATCHABLE_TAIL_CALL)
+ return false;
+ }
return true;
}