aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp32
1 files changed, 12 insertions, 20 deletions
diff --git a/contrib/llvm-project/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp b/contrib/llvm-project/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
index 01aba47cdbff..19bc841b1052 100644
--- a/contrib/llvm-project/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
+++ b/contrib/llvm-project/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
@@ -311,7 +311,7 @@ void wholeprogramdevirt::setAfterReturnValues(
VirtualCallTarget::VirtualCallTarget(GlobalValue *Fn, const TypeMemberInfo *TM)
: Fn(Fn), TM(TM),
- IsBigEndian(Fn->getParent()->getDataLayout().isBigEndian()),
+ IsBigEndian(Fn->getDataLayout().isBigEndian()),
WasDevirt(false) {}
namespace {
@@ -434,7 +434,7 @@ struct VirtualCallSite {
emitRemark(OptName, TargetName, OREGetter);
CB.replaceAllUsesWith(New);
if (auto *II = dyn_cast<InvokeInst>(&CB)) {
- BranchInst::Create(II->getNormalDest(), &CB);
+ BranchInst::Create(II->getNormalDest(), CB.getIterator());
II->getUnwindDest()->removePredecessor(II->getParent());
}
CB.eraseFromParent();
@@ -861,7 +861,7 @@ void llvm::updatePublicTypeTestCalls(Module &M,
auto *CI = cast<CallInst>(U.getUser());
auto *NewCI = CallInst::Create(
TypeTestFunc, {CI->getArgOperand(0), CI->getArgOperand(1)},
- std::nullopt, "", CI);
+ std::nullopt, "", CI->getIterator());
CI->replaceAllUsesWith(NewCI);
CI->eraseFromParent();
}
@@ -1066,17 +1066,10 @@ bool DevirtModule::tryFindVirtualCallTargets(
GlobalObject::VCallVisibilityPublic)
return false;
- Constant *Ptr = getPointerAtOffset(TM.Bits->GV->getInitializer(),
- TM.Offset + ByteOffset, M, TM.Bits->GV);
- if (!Ptr)
- return false;
-
- auto C = Ptr->stripPointerCasts();
- // Make sure this is a function or alias to a function.
- auto Fn = dyn_cast<Function>(C);
- auto A = dyn_cast<GlobalAlias>(C);
- if (!Fn && A)
- Fn = dyn_cast<Function>(A->getAliasee());
+ Function *Fn = nullptr;
+ Constant *C = nullptr;
+ std::tie(Fn, C) =
+ getFunctionAtVTableOffset(TM.Bits->GV, TM.Offset + ByteOffset, M);
if (!Fn)
return false;
@@ -1203,8 +1196,7 @@ void DevirtModule::applySingleImplDevirt(VTableSlotInfo &SlotInfo,
// function pointer to the devirtualized target. In case of a mismatch,
// fall back to indirect call.
if (DevirtCheckMode == WPDCheckMode::Fallback) {
- MDNode *Weights =
- MDBuilder(M.getContext()).createBranchWeights((1U << 20) - 1, 1);
+ MDNode *Weights = MDBuilder(M.getContext()).createLikelyBranchWeights();
// Version the indirect call site. If the called value is equal to the
// given callee, 'NewInst' will be executed, otherwise the original call
// site will be executed.
@@ -1232,8 +1224,8 @@ void DevirtModule::applySingleImplDevirt(VTableSlotInfo &SlotInfo,
CB.setMetadata(LLVMContext::MD_callees, nullptr);
if (CB.getCalledOperand() &&
CB.getOperandBundle(LLVMContext::OB_ptrauth)) {
- auto *NewCS =
- CallBase::removeOperandBundle(&CB, LLVMContext::OB_ptrauth, &CB);
+ auto *NewCS = CallBase::removeOperandBundle(
+ &CB, LLVMContext::OB_ptrauth, CB.getIterator());
CB.replaceAllUsesWith(NewCS);
// Schedule for deletion at the end of pass run.
CallsWithPtrAuthBundleRemoved.push_back(&CB);
@@ -1624,7 +1616,7 @@ std::string DevirtModule::getGlobalName(VTableSlot Slot,
for (uint64_t Arg : Args)
OS << '_' << Arg;
OS << '_' << Name;
- return OS.str();
+ return FullName;
}
bool DevirtModule::shouldExportConstantsAsAbsoluteSymbols() {
@@ -1935,7 +1927,7 @@ void DevirtModule::rebuildGlobal(VTableBits &B) {
// element (the original initializer).
auto Alias = GlobalAlias::create(
B.GV->getInitializer()->getType(), 0, B.GV->getLinkage(), "",
- ConstantExpr::getGetElementPtr(
+ ConstantExpr::getInBoundsGetElementPtr(
NewInit->getType(), NewGV,
ArrayRef<Constant *>{ConstantInt::get(Int32Ty, 0),
ConstantInt::get(Int32Ty, 1)}),