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);
47 for (
Function &OuterDef : M->functions()) {
48 if (OuterDef.isDeclaration())
61 InnerDef->
addFnAttr(Attribute::OptimizeNone);
71 OuterDef.addFnAttr(Attribute::NoIPA);
75 OuterDef.addFnAttr(Attribute::NoOutline);
77 if (M->getTargetTriple().isX86_64()) {
78 OuterDef.addFnAttr(
"tail-pad-to-size",
"5");
79 OuterDef.addFnAttr(
"tail-pad-value",
"144");
84 if (OuterDef.hasComdat()) {
85 std::string NewComdat =
86 Twine(
"__dyndbg." + OuterDef.getComdat()->getName()).
str();
87 Comdat *
C = M->getOrInsertComdat(NewComdat);
88 C->setSelectionKind(OuterDef.getComdat()->getSelectionKind());
94 if (ShouldPromoteGlobal(OuterDef)) {
95 InnerDef->
setName(
"__dyndbg." + InnerDef->
getName() + PromotionSuffix);
107 OuterDef.getAddressSpace(), OuterDef.getName(), UnoptM.get());
116 VMap[&OuterDef] = InnerDeclOfOuterDef;
127 if (GV.isDiscardableIfUnused()) {
128 if (GV.getNumUses()) {
131 if (GV.getName().empty())
132 GV.setName(
"__unnamed");
137 auto GVAndUnoptPair = VMap.
find(&GV);
138 assert(GVAndUnoptPair != VMap.
end() &&
"Unmapped global?");
142 "expected only declarations in VMap now");
144 GVAndUnoptPair->second =
nullptr;
150 if (!ShouldPromoteGlobal(GV))
155 GV.getName() + PromotionSuffix, &GV);
162 UnoptGV->
setName(Alias->getName());
165 "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.