Go to the documentation of this file.
22 #define DEBUG_TYPE "moduleutils"
36 unsigned n =
Init->getNumOperands();
38 for (
unsigned i = 0;
i !=
n; ++
i)
39 CurrentCtors.push_back(cast<Constant>(
Init->getOperand(
i)));
41 GVCtor->eraseFromParent();
53 CurrentCtors.push_back(RuntimeCtorInit);
80 for (
auto &
Op : CA->operands()) {
90 for (
auto *V : Values) {
116 assert(!InitName.
empty() &&
"Expected init function name");
117 return M.getOrInsertFunction(
139 assert(!InitName.
empty() &&
"Expected init function name");
141 "Sanitizer's init function expects different number of arguments");
147 if (!VersionCheckName.
empty()) {
153 return std::make_pair(Ctor, InitFunction);
156 std::pair<Function *, FunctionCallee>
162 assert(!CtorName.
empty() &&
"Expected ctor function name");
164 if (
Function *Ctor =
M.getFunction(CtorName))
167 if (Ctor->arg_empty() ||
174 M, CtorName, InitName, InitArgTypes, InitArgs, VersionCheckName);
175 FunctionsCreatedCallback(Ctor, InitFunction);
176 return std::make_pair(Ctor, InitFunction);
183 for (
Function *
F : DeadComdatFunctions) {
191 for (
Comdat *
C : MaybeDeadComdats) {
193 auto *
F = dyn_cast<Function>(GO);
196 if (
all_of(
C->getUsers(), IsUserDead))
209 bool ExportsSymbols =
false;
211 if (GV.isDeclaration() || GV.getName().startswith(
"llvm.") ||
212 !GV.hasExternalLinkage() || GV.hasComdat())
214 ExportsSymbols =
true;
221 for (
auto &GV :
M->globals())
223 for (
auto &GA :
M->aliases())
225 for (
auto &
IF :
M->ifuncs())
236 return (
"." + Str).str();
241 if (VariantMappings.
empty())
246 for (
const std::string &VariantMapping : VariantMappings)
247 Out << VariantMapping <<
",";
254 for (
const std::string &VariantMapping : VariantMappings) {
255 LLVM_DEBUG(
dbgs() <<
"VFABI: adding mapping '" << VariantMapping <<
"'\n");
257 assert(
VI.hasValue() &&
"Cannot add an invalid VFABI name.");
258 assert(
M->getNamedValue(
VI.getValue().VectorName) &&
259 "Cannot add variant to attribute: "
260 "vector function declaration is missing.");
274 ModuleConstant,
"llvm.embedded.object");
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
const char * getBufferStart() const
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
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
static void stringifyResult(MD5Result &Result, SmallVectorImpl< char > &Str)
Translates the bytes in Res to a hex string that is deposited into Str.
static Constant * get(StructType *T, ArrayRef< Constant * > V)
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Function * createSanitizerCtor(Module &M, StringRef CtorName)
Creates sanitizer constructor function.
const BasicBlock & getEntryBlock() const
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
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.
size_t getBufferSize() const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Class to represent array types.
bool empty() const
empty - Check if the array is empty.
bool hasInitializer() const
Definitions have initializers, declarations don't.
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
LLVM Basic Block Representation.
void appendToGlobalDtors(Module &M, Function *F, int Priority, Constant *Data=nullptr)
Same as appendToGlobalCtors(), but for global dtors.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
void setSection(StringRef S)
Change the section for this global.
(vector float) vec_cmpeq(*A, *B) C
void addFnAttr(Attribute::AttrKind Kind)
Adds the attribute to the function.
void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
@ InternalLinkage
Rename collisions when linking (static functions).
This struct is a compact representation of a valid (non-zero power of two) alignment.
An efficient, type-erasing, non-owning reference to a callable.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
This is an important base class in LLVM.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
constexpr LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
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 filterDeadComdatFunctions(SmallVectorImpl< Function * > &DeadComdatFunctions)
Filter out potentially dead comdat functions where other entries keep the entire comdat group alive.
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
FunctionCallee declareSanitizerInitFunction(Module &M, StringRef InitName, ArrayRef< Type * > InitArgTypes)
static void appendToGlobalArray(const char *Array, Module &M, Function *F, int Priority, Constant *Data)
void embedBufferInModule(Module &M, MemoryBufferRef Buf, StringRef SectionName, Align Alignment=Align(1))
Embed the memory buffer Buf into the module M as a global using the specified section name.
PointerType * getInt8PtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer to an 8-bit integer value.
void appendToUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.used list.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
A Module instance is used to store all the information related to an LLVM module.
@ AppendingLinkage
Special purpose, only applies to global arrays.
static Function * createWithDefaultAttr(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Creates a function with some attributes recorded in llvm.module.flags applied.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Class to represent struct types.
StringRef - Represent a constant reference to a string, i.e.
Type * getType() const
All values are typed, get the type of this value.
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
unsigned getNumElements() const
Random access to the elements.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
void setVectorVariantNames(CallInst *CI, ArrayRef< std::string > VariantMappings)
Overwrite the Vector Function ABI variants attribute with the names provide in VariantMappings.
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
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 Constant * get(ArrayType *T, ArrayRef< Constant * > V)
StringRef str() const
Explicit conversion to StringRef.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
static Type * getVoidTy(LLVMContext &C)
@ PrivateLinkage
Like Internal, but omit from symbol table.
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
size_t size() const
size - Get the array size.
static constexpr const char * MappingsAttrName
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
A raw_ostream that writes to an SmallVector or SmallString.
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Optional< VFInfo > tryDemangleForVFABI(StringRef MangledName, const Module &M)
Function to construct a VFInfo out of a mangled names in the following format:
This class represents a function call, abstracting a target machine's calling convention.
Type * getVoidTy()
Fetch the type representing void.
static void appendToUsedList(Module &M, StringRef Name, ArrayRef< GlobalValue * > Values)
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 setAlignment(MaybeAlign Align)
The same transformation can work with an even modulo with the addition of a and shrink the compare RHS by the same amount Unless the target supports that transformation probably isn t worthwhile The transformation can also easily be made to work with non zero equality for n
bool contains(ConstPtrType Ptr) const
void reserve(size_type N)
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
Class to represent function types.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.