Skip to content

Commit f2208d3

Browse files
authored
Merge pull request rust-lang#159 from vext01/unsupported-calls
Reject a bunch of call variants that we haven't considered yet.
2 parents c645c79 + 140c475 commit f2208d3

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

llvm/lib/YkIR/YkIRWriter.cpp

+75
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,71 @@ class YkIRWriter {
535535

536536
void serialiseCallInst(CallInst *I, FuncLowerCtxt &FLCtxt, unsigned BBIdx,
537537
unsigned &InstIdx) {
538+
// Tail calls:
539+
//
540+
// - The `tail` keyword is documented as ignorable, so we do.
541+
//
542+
// - The `notail` keyword just means don't add `tail` or `musttail`. I
543+
// think this has no consequences for us.
544+
//
545+
// - `musttail` is tricky. It means "it is semantically incorrect to NOT
546+
// tail call codegen this". I don't even know what this means for an
547+
// inlining tracer, so let's just reject it for now.
548+
if (I->isMustTailCall()) {
549+
serialiseUnimplementedInstruction(I, FLCtxt, BBIdx, InstIdx);
550+
}
551+
// We don't support some parameter attributes yet.
552+
AttributeList Attrs = I->getAttributes();
553+
for (unsigned AI = 0; AI < I->arg_size(); AI++) {
554+
for (auto &Attr : Attrs.getParamAttrs(AI)) {
555+
// `nonull` and `noundef` are used a lot. I think for our purposes they
556+
// can be safely ignored.
557+
if (Attr.isEnumAttribute() &&
558+
((Attr.getKindAsEnum() == Attribute::NonNull) ||
559+
(Attr.getKindAsEnum() == Attribute::NoUndef))) {
560+
continue;
561+
}
562+
serialiseUnimplementedInstruction(I, FLCtxt, BBIdx, InstIdx);
563+
return;
564+
}
565+
}
566+
// We don't support ANY return value attributes yet.
567+
if (Attrs.getRetAttrs().getNumAttributes() > 0) {
568+
serialiseUnimplementedInstruction(I, FLCtxt, BBIdx, InstIdx);
569+
return;
570+
}
571+
// We don't support some function attributes.
572+
//
573+
// Note that although we haven't thought about unwinding, if we reject any
574+
// call to a function that isn't `nounwind` we are unable to lower much at
575+
// all (including the call to the control point). So for now we have to
576+
// accept calls to functions that might unwind.
577+
AttributeSet FnAttrs = Attrs.getFnAttrs();
578+
for (auto &Attr : FnAttrs) {
579+
// - `cold` can be ignored.
580+
// - `nounwind` has no consequences for us at the moment.
581+
if (Attr.isEnumAttribute() &&
582+
((Attr.getKindAsEnum() == Attribute::Cold) ||
583+
(Attr.getKindAsEnum() == Attribute::NoUnwind))) {
584+
continue;
585+
}
586+
// Anything else, we've not thought about.
587+
serialiseUnimplementedInstruction(I, FLCtxt, BBIdx, InstIdx);
588+
return;
589+
}
590+
// In addition, we don't support:
591+
//
592+
// - fast math flags
593+
// - Non-C calling conventions.
594+
// - operand bundles
595+
// - non-zero address spaces
596+
//
597+
// Note: address spaces are blanket handled elsewhere in serialiseInst().
598+
if ((isa<FPMathOperator>(I) && I->getFastMathFlags().any()) ||
599+
(I->getCallingConv() != CallingConv::C) || I->hasOperandBundles()) {
600+
serialiseUnimplementedInstruction(I, FLCtxt, BBIdx, InstIdx);
601+
return;
602+
}
538603
if (I->isInlineAsm()) {
539604
// For now we omit calls to empty inline asm blocks.
540605
//
@@ -938,6 +1003,16 @@ class YkIRWriter {
9381003

9391004
void serialiseInst(Instruction *I, FuncLowerCtxt &FLCtxt, unsigned BBIdx,
9401005
unsigned &InstIdx) {
1006+
// Catch unsupported pointer operands in non-zero address spaces.
1007+
for (auto &O : I->operands()) {
1008+
if (PointerType *P = dyn_cast<PointerType>(O->getType())) {
1009+
if (P->getAddressSpace() != 0) {
1010+
serialiseUnimplementedInstruction(I, FLCtxt, BBIdx, InstIdx);
1011+
return;
1012+
}
1013+
}
1014+
}
1015+
9411016
// Macro to make the dispatch below easier to read/sort.
9421017
#define INST_SERIALISE(LLVM_INST, LLVM_INST_TYPE, SERIALISER) \
9431018
if (LLVM_INST_TYPE *II = dyn_cast<LLVM_INST_TYPE>(LLVM_INST)) { \

0 commit comments

Comments
 (0)