OLD | NEW |
1 //===- subzero/src/llvm2ice.cpp - Driver for testing ----------------------===// | 1 //===- subzero/src/llvm2ice.cpp - Driver for testing ----------------------===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file defines a driver that uses LLVM capabilities to parse a | 10 // This file defines a driver that uses LLVM capabilities to parse a |
11 // bitcode file and build the LLVM IR, and then convert the LLVM basic | 11 // bitcode file and build the LLVM IR, and then convert the LLVM basic |
12 // blocks, instructions, and operands into their Subzero equivalents. | 12 // blocks, instructions, and operands into their Subzero equivalents. |
13 // | 13 // |
14 //===----------------------------------------------------------------------===// | 14 //===----------------------------------------------------------------------===// |
15 | 15 |
16 #include "IceCfg.h" | 16 #include "IceCfg.h" |
17 #include "IceClFlags.h" | 17 #include "IceClFlags.h" |
18 #include "IceConverter.h" | 18 #include "IceConverter.h" |
19 #include "IceDefs.h" | |
20 #include "IceTargetLowering.h" | |
21 #include "IceTypes.h" | |
22 #include "PNaClTranslator.h" | 19 #include "PNaClTranslator.h" |
23 | 20 |
24 #include "llvm/IR/Constants.h" | |
25 #include "llvm/IR/LLVMContext.h" | 21 #include "llvm/IR/LLVMContext.h" |
26 #include "llvm/IR/Module.h" | |
27 #include "llvm/IRReader/IRReader.h" | 22 #include "llvm/IRReader/IRReader.h" |
28 #include "llvm/Support/CommandLine.h" | 23 #include "llvm/Support/CommandLine.h" |
29 #include "llvm/Support/raw_os_ostream.h" | 24 #include "llvm/Support/raw_os_ostream.h" |
30 #include "llvm/Support/SourceMgr.h" | 25 #include "llvm/Support/SourceMgr.h" |
31 | 26 |
32 #include <fstream> | 27 #include <fstream> |
33 #include <iostream> | 28 #include <iostream> |
34 | 29 |
35 using namespace llvm; | 30 using namespace llvm; |
36 | 31 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix); | 125 Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix); |
131 | 126 |
132 Ice::ClFlags Flags; | 127 Ice::ClFlags Flags; |
133 Flags.DisableInternal = DisableInternal; | 128 Flags.DisableInternal = DisableInternal; |
134 Flags.SubzeroTimingEnabled = SubzeroTimingEnabled; | 129 Flags.SubzeroTimingEnabled = SubzeroTimingEnabled; |
135 Flags.DisableTranslation = DisableTranslation; | 130 Flags.DisableTranslation = DisableTranslation; |
136 | 131 |
137 if (BuildOnRead) { | 132 if (BuildOnRead) { |
138 Ice::PNaClTranslator Translator(&Ctx, Flags); | 133 Ice::PNaClTranslator Translator(&Ctx, Flags); |
139 Translator.translate(IRFilename); | 134 Translator.translate(IRFilename); |
140 return Translator.getExitStatus(); | 135 return Translator.getErrorStatus(); |
141 } else { | 136 } else { |
142 // Parse the input LLVM IR file into a module. | 137 // Parse the input LLVM IR file into a module. |
143 SMDiagnostic Err; | 138 SMDiagnostic Err; |
144 Ice::Timer T; | 139 Ice::Timer T; |
145 Module *Mod = | 140 Module *Mod = |
146 NaClParseIRFile(IRFilename, InputFileFormat, Err, getGlobalContext()); | 141 NaClParseIRFile(IRFilename, InputFileFormat, Err, getGlobalContext()); |
147 | 142 |
148 if (SubzeroTimingEnabled) { | 143 if (SubzeroTimingEnabled) { |
149 std::cerr << "[Subzero timing] IR Parsing: " << T.getElapsedSec() | 144 std::cerr << "[Subzero timing] IR Parsing: " << T.getElapsedSec() |
150 << " sec\n"; | 145 << " sec\n"; |
151 } | 146 } |
152 | 147 |
153 if (!Mod) { | 148 if (!Mod) { |
154 Err.print(argv[0], errs()); | 149 Err.print(argv[0], errs()); |
155 return 1; | 150 return 1; |
156 } | 151 } |
157 | 152 |
158 // TODO(stichnot): Move this into IceConverter.cpp. | |
159 OwningPtr<Ice::TargetGlobalInitLowering> GlobalLowering( | |
160 Ice::TargetGlobalInitLowering::createLowering(TargetArch, &Ctx)); | |
161 for (Module::const_global_iterator I = Mod->global_begin(), | |
162 E = Mod->global_end(); | |
163 I != E; ++I) { | |
164 if (!I->hasInitializer()) | |
165 continue; | |
166 const Constant *Initializer = I->getInitializer(); | |
167 Ice::IceString Name = I->getName(); | |
168 unsigned Align = I->getAlignment(); | |
169 uint64_t NumElements = 0; | |
170 const char *Data = NULL; | |
171 bool IsInternal = I->hasInternalLinkage(); | |
172 bool IsConst = I->isConstant(); | |
173 bool IsZeroInitializer = false; | |
174 | |
175 if (const ConstantDataArray *CDA = | |
176 dyn_cast<ConstantDataArray>(Initializer)) { | |
177 NumElements = CDA->getNumElements(); | |
178 assert(isa<IntegerType>(CDA->getElementType()) && | |
179 cast<IntegerType>(CDA->getElementType())->getBitWidth() == 8); | |
180 Data = CDA->getRawDataValues().data(); | |
181 } else if (isa<ConstantAggregateZero>(Initializer)) { | |
182 if (const ArrayType *AT = dyn_cast<ArrayType>(Initializer->getType())) { | |
183 assert(isa<IntegerType>(AT->getElementType()) && | |
184 cast<IntegerType>(AT->getElementType())->getBitWidth() == 8); | |
185 NumElements = AT->getNumElements(); | |
186 IsZeroInitializer = true; | |
187 } else { | |
188 llvm_unreachable("Unhandled constant aggregate zero type"); | |
189 } | |
190 } else { | |
191 llvm_unreachable("Unhandled global initializer"); | |
192 } | |
193 | |
194 GlobalLowering->lower(Name, Align, IsInternal, IsConst, IsZeroInitializer, | |
195 NumElements, Data, DisableTranslation); | |
196 } | |
197 GlobalLowering.reset(); | |
198 | |
199 Ice::Converter Converter(&Ctx, Flags); | 153 Ice::Converter Converter(&Ctx, Flags); |
200 return Converter.convertToIce(Mod); | 154 Converter.convertToIce(Mod); |
| 155 return Converter.getErrorStatus(); |
201 } | 156 } |
202 } | 157 } |
OLD | NEW |