17std::unique_ptr<Module>
20 assert(M->getNamedMetadata(
"llvm.dbg.cu") &&
21 "Expected module with debug info");
23 auto ShouldPromoteGlobal = [](
const GlobalValue &GV) {
24 if (!GV.hasLocalLinkage())
38 auto ShouldCloneDefinition = [](
const GlobalValue *GV) {
42 std::unique_ptr<Module> UnoptM =
CloneModule(*M, VMap, ShouldCloneDefinition);
46 for (
Function &OuterDef : M->functions()) {
47 if (OuterDef.isDeclaration())
60 InnerDef->
addFnAttr(Attribute::OptimizeNone);
70 OuterDef.addFnAttr(Attribute::NoIPA);
74 OuterDef.addFnAttr(Attribute::NoOutline);
76 if (M->getTargetTriple().isX86_64()) {
77 OuterDef.addFnAttr(
"tail-pad-to-size",
"5");
78 OuterDef.addFnAttr(
"tail-pad-value",
"144");
83 if (OuterDef.hasComdat()) {
84 std::string NewComdat =
85 Twine(
"__dyndbg." + OuterDef.getComdat()->getName()).
str();
86 Comdat *
C = M->getOrInsertComdat(NewComdat);
87 C->setSelectionKind(OuterDef.getComdat()->getSelectionKind());
93 if (ShouldPromoteGlobal(OuterDef)) {
94 InnerDef->
setName(
"__dyndbg." + InnerDef->
getName() + PromotionSuffix);
106 OuterDef.getAddressSpace(), OuterDef.getName(), UnoptM.get());
115 VMap[&OuterDef] = InnerDeclOfOuterDef;
126 if (GV.isDiscardableIfUnused()) {
127 if (GV.getNumUses()) {
130 if (GV.getName().empty())
131 GV.setName(
"__unnamed");
136 auto GVAndUnoptPair = VMap.
find(&GV);
137 assert(GVAndUnoptPair != VMap.
end() &&
"Unmapped global?");
141 "expected only declarations in VMap now");
143 GVAndUnoptPair->second =
nullptr;
149 if (!ShouldPromoteGlobal(GV))
154 GV.getName() + PromotionSuffix, &GV);
161 UnoptGV->
setName(Alias->getName());
164 "Expected ExternalLinkage from CloneModule or inserted decl");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
Module.h This file contains the declarations for the Module class.
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
void setPersonalityFn(Constant *Fn)
void removeFnAttr(Attribute::AttrKind Kind)
Remove function attributes from this function.
void copyAttributesFrom(const Function *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a Function) from the ...
static LLVM_ABI GlobalAlias * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Aliasee, Module *Parent)
If a parent module is specified, the alias is automatically inserted into the end of the specified mo...
LLVM_ABI void setComdat(Comdat *C)
LinkageTypes getLinkage() const
void setLinkage(LinkageTypes LT)
@ HiddenVisibility
The GV is hidden.
void setVisibility(VisibilityTypes V)
@ ExternalLinkage
Externally visible function.
A Module instance is used to store all the information related to an LLVM module.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
iterator find(const KeyT &Val)
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
This is an optimization pass for GlobalISel generic memory operations.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
ValueMap< const Value *, WeakTrackingVH > ValueToValueMapTy
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI std::unique_ptr< Module > CloneModule(const Module &M)
Return an exact copy of the specified module.
LLVM_ABI std::unique_ptr< Module > prepareForDynamicDebugging(Module *M, StringRef PromotionSuffix)
Modify M to prepare it for dynamic debugging before running optimizations.