llvm.org GIT mirror llvm / d57c749
bitcode support change for fast flags compatibility Summary: The discussion and as per need, each vendor needs a way to keep the old fast flags and the new fast flags in the auto upgrade path of the IR upgrader. This revision addresses that issue. Patched by Michael Berg Reviewers: qcolombet, hans, steven_wu Reviewed By: qcolombet, steven_wu Subscribers: dexonsmith, vsk, mehdi_amini, andrewrk, MatzeB, wristow, spatel Differential Revision: https://reviews.llvm.org/D43253 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@325525 91177308-0d34-0410-b5e6-96231b3b80d8 Steven Wu 2 years ago
9 changed file(s) with 41 addition(s) and 45 deletion(s). Raw diff Collapse all Expand all
406406 OBO_NO_SIGNED_WRAP = 1
407407 };
408408
409 /// FastMath Flags
410 /// This is a fixed layout derived from the bitcode emitted by LLVM 5.0
411 /// intended to decouple the in-memory representation from the serialization.
412 enum FastMathMap {
413 UnsafeAlgebra = (1 << 0), // Legacy
414 NoNaNs = (1 << 1),
415 NoInfs = (1 << 2),
416 NoSignedZeros = (1 << 3),
417 AllowReciprocal = (1 << 4),
418 AllowContract = (1 << 5),
419 ApproxFunc = (1 << 6),
420 AllowReassoc = (1 << 7)
421 };
422
409423 /// PossiblyExactOperatorOptionalFlags - Flags for serializing
410424 /// PossiblyExactOperator's SubclassOptionalData contents.
411425 enum PossiblyExactOperatorOptionalFlags { PEO_EXACT = 0 };
10461046
10471047 static FastMathFlags getDecodedFastMathFlags(unsigned Val) {
10481048 FastMathFlags FMF;
1049 if (0 != (Val & FastMathFlags::AllowReassoc))
1049 if (0 != (Val & bitc::UnsafeAlgebra))
1050 FMF.setFast();
1051 if (0 != (Val & bitc::AllowReassoc))
10501052 FMF.setAllowReassoc();
1051 if (0 != (Val & FastMathFlags::NoNaNs))
1053 if (0 != (Val & bitc::NoNaNs))
10521054 FMF.setNoNaNs();
1053 if (0 != (Val & FastMathFlags::NoInfs))
1055 if (0 != (Val & bitc::NoInfs))
10541056 FMF.setNoInfs();
1055 if (0 != (Val & FastMathFlags::NoSignedZeros))
1057 if (0 != (Val & bitc::NoSignedZeros))
10561058 FMF.setNoSignedZeros();
1057 if (0 != (Val & FastMathFlags::AllowReciprocal))
1059 if (0 != (Val & bitc::AllowReciprocal))
10581060 FMF.setAllowReciprocal();
1059 if (0 != (Val & FastMathFlags::AllowContract))
1061 if (0 != (Val & bitc::AllowContract))
10601062 FMF.setAllowContract(true);
1061 if (0 != (Val & FastMathFlags::ApproxFunc))
1063 if (0 != (Val & bitc::ApproxFunc))
10621064 FMF.setApproxFunc();
10631065 return FMF;
10641066 }
13331333 Flags |= 1 << bitc::PEO_EXACT;
13341334 } else if (const auto *FPMO = dyn_cast(V)) {
13351335 if (FPMO->hasAllowReassoc())
1336 Flags |= FastMathFlags::AllowReassoc;
1336 Flags |= bitc::AllowReassoc;
13371337 if (FPMO->hasNoNaNs())
1338 Flags |= FastMathFlags::NoNaNs;
1338 Flags |= bitc::NoNaNs;
13391339 if (FPMO->hasNoInfs())
1340 Flags |= FastMathFlags::NoInfs;
1340 Flags |= bitc::NoInfs;
13411341 if (FPMO->hasNoSignedZeros())
1342 Flags |= FastMathFlags::NoSignedZeros;
1342 Flags |= bitc::NoSignedZeros;
13431343 if (FPMO->hasAllowReciprocal())
1344 Flags |= FastMathFlags::AllowReciprocal;
1344 Flags |= bitc::AllowReciprocal;
13451345 if (FPMO->hasAllowContract())
1346 Flags |= FastMathFlags::AllowContract;
1346 Flags |= bitc::AllowContract;
13471347 if (FPMO->hasApproxFunc())
1348 Flags |= FastMathFlags::ApproxFunc;
1348 Flags |= bitc::ApproxFunc;
13491349 }
13501350
13511351 return Flags;
31953195 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LHS
31963196 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // RHS
31973197 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // opc
3198 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7)); // flags
3198 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8)); // flags
31993199 if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
32003200 FUNCTION_INST_BINOP_FLAGS_ABBREV)
32013201 llvm_unreachable("Unexpected abbrev ordering!");
611611 %f.arcp = fadd arcp float %op1, %op2
612612 ; CHECK: %f.arcp = fadd arcp float %op1, %op2
613613 %f.fast = fadd fast float %op1, %op2
614 ; 'fast' used to be its own bit, but this changed in Oct 2017.
615 ; The binary test file does not have the newer 'contract' and 'afn' bits set, so this is not fully 'fast'.
616 ; CHECK: %f.fast = fadd reassoc nnan ninf nsz arcp float %op1, %op2
614 ; CHECK: %f.fast = fadd fast float %op1, %op2
617615 ret void
618616 }
619617
655655 %f.arcp = fadd arcp float %op1, %op2
656656 ; CHECK: %f.arcp = fadd arcp float %op1, %op2
657657 %f.fast = fadd fast float %op1, %op2
658 ; 'fast' used to be its own bit, but this changed in Oct 2017.
659 ; The binary test file does not have the newer 'contract' and 'afn' bits set, so this is not fully 'fast'.
660 ; CHECK: %f.fast = fadd reassoc nnan ninf nsz arcp float %op1, %op2
658 ; CHECK: %f.fast = fadd fast float %op1, %op2
661659 ret void
662660 }
663661
686686 %f.arcp = fadd arcp float %op1, %op2
687687 ; CHECK: %f.arcp = fadd arcp float %op1, %op2
688688 %f.fast = fadd fast float %op1, %op2
689 ; 'fast' used to be its own bit, but this changed in Oct 2017.
690 ; The binary test file does not have the newer 'contract' and 'afn' bits set, so this is not fully 'fast'.
691 ; CHECK: %f.fast = fadd reassoc nnan ninf nsz arcp float %op1, %op2
689 ; CHECK: %f.fast = fadd fast float %op1, %op2
692690 ret void
693691 }
694692
701699 ; CHECK-LABEL: fastMathFlagsForCalls(
702700 define void @fastMathFlagsForCalls(float %f, double %d1, <4 x double> %d2) {
703701 %call.fast = call fast float @fmf1()
704 ; 'fast' used to be its own bit, but this changed in Oct 2017.
705 ; The binary test file does not have the newer 'contract' and 'aml' bits set, so this is not fully 'fast'.
706 ; CHECK: %call.fast = call reassoc nnan ninf nsz arcp float @fmf1()
702 ; CHECK: %call.fast = call fast float @fmf1()
707703
708704 ; Throw in some other attributes to make sure those stay in the right places.
709705
757757 %f.arcp = fadd arcp float %op1, %op2
758758 ; CHECK: %f.arcp = fadd arcp float %op1, %op2
759759 %f.fast = fadd fast float %op1, %op2
760 ; 'fast' used to be its own bit, but this changed in Oct 2017.
761 ; The binary test file does not have the newer 'contract' and 'afn' bits set, so this is not fully 'fast'.
762 ; CHECK: %f.fast = fadd reassoc nnan ninf nsz arcp float %op1, %op2
760 ; CHECK: %f.fast = fadd fast float %op1, %op2
763761 ret void
764762 }
765763
772770 ; CHECK-LABEL: fastMathFlagsForCalls(
773771 define void @fastMathFlagsForCalls(float %f, double %d1, <4 x double> %d2) {
774772 %call.fast = call fast float @fmf1()
775 ; 'fast' used to be its own bit, but this changed in Oct 2017.
776 ; The binary test file does not have the newer 'contract' and 'afn' bits set, so this is not fully 'fast'.
777 ; CHECK: %call.fast = call reassoc nnan ninf nsz arcp float @fmf1()
773 ; CHECK: %call.fast = call fast float @fmf1()
778774
779775 ; Throw in some other attributes to make sure those stay in the right places.
780776
756756 ; CHECK: %f.nsz = fadd nsz float %op1, %op2
757757 %f.arcp = fadd arcp float %op1, %op2
758758 ; CHECK: %f.arcp = fadd arcp float %op1, %op2
759 ; 'fast' used to be its own bit, but this changed in Oct 2017.
760 ; The binary test file does not have the newer 'contract' and 'afn' bits set, so this is not fully 'fast'.
761759 %f.fast = fadd fast float %op1, %op2
762 ; CHECK: %f.fast = fadd reassoc nnan ninf nsz arcp float %op1, %op2
760 ; CHECK: %f.fast = fadd fast float %op1, %op2
763761 ret void
764762 }
765763
772770 ; CHECK-LABEL: fastMathFlagsForCalls(
773771 define void @fastMathFlagsForCalls(float %f, double %d1, <4 x double> %d2) {
774772 %call.fast = call fast float @fmf1()
775 ; 'fast' used to be its own bit, but this changed in Oct 2017.
776 ; The binary test file does not have the newer 'contract' and 'afn' bits set, so this is not fully 'fast'.
777 ; CHECK: %call.fast = call reassoc nnan ninf nsz arcp float @fmf1()
773 ; CHECK: %call.fast = call fast float @fmf1()
778774
779775 ; Throw in some other attributes to make sure those stay in the right places.
780776
764764 %f.contract = fadd contract float %op1, %op2
765765 ; CHECK: %f.contract = fadd contract float %op1, %op2
766766 %f.fast = fadd fast float %op1, %op2
767 ; 'fast' used to be its own bit, but this changed in Oct 2017.
768 ; The binary test file does not have the newer 'afn' bit set, so this is not fully 'fast'.
769 ; CHECK: %f.fast = fadd reassoc nnan ninf nsz arcp contract float %op1, %op2
767 ; CHECK: %f.fast = fadd fast float %op1, %op2
770768 ret void
771769 }
772770
779777 ; CHECK-LABEL: fastMathFlagsForCalls(
780778 define void @fastMathFlagsForCalls(float %f, double %d1, <4 x double> %d2) {
781779 %call.fast = call fast float @fmf1()
782 ; 'fast' used to be its own bit, but this changed in Oct 2017.
783 ; The binary test file does not have the newer 'afn' bit set, so this is not fully 'fast'.
784 ; CHECK: %call.fast = call reassoc nnan ninf nsz arcp contract float @fmf1()
780 ; CHECK: %call.fast = call fast float @fmf1()
785781
786782 ; Throw in some other attributes to make sure those stay in the right places.
787783