llvm.org GIT mirror llvm / 8dae138
Fix WriteAsOperand to not emit a leading space character. Adjust its callers to emit a space character before calling it when a space is needed. This fixes several spurious whitespace issues in ScalarEvolution's debug dumps. See the test changes for examples. This also fixes odd space-after-tab indentation in the output for switch statements, and changes calls from being printed like this: call void @foo( i32 %x ) to this: call void @foo(i32 %x) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56196 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 11 years ago
12 changed file(s) with 70 addition(s) and 44 deletion(s). Raw diff Collapse all Expand all
890890
891891 // If we found some loop invariants, fold them into the recurrence.
892892 if (!LIOps.empty()) {
893 // NLI + LI + { Start,+,Step} --> NLI + { LI+Start,+,Step }
893 // NLI + LI + {Start,+,Step} --> NLI + {LI+Start,+,Step}
894894 LIOps.push_back(AddRec->getStart());
895895
896896 std::vector AddRecOps(AddRec->op_begin(), AddRec->op_end());
10381038
10391039 // If we found some loop invariants, fold them into the recurrence.
10401040 if (!LIOps.empty()) {
1041 // NLI * LI * { Start,+,Step} --> NLI * { LI*Start,+,LI*Step }
1041 // NLI * LI * {Start,+,Step} --> NLI * {LI*Start,+,LI*Step}
10421042 std::vector NewOps;
10431043 NewOps.reserve(AddRec->getNumOperands());
10441044 if (LIOps.size() == 1) {
11541154
11551155 if (Operands.back()->isZero()) {
11561156 Operands.pop_back();
1157 return getAddRecExpr(Operands, L); // { X,+,0 } --> X
1157 return getAddRecExpr(Operands, L); // {X,+,0} --> X
11581158 }
11591159
11601160 // Canonicalize nested AddRecs in by nesting them in order of loop depth.
30433043 for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
30443044 if (I->getType()->isInteger()) {
30453045 OS << *I;
3046 OS << " --> ";
3046 OS << " --> ";
30473047 SCEVHandle SV = getSCEV(&*I);
30483048 SV->print(OS);
30493049 OS << "\t\t";
776776 if (CA->getNumOperands()) {
777777 Out << ' ';
778778 printTypeInt(Out, ETy, TypeTable);
779 Out << ' ';
779780 WriteAsOperandInternal(Out, CA->getOperand(0),
780781 TypeTable, Machine);
781782 for (unsigned i = 1, e = CA->getNumOperands(); i != e; ++i) {
782783 Out << ", ";
783784 printTypeInt(Out, ETy, TypeTable);
785 Out << ' ';
784786 WriteAsOperandInternal(Out, CA->getOperand(i), TypeTable, Machine);
785787 }
788 Out << ' ';
786789 }
787 Out << " ]";
790 Out << ']';
788791 }
789792 return;
790793 }
797800 if (N) {
798801 Out << ' ';
799802 printTypeInt(Out, CS->getOperand(0)->getType(), TypeTable);
803 Out << ' ';
800804
801805 WriteAsOperandInternal(Out, CS->getOperand(0), TypeTable, Machine);
802806
803807 for (unsigned i = 1; i < N; i++) {
804808 Out << ", ";
805809 printTypeInt(Out, CS->getOperand(i)->getType(), TypeTable);
810 Out << ' ';
806811
807812 WriteAsOperandInternal(Out, CS->getOperand(i), TypeTable, Machine);
808813 }
814 Out << ' ';
809815 }
810816
811 Out << " }";
817 Out << '}';
812818 if (CS->getType()->isPacked())
813819 Out << '>';
814820 return;
820826 "Number of operands for a PackedConst must be > 0");
821827 Out << "< ";
822828 printTypeInt(Out, ETy, TypeTable);
829 Out << ' ';
823830 WriteAsOperandInternal(Out, CP->getOperand(0), TypeTable, Machine);
824831 for (unsigned i = 1, e = CP->getNumOperands(); i != e; ++i) {
825832 Out << ", ";
826833 printTypeInt(Out, ETy, TypeTable);
834 Out << ' ';
827835 WriteAsOperandInternal(Out, CP->getOperand(i), TypeTable, Machine);
828836 }
829837 Out << " >";
848856
849857 for (User::const_op_iterator OI=CE->op_begin(); OI != CE->op_end(); ++OI) {
850858 printTypeInt(Out, (*OI)->getType(), TypeTable);
859 Out << ' ';
851860 WriteAsOperandInternal(Out, *OI, TypeTable, Machine);
852861 if (OI+1 != CE->op_end())
853862 Out << ", ";
879888 static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
880889 std::map &TypeTable,
881890 SlotTracker *Machine) {
882 Out << ' ';
883891 if (V->hasName()) {
884892 PrintLLVMName(Out, V);
885893 return;
951959 if (Context)
952960 fillTypeNameTable(Context, TypeNames);
953961
954 if (PrintType)
962 if (PrintType) {
955963 printTypeInt(Out, V->getType(), TypeNames);
964 Out << ' ';
965 }
956966
957967 WriteAsOperandInternal(Out, V, TypeNames, 0);
958968 }
11071117 Out << "";
11081118 } else {
11091119 if (PrintType) {
1120 printType(Operand->getType());
11101121 Out << ' ';
1111 printType(Operand->getType());
11121122 }
11131123 WriteAsOperandInternal(Out, Operand, TypeNames, &Machine);
11141124 }
11191129 if (Operand == 0) {
11201130 Out << "";
11211131 } else {
1122 Out << ' ';
11231132 // Print the type
11241133 printType(Operand->getType());
11251134 // Print parameter attributes list
11261135 if (Attrs != ParamAttr::None)
11271136 Out << ' ' << ParamAttr::getAsString(Attrs);
1137 Out << ' ';
11281138 // Print the operand
11291139 WriteAsOperandInternal(Out, Operand, TypeNames, &Machine);
11301140 }
12381248 Out << (GV->isConstant() ? "constant " : "global ");
12391249 printType(GV->getType()->getElementType());
12401250
1241 if (GV->hasInitializer())
1251 if (GV->hasInitializer()) {
1252 Out << ' ';
12421253 writeOperand(GV->getInitializer(), false);
1254 }
12431255
12441256 if (unsigned AddressSpace = GV->getType()->getAddressSpace())
12451257 Out << " addrspace(" << AddressSpace << ") ";
14731485 if (PI == PE) {
14741486 Out << " No predecessors!";
14751487 } else {
1476 Out << " preds =";
1488 Out << " preds = ";
14771489 writeOperand(*PI, false);
14781490 for (++PI; PI != PE; ++PI) {
1479 Out << ',';
1491 Out << ", ";
14801492 writeOperand(*PI, false);
14811493 }
14821494 }
15581570
15591571 // Special case conditional branches to swizzle the condition out to the front
15601572 if (isa(I) && I.getNumOperands() > 1) {
1573 Out << ' ';
15611574 writeOperand(I.getOperand(2), true);
1562 Out << ',';
1575 Out << ", ";
15631576 writeOperand(Operand, true);
1564 Out << ',';
1577 Out << ", ";
15651578 writeOperand(I.getOperand(1), true);
15661579
15671580 } else if (isa(I)) {
15681581 // Special case switch statement to get formatting nice and correct...
1582 Out << ' ';
15691583 writeOperand(Operand , true);
1570 Out << ',';
1584 Out << ", ";
15711585 writeOperand(I.getOperand(1), true);
15721586 Out << " [";
15731587
15741588 for (unsigned op = 2, Eop = I.getNumOperands(); op < Eop; op += 2) {
15751589 Out << "\n\t\t";
15761590 writeOperand(I.getOperand(op ), true);
1577 Out << ',';
1591 Out << ", ";
15781592 writeOperand(I.getOperand(op+1), true);
15791593 }
15801594 Out << "\n\t]";
15851599
15861600 for (unsigned op = 0, Eop = I.getNumOperands(); op < Eop; op += 2) {
15871601 if (op) Out << ", ";
1588 Out << '[';
1589 writeOperand(I.getOperand(op ), false); Out << ',';
1602 Out << "[ ";
1603 writeOperand(I.getOperand(op ), false); Out << ", ";
15901604 writeOperand(I.getOperand(op+1), false); Out << " ]";
15911605 }
15921606 } else if (const ExtractValueInst *EVI = dyn_cast(&I)) {
1607 Out << ' ';
15931608 writeOperand(I.getOperand(0), true);
15941609 for (const unsigned *i = EVI->idx_begin(), *e = EVI->idx_end(); i != e; ++i)
15951610 Out << ", " << *i;
15961611 } else if (const InsertValueInst *IVI = dyn_cast(&I)) {
1597 writeOperand(I.getOperand(0), true); Out << ',';
1612 Out << ' ';
1613 writeOperand(I.getOperand(0), true); Out << ", ";
15981614 writeOperand(I.getOperand(1), true);
15991615 for (const unsigned *i = IVI->idx_begin(), *e = IVI->idx_end(); i != e; ++i)
16001616 Out << ", " << *i;
16211637 // only do this if the first argument is a pointer to a nonvararg function,
16221638 // and if the return type is not a pointer to a function.
16231639 //
1640 Out << ' ';
16241641 if (!FTy->isVarArg() &&
16251642 (!isa(RetTy) ||
16261643 !isa(cast(RetTy)->getElementType()))) {
1627 Out << ' '; printType(RetTy);
1644 printType(RetTy);
1645 Out << ' ';
16281646 writeOperand(Operand, false);
16291647 } else {
16301648 writeOperand(Operand, true);
16321650 Out << '(';
16331651 for (unsigned op = 1, Eop = I.getNumOperands(); op < Eop; ++op) {
16341652 if (op > 1)
1635 Out << ',';
1653 Out << ", ";
16361654 writeParamOperand(I.getOperand(op), PAL.getParamAttrs(op));
16371655 }
1638 Out << " )";
1656 Out << ')';
16391657 if (PAL.getParamAttrs(0) != ParamAttr::None)
16401658 Out << ' ' << ParamAttr::getAsString(PAL.getParamAttrs(0));
16411659 } else if (const InvokeInst *II = dyn_cast(&I)) {
16491667 case CallingConv::C: break; // default
16501668 case CallingConv::Fast: Out << " fastcc"; break;
16511669 case CallingConv::Cold: Out << " coldcc"; break;
1652 case CallingConv::X86_StdCall: Out << "x86_stdcallcc "; break;
1653 case CallingConv::X86_FastCall: Out << "x86_fastcallcc "; break;
1654 case CallingConv::X86_SSECall: Out << "x86_ssecallcc "; break;
1670 case CallingConv::X86_StdCall: Out << " x86_stdcallcc"; break;
1671 case CallingConv::X86_FastCall: Out << " x86_fastcallcc"; break;
1672 case CallingConv::X86_SSECall: Out << " x86_ssecallcc"; break;
16551673 default: Out << " cc" << II->getCallingConv(); break;
16561674 }
16571675
16651683 Out << ' '; printType(RetTy);
16661684 writeOperand(Operand, false);
16671685 } else {
1686 Out << ' ';
16681687 writeOperand(Operand, true);
16691688 }
16701689
16711690 Out << '(';
16721691 for (unsigned op = 3, Eop = I.getNumOperands(); op < Eop; ++op) {
16731692 if (op > 3)
1674 Out << ',';
1693 Out << ", ";
16751694 writeParamOperand(I.getOperand(op), PAL.getParamAttrs(op-2));
16761695 }
16771696
1678 Out << " )";
1697 Out << ')';
16791698 if (PAL.getParamAttrs(0) != ParamAttr::None)
16801699 Out << ' ' << ParamAttr::getAsString(PAL.getParamAttrs(0));
1681 Out << "\n\t\t\tto";
1700 Out << "\n\t\t\tto ";
16821701 writeOperand(II->getNormalDest(), true);
1683 Out << " unwind";
1702 Out << " unwind ";
16841703 writeOperand(II->getUnwindDest(), true);
16851704
16861705 } else if (const AllocationInst *AI = dyn_cast(&I)) {
16871706 Out << ' ';
16881707 printType(AI->getType()->getElementType());
16891708 if (AI->isArrayAllocation()) {
1690 Out << ',';
1709 Out << ", ";
16911710 writeOperand(AI->getArraySize(), true);
16921711 }
16931712 if (AI->getAlignment()) {
16941713 Out << ", align " << AI->getAlignment();
16951714 }
16961715 } else if (isa(I)) {
1697 if (Operand) writeOperand(Operand, true); // Work with broken code
1716 if (Operand) {
1717 Out << ' ';
1718 writeOperand(Operand, true); // Work with broken code
1719 }
16981720 Out << " to ";
16991721 printType(I.getType());
17001722 } else if (isa(I)) {
1701 if (Operand) writeOperand(Operand, true); // Work with broken code
1723 if (Operand) {
1724 Out << ' ';
1725 writeOperand(Operand, true); // Work with broken code
1726 }
17021727 Out << ", ";
17031728 printType(I.getType());
17041729 } else if (Operand) { // Print the normal way...
17281753 printType(TheType);
17291754 }
17301755
1756 Out << ' ';
17311757 for (unsigned i = 0, E = I.getNumOperands(); i != E; ++i) {
1732 if (i) Out << ',';
1758 if (i) Out << ", ";
17331759 writeOperand(I.getOperand(i), PrintAllTypes);
17341760 }
17351761 }
11 ; not a child of the loopentry.6 loop.
22 ;
33 ; RUN: llvm-as < %s | opt -analyze -loops | \
4 ; RUN: grep {^ Loop Containing: %loopentry.7}
4 ; RUN: grep {^ Loop Containing: %loopentry.7}
55
66 define void @getAndMoveToFrontDecode() {
77 br label %endif.2
0 ; RUN: llvm-as < %s | opt -analyze -scalar-evolution \
1 ; RUN: -scalar-evolution-max-iterations=0 | grep {Loop bb: 100 iterations}
1 ; RUN: -scalar-evolution-max-iterations=0 | grep {Loop bb: 100 iterations}
22 ; PR1533
33
44 @array = weak global [101 x i32] zeroinitializer, align 32 ; <[100 x i32]*> [#uses=1]
None ; RUN: llvm-as < %s | opt -scalar-evolution -analyze | grep {Loop bb: ( -1 + ( -1 \\* %x) + %y) iterations!}
0 ; RUN: llvm-as < %s | opt -scalar-evolution -analyze | grep {Loop bb: (-1 + (-1 \\* %x) + %y) iterations!}
11 ; PR1597
22
33 define i32 @f(i32 %x, i32 %y) {
None ; RUN: llvm-as < %s | opt -scalar-evolution -analyze | grep {Loop loop: ( 100 + ( -100 smax %n)) iterations!}
0 ; RUN: llvm-as < %s | opt -scalar-evolution -analyze | grep {Loop loop: (100 + (-100 smax %n)) iterations!}
11 ; PR2002
22
33 define void @foo(i8 %n) {
0 ; RUN: llvm-as < %s | opt -analyze -scalar-evolution -disable-output \
11 ; RUN: -scalar-evolution-max-iterations=0 | \
2 ; RUN: grep -F "( -1 + ( -1 * %j)) iterations"
2 ; RUN: grep -F "(-1 + (-1 * %j)) iterations"
33 ; PR2607
44
55 define i32 @_Z1aj(i32 %j) nounwind {
0 ; RUN: llvm-as < %s | opt -analyze -scalar-evolution -disable-output \
11 ; RUN: -scalar-evolution-max-iterations=0 | \
2 ; RUN: grep -F "( -2147483632 + ( 2147483632 smax ( -1 + ( -1 * %x)) smax ( -1 + ( -1 * %y)))) iterations"
2 ; RUN: grep -F "(-2147483632 + (2147483632 smax (-1 + (-1 * %x)) smax (-1 + (-1 * %y)))) iterations"
33 ; PR2607
44
55 define i32 @b(i32 %x, i32 %y) {
0 ; RUN: llvm-as < %s | opt -analyze -scalar-evolution -disable-output \
1 ; RUN: -scalar-evolution-max-iterations=0 | grep -F "Exits: 20028"
1 ; RUN: -scalar-evolution-max-iterations=0 | grep -F "Exits: 20028"
22 ; PR2621
33
44 define i32 @a() nounwind {
0 ; RUN: llvm-as < %s | opt -analyze -scalar-evolution -disable-output \
1 ; RUN: -scalar-evolution-max-iterations=0 | grep -F "Exits: -19168"
1 ; RUN: -scalar-evolution-max-iterations=0 | grep -F "Exits: -19168"
22 ; PR2621
33
44 define i32 @a() nounwind {
None ; RUN: llvm-as < %s | opt -scalar-evolution -analyze | grep {Loop bb3: ( -1 + %n) iterations!}
0 ; RUN: llvm-as < %s | opt -scalar-evolution -analyze | grep {Loop bb3: (-1 + %n) iterations!}
11
22 ; We don't want to use a max in the trip count expression in
33 ; this testcase.
0 ; RUN: llvm-as < %s | opt -analyze -scalar-evolution | grep smax | count 2
11 ; RUN: llvm-as < %s | opt -analyze -scalar-evolution | grep \
2 ; RUN: {%. smax %. smax %.}
2 ; RUN: {%. smax %. smax %.}
33 ; PR1614
44
55 define i32 @x(i32 %a, i32 %b, i32 %c) {