|
12 | 12 |
|
13 | 13 | #include "bolt/Core/MCPlusBuilder.h" |
14 | 14 | #include "bolt/Core/MCPlus.h" |
| 15 | +#include "llvm/MC/MCContext.h" |
15 | 16 | #include "llvm/MC/MCInst.h" |
16 | 17 | #include "llvm/MC/MCInstrAnalysis.h" |
17 | 18 | #include "llvm/MC/MCInstrDesc.h" |
@@ -266,17 +267,29 @@ bool MCPlusBuilder::clearOffset(MCInst &Inst) const { |
266 | 267 | return true; |
267 | 268 | } |
268 | 269 |
|
269 | | -MCSymbol *MCPlusBuilder::getLabel(const MCInst &Inst) const { |
| 270 | +MCSymbol *MCPlusBuilder::getInstLabel(const MCInst &Inst) const { |
270 | 271 | if (std::optional<int64_t> Label = |
271 | 272 | getAnnotationOpValue(Inst, MCAnnotation::kLabel)) |
272 | 273 | return reinterpret_cast<MCSymbol *>(*Label); |
273 | 274 | return nullptr; |
274 | 275 | } |
275 | 276 |
|
276 | | -bool MCPlusBuilder::setLabel(MCInst &Inst, MCSymbol *Label) const { |
| 277 | +MCSymbol *MCPlusBuilder::getOrCreateInstLabel(MCInst &Inst, const Twine &Name, |
| 278 | + MCContext *Ctx) const { |
| 279 | + MCSymbol *Label = getInstLabel(Inst); |
| 280 | + if (Label) |
| 281 | + return Label; |
| 282 | + |
| 283 | + Label = Ctx->createNamedTempSymbol(Name); |
| 284 | + setAnnotationOpValue(Inst, MCAnnotation::kLabel, |
| 285 | + reinterpret_cast<int64_t>(Label)); |
| 286 | + return Label; |
| 287 | +} |
| 288 | + |
| 289 | +void MCPlusBuilder::setInstLabel(MCInst &Inst, MCSymbol *Label) const { |
| 290 | + assert(!getInstLabel(Inst) && "Instruction already has assigned label."); |
277 | 291 | setAnnotationOpValue(Inst, MCAnnotation::kLabel, |
278 | 292 | reinterpret_cast<int64_t>(Label)); |
279 | | - return true; |
280 | 293 | } |
281 | 294 |
|
282 | 295 | std::optional<uint32_t> MCPlusBuilder::getSize(const MCInst &Inst) const { |
|
0 commit comments