Skip to content

Commit 0cc0d20

Browse files
bors[bot]vext01
andauthored
84: Improve unimplemented stuff and serialise instruction types. r=ltratt a=vext01 Co-authored-by: Edd Barrett <[email protected]>
2 parents 21c2d42 + 050b73c commit 0cc0d20

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

llvm/lib/YkIR/YkIRWriter.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ enum OpCode {
5151
enum OperandKind {
5252
Constant = 0,
5353
LocalVariable,
54-
String,
54+
UnimplementedOperand = 255,
5555
};
5656

5757
enum TypeKind {
5858
Integer = 0,
5959
UnimplementedType = 255, // YKFIXME: Will eventually be deleted.
6060
};
6161

62-
string valueToString(Value *V) {
62+
template <class T> string toString(T *X) {
6363
string S;
6464
raw_string_ostream SS(S);
65-
V->print(SS);
65+
X->print(SS);
6666
return S;
6767
}
6868

@@ -153,17 +153,16 @@ class YkIRWriter {
153153
}
154154

155155
void serialiseStringOperand(const char *S) {
156-
OutStreamer.emitInt8(OperandKind::String);
156+
OutStreamer.emitInt8(OperandKind::UnimplementedOperand);
157157
serialiseString(S);
158158
}
159159

160160
// YKFIXME: This allows programs which we haven't yet defined a
161161
// lowering for to compile. For now We just emit a string operand containing
162162
// the unhandled LLVM operand in textual form.
163163
void serialiseUnimplementedOperand(Value *V) {
164-
OutStreamer.emitInt8(OperandKind::String);
165-
OutStreamer.emitInt8('?');
166-
serialiseString(valueToString(V));
164+
OutStreamer.emitInt8(OperandKind::UnimplementedOperand);
165+
serialiseString(toString(V));
167166
}
168167

169168
void serialiseOperand(Instruction *Parent, Value *V) {
@@ -180,6 +179,7 @@ class YkIRWriter {
180179
/// Does a naiave serialisation of an LLVM instruction by iterating over its
181180
/// operands and serialising them in turn.
182181
void serialiseInstGeneric(Instruction *I, OpCode Opc) {
182+
OutStreamer.emitSizeT(typeIndex(I->getType()));
183183
serialiseOpcode(Opc);
184184
OutStreamer.emitInt32(I->getNumOperands());
185185
for (Value *O : I->operands()) {
@@ -203,13 +203,15 @@ class YkIRWriter {
203203
serialiseUnimplementedInstruction(I);
204204
}
205205

206+
// An unimplemented instruction is lowered to an instruction with one
207+
// unimplemented operand containing the textual LLVM IR we couldn't handle.
206208
void serialiseUnimplementedInstruction(Instruction *I) {
207209
// opcode:
208210
serialiseOpcode(UnimplementedInstruction);
209211
// num_operands:
210212
OutStreamer.emitInt32(1);
211213
// problem instruction:
212-
serialiseStringOperand(valueToString(I).data());
214+
serialiseUnimplementedOperand(I);
213215
}
214216

215217
void serialiseBlock(BasicBlock &BB) {
@@ -238,11 +240,11 @@ class YkIRWriter {
238240
OutStreamer.emitInt32(ITy->getBitWidth());
239241
} else {
240242
OutStreamer.emitInt8(TypeKind::UnimplementedType);
243+
serialiseString(toString(Ty));
241244
}
242245
}
243246

244247
void serialiseConstantInt(ConstantInt *CI) {
245-
// OutStreamer.emitInt8(OperandKind::Constant);
246248
OutStreamer.emitSizeT(typeIndex(CI->getType()));
247249
OutStreamer.emitSizeT(CI->getBitWidth() / 8);
248250
for (size_t I = 0; I < CI->getBitWidth(); I += 8) {

0 commit comments

Comments
 (0)