LLVM: lib/IR/ValueSymbolTable.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

15#include "llvm/Config/llvm-config.h"

25#include

26

27using namespace llvm;

28

29#define DEBUG_TYPE "valuesymtab"

30

31

33#ifndef NDEBUG

34 for (const auto &VI : vmap)

35 dbgs() << "Value still in symbol table! Type = '"

36 << *VI.getValue()->getType() << "' Name = '" << VI.getKeyData()

37 << "'\n";

38 assert(vmap.empty() && "Values remain in symbol table!");

39#endif

40}

41

44 unsigned BaseSize = UniqueName.size();

45 bool AppenDot = false;

47

48

49

50

51

52

53 const Module *M = GV->getParent();

54 if (!(M && M->getTargetTriple().isNVPTX()))

55 AppenDot = true;

56 }

57

58 while (true) {

59

60 UniqueName.resize(BaseSize);

62 if (AppenDot)

63 S << ".";

64 S << ++LastUnique;

65

66

67 if (MaxNameSize > -1 && UniqueName.size() > (size_t)MaxNameSize) {

68 assert(BaseSize >= UniqueName.size() - (size_t)MaxNameSize &&

69 "Can't generate unique name: MaxNameSize is too small.");

70 BaseSize -= UniqueName.size() - (size_t)MaxNameSize;

71 continue;

72 }

73

74 auto IterBool = vmap.insert(std::make_pair(UniqueName.str(), V));

75 if (IterBool.second)

76 return &*IterBool.first;

77 }

78}

79

80

81

82void ValueSymbolTable::reinsertValue(Value *V) {

83 assert(V->hasName() && "Can't insert nameless Value into symbol table");

84

85

86 if (vmap.insert(V->getValueName())) {

87

88

89 return;

90 }

91

92

93 SmallString<256> UniqueName(V->getName().begin(), V->getName().end());

94

95

97 V->getValueName()->Destroy(Allocator);

98

99 ValueName *VN = makeUniqueName(V, UniqueName);

100 V->setValueName(VN);

101}

102

103void ValueSymbolTable::removeValueName(ValueName *V) {

104

105

106 vmap.remove(V);

107}

108

109

110

111

113 if (MaxNameSize > -1 && Name.size() > (unsigned)MaxNameSize)

114 Name = Name.substr(0, std::max(1u, (unsigned)MaxNameSize));

115

116

117 auto IterBool = vmap.insert(std::make_pair(Name, V));

118 if (IterBool.second) {

119

120

121 return &*IterBool.first;

122 }

123

124

125 SmallString<256> UniqueName(Name.begin(), Name.end());

126 return makeUniqueName(V, UniqueName);

127}

128

129#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

130

131

133

134 for (const auto &I : *this) {

135

136 I.getValue()->dump();

137

138 }

139}

140#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

#define LLVM_DUMP_METHOD

Mark debug helper function definitions like dump() that should not be stripped from debug builds.

Module.h This file contains the declarations for the Module class.

This file defines the SmallString class.

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

SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...

StringRef str() const

Explicit conversion to StringRef.

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

LLVM_ABI void dump() const

This function can be used from the debugger to display the content of the symbol table while debuggin...

Definition ValueSymbolTable.cpp:132

LLVM_ABI ~ValueSymbolTable()

Definition ValueSymbolTable.cpp:32

LLVM Value Representation.

A raw_ostream that writes to an SmallVector or SmallString.

This is an optimization pass for GlobalISel generic memory operations.

StringMapEntry< Value * > ValueName

decltype(auto) dyn_cast(const From &Val)

dyn_cast - Return the argument parameter cast to the specified type.

LLVM_ABI raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.