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

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 for patch set 1. 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 Stream << "??";
jvoung (off chromium) 2014/02/06 20:37:19 This shouldn't be possible right?
Karl 2014/02/07 19:37:29 Yes. Adding assert to cause failure.
42 break;
43 }
44 } else {
45 Stream << "??";
jvoung (off chromium) 2014/02/06 20:37:19 Should be impossible?
Karl 2014/02/07 19:37:29 Yes. Adding assert to cause failure.
46 }
47 }
48
49 static void PrintExpression(raw_ostream &Stream,
50 const NaClBitCodeAbbrev *Abbrev,
51 unsigned &Index) {
52 // Bail out early, in case we are incrementally building the
53 // expression and the argument is not available yet.
54 if (Index >= Abbrev->getNumOperandInfos()) return;
55
56 const NaClBitCodeAbbrevOp &Op = Abbrev->getOperandInfo(Index);
57 Op.Print(Stream);
58 if (unsigned NumArgs = Op.NumArguments()) {
59 Stream << "(";
60 for (unsigned i = 0; i < NumArgs; ++i) {
61 ++Index;
62 if (i > 0) Stream << ",";
63 PrintExpression(Stream, Abbrev, Index);
64 }
65 Stream << ")";
66 }
67 }
68
69 void NaClBitCodeAbbrev::Print(raw_ostream &Stream) const {
70 Stream << "[";
71 for (unsigned i = 0; i < getNumOperandInfos(); ++i) {
72 if (i > 0) Stream << ", ";
73 PrintExpression(Stream, this, i);
74 }
75 Stream << "]\n";
76 }
77
78 NaClBitCodeAbbrev *NaClBitCodeAbbrev::Simplify() const {
79 NaClBitCodeAbbrev *Abbrev = new NaClBitCodeAbbrev();
80 for (unsigned i = 0; i < OperandList.size(); ++i) {
81 const NaClBitCodeAbbrevOp &Op = OperandList[i];
82 // Simplify if possible. Currently, the only simplification known
83 // is to remove unnecessary operands appearing immediately before an
84 // array operator. That is, apply the simplification:
85 // Op Array(Op) -> Array(Op)
86 while (Abbrev->OperandList.size() >= 2
87 && Abbrev->OperandList.back().isArrayOp()
jvoung (off chromium) 2014/02/06 20:37:19 How can the NaClBitCodeAbbrevOp::Array be the last
Karl 2014/02/07 19:37:29 This is a nested loop, where we are incrementally
jvoung (off chromium) 2014/02/07 21:34:10 Ah, I mixed up the "this" Abbrev and the new Abbre
88 && Abbrev->OperandList[Abbrev->OperandList.size()-2] == Op) {
89 Abbrev->OperandList.pop_back();
90 Abbrev->OperandList.pop_back();
91 Abbrev->OperandList.push_back(
92 NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array));
93 }
94 Abbrev->OperandList.push_back(Op);
95 }
96 return Abbrev;
97 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698