2
0

BitstreamReader.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. //===- BitstreamReader.cpp - BitstreamReader implementation ---------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #include "llvm/Bitcode/BitstreamReader.h"
  10. using namespace llvm;
  11. //===----------------------------------------------------------------------===//
  12. // BitstreamCursor implementation
  13. //===----------------------------------------------------------------------===//
  14. void BitstreamCursor::freeState() {
  15. // Free all the Abbrevs.
  16. CurAbbrevs.clear();
  17. // Free all the Abbrevs in the block scope.
  18. BlockScope.clear();
  19. }
  20. /// EnterSubBlock - Having read the ENTER_SUBBLOCK abbrevid, enter
  21. /// the block, and return true if the block has an error.
  22. bool BitstreamCursor::EnterSubBlock(unsigned BlockID, unsigned *NumWordsP) {
  23. // Save the current block's state on BlockScope.
  24. BlockScope.push_back(Block(CurCodeSize));
  25. BlockScope.back().PrevAbbrevs.swap(CurAbbrevs);
  26. // Add the abbrevs specific to this block to the CurAbbrevs list.
  27. if (const BitstreamReader::BlockInfo *Info =
  28. BitStream->getBlockInfo(BlockID)) {
  29. CurAbbrevs.insert(CurAbbrevs.end(), Info->Abbrevs.begin(),
  30. Info->Abbrevs.end());
  31. }
  32. // Get the codesize of this block.
  33. CurCodeSize = ReadVBR(bitc::CodeLenWidth);
  34. // We can't read more than MaxChunkSize at a time
  35. if (CurCodeSize > MaxChunkSize)
  36. return true;
  37. SkipToFourByteBoundary();
  38. unsigned NumWords = Read(bitc::BlockSizeWidth);
  39. if (NumWordsP) *NumWordsP = NumWords;
  40. // Validate that this block is sane.
  41. return CurCodeSize == 0 || AtEndOfStream();
  42. }
  43. static uint64_t readAbbreviatedField(BitstreamCursor &Cursor,
  44. const BitCodeAbbrevOp &Op) {
  45. assert(!Op.isLiteral() && "Not to be used with literals!");
  46. // Decode the value as we are commanded.
  47. switch (Op.getEncoding()) {
  48. case BitCodeAbbrevOp::Array:
  49. case BitCodeAbbrevOp::Blob:
  50. llvm_unreachable("Should not reach here");
  51. case BitCodeAbbrevOp::Fixed:
  52. assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize);
  53. return Cursor.Read((unsigned)Op.getEncodingData());
  54. case BitCodeAbbrevOp::VBR:
  55. assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize);
  56. return Cursor.ReadVBR64((unsigned)Op.getEncodingData());
  57. case BitCodeAbbrevOp::Char6:
  58. return BitCodeAbbrevOp::DecodeChar6(Cursor.Read(6));
  59. }
  60. llvm_unreachable("invalid abbreviation encoding");
  61. }
  62. static void skipAbbreviatedField(BitstreamCursor &Cursor,
  63. const BitCodeAbbrevOp &Op) {
  64. assert(!Op.isLiteral() && "Not to be used with literals!");
  65. // Decode the value as we are commanded.
  66. switch (Op.getEncoding()) {
  67. case BitCodeAbbrevOp::Array:
  68. case BitCodeAbbrevOp::Blob:
  69. llvm_unreachable("Should not reach here");
  70. case BitCodeAbbrevOp::Fixed:
  71. assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize);
  72. Cursor.Read((unsigned)Op.getEncodingData());
  73. break;
  74. case BitCodeAbbrevOp::VBR:
  75. assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize);
  76. Cursor.ReadVBR64((unsigned)Op.getEncodingData());
  77. break;
  78. case BitCodeAbbrevOp::Char6:
  79. Cursor.Read(6);
  80. break;
  81. }
  82. }
  83. /// skipRecord - Read the current record and discard it.
  84. void BitstreamCursor::skipRecord(unsigned AbbrevID) {
  85. // Skip unabbreviated records by reading past their entries.
  86. if (AbbrevID == bitc::UNABBREV_RECORD) {
  87. unsigned Code = ReadVBR(6);
  88. (void)Code;
  89. unsigned NumElts = ReadVBR(6);
  90. for (unsigned i = 0; i != NumElts; ++i)
  91. (void)ReadVBR64(6);
  92. return;
  93. }
  94. const BitCodeAbbrev *Abbv = getAbbrev(AbbrevID);
  95. for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) {
  96. const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
  97. if (Op.isLiteral())
  98. continue;
  99. if (Op.getEncoding() != BitCodeAbbrevOp::Array &&
  100. Op.getEncoding() != BitCodeAbbrevOp::Blob) {
  101. skipAbbreviatedField(*this, Op);
  102. continue;
  103. }
  104. if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
  105. // Array case. Read the number of elements as a vbr6.
  106. unsigned NumElts = ReadVBR(6);
  107. // Get the element encoding.
  108. assert(i+2 == e && "array op not second to last?");
  109. const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
  110. #if 1 // HLSL Change - Make skipping go brrrrrrrrrrr
  111. {
  112. const auto &Op = EltEnc;
  113. auto &Cursor = *this;
  114. auto CurBit = Cursor.GetCurrentBitNo();
  115. // Decode the value as we are commanded.
  116. switch (EltEnc.getEncoding()) {
  117. case BitCodeAbbrevOp::Array:
  118. case BitCodeAbbrevOp::Blob:
  119. llvm_unreachable("Should not reach here");
  120. case BitCodeAbbrevOp::Fixed:
  121. assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize);
  122. Cursor.JumpToBit(CurBit + NumElts * Op.getEncodingData());
  123. break;
  124. case BitCodeAbbrevOp::VBR:
  125. assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize);
  126. for (; NumElts; --NumElts)
  127. Cursor.ReadVBR64((unsigned)Op.getEncodingData());
  128. break;
  129. case BitCodeAbbrevOp::Char6:
  130. Cursor.JumpToBit(CurBit + NumElts * 6);
  131. break;
  132. }
  133. }
  134. #else
  135. // Read all the elements.
  136. for (; NumElts; --NumElts)
  137. skipAbbreviatedField(*this, EltEnc);
  138. #endif
  139. continue;
  140. }
  141. assert(Op.getEncoding() == BitCodeAbbrevOp::Blob);
  142. // Blob case. Read the number of bytes as a vbr6.
  143. unsigned NumElts = ReadVBR(6);
  144. SkipToFourByteBoundary(); // 32-bit alignment
  145. // Figure out where the end of this blob will be including tail padding.
  146. size_t NewEnd = GetCurrentBitNo()+((NumElts+3)&~3)*8;
  147. // If this would read off the end of the bitcode file, just set the
  148. // record to empty and return.
  149. if (!canSkipToPos(NewEnd/8)) {
  150. NextChar = BitStream->getBitcodeBytes().getExtent();
  151. break;
  152. }
  153. // Skip over the blob.
  154. JumpToBit(NewEnd);
  155. }
  156. }
  157. // HLSL Change - Begin
  158. unsigned BitstreamCursor::peekRecord(unsigned AbbrevID) {
  159. auto last_bit_pos = GetCurrentBitNo();
  160. if (AbbrevID == bitc::UNABBREV_RECORD) {
  161. unsigned Code = ReadVBR(6);
  162. this->JumpToBit(last_bit_pos);
  163. return Code;
  164. }
  165. const BitCodeAbbrev *Abbv = getAbbrev(AbbrevID);
  166. // Read the record code first.
  167. assert(Abbv->getNumOperandInfos() != 0 && "no record code in abbreviation?");
  168. const BitCodeAbbrevOp &CodeOp = Abbv->getOperandInfo(0);
  169. unsigned Code;
  170. if (CodeOp.isLiteral())
  171. Code = CodeOp.getLiteralValue();
  172. else {
  173. if (CodeOp.getEncoding() == BitCodeAbbrevOp::Array ||
  174. CodeOp.getEncoding() == BitCodeAbbrevOp::Blob)
  175. report_fatal_error("Abbreviation starts with an Array or a Blob");
  176. Code = readAbbreviatedField(*this, CodeOp);
  177. }
  178. this->JumpToBit(last_bit_pos);
  179. return Code;
  180. }
  181. template<typename T>
  182. void BitstreamCursor::AddRecordElements(BitCodeAbbrevOp::Encoding enc, uint64_t encData, unsigned NumElts, SmallVectorImpl<T> &Vals) {
  183. const unsigned size = (unsigned)encData;
  184. if (enc == BitCodeAbbrevOp::VBR) {
  185. assert((unsigned)encData <= MaxChunkSize);
  186. for (; NumElts; --NumElts) {
  187. Vals.push_back((T)ReadVBR64(size));
  188. }
  189. }
  190. else if (enc == BitCodeAbbrevOp::Char6) {
  191. assert((unsigned)encData <= MaxChunkSize);
  192. for (; NumElts; --NumElts) {
  193. Vals.push_back(BitCodeAbbrevOp::DecodeChar6(Read(6)));
  194. }
  195. }
  196. else {
  197. llvm_unreachable("Unknown kind of thing");
  198. }
  199. }
  200. // HLSL Change - End
  201. unsigned BitstreamCursor::readRecord(unsigned AbbrevID,
  202. SmallVectorImpl<uint64_t> &Vals,
  203. StringRef *Blob,
  204. SmallVectorImpl<uint8_t> *Uint8Vals // HLSL Change
  205. ) {
  206. if (AbbrevID == bitc::UNABBREV_RECORD) {
  207. unsigned Code = ReadVBR(6);
  208. unsigned NumElts = ReadVBR(6);
  209. if (Uint8Vals) {
  210. for (unsigned i = 0; i != NumElts; ++i)
  211. Uint8Vals->push_back((uint8_t)ReadVBR64(6));
  212. }
  213. else {
  214. for (unsigned i = 0; i != NumElts; ++i)
  215. Vals.push_back(ReadVBR64(6));
  216. }
  217. return Code;
  218. }
  219. const BitCodeAbbrev *Abbv = getAbbrev(AbbrevID);
  220. // Read the record code first.
  221. assert(Abbv->getNumOperandInfos() != 0 && "no record code in abbreviation?");
  222. const BitCodeAbbrevOp &CodeOp = Abbv->getOperandInfo(0);
  223. unsigned Code;
  224. if (CodeOp.isLiteral())
  225. Code = CodeOp.getLiteralValue();
  226. else {
  227. if (CodeOp.getEncoding() == BitCodeAbbrevOp::Array ||
  228. CodeOp.getEncoding() == BitCodeAbbrevOp::Blob)
  229. report_fatal_error("Abbreviation starts with an Array or a Blob");
  230. Code = readAbbreviatedField(*this, CodeOp);
  231. }
  232. for (unsigned i = 1, e = Abbv->getNumOperandInfos(); i != e; ++i) {
  233. const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
  234. if (Op.isLiteral()) {
  235. Vals.push_back(Op.getLiteralValue());
  236. continue;
  237. }
  238. if (Op.getEncoding() != BitCodeAbbrevOp::Array &&
  239. Op.getEncoding() != BitCodeAbbrevOp::Blob) {
  240. Vals.push_back(readAbbreviatedField(*this, Op));
  241. continue;
  242. }
  243. if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
  244. // Array case. Read the number of elements as a vbr6.
  245. unsigned NumElts = ReadVBR(6);
  246. // Get the element encoding.
  247. if (i + 2 != e)
  248. report_fatal_error("Array op not second to last");
  249. const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
  250. if (!EltEnc.isEncoding())
  251. report_fatal_error(
  252. "Array element type has to be an encoding of a type");
  253. if (EltEnc.getEncoding() == BitCodeAbbrevOp::Array ||
  254. EltEnc.getEncoding() == BitCodeAbbrevOp::Blob)
  255. report_fatal_error("Array element type can't be an Array or a Blob");
  256. #if 1 // HLSL Change
  257. // Read all the elements a little faster.
  258. {
  259. BitCodeAbbrevOp::Encoding enc = EltEnc.getEncoding();
  260. uint64_t encData = 0;
  261. if (EltEnc.hasEncodingData())
  262. encData = EltEnc.getEncodingData();
  263. unsigned size = (unsigned)encData;
  264. if (Uint8Vals) {
  265. if (enc == BitCodeAbbrevOp::Fixed) {
  266. assert((unsigned)encData <= MaxChunkSize);
  267. assert((unsigned)encData == 8);
  268. // Special optimization for fixed elements that are 8 bits
  269. Uint8Vals->resize(NumElts);
  270. uint8_t *ptr = Uint8Vals->data();
  271. unsigned i = 0;
  272. constexpr unsigned BytesInWord = sizeof(size_t);
  273. // First, read word by word instead of byte by byte
  274. for (; NumElts >= BytesInWord; NumElts -= BytesInWord) {
  275. const size_t e = Read(BytesInWord * 8);
  276. memcpy(ptr + i, &e, sizeof(e));
  277. i += BytesInWord;
  278. }
  279. for (; NumElts; --NumElts)
  280. Uint8Vals->operator[](i++) = (uint8_t)Read(8);
  281. }
  282. else {
  283. AddRecordElements(enc, encData, NumElts, *Uint8Vals);
  284. }
  285. }
  286. else {
  287. if (enc == BitCodeAbbrevOp::Fixed) {
  288. assert((unsigned)encData <= MaxChunkSize);
  289. Vals.reserve(Vals.size() + NumElts);
  290. for (; NumElts; --NumElts)
  291. Vals.push_back(Read(size));
  292. }
  293. else {
  294. AddRecordElements(enc, encData, NumElts, Vals);
  295. }
  296. }
  297. }
  298. #else // HLSL Change
  299. // Read all the elements.
  300. for (; NumElts; --NumElts)
  301. Vals.push_back(readAbbreviatedField(*this, EltEnc));
  302. #endif // HLSL Change
  303. continue;
  304. }
  305. assert(Op.getEncoding() == BitCodeAbbrevOp::Blob);
  306. // Blob case. Read the number of bytes as a vbr6.
  307. unsigned NumElts = ReadVBR(6);
  308. SkipToFourByteBoundary(); // 32-bit alignment
  309. // Figure out where the end of this blob will be including tail padding.
  310. size_t CurBitPos = GetCurrentBitNo();
  311. size_t NewEnd = CurBitPos+((NumElts+3)&~3)*8;
  312. // If this would read off the end of the bitcode file, just set the
  313. // record to empty and return.
  314. if (!canSkipToPos(NewEnd/8)) {
  315. Vals.append(NumElts, 0);
  316. NextChar = BitStream->getBitcodeBytes().getExtent();
  317. break;
  318. }
  319. // Otherwise, inform the streamer that we need these bytes in memory.
  320. const char *Ptr = (const char*)
  321. BitStream->getBitcodeBytes().getPointer(CurBitPos/8, NumElts);
  322. // If we can return a reference to the data, do so to avoid copying it.
  323. if (Blob) {
  324. *Blob = StringRef(Ptr, NumElts);
  325. } else {
  326. // Otherwise, unpack into Vals with zero extension.
  327. for (; NumElts; --NumElts)
  328. Vals.push_back((unsigned char)*Ptr++);
  329. }
  330. // Skip over tail padding.
  331. JumpToBit(NewEnd);
  332. }
  333. return Code;
  334. }
  335. void BitstreamCursor::ReadAbbrevRecord() {
  336. BitCodeAbbrev *Abbv = new BitCodeAbbrev();
  337. unsigned NumOpInfo = ReadVBR(5);
  338. for (unsigned i = 0; i != NumOpInfo; ++i) {
  339. bool IsLiteral = Read(1);
  340. if (IsLiteral) {
  341. Abbv->Add(BitCodeAbbrevOp(ReadVBR64(8)));
  342. continue;
  343. }
  344. BitCodeAbbrevOp::Encoding E = (BitCodeAbbrevOp::Encoding)Read(3);
  345. if (BitCodeAbbrevOp::hasEncodingData(E)) {
  346. uint64_t Data = ReadVBR64(5);
  347. // As a special case, handle fixed(0) (i.e., a fixed field with zero bits)
  348. // and vbr(0) as a literal zero. This is decoded the same way, and avoids
  349. // a slow path in Read() to have to handle reading zero bits.
  350. if ((E == BitCodeAbbrevOp::Fixed || E == BitCodeAbbrevOp::VBR) &&
  351. Data == 0) {
  352. Abbv->Add(BitCodeAbbrevOp(0));
  353. continue;
  354. }
  355. if ((E == BitCodeAbbrevOp::Fixed || E == BitCodeAbbrevOp::VBR) &&
  356. Data > MaxChunkSize)
  357. report_fatal_error(
  358. "Fixed or VBR abbrev record with size > MaxChunkData");
  359. Abbv->Add(BitCodeAbbrevOp(E, Data));
  360. } else
  361. Abbv->Add(BitCodeAbbrevOp(E));
  362. }
  363. if (Abbv->getNumOperandInfos() == 0)
  364. report_fatal_error("Abbrev record with no operands");
  365. CurAbbrevs.push_back(Abbv);
  366. }
  367. bool BitstreamCursor::ReadBlockInfoBlock(unsigned *pCount) {
  368. // If this is the second stream to get to the block info block, skip it.
  369. if (BitStream->hasBlockInfoRecords())
  370. return SkipBlock();
  371. if (EnterSubBlock(bitc::BLOCKINFO_BLOCK_ID)) return true;
  372. SmallVector<uint64_t, 64> Record;
  373. BitstreamReader::BlockInfo *CurBlockInfo = nullptr;
  374. // Read all the records for this module.
  375. while (1) {
  376. BitstreamEntry Entry = advanceSkippingSubblocks(AF_DontAutoprocessAbbrevs, pCount);
  377. switch (Entry.Kind) {
  378. case llvm::BitstreamEntry::SubBlock: // Handled for us already.
  379. case llvm::BitstreamEntry::Error:
  380. return true;
  381. case llvm::BitstreamEntry::EndBlock:
  382. return false;
  383. case llvm::BitstreamEntry::Record:
  384. // The interesting case.
  385. break;
  386. }
  387. // Read abbrev records, associate them with CurBID.
  388. if (Entry.ID == bitc::DEFINE_ABBREV) {
  389. if (!CurBlockInfo) return true;
  390. ReadAbbrevRecord();
  391. // ReadAbbrevRecord installs the abbrev in CurAbbrevs. Move it to the
  392. // appropriate BlockInfo.
  393. CurBlockInfo->Abbrevs.push_back(std::move(CurAbbrevs.back()));
  394. CurAbbrevs.pop_back();
  395. continue;
  396. }
  397. // Read a record.
  398. Record.clear();
  399. switch (readRecord(Entry.ID, Record)) {
  400. default: break; // Default behavior, ignore unknown content.
  401. case bitc::BLOCKINFO_CODE_SETBID:
  402. if (Record.size() < 1) return true;
  403. CurBlockInfo = &BitStream->getOrCreateBlockInfo((unsigned)Record[0]);
  404. break;
  405. case bitc::BLOCKINFO_CODE_BLOCKNAME: {
  406. if (!CurBlockInfo) return true;
  407. if (BitStream->isIgnoringBlockInfoNames()) break; // Ignore name.
  408. std::string Name;
  409. for (unsigned i = 0, e = Record.size(); i != e; ++i)
  410. Name += (char)Record[i];
  411. CurBlockInfo->Name = Name;
  412. break;
  413. }
  414. case bitc::BLOCKINFO_CODE_SETRECORDNAME: {
  415. if (!CurBlockInfo) return true;
  416. if (BitStream->isIgnoringBlockInfoNames()) break; // Ignore name.
  417. std::string Name;
  418. for (unsigned i = 1, e = Record.size(); i != e; ++i)
  419. Name += (char)Record[i];
  420. CurBlockInfo->RecordNames.push_back(std::make_pair((unsigned)Record[0],
  421. Name));
  422. break;
  423. }
  424. }
  425. }
  426. }
  427. // HLSL Change Starts
  428. void BitstreamUseTracker::track(BitstreamUseTracker *BT, uint64_t begin,
  429. uint64_t end) {
  430. if (BT)
  431. BT->insert(begin, end);
  432. }
  433. BitstreamUseTracker::ExtendResult
  434. BitstreamUseTracker::extendRange(UseRange &Curr, UseRange &NewRange) {
  435. // Most likely case first.
  436. if (Curr.first <= NewRange.first && Curr.second < NewRange.second) {
  437. Curr.second = NewRange.second;
  438. return ExtendedEnd;
  439. }
  440. if (Curr.first <= NewRange.first && NewRange.second <= Curr.second) {
  441. return Included; // already included.
  442. }
  443. if (NewRange.first < Curr.first && NewRange.second <= Curr.second) {
  444. return ExtendedBegin;
  445. }
  446. if (NewRange.first < Curr.first && Curr.second < NewRange.second) {
  447. return ExtendedBoth;
  448. }
  449. return Exclusive;
  450. }
  451. bool BitstreamUseTracker::isDense(uint64_t endBitoffset) const {
  452. return Ranges.size() == 1 && Ranges[0].first == 0 &&
  453. Ranges[0].second == endBitoffset;
  454. }
  455. bool BitstreamUseTracker::considerMergeRight(size_t idx) {
  456. bool changed = false;
  457. while (idx < Ranges.size() - 1) {
  458. if (Ranges[idx].second >= Ranges[idx + 1].first) {
  459. Ranges[idx].second = Ranges[idx + 1].second;
  460. Ranges.erase(&Ranges[idx + 1]);
  461. changed = true;
  462. }
  463. }
  464. return changed;
  465. }
  466. void BitstreamUseTracker::insert(uint64_t begin, uint64_t end) {
  467. UseRange IR(begin, end);
  468. for (size_t i = 0, E = Ranges.size(); i < E; ++i) {
  469. ExtendResult ER = extendRange(Ranges[i], IR);
  470. switch (ER) {
  471. case Included:
  472. return;
  473. case ExtendedEnd:
  474. considerMergeRight(i);
  475. return;
  476. case ExtendedBegin:
  477. if (i > 0)
  478. considerMergeRight(i - 1);
  479. return;
  480. case ExtendedBoth:
  481. if (i > 0) {
  482. if (!considerMergeRight(i - 1))
  483. considerMergeRight(i);
  484. } else
  485. considerMergeRight(i);
  486. return;
  487. case Exclusive:
  488. // If completely to the left, then insert there; otherwise,
  489. // keep traversing in order.
  490. if (end <= Ranges[i].first) {
  491. Ranges.insert(&Ranges[i], IR);
  492. return;
  493. }
  494. }
  495. }
  496. // This range goes at the end.
  497. Ranges.push_back(IR);
  498. }
  499. BitstreamUseTracker::ScopeTrack
  500. BitstreamUseTracker::scope_track(BitstreamCursor *BC) {
  501. ScopeTrack Result;
  502. Result.BC = BC;
  503. Result.begin = BC->GetCurrentBitNo();
  504. return Result;
  505. }
  506. // HLSL Change Ends