//===-- 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 "MCTargetDesc/NVPTXBaseInfo.h" #include "NVPTX.h" #include "NVPTXUtilities.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" usingnamespacellvm; namespace llvm { void initializeNVPTXLowerAllocaPass(PassRegistry &); } namespace { class NVPTXLowerAlloca : public FunctionPass { … }; } // namespace char NVPTXLowerAlloca::ID = …; INITIALIZE_PASS(…) // ============================================================================= // Main function for this pass. // ============================================================================= bool NVPTXLowerAlloca::runOnFunction(Function &F) { … } FunctionPass *llvm::createNVPTXLowerAllocaPass() { … }