32 #define DEBUG_TYPE "wasm-lower-global-dtors" 35 class LowerGlobalDtors final :
public ModulePass {
37 return "WebAssembly Lower @llvm.global_dtors";
45 bool runOnModule(
Module &M)
override;
55 "Lower @llvm.global_dtors for WebAssembly",
false,
false)
58 return new LowerGlobalDtors();
61 bool LowerGlobalDtors::runOnModule(
Module &M) {
62 LLVM_DEBUG(
dbgs() <<
"********** Lower Global Destructors **********\n");
82 std::map<uint16_t, MapVector<Constant *, std::vector<Constant *>>> DtorFuncs;
100 DtorFuncs[PriorityValue][Associated].push_back(DtorFunc);
102 if (DtorFuncs.empty())
108 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))
147 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.
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
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)
unsigned getNumElements() const
Random access to the elements.
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 isIntegerTy() const
True if this is an instance of IntegerType.
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...
bool isPointerTy() const
True if this is an instance of PointerType.
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.
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
getLimitedValue - If the value is smaller than the specified limit, return it, otherwise return the l...
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:
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)
const Value * stripPointerCastsNoFollowAliases() const
Strip off pointer casts and all-zero GEPs.
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.
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.
Type * getTypeAtIndex(const Value *V) const
Given an index value into the type, return the type of the element.