Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
ModuleUtils.cpp
Go to the documentation of this file.
1//===-- ModuleUtils.cpp - Functions to manipulate Modules -----------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This family of functions perform manipulations on Modules.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/Transforms/Utils/ModuleUtils.h"
14#include "llvm/Analysis/VectorUtils.h"
15#include "llvm/ADT/SmallString.h"
16#include "llvm/IR/DerivedTypes.h"
17#include "llvm/IR/Function.h"
18#include "llvm/IR/IRBuilder.h"
19#include "llvm/IR/MDBuilder.h"
20#include "llvm/IR/Module.h"
21#include "llvm/Support/MD5.h"
22#include "llvm/Support/raw_ostream.h"
23#include "llvm/Support/xxhash.h"
24
25using namespacellvm;
26
27#define DEBUG_TYPE "moduleutils"
28
29staticvoidappendToGlobalArray(StringRef ArrayName,Module &M,Function *F,
30int Priority,Constant *Data) {
31IRBuilder<> IRB(M.getContext());
32
33// Get the current set of static global constructors and add the new ctor
34// to the list.
35SmallVector<Constant *, 16> CurrentCtors;
36StructType *EltTy;
37if (GlobalVariable *GVCtor = M.getNamedGlobal(ArrayName)) {
38 EltTy = cast<StructType>(GVCtor->getValueType()->getArrayElementType());
39if (Constant *Init = GVCtor->getInitializer()) {
40unsigned n =Init->getNumOperands();
41 CurrentCtors.reserve(n + 1);
42for (unsigned i = 0; i != n; ++i)
43 CurrentCtors.push_back(cast<Constant>(Init->getOperand(i)));
44 }
45 GVCtor->eraseFromParent();
46 }else {
47 EltTy =StructType::get(
48 IRB.getInt32Ty(),
49 PointerType::get(M.getContext(),F->getAddressSpace()), IRB.getPtrTy());
50 }
51
52// Build a 3 field global_ctor entry. We don't take a comdat key.
53Constant *CSVals[3];
54 CSVals[0] = IRB.getInt32(Priority);
55 CSVals[1] =F;
56 CSVals[2] = Data ?ConstantExpr::getPointerCast(Data, IRB.getPtrTy())
57 :Constant::getNullValue(IRB.getPtrTy());
58Constant *RuntimeCtorInit =
59ConstantStruct::get(EltTy,ArrayRef(CSVals, EltTy->getNumElements()));
60
61 CurrentCtors.push_back(RuntimeCtorInit);
62
63// Create a new initializer.
64ArrayType *AT = ArrayType::get(EltTy, CurrentCtors.size());
65Constant *NewInit =ConstantArray::get(AT, CurrentCtors);
66
67// Create the new global variable and replace all uses of
68// the old global variable with the new one.
69 (void)newGlobalVariable(M, NewInit->getType(),false,
70GlobalValue::AppendingLinkage, NewInit, ArrayName);
71}
72
73voidllvm::appendToGlobalCtors(Module &M,Function *F,int Priority,Constant *Data) {
74appendToGlobalArray("llvm.global_ctors", M,F, Priority, Data);
75}
76
77voidllvm::appendToGlobalDtors(Module &M,Function *F,int Priority,Constant *Data) {
78appendToGlobalArray("llvm.global_dtors", M,F, Priority, Data);
79}
80
81staticvoidtransformGlobalArray(StringRef ArrayName,Module &M,
82constGlobalCtorTransformFn &Fn) {
83GlobalVariable *GVCtor = M.getNamedGlobal(ArrayName);
84if (!GVCtor)
85return;
86
87IRBuilder<> IRB(M.getContext());
88SmallVector<Constant *, 16> CurrentCtors;
89bool Changed =false;
90StructType *EltTy =
91 cast<StructType>(GVCtor->getValueType()->getArrayElementType());
92if (Constant *Init = GVCtor->getInitializer()) {
93 CurrentCtors.reserve(Init->getNumOperands());
94for (Value *OP :Init->operands()) {
95Constant *C = cast<Constant>(OP);
96Constant *NewC = Fn(C);
97 Changed |= (!NewC || NewC !=C);
98if (NewC)
99 CurrentCtors.push_back(NewC);
100 }
101 }
102if (!Changed)
103return;
104
105 GVCtor->eraseFromParent();
106
107// Create a new initializer.
108ArrayType *AT = ArrayType::get(EltTy, CurrentCtors.size());
109Constant *NewInit =ConstantArray::get(AT, CurrentCtors);
110
111// Create the new global variable and replace all uses of
112// the old global variable with the new one.
113 (void)newGlobalVariable(M, NewInit->getType(),false,
114GlobalValue::AppendingLinkage, NewInit, ArrayName);
115}
116
117voidllvm::transformGlobalCtors(Module &M,constGlobalCtorTransformFn &Fn) {
118transformGlobalArray("llvm.global_ctors", M, Fn);
119}
120
121voidllvm::transformGlobalDtors(Module &M,constGlobalCtorTransformFn &Fn) {
122transformGlobalArray("llvm.global_dtors", M, Fn);
123}
124
125staticvoidcollectUsedGlobals(GlobalVariable *GV,
126SmallSetVector<Constant *, 16> &Init) {
127if (!GV || !GV->hasInitializer())
128return;
129
130auto *CA = cast<ConstantArray>(GV->getInitializer());
131for (Use &Op : CA->operands())
132Init.insert(cast<Constant>(Op));
133}
134
135staticvoidappendToUsedList(Module &M,StringRefName,ArrayRef<GlobalValue *> Values) {
136GlobalVariable *GV = M.getGlobalVariable(Name);
137
138SmallSetVector<Constant *, 16>Init;
139collectUsedGlobals(GV,Init);
140if (GV)
141 GV->eraseFromParent();
142
143Type *ArrayEltTy =llvm::PointerType::getUnqual(M.getContext());
144for (auto *V : Values)
145Init.insert(ConstantExpr::getPointerBitCastOrAddrSpaceCast(V, ArrayEltTy));
146
147if (Init.empty())
148return;
149
150ArrayType *ATy = ArrayType::get(ArrayEltTy,Init.size());
151 GV =newllvm::GlobalVariable(M, ATy,false,GlobalValue::AppendingLinkage,
152ConstantArray::get(ATy,Init.getArrayRef()),
153Name);
154 GV->setSection("llvm.metadata");
155}
156
157voidllvm::appendToUsed(Module &M,ArrayRef<GlobalValue *> Values) {
158appendToUsedList(M,"llvm.used", Values);
159}
160
161voidllvm::appendToCompilerUsed(Module &M,ArrayRef<GlobalValue *> Values) {
162appendToUsedList(M,"llvm.compiler.used", Values);
163}
164
165staticvoidremoveFromUsedList(Module &M,StringRefName,
166function_ref<bool(Constant *)> ShouldRemove) {
167GlobalVariable *GV = M.getNamedGlobal(Name);
168if (!GV)
169return;
170
171SmallSetVector<Constant *, 16>Init;
172collectUsedGlobals(GV,Init);
173
174Type *ArrayEltTy = cast<ArrayType>(GV->getValueType())->getElementType();
175
176SmallVector<Constant *, 16> NewInit;
177for (Constant *MaybeRemoved :Init) {
178if (!ShouldRemove(MaybeRemoved->stripPointerCasts()))
179 NewInit.push_back(MaybeRemoved);
180 }
181
182if (!NewInit.empty()) {
183ArrayType *ATy = ArrayType::get(ArrayEltTy, NewInit.size());
184GlobalVariable *NewGV =
185newGlobalVariable(M, ATy,false,GlobalValue::AppendingLinkage,
186ConstantArray::get(ATy, NewInit),"", GV,
187 GV->getThreadLocalMode(), GV->getAddressSpace());
188 NewGV->setSection(GV->getSection());
189 NewGV->takeName(GV);
190 }
191
192 GV->eraseFromParent();
193}
194
195voidllvm::removeFromUsedLists(Module &M,
196function_ref<bool(Constant *)> ShouldRemove) {
197removeFromUsedList(M,"llvm.used", ShouldRemove);
198removeFromUsedList(M,"llvm.compiler.used", ShouldRemove);
199}
200
201voidllvm::setKCFIType(Module &M,Function &F,StringRef MangledType) {
202if (!M.getModuleFlag("kcfi"))
203return;
204// Matches CodeGenModule::CreateKCFITypeId in Clang.
205LLVMContext &Ctx = M.getContext();
206MDBuilder MDB(Ctx);
207 std::stringType = MangledType.str();
208if (M.getModuleFlag("cfi-normalize-integers"))
209Type +=".normalized";
210F.setMetadata(LLVMContext::MD_kcfi_type,
211MDNode::get(Ctx, MDB.createConstant(ConstantInt::get(
212Type::getInt32Ty(Ctx),
213static_cast<uint32_t>(xxHash64(Type))))));
214// If the module was compiled with -fpatchable-function-entry, ensure
215// we use the same patchable-function-prefix.
216if (auto *MD = mdconst::extract_or_null<ConstantInt>(
217 M.getModuleFlag("kcfi-offset"))) {
218if (unsignedOffset = MD->getZExtValue())
219F.addFnAttr("patchable-function-prefix", std::to_string(Offset));
220 }
221}
222
223FunctionCalleellvm::declareSanitizerInitFunction(Module &M,StringRef InitName,
224ArrayRef<Type *> InitArgTypes,
225bool Weak) {
226assert(!InitName.empty() &&"Expected init function name");
227auto *VoidTy =Type::getVoidTy(M.getContext());
228auto *FnTy = FunctionType::get(VoidTy, InitArgTypes,false);
229auto FnCallee = M.getOrInsertFunction(InitName, FnTy);
230auto *Fn = cast<Function>(FnCallee.getCallee());
231if (Weak && Fn->isDeclaration())
232 Fn->setLinkage(Function::ExternalWeakLinkage);
233return FnCallee;
234}
235
236Function *llvm::createSanitizerCtor(Module &M,StringRef CtorName) {
237Function *Ctor =Function::createWithDefaultAttr(
238 FunctionType::get(Type::getVoidTy(M.getContext()),false),
239GlobalValue::InternalLinkage, M.getDataLayout().getProgramAddressSpace(),
240 CtorName, &M);
241 Ctor->addFnAttr(Attribute::NoUnwind);
242setKCFIType(M, *Ctor,"_ZTSFvvE");// void (*)(void)
243BasicBlock *CtorBB =BasicBlock::Create(M.getContext(),"", Ctor);
244ReturnInst::Create(M.getContext(), CtorBB);
245// Ensure Ctor cannot be discarded, even if in a comdat.
246appendToUsed(M, {Ctor});
247return Ctor;
248}
249
250std::pair<Function *, FunctionCallee>llvm::createSanitizerCtorAndInitFunctions(
251Module &M,StringRef CtorName,StringRef InitName,
252ArrayRef<Type *> InitArgTypes,ArrayRef<Value *> InitArgs,
253StringRef VersionCheckName,bool Weak) {
254assert(!InitName.empty() &&"Expected init function name");
255assert(InitArgs.size() == InitArgTypes.size() &&
256"Sanitizer's init function expects different number of arguments");
257FunctionCallee InitFunction =
258declareSanitizerInitFunction(M, InitName, InitArgTypes, Weak);
259Function *Ctor =createSanitizerCtor(M, CtorName);
260IRBuilder<> IRB(M.getContext());
261
262BasicBlock *RetBB = &Ctor->getEntryBlock();
263if (Weak) {
264 RetBB->setName("ret");
265auto *EntryBB =BasicBlock::Create(M.getContext(),"entry", Ctor, RetBB);
266auto *CallInitBB =
267BasicBlock::Create(M.getContext(),"callfunc", Ctor, RetBB);
268auto *InitFn = cast<Function>(InitFunction.getCallee());
269auto *InitFnPtr =
270 PointerType::get(M.getContext(), InitFn->getAddressSpace());
271 IRB.SetInsertPoint(EntryBB);
272Value *InitNotNull =
273 IRB.CreateICmpNE(InitFn,ConstantPointerNull::get(InitFnPtr));
274 IRB.CreateCondBr(InitNotNull, CallInitBB, RetBB);
275 IRB.SetInsertPoint(CallInitBB);
276 }else {
277 IRB.SetInsertPoint(RetBB->getTerminator());
278 }
279
280 IRB.CreateCall(InitFunction, InitArgs);
281if (!VersionCheckName.empty()) {
282FunctionCallee VersionCheckFunction = M.getOrInsertFunction(
283 VersionCheckName, FunctionType::get(IRB.getVoidTy(), {},false),
284AttributeList());
285 IRB.CreateCall(VersionCheckFunction, {});
286 }
287
288if (Weak)
289 IRB.CreateBr(RetBB);
290
291return std::make_pair(Ctor, InitFunction);
292}
293
294std::pair<Function *, FunctionCallee>
295llvm::getOrCreateSanitizerCtorAndInitFunctions(
296Module &M,StringRef CtorName,StringRef InitName,
297ArrayRef<Type *> InitArgTypes,ArrayRef<Value *> InitArgs,
298function_ref<void(Function *,FunctionCallee)> FunctionsCreatedCallback,
299StringRef VersionCheckName,bool Weak) {
300assert(!CtorName.empty() &&"Expected ctor function name");
301
302if (Function *Ctor = M.getFunction(CtorName))
303// FIXME: Sink this logic into the module, similar to the handling of
304// globals. This will make moving to a concurrent model much easier.
305if (Ctor->arg_empty() ||
306 Ctor->getReturnType() ==Type::getVoidTy(M.getContext()))
307return {Ctor,
308declareSanitizerInitFunction(M, InitName, InitArgTypes, Weak)};
309
310Function *Ctor;
311FunctionCallee InitFunction;
312 std::tie(Ctor, InitFunction) =llvm::createSanitizerCtorAndInitFunctions(
313 M, CtorName, InitName, InitArgTypes, InitArgs, VersionCheckName, Weak);
314 FunctionsCreatedCallback(Ctor, InitFunction);
315return std::make_pair(Ctor, InitFunction);
316}
317
318voidllvm::filterDeadComdatFunctions(
319SmallVectorImpl<Function *> &DeadComdatFunctions) {
320SmallPtrSet<Function *, 32> MaybeDeadFunctions;
321SmallPtrSet<Comdat *, 32> MaybeDeadComdats;
322for (Function *F : DeadComdatFunctions) {
323 MaybeDeadFunctions.insert(F);
324if (Comdat *C =F->getComdat())
325 MaybeDeadComdats.insert(C);
326 }
327
328// Find comdats for which all users are dead now.
329SmallPtrSet<Comdat *, 32> DeadComdats;
330for (Comdat *C : MaybeDeadComdats) {
331auto IsUserDead = [&](GlobalObject *GO) {
332auto *F = dyn_cast<Function>(GO);
333returnF && MaybeDeadFunctions.contains(F);
334 };
335if (all_of(C->getUsers(), IsUserDead))
336 DeadComdats.insert(C);
337 }
338
339// Only keep functions which have no comdat or a dead comdat.
340erase_if(DeadComdatFunctions, [&](Function *F) {
341Comdat *C =F->getComdat();
342returnC && !DeadComdats.contains(C);
343 });
344}
345
346std::stringllvm::getUniqueModuleId(Module *M) {
347MD5 Md5;
348bool ExportsSymbols =false;
349auto AddGlobal = [&](GlobalValue &GV) {
350if (GV.isDeclaration() || GV.getName().starts_with("llvm.") ||
351 !GV.hasExternalLinkage() || GV.hasComdat())
352return;
353 ExportsSymbols =true;
354 Md5.update(GV.getName());
355 Md5.update(ArrayRef<uint8_t>{0});
356 };
357
358for (auto &F : *M)
359 AddGlobal(F);
360for (auto &GV : M->globals())
361 AddGlobal(GV);
362for (auto &GA : M->aliases())
363 AddGlobal(GA);
364for (auto &IF : M->ifuncs())
365 AddGlobal(IF);
366
367if (!ExportsSymbols)
368return"";
369
370MD5::MD5Result R;
371 Md5.final(R);
372
373SmallString<32> Str;
374MD5::stringifyResult(R, Str);
375return ("." + Str).str();
376}
377
378voidllvm::embedBufferInModule(Module &M,MemoryBufferRef Buf,
379StringRefSectionName,Align Alignment) {
380// Embed the memory buffer into the module.
381Constant *ModuleConstant =ConstantDataArray::get(
382 M.getContext(),ArrayRef(Buf.getBufferStart(), Buf.getBufferSize()));
383GlobalVariable *GV =newGlobalVariable(
384 M, ModuleConstant->getType(),true,GlobalValue::PrivateLinkage,
385 ModuleConstant,"llvm.embedded.object");
386 GV->setSection(SectionName);
387 GV->setAlignment(Alignment);
388
389LLVMContext &Ctx = M.getContext();
390NamedMDNode *MD = M.getOrInsertNamedMetadata("llvm.embedded.objects");
391Metadata *MDVals[] = {ConstantAsMetadata::get(GV),
392MDString::get(Ctx,SectionName)};
393
394 MD->addOperand(llvm::MDNode::get(Ctx, MDVals));
395 GV->setMetadata(LLVMContext::MD_exclude,llvm::MDNode::get(Ctx, {}));
396
397appendToCompilerUsed(M, GV);
398}
399
400boolllvm::lowerGlobalIFuncUsersAsGlobalCtor(
401Module &M,ArrayRef<GlobalIFunc *> FilteredIFuncsToLower) {
402SmallVector<GlobalIFunc *, 32> AllIFuncs;
403ArrayRef<GlobalIFunc *> IFuncsToLower = FilteredIFuncsToLower;
404if (FilteredIFuncsToLower.empty()) {// Default to lowering all ifuncs
405for (GlobalIFunc &GI : M.ifuncs())
406 AllIFuncs.push_back(&GI);
407 IFuncsToLower = AllIFuncs;
408 }
409
410bool UnhandledUsers =false;
411LLVMContext &Ctx = M.getContext();
412constDataLayout &DL = M.getDataLayout();
413
414PointerType *TableEntryTy =
415 PointerType::get(Ctx,DL.getProgramAddressSpace());
416
417ArrayType *FuncPtrTableTy =
418 ArrayType::get(TableEntryTy, IFuncsToLower.size());
419
420Align PtrAlign =DL.getABITypeAlign(TableEntryTy);
421
422// Create a global table of function pointers we'll initialize in a global
423// constructor.
424auto *FuncPtrTable =newGlobalVariable(
425 M, FuncPtrTableTy,false,GlobalValue::InternalLinkage,
426PoisonValue::get(FuncPtrTableTy),"",nullptr,
427 GlobalVariable::NotThreadLocal,DL.getDefaultGlobalsAddressSpace());
428 FuncPtrTable->setAlignment(PtrAlign);
429
430// Create a function to initialize the function pointer table.
431Function *NewCtor =Function::Create(
432 FunctionType::get(Type::getVoidTy(Ctx),false), Function::InternalLinkage,
433DL.getProgramAddressSpace(),"", &M);
434
435BasicBlock *BB =BasicBlock::Create(Ctx,"", NewCtor);
436IRBuilder<> InitBuilder(BB);
437
438size_t TableIndex = 0;
439for (GlobalIFunc *GI : IFuncsToLower) {
440Function *ResolvedFunction = GI->getResolverFunction();
441
442// We don't know what to pass to a resolver function taking arguments
443//
444// FIXME: Is this even valid? clang and gcc don't complain but this
445// probably should be invalid IR. We could just pass through undef.
446if (!std::empty(ResolvedFunction->getFunctionType()->params())) {
447LLVM_DEBUG(dbgs() <<"Not lowering ifunc resolver function "
448 << ResolvedFunction->getName() <<" with parameters\n");
449 UnhandledUsers =true;
450continue;
451 }
452
453// Initialize the function pointer table.
454CallInst *ResolvedFunc = InitBuilder.CreateCall(ResolvedFunction);
455Value *Casted = InitBuilder.CreatePointerCast(ResolvedFunc, TableEntryTy);
456Constant *GEP = cast<Constant>(InitBuilder.CreateConstInBoundsGEP2_32(
457 FuncPtrTableTy, FuncPtrTable, 0, TableIndex++));
458 InitBuilder.CreateAlignedStore(Casted,GEP, PtrAlign);
459
460// Update all users to load a pointer from the global table.
461for (User *User :make_early_inc_range(GI->users())) {
462Instruction *UserInst = dyn_cast<Instruction>(User);
463if (!UserInst) {
464// TODO: Should handle constantexpr casts in user instructions. Probably
465// can't do much about constant initializers.
466 UnhandledUsers =true;
467continue;
468 }
469
470IRBuilder<> UseBuilder(UserInst);
471LoadInst *ResolvedTarget =
472 UseBuilder.CreateAlignedLoad(TableEntryTy,GEP, PtrAlign);
473Value *ResolvedCast =
474 UseBuilder.CreatePointerCast(ResolvedTarget, GI->getType());
475 UserInst->replaceUsesOfWith(GI, ResolvedCast);
476 }
477
478// If we handled all users, erase the ifunc.
479if (GI->use_empty())
480 GI->eraseFromParent();
481 }
482
483 InitBuilder.CreateRetVoid();
484
485PointerType *ConstantDataTy = PointerType::get(Ctx, 0);
486
487// TODO: Is this the right priority? Probably should be before any other
488// constructors?
489constint Priority = 10;
490appendToGlobalCtors(M, NewCtor, Priority,
491ConstantPointerNull::get(ConstantDataTy));
492return UnhandledUsers;
493}
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition:ARMSLSHardening.cpp:73
LLVM_DEBUG
#define LLVM_DEBUG(...)
Definition:Debug.h:106
DerivedTypes.h
Name
std::string Name
Definition:ELFObjHandler.cpp:77
GEP
Hexagon Common GEP
Definition:HexagonCommonGEP.cpp:170
IRBuilder.h
Function.h
Module.h
Module.h This file contains the declarations for the Module class.
F
#define F(x, y, z)
Definition:MD5.cpp:55
MD5.h
MDBuilder.h
appendToUsedList
static void appendToUsedList(Module &M, StringRef Name, ArrayRef< GlobalValue * > Values)
Definition:ModuleUtils.cpp:135
collectUsedGlobals
static void collectUsedGlobals(GlobalVariable *GV, SmallSetVector< Constant *, 16 > &Init)
Definition:ModuleUtils.cpp:125
transformGlobalArray
static void transformGlobalArray(StringRef ArrayName, Module &M, const GlobalCtorTransformFn &Fn)
Definition:ModuleUtils.cpp:81
removeFromUsedList
static void removeFromUsedList(Module &M, StringRef Name, function_ref< bool(Constant *)> ShouldRemove)
Definition:ModuleUtils.cpp:165
appendToGlobalArray
static void appendToGlobalArray(StringRef ArrayName, Module &M, Function *F, int Priority, Constant *Data)
Definition:ModuleUtils.cpp:29
ModuleUtils.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
OP
#define OP(OPC)
Definition:Instruction.h:45
SmallString.h
This file defines the SmallString class.
VectorUtils.h
ArrayType
Definition:ItaniumDemangle.h:785
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition:ArrayRef.h:41
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition:ArrayRef.h:168
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition:ArrayRef.h:163
llvm::ArrayType
Class to represent array types.
Definition:DerivedTypes.h:395
llvm::AttributeList
Definition:Attributes.h:490
llvm::BasicBlock
LLVM Basic Block Representation.
Definition:BasicBlock.h:61
llvm::BasicBlock::Create
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition:BasicBlock.h:213
llvm::BasicBlock::getTerminator
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...
Definition:BasicBlock.h:240
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition:Instructions.h:1479
llvm::Comdat
Definition:Comdat.h:33
llvm::ConstantArray::get
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
Definition:Constants.cpp:1312
llvm::ConstantAsMetadata::get
static ConstantAsMetadata * get(Constant *C)
Definition:Metadata.h:532
llvm::ConstantDataArray::get
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
Definition:Constants.h:709
llvm::ConstantExpr::getPointerCast
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
Definition:Constants.cpp:2253
llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
Definition:Constants.cpp:2268
llvm::ConstantPointerNull::get
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
Definition:Constants.cpp:1826
llvm::ConstantStruct::get
static Constant * get(StructType *T, ArrayRef< Constant * > V)
Definition:Constants.cpp:1378
llvm::Constant
This is an important base class in LLVM.
Definition:Constant.h:42
llvm::Constant::getNullValue
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Definition:Constants.cpp:373
llvm::DWARFExpression::Operation
This class represents an Operation in the Expression.
Definition:DWARFExpression.h:32
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition:DataLayout.h:63
llvm::FunctionCallee
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Definition:DerivedTypes.h:170
llvm::FunctionCallee::getCallee
Value * getCallee()
Definition:DerivedTypes.h:189
llvm::FunctionType::params
ArrayRef< Type * > params() const
Definition:DerivedTypes.h:132
llvm::Function
Definition:Function.h:63
llvm::Function::addFnAttr
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
Definition:Function.cpp:641
llvm::Function::Create
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition:Function.h:173
llvm::Function::getEntryBlock
const BasicBlock & getEntryBlock() const
Definition:Function.h:809
llvm::Function::getFunctionType
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition:Function.h:216
llvm::Function::createWithDefaultAttr
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 and the LLVMContext applied.
Definition:Function.cpp:390
llvm::GlobalIFunc
Definition:GlobalIFunc.h:34
llvm::GlobalObject
Definition:GlobalObject.h:27
llvm::GlobalObject::getSection
StringRef getSection() const
Get the custom section of this global if it has one.
Definition:GlobalObject.h:117
llvm::GlobalObject::setMetadata
void setMetadata(unsigned KindID, MDNode *Node)
Set a particular kind of metadata attachment.
Definition:Metadata.cpp:1531
llvm::GlobalObject::setAlignment
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalObject.
Definition:Globals.cpp:143
llvm::GlobalObject::setSection
void setSection(StringRef S)
Change the section for this global.
Definition:Globals.cpp:273
llvm::GlobalValue
Definition:GlobalValue.h:48
llvm::GlobalValue::getThreadLocalMode
ThreadLocalMode getThreadLocalMode() const
Definition:GlobalValue.h:272
llvm::GlobalValue::getAddressSpace
unsigned getAddressSpace() const
Definition:GlobalValue.h:206
llvm::GlobalValue::PrivateLinkage
@ PrivateLinkage
Like Internal, but omit from symbol table.
Definition:GlobalValue.h:60
llvm::GlobalValue::InternalLinkage
@ InternalLinkage
Rename collisions when linking (static functions).
Definition:GlobalValue.h:59
llvm::GlobalValue::AppendingLinkage
@ AppendingLinkage
Special purpose, only applies to global arrays.
Definition:GlobalValue.h:58
llvm::GlobalValue::getValueType
Type * getValueType() const
Definition:GlobalValue.h:297
llvm::GlobalVariable
Definition:GlobalVariable.h:39
llvm::GlobalVariable::getInitializer
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
Definition:GlobalVariable.h:150
llvm::GlobalVariable::hasInitializer
bool hasInitializer() const
Definitions have initializers, declarations don't.
Definition:GlobalVariable.h:106
llvm::GlobalVariable::eraseFromParent
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
Definition:Globals.cpp:488
llvm::IRBuilderBase::CreateAlignedLoad
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, const char *Name)
Definition:IRBuilder.h:1815
llvm::IRBuilderBase::CreatePointerCast
Value * CreatePointerCast(Value *V, Type *DestTy, const Twine &Name="")
Definition:IRBuilder.h:2199
llvm::IRBuilderBase::getInt32Ty
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
Definition:IRBuilder.h:545
llvm::IRBuilderBase::CreateICmpNE
Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")
Definition:IRBuilder.h:2274
llvm::IRBuilderBase::getInt32
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Definition:IRBuilder.h:505
llvm::IRBuilderBase::CreateCondBr
BranchInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, MDNode *BranchWeights=nullptr, MDNode *Unpredictable=nullptr)
Create a conditional 'br Cond, TrueDest, FalseDest' instruction.
Definition:IRBuilder.h:1164
llvm::IRBuilderBase::CreateRetVoid
ReturnInst * CreateRetVoid()
Create a 'ret void' instruction.
Definition:IRBuilder.h:1134
llvm::IRBuilderBase::CreateConstInBoundsGEP2_32
Value * CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name="")
Definition:IRBuilder.h:1921
llvm::IRBuilderBase::CreateCall
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition:IRBuilder.h:2449
llvm::IRBuilderBase::getPtrTy
PointerType * getPtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer.
Definition:IRBuilder.h:588
llvm::IRBuilderBase::CreateBr
BranchInst * CreateBr(BasicBlock *Dest)
Create an unconditional 'br label X' instruction.
Definition:IRBuilder.h:1158
llvm::IRBuilderBase::SetInsertPoint
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
Definition:IRBuilder.h:199
llvm::IRBuilderBase::getVoidTy
Type * getVoidTy()
Fetch the type representing void.
Definition:IRBuilder.h:583
llvm::IRBuilderBase::CreateAlignedStore
StoreInst * CreateAlignedStore(Value *Val, Value *Ptr, MaybeAlign Align, bool isVolatile=false)
Definition:IRBuilder.h:1834
llvm::IRBuilder
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition:IRBuilder.h:2705
llvm::Init
Definition:Record.h:285
llvm::Instruction
Definition:Instruction.h:68
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition:LLVMContext.h:67
llvm::LoadInst
An instruction for reading from memory.
Definition:Instructions.h:176
llvm::MD5
Definition:MD5.h:41
llvm::MD5::update
void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
Definition:MD5.cpp:189
llvm::MD5::stringifyResult
static void stringifyResult(MD5Result &Result, SmallVectorImpl< char > &Str)
Translates the bytes in Res to a hex string that is deposited into Str.
Definition:MD5.cpp:287
llvm::MD5::final
void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
Definition:MD5.cpp:234
llvm::MDBuilder
Definition:MDBuilder.h:36
llvm::MDBuilder::createConstant
ConstantAsMetadata * createConstant(Constant *C)
Return the given constant as metadata.
Definition:MDBuilder.cpp:24
llvm::MDNode::get
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition:Metadata.h:1549
llvm::MDString::get
static MDString * get(LLVMContext &Context, StringRef Str)
Definition:Metadata.cpp:606
llvm::MemoryBufferRef
Definition:MemoryBufferRef.h:22
llvm::MemoryBufferRef::getBufferSize
size_t getBufferSize() const
Definition:MemoryBufferRef.h:37
llvm::MemoryBufferRef::getBufferStart
const char * getBufferStart() const
Definition:MemoryBufferRef.h:35
llvm::Metadata
Root of the metadata hierarchy.
Definition:Metadata.h:62
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition:Module.h:65
llvm::NamedMDNode
A tuple of MDNodes.
Definition:Metadata.h:1737
llvm::NamedMDNode::addOperand
void addOperand(MDNode *M)
Definition:Metadata.cpp:1431
llvm::PointerType
Class to represent pointers.
Definition:DerivedTypes.h:670
llvm::PointerType::getUnqual
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
Definition:DerivedTypes.h:686
llvm::PoisonValue::get
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition:Constants.cpp:1878
llvm::ReturnInst::Create
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, InsertPosition InsertBefore=nullptr)
Definition:Instructions.h:2965
llvm::SmallPtrSetImpl::insert
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition:SmallPtrSet.h:384
llvm::SmallPtrSetImpl::contains
bool contains(ConstPtrType Ptr) const
Definition:SmallPtrSet.h:458
llvm::SmallPtrSet
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition:SmallPtrSet.h:519
llvm::SmallSetVector
A SetVector that performs no allocations if smaller than a certain size.
Definition:SetVector.h:370
llvm::SmallString
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition:SmallString.h:26
llvm::SmallVectorBase::empty
bool empty() const
Definition:SmallVector.h:81
llvm::SmallVectorBase::size
size_t size() const
Definition:SmallVector.h:78
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition:SmallVector.h:573
llvm::SmallVectorImpl::reserve
void reserve(size_type N)
Definition:SmallVector.h:663
llvm::SmallVectorTemplateBase::push_back
void push_back(const T &Elt)
Definition:SmallVector.h:413
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition:SmallVector.h:1196
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:StringRef.h:51
llvm::StringRef::str
std::string str() const
str - Get the contents as an std::string.
Definition:StringRef.h:229
llvm::StringRef::empty
constexpr bool empty() const
empty - Check if the string is empty.
Definition:StringRef.h:147
llvm::StructType
Class to represent struct types.
Definition:DerivedTypes.h:218
llvm::StructType::get
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Definition:Type.cpp:406
llvm::StructType::getNumElements
unsigned getNumElements() const
Random access to the elements.
Definition:DerivedTypes.h:365
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition:Type.h:45
llvm::Type::getArrayElementType
Type * getArrayElementType() const
Definition:Type.h:411
llvm::Type::getVoidTy
static Type * getVoidTy(LLVMContext &C)
llvm::Type::getInt32Ty
static IntegerType * getInt32Ty(LLVMContext &C)
llvm::Use
A Use represents the edge between a Value definition and its users.
Definition:Use.h:43
llvm::User
Definition:User.h:44
llvm::User::replaceUsesOfWith
bool replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
Definition:User.cpp:21
llvm::Value
LLVM Value Representation.
Definition:Value.h:74
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition:Value.h:255
llvm::Value::setName
void setName(const Twine &Name)
Change the name of the value.
Definition:Value.cpp:377
llvm::Value::getName
StringRef getName() const
Return a constant reference to the value's name.
Definition:Value.cpp:309
llvm::Value::takeName
void takeName(Value *V)
Transfer the name from V to this value.
Definition:Value.cpp:383
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition:STLFunctionalExtras.h:37
uint32_t
llvm::CallingConv::C
@ C
The default llvm calling convention, compatible with C.
Definition:CallingConv.h:34
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::Offset
@ Offset
Definition:DWP.cpp:480
llvm::all_of
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition:STLExtras.h:1739
llvm::createSanitizerCtor
Function * createSanitizerCtor(Module &M, StringRef CtorName)
Creates sanitizer constructor function.
Definition:ModuleUtils.cpp:236
llvm::make_early_inc_range
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition:STLExtras.h:657
llvm::declareSanitizerInitFunction
FunctionCallee declareSanitizerInitFunction(Module &M, StringRef InitName, ArrayRef< Type * > InitArgTypes, bool Weak=false)
Definition:ModuleUtils.cpp:223
llvm::transformGlobalDtors
void transformGlobalDtors(Module &M, const GlobalCtorTransformFn &Fn)
Definition:ModuleUtils.cpp:121
llvm::getUniqueModuleId
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...
Definition:ModuleUtils.cpp:346
llvm::getOrCreateSanitizerCtorAndInitFunctions
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(), bool Weak=false)
Creates sanitizer constructor function lazily.
Definition:ModuleUtils.cpp:295
llvm::createSanitizerCtorAndInitFunctions
std::pair< Function *, FunctionCallee > createSanitizerCtorAndInitFunctions(Module &M, StringRef CtorName, StringRef InitName, ArrayRef< Type * > InitArgTypes, ArrayRef< Value * > InitArgs, StringRef VersionCheckName=StringRef(), bool Weak=false)
Creates sanitizer constructor function, and calls sanitizer's init function from it.
Definition:ModuleUtils.cpp:250
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition:Debug.cpp:163
llvm::removeFromUsedLists
void removeFromUsedLists(Module &M, function_ref< bool(Constant *)> ShouldRemove)
Removes global values from the llvm.used and llvm.compiler.used arrays.
Definition:ModuleUtils.cpp:195
llvm::appendToCompilerUsed
void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
Definition:ModuleUtils.cpp:161
llvm::appendToGlobalCtors
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.
Definition:ModuleUtils.cpp:73
llvm::setKCFIType
void setKCFIType(Module &M, Function &F, StringRef MangledType)
Sets the KCFI type for the function.
Definition:ModuleUtils.cpp:201
llvm::transformGlobalCtors
void transformGlobalCtors(Module &M, const GlobalCtorTransformFn &Fn)
Definition:ModuleUtils.cpp:117
llvm::erase_if
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
Definition:STLExtras.h:2099
llvm::filterDeadComdatFunctions
void filterDeadComdatFunctions(SmallVectorImpl< Function * > &DeadComdatFunctions)
Filter out potentially dead comdat functions where other entries keep the entire comdat group alive.
Definition:ModuleUtils.cpp:318
llvm::embedBufferInModule
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.
Definition:ModuleUtils.cpp:378
llvm::lowerGlobalIFuncUsersAsGlobalCtor
bool lowerGlobalIFuncUsersAsGlobalCtor(Module &M, ArrayRef< GlobalIFunc * > IFuncsToLower={})
Lower all calls to ifuncs by replacing uses with indirect calls loaded out of a global table initiali...
Definition:ModuleUtils.cpp:400
llvm::appendToUsed
void appendToUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.used list.
Definition:ModuleUtils.cpp:157
llvm::appendToGlobalDtors
void appendToGlobalDtors(Module &M, Function *F, int Priority, Constant *Data=nullptr)
Same as appendToGlobalCtors(), but for global dtors.
Definition:ModuleUtils.cpp:77
llvm::xxHash64
uint64_t xxHash64(llvm::StringRef Data)
Definition:xxhash.cpp:103
raw_ostream.h
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition:Alignment.h:39
llvm::MD5::MD5Result
Definition:MD5.h:43
llvm::SectionName
Definition:DWARFSection.h:21
xxhash.h

Generated on Fri Jul 18 2025 16:39:10 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp