Skip to content

Commit 6c4caae

Browse files
authored
[LLVM][TableGen] Move DecoderEmitter output to anonymous namespace (#136214)
- Move the code generated by DecoderEmitter to anonymous namespace. - Move AMDGPU's usage of this code from header file to .cpp file. Note, we get build errors like "call to function 'decodeInstruction' that is neither visible in the template definition nor found by argument-dependent lookup" if we do not change AMDGPU.
1 parent a8fe21f commit 6c4caae

File tree

3 files changed

+44
-34
lines changed

3 files changed

+44
-34
lines changed

llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,46 @@ static DecodeStatus decodeVersionImm(MCInst &Inst, unsigned Imm,
487487
//
488488
//===----------------------------------------------------------------------===//
489489

490+
template <typename InsnType>
491+
DecodeStatus AMDGPUDisassembler::tryDecodeInst(const uint8_t *Table, MCInst &MI,
492+
InsnType Inst, uint64_t Address,
493+
raw_ostream &Comments) const {
494+
assert(MI.getOpcode() == 0);
495+
assert(MI.getNumOperands() == 0);
496+
MCInst TmpInst;
497+
HasLiteral = false;
498+
const auto SavedBytes = Bytes;
499+
500+
SmallString<64> LocalComments;
501+
raw_svector_ostream LocalCommentStream(LocalComments);
502+
CommentStream = &LocalCommentStream;
503+
504+
DecodeStatus Res =
505+
decodeInstruction(Table, TmpInst, Inst, Address, this, STI);
506+
507+
CommentStream = nullptr;
508+
509+
if (Res != MCDisassembler::Fail) {
510+
MI = TmpInst;
511+
Comments << LocalComments;
512+
return MCDisassembler::Success;
513+
}
514+
Bytes = SavedBytes;
515+
return MCDisassembler::Fail;
516+
}
517+
518+
template <typename InsnType>
519+
DecodeStatus
520+
AMDGPUDisassembler::tryDecodeInst(const uint8_t *Table1, const uint8_t *Table2,
521+
MCInst &MI, InsnType Inst, uint64_t Address,
522+
raw_ostream &Comments) const {
523+
for (const uint8_t *T : {Table1, Table2}) {
524+
if (DecodeStatus Res = tryDecodeInst(T, MI, Inst, Address, Comments))
525+
return Res;
526+
}
527+
return MCDisassembler::Fail;
528+
}
529+
490530
template <typename T> static inline T eatBytes(ArrayRef<uint8_t>& Bytes) {
491531
assert(Bytes.size() >= sizeof(T));
492532
const auto Res =

llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.h

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -130,41 +130,11 @@ class AMDGPUDisassembler : public MCDisassembler {
130130

131131
template <typename InsnType>
132132
DecodeStatus tryDecodeInst(const uint8_t *Table, MCInst &MI, InsnType Inst,
133-
uint64_t Address, raw_ostream &Comments) const {
134-
assert(MI.getOpcode() == 0);
135-
assert(MI.getNumOperands() == 0);
136-
MCInst TmpInst;
137-
HasLiteral = false;
138-
const auto SavedBytes = Bytes;
139-
140-
SmallString<64> LocalComments;
141-
raw_svector_ostream LocalCommentStream(LocalComments);
142-
CommentStream = &LocalCommentStream;
143-
144-
DecodeStatus Res =
145-
decodeInstruction(Table, TmpInst, Inst, Address, this, STI);
146-
147-
CommentStream = nullptr;
148-
149-
if (Res != Fail) {
150-
MI = TmpInst;
151-
Comments << LocalComments;
152-
return MCDisassembler::Success;
153-
}
154-
Bytes = SavedBytes;
155-
return MCDisassembler::Fail;
156-
}
157-
133+
uint64_t Address, raw_ostream &Comments) const;
158134
template <typename InsnType>
159135
DecodeStatus tryDecodeInst(const uint8_t *Table1, const uint8_t *Table2,
160136
MCInst &MI, InsnType Inst, uint64_t Address,
161-
raw_ostream &Comments) const {
162-
for (const uint8_t *T : {Table1, Table2}) {
163-
if (DecodeStatus Res = tryDecodeInst(T, MI, Inst, Address, Comments))
164-
return Res;
165-
}
166-
return MCDisassembler::Fail;
167-
}
137+
raw_ostream &Comments) const;
168138

169139
Expected<bool> onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size,
170140
ArrayRef<uint8_t> Bytes,

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,7 +2417,7 @@ void DecoderEmitter::run(raw_ostream &o) {
24172417
#include "llvm/TargetParser/SubtargetFeature.h"
24182418
#include <assert.h>
24192419
2420-
namespace llvm {
2420+
namespace {
24212421
)";
24222422

24232423
emitFieldFromInstruction(OS);
@@ -2561,7 +2561,7 @@ namespace llvm {
25612561
// Emit the main entry point for the decoder, decodeInstruction().
25622562
emitDecodeInstruction(OS, IsVarLenInst);
25632563

2564-
OS << "\n} // end namespace llvm\n";
2564+
OS << "\n} // namespace\n";
25652565
}
25662566

25672567
void llvm::EmitDecoder(const RecordKeeper &RK, raw_ostream &OS,

0 commit comments

Comments
 (0)