diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2012-03-24 00:14:51 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2012-03-24 00:14:51 +0000 |
commit | 39dd328ed0892e063d02768336c4b792c925cdc3 (patch) | |
tree | aa22c2c837d8e0dd7d4cc7747d37d37f2235bd73 /lib/VMCore | |
parent | 1db394921b9635980555cc8d7e0d05b5e885784f (diff) | |
download | external_llvm-39dd328ed0892e063d02768336c4b792c925cdc3.zip external_llvm-39dd328ed0892e063d02768336c4b792c925cdc3.tar.gz external_llvm-39dd328ed0892e063d02768336c4b792c925cdc3.tar.bz2 |
First part of PR12251. Add documentation and verifier support for the range
metadata.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153359 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/LLVMContext.cpp | 5 | ||||
-rw-r--r-- | lib/VMCore/Verifier.cpp | 24 |
2 files changed, 29 insertions, 0 deletions
diff --git a/lib/VMCore/LLVMContext.cpp b/lib/VMCore/LLVMContext.cpp index d77e996..68c5621 100644 --- a/lib/VMCore/LLVMContext.cpp +++ b/lib/VMCore/LLVMContext.cpp @@ -48,6 +48,11 @@ LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl(*this)) { unsigned FPAccuracyID = getMDKindID("fpaccuracy"); assert(FPAccuracyID == MD_fpaccuracy && "fpaccuracy kind id drifted"); (void)FPAccuracyID; + + // Create the 'range' metadata kind. + unsigned RangeID = getMDKindID("range"); + assert(RangeID == MD_range && "range kind id drifted"); + (void)RangeID; } LLVMContext::~LLVMContext() { delete pImpl; } diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index 5b9b2a5..f62441b 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -51,6 +51,7 @@ #include "llvm/DerivedTypes.h" #include "llvm/InlineAsm.h" #include "llvm/IntrinsicInst.h" +#include "llvm/LLVMContext.h" #include "llvm/Metadata.h" #include "llvm/Module.h" #include "llvm/Pass.h" @@ -1369,6 +1370,25 @@ void Verifier::visitLoadInst(LoadInst &LI) { Assert1(LI.getSynchScope() == CrossThread, "Non-atomic load cannot have SynchronizationScope specified", &LI); } + + if (MDNode *Range = LI.getMetadata(LLVMContext::MD_range)) { + unsigned NumOperands = Range->getNumOperands(); + Assert1(NumOperands % 2 == 0, "Unfinished range!", Range); + unsigned NumRanges = NumOperands / 2; + Assert1(NumRanges >= 1, "It should have at least one range!", Range); + for (unsigned i = 0; i < NumRanges; ++i) { + ConstantInt *Low = dyn_cast<ConstantInt>(Range->getOperand(2*i)); + Assert1(Low, "The lower limit must be an integer!", Low); + ConstantInt *High = dyn_cast<ConstantInt>(Range->getOperand(2*i + 1)); + Assert1(High, "The upper limit must be an integer!", High); + Assert1(High->getType() == Low->getType() && + High->getType() == ElTy, "Range types must match load type!", + &LI); + Assert1(High->getValue() != Low->getValue(), "Range must not be empty!", + Range); + } + } + visitInstruction(LI); } @@ -1641,6 +1661,10 @@ void Verifier::visitInstruction(Instruction &I) { "Cannot take the address of an inline asm!", &I); } } + + MDNode *MD = I.getMetadata(LLVMContext::MD_range); + Assert1(!MD || isa<LoadInst>(I), "Ranges are only for loads!", &I); + InstsInThisBlock.insert(&I); } |