LLVM: include/llvm/IR/Module.h Source File (original) (raw)

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

34#include

35#include

36#include

37#include

38#include

39#include

40#include

41

42namespace llvm {

43

46class GVMaterializer;

47class LLVMContext;

48class MemoryBuffer;

49class ModuleSummaryIndex;

50class RandomNumberGenerator;

51class StructType;

52class VersionTuple;

53

54

55

56

57

58

59

60

61

62

63

64

66

67

68public:

69

71

73

75

77

79

81

83

84

86

88

89

91

93

94

96

98

99

101

103

104

106

108

109

111

113

114

116

117

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

148

149

151

152

153 ModFlagBehaviorFirstVal = Error,

154 ModFlagBehaviorLastVal = Min

156

157

158

159 static bool isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB);

160

165

167 : Behavior(B), Key(K), Val(V) {}

168 };

169

170

171

172

173private:

174 LLVMContext &Context;

175

176 GlobalListType GlobalList;

177 FunctionListType FunctionList;

178 AliasListType AliasList;

179 IFuncListType IFuncList;

180 NamedMDListType NamedMDList;

181 std::string GlobalScopeAsm;

182 std::unique_ptr ValSymTab;

183 ComdatSymTabType ComdatSymTab;

184 std::unique_ptr

185 OwnedMemoryBuffer;

186

187 std::unique_ptr

188 Materializer;

189 std::string ModuleID;

190 std::string SourceFileName;

191

192 std::string TargetTriple;

193

194 NamedMDSymTabType NamedMDSymTab;

195 DataLayout DL;

197 CurrentIntrinsicIds;

198

200 UniquedIntrinsicNames;

201

202

203

204

205

207

209

210

211

212

213public:

214

215

216

218

219

220

221

222 void removeDebugIntrinsicDeclarations();

223

224

226 for (auto &F : *this) {

227 F.convertToNewDbgValues();

228 }

229 IsNewDbgInfoFormat = true;

230 }

231

232

234 for (auto &F : *this) {

235 F.convertFromNewDbgValues();

236 }

237 IsNewDbgInfoFormat = false;

238 }

239

241 if (UseNewFormat && !IsNewDbgInfoFormat)

242 convertToNewDbgValues();

243 else if (!UseNewFormat && IsNewDbgInfoFormat)

244 convertFromNewDbgValues();

245 }

247 for (auto &F : *this) {

248 F.setNewDbgInfoFormatFlag(NewFlag);

249 }

250 IsNewDbgInfoFormat = NewFlag;

251 }

252

253

254

256

258

259

261

262

263

264

265

266

267

269

270

271

272

273 unsigned getInstructionCount() const;

274

275

276

277

278

280

281

282

283

284

286

287

288

290 return DL.getStringRepresentation();

291 }

292

293

295

296

297

299

300

301

303

304

305

307

308

309

310

311

312

313

314

315

316

317 std::unique_ptr createRNG(const StringRef Name) const;

318

319

320

322 return getContext().getDiagHandlerPtr()->isAnalysisRemarkEnabled(

323 "size-info");

324 }

325

326

327

328

329

330

332

333

335

336

339

340

342

343

344

346 GlobalScopeAsm = std::string(Asm);

347 if (!GlobalScopeAsm.empty() && GlobalScopeAsm.back() != '\n')

348 GlobalScopeAsm += '\n';

349 }

350

351

352

354 GlobalScopeAsm += Asm;

355 if (!GlobalScopeAsm.empty() && GlobalScopeAsm.back() != '\n')

356 GlobalScopeAsm += '\n';

357 }

358

359

360

361

362

363

364

365

367

368

369 unsigned getNumNamedValues() const;

370

371

372

374

375

376

378

379

380

381

383

384 std::vector<StructType *> getIdentifiedStructTypes() const;

385

386

387

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

407

409

410

411

412 template <typename... ArgsTy>

415 ArgsTy... Args) {

417 return getOrInsertFunction(Name,

418 FunctionType::get(RetTy, ArgTys, false),

420 }

421

422

423 template <typename... ArgsTy>

425 ArgsTy... Args) {

427 }

428

429

430 template <typename... ArgsTy>

433 FunctionType *Invalid, ArgsTy... Args) = delete;

434

435

436

438

439

440

441

442

443

444

445

446

449 }

450

452

454 bool AllowInternal = false) {

456 AllowInternal);

457 }

458

459

460

461

464 }

467 static_cast<const Module *>(this)->getNamedGlobal(Name));

468 }

469

470

471

472

473

477

478

479

481

482

483

484

485

486

487

488

490

491

492

493

494

495

496

497

499

500

501

502

503

504

505

507

508

509

510

512

513

514 void eraseNamedMetadata(NamedMDNode *NMD);

515

516

517

518

519

520

521

523

524

525

526

527

528

530

531

532

534

535

536

538

539

540

541

542 NamedMDNode *getOrInsertModuleFlagsMetadata();

543

544

545

546 void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val);

547 void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Constant *Val);

548 void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, uint32_t Val);

550

551 void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val);

552 void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, Constant *Val);

553 void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, uint32_t Val);

554

555

556

557

558

559

560

561

562

563

564

565

567

570

571

573

574

575

577

579

580

582

584

585

587 insertGlobalVariable(GlobalList.end(), GV);

588 }

589

590

592 GlobalList.insert(Where, GV);

593 }

594

595

596

597private:

598

599

600

601

602

603 const GlobalListType &getGlobalList() const { return GlobalList; }

604

605 GlobalListType &getGlobalList() { return GlobalList; }

606

608 return &Module::GlobalList;

609 }

611

612public:

613

615

618 return &Module::FunctionList;

619 }

620

621

623

625

627

628

629

630

632

634

636

637

638

639

641

643

645 NamedMDList.push_back(MDNode);

646 }

647

648

649

650private:

651

652 const AliasListType &getAliasList() const { return AliasList; }

653

654 AliasListType &getAliasList() { return AliasList; }

655

657 return &Module::AliasList;

658 }

660

661

662 const IFuncListType &getIFuncList() const { return IFuncList; }

663

664 IFuncListType &getIFuncList() { return IFuncList; }

665

667 return &Module::IFuncList;

668 }

670

671

672 const NamedMDListType &getNamedMDList() const { return NamedMDList; }

673

674 NamedMDListType &getNamedMDList() { return NamedMDList; }

675

676 static NamedMDListType Module::*getSublistAccess(NamedMDNode*) {

677 return &Module::NamedMDList;

678 }

679

680public:

681

683

685

686

688

690

691

692

693

694

699 size_t global_size () const { return GlobalList.size(); }

701

703 return make_range(global_begin(), global_end());

704 }

706 return make_range(global_begin(), global_end());

707 }

708

709

710

711

712

721 size_t size() const { return FunctionList.size(); }

722 bool empty() const { return FunctionList.empty(); }

723

726 }

729 }

730

731

732

733

734

739 size_t alias_size () const { return AliasList.size(); }

740 bool alias_empty() const { return AliasList.empty(); }

741

743 return make_range(alias_begin(), alias_end());

744 }

746 return make_range(alias_begin(), alias_end());

747 }

748

749

750

751

752

757 size_t ifunc_size () const { return IFuncList.size(); }

758 bool ifunc_empty() const { return IFuncList.empty(); }

759

761 return make_range(ifunc_begin(), ifunc_end());

762 }

764 return make_range(ifunc_begin(), ifunc_end());

765 }

766

767

768

769

770

776

779

786

789

790

791

792

793

796 return NamedMDList.begin();

797 }

798

801 return NamedMDList.end();

802 }

803

806

808 return make_range(named_metadata_begin(), named_metadata_end());

809 }

811 return make_range(named_metadata_begin(), named_metadata_end());

812 }

813

814

817 unsigned Idx;

818

819 void SkipNoDebugCUs();

820

821 public:

827

829 : CUs(CUs), Idx(Idx) {

830 SkipNoDebugCUs();

831 }

832

835 SkipNoDebugCUs();

836 return *this;

837 }

838

842 return T;

843 }

844

846 return Idx == I.Idx;

847 }

848

850 return Idx != I.Idx;

851 }

852

855 };

856

858 auto *CUs = getNamedMetadata("llvm.dbg.cu");

860 }

861

863 auto *CUs = getNamedMetadata("llvm.dbg.cu");

865 }

866

867

868

869

871 auto *CUs = getNamedMetadata("llvm.dbg.cu");

875 }

876

877

878

879

880

881

882

883

884

885 void dropTriviallyDeadConstantArrays();

886

887

888

889

890

891

892

893

895 bool ShouldPreserveUseListOrder = false,

896 bool IsForDebug = false) const;

897

898

899 void dump() const;

900

901

902

903

904

905

906

907 void dropAllReferences();

908

909

910

911

912

913

914

915 unsigned getNumberRegisterParameters() const;

916

917

918 unsigned getDwarfVersion() const;

919

920

921 bool isDwarf64() const;

922

923

924

925 unsigned getCodeViewFlag() const;

926

927

928

929

930

931

933

934

936

937

938

939

940

941

942

944

945

947

948

949

950

951

952

953

954 std::optionalCodeModel::Model getCodeModel() const;

955

956

958

959

960

961

962

963

964

965 std::optional<uint64_t> getLargeDataThreshold() const;

966

967

968 void setLargeDataThreshold(uint64_t Threshold);

969

970

971

972

973

974

976

977

978

979 Metadata *getProfileSummary(bool IsCS) const;

980

981

982

983 bool getSemanticInterposition() const;

984

985

986 void setSemanticInterposition(bool);

987

988

989 bool getRtLibUseGOT() const;

990

991

992 void setRtLibUseGOT();

993

994

995

996 bool getDirectAccessExternalData() const;

997 void setDirectAccessExternalData(bool Value);

998

999

1002

1003

1004

1007

1008

1009 StringRef getStackProtectorGuard() const;

1010 void setStackProtectorGuard(StringRef Kind);

1011

1012

1013

1014

1015 StringRef getStackProtectorGuardReg() const;

1016 void setStackProtectorGuardReg(StringRef Reg);

1017

1018

1019 StringRef getStackProtectorGuardSymbol() const;

1020 void setStackProtectorGuardSymbol(StringRef Symbol);

1021

1022

1023 int getStackProtectorGuardOffset() const;

1024 void setStackProtectorGuardOffset(int Offset);

1025

1026

1027 unsigned getOverrideStackAlignment() const;

1028 void setOverrideStackAlignment(unsigned Align);

1029

1030 unsigned getMaxTLSAlignment() const;

1031

1032

1033

1034

1035

1037

1038

1039

1040

1042

1043

1044

1045 void setOwnedMemoryBuffer(std::unique_ptr MB);

1046

1047

1048

1050

1051

1052

1053

1054

1055 StringRef getDarwinTargetVariantTriple() const;

1056

1057

1058

1059 void setDarwinTargetVariantTriple(StringRef T);

1060

1061

1062

1063

1064 VersionTuple getDarwinTargetVariantSDKVersion() const;

1065

1066

1067 void setDarwinTargetVariantSDKVersion(VersionTuple Version);

1068};

1069

1070

1071

1072

1074 SmallVectorImpl<GlobalValue *> &Vec,

1075 bool CompilerUsed);

1076

1077

1079 M.print(O, nullptr);

1080 return O;

1081}

1082

1083

1085

1086

1087

1088

1090 return reinterpret_cast<Module*>(MP);

1091}

1092

1093}

1094

1095#endif

This file defines the StringMap class.

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)

This file contains the simple types necessary to represent the attributes associated with functions a...

static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")

static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")

#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)

Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx

std::optional< std::vector< StOtherPiece > > Other

static Function * getFunction(Constant *C)

This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...

Machine Check Debug Module

static Constant * getOrInsertGlobal(Module &M, StringRef Name, Type *Ty)

static CodeModel::Model getCodeModel(const PPCSubtarget &S, const TargetMachine &TM, const MachineOperand &MO)

static GlobalVariable * getGlobalVariable(Module &M, Type *Ty, WebAssemblyTargetMachine &TM, const char *Name)

This is an important base class in LLVM.

A parsed version of the target data layout string in and methods for querying it.

Lightweight error class with error context and mandatory checking.

A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...

Class to represent function types.

This is an important class for using LLVM in a threaded context.

Class to hold module path string table and global value map, and encapsulate methods for operating on...

An iterator for DICompileUnits that skips those marked NoDebug.

debug_compile_units_iterator & operator++()

bool operator==(const debug_compile_units_iterator &I) const

debug_compile_units_iterator operator++(int)

std::input_iterator_tag iterator_category

std::ptrdiff_t difference_type

debug_compile_units_iterator(NamedMDNode *CUs, unsigned Idx)

bool operator!=(const debug_compile_units_iterator &I) const

A Module instance is used to store all the information related to an LLVM module.

global_iterator global_begin()

void removeIFunc(GlobalIFunc *IFunc)

Detach IFunc from the list but don't delete it.

const_global_iterator global_begin() const

const_iterator begin() const

ifunc_iterator ifunc_begin()

void eraseNamedMDNode(NamedMDNode *MDNode)

Remove MDNode from the list and delete it.

const std::string & getModuleInlineAsm() const

Get any module-scope inline assembly blocks.

ModFlagBehavior

This enumeration defines the supported behaviors of module flags.

LLVMContext & getContext() const

Get the global data context.

void insertIFunc(GlobalIFunc *IFunc)

Insert IFunc at the end of the alias list and take ownership.

iterator_range< const_alias_iterator > aliases() const

void setModuleInlineAsm(StringRef Asm)

Set the module-scope inline assembly blocks.

const ComdatSymTabType & getComdatSymbolTable() const

Get the Module's symbol table for COMDATs (constant).

bool IsNewDbgInfoFormat

Is this Module using intrinsics to record the position of debugging information, or non-intrinsic rec...

global_iterator global_end()

GlobalVariable * getNamedGlobal(StringRef Name)

NamedMDListType::iterator named_metadata_iterator

The named metadata iterators.

size_t alias_size() const

const_global_iterator global_end() const

bool global_empty() const

void convertToNewDbgValues()

FunctionCallee getOrInsertFunction(StringRef Name, AttributeList AttributeList, Type *RetTy, ArgsTy... Args)

Same as above, but takes a list of function arguments, which makes it easier for clients to use.

const_ifunc_iterator ifunc_end() const

void convertFromNewDbgValues()

iterator_range< ifunc_iterator > ifuncs()

bool named_metadata_empty() const

ValueSymbolTable & getValueSymbolTable()

Get the Module's symbol table of global variable and function identifiers.

NamedMDListType::const_iterator const_named_metadata_iterator

The named metadata constant iterators.

const_named_metadata_iterator named_metadata_begin() const

size_t global_size() const

iterator_range< debug_compile_units_iterator > debug_compile_units() const

Return an iterator for all DICompileUnits listed in this Module's llvm.dbg.cu named metadata node and...

iterator_range< iterator > functions()

StringRef getName() const

Get a short "name" for the module.

GVMaterializer * getMaterializer() const

Retrieves the GVMaterializer, if any, for this Module.

const std::string & getSourceFileName() const

Get the module's original source file name.

IFuncListType::iterator ifunc_iterator

The Global IFunc iterators.

const_alias_iterator alias_end() const

void removeAlias(GlobalAlias *Alias)

Detach Alias from the list but don't delete it.

iterator_range< named_metadata_iterator > named_metadata()

named_metadata_iterator named_metadata_begin()

ifunc_iterator ifunc_end()

GlobalListType::const_iterator const_global_iterator

The Global Variable constant iterator.

iterator_range< alias_iterator > aliases()

const std::string & getTargetTriple() const

Get the target triple which is a string describing the target host.

void insertGlobalVariable(GlobalListType::iterator Where, GlobalVariable *GV)

Insert global variable GV into the global variable list before Where and take ownership.

alias_iterator alias_end()

const_alias_iterator alias_begin() const

const_reverse_iterator rbegin() const

alias_iterator alias_begin()

FunctionListType::iterator iterator

The Function iterators.

GlobalVariable * getGlobalVariable(StringRef Name, bool AllowInternal=false)

void eraseIFunc(GlobalIFunc *IFunc)

Remove IFunc from the list and delete it.

bool shouldEmitInstrCountChangedRemark()

Return true if size-info optimization remark is enabled, false otherwise.

GlobalListType::iterator global_iterator

The Global Variable iterator.

void setNewDbgInfoFormatFlag(bool NewFlag)

FunctionListType::const_reverse_iterator const_reverse_iterator

The Function constant reverse iterator.

FunctionCallee getOrInsertFunction(StringRef Name, AttributeList AttributeList, FunctionType *Invalid, ArgsTy... Args)=delete

iterator_range< global_iterator > globals()

const_reverse_iterator rend() const

iterator_range< const_named_metadata_iterator > named_metadata() const

IFuncListType::const_iterator const_ifunc_iterator

The Global IFunc constant iterator.

size_t ifunc_size() const

FunctionListType & getFunctionList()

Get the Module's list of functions.

void eraseAlias(GlobalAlias *Alias)

Remove Alias from the list and delete it.

const std::string & getModuleIdentifier() const

Get the module identifier which is, essentially, the name of the module.

void eraseGlobalVariable(GlobalVariable *GV)

Remove global variable GV from the list and delete it.

reverse_iterator rbegin()

FunctionCallee getOrInsertFunction(StringRef Name, Type *RetTy, ArgsTy... Args)

Same as above, but without the attributes.

void insertNamedMDNode(NamedMDNode *MDNode)

Insert MDNode at the end of the alias list and take ownership.

const_named_metadata_iterator named_metadata_end() const

void removeNamedMDNode(NamedMDNode *MDNode)

Detach MDNode from the list but don't delete it.

AliasListType::iterator alias_iterator

The Global Alias iterators.

GlobalVariable * getGlobalVariable(StringRef Name) const

Look up the specified global variable in the module symbol table.

void insertGlobalVariable(GlobalVariable *GV)

Insert global variable GV at the end of the global variable list and take ownership.

const ValueSymbolTable & getValueSymbolTable() const

Get the symbol table of global variable and function identifiers.

size_t named_metadata_size() const

named_metadata_iterator named_metadata_end()

bool isMaterialized() const

const GlobalVariable * getNamedGlobal(StringRef Name) const

Return the global variable in the module with the specified name, of arbitrary type.

AliasListType::const_iterator const_alias_iterator

The Global Alias constant iterator.

ComdatSymTabType & getComdatSymbolTable()

Get the Module's symbol table for COMDATs.

FunctionListType::reverse_iterator reverse_iterator

The Function reverse iterator.

const DataLayout & getDataLayout() const

Get the data layout for the module's target platform.

iterator_range< const_iterator > functions() const

void setIsNewDbgInfoFormat(bool UseNewFormat)

NamedMDNode * getModuleFlagsMetadata() const

Returns the NamedMDNode in the module that represents module-level flags.

iterator_range< const_global_iterator > globals() const

void setModuleIdentifier(StringRef ID)

Set the module identifier.

iterator_range< const_ifunc_iterator > ifuncs() const

const_iterator end() const

void setSourceFileName(StringRef Name)

Set the module's original source file name.

const_ifunc_iterator ifunc_begin() const

const std::string & getDataLayoutStr() const

Get the data layout string for the module's target platform.

static FunctionListType Module::* getSublistAccess(Function *)

void appendModuleInlineAsm(StringRef Asm)

Append to the module-scope inline assembly blocks.

FunctionListType::const_iterator const_iterator

The Function constant iterator.

void insertAlias(GlobalAlias *Alias)

Insert Alias at the end of the alias list and take ownership.

debug_compile_units_iterator debug_compile_units_begin() const

void setTargetTriple(StringRef T)

Set the target triple.

void removeGlobalVariable(GlobalVariable *GV)

Detach global variable GV from the list but don't delete it.

debug_compile_units_iterator debug_compile_units_end() const

This class consists of common code factored out of the SmallVector class to reduce code duplication b...

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

StringRef - Represent a constant reference to a string, i.e.

The instances of the Type class are immutable: once they are created, they are never changed.

This class provides a symbol table of name/value pairs.

LLVM Value Representation.

Represents a version number in the form major[.minor[.subminor[.build]]].

Iterator wrapper that concatenates sequences together.

An efficient, type-erasing, non-owning reference to a callable.

base_list_type::const_reverse_iterator const_reverse_iterator

base_list_type::reverse_iterator reverse_iterator

base_list_type::const_iterator const_iterator

base_list_type::iterator iterator

An intrusive list with ownership and callbacks specified/controlled by ilist_traits,...

A range adaptor for a pair of iterators.

This class implements an extremely fast bulk output stream that can only output to a stream.

struct LLVMOpaqueModule * LLVMModuleRef

The top-level container for all other LLVM Intermediate Representation (IR) objects.

struct LLVMOpaqueModuleProvider * LLVMModuleProviderRef

Interface used to provide a module to JIT or interpreter.

This provides a very simple, boring adaptor for a begin and end iterator into a range type.

This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.

This is an optimization pass for GlobalISel generic memory operations.

void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)

APInt operator*(APInt a, uint64_t RHS)

iterator_range< T > make_range(T x, T y)

Convenience function for iterating over sub-ranges.

Attribute unwrap(LLVMAttributeRef Attr)

raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)

GlobalVariable * collectUsedGlobalVariables(const Module &M, SmallVectorImpl< GlobalValue * > &Vec, bool CompilerUsed)

Given "llvm.used" or "llvm.compiler.used" as a global name, collect the initializer elements of that ...

This struct is a compact representation of a valid (non-zero power of two) alignment.

Description of the encoding of one expression Op.

ModuleFlagEntry(ModFlagBehavior B, MDString *K, Metadata *V)