| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#ifndef LLVM_IR_MODULE_H |
| 15 |
#define LLVM_IR_MODULE_H |
| 16 |
|
| 17 |
#include "llvm-c/Types.h" |
| 18 |
#include "llvm/ADT/Optional.h" |
| 19 |
#include "llvm/ADT/STLExtras.h" |
| 20 |
#include "llvm/ADT/StringMap.h" |
| 21 |
#include "llvm/ADT/StringRef.h" |
| 22 |
#include "llvm/ADT/iterator_range.h" |
| 23 |
#include "llvm/IR/Attributes.h" |
| 24 |
#include "llvm/IR/Comdat.h" |
| 25 |
#include "llvm/IR/DataLayout.h" |
| 26 |
#include "llvm/IR/Function.h" |
| 27 |
#include "llvm/IR/GlobalAlias.h" |
| 28 |
#include "llvm/IR/GlobalIFunc.h" |
| 29 |
#include "llvm/IR/GlobalVariable.h" |
| 30 |
#include "llvm/IR/Metadata.h" |
| 31 |
#include "llvm/IR/ProfileSummary.h" |
| 32 |
#include "llvm/IR/SymbolTableListTraits.h" |
| 33 |
#include "llvm/Support/CBindingWrapping.h" |
| 34 |
#include "llvm/Support/CodeGen.h" |
| 35 |
#include <cstddef> |
| 36 |
#include <cstdint> |
| 37 |
#include <iterator> |
| 38 |
#include <memory> |
| 39 |
#include <string> |
| 40 |
#include <vector> |
| 41 |
|
| 42 |
namespace llvm { |
| 43 |
|
| 44 |
class Error; |
| 45 |
class FunctionType; |
| 46 |
class GVMaterializer; |
| 47 |
class LLVMContext; |
| 48 |
class MemoryBuffer; |
| 49 |
class ModuleSummaryIndex; |
| 50 |
class RandomNumberGenerator; |
| 51 |
class StructType; |
| 52 |
class VersionTuple; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
class LLVM_EXTERNAL_VISIBILITY Module { |
| 66 |
|
| 67 |
|
| 68 |
public: |
| 69 |
|
| 70 |
using GlobalListType = SymbolTableList<GlobalVariable>; |
| 71 |
|
| 72 |
using FunctionListType = SymbolTableList<Function>; |
| 73 |
|
| 74 |
using AliasListType = SymbolTableList<GlobalAlias>; |
| 75 |
|
| 76 |
using IFuncListType = SymbolTableList<GlobalIFunc>; |
| 77 |
|
| 78 |
using NamedMDListType = ilist<NamedMDNode>; |
| 79 |
|
| 80 |
using ComdatSymTabType = StringMap<Comdat>; |
| 81 |
|
| 82 |
using NamedMDSymTabType = StringMap<NamedMDNode *>; |
| 83 |
|
| 84 |
|
| 85 |
using global_iterator = GlobalListType::iterator; |
| 86 |
|
| 87 |
using const_global_iterator = GlobalListType::const_iterator; |
| 88 |
|
| 89 |
|
| 90 |
using iterator = FunctionListType::iterator; |
| 91 |
|
| 92 |
using const_iterator = FunctionListType::const_iterator; |
| 93 |
|
| 94 |
|
| 95 |
using reverse_iterator = FunctionListType::reverse_iterator; |
| 96 |
|
| 97 |
using const_reverse_iterator = FunctionListType::const_reverse_iterator; |
| 98 |
|
| 99 |
|
| 100 |
using alias_iterator = AliasListType::iterator; |
| 101 |
|
| 102 |
using const_alias_iterator = AliasListType::const_iterator; |
| 103 |
|
| 104 |
|
| 105 |
using ifunc_iterator = IFuncListType::iterator; |
| 106 |
|
| 107 |
using const_ifunc_iterator = IFuncListType::const_iterator; |
| 108 |
|
| 109 |
|
| 110 |
using named_metadata_iterator = NamedMDListType::iterator; |
| 111 |
|
| 112 |
using const_named_metadata_iterator = NamedMDListType::const_iterator; |
| 113 |
|
| 114 |
|
| 115 |
enum ModFlagBehavior { |
| 116 |
|
| 117 |
|
| 118 |
Error = 1, |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
Warning = 2, |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
Require = 3, |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
Override = 4, |
| 137 |
|
| 138 |
|
| 139 |
Append = 5, |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
AppendUnique = 6, |
| 145 |
|
| 146 |
|
| 147 |
Max = 7, |
| 148 |
|
| 149 |
|
| 150 |
ModFlagBehaviorFirstVal = Error, |
| 151 |
ModFlagBehaviorLastVal = Max |
| 152 |
}; |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
static bool isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB); |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
static bool isValidModuleFlag(const MDNode &ModFlag, ModFlagBehavior &MFB, |
| 161 |
MDString *&Key, Metadata *&Val); |
| 162 |
|
| 163 |
struct ModuleFlagEntry { |
| 164 |
ModFlagBehavior Behavior; |
| 165 |
MDString *Key; |
| 166 |
Metadata *Val; |
| 167 |
|
| 168 |
ModuleFlagEntry(ModFlagBehavior B, MDString *K, Metadata *V) |
| 169 |
: Behavior(B), Key(K), Val(V) {} |
| 170 |
}; |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
private: |
| 176 |
LLVMContext &Context; |
| 177 |
|
| 178 |
GlobalListType GlobalList; |
| 179 |
FunctionListType FunctionList; |
| 180 |
AliasListType AliasList; |
| 181 |
IFuncListType IFuncList; |
| 182 |
NamedMDListType NamedMDList; |
| 183 |
std::string GlobalScopeAsm; |
| 184 |
std::unique_ptr<ValueSymbolTable> ValSymTab; |
| 185 |
ComdatSymTabType ComdatSymTab; |
| 186 |
std::unique_ptr<MemoryBuffer> |
| 187 |
OwnedMemoryBuffer; |
| 188 |
|
| 189 |
std::unique_ptr<GVMaterializer> |
| 190 |
Materializer; |
| 191 |
std::string ModuleID; |
| 192 |
std::string SourceFileName; |
| 193 |
|
| 194 |
std::string TargetTriple; |
| 195 |
|
| 196 |
NamedMDSymTabType NamedMDSymTab; |
| 197 |
DataLayout DL; |
| 198 |
StringMap<unsigned> |
| 199 |
CurrentIntrinsicIds; |
| 200 |
|
| 201 |
DenseMap<std::pair<Intrinsic::ID, const FunctionType *>, unsigned> |
| 202 |
UniquedIntrinsicNames; |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
friend class Constant; |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
public: |
| 213 |
|
| 214 |
|
| 215 |
explicit Module(StringRef ModuleID, LLVMContext& C); |
| 216 |
|
| 217 |
~Module(); |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
const std::string &getModuleIdentifier() const { return ModuleID; } |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
unsigned getInstructionCount() const; |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
const std::string &getSourceFileName() const { return SourceFileName; } |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
StringRef getName() const { return ModuleID; } |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
const std::string &getDataLayoutStr() const { |
| 247 |
return DL.getStringRepresentation(); |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
const DataLayout &getDataLayout() const; |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
const std::string &getTargetTriple() const { return TargetTriple; } |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
LLVMContext &getContext() const { return Context; } |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
const std::string &getModuleInlineAsm() const { return GlobalScopeAsm; } |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
std::unique_ptr<RandomNumberGenerator> createRNG(const StringRef Name) const; |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
bool shouldEmitInstrCountChangedRemark() { |
| 279 |
return getContext().getDiagHandlerPtr()->isAnalysisRemarkEnabled( |
| 280 |
"size-info"); |
| 281 |
} |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
void setModuleIdentifier(StringRef ID) { ModuleID = std::string(ID); } |
| 289 |
|
| 290 |
|
| 291 |
void setSourceFileName(StringRef Name) { SourceFileName = std::string(Name); } |
| 292 |
|
| 293 |
|
| 294 |
void setDataLayout(StringRef Desc); |
| 295 |
void setDataLayout(const DataLayout &Other); |
| 296 |
|
| 297 |
|
| 298 |
void setTargetTriple(StringRef T) { TargetTriple = std::string(T); } |
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
void setModuleInlineAsm(StringRef Asm) { |
| 303 |
GlobalScopeAsm = std::string(Asm); |
| 304 |
if (!GlobalScopeAsm.empty() && GlobalScopeAsm.back() != '\n') |
| 305 |
GlobalScopeAsm += '\n'; |
| 306 |
} |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
void appendModuleInlineAsm(StringRef Asm) { |
| 311 |
GlobalScopeAsm += Asm; |
| 312 |
if (!GlobalScopeAsm.empty() && GlobalScopeAsm.back() != '\n') |
| 313 |
GlobalScopeAsm += '\n'; |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
GlobalValue *getNamedValue(StringRef Name) const; |
| 324 |
|
| 325 |
|
| 326 |
unsigned getNumNamedValues() const; |
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
unsigned getMDKindID(StringRef Name) const; |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
void getMDKindNames(SmallVectorImpl<StringRef> &Result) const; |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
void getOperandBundleTags(SmallVectorImpl<StringRef> &Result) const; |
| 340 |
|
| 341 |
std::vector<StructType *> getIdentifiedStructTypes() const; |
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
std::string getUniqueIntrinsicName(StringRef BaseName, Intrinsic::ID Id, |
| 346 |
const FunctionType *Proto); |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T, |
| 364 |
AttributeList AttributeList); |
| 365 |
|
| 366 |
FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T); |
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
template <typename... ArgsTy> |
| 375 |
FunctionCallee getOrInsertFunction(StringRef Name, |
| 376 |
AttributeList AttributeList, Type *RetTy, |
| 377 |
ArgsTy... Args) { |
| 378 |
SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...}; |
| 379 |
return getOrInsertFunction(Name, |
| 380 |
FunctionType::get(RetTy, ArgTys, false), |
| 381 |
AttributeList); |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
template <typename... ArgsTy> |
| 386 |
FunctionCallee getOrInsertFunction(StringRef Name, Type *RetTy, |
| 387 |
ArgsTy... Args) { |
| 388 |
return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...); |
| 389 |
} |
| 390 |
|
| 391 |
|
| 392 |
template <typename... ArgsTy> |
| 393 |
FunctionCallee |
| 394 |
getOrInsertFunction(StringRef Name, AttributeList AttributeList, |
| 395 |
FunctionType *Invalid, ArgsTy... Args) = delete; |
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
Function *getFunction(StringRef Name) const; |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
GlobalVariable *getGlobalVariable(StringRef Name) const { |
| 410 |
return getGlobalVariable(Name, false); |
| 411 |
} |
| 412 |
|
| 413 |
GlobalVariable *getGlobalVariable(StringRef Name, bool AllowInternal) const; |
| 414 |
|
| 415 |
GlobalVariable *getGlobalVariable(StringRef Name, |
| 416 |
bool AllowInternal = false) { |
| 417 |
return static_cast<const Module *>(this)->getGlobalVariable(Name, |
| 418 |
AllowInternal); |
| 419 |
} |
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
const GlobalVariable *getNamedGlobal(StringRef Name) const { |
| 425 |
return getGlobalVariable(Name, true); |
| 426 |
} |
| 427 |
GlobalVariable *getNamedGlobal(StringRef Name) { |
| 428 |
return const_cast<GlobalVariable *>( |
| 429 |
static_cast<const Module *>(this)->getNamedGlobal(Name)); |
| 430 |
} |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
Constant * |
| 437 |
getOrInsertGlobal(StringRef Name, Type *Ty, |
| 438 |
function_ref<GlobalVariable *()> CreateGlobalCallback); |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
Constant *getOrInsertGlobal(StringRef Name, Type *Ty); |
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
GlobalAlias *getNamedAlias(StringRef Name) const; |
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
GlobalIFunc *getNamedIFunc(StringRef Name) const; |
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
NamedMDNode *getNamedMetadata(const Twine &Name) const; |
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
NamedMDNode *getOrInsertNamedMetadata(StringRef Name); |
| 474 |
|
| 475 |
|
| 476 |
void eraseNamedMetadata(NamedMDNode *NMD); |
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
Comdat *getOrInsertComdat(StringRef Name); |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
void getModuleFlagsMetadata(SmallVectorImpl<ModuleFlagEntry> &Flags) const; |
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
Metadata *getModuleFlag(StringRef Key) const; |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
NamedMDNode *getModuleFlagsMetadata() const; |
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
NamedMDNode *getOrInsertModuleFlagsMetadata(); |
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val); |
| 509 |
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Constant *Val); |
| 510 |
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, uint32_t Val); |
| 511 |
void addModuleFlag(MDNode *Node); |
| 512 |
|
| 513 |
void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val); |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
void setMaterializer(GVMaterializer *GVM); |
| 527 |
|
| 528 |
GVMaterializer *getMaterializer() const { return Materializer.get(); } |
| 529 |
bool isMaterialized() const { return !getMaterializer(); } |
| 530 |
|
| 531 |
|
| 532 |
llvm::Error materialize(GlobalValue *GV); |
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
llvm::Error materializeAll(); |
| 537 |
|
| 538 |
llvm::Error materializeMetadata(); |
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
const GlobalListType &getGlobalList() const { return GlobalList; } |
| 546 |
|
| 547 |
GlobalListType &getGlobalList() { return GlobalList; } |
| 548 |
|
| 549 |
static GlobalListType Module::*getSublistAccess(GlobalVariable*) { |
| 550 |
return &Module::GlobalList; |
| 551 |
} |
| 552 |
|
| 553 |
|
| 554 |
const FunctionListType &getFunctionList() const { return FunctionList; } |
| 555 |
|
| 556 |
FunctionListType &getFunctionList() { return FunctionList; } |
| 557 |
static FunctionListType Module::*getSublistAccess(Function*) { |
| 558 |
return &Module::FunctionList; |
| 559 |
} |
| 560 |
|
| 561 |
|
| 562 |
const AliasListType &getAliasList() const { return AliasList; } |
| 563 |
|
| 564 |
AliasListType &getAliasList() { return AliasList; } |
| 565 |
|
| 566 |
static AliasListType Module::*getSublistAccess(GlobalAlias*) { |
| 567 |
return &Module::AliasList; |
| 568 |
} |
| 569 |
|
| 570 |
|
| 571 |
const IFuncListType &getIFuncList() const { return IFuncList; } |
| 572 |
|
| 573 |
IFuncListType &getIFuncList() { return IFuncList; } |
| 574 |
|
| 575 |
static IFuncListType Module::*getSublistAccess(GlobalIFunc*) { |
| 576 |
return &Module::IFuncList; |
| 577 |
} |
| 578 |
|
| 579 |
|
| 580 |
const NamedMDListType &getNamedMDList() const { return NamedMDList; } |
| 581 |
|
| 582 |
NamedMDListType &getNamedMDList() { return NamedMDList; } |
| 583 |
|
| 584 |
static NamedMDListType Module::*getSublistAccess(NamedMDNode*) { |
| 585 |
return &Module::NamedMDList; |
| 586 |
} |
| 587 |
|
| 588 |
|
| 589 |
const ValueSymbolTable &getValueSymbolTable() const { return *ValSymTab; } |
| 590 |
|
| 591 |
ValueSymbolTable &getValueSymbolTable() { return *ValSymTab; } |
| 592 |
|
| 593 |
|
| 594 |
const ComdatSymTabType &getComdatSymbolTable() const { return ComdatSymTab; } |
| 595 |
|
| 596 |
ComdatSymTabType &getComdatSymbolTable() { return ComdatSymTab; } |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
global_iterator global_begin() { return GlobalList.begin(); } |
| 603 |
const_global_iterator global_begin() const { return GlobalList.begin(); } |
| 604 |
global_iterator global_end () { return GlobalList.end(); } |
| 605 |
const_global_iterator global_end () const { return GlobalList.end(); } |
| 606 |
size_t global_size () const { return GlobalList.size(); } |
| 607 |
bool global_empty() const { return GlobalList.empty(); } |
| 608 |
|
| 609 |
iterator_range<global_iterator> globals() { |
| 610 |
return make_range(global_begin(), global_end()); |
| 611 |
} |
| 612 |
iterator_range<const_global_iterator> globals() const { |
| 613 |
return make_range(global_begin(), global_end()); |
| 614 |
} |
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
iterator begin() { return FunctionList.begin(); } |
| 621 |
const_iterator begin() const { return FunctionList.begin(); } |
| 622 |
iterator end () { return FunctionList.end(); } |
| 623 |
const_iterator end () const { return FunctionList.end(); } |
| 624 |
reverse_iterator rbegin() { return FunctionList.rbegin(); } |
| 625 |
const_reverse_iterator rbegin() const{ return FunctionList.rbegin(); } |
| 626 |
reverse_iterator rend() { return FunctionList.rend(); } |
| 627 |
const_reverse_iterator rend() const { return FunctionList.rend(); } |
| 628 |
size_t size() const { return FunctionList.size(); } |
| 629 |
bool empty() const { return FunctionList.empty(); } |
| 630 |
|
| 631 |
iterator_range<iterator> functions() { |
| 632 |
return make_range(begin(), end()); |
| 633 |
} |
| 634 |
iterator_range<const_iterator> functions() const { |
| 635 |
return make_range(begin(), end()); |
| 636 |
} |
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
alias_iterator alias_begin() { return AliasList.begin(); } |
| 643 |
const_alias_iterator alias_begin() const { return AliasList.begin(); } |
| 644 |
alias_iterator alias_end () { return AliasList.end(); } |
| 645 |
const_alias_iterator alias_end () const { return AliasList.end(); } |
| 646 |
size_t alias_size () const { return AliasList.size(); } |
| 647 |
bool alias_empty() const { return AliasList.empty(); } |
| 648 |
|
| 649 |
iterator_range<alias_iterator> aliases() { |
| 650 |
return make_range(alias_begin(), alias_end()); |
| 651 |
} |
| 652 |
iterator_range<const_alias_iterator> aliases() const { |
| 653 |
return make_range(alias_begin(), alias_end()); |
| 654 |
} |
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
ifunc_iterator ifunc_begin() { return IFuncList.begin(); } |
| 661 |
const_ifunc_iterator ifunc_begin() const { return IFuncList.begin(); } |
| 662 |
ifunc_iterator ifunc_end () { return IFuncList.end(); } |
| 663 |
const_ifunc_iterator ifunc_end () const { return IFuncList.end(); } |
| 664 |
size_t ifunc_size () const { return IFuncList.size(); } |
| 665 |
bool ifunc_empty() const { return IFuncList.empty(); } |
| 666 |
|
| 667 |
iterator_range<ifunc_iterator> ifuncs() { |
| 668 |
return make_range(ifunc_begin(), ifunc_end()); |
| 669 |
} |
| 670 |
iterator_range<const_ifunc_iterator> ifuncs() const { |
| 671 |
return make_range(ifunc_begin(), ifunc_end()); |
| 672 |
} |
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
using global_object_iterator = |
| 679 |
concat_iterator<GlobalObject, iterator, global_iterator>; |
| 680 |
using const_global_object_iterator = |
| 681 |
concat_iterator<const GlobalObject, const_iterator, |
| 682 |
const_global_iterator>; |
| 683 |
|
| 684 |
iterator_range<global_object_iterator> global_objects(); |
| 685 |
iterator_range<const_global_object_iterator> global_objects() const; |
| 686 |
|
| 687 |
using global_value_iterator = |
| 688 |
concat_iterator<GlobalValue, iterator, global_iterator, alias_iterator, |
| 689 |
ifunc_iterator>; |
| 690 |
using const_global_value_iterator = |
| 691 |
concat_iterator<const GlobalValue, const_iterator, const_global_iterator, |
| 692 |
const_alias_iterator, const_ifunc_iterator>; |
| 693 |
|
| 694 |
iterator_range<global_value_iterator> global_values(); |
| 695 |
iterator_range<const_global_value_iterator> global_values() const; |
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
named_metadata_iterator named_metadata_begin() { return NamedMDList.begin(); } |
| 702 |
const_named_metadata_iterator named_metadata_begin() const { |
| 703 |
return NamedMDList.begin(); |
| 704 |
} |
| 705 |
|
| 706 |
named_metadata_iterator named_metadata_end() { return NamedMDList.end(); } |
| 707 |
const_named_metadata_iterator named_metadata_end() const { |
| 708 |
return NamedMDList.end(); |
| 709 |
} |
| 710 |
|
| 711 |
size_t named_metadata_size() const { return NamedMDList.size(); } |
| 712 |
bool named_metadata_empty() const { return NamedMDList.empty(); } |
| 713 |
|
| 714 |
iterator_range<named_metadata_iterator> named_metadata() { |
| 715 |
return make_range(named_metadata_begin(), named_metadata_end()); |
| 716 |
} |
| 717 |
iterator_range<const_named_metadata_iterator> named_metadata() const { |
| 718 |
return make_range(named_metadata_begin(), named_metadata_end()); |
| 719 |
} |
| 720 |
|
| 721 |
|
| 722 |
class debug_compile_units_iterator { |
| 723 |
NamedMDNode *CUs; |
| 724 |
unsigned Idx; |
| 725 |
|
| 726 |
void SkipNoDebugCUs(); |
| 727 |
|
| 728 |
public: |
| 729 |
using iterator_category = std::input_iterator_tag; |
| 730 |
using value_type = DICompileUnit *; |
| 731 |
using difference_type = std::ptrdiff_t; |
| 732 |
using pointer = value_type *; |
| 733 |
using reference = value_type &; |
| 734 |
|
| 735 |
explicit debug_compile_units_iterator(NamedMDNode *CUs, unsigned Idx) |
| 736 |
: CUs(CUs), Idx(Idx) { |
| 737 |
SkipNoDebugCUs(); |
| 738 |
} |
| 739 |
|
| 740 |
debug_compile_units_iterator &operator++() { |
| 741 |
++Idx; |
| 742 |
SkipNoDebugCUs(); |
| 743 |
return *this; |
| 744 |
} |
| 745 |
|
| 746 |
debug_compile_units_iterator operator++(int) { |
| 747 |
debug_compile_units_iterator T(*this); |
| 748 |
++Idx; |
| 749 |
return T; |
| 750 |
} |
| 751 |
|
| 752 |
bool operator==(const debug_compile_units_iterator &I) const { |
| 753 |
return Idx == I.Idx; |
| 754 |
} |
| 755 |
|
| 756 |
bool operator!=(const debug_compile_units_iterator &I) const { |
| 757 |
return Idx != I.Idx; |
| 758 |
} |
| 759 |
|
| 760 |
DICompileUnit *operator*() const; |
| 761 |
DICompileUnit *operator->() const; |
| 762 |
}; |
| 763 |
|
| 764 |
debug_compile_units_iterator debug_compile_units_begin() const { |
| 765 |
auto *CUs = getNamedMetadata("llvm.dbg.cu"); |
| 766 |
return debug_compile_units_iterator(CUs, 0); |
| 767 |
} |
| 768 |
|
| 769 |
debug_compile_units_iterator debug_compile_units_end() const { |
| 770 |
auto *CUs = getNamedMetadata("llvm.dbg.cu"); |
| 771 |
return debug_compile_units_iterator(CUs, CUs ? CUs->getNumOperands() : 0); |
| 772 |
} |
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
iterator_range<debug_compile_units_iterator> debug_compile_units() const { |
| 778 |
auto *CUs = getNamedMetadata("llvm.dbg.cu"); |
| 779 |
return make_range( |
| 780 |
debug_compile_units_iterator(CUs, 0), |
| 781 |
debug_compile_units_iterator(CUs, CUs ? CUs->getNumOperands() : 0)); |
| 782 |
} |
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
void dropTriviallyDeadConstantArrays(); |
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW, |
| 802 |
bool ShouldPreserveUseListOrder = false, |
| 803 |
bool IsForDebug = false) const; |
| 804 |
|
| 805 |
|
| 806 |
void dump() const; |
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
void dropAllReferences(); |
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
unsigned getNumberRegisterParameters() const; |
| 823 |
|
| 824 |
|
| 825 |
unsigned getDwarfVersion() const; |
| 826 |
|
| 827 |
|
| 828 |
bool isDwarf64() const; |
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
unsigned getCodeViewFlag() const; |
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
PICLevel::Level getPICLevel() const; |
| 840 |
|
| 841 |
|
| 842 |
void setPICLevel(PICLevel::Level PL); |
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
PIELevel::Level getPIELevel() const; |
| 851 |
|
| 852 |
|
| 853 |
void setPIELevel(PIELevel::Level PL); |
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
Optional<CodeModel::Model> getCodeModel() const; |
| 862 |
|
| 863 |
|
| 864 |
void setCodeModel(CodeModel::Model CL); |
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
void setProfileSummary(Metadata *M, ProfileSummary::Kind Kind); |
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
Metadata *getProfileSummary(bool IsCS) const; |
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
bool getSemanticInterposition() const; |
| 880 |
|
| 881 |
|
| 882 |
void setSemanticInterposition(bool); |
| 883 |
|
| 884 |
|
| 885 |
bool getRtLibUseGOT() const; |
| 886 |
|
| 887 |
|
| 888 |
void setRtLibUseGOT(); |
| 889 |
|
| 890 |
|
| 891 |
bool getUwtable() const; |
| 892 |
void setUwtable(); |
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
FramePointerKind getFramePointer() const; |
| 897 |
void setFramePointer(FramePointerKind Kind); |
| 898 |
|
| 899 |
|
| 900 |
StringRef getStackProtectorGuard() const; |
| 901 |
void setStackProtectorGuard(StringRef Kind); |
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
StringRef getStackProtectorGuardReg() const; |
| 907 |
void setStackProtectorGuardReg(StringRef Reg); |
| 908 |
|
| 909 |
|
| 910 |
int getStackProtectorGuardOffset() const; |
| 911 |
void setStackProtectorGuardOffset(int Offset); |
| 912 |
|
| 913 |
|
| 914 |
unsigned getOverrideStackAlignment() const; |
| 915 |
void setOverrideStackAlignment(unsigned Align); |
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
void setSDKVersion(const VersionTuple &V); |
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
VersionTuple getSDKVersion() const; |
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
void setOwnedMemoryBuffer(std::unique_ptr<MemoryBuffer> MB); |
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
void setPartialSampleProfileRatio(const ModuleSummaryIndex &Index); |
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
StringRef getDarwinTargetVariantTriple() const; |
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
VersionTuple getDarwinTargetVariantSDKVersion() const; |
| 946 |
}; |
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
GlobalVariable *collectUsedGlobalVariables(const Module &M, |
| 952 |
SmallVectorImpl<GlobalValue *> &Vec, |
| 953 |
bool CompilerUsed); |
| 954 |
|
| 955 |
|
| 956 |
inline raw_ostream &operator<<(raw_ostream &O, const Module &M) { |
| 957 |
M.print(O, nullptr); |
| 958 |
return O; |
| 959 |
} |
| 960 |
|
| 961 |
|
| 962 |
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef) |
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
inline Module *unwrap(LLVMModuleProviderRef MP) { |
| 968 |
return reinterpret_cast<Module*>(MP); |
| 969 |
} |
| 970 |
|
| 971 |
} |
| 972 |
|
| 973 |
#endif |