|
29 | 29 | #include "llvm/IR/BasicBlock.h" |
30 | 30 | #include "llvm/IR/Constant.h" |
31 | 31 | #include "llvm/IR/ConstantRange.h" |
| 32 | +#include "llvm/IR/ConstantRangeList.h" |
32 | 33 | #include "llvm/IR/Constants.h" |
33 | 34 | #include "llvm/IR/DebugInfoMetadata.h" |
34 | 35 | #include "llvm/IR/DebugLoc.h" |
@@ -1354,6 +1355,43 @@ MDNode *MDNode::getMostGenericRange(MDNode *A, MDNode *B) { |
1354 | 1355 | return MDNode::get(A->getContext(), MDs); |
1355 | 1356 | } |
1356 | 1357 |
|
| 1358 | +MDNode *MDNode::getMostGenericNoaliasAddrspace(MDNode *A, MDNode *B) { |
| 1359 | + if (!A || !B) |
| 1360 | + return nullptr; |
| 1361 | + |
| 1362 | + if (A == B) |
| 1363 | + return A; |
| 1364 | + |
| 1365 | + SmallVector<ConstantRange> RangeListA, RangeListB; |
| 1366 | + for (unsigned I = 0, E = A->getNumOperands() / 2; I != E; ++I) { |
| 1367 | + auto *LowA = mdconst::extract<ConstantInt>(A->getOperand(2 * I + 0)); |
| 1368 | + auto *HighA = mdconst::extract<ConstantInt>(A->getOperand(2 * I + 1)); |
| 1369 | + RangeListA.push_back(ConstantRange(LowA->getValue(), HighA->getValue())); |
| 1370 | + } |
| 1371 | + |
| 1372 | + for (unsigned I = 0, E = B->getNumOperands() / 2; I != E; ++I) { |
| 1373 | + auto *LowB = mdconst::extract<ConstantInt>(B->getOperand(2 * I + 0)); |
| 1374 | + auto *HighB = mdconst::extract<ConstantInt>(B->getOperand(2 * I + 1)); |
| 1375 | + RangeListB.push_back(ConstantRange(LowB->getValue(), HighB->getValue())); |
| 1376 | + } |
| 1377 | + |
| 1378 | + ConstantRangeList CRLA(RangeListA); |
| 1379 | + ConstantRangeList CRLB(RangeListB); |
| 1380 | + ConstantRangeList Result = CRLA.intersectWith(CRLB); |
| 1381 | + if (Result.empty()) |
| 1382 | + return nullptr; |
| 1383 | + |
| 1384 | + SmallVector<Metadata *> MDs; |
| 1385 | + for (const ConstantRange &CR : Result) { |
| 1386 | + MDs.push_back(ConstantAsMetadata::get( |
| 1387 | + ConstantInt::get(A->getContext(), CR.getLower()))); |
| 1388 | + MDs.push_back(ConstantAsMetadata::get( |
| 1389 | + ConstantInt::get(A->getContext(), CR.getUpper()))); |
| 1390 | + } |
| 1391 | + |
| 1392 | + return MDNode::get(A->getContext(), MDs); |
| 1393 | +} |
| 1394 | + |
1357 | 1395 | MDNode *MDNode::getMostGenericAlignmentOrDereferenceable(MDNode *A, MDNode *B) { |
1358 | 1396 | if (!A || !B) |
1359 | 1397 | return nullptr; |
|
0 commit comments