26#define DEBUG_TYPE "amdgpu-lower-ctor-dtor"
30static Function *createInitOrFiniKernelFunction(
Module &M,
bool IsCtor) {
31 StringRef InitOrFiniKernelName =
"amdgcn.device.init";
33 InitOrFiniKernelName =
"amdgcn.device.fini";
44 InitOrFiniKernel->
addFnAttr(
"device-init");
46 InitOrFiniKernel->
addFnAttr(
"device-fini");
47 return InitOrFiniKernel;
59 Function *InitOrFiniKernel = createInitOrFiniKernelFunction(M, IsCtor);
65 auto *CS = cast<ConstantStruct>(V);
66 IRB.
CreateCall(ConstructorTy, CS->getOperand(1));
75static bool lowerCtorsAndDtors(
Module &M) {
77 Modified |= createInitOrFiniKernel(M,
"llvm.global_ctors",
true);
78 Modified |= createInitOrFiniKernel(M,
"llvm.global_dtors",
false);
82class AMDGPUCtorDtorLoweringLegacy final :
public ModulePass {
87 return lowerCtorsAndDtors(M);
99char AMDGPUCtorDtorLoweringLegacy::ID = 0;
101 AMDGPUCtorDtorLoweringLegacy::ID;
103 "Lower ctors and dtors for AMDGPU",
false,
false)
106 return new AMDGPUCtorDtorLoweringLegacy();
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
A container for analyses that lazily runs them and caches their results.
LLVM Basic Block Representation.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
ConstantArray - Constant Array Declarations.
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
const BasicBlock & getEntryBlock() const
FunctionType * getFunctionType() const
Returns the FunctionType for me.
static Function * createWithDefaultAttr(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Creates a function with some attributes recorded in llvm.module.flags applied.
void setCallingConv(CallingConv::ID CC)
@ ExternalLinkage
Externally visible function.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool hasInitializer() const
Definitions have initializers, declarations don't.
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args=std::nullopt, const Twine &Name="", MDNode *FPMathTag=nullptr)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
virtual bool runOnModule(Module &M)=0
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
StringRef - Represent a constant reference to a string, i.e.
static Type * getVoidTy(LLVMContext &C)
unsigned getNumOperands() const
LLVM Value Representation.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ AMDGPU_KERNEL
Used for AMDGPU code object kernels.
This is an optimization pass for GlobalISel generic memory operations.
char & AMDGPUCtorDtorLoweringLegacyPassID
ModulePass * createAMDGPUCtorDtorLoweringLegacyPass()
void appendToUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.used list.