31 #define DEBUG_TYPE "wasm-lower-global-dtors" 34 class LowerGlobalDtors final :
public ModulePass {
36 return "WebAssembly Lower @llvm.global_dtors";
44 bool runOnModule(
Module &M)
override;
54 "Lower @llvm.global_dtors for WebAssembly",
false,
false)
57 return new LowerGlobalDtors();
60 bool LowerGlobalDtors::runOnModule(
Module &M) {
61 LLVM_DEBUG(
dbgs() <<
"********** Lower Global Destructors **********\n");
73 if (!ETy || ETy->getNumElements() != 3 ||
74 !ETy->getTypeAtIndex(0U)->isIntegerTy() ||
75 !ETy->getTypeAtIndex(1U)->isPointerTy() ||
76 !ETy->getTypeAtIndex(2U)->isPointerTy())
81 std::map<uint16_t, MapVector<Constant *, std::vector<Constant *>>> DtorFuncs;
90 uint16_t PriorityValue = Priority->getLimitedValue(UINT16_MAX);
99 DtorFuncs[PriorityValue][Associated].push_back(DtorFunc);
101 if (DtorFuncs.empty())
107 Type *AtExitFuncArgs[] = {VoidStar};
123 M, DsoHandleTy,
true,
132 for (
auto &PriorityAndMore : DtorFuncs) {
133 uint16_t Priority = PriorityAndMore.first;
134 for (
auto &AssociatedAndMore : PriorityAndMore.second) {
135 Constant *Associated = AssociatedAndMore.first;
140 (Priority != UINT16_MAX ? (
Twine(
".") +
Twine(Priority))
149 for (
auto Dtor : AssociatedAndMore.second)
155 "register_call_dtors" +
156 (Priority != UINT16_MAX ? (
Twine(
".") +
Twine(Priority))
166 Value *
Args[] = {CallDtors, Null, DsoHandle};
void setVisibility(VisibilityTypes V)
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
Like Internal, but omit from symbol table.
GlobalVariable * getGlobalVariable(StringRef Name) const
Look up the specified global variable in the module symbol table.
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end...
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Class to represent struct types.
LLVMContext & getContext() const
Get the global data context.
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
Class to represent function types.
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Type * getType() const
All values are typed, get the type of this value.
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type. ...
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Value * getOperand(unsigned i) const
Class to represent pointers.
ExternalWeak linkage description.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
This function has undefined behavior.
This is an important base class in LLVM.
ModulePass * createWebAssemblyLowerGlobalDtors()
This file contains the declarations for the subclasses of Constant, which represent the different fla...
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
Represent the analysis usage information of a pass.
static Type * getVoidTy(LLVMContext &C)
This instruction compares its operands according to the predicate given to the constructor.
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
const Constant * stripPointerCasts() const
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
This is the shared class of boolean and integer constants.
Module.h This file contains the declarations for the Module class.
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
void appendToGlobalCtors(Module &M, Function *F, int Priority, Constant *Data=nullptr)
Append F to the list of global ctors of module M with the given Priority.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
ConstantArray - Constant Array Declarations.
INITIALIZE_PASS(LowerGlobalDtors, DEBUG_TYPE, "Lower @llvm.global_dtors for WebAssembly", false, false) ModulePass *llvm
ArrayType * getType() const
Specialize the getType() method to always return an ArrayType, which reduces the amount of casting ne...
static IntegerType * getInt32Ty(LLVMContext &C)
StringRef getName() const
Return a constant reference to the value's name.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
LLVM Value Representation.
bool hasInitializer() const
Definitions have initializers, declarations don't.
Type * getElementType() const
StringRef - Represent a constant reference to a string, i.e.
static IntegerType * getInt8Ty(LLVMContext &C)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.