003 File Manager
Current Path:
/usr/src/contrib/llvm-project/llvm/lib/Target/NVPTX
usr
/
src
/
contrib
/
llvm-project
/
llvm
/
lib
/
Target
/
NVPTX
/
📁
..
📁
MCTargetDesc
📄
ManagedStringPool.h
(1.41 KB)
📄
NVPTX.h
(3.22 KB)
📄
NVPTX.td
(4.99 KB)
📄
NVPTXAllocaHoisting.cpp
(2.12 KB)
📄
NVPTXAllocaHoisting.h
(755 B)
📄
NVPTXAsmPrinter.cpp
(71.02 KB)
📄
NVPTXAsmPrinter.h
(11.23 KB)
📄
NVPTXAssignValidGlobalNames.cpp
(2.74 KB)
📄
NVPTXFrameLowering.cpp
(3.41 KB)
📄
NVPTXFrameLowering.h
(1.34 KB)
📄
NVPTXGenericToNVVM.cpp
(11.59 KB)
📄
NVPTXISelDAGToDAG.cpp
(134.03 KB)
📄
NVPTXISelDAGToDAG.h
(3.54 KB)
📄
NVPTXISelLowering.cpp
(198.59 KB)
📄
NVPTXISelLowering.h
(15.65 KB)
📄
NVPTXImageOptimizer.cpp
(5.64 KB)
📄
NVPTXInstrFormats.td
(1.72 KB)
📄
NVPTXInstrInfo.cpp
(7.88 KB)
📄
NVPTXInstrInfo.h
(2.87 KB)
📄
NVPTXInstrInfo.td
(133.35 KB)
📄
NVPTXIntrinsics.td
(329.76 KB)
📄
NVPTXLowerAggrCopies.cpp
(4.85 KB)
📄
NVPTXLowerAggrCopies.h
(744 B)
📄
NVPTXLowerAlloca.cpp
(4.27 KB)
📄
NVPTXLowerArgs.cpp
(9.16 KB)
📄
NVPTXMCExpr.cpp
(2.04 KB)
📄
NVPTXMCExpr.h
(3.92 KB)
📄
NVPTXMachineFunctionInfo.h
(1.71 KB)
📄
NVPTXPeephole.cpp
(4.92 KB)
📄
NVPTXPrologEpilogPass.cpp
(8.91 KB)
📄
NVPTXProxyRegErasure.cpp
(3.81 KB)
📄
NVPTXRegisterInfo.cpp
(4.41 KB)
📄
NVPTXRegisterInfo.h
(2.04 KB)
📄
NVPTXRegisterInfo.td
(3.12 KB)
📄
NVPTXReplaceImageHandles.cpp
(6.27 KB)
📄
NVPTXSubtarget.cpp
(2.15 KB)
📄
NVPTXSubtarget.h
(3.02 KB)
📄
NVPTXTargetMachine.cpp
(14.25 KB)
📄
NVPTXTargetMachine.h
(3.33 KB)
📄
NVPTXTargetObjectFile.h
(1.53 KB)
📄
NVPTXTargetTransformInfo.cpp
(6.18 KB)
📄
NVPTXTargetTransformInfo.h
(4.7 KB)
📄
NVPTXUtilities.cpp
(9.37 KB)
📄
NVPTXUtilities.h
(2.03 KB)
📄
NVVMIntrRange.cpp
(4.88 KB)
📄
NVVMReflect.cpp
(6.8 KB)
📁
TargetInfo
📄
cl_common_defines.h
(3.94 KB)
Editing: NVPTXLowerAlloca.cpp
//===-- NVPTXLowerAlloca.cpp - Make alloca to use local memory =====--===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // For all alloca instructions, and add a pair of cast to local address for // each of them. For example, // // %A = alloca i32 // store i32 0, i32* %A ; emits st.u32 // // will be transformed to // // %A = alloca i32 // %Local = addrspacecast i32* %A to i32 addrspace(5)* // %Generic = addrspacecast i32 addrspace(5)* %A to i32* // store i32 0, i32 addrspace(5)* %Generic ; emits st.local.u32 // // And we will rely on NVPTXInferAddressSpaces to combine the last two // instructions. // //===----------------------------------------------------------------------===// #include "NVPTX.h" #include "NVPTXUtilities.h" #include "MCTargetDesc/NVPTXBaseInfo.h" #include "llvm/IR/Function.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Module.h" #include "llvm/IR/Type.h" #include "llvm/Pass.h" using namespace llvm; namespace llvm { void initializeNVPTXLowerAllocaPass(PassRegistry &); } namespace { class NVPTXLowerAlloca : public FunctionPass { bool runOnFunction(Function &F) override; public: static char ID; // Pass identification, replacement for typeid NVPTXLowerAlloca() : FunctionPass(ID) {} StringRef getPassName() const override { return "convert address space of alloca'ed memory to local"; } }; } // namespace char NVPTXLowerAlloca::ID = 1; INITIALIZE_PASS(NVPTXLowerAlloca, "nvptx-lower-alloca", "Lower Alloca", false, false) // ============================================================================= // Main function for this pass. // ============================================================================= bool NVPTXLowerAlloca::runOnFunction(Function &F) { if (skipFunction(F)) return false; bool Changed = false; for (auto &BB : F) for (auto &I : BB) { if (auto allocaInst = dyn_cast<AllocaInst>(&I)) { Changed = true; auto ETy = cast<PointerType>(allocaInst->getType())->getElementType(); auto LocalAddrTy = PointerType::get(ETy, ADDRESS_SPACE_LOCAL); auto NewASCToLocal = new AddrSpaceCastInst(allocaInst, LocalAddrTy, ""); auto GenericAddrTy = PointerType::get(ETy, ADDRESS_SPACE_GENERIC); auto NewASCToGeneric = new AddrSpaceCastInst(NewASCToLocal, GenericAddrTy, ""); NewASCToLocal->insertAfter(allocaInst); NewASCToGeneric->insertAfter(NewASCToLocal); for (Value::use_iterator UI = allocaInst->use_begin(), UE = allocaInst->use_end(); UI != UE;) { // Check Load, Store, GEP, and BitCast Uses on alloca and make them // use the converted generic address, in order to expose non-generic // addrspacecast to NVPTXInferAddressSpaces. For other types // of instructions this is unnecessary and may introduce redundant // address cast. const auto &AllocaUse = *UI++; auto LI = dyn_cast<LoadInst>(AllocaUse.getUser()); if (LI && LI->getPointerOperand() == allocaInst && !LI->isVolatile()) { LI->setOperand(LI->getPointerOperandIndex(), NewASCToGeneric); continue; } auto SI = dyn_cast<StoreInst>(AllocaUse.getUser()); if (SI && SI->getPointerOperand() == allocaInst && !SI->isVolatile()) { SI->setOperand(SI->getPointerOperandIndex(), NewASCToGeneric); continue; } auto GI = dyn_cast<GetElementPtrInst>(AllocaUse.getUser()); if (GI && GI->getPointerOperand() == allocaInst) { GI->setOperand(GI->getPointerOperandIndex(), NewASCToGeneric); continue; } auto BI = dyn_cast<BitCastInst>(AllocaUse.getUser()); if (BI && BI->getOperand(0) == allocaInst) { BI->setOperand(0, NewASCToGeneric); continue; } } } } return Changed; } FunctionPass *llvm::createNVPTXLowerAllocaPass() { return new NVPTXLowerAlloca(); }
Upload File
Create Folder