Skip to content

Commit f162735

Browse files
committed
Serialise function operands.
1 parent 5f5eed0 commit f162735

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

llvm/lib/YkIR/YkIRWriter.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ enum OperandKind {
5252
Constant = 0,
5353
LocalVariable,
5454
Type,
55+
Function,
5556
UnimplementedOperand = 255,
5657
};
5758

@@ -148,6 +149,12 @@ class YkIRWriter {
148149
return Idx;
149150
}
150151

152+
size_t functionIndex(llvm::Function *F) {
153+
// FIXME: For now we assume that function indicies in LLVM IR and our IR
154+
// are the same.
155+
return getIndex(&M, F);
156+
}
157+
151158
public:
152159
YkIRWriter(Module &M, MCStreamer &OutStreamer)
153160
: M(M), OutStreamer(OutStreamer) {}
@@ -177,6 +184,11 @@ class YkIRWriter {
177184
serialiseString(S);
178185
}
179186

187+
void serialiseFunctionOperand(llvm::Function *F) {
188+
OutStreamer.emitInt8(OperandKind::Function);
189+
OutStreamer.emitSizeT(functionIndex(F));
190+
}
191+
180192
// YKFIXME: This allows programs which we haven't yet defined a
181193
// lowering for to compile. For now We just emit a string operand containing
182194
// the unhandled LLVM operand in textual form.
@@ -187,7 +199,9 @@ class YkIRWriter {
187199

188200
void serialiseOperand(Instruction *Parent, ValueLoweringMap &VLMap,
189201
Value *V) {
190-
if (llvm::Constant *C = dyn_cast<llvm::Constant>(V)) {
202+
if (llvm::Function *F = dyn_cast<llvm::Function>(V)) {
203+
serialiseFunctionOperand(F);
204+
} else if (llvm::Constant *C = dyn_cast<llvm::Constant>(V)) {
191205
serialiseConstantOperand(Parent, C);
192206
} else if (Instruction *I = dyn_cast<Instruction>(V)) {
193207
// If an instruction defines the operand, it's a local variable.
@@ -325,7 +339,7 @@ class YkIRWriter {
325339
BBIdx++;
326340
}
327341

328-
void serialiseFunc(Function &F) {
342+
void serialiseFunc(llvm::Function &F) {
329343
// name:
330344
serialiseString(F.getName());
331345
// num_blocks:
@@ -385,7 +399,7 @@ class YkIRWriter {
385399
// num_funcs:
386400
OutStreamer.emitSizeT(M.size());
387401
// funcs:
388-
for (Function &F : M) {
402+
for (llvm::Function &F : M) {
389403
serialiseFunc(F);
390404
}
391405

0 commit comments

Comments
 (0)