Go to the documentation of this file.
23 #define DEBUG_TYPE "moduleutils"
37 unsigned n =
Init->getNumOperands();
39 for (
unsigned i = 0;
i !=
n; ++
i)
40 CurrentCtors.push_back(cast<Constant>(
Init->getOperand(
i)));
42 GVCtor->eraseFromParent();
54 CurrentCtors.push_back(RuntimeCtorInit);
81 for (
auto &
Op : CA->operands()) {
91 for (
auto *V : Values) {
117 assert(!InitName.
empty() &&
"Expected init function name");
118 return M.getOrInsertFunction(
137 assert(!InitName.
empty() &&
"Expected init function name");
139 "Sanitizer's init function expects different number of arguments");
145 if (!VersionCheckName.
empty()) {
151 return std::make_pair(Ctor, InitFunction);
154 std::pair<Function *, FunctionCallee>
160 assert(!CtorName.
empty() &&
"Expected ctor function name");
162 if (
Function *Ctor =
M.getFunction(CtorName))
165 if (Ctor->arg_size() == 0 ||
172 M, CtorName, InitName, InitArgTypes, InitArgs, VersionCheckName);
173 FunctionsCreatedCallback(Ctor, InitFunction);
174 return std::make_pair(Ctor, InitFunction);
178 assert(!
Name.empty() &&
"Expected init function name");
180 if (
F->arg_size() != 0 ||
184 Stream <<
"Sanitizer interface function defined with wrong type: " << *
F;
206 for (
Function *
F : DeadComdatFunctions) {
208 assert(
C &&
"Expected all input GVs to be in a comdat!");
209 ComdatEntriesCovered[
C] += 1;
212 auto CheckComdat = [&](
Comdat &
C) {
213 auto CI = ComdatEntriesCovered.
find(&
C);
214 if (CI == ComdatEntriesCovered.
end())
219 if (CI->second > 0) {
226 ComdatEntriesCovered.
erase(CI);
229 auto CheckAllComdats = [&] {
233 if (ComdatEntriesCovered.
empty())
237 if (
Comdat *
C = GV.getComdat()) {
239 if (ComdatEntriesCovered.
empty())
243 if (
Comdat *
C = GA.getComdat()) {
245 if (ComdatEntriesCovered.
empty())
251 if (ComdatEntriesCovered.
empty()) {
252 DeadComdatFunctions.clear();
259 ComdatEntriesCovered.
end();
265 bool ExportsSymbols =
false;
267 if (GV.isDeclaration() || GV.getName().startswith(
"llvm.") ||
268 !GV.hasExternalLinkage() || GV.hasComdat())
270 ExportsSymbols =
true;
277 for (
auto &GV :
M->globals())
279 for (
auto &GA :
M->aliases())
281 for (
auto &
IF :
M->ifuncs())
292 return (
"$" + Str).str();
297 if (VariantMappings.empty())
302 for (
const std::string &VariantMapping : VariantMappings)
303 Out << VariantMapping <<
",";
310 for (
const std::string &VariantMapping : VariantMappings) {
311 LLVM_DEBUG(
dbgs() <<
"VFABI: adding mapping '" << VariantMapping <<
"'\n");
313 assert(
VI.hasValue() &&
"Cannot add an invalid VFABI name.");
314 assert(
M->getNamedValue(
VI.getValue().VectorName) &&
315 "Cannot add variant to attribute: "
316 "vector function declaration is missing.");
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
This class represents lattice values for constants.
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...
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
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.
void setVectorVariantNames(CallInst *CI, const SmallVector< std::string, 8 > &VariantMappings)
Overwrite the Vector Function ABI variants attribute with the names provide in VariantMappings.
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
void filterDeadComdatFunctions(Module &M, SmallVectorImpl< Function * > &DeadComdatFunctions)
Filter out potentially dead comdat functions where other entries keep the entire comdat group alive.
static Constant * get(StructType *T, ArrayRef< Constant * > V)
static void stringifyResult(MD5Result &Result, SmallString< 32 > &Str)
Translates the bytes in Res to a hex string that is deposited into Str.
A raw_ostream that writes to an std::string.
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 Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
llvm::DenseMapBase< SmallDenseMap< KeyT, ValueT, 4, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::erase bool erase(const KeyT &Val)
The instances of the Type class are immutable: once they are created, they are never changed.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Class to represent array types.
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.
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 appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
@ InternalLinkage
Rename collisions when linking (static functions).
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 generic address space (address sp...
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.
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)
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.
llvm::DenseMapBase< SmallDenseMap< KeyT, ValueT, 4, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::find iterator find(const_arg_type_t< KeyT > Val)
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
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.
Function * getOrCreateInitFunction(Module &M, StringRef Name)
@ AppendingLinkage
Special purpose, only applies to global arrays.
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 BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
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...
unsigned getNumElements() const
Random access to the elements.
llvm::DenseMapBase< SmallDenseMap< KeyT, ValueT, 4, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::empty LLVM_NODISCARD bool empty() const
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
llvm::DenseMapBase< SmallDenseMap< KeyT, ValueT, 4, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::end iterator end()
const Comdat * getComdat() const
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)
size_t size() const
size - Get the array size.
static constexpr const char * MappingsAttrName
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...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void addAttribute(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
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.
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
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.