llvm.org GIT mirror llvm / c49b29e
Require intervals in the range metadata to be in a canonical form: They must be non contiguous, non overlapping and sorted by the lower end. While this is technically a backward incompatibility, every frontent currently produces range metadata with a single interval and we don't have any pass that merges intervals yet, so no existing bitcode files should be rejected by this. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@157741 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 8 years ago
4 changed file(s) with 74 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
30533053
  • The range should not represent the full or empty set. That is,
  • 30543054 a!=b.
    30553055
    3056

    In addiion, the pairs must be in signed order of the lower bound and

    3057 they must be non contigous.

    30563058
    30573059

    Examples:

    30583060
    30603062 %a = load i8* %x, align 1, !range !0 ; Can only be 0 or 1
    30613063 %b = load i8* %y, align 1, !range !1 ; Can only be 255 (-1), 0 or 1
    30623064 %c = load i8* %z, align 1, !range !2 ; Can only be 0, 1, 3, 4 or 5
    3065 %d = load i8* %z, align 1, !range !3 ; Can only be -2, -1, 3, 4 or 5
    30633066 ...
    30643067 !0 = metadata !{ i8 0, i8 2 }
    30653068 !1 = metadata !{ i8 255, i8 2 }
    30663069 !2 = metadata !{ i8 0, i8 2, i8 3, i8 6 }
    3070 !3 = metadata !{ i8 -2, i8 0, i8 3, i8 6 }
    30673071
    30683072
    30693073
    13821382 Assert1(NumOperands % 2 == 0, "Unfinished range!", Range);
    13831383 unsigned NumRanges = NumOperands / 2;
    13841384 Assert1(NumRanges >= 1, "It should have at least one range!", Range);
    1385
    1386 APInt LastHigh;
    13851387 for (unsigned i = 0; i < NumRanges; ++i) {
    13861388 ConstantInt *Low = dyn_cast(Range->getOperand(2*i));
    13871389 Assert1(Low, "The lower limit must be an integer!", Low);
    13901392 Assert1(High->getType() == Low->getType() &&
    13911393 High->getType() == ElTy, "Range types must match load type!",
    13921394 &LI);
    1393 Assert1(High->getValue() != Low->getValue(), "Range must not be empty!",
    1394 Range);
    1395
    1396 APInt HighV = High->getValue();
    1397 APInt LowV = Low->getValue();
    1398 Assert1(HighV != LowV, "Range must not be empty!", Range);
    1399 if (i != 0) {
    1400 Assert1(Low->getValue().sgt(LastHigh),
    1401 "Intervals are overlapping, contiguous or not in order", Range);
    1402 if (i == NumRanges - 1 && HighV.slt(LowV)) {
    1403 APInt First = dyn_cast(Range->getOperand(0))->getValue();
    1404 Assert1(First.sgt(HighV),
    1405 "First and last intervals are contiguous or overlap", Range);
    1406 }
    1407 }
    1408 LastHigh = High->getValue();
    13951409 }
    13961410 }
    13971411
    7575 }
    7676 !8 = metadata !{i8 0, i8 0}
    7777 ; CHECK: Range must not be empty!
    78
    79 define i8 @f10(i8* %x) {
    80 entry:
    81 %y = load i8* %x, align 1, !range !9
    82 ret i8 %y
    83 }
    84 !9 = metadata !{i8 0, i8 2, i8 1, i8 3}
    85 ; CHECK: Intervals are overlapping, contiguous or not in order
    86
    87 define i8 @f11(i8* %x) {
    88 entry:
    89 %y = load i8* %x, align 1, !range !10
    90 ret i8 %y
    91 }
    92 !10 = metadata !{i8 0, i8 2, i8 2, i8 3}
    93 ; CHECK: Intervals are overlapping, contiguous or not in order
    94
    95 define i8 @f12(i8* %x) {
    96 entry:
    97 %y = load i8* %x, align 1, !range !11
    98 ret i8 %y
    99 }
    100 !11 = metadata !{i8 1, i8 2, i8 -1, i8 0}
    101 ; CHECK: Intervals are overlapping, contiguous or not in order
    102
    103 define i8 @f13(i8* %x) {
    104 entry:
    105 %y = load i8* %x, align 1, !range !12
    106 ret i8 %y
    107 }
    108 !12 = metadata !{i8 1, i8 3, i8 5, i8 1}
    109 ; CHECK: First and last intervals are contiguous or overlap
    110
    111 define i8 @f14(i8* %x) {
    112 entry:
    113 %y = load i8* %x, align 1, !range !13
    114 ret i8 %y
    115 }
    116 !13 = metadata !{i8 1, i8 3, i8 5, i8 2}
    117 ; CHECK: First and last intervals are contiguous or overlap
    1919 ret i8 %y
    2020 }
    2121 !2 = metadata !{i8 1, i8 3, i8 5, i8 42}
    22
    23 define i8 @f4(i8* %x) {
    24 entry:
    25 %y = load i8* %x, align 1, !range !3
    26 ret i8 %y
    27 }
    28 !3 = metadata !{i8 -1, i8 0, i8 1, i8 2}
    29
    30 define i8 @f5(i8* %x) {
    31 entry:
    32 %y = load i8* %x, align 1, !range !4
    33 ret i8 %y
    34 }
    35 !4 = metadata !{i8 -1, i8 0, i8 1, i8 -2}