Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: lib/Bitcode/NaCl/Reader/NaClBitCodes.cpp

Issue 154603002: Make pnacl-bccompress add abbreviations for obvious constants. (Closed) Base URL: http://git.chromium.org/native_client/pnacl-llvm.git@master
Patch Set: Fixs nits associated with Patch Set 4. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/Bitcode/NaCl/Reader/CMakeLists.txt ('k') | lib/Bitcode/NaCl/Reader/NaClBitcodeDist.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 //===- NaClBitcodeHeader.cpp ----------------------------------------------===//
2 // PNaCl bitcode header reader.
3 //
4 // The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10 //
11 // Implementation of Bitcode abbrevations.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "llvm/Bitcode/NaCl/NaClBitCodes.h"
16 #include "llvm/Support/raw_ostream.h"
17 #include "llvm/Support/ErrorHandling.h"
18
19 using namespace llvm;
20
21 void NaClBitCodeAbbrevOp::Print(raw_ostream& Stream) const {
22 if (isLiteral()) {
23 Stream << getLiteralValue();
24 } else if (isEncoding()) {
25 switch (getEncoding()) {
26 case Fixed:
27 Stream << "Fixed(" << getEncodingData() << ")";
28 break;
29 case VBR:
30 Stream << "VBR(" << getEncodingData() << ")";
31 break;
32 case Array:
33 Stream << "Array";
34 break;
35 case Char6:
36 Stream << "Char6";
37 break;
38 case Blob:
39 Stream << "Blob";
40 break;
41 default:
42 llvm_unreachable("Unknown bitcode abbreviation operator");
43 Stream << "??"; // In case asserts are turned off.
44 break;
45 }
46 } else {
47 llvm_unreachable("Unknown bitcode abbreviation operator");
48 Stream << "??"; // In case asserts are turned off.
49 }
50 }
51
52 static void PrintExpression(raw_ostream &Stream,
53 const NaClBitCodeAbbrev *Abbrev,
54 unsigned &Index) {
55 // Bail out early, in case we are incrementally building the
56 // expression and the argument is not available yet.
57 if (Index >= Abbrev->getNumOperandInfos()) return;
58
59 const NaClBitCodeAbbrevOp &Op = Abbrev->getOperandInfo(Index);
60 Op.Print(Stream);
61 if (unsigned NumArgs = Op.NumArguments()) {
62 Stream << "(";
63 for (unsigned i = 0; i < NumArgs; ++i) {
64 ++Index;
65 if (i > 0) Stream << ",";
66 PrintExpression(Stream, Abbrev, Index);
67 }
68 Stream << ")";
69 }
70 }
71
72 void NaClBitCodeAbbrev::Print(raw_ostream &Stream) const {
73 Stream << "[";
74 for (unsigned i = 0; i < getNumOperandInfos(); ++i) {
75 if (i > 0) Stream << ", ";
76 PrintExpression(Stream, this, i);
77 }
78 Stream << "]\n";
79 }
80
81 NaClBitCodeAbbrev *NaClBitCodeAbbrev::Simplify() const {
82 NaClBitCodeAbbrev *Abbrev = new NaClBitCodeAbbrev();
83 for (unsigned i = 0; i < OperandList.size(); ++i) {
84 const NaClBitCodeAbbrevOp &Op = OperandList[i];
85 // Simplify if possible. Currently, the only simplification known
86 // is to remove unnecessary operands appearing immediately before an
87 // array operator. That is, apply the simplification:
88 // Op Array(Op) -> Array(Op)
89 assert(!Op.isArrayOp() || i == OperandList.size()-2);
90 while (Op.isArrayOp() && !Abbrev->OperandList.empty() &&
91 Abbrev->OperandList.back() == OperandList[i+1]) {
92 Abbrev->OperandList.pop_back();
93 }
94 Abbrev->OperandList.push_back(Op);
95 }
96 return Abbrev;
97 }
OLDNEW
« no previous file with comments | « lib/Bitcode/NaCl/Reader/CMakeLists.txt ('k') | lib/Bitcode/NaCl/Reader/NaClBitcodeDist.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698