Go to the documentation of this file.
31 #define DEBUG_TYPE "lower-global-dtors"
34 class LowerGlobalDtorsLegacyPass final :
public ModulePass {
36 return "Lower @llvm.global_dtors via `__cxa_atexit`";
44 bool runOnModule(
Module &
M)
override;
56 "Lower @llvm.global_dtors via `__cxa_atexit`",
false,
false)
59 return new LowerGlobalDtorsLegacyPass();
63 bool LowerGlobalDtorsLegacyPass::runOnModule(
Module &M) {
return runImpl(M); }
87 if (!ETy || ETy->getNumElements() != 3 ||
88 !ETy->getTypeAtIndex(0U)->isIntegerTy() ||
89 !ETy->getTypeAtIndex(1U)->isPointerTy() ||
90 !ETy->getTypeAtIndex(2U)->isPointerTy())
98 std::vector<std::pair<Constant *, std::vector<Constant *>>>
101 auto *CS = dyn_cast<ConstantStruct>(
O);
105 auto *Priority = dyn_cast<ConstantInt>(CS->getOperand(0));
108 uint16_t PriorityValue = Priority->getLimitedValue(UINT16_MAX);
117 auto &AtThisPriority = DtorFuncs[PriorityValue];
118 if (AtThisPriority.empty() || AtThisPriority.back().first != Associated) {
119 std::vector<Constant *> NewList;
120 NewList.push_back(DtorFunc);
121 AtThisPriority.push_back(std::make_pair(Associated, NewList));
123 AtThisPriority.back().second.push_back(DtorFunc);
126 if (DtorFuncs.empty())
132 Type *AtExitFuncArgs[] = {VoidStar};
145 Constant *DsoHandle =
M.getOrInsertGlobal(
"__dso_handle", DsoHandleTy, [&] {
156 for (
auto &PriorityAndMore : DtorFuncs) {
157 uint16_t Priority = PriorityAndMore.first;
159 auto &AtThisPriority = PriorityAndMore.second;
160 for (
auto &AssociatedAndMore : AtThisPriority) {
161 Constant *Associated = AssociatedAndMore.first;
167 (Priority != UINT16_MAX ? (
Twine(
".") +
Twine(Priority))
169 (AtThisPriority.size() > 1 ?
Twine(
"$") +
Twine(ThisId)
178 for (
auto Dtor :
reverse(AssociatedAndMore.second))
184 "register_call_dtors" +
185 (Priority != UINT16_MAX ? (
Twine(
".") +
Twine(Priority))
187 (AtThisPriority.size() > 1 ?
Twine(
"$") +
Twine(ThisId)
197 Value *
Args[] = {CallDtors, Null, DsoHandle};
A set of analyses that are preserved following a run of a transformation pass.
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
This is an optimization pass for GlobalISel generic memory operations.
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
@ HiddenVisibility
The GV is hidden.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
void initializeLowerGlobalDtorsLegacyPassPass(PassRegistry &)
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
The instances of the Type class are immutable: once they are created, they are never changed.
auto reverse(ContainerTy &&C, std::enable_if_t< has_rbegin< ContainerTy >::value > *=nullptr)
ModulePass * createLowerGlobalDtorsLegacyPass()
static IntegerType * getInt8Ty(LLVMContext &C)
static IntegerType * getInt32Ty(LLVMContext &C)
bool hasInitializer() const
Definitions have initializers, declarations don't.
LLVM Basic Block Representation.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
(vector float) vec_cmpeq(*A, *B) C
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Represent the analysis usage information of a pass.
ConstantArray - Constant Array Declarations.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
ArrayType * getType() const
Specialize the getType() method to always return an ArrayType, which reduces the amount of casting ne...
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
This is an important base class in LLVM.
This instruction compares its operands according to the predicate given to the constructor.
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
This is an important class for using LLVM in a threaded context.
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
Class to represent pointers.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
A Module instance is used to store all the information related to an LLVM module.
INITIALIZE_PASS(LowerGlobalDtorsLegacyPass, DEBUG_TYPE, "Lower @llvm.global_dtors via `__cxa_atexit`", false, false) ModulePass *llvm
void setPreservesCFG()
This function should be called by the pass, iff they do not:
StringRef - Represent a constant reference to a string, i.e.
Type * getType() const
All values are typed, get the type of this value.
Represents analyses that only rely on functions' control flow.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
StringRef getName() const
Return a constant reference to the value's name.
const Constant * stripPointerCasts() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
static Type * getVoidTy(LLVMContext &C)
@ PrivateLinkage
Like Internal, but omit from symbol table.
void preserveSet()
Mark an analysis set as preserved.
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
static bool runImpl(Module &M)
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
A container for analyses that lazily runs them and caches their results.
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
This function has undefined behavior.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
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.
Value * getOperand(unsigned i) const
@ ExternalWeakLinkage
ExternalWeak linkage description.
void setVisibility(VisibilityTypes V)
LLVM Value Representation.
Type * getElementType() const
Class to represent function types.