35 unsigned n =
Init->getNumOperands();
36 CurrentCtors.reserve(n + 1);
37 for (
unsigned i = 0; i != n; ++i)
38 CurrentCtors.push_back(cast<Constant>(
Init->getOperand(i)));
40 GVCtor->eraseFromParent();
45 CSVals[0] = IRB.getInt32(Priority);
52 CurrentCtors.push_back(RuntimeCtorInit);
78 for (
auto &
Op : CA->operands()) {
80 if (InitAsSet.
insert(C).second)
87 for (
auto *V : Values) {
89 if (InitAsSet.
insert(C).second)
99 GV->setSection(
"llvm.metadata");
113 assert(!InitName.
empty() &&
"Expected init function name");
124 assert(!InitName.
empty() &&
"Expected init function name");
126 "Sanitizer's init function expects different number of arguments");
134 IRB.CreateCall(InitFunction, InitArgs);
135 if (!VersionCheckName.
empty()) {
139 IRB.CreateCall(VersionCheckFunction, {});
141 return std::make_pair(Ctor, InitFunction);
144 std::pair<Function *, FunctionCallee>
150 assert(!CtorName.
empty() &&
"Expected ctor function name");
155 if (Ctor->arg_size() == 0 ||
162 M, CtorName, InitName, InitArgTypes, InitArgs, VersionCheckName);
163 FunctionsCreatedCallback(Ctor, InitFunction);
164 return std::make_pair(Ctor, InitFunction);
168 assert(!Name.
empty() &&
"Expected init function name");
170 if (
F->arg_size() != 0 ||
174 Stream <<
"Sanitizer interface function defined with wrong type: " << *
F;
196 for (
Function *
F : DeadComdatFunctions) {
198 assert(C &&
"Expected all input GVs to be in a comdat!");
199 ComdatEntriesCovered[
C] += 1;
202 auto CheckComdat = [&](
Comdat &
C) {
203 auto CI = ComdatEntriesCovered.
find(&
C);
204 if (CI == ComdatEntriesCovered.
end())
209 if (CI->second > 0) {
216 ComdatEntriesCovered.
erase(CI);
219 auto CheckAllComdats = [&] {
223 if (ComdatEntriesCovered.
empty())
227 if (
Comdat *
C = GV.getComdat()) {
229 if (ComdatEntriesCovered.
empty())
233 if (
Comdat *
C = GA.getComdat()) {
235 if (ComdatEntriesCovered.
empty())
241 if (ComdatEntriesCovered.
empty()) {
242 DeadComdatFunctions.clear();
249 ComdatEntriesCovered.
end();
255 bool ExportsSymbols =
false;
257 if (GV.isDeclaration() || GV.getName().startswith(
"llvm.") ||
258 !GV.hasExternalLinkage() || GV.hasComdat())
260 ExportsSymbols =
true;
267 for (
auto &GV : M->globals())
269 for (
auto &GA : M->aliases())
271 for (
auto &
IF : M->ifuncs())
282 return (
"$" + Str).str();
287 if (VariantMappings.
empty())
292 for (
const std::string &VariantMapping : VariantMappings)
293 Out << VariantMapping <<
",";
300 for (
const std::string &VariantMapping : VariantMappings) {
304 "Cannot add variant to attribute: " 305 "vector function declaration is missing.");
void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue *> Values)
Adds global values to the llvm.compiler.used list.
void appendToGlobalDtors(Module &M, Function *F, int Priority, Constant *Data=nullptr)
Same as appendToGlobalCtors(), but for global dtors.
Special purpose, only applies to global arrays.
Function * getOrCreateInitFunction(Module &M, StringRef Name)
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
static void stringifyResult(MD5Result &Result, SmallString< 32 > &Str)
Translates the bytes in Res to a hex string that is deposited into Str.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
unsigned getNumElements() const
Random access to the elements.
void push_back(const T &Elt)
This class represents a function call, abstracting a target machine's calling convention.
An efficient, type-erasing, non-owning reference to a callable.
const GlobalVariable * getNamedGlobal(StringRef Name) const
Return the global variable in the module with the specified name, of arbitrary type.
A raw_ostream that writes to an SmallVector or SmallString.
GlobalVariable * getGlobalVariable(StringRef Name) const
Look up the specified global variable in the module symbol table.
void addAttribute(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
static Constant * get(ArrayType *T, ArrayRef< Constant *> V)
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)
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
Class to represent struct types.
LLVMContext & getContext() const
Get the global data context.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
static StructType * get(LLVMContext &Context, ArrayRef< Type *> Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
StringRef str() const
Explicit conversion to StringRef.
Class to represent function types.
void appendToUsed(Module &M, ArrayRef< GlobalValue *> Values)
Adds global values to the llvm.used list.
const T & getValue() const LLVM_LVALUE_FUNCTION
Class to represent array types.
static constexpr char const * MappingsAttrName
std::pair< Function *, FunctionCallee > getOrCreateSanitizerCtorAndInitFunctions(Module &M, StringRef CtorName, StringRef InitName, ArrayRef< Type *> InitArgTypes, ArrayRef< Value *> InitArgs, function_ref< void(Function *, FunctionCallee)> FunctionsCreatedCallback, StringRef VersionCheckName=StringRef())
Creates sanitizer constructor function lazily.
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type. ...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
iterator find(const_arg_type_t< KeyT > Val)
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool erase(const KeyT &Val)
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
iterator_range< iterator > functions()
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
size_t size() const
size - Get the array size.
This is an important base class in LLVM.
static void appendToGlobalArray(const char *Array, Module &M, Function *F, int Priority, Constant *Data)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
static Type * getVoidTy(LLVMContext &C)
Optional< VFInfo > tryDemangleForVFABI(StringRef MangledName)
Function to contruct a VFInfo out of a mangled names in the following format:
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static Constant * get(StructType *T, ArrayRef< Constant *> V)
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
static void appendToUsedList(Module &M, StringRef Name, ArrayRef< GlobalValue *> Values)
std::string getUniqueModuleId(Module *M)
Produce a unique identifier for this module by taking the MD5 sum of the names of the module's strong...
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the generic address space (address sp...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
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.
FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
const Comdat * getComdat() const
FunctionCallee declareSanitizerInitFunction(Module &M, StringRef InitName, ArrayRef< Type *> InitArgTypes)
void filterDeadComdatFunctions(Module &M, SmallVectorImpl< Function *> &DeadComdatFunctions)
Filter out potentially dead comdat functions where other entries keep the entire comdat group alive...
LLVM_NODISCARD bool empty() const
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
Rename collisions when linking (static functions).
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
LLVM_NODISCARD bool empty() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A raw_ostream that writes to an std::string.
void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
iterator_range< global_iterator > globals()
StringRef - Represent a constant reference to a string, i.e.
std::pair< Function *, FunctionCallee > createSanitizerCtorAndInitFunctions(Module &M, StringRef CtorName, StringRef InitName, ArrayRef< Type *> InitArgTypes, ArrayRef< Value *> InitArgs, StringRef VersionCheckName=StringRef())
Creates sanitizer constructor function, and calls sanitizer's init function from it.
void setVectorVariantNames(CallInst *CI, const SmallVector< std::string, 8 > &VariantMappings)
Overwrite the Vector Function ABI variants attribute with the names provide in VariantMappings.
iterator_range< alias_iterator > aliases()