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

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: Fix issues raised in Patch Set 1 and 2. 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
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
18 using namespace llvm;
19
20 void NaClBitCodeAbbrevOp::Print(raw_ostream& Stream) const {
21 if (isLiteral()) {
22 Stream << getLiteralValue();
23 } else if (isEncoding()) {
24 switch (getEncoding()) {
25 case Fixed:
26 Stream << "Fixed(" << getEncodingData() << ")";
27 break;
28 case VBR:
29 Stream << "VBR(" << getEncodingData() << ")";
30 break;
31 case Array:
32 Stream << "Array";
33 break;
34 case Char6:
35 Stream << "Char6";
36 break;
37 case Blob:
38 Stream << "Blob";
39 break;
40 default:
41 assert(false);
jvoung (off chromium) 2014/02/07 21:34:10 llvm_unreachable("...") instead ?
Karl 2014/02/07 23:26:04 Done.
42 Stream << "??"; // In case asserts are turned off.
43 break;
44 }
45 } else {
46 assert(false);
47 Stream << "??"; // In case asserts are turned off.
48 }
49 }
50
51 static void PrintExpression(raw_ostream &Stream,
52 const NaClBitCodeAbbrev *Abbrev,
53 unsigned &Index) {
54 // Bail out early, in case we are incrementally building the
55 // expression and the argument is not available yet.
56 if (Index >= Abbrev->getNumOperandInfos()) return;
57
58 const NaClBitCodeAbbrevOp &Op = Abbrev->getOperandInfo(Index);
59 Op.Print(Stream);
60 if (unsigned NumArgs = Op.NumArguments()) {
61 Stream << "(";
62 for (unsigned i = 0; i < NumArgs; ++i) {
63 ++Index;
64 if (i > 0) Stream << ",";
65 PrintExpression(Stream, Abbrev, Index);
66 }
67 Stream << ")";
68 }
69 }
70
71 void NaClBitCodeAbbrev::Print(raw_ostream &Stream) const {
72 Stream << "[";
73 for (unsigned i = 0; i < getNumOperandInfos(); ++i) {
74 if (i > 0) Stream << ", ";
75 PrintExpression(Stream, this, i);
76 }
77 Stream << "]\n";
78 }
79
80 NaClBitCodeAbbrev *NaClBitCodeAbbrev::Simplify() const {
81 NaClBitCodeAbbrev *Abbrev = new NaClBitCodeAbbrev();
82 for (unsigned i = 0; i < OperandList.size(); ++i) {
83 const NaClBitCodeAbbrevOp &Op = OperandList[i];
84 // Simplify if possible. Currently, the only simplification known
85 // is to remove unnecessary operands appearing immediately before an
86 // array operator. That is, apply the simplification:
87 // Op Array(Op) -> Array(Op)
jvoung (off chromium) 2014/02/07 21:34:10 perhaps check if that the abbrev is well formed:
Karl 2014/02/07 23:26:04 Done.
88 while (Op.isArrayOp() && !Abbrev->OperandList.empty() &&
89 Abbrev->OperandList.back() == OperandList[i+1]) {
90 Abbrev->OperandList.pop_back();
91 }
92 Abbrev->OperandList.push_back(Op);
93 }
94 return Abbrev;
95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698