mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-19 19:12:56 +02:00
[CallSite removal][MemCpyOptimizer] Replace CallSite with CallBase. NFC
There are also some adjustments to use MaybeAlign in here due to CallBase::getParamAlignment() being deprecated. It would be a little cleaner if getOrEnforceKnownAlignment was migrated to Align/MaybeAlign. Differential Revision: https://reviews.llvm.org/D78345
This commit is contained in:
parent
f4b3697721
commit
f5692f59bc
@ -16,7 +16,6 @@
|
||||
|
||||
#include "llvm/Analysis/AliasAnalysis.h"
|
||||
#include "llvm/IR/BasicBlock.h"
|
||||
#include "llvm/IR/CallSite.h"
|
||||
#include "llvm/IR/PassManager.h"
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
@ -66,7 +65,7 @@ private:
|
||||
bool processMemCpyMemCpyDependence(MemCpyInst *M, MemCpyInst *MDep);
|
||||
bool processMemSetMemCpyDependence(MemCpyInst *M, MemSetInst *MDep);
|
||||
bool performMemCpyToMemSetOptzn(MemCpyInst *M, MemSetInst *MDep);
|
||||
bool processByValArgument(CallSite CS, unsigned ArgNo);
|
||||
bool processByValArgument(CallBase &CB, unsigned ArgNo);
|
||||
Instruction *tryMergingIntoMemset(Instruction *I, Value *StartPtr,
|
||||
Value *ByteVal);
|
||||
|
||||
|
@ -1242,15 +1242,15 @@ bool MemCpyOptPass::processMemMove(MemMoveInst *M) {
|
||||
}
|
||||
|
||||
/// This is called on every byval argument in call sites.
|
||||
bool MemCpyOptPass::processByValArgument(CallSite CS, unsigned ArgNo) {
|
||||
const DataLayout &DL = CS.getCaller()->getParent()->getDataLayout();
|
||||
bool MemCpyOptPass::processByValArgument(CallBase &CB, unsigned ArgNo) {
|
||||
const DataLayout &DL = CB.getCaller()->getParent()->getDataLayout();
|
||||
// Find out what feeds this byval argument.
|
||||
Value *ByValArg = CS.getArgument(ArgNo);
|
||||
Value *ByValArg = CB.getArgOperand(ArgNo);
|
||||
Type *ByValTy = cast<PointerType>(ByValArg->getType())->getElementType();
|
||||
uint64_t ByValSize = DL.getTypeAllocSize(ByValTy);
|
||||
MemDepResult DepInfo = MD->getPointerDependencyFrom(
|
||||
MemoryLocation(ByValArg, LocationSize::precise(ByValSize)), true,
|
||||
CS.getInstruction()->getIterator(), CS.getInstruction()->getParent());
|
||||
CB.getIterator(), CB.getParent());
|
||||
if (!DepInfo.isClobber())
|
||||
return false;
|
||||
|
||||
@ -1269,16 +1269,16 @@ bool MemCpyOptPass::processByValArgument(CallSite CS, unsigned ArgNo) {
|
||||
|
||||
// Get the alignment of the byval. If the call doesn't specify the alignment,
|
||||
// then it is some target specific value that we can't know.
|
||||
unsigned ByValAlign = CS.getParamAlignment(ArgNo);
|
||||
if (ByValAlign == 0) return false;
|
||||
MaybeAlign ByValAlign = CB.getParamAlign(ArgNo);
|
||||
if (!ByValAlign) return false;
|
||||
|
||||
// If it is greater than the memcpy, then we check to see if we can force the
|
||||
// source of the memcpy to the alignment we need. If we fail, we bail out.
|
||||
AssumptionCache &AC = LookupAssumptionCache();
|
||||
DominatorTree &DT = LookupDomTree();
|
||||
if (MDep->getSourceAlignment() < ByValAlign &&
|
||||
getOrEnforceKnownAlignment(MDep->getSource(), ByValAlign, DL,
|
||||
CS.getInstruction(), &AC, &DT) < ByValAlign)
|
||||
if (MDep->getSourceAlign() < ByValAlign &&
|
||||
getOrEnforceKnownAlignment(MDep->getSource(), ByValAlign->value(), DL,
|
||||
&CB, &AC, &DT) < ByValAlign->value())
|
||||
return false;
|
||||
|
||||
// The address space of the memcpy source must match the byval argument
|
||||
@ -1297,14 +1297,14 @@ bool MemCpyOptPass::processByValArgument(CallSite CS, unsigned ArgNo) {
|
||||
// not just the defining memcpy.
|
||||
MemDepResult SourceDep = MD->getPointerDependencyFrom(
|
||||
MemoryLocation::getForSource(MDep), false,
|
||||
CS.getInstruction()->getIterator(), MDep->getParent());
|
||||
CB.getIterator(), MDep->getParent());
|
||||
if (!SourceDep.isClobber() || SourceDep.getInst() != MDep)
|
||||
return false;
|
||||
|
||||
Value *TmpCast = MDep->getSource();
|
||||
if (MDep->getSource()->getType() != ByValArg->getType()) {
|
||||
BitCastInst *TmpBitCast = new BitCastInst(MDep->getSource(), ByValArg->getType(),
|
||||
"tmpcast", CS.getInstruction());
|
||||
"tmpcast", &CB);
|
||||
// Set the tmpcast's DebugLoc to MDep's
|
||||
TmpBitCast->setDebugLoc(MDep->getDebugLoc());
|
||||
TmpCast = TmpBitCast;
|
||||
@ -1312,10 +1312,10 @@ bool MemCpyOptPass::processByValArgument(CallSite CS, unsigned ArgNo) {
|
||||
|
||||
LLVM_DEBUG(dbgs() << "MemCpyOptPass: Forwarding memcpy to byval:\n"
|
||||
<< " " << *MDep << "\n"
|
||||
<< " " << *CS.getInstruction() << "\n");
|
||||
<< " " << CB << "\n");
|
||||
|
||||
// Otherwise we're good! Update the byval argument.
|
||||
CS.setArgument(ArgNo, TmpCast);
|
||||
CB.setArgOperand(ArgNo, TmpCast);
|
||||
++NumMemCpyInstr;
|
||||
return true;
|
||||
}
|
||||
@ -1349,10 +1349,10 @@ bool MemCpyOptPass::iterateOnFunction(Function &F) {
|
||||
RepeatInstruction = processMemCpy(M);
|
||||
else if (MemMoveInst *M = dyn_cast<MemMoveInst>(I))
|
||||
RepeatInstruction = processMemMove(M);
|
||||
else if (auto CS = CallSite(I)) {
|
||||
for (unsigned i = 0, e = CS.arg_size(); i != e; ++i)
|
||||
if (CS.isByValArgument(i))
|
||||
MadeChange |= processByValArgument(CS, i);
|
||||
else if (auto *CB = dyn_cast<CallBase>(I)) {
|
||||
for (unsigned i = 0, e = CB->arg_size(); i != e; ++i)
|
||||
if (CB->isByValArgument(i))
|
||||
MadeChange |= processByValArgument(*CB, i);
|
||||
}
|
||||
|
||||
// Reprocess the instruction if desired.
|
||||
|
Loading…
Reference in New Issue
Block a user