From 484fc93eff0295b1aa52b9a64d22346580e4b0e2 Mon Sep 17 00:00:00 2001 From: Stepan Dyatkovskiy Date: Mon, 28 May 2012 12:39:09 +0000 Subject: PR1255: Case Ranges Implemented IntItem - the wrapper around APInt. Why not to use APInt item directly right now? 1. It will very difficult to implement case ranges as series of small patches. We got several large and heavy patches. Each patch will about 90-120 kb. If you replace ConstantInt with APInt in SwitchInst you will need to changes at the same time all Readers,Writers and absolutely all passes that uses SwitchInst. 2. We can implement APInt pool inside and save memory space. E.g. we use several switches that works with 256 bit items (switch on signatures, or strings). We can avoid value duplicates in this case. 3. IntItem can be easyly easily replaced with APInt. 4. Currenly we can interpret IntItem both as ConstantInt and as APInt. It allows to provide SwitchInst methods that works with ConstantInt for non-updated passes. Why I need it right now? Currently I need to update SimplifyCFG pass (EqualityComparisons). I need to work with APInts directly a lot, so peaces of code ConstantInt *V = ...; if (V->getValue().ugt(AnotherV->getValue()) { ... } will look awful. Much more better this way: IntItem V = ConstantIntVal->getValue(); if (AnotherV < V) { } Of course any reviews are welcome. P.S.: I'm also going to rename ConstantRangesSet to IntegersSubset, and CRSBuilder to IntegersSubsetMapping (allows to map individual subsets of integers to the BasicBlocks). Since in future these classes will founded on APInt, it will possible to use them in more generic ways. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@157576 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Bitcode/Reader/BitcodeReader.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'lib/Bitcode/Reader') diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 5a132a4..3477bbc 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2283,18 +2283,21 @@ bool BitcodeReader::ParseFunctionBody(Function *F) { ActiveWords = Record[CurIdx++]; Low = ReadWideAPInt(&Record[CurIdx], ActiveWords, ValueBitWidth); CurIdx += ActiveWords; - + if (!isSingleNumber) { ActiveWords = 1; if (ValueBitWidth > 64) ActiveWords = Record[CurIdx++]; APInt High = ReadWideAPInt(&Record[CurIdx], ActiveWords, ValueBitWidth); - CaseBuilder.add(cast(ConstantInt::get(OpTy, Low)), - cast(ConstantInt::get(OpTy, High))); + IntItemConstantIntImpl HighImpl = + cast(ConstantInt::get(OpTy, High)); + + CaseBuilder.add(IntItem::fromType(OpTy, Low), + IntItem::fromType(OpTy, High)); CurIdx += ActiveWords; } else - CaseBuilder.add(cast(ConstantInt::get(OpTy, Low))); + CaseBuilder.add(IntItem::fromType(OpTy, Low)); } BasicBlock *DestBB = getBasicBlock(Record[CurIdx++]); ConstantRangesSet Case = CaseBuilder.getCase(); -- cgit v1.1