llvm.org GIT mirror llvm / e553fea
Small improvement to InstrinsicEmitter::EmitAttributes. This change removes the “pushing” and “clearing” of the SmallVector and instead uses const arrays to pass the attributeKinds to AttributeSet::get . Patch by Aditya Nandakumar. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194899 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 7 years ago
1 changed file(s) with 38 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
571571 OS << " AttributeSet AS[" << maxArgAttrs+1 << "];\n";
572572 OS << " unsigned NumAttrs = 0;\n";
573573 OS << " if (id != 0) {\n";
574 OS << " SmallVector AttrVec;\n";
575574 OS << " switch(IntrinsicsToAttributesMap[id - ";
576575 if (TargetOnly)
577576 OS << "Intrinsic::num_intrinsics";
581580 OS << " default: llvm_unreachable(\"Invalid attribute number\");\n";
582581 for (UniqAttrMapTy::const_iterator I = UniqAttributes.begin(),
583582 E = UniqAttributes.end(); I != E; ++I) {
584 OS << " case " << I->second << ":\n";
583 OS << " case " << I->second << ": {\n";
585584
586585 const CodeGenIntrinsic &intrinsic = *(I->first);
587586
594593 while (ai != ae) {
595594 unsigned argNo = intrinsic.ArgumentAttributes[ai].first;
596595
597 OS << " AttrVec.clear();\n";
596 OS << " const Attribute::AttrKind AttrParam" << argNo + 1 <<"[]= {";
597 bool addComma = false;
598598
599599 do {
600600 switch (intrinsic.ArgumentAttributes[ai].second) {
601601 case CodeGenIntrinsic::NoCapture:
602 OS << " AttrVec.push_back(Attribute::NoCapture);\n";
602 if (addComma)
603 OS << ",";
604 OS << "Attribute::NoCapture";
605 addComma = true;
603606 break;
604607 case CodeGenIntrinsic::ReadOnly:
605 OS << " AttrVec.push_back(Attribute::ReadOnly);\n";
608 if (addComma)
609 OS << ",";
610 OS << "Attribute::ReadOnly";
611 addComma = true;
606612 break;
607613 case CodeGenIntrinsic::ReadNone:
608 OS << " AttrVec.push_back(Attribute::ReadNone);\n";
614 if (addComma)
615 OS << ",";
616 OS << "Attributes::ReadNone";
617 addComma = true;
609618 break;
610619 }
611620
612621 ++ai;
613622 } while (ai != ae && intrinsic.ArgumentAttributes[ai].first == argNo);
614
623 OS << "};\n";
615624 OS << " AS[" << numAttrs++ << "] = AttributeSet::get(C, "
616 << argNo+1 << ", AttrVec);\n";
625 << argNo+1 << ", AttrParam" << argNo +1 << ");\n";
617626 }
618627 }
619628
620629 ModRefKind modRef = getModRefKind(intrinsic);
621630
622631 if (!intrinsic.canThrow || modRef || intrinsic.isNoReturn) {
623 OS << " AttrVec.clear();\n";
624
625 if (!intrinsic.canThrow)
626 OS << " AttrVec.push_back(Attribute::NoUnwind);\n";
627 if (intrinsic.isNoReturn)
628 OS << " AttrVec.push_back(Attribute::NoReturn);\n";
632 OS << " const Attribute::AttrKind Atts[] = {";
633 bool addComma = false;
634 if (!intrinsic.canThrow) {
635 OS << "Attribute::NoUnwind";
636 addComma = true;
637 }
638 if (intrinsic.isNoReturn) {
639 if (addComma)
640 OS << ",";
641 OS << "Attribute::NoReturn";
642 addComma = true;
643 }
629644
630645 switch (modRef) {
631646 case MRK_none: break;
632647 case MRK_readonly:
633 OS << " AttrVec.push_back(Attribute::ReadOnly);\n";
648 if (addComma)
649 OS << ",";
650 OS << "Attribute::ReadOnly";
634651 break;
635652 case MRK_readnone:
636 OS << " AttrVec.push_back(Attribute::ReadNone);\n";
653 if (addComma)
654 OS << ",";
655 OS << "Attribute::ReadNone";
637656 break;
638657 }
658 OS << "};\n";
639659 OS << " AS[" << numAttrs++ << "] = AttributeSet::get(C, "
640 << "AttributeSet::FunctionIndex, AttrVec);\n";
660 << "AttributeSet::FunctionIndex, Atts);\n";
641661 }
642662
643663 if (numAttrs) {
644664 OS << " NumAttrs = " << numAttrs << ";\n";
645665 OS << " break;\n";
666 OS << " }\n";
646667 } else {
647668 OS << " return AttributeSet();\n";
648669 }