llvm.org GIT mirror llvm / 7e9df19
Use printable names to implement directional labels. This changes the implementation of local directional labels to use a dedicated map. With that it can then just use CreateTempSymbol, which is what the rest of MC uses. CreateTempSymbol doesn't do a great job at making sure the names are unique (or being efficient when the names are not needed), but that should probably be fixed in a followup patch. This fixes pr18928. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203826 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 6 years ago
5 changed file(s) with 46 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
6969 /// Symbols - Bindings of names to symbols.
7070 SymbolTable Symbols;
7171
72 /// A maping from a local label number and an instance count to a symbol.
73 /// For example, in the assembly
74 /// 1:
75 /// 2:
76 /// 1:
77 /// We have three labels represented by the pairs (1, 0), (2, 0) and (1, 1)
78 DenseMap, MCSymbol*> LocalSymbols;
79
7280 /// UsedNames - Keeps tracks of names that were used both for used declared
7381 /// and artificial symbols.
7482 StringMap UsedNames;
8189 DenseMap Instances;
8290 /// NextInstance() creates the next instance of the directional local label
8391 /// for the LocalLabelVal and adds it to the map if needed.
84 unsigned NextInstance(int64_t LocalLabelVal);
92 unsigned NextInstance(unsigned LocalLabelVal);
8593 /// GetInstance() gets the current instance of the directional local label
8694 /// for the LocalLabelVal and adds it to the map if needed.
87 unsigned GetInstance(int64_t LocalLabelVal);
95 unsigned GetInstance(unsigned LocalLabelVal);
8896
8997 /// The file name of the log file from the environment variable
9098 /// AS_SECURE_LOG_FILE. Which must be set before the .secure_log_unique
153161
154162 MCSymbol *CreateSymbol(StringRef Name);
155163
164 MCSymbol *getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal,
165 unsigned Instance);
166
156167 public:
157168 explicit MCContext(const MCAsmInfo *MAI, const MCRegisterInfo *MRI,
158169 const MCObjectFileInfo *MOFI, const SourceMgr *Mgr = 0,
189200 /// symbol names.
190201 unsigned getUniqueSymbolID() { return NextUniqueID++; }
191202
192 /// CreateDirectionalLocalSymbol - Create the definition of a directional
193 /// local symbol for numbered label (used for "1:" definitions).
194 MCSymbol *CreateDirectionalLocalSymbol(int64_t LocalLabelVal);
195
196 /// GetDirectionalLocalSymbol - Create and return a directional local
197 /// symbol for numbered label (used for "1b" or 1f" references).
198 MCSymbol *GetDirectionalLocalSymbol(int64_t LocalLabelVal, int bORf);
203 /// Create the definition of a directional local symbol for numbered label
204 /// (used for "1:" definitions).
205 MCSymbol *CreateDirectionalLocalSymbol(unsigned LocalLabelVal);
206
207 /// Create and return a directional local symbol for numbered label (used
208 /// for "1b" or 1f" references).
209 MCSymbol *GetDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before);
199210
200211 /// GetOrCreateSymbol - Lookup the symbol inside with the specified
201212 /// @p Name. If it exists, return it. If not, create a forward
161161 return CreateSymbol(NameSV);
162162 }
163163
164 unsigned MCContext::NextInstance(int64_t LocalLabelVal) {
164 unsigned MCContext::NextInstance(unsigned LocalLabelVal) {
165165 MCLabel *&Label = Instances[LocalLabelVal];
166166 if (!Label)
167167 Label = new (*this) MCLabel(0);
168168 return Label->incInstance();
169169 }
170170
171 unsigned MCContext::GetInstance(int64_t LocalLabelVal) {
171 unsigned MCContext::GetInstance(unsigned LocalLabelVal) {
172172 MCLabel *&Label = Instances[LocalLabelVal];
173173 if (!Label)
174174 Label = new (*this) MCLabel(0);
175175 return Label->getInstance();
176176 }
177177
178 MCSymbol *MCContext::CreateDirectionalLocalSymbol(int64_t LocalLabelVal) {
179 return GetOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) +
180 Twine(LocalLabelVal) +
181 "\2" +
182 Twine(NextInstance(LocalLabelVal)));
183 }
184 MCSymbol *MCContext::GetDirectionalLocalSymbol(int64_t LocalLabelVal,
185 int bORf) {
186 return GetOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) +
187 Twine(LocalLabelVal) +
188 "\2" +
189 Twine(GetInstance(LocalLabelVal) + bORf));
178 MCSymbol *MCContext::getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal,
179 unsigned Instance) {
180 MCSymbol *&Sym = LocalSymbols[std::make_pair(LocalLabelVal, Instance)];
181 if (!Sym)
182 Sym = CreateTempSymbol();
183 return Sym;
184 }
185
186 MCSymbol *MCContext::CreateDirectionalLocalSymbol(unsigned LocalLabelVal) {
187 unsigned Instance = NextInstance(LocalLabelVal);
188 return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
189 }
190
191 MCSymbol *MCContext::GetDirectionalLocalSymbol(unsigned LocalLabelVal,
192 bool Before) {
193 unsigned Instance = GetInstance(LocalLabelVal);
194 if (!Before)
195 ++Instance;
196 return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
190197 }
191198
192199 MCSymbol *MCContext::LookupSymbol(StringRef Name) const {
883883 }
884884 if (IDVal == "f" || IDVal == "b") {
885885 MCSymbol *Sym =
886 Ctx.GetDirectionalLocalSymbol(IntVal, IDVal == "f" ? 1 : 0);
886 Ctx.GetDirectionalLocalSymbol(IntVal, IDVal == "b");
887887 Res = MCSymbolRefExpr::Create(Sym, Variant, getContext());
888888 if (IDVal == "b" && Sym->isUndefined())
889889 return Error(Loc, "invalid reference to undefined symbol");
11041104 StringRef IDVal = getTok().getString();
11051105 if (IDVal == "f" || IDVal == "b") {
11061106 MCSymbol *Sym =
1107 getContext().GetDirectionalLocalSymbol(IntVal,
1108 IDVal == "f" ? 1 : 0);
1107 getContext().GetDirectionalLocalSymbol(IntVal, IDVal == "b");
11091108 MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
11101109 const MCExpr *Val =
11111110 MCSymbolRefExpr::Create(Sym, Variant, getContext());
77 .intel_syntax
88 cmp rdi, 1
99 jge 1f
10 // CHECK: jge "L11"
10 // CHECK: jge Ltmp0
1111 add rdi, 2
12 // CHECK: addq $2, %rdi
1213 1:
13 // CHECK: "L11":
14 // CHECK: Ltmp0:
1415 add rdi, 1
1516 ret