2012-05-05 04:18:50 +08:00
|
|
|
//===- NVPTXLowerAggrCopies.cpp - ------------------------------*- C++ -*--===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2015-07-17 00:27:19 +08:00
|
|
|
//
|
2015-07-17 04:42:38 +08:00
|
|
|
// \file
|
2012-05-05 04:18:50 +08:00
|
|
|
// Lower aggregate copies, memset, memcpy, memmov intrinsics into loops when
|
|
|
|
// the size is large or is not a compile-time constant.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-06-29 20:38:19 +08:00
|
|
|
#include "NVPTXLowerAggrCopies.h"
|
2015-03-09 23:50:58 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunctionAnalysis.h"
|
|
|
|
#include "llvm/CodeGen/StackProtector.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/DataLayout.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/IR/IRBuilder.h"
|
|
|
|
#include "llvm/IR/Instructions.h"
|
|
|
|
#include "llvm/IR/IntrinsicInst.h"
|
|
|
|
#include "llvm/IR/Intrinsics.h"
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
2015-03-05 02:43:29 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2015-07-17 00:27:19 +08:00
|
|
|
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
2015-03-05 02:43:29 +08:00
|
|
|
|
|
|
|
#define DEBUG_TYPE "nvptx"
|
2012-05-05 04:18:50 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2015-03-09 23:50:58 +08:00
|
|
|
namespace {
|
2015-07-17 00:27:19 +08:00
|
|
|
|
2015-03-09 23:50:58 +08:00
|
|
|
// actual analysis class, which is a functionpass
|
|
|
|
struct NVPTXLowerAggrCopies : public FunctionPass {
|
|
|
|
static char ID;
|
|
|
|
|
|
|
|
NVPTXLowerAggrCopies() : FunctionPass(ID) {}
|
|
|
|
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
|
|
AU.addPreserved<MachineFunctionAnalysis>();
|
|
|
|
AU.addPreserved<StackProtector>();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool runOnFunction(Function &F) override;
|
|
|
|
|
|
|
|
static const unsigned MaxAggrCopySize = 128;
|
|
|
|
|
|
|
|
const char *getPassName() const override {
|
|
|
|
return "Lower aggregate copies/intrinsics into loops";
|
|
|
|
}
|
|
|
|
};
|
2012-05-05 04:18:50 +08:00
|
|
|
|
|
|
|
char NVPTXLowerAggrCopies::ID = 0;
|
|
|
|
|
2015-07-17 00:27:19 +08:00
|
|
|
// Lower memcpy to loop.
|
2015-07-17 04:42:38 +08:00
|
|
|
void convertMemCpyToLoop(Instruction *ConvertedInst, Value *SrcAddr,
|
|
|
|
Value *DstAddr, Value *CopyLen, bool SrcIsVolatile,
|
|
|
|
bool DstIsVolatile, LLVMContext &Context,
|
|
|
|
Function &F) {
|
|
|
|
Type *TypeOfCopyLen = CopyLen->getType();
|
2012-05-05 04:18:50 +08:00
|
|
|
|
2015-07-17 04:42:38 +08:00
|
|
|
BasicBlock *OrigBB = ConvertedInst->getParent();
|
|
|
|
BasicBlock *NewBB =
|
|
|
|
ConvertedInst->getParent()->splitBasicBlock(ConvertedInst, "split");
|
|
|
|
BasicBlock *LoopBB = BasicBlock::Create(Context, "loadstoreloop", &F, NewBB);
|
2012-05-05 04:18:50 +08:00
|
|
|
|
2015-07-17 04:42:38 +08:00
|
|
|
OrigBB->getTerminator()->setSuccessor(0, LoopBB);
|
2015-10-20 08:54:09 +08:00
|
|
|
IRBuilder<> Builder(OrigBB->getTerminator());
|
2012-05-05 04:18:50 +08:00
|
|
|
|
2015-07-17 04:42:38 +08:00
|
|
|
// SrcAddr and DstAddr are expected to be pointer types,
|
2012-05-05 04:18:50 +08:00
|
|
|
// so no check is made here.
|
2015-07-17 04:42:38 +08:00
|
|
|
unsigned SrcAS = cast<PointerType>(SrcAddr->getType())->getAddressSpace();
|
|
|
|
unsigned DstAS = cast<PointerType>(DstAddr->getType())->getAddressSpace();
|
2012-05-05 04:18:50 +08:00
|
|
|
|
|
|
|
// Cast pointers to (char *)
|
2015-07-17 04:42:38 +08:00
|
|
|
SrcAddr = Builder.CreateBitCast(SrcAddr, Builder.getInt8PtrTy(SrcAS));
|
|
|
|
DstAddr = Builder.CreateBitCast(DstAddr, Builder.getInt8PtrTy(DstAS));
|
2012-05-05 04:18:50 +08:00
|
|
|
|
2015-07-17 04:42:38 +08:00
|
|
|
IRBuilder<> LoopBuilder(LoopBB);
|
|
|
|
PHINode *LoopIndex = LoopBuilder.CreatePHI(TypeOfCopyLen, 0);
|
|
|
|
LoopIndex->addIncoming(ConstantInt::get(TypeOfCopyLen, 0), OrigBB);
|
2012-05-05 04:18:50 +08:00
|
|
|
|
2015-07-17 04:42:38 +08:00
|
|
|
// load from SrcAddr+LoopIndex
|
2015-07-10 23:40:33 +08:00
|
|
|
// TODO: we can leverage the align parameter of llvm.memcpy for more efficient
|
|
|
|
// word-sized loads and stores.
|
2015-07-18 00:42:33 +08:00
|
|
|
Value *Element =
|
|
|
|
LoopBuilder.CreateLoad(LoopBuilder.CreateInBoundsGEP(
|
|
|
|
LoopBuilder.getInt8Ty(), SrcAddr, LoopIndex),
|
|
|
|
SrcIsVolatile);
|
2015-07-17 04:42:38 +08:00
|
|
|
// store at DstAddr+LoopIndex
|
2015-07-18 00:42:33 +08:00
|
|
|
LoopBuilder.CreateStore(Element,
|
|
|
|
LoopBuilder.CreateInBoundsGEP(LoopBuilder.getInt8Ty(),
|
|
|
|
DstAddr, LoopIndex),
|
|
|
|
DstIsVolatile);
|
2015-07-17 04:42:38 +08:00
|
|
|
|
|
|
|
// The value for LoopIndex coming from backedge is (LoopIndex + 1)
|
|
|
|
Value *NewIndex =
|
|
|
|
LoopBuilder.CreateAdd(LoopIndex, ConstantInt::get(TypeOfCopyLen, 1));
|
|
|
|
LoopIndex->addIncoming(NewIndex, LoopBB);
|
|
|
|
|
|
|
|
LoopBuilder.CreateCondBr(LoopBuilder.CreateICmpULT(NewIndex, CopyLen), LoopBB,
|
|
|
|
NewBB);
|
2012-05-05 04:18:50 +08:00
|
|
|
}
|
|
|
|
|
2015-07-17 00:27:19 +08:00
|
|
|
// Lower memmove to IR. memmove is required to correctly copy overlapping memory
|
|
|
|
// regions; therefore, it has to check the relative positions of the source and
|
|
|
|
// destination pointers and choose the copy direction accordingly.
|
|
|
|
//
|
|
|
|
// The code below is an IR rendition of this C function:
|
|
|
|
//
|
|
|
|
// void* memmove(void* dst, const void* src, size_t n) {
|
|
|
|
// unsigned char* d = dst;
|
|
|
|
// const unsigned char* s = src;
|
|
|
|
// if (s < d) {
|
|
|
|
// // copy backwards
|
|
|
|
// while (n--) {
|
|
|
|
// d[n] = s[n];
|
|
|
|
// }
|
|
|
|
// } else {
|
|
|
|
// // copy forward
|
|
|
|
// for (size_t i = 0; i < n; ++i) {
|
|
|
|
// d[i] = s[i];
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// return dst;
|
|
|
|
// }
|
2015-07-17 04:42:38 +08:00
|
|
|
void convertMemMoveToLoop(Instruction *ConvertedInst, Value *SrcAddr,
|
|
|
|
Value *DstAddr, Value *CopyLen, bool SrcIsVolatile,
|
|
|
|
bool DstIsVolatile, LLVMContext &Context,
|
|
|
|
Function &F) {
|
|
|
|
Type *TypeOfCopyLen = CopyLen->getType();
|
|
|
|
BasicBlock *OrigBB = ConvertedInst->getParent();
|
2015-07-17 00:27:19 +08:00
|
|
|
|
|
|
|
// Create the a comparison of src and dst, based on which we jump to either
|
|
|
|
// the forward-copy part of the function (if src >= dst) or the backwards-copy
|
|
|
|
// part (if src < dst).
|
|
|
|
// SplitBlockAndInsertIfThenElse conveniently creates the basic if-then-else
|
|
|
|
// structure. Its block terminators (unconditional branches) are replaced by
|
|
|
|
// the appropriate conditional branches when the loop is built.
|
2015-07-17 04:42:38 +08:00
|
|
|
ICmpInst *PtrCompare = new ICmpInst(ConvertedInst, ICmpInst::ICMP_ULT,
|
|
|
|
SrcAddr, DstAddr, "compare_src_dst");
|
2015-07-17 00:27:19 +08:00
|
|
|
TerminatorInst *ThenTerm, *ElseTerm;
|
2015-07-17 04:42:38 +08:00
|
|
|
SplitBlockAndInsertIfThenElse(PtrCompare, ConvertedInst, &ThenTerm,
|
|
|
|
&ElseTerm);
|
2015-07-17 00:27:19 +08:00
|
|
|
|
|
|
|
// Each part of the function consists of two blocks:
|
|
|
|
// copy_backwards: used to skip the loop when n == 0
|
|
|
|
// copy_backwards_loop: the actual backwards loop BB
|
|
|
|
// copy_forward: used to skip the loop when n == 0
|
|
|
|
// copy_forward_loop: the actual forward loop BB
|
|
|
|
BasicBlock *CopyBackwardsBB = ThenTerm->getParent();
|
|
|
|
CopyBackwardsBB->setName("copy_backwards");
|
|
|
|
BasicBlock *CopyForwardBB = ElseTerm->getParent();
|
|
|
|
CopyForwardBB->setName("copy_forward");
|
2015-07-17 04:42:38 +08:00
|
|
|
BasicBlock *ExitBB = ConvertedInst->getParent();
|
2015-07-17 00:27:19 +08:00
|
|
|
ExitBB->setName("memmove_done");
|
|
|
|
|
|
|
|
// Initial comparison of n == 0 that lets us skip the loops altogether. Shared
|
|
|
|
// between both backwards and forward copy clauses.
|
|
|
|
ICmpInst *CompareN =
|
2015-07-17 04:42:38 +08:00
|
|
|
new ICmpInst(OrigBB->getTerminator(), ICmpInst::ICMP_EQ, CopyLen,
|
|
|
|
ConstantInt::get(TypeOfCopyLen, 0), "compare_n_to_0");
|
2015-07-17 00:27:19 +08:00
|
|
|
|
|
|
|
// Copying backwards.
|
|
|
|
BasicBlock *LoopBB =
|
|
|
|
BasicBlock::Create(Context, "copy_backwards_loop", &F, CopyForwardBB);
|
|
|
|
IRBuilder<> LoopBuilder(LoopBB);
|
2015-07-17 04:42:38 +08:00
|
|
|
PHINode *LoopPhi = LoopBuilder.CreatePHI(TypeOfCopyLen, 0);
|
2015-07-17 00:27:19 +08:00
|
|
|
Value *IndexPtr = LoopBuilder.CreateSub(
|
2015-07-17 04:42:38 +08:00
|
|
|
LoopPhi, ConstantInt::get(TypeOfCopyLen, 1), "index_ptr");
|
2015-07-17 00:27:19 +08:00
|
|
|
Value *Element = LoopBuilder.CreateLoad(
|
2015-07-17 04:42:38 +08:00
|
|
|
LoopBuilder.CreateInBoundsGEP(SrcAddr, IndexPtr), "element");
|
2015-07-17 00:27:19 +08:00
|
|
|
LoopBuilder.CreateStore(Element,
|
2015-07-17 04:42:38 +08:00
|
|
|
LoopBuilder.CreateInBoundsGEP(DstAddr, IndexPtr));
|
2015-07-17 00:27:19 +08:00
|
|
|
LoopBuilder.CreateCondBr(
|
2015-07-17 04:42:38 +08:00
|
|
|
LoopBuilder.CreateICmpEQ(IndexPtr, ConstantInt::get(TypeOfCopyLen, 0)),
|
2015-07-17 00:27:19 +08:00
|
|
|
ExitBB, LoopBB);
|
|
|
|
LoopPhi->addIncoming(IndexPtr, LoopBB);
|
2015-07-17 04:42:38 +08:00
|
|
|
LoopPhi->addIncoming(CopyLen, CopyBackwardsBB);
|
2015-07-17 00:27:19 +08:00
|
|
|
BranchInst::Create(ExitBB, LoopBB, CompareN, ThenTerm);
|
2015-07-17 00:51:48 +08:00
|
|
|
ThenTerm->eraseFromParent();
|
2015-07-17 00:27:19 +08:00
|
|
|
|
|
|
|
// Copying forward.
|
|
|
|
BasicBlock *FwdLoopBB =
|
|
|
|
BasicBlock::Create(Context, "copy_forward_loop", &F, ExitBB);
|
|
|
|
IRBuilder<> FwdLoopBuilder(FwdLoopBB);
|
2015-07-17 04:42:38 +08:00
|
|
|
PHINode *FwdCopyPhi = FwdLoopBuilder.CreatePHI(TypeOfCopyLen, 0, "index_ptr");
|
2015-07-17 00:27:19 +08:00
|
|
|
Value *FwdElement = FwdLoopBuilder.CreateLoad(
|
2015-07-17 04:42:38 +08:00
|
|
|
FwdLoopBuilder.CreateInBoundsGEP(SrcAddr, FwdCopyPhi), "element");
|
2015-07-17 00:27:19 +08:00
|
|
|
FwdLoopBuilder.CreateStore(
|
2015-07-17 04:42:38 +08:00
|
|
|
FwdElement, FwdLoopBuilder.CreateInBoundsGEP(DstAddr, FwdCopyPhi));
|
2015-07-17 00:27:19 +08:00
|
|
|
Value *FwdIndexPtr = FwdLoopBuilder.CreateAdd(
|
2015-07-17 04:42:38 +08:00
|
|
|
FwdCopyPhi, ConstantInt::get(TypeOfCopyLen, 1), "index_increment");
|
|
|
|
FwdLoopBuilder.CreateCondBr(FwdLoopBuilder.CreateICmpEQ(FwdIndexPtr, CopyLen),
|
2015-07-17 00:27:19 +08:00
|
|
|
ExitBB, FwdLoopBB);
|
|
|
|
FwdCopyPhi->addIncoming(FwdIndexPtr, FwdLoopBB);
|
2015-07-17 04:42:38 +08:00
|
|
|
FwdCopyPhi->addIncoming(ConstantInt::get(TypeOfCopyLen, 0), CopyForwardBB);
|
2015-07-17 00:27:19 +08:00
|
|
|
|
|
|
|
BranchInst::Create(ExitBB, FwdLoopBB, CompareN, ElseTerm);
|
2015-07-17 00:51:48 +08:00
|
|
|
ElseTerm->eraseFromParent();
|
2015-07-17 00:27:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Lower memset to loop.
|
2015-07-17 04:42:38 +08:00
|
|
|
void convertMemSetToLoop(Instruction *ConvertedInst, Value *DstAddr,
|
|
|
|
Value *CopyLen, Value *SetValue, LLVMContext &Context,
|
|
|
|
Function &F) {
|
|
|
|
BasicBlock *OrigBB = ConvertedInst->getParent();
|
|
|
|
BasicBlock *NewBB =
|
|
|
|
ConvertedInst->getParent()->splitBasicBlock(ConvertedInst, "split");
|
|
|
|
BasicBlock *LoopBB = BasicBlock::Create(Context, "loadstoreloop", &F, NewBB);
|
2012-05-05 04:18:50 +08:00
|
|
|
|
2015-07-17 04:42:38 +08:00
|
|
|
OrigBB->getTerminator()->setSuccessor(0, LoopBB);
|
2015-10-20 08:54:09 +08:00
|
|
|
IRBuilder<> Builder(OrigBB->getTerminator());
|
2012-05-05 04:18:50 +08:00
|
|
|
|
|
|
|
// Cast pointer to the type of value getting stored
|
2015-07-17 04:42:38 +08:00
|
|
|
unsigned dstAS = cast<PointerType>(DstAddr->getType())->getAddressSpace();
|
|
|
|
DstAddr = Builder.CreateBitCast(DstAddr,
|
|
|
|
PointerType::get(SetValue->getType(), dstAS));
|
2012-05-05 04:18:50 +08:00
|
|
|
|
2015-07-17 04:42:38 +08:00
|
|
|
IRBuilder<> LoopBuilder(LoopBB);
|
|
|
|
PHINode *LoopIndex = LoopBuilder.CreatePHI(CopyLen->getType(), 0);
|
|
|
|
LoopIndex->addIncoming(ConstantInt::get(CopyLen->getType(), 0), OrigBB);
|
2012-05-05 04:18:50 +08:00
|
|
|
|
2015-07-17 04:42:38 +08:00
|
|
|
LoopBuilder.CreateStore(
|
2015-07-18 00:42:33 +08:00
|
|
|
SetValue,
|
|
|
|
LoopBuilder.CreateInBoundsGEP(SetValue->getType(), DstAddr, LoopIndex),
|
2015-07-17 04:42:38 +08:00
|
|
|
false);
|
2012-05-05 04:18:50 +08:00
|
|
|
|
2015-07-17 04:42:38 +08:00
|
|
|
Value *NewIndex =
|
|
|
|
LoopBuilder.CreateAdd(LoopIndex, ConstantInt::get(CopyLen->getType(), 1));
|
|
|
|
LoopIndex->addIncoming(NewIndex, LoopBB);
|
2012-05-05 04:18:50 +08:00
|
|
|
|
2015-07-17 04:42:38 +08:00
|
|
|
LoopBuilder.CreateCondBr(LoopBuilder.CreateICmpULT(NewIndex, CopyLen), LoopBB,
|
|
|
|
NewBB);
|
2012-05-05 04:18:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool NVPTXLowerAggrCopies::runOnFunction(Function &F) {
|
2015-07-17 04:42:38 +08:00
|
|
|
SmallVector<LoadInst *, 4> AggrLoads;
|
2015-07-17 00:27:19 +08:00
|
|
|
SmallVector<MemIntrinsic *, 4> MemCalls;
|
2012-05-05 04:18:50 +08:00
|
|
|
|
2015-03-05 02:43:29 +08:00
|
|
|
const DataLayout &DL = F.getParent()->getDataLayout();
|
2012-05-05 04:18:50 +08:00
|
|
|
LLVMContext &Context = F.getParent()->getContext();
|
|
|
|
|
2015-07-17 00:27:19 +08:00
|
|
|
// Collect all aggregate loads and mem* calls.
|
2012-05-05 04:18:50 +08:00
|
|
|
for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI) {
|
|
|
|
for (BasicBlock::iterator II = BI->begin(), IE = BI->end(); II != IE;
|
2013-03-30 22:29:21 +08:00
|
|
|
++II) {
|
2015-07-17 04:42:38 +08:00
|
|
|
if (LoadInst *LI = dyn_cast<LoadInst>(II)) {
|
|
|
|
if (!LI->hasOneUse())
|
2013-03-30 22:29:21 +08:00
|
|
|
continue;
|
2012-05-05 04:18:50 +08:00
|
|
|
|
2015-07-17 04:42:38 +08:00
|
|
|
if (DL.getTypeStoreSize(LI->getType()) < MaxAggrCopySize)
|
2013-03-30 22:29:21 +08:00
|
|
|
continue;
|
2012-05-05 04:18:50 +08:00
|
|
|
|
2015-07-17 04:42:38 +08:00
|
|
|
if (StoreInst *SI = dyn_cast<StoreInst>(LI->user_back())) {
|
|
|
|
if (SI->getOperand(0) != LI)
|
2013-03-30 22:29:21 +08:00
|
|
|
continue;
|
2015-07-17 04:42:38 +08:00
|
|
|
AggrLoads.push_back(LI);
|
2012-05-05 04:18:50 +08:00
|
|
|
}
|
2015-07-17 00:27:19 +08:00
|
|
|
} else if (MemIntrinsic *IntrCall = dyn_cast<MemIntrinsic>(II)) {
|
|
|
|
// Convert intrinsic calls with variable size or with constant size
|
|
|
|
// larger than the MaxAggrCopySize threshold.
|
|
|
|
if (ConstantInt *LenCI = dyn_cast<ConstantInt>(IntrCall->getLength())) {
|
|
|
|
if (LenCI->getZExtValue() >= MaxAggrCopySize) {
|
|
|
|
MemCalls.push_back(IntrCall);
|
2012-05-05 04:18:50 +08:00
|
|
|
}
|
|
|
|
} else {
|
2015-07-17 00:27:19 +08:00
|
|
|
MemCalls.push_back(IntrCall);
|
2012-05-05 04:18:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-17 00:27:19 +08:00
|
|
|
|
2015-07-17 04:42:38 +08:00
|
|
|
if (AggrLoads.size() == 0 && MemCalls.size() == 0) {
|
2013-03-30 22:29:21 +08:00
|
|
|
return false;
|
2015-07-17 00:27:19 +08:00
|
|
|
}
|
2012-05-05 04:18:50 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// Do the transformation of an aggr load/copy/set to a loop
|
|
|
|
//
|
2015-07-17 04:42:38 +08:00
|
|
|
for (LoadInst *LI : AggrLoads) {
|
|
|
|
StoreInst *SI = dyn_cast<StoreInst>(*LI->user_begin());
|
|
|
|
Value *SrcAddr = LI->getOperand(0);
|
|
|
|
Value *DstAddr = SI->getOperand(1);
|
|
|
|
unsigned NumLoads = DL.getTypeStoreSize(LI->getType());
|
|
|
|
Value *CopyLen = ConstantInt::get(Type::getInt32Ty(Context), NumLoads);
|
|
|
|
|
|
|
|
convertMemCpyToLoop(/* ConvertedInst */ SI,
|
|
|
|
/* SrcAddr */ SrcAddr, /* DstAddr */ DstAddr,
|
|
|
|
/* CopyLen */ CopyLen,
|
|
|
|
/* SrcIsVolatile */ LI->isVolatile(),
|
|
|
|
/* DstIsVolatile */ SI->isVolatile(),
|
|
|
|
/* Context */ Context,
|
|
|
|
/* Function F */ F);
|
|
|
|
|
|
|
|
SI->eraseFromParent();
|
|
|
|
LI->eraseFromParent();
|
2012-05-05 04:18:50 +08:00
|
|
|
}
|
|
|
|
|
2015-07-17 00:27:19 +08:00
|
|
|
// Transform mem* intrinsic calls.
|
|
|
|
for (MemIntrinsic *MemCall : MemCalls) {
|
|
|
|
if (MemCpyInst *Memcpy = dyn_cast<MemCpyInst>(MemCall)) {
|
2015-07-17 04:42:38 +08:00
|
|
|
convertMemCpyToLoop(/* ConvertedInst */ Memcpy,
|
|
|
|
/* SrcAddr */ Memcpy->getRawSource(),
|
|
|
|
/* DstAddr */ Memcpy->getRawDest(),
|
|
|
|
/* CopyLen */ Memcpy->getLength(),
|
|
|
|
/* SrcIsVolatile */ Memcpy->isVolatile(),
|
|
|
|
/* DstIsVolatile */ Memcpy->isVolatile(),
|
2015-07-10 23:40:33 +08:00
|
|
|
/* Context */ Context,
|
|
|
|
/* Function F */ F);
|
2015-07-17 00:27:19 +08:00
|
|
|
} else if (MemMoveInst *Memmove = dyn_cast<MemMoveInst>(MemCall)) {
|
2015-07-17 04:42:38 +08:00
|
|
|
convertMemMoveToLoop(/* ConvertedInst */ Memmove,
|
|
|
|
/* SrcAddr */ Memmove->getRawSource(),
|
|
|
|
/* DstAddr */ Memmove->getRawDest(),
|
|
|
|
/* CopyLen */ Memmove->getLength(),
|
|
|
|
/* SrcIsVolatile */ Memmove->isVolatile(),
|
|
|
|
/* DstIsVolatile */ Memmove->isVolatile(),
|
2015-07-17 00:27:19 +08:00
|
|
|
/* Context */ Context,
|
|
|
|
/* Function F */ F);
|
|
|
|
|
|
|
|
} else if (MemSetInst *Memset = dyn_cast<MemSetInst>(MemCall)) {
|
2015-07-17 04:42:38 +08:00
|
|
|
convertMemSetToLoop(/* ConvertedInst */ Memset,
|
|
|
|
/* DstAddr */ Memset->getRawDest(),
|
|
|
|
/* CopyLen */ Memset->getLength(),
|
|
|
|
/* SetValue */ Memset->getValue(),
|
2015-07-17 00:27:19 +08:00
|
|
|
/* Context */ Context,
|
2015-07-17 04:42:38 +08:00
|
|
|
/* Function F */ F);
|
2015-07-17 00:27:19 +08:00
|
|
|
}
|
|
|
|
MemCall->eraseFromParent();
|
2012-05-05 04:18:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-17 00:27:19 +08:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
void initializeNVPTXLowerAggrCopiesPass(PassRegistry &);
|
|
|
|
}
|
|
|
|
|
|
|
|
INITIALIZE_PASS(NVPTXLowerAggrCopies, "nvptx-lower-aggr-copies",
|
|
|
|
"Lower aggregate copies, and llvm.mem* intrinsics into loops",
|
|
|
|
false, false)
|
|
|
|
|
2012-05-05 04:18:50 +08:00
|
|
|
FunctionPass *llvm::createLowerAggrCopies() {
|
|
|
|
return new NVPTXLowerAggrCopies();
|
|
|
|
}
|