blob: 9e003ef8b68edc215aad5cf9248622ea9165aa4f [file] [log] [blame]
Karl Schimpfe1e013c2014-06-27 09:15:29 -07001//===- subzero/src/IceConverter.cpp - Converts LLVM to Ice ---------------===//
2//
3// The Subzero Code Generator
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the LLVM to ICE converter.
11//
12//===----------------------------------------------------------------------===//
13
Jim Stichnotha18cc9c2014-09-30 19:10:22 -070014#include <iostream>
15
16#include "llvm/IR/Constant.h"
17#include "llvm/IR/Constants.h"
18#include "llvm/IR/DataLayout.h"
19#include "llvm/IR/Instruction.h"
20#include "llvm/IR/Instructions.h"
21#include "llvm/IR/LLVMContext.h"
22#include "llvm/IR/Module.h"
23
Karl Schimpfe1e013c2014-06-27 09:15:29 -070024#include "IceCfg.h"
25#include "IceCfgNode.h"
Karl Schimpf8d7abae2014-07-07 14:50:30 -070026#include "IceClFlags.h"
Jim Stichnothc4554d72014-09-30 16:49:38 -070027#include "IceConverter.h"
Karl Schimpfe1e013c2014-06-27 09:15:29 -070028#include "IceDefs.h"
29#include "IceGlobalContext.h"
Karl Schimpfe3f64d02014-10-07 10:38:22 -070030#include "IceGlobalInits.h"
Karl Schimpfe1e013c2014-06-27 09:15:29 -070031#include "IceInst.h"
32#include "IceOperand.h"
Karl Schimpfb164d202014-07-11 10:26:34 -070033#include "IceTargetLowering.h"
Karl Schimpfe1e013c2014-06-27 09:15:29 -070034#include "IceTypes.h"
Karl Schimpfd6064a12014-08-27 15:34:58 -070035#include "IceTypeConverter.h"
Karl Schimpfe1e013c2014-06-27 09:15:29 -070036
Karl Schimpf9d98d792014-10-13 15:01:08 -070037// TODO(kschimpf): Remove two namespaces being visible at once.
Karl Schimpfe1e013c2014-06-27 09:15:29 -070038using namespace llvm;
39
40namespace {
41
42// Debugging helper
43template <typename T> static std::string LLVMObjectAsString(const T *O) {
44 std::string Dump;
45 raw_string_ostream Stream(Dump);
46 O->print(Stream);
47 return Stream.str();
48}
49
Karl Schimpfe3f64d02014-10-07 10:38:22 -070050// Base class for converting LLVM to ICE.
Karl Schimpfe1e013c2014-06-27 09:15:29 -070051class LLVM2ICEConverter {
Karl Schimpfe3f64d02014-10-07 10:38:22 -070052 LLVM2ICEConverter(const LLVM2ICEConverter &) = delete;
53 LLVM2ICEConverter &operator=(const LLVM2ICEConverter &) = delete;
54
Karl Schimpfe1e013c2014-06-27 09:15:29 -070055public:
Karl Schimpf9d98d792014-10-13 15:01:08 -070056 LLVM2ICEConverter(Ice::Converter &Converter)
57 : Converter(Converter), Ctx(Converter.getContext()),
58 TypeConverter(Converter.getModule()->getContext()) {}
59
60 Ice::Converter &getConverter() const { return Converter; }
Karl Schimpfe3f64d02014-10-07 10:38:22 -070061
62protected:
Karl Schimpf9d98d792014-10-13 15:01:08 -070063 Ice::Converter &Converter;
Karl Schimpfe3f64d02014-10-07 10:38:22 -070064 Ice::GlobalContext *Ctx;
65 const Ice::TypeConverter TypeConverter;
66};
67
68// Converter from LLVM functions to ICE. The entry point is the
69// convertFunction method.
70//
71// Note: this currently assumes that the given IR was verified to be
72// valid PNaCl bitcode. Otherwise, the behavior is undefined.
73class LLVM2ICEFunctionConverter : LLVM2ICEConverter {
74 LLVM2ICEFunctionConverter(const LLVM2ICEFunctionConverter &) = delete;
75 LLVM2ICEFunctionConverter &
76 operator=(const LLVM2ICEFunctionConverter &) = delete;
77
78public:
Karl Schimpf9d98d792014-10-13 15:01:08 -070079 LLVM2ICEFunctionConverter(Ice::Converter &Converter)
80 : LLVM2ICEConverter(Converter), Func(nullptr) {}
Karl Schimpfe1e013c2014-06-27 09:15:29 -070081
82 // Caller is expected to delete the returned Ice::Cfg object.
83 Ice::Cfg *convertFunction(const Function *F) {
84 VarMap.clear();
85 NodeMap.clear();
86 Func = new Ice::Cfg(Ctx);
87 Func->setFunctionName(F->getName());
Karl Schimpfd6064a12014-08-27 15:34:58 -070088 Func->setReturnType(convertToIceType(F->getReturnType()));
Karl Schimpfe1e013c2014-06-27 09:15:29 -070089 Func->setInternal(F->hasInternalLinkage());
Jim Stichnoth8363a062014-10-07 10:02:38 -070090 Ice::TimerMarker T(Ice::TimerStack::TT_llvmConvert, Func);
Karl Schimpfe1e013c2014-06-27 09:15:29 -070091
92 // The initial definition/use of each arg is the entry node.
Jim Stichnothf44f3712014-10-01 14:05:51 -070093 for (auto ArgI = F->arg_begin(), ArgE = F->arg_end(); ArgI != ArgE;
94 ++ArgI) {
Karl Schimpfe1e013c2014-06-27 09:15:29 -070095 Func->addArg(mapValueToIceVar(ArgI));
96 }
97
98 // Make an initial pass through the block list just to resolve the
99 // blocks in the original linearized order. Otherwise the ICE
100 // linearized order will be affected by branch targets in
101 // terminator instructions.
Jim Stichnothf44f3712014-10-01 14:05:51 -0700102 for (const BasicBlock &BBI : *F)
103 mapBasicBlockToNode(&BBI);
104 for (const BasicBlock &BBI : *F)
105 convertBasicBlock(&BBI);
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700106 Func->setEntryNode(mapBasicBlockToNode(&F->getEntryBlock()));
107 Func->computePredecessors();
108
109 return Func;
110 }
111
112 // convertConstant() does not use Func or require it to be a valid
113 // Ice::Cfg pointer. As such, it's suitable for e.g. constructing
114 // global initializers.
115 Ice::Constant *convertConstant(const Constant *Const) {
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700116 if (const auto GV = dyn_cast<GlobalValue>(Const)) {
Karl Schimpfdf6f9d12014-10-20 14:09:00 -0700117 Ice::GlobalDeclaration *Decl = getConverter().getGlobalDeclaration(GV);
118 const Ice::RelocOffsetT Offset = 0;
Jim Stichnothd2cb4362014-11-20 11:24:42 -0800119 return Ctx->getConstantSym(Offset, Decl->getName(),
Karl Schimpfdf6f9d12014-10-20 14:09:00 -0700120 Decl->getSuppressMangling());
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700121 } else if (const auto CI = dyn_cast<ConstantInt>(Const)) {
Jan Voungbc004632014-09-16 15:09:10 -0700122 Ice::Type Ty = convertToIceType(CI->getType());
Jim Stichnothd2cb4362014-11-20 11:24:42 -0800123 return Ctx->getConstantInt(Ty, CI->getSExtValue());
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700124 } else if (const auto CFP = dyn_cast<ConstantFP>(Const)) {
Karl Schimpfd6064a12014-08-27 15:34:58 -0700125 Ice::Type Type = convertToIceType(CFP->getType());
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700126 if (Type == Ice::IceType_f32)
127 return Ctx->getConstantFloat(CFP->getValueAPF().convertToFloat());
128 else if (Type == Ice::IceType_f64)
129 return Ctx->getConstantDouble(CFP->getValueAPF().convertToDouble());
130 llvm_unreachable("Unexpected floating point type");
Karl Schimpf9d98d792014-10-13 15:01:08 -0700131 return nullptr;
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700132 } else if (const auto CU = dyn_cast<UndefValue>(Const)) {
Karl Schimpfd6064a12014-08-27 15:34:58 -0700133 return Ctx->getConstantUndef(convertToIceType(CU->getType()));
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700134 } else {
135 llvm_unreachable("Unhandled constant type");
Karl Schimpf9d98d792014-10-13 15:01:08 -0700136 return nullptr;
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700137 }
138 }
139
140private:
141 // LLVM values (instructions, etc.) are mapped directly to ICE variables.
142 // mapValueToIceVar has a version that forces an ICE type on the variable,
Karl Schimpfd6064a12014-08-27 15:34:58 -0700143 // and a version that just uses convertToIceType on V.
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700144 Ice::Variable *mapValueToIceVar(const Value *V, Ice::Type IceTy) {
145 if (IceTy == Ice::IceType_void)
Karl Schimpf9d98d792014-10-13 15:01:08 -0700146 return nullptr;
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700147 if (VarMap.find(V) == VarMap.end()) {
Jim Stichnoth9a04c072014-12-11 15:51:42 -0800148 VarMap[V] = Func->makeVariable(IceTy);
149 if (ALLOW_DUMP)
150 VarMap[V]->setName(Func, V->getName());
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700151 }
152 return VarMap[V];
153 }
154
155 Ice::Variable *mapValueToIceVar(const Value *V) {
Karl Schimpfd6064a12014-08-27 15:34:58 -0700156 return mapValueToIceVar(V, convertToIceType(V->getType()));
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700157 }
158
159 Ice::CfgNode *mapBasicBlockToNode(const BasicBlock *BB) {
160 if (NodeMap.find(BB) == NodeMap.end()) {
Jim Stichnoth668a7a32014-12-10 15:32:25 -0800161 NodeMap[BB] = Func->makeNode();
162 if (ALLOW_DUMP)
163 NodeMap[BB]->setName(BB->getName());
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700164 }
165 return NodeMap[BB];
166 }
167
Karl Schimpfd6064a12014-08-27 15:34:58 -0700168 Ice::Type convertToIceType(Type *LLVMTy) const {
169 Ice::Type IceTy = TypeConverter.convertToIceType(LLVMTy);
170 if (IceTy == Ice::IceType_NUM)
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700171 report_fatal_error(std::string("Invalid PNaCl type ") +
172 LLVMObjectAsString(LLVMTy));
Karl Schimpfd6064a12014-08-27 15:34:58 -0700173 return IceTy;
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700174 }
175
176 // Given an LLVM instruction and an operand number, produce the
177 // Ice::Operand this refers to. If there's no such operand, return
Karl Schimpf9d98d792014-10-13 15:01:08 -0700178 // nullptr.
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700179 Ice::Operand *convertOperand(const Instruction *Inst, unsigned OpNum) {
180 if (OpNum >= Inst->getNumOperands()) {
Karl Schimpf9d98d792014-10-13 15:01:08 -0700181 return nullptr;
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700182 }
183 const Value *Op = Inst->getOperand(OpNum);
184 return convertValue(Op);
185 }
186
187 Ice::Operand *convertValue(const Value *Op) {
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700188 if (const auto Const = dyn_cast<Constant>(Op)) {
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700189 return convertConstant(Const);
190 } else {
191 return mapValueToIceVar(Op);
192 }
193 }
194
195 // Note: this currently assumes a 1x1 mapping between LLVM IR and Ice
196 // instructions.
197 Ice::Inst *convertInstruction(const Instruction *Inst) {
198 switch (Inst->getOpcode()) {
199 case Instruction::PHI:
200 return convertPHINodeInstruction(cast<PHINode>(Inst));
201 case Instruction::Br:
202 return convertBrInstruction(cast<BranchInst>(Inst));
203 case Instruction::Ret:
204 return convertRetInstruction(cast<ReturnInst>(Inst));
205 case Instruction::IntToPtr:
206 return convertIntToPtrInstruction(cast<IntToPtrInst>(Inst));
207 case Instruction::PtrToInt:
208 return convertPtrToIntInstruction(cast<PtrToIntInst>(Inst));
209 case Instruction::ICmp:
210 return convertICmpInstruction(cast<ICmpInst>(Inst));
211 case Instruction::FCmp:
212 return convertFCmpInstruction(cast<FCmpInst>(Inst));
213 case Instruction::Select:
214 return convertSelectInstruction(cast<SelectInst>(Inst));
215 case Instruction::Switch:
216 return convertSwitchInstruction(cast<SwitchInst>(Inst));
217 case Instruction::Load:
218 return convertLoadInstruction(cast<LoadInst>(Inst));
219 case Instruction::Store:
220 return convertStoreInstruction(cast<StoreInst>(Inst));
221 case Instruction::ZExt:
222 return convertCastInstruction(cast<ZExtInst>(Inst), Ice::InstCast::Zext);
223 case Instruction::SExt:
224 return convertCastInstruction(cast<SExtInst>(Inst), Ice::InstCast::Sext);
225 case Instruction::Trunc:
226 return convertCastInstruction(cast<TruncInst>(Inst),
227 Ice::InstCast::Trunc);
228 case Instruction::FPTrunc:
229 return convertCastInstruction(cast<FPTruncInst>(Inst),
230 Ice::InstCast::Fptrunc);
231 case Instruction::FPExt:
232 return convertCastInstruction(cast<FPExtInst>(Inst),
233 Ice::InstCast::Fpext);
234 case Instruction::FPToSI:
235 return convertCastInstruction(cast<FPToSIInst>(Inst),
236 Ice::InstCast::Fptosi);
237 case Instruction::FPToUI:
238 return convertCastInstruction(cast<FPToUIInst>(Inst),
239 Ice::InstCast::Fptoui);
240 case Instruction::SIToFP:
241 return convertCastInstruction(cast<SIToFPInst>(Inst),
242 Ice::InstCast::Sitofp);
243 case Instruction::UIToFP:
244 return convertCastInstruction(cast<UIToFPInst>(Inst),
245 Ice::InstCast::Uitofp);
246 case Instruction::BitCast:
247 return convertCastInstruction(cast<BitCastInst>(Inst),
248 Ice::InstCast::Bitcast);
249 case Instruction::Add:
250 return convertArithInstruction(Inst, Ice::InstArithmetic::Add);
251 case Instruction::Sub:
252 return convertArithInstruction(Inst, Ice::InstArithmetic::Sub);
253 case Instruction::Mul:
254 return convertArithInstruction(Inst, Ice::InstArithmetic::Mul);
255 case Instruction::UDiv:
256 return convertArithInstruction(Inst, Ice::InstArithmetic::Udiv);
257 case Instruction::SDiv:
258 return convertArithInstruction(Inst, Ice::InstArithmetic::Sdiv);
259 case Instruction::URem:
260 return convertArithInstruction(Inst, Ice::InstArithmetic::Urem);
261 case Instruction::SRem:
262 return convertArithInstruction(Inst, Ice::InstArithmetic::Srem);
263 case Instruction::Shl:
264 return convertArithInstruction(Inst, Ice::InstArithmetic::Shl);
265 case Instruction::LShr:
266 return convertArithInstruction(Inst, Ice::InstArithmetic::Lshr);
267 case Instruction::AShr:
268 return convertArithInstruction(Inst, Ice::InstArithmetic::Ashr);
269 case Instruction::FAdd:
270 return convertArithInstruction(Inst, Ice::InstArithmetic::Fadd);
271 case Instruction::FSub:
272 return convertArithInstruction(Inst, Ice::InstArithmetic::Fsub);
273 case Instruction::FMul:
274 return convertArithInstruction(Inst, Ice::InstArithmetic::Fmul);
275 case Instruction::FDiv:
276 return convertArithInstruction(Inst, Ice::InstArithmetic::Fdiv);
277 case Instruction::FRem:
278 return convertArithInstruction(Inst, Ice::InstArithmetic::Frem);
279 case Instruction::And:
280 return convertArithInstruction(Inst, Ice::InstArithmetic::And);
281 case Instruction::Or:
282 return convertArithInstruction(Inst, Ice::InstArithmetic::Or);
283 case Instruction::Xor:
284 return convertArithInstruction(Inst, Ice::InstArithmetic::Xor);
Matt Wala49889232014-07-18 12:45:09 -0700285 case Instruction::ExtractElement:
286 return convertExtractElementInstruction(cast<ExtractElementInst>(Inst));
287 case Instruction::InsertElement:
288 return convertInsertElementInstruction(cast<InsertElementInst>(Inst));
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700289 case Instruction::Call:
290 return convertCallInstruction(cast<CallInst>(Inst));
291 case Instruction::Alloca:
292 return convertAllocaInstruction(cast<AllocaInst>(Inst));
293 case Instruction::Unreachable:
294 return convertUnreachableInstruction(cast<UnreachableInst>(Inst));
295 default:
296 report_fatal_error(std::string("Invalid PNaCl instruction: ") +
297 LLVMObjectAsString(Inst));
298 }
299
300 llvm_unreachable("convertInstruction");
Karl Schimpf9d98d792014-10-13 15:01:08 -0700301 return nullptr;
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700302 }
303
304 Ice::Inst *convertLoadInstruction(const LoadInst *Inst) {
305 Ice::Operand *Src = convertOperand(Inst, 0);
306 Ice::Variable *Dest = mapValueToIceVar(Inst);
307 return Ice::InstLoad::create(Func, Dest, Src);
308 }
309
310 Ice::Inst *convertStoreInstruction(const StoreInst *Inst) {
311 Ice::Operand *Addr = convertOperand(Inst, 1);
312 Ice::Operand *Val = convertOperand(Inst, 0);
313 return Ice::InstStore::create(Func, Val, Addr);
314 }
315
316 Ice::Inst *convertArithInstruction(const Instruction *Inst,
317 Ice::InstArithmetic::OpKind Opcode) {
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700318 const auto BinOp = cast<BinaryOperator>(Inst);
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700319 Ice::Operand *Src0 = convertOperand(Inst, 0);
320 Ice::Operand *Src1 = convertOperand(Inst, 1);
321 Ice::Variable *Dest = mapValueToIceVar(BinOp);
322 return Ice::InstArithmetic::create(Func, Opcode, Dest, Src0, Src1);
323 }
324
325 Ice::Inst *convertPHINodeInstruction(const PHINode *Inst) {
326 unsigned NumValues = Inst->getNumIncomingValues();
327 Ice::InstPhi *IcePhi =
328 Ice::InstPhi::create(Func, NumValues, mapValueToIceVar(Inst));
329 for (unsigned N = 0, E = NumValues; N != E; ++N) {
330 IcePhi->addArgument(convertOperand(Inst, N),
331 mapBasicBlockToNode(Inst->getIncomingBlock(N)));
332 }
333 return IcePhi;
334 }
335
336 Ice::Inst *convertBrInstruction(const BranchInst *Inst) {
337 if (Inst->isConditional()) {
338 Ice::Operand *Src = convertOperand(Inst, 0);
339 BasicBlock *BBThen = Inst->getSuccessor(0);
340 BasicBlock *BBElse = Inst->getSuccessor(1);
341 Ice::CfgNode *NodeThen = mapBasicBlockToNode(BBThen);
342 Ice::CfgNode *NodeElse = mapBasicBlockToNode(BBElse);
343 return Ice::InstBr::create(Func, Src, NodeThen, NodeElse);
344 } else {
345 BasicBlock *BBSucc = Inst->getSuccessor(0);
346 return Ice::InstBr::create(Func, mapBasicBlockToNode(BBSucc));
347 }
348 }
349
350 Ice::Inst *convertIntToPtrInstruction(const IntToPtrInst *Inst) {
351 Ice::Operand *Src = convertOperand(Inst, 0);
Karl Schimpfd6064a12014-08-27 15:34:58 -0700352 Ice::Variable *Dest =
353 mapValueToIceVar(Inst, TypeConverter.getIcePointerType());
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700354 return Ice::InstAssign::create(Func, Dest, Src);
355 }
356
357 Ice::Inst *convertPtrToIntInstruction(const PtrToIntInst *Inst) {
358 Ice::Operand *Src = convertOperand(Inst, 0);
359 Ice::Variable *Dest = mapValueToIceVar(Inst);
360 return Ice::InstAssign::create(Func, Dest, Src);
361 }
362
363 Ice::Inst *convertRetInstruction(const ReturnInst *Inst) {
364 Ice::Operand *RetOperand = convertOperand(Inst, 0);
365 if (RetOperand) {
366 return Ice::InstRet::create(Func, RetOperand);
367 } else {
368 return Ice::InstRet::create(Func);
369 }
370 }
371
372 Ice::Inst *convertCastInstruction(const Instruction *Inst,
373 Ice::InstCast::OpKind CastKind) {
374 Ice::Operand *Src = convertOperand(Inst, 0);
375 Ice::Variable *Dest = mapValueToIceVar(Inst);
376 return Ice::InstCast::create(Func, CastKind, Dest, Src);
377 }
378
379 Ice::Inst *convertICmpInstruction(const ICmpInst *Inst) {
380 Ice::Operand *Src0 = convertOperand(Inst, 0);
381 Ice::Operand *Src1 = convertOperand(Inst, 1);
382 Ice::Variable *Dest = mapValueToIceVar(Inst);
383
384 Ice::InstIcmp::ICond Cond;
385 switch (Inst->getPredicate()) {
386 default:
387 llvm_unreachable("ICmpInst predicate");
388 case CmpInst::ICMP_EQ:
389 Cond = Ice::InstIcmp::Eq;
390 break;
391 case CmpInst::ICMP_NE:
392 Cond = Ice::InstIcmp::Ne;
393 break;
394 case CmpInst::ICMP_UGT:
395 Cond = Ice::InstIcmp::Ugt;
396 break;
397 case CmpInst::ICMP_UGE:
398 Cond = Ice::InstIcmp::Uge;
399 break;
400 case CmpInst::ICMP_ULT:
401 Cond = Ice::InstIcmp::Ult;
402 break;
403 case CmpInst::ICMP_ULE:
404 Cond = Ice::InstIcmp::Ule;
405 break;
406 case CmpInst::ICMP_SGT:
407 Cond = Ice::InstIcmp::Sgt;
408 break;
409 case CmpInst::ICMP_SGE:
410 Cond = Ice::InstIcmp::Sge;
411 break;
412 case CmpInst::ICMP_SLT:
413 Cond = Ice::InstIcmp::Slt;
414 break;
415 case CmpInst::ICMP_SLE:
416 Cond = Ice::InstIcmp::Sle;
417 break;
418 }
419
420 return Ice::InstIcmp::create(Func, Cond, Dest, Src0, Src1);
421 }
422
423 Ice::Inst *convertFCmpInstruction(const FCmpInst *Inst) {
424 Ice::Operand *Src0 = convertOperand(Inst, 0);
425 Ice::Operand *Src1 = convertOperand(Inst, 1);
426 Ice::Variable *Dest = mapValueToIceVar(Inst);
427
428 Ice::InstFcmp::FCond Cond;
429 switch (Inst->getPredicate()) {
430
431 default:
432 llvm_unreachable("FCmpInst predicate");
433
434 case CmpInst::FCMP_FALSE:
435 Cond = Ice::InstFcmp::False;
436 break;
437 case CmpInst::FCMP_OEQ:
438 Cond = Ice::InstFcmp::Oeq;
439 break;
440 case CmpInst::FCMP_OGT:
441 Cond = Ice::InstFcmp::Ogt;
442 break;
443 case CmpInst::FCMP_OGE:
444 Cond = Ice::InstFcmp::Oge;
445 break;
446 case CmpInst::FCMP_OLT:
447 Cond = Ice::InstFcmp::Olt;
448 break;
449 case CmpInst::FCMP_OLE:
450 Cond = Ice::InstFcmp::Ole;
451 break;
452 case CmpInst::FCMP_ONE:
453 Cond = Ice::InstFcmp::One;
454 break;
455 case CmpInst::FCMP_ORD:
456 Cond = Ice::InstFcmp::Ord;
457 break;
458 case CmpInst::FCMP_UEQ:
459 Cond = Ice::InstFcmp::Ueq;
460 break;
461 case CmpInst::FCMP_UGT:
462 Cond = Ice::InstFcmp::Ugt;
463 break;
464 case CmpInst::FCMP_UGE:
465 Cond = Ice::InstFcmp::Uge;
466 break;
467 case CmpInst::FCMP_ULT:
468 Cond = Ice::InstFcmp::Ult;
469 break;
470 case CmpInst::FCMP_ULE:
471 Cond = Ice::InstFcmp::Ule;
472 break;
473 case CmpInst::FCMP_UNE:
474 Cond = Ice::InstFcmp::Une;
475 break;
476 case CmpInst::FCMP_UNO:
477 Cond = Ice::InstFcmp::Uno;
478 break;
479 case CmpInst::FCMP_TRUE:
480 Cond = Ice::InstFcmp::True;
481 break;
482 }
483
484 return Ice::InstFcmp::create(Func, Cond, Dest, Src0, Src1);
485 }
486
Matt Wala49889232014-07-18 12:45:09 -0700487 Ice::Inst *convertExtractElementInstruction(const ExtractElementInst *Inst) {
488 Ice::Variable *Dest = mapValueToIceVar(Inst);
489 Ice::Operand *Source1 = convertValue(Inst->getOperand(0));
490 Ice::Operand *Source2 = convertValue(Inst->getOperand(1));
491 return Ice::InstExtractElement::create(Func, Dest, Source1, Source2);
492 }
493
494 Ice::Inst *convertInsertElementInstruction(const InsertElementInst *Inst) {
495 Ice::Variable *Dest = mapValueToIceVar(Inst);
496 Ice::Operand *Source1 = convertValue(Inst->getOperand(0));
497 Ice::Operand *Source2 = convertValue(Inst->getOperand(1));
498 Ice::Operand *Source3 = convertValue(Inst->getOperand(2));
499 return Ice::InstInsertElement::create(Func, Dest, Source1, Source2,
500 Source3);
501 }
502
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700503 Ice::Inst *convertSelectInstruction(const SelectInst *Inst) {
504 Ice::Variable *Dest = mapValueToIceVar(Inst);
505 Ice::Operand *Cond = convertValue(Inst->getCondition());
506 Ice::Operand *Source1 = convertValue(Inst->getTrueValue());
507 Ice::Operand *Source2 = convertValue(Inst->getFalseValue());
508 return Ice::InstSelect::create(Func, Dest, Cond, Source1, Source2);
509 }
510
511 Ice::Inst *convertSwitchInstruction(const SwitchInst *Inst) {
512 Ice::Operand *Source = convertValue(Inst->getCondition());
513 Ice::CfgNode *LabelDefault = mapBasicBlockToNode(Inst->getDefaultDest());
514 unsigned NumCases = Inst->getNumCases();
515 Ice::InstSwitch *Switch =
516 Ice::InstSwitch::create(Func, NumCases, Source, LabelDefault);
517 unsigned CurrentCase = 0;
518 for (SwitchInst::ConstCaseIt I = Inst->case_begin(), E = Inst->case_end();
519 I != E; ++I, ++CurrentCase) {
Jim Stichnothcabfa302014-09-03 15:19:12 -0700520 uint64_t CaseValue = I.getCaseValue()->getSExtValue();
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700521 Ice::CfgNode *CaseSuccessor = mapBasicBlockToNode(I.getCaseSuccessor());
522 Switch->addBranch(CurrentCase, CaseValue, CaseSuccessor);
523 }
524 return Switch;
525 }
526
527 Ice::Inst *convertCallInstruction(const CallInst *Inst) {
528 Ice::Variable *Dest = mapValueToIceVar(Inst);
529 Ice::Operand *CallTarget = convertValue(Inst->getCalledValue());
530 unsigned NumArgs = Inst->getNumArgOperands();
531 // Note: Subzero doesn't (yet) do anything special with the Tail
532 // flag in the bitcode, i.e. CallInst::isTailCall().
Karl Schimpf9d98d792014-10-13 15:01:08 -0700533 Ice::InstCall *NewInst = nullptr;
534 const Ice::Intrinsics::FullIntrinsicInfo *Info = nullptr;
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700535
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700536 if (const auto Target = dyn_cast<Ice::ConstantRelocatable>(CallTarget)) {
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700537 // Check if this direct call is to an Intrinsic (starts with "llvm.")
538 static const char LLVMPrefix[] = "llvm.";
539 const size_t LLVMPrefixLen = strlen(LLVMPrefix);
540 Ice::IceString Name = Target->getName();
541 if (Name.substr(0, LLVMPrefixLen) == LLVMPrefix) {
542 Ice::IceString NameSuffix = Name.substr(LLVMPrefixLen);
543 Info = Ctx->getIntrinsicsInfo().find(NameSuffix);
544 if (!Info) {
545 report_fatal_error(std::string("Invalid PNaCl intrinsic call: ") +
546 LLVMObjectAsString(Inst));
547 }
548 NewInst = Ice::InstIntrinsicCall::create(Func, NumArgs, Dest,
549 CallTarget, Info->Info);
550 }
551 }
552
553 // Not an intrinsic call.
Karl Schimpf9d98d792014-10-13 15:01:08 -0700554 if (NewInst == nullptr) {
Karl Schimpf8df26f32014-09-19 09:33:26 -0700555 NewInst = Ice::InstCall::create(Func, NumArgs, Dest, CallTarget,
556 Inst->isTailCall());
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700557 }
558 for (unsigned i = 0; i < NumArgs; ++i) {
559 NewInst->addArg(convertOperand(Inst, i));
560 }
561 if (Info) {
562 validateIntrinsicCall(NewInst, Info);
563 }
564 return NewInst;
565 }
566
567 Ice::Inst *convertAllocaInstruction(const AllocaInst *Inst) {
568 // PNaCl bitcode only contains allocas of byte-granular objects.
569 Ice::Operand *ByteCount = convertValue(Inst->getArraySize());
570 uint32_t Align = Inst->getAlignment();
Karl Schimpfd6064a12014-08-27 15:34:58 -0700571 Ice::Variable *Dest =
572 mapValueToIceVar(Inst, TypeConverter.getIcePointerType());
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700573
574 return Ice::InstAlloca::create(Func, ByteCount, Align, Dest);
575 }
576
577 Ice::Inst *convertUnreachableInstruction(const UnreachableInst * /*Inst*/) {
578 return Ice::InstUnreachable::create(Func);
579 }
580
581 Ice::CfgNode *convertBasicBlock(const BasicBlock *BB) {
582 Ice::CfgNode *Node = mapBasicBlockToNode(BB);
Jim Stichnothf44f3712014-10-01 14:05:51 -0700583 for (const Instruction &II : *BB) {
584 Ice::Inst *Inst = convertInstruction(&II);
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700585 Node->appendInst(Inst);
586 }
587 return Node;
588 }
589
590 void validateIntrinsicCall(const Ice::InstCall *Call,
591 const Ice::Intrinsics::FullIntrinsicInfo *I) {
Karl Schimpf8df26f32014-09-19 09:33:26 -0700592 Ice::SizeT ArgIndex = 0;
593 switch (I->validateCall(Call, ArgIndex)) {
594 default:
595 report_fatal_error("Unknown validation error for intrinsic call");
596 break;
597 case Ice::Intrinsics::IsValidCall:
598 break;
599 case Ice::Intrinsics::BadReturnType: {
600 std::string Buffer;
601 raw_string_ostream StrBuf(Buffer);
602 StrBuf << "Intrinsic call expects return type " << I->getReturnType()
603 << ". Found: " << Call->getReturnType();
604 report_fatal_error(StrBuf.str());
605 break;
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700606 }
Karl Schimpf8df26f32014-09-19 09:33:26 -0700607 case Ice::Intrinsics::WrongNumOfArgs: {
608 std::string Buffer;
609 raw_string_ostream StrBuf(Buffer);
610 StrBuf << "Intrinsic call expects " << I->getNumArgs()
611 << ". Found: " << Call->getNumArgs();
612 report_fatal_error(StrBuf.str());
613 break;
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700614 }
Karl Schimpf8df26f32014-09-19 09:33:26 -0700615 case Ice::Intrinsics::WrongCallArgType: {
616 std::string Buffer;
617 raw_string_ostream StrBuf(Buffer);
618 StrBuf << "Intrinsic call argument " << ArgIndex << " expects type "
619 << I->getArgType(ArgIndex)
620 << ". Found: " << Call->getArg(ArgIndex)->getType();
621 report_fatal_error(StrBuf.str());
622 break;
623 }
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700624 }
625 }
626
627private:
628 // Data
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700629 Ice::Cfg *Func;
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700630 std::map<const Value *, Ice::Variable *> VarMap;
631 std::map<const BasicBlock *, Ice::CfgNode *> NodeMap;
632};
633
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700634// Converter from LLVM global variables to ICE. The entry point is the
635// convertGlobalsToIce method.
636//
637// Note: this currently assumes that the given IR was verified to be
638// valid PNaCl bitcode. Othewise, the behavior is undefined.
639class LLVM2ICEGlobalsConverter : public LLVM2ICEConverter {
640 LLVM2ICEGlobalsConverter(const LLVM2ICEGlobalsConverter &) = delete;
641 LLVM2ICEGlobalsConverter &
642 operator-(const LLVM2ICEGlobalsConverter &) = delete;
643
644public:
Karl Schimpf9d98d792014-10-13 15:01:08 -0700645 LLVM2ICEGlobalsConverter(Ice::Converter &Converter)
646 : LLVM2ICEConverter(Converter) {}
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700647
Karl Schimpf9d98d792014-10-13 15:01:08 -0700648 /// Converts global variables, and their initializers into ICE
649 /// global variable declarations, for module Mod. Puts corresponding
650 /// converted declarations into VariableDeclarations.
651 void convertGlobalsToIce(
652 Module *Mod,
653 Ice::Translator::VariableDeclarationListType &VariableDeclarations);
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700654
655private:
Karl Schimpf9d98d792014-10-13 15:01:08 -0700656 // Adds the Initializer to the list of initializers for the Global
657 // variable declaraation.
658 void addGlobalInitializer(Ice::VariableDeclaration &Global,
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700659 const Constant *Initializer) {
660 const bool HasOffset = false;
Jan Voungc0d965f2014-11-04 16:55:01 -0800661 const Ice::RelocOffsetT Offset = 0;
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700662 addGlobalInitializer(Global, Initializer, HasOffset, Offset);
663 }
664
Karl Schimpf9d98d792014-10-13 15:01:08 -0700665 // Adds Initializer to the list of initializers for Global variable
666 // declaration. HasOffset is true only if Initializer is a
667 // relocation initializer and Offset should be added to the
668 // relocation.
669 void addGlobalInitializer(Ice::VariableDeclaration &Global,
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700670 const Constant *Initializer, bool HasOffset,
Jan Voungc0d965f2014-11-04 16:55:01 -0800671 Ice::RelocOffsetT Offset);
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700672
673 // Converts the given constant C to the corresponding integer
674 // literal it contains.
Jan Voungc0d965f2014-11-04 16:55:01 -0800675 Ice::RelocOffsetT getIntegerLiteralConstant(const Value *C) {
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700676 const auto CI = dyn_cast<ConstantInt>(C);
677 if (CI && CI->getType()->isIntegerTy(32))
678 return CI->getSExtValue();
679
680 std::string Buffer;
681 raw_string_ostream StrBuf(Buffer);
682 StrBuf << "Constant not i32 literal: " << *C;
683 report_fatal_error(StrBuf.str());
684 return 0;
685 }
686};
687
688void LLVM2ICEGlobalsConverter::convertGlobalsToIce(
Karl Schimpf9d98d792014-10-13 15:01:08 -0700689 Module *Mod,
690 Ice::Translator::VariableDeclarationListType &VariableDeclarations) {
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700691 for (Module::const_global_iterator I = Mod->global_begin(),
692 E = Mod->global_end();
693 I != E; ++I) {
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700694
Karl Schimpf9d98d792014-10-13 15:01:08 -0700695 const GlobalVariable *GV = I;
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700696
Karl Schimpf9d98d792014-10-13 15:01:08 -0700697 Ice::GlobalDeclaration *Var = getConverter().getGlobalDeclaration(GV);
698 Ice::VariableDeclaration* VarDecl = cast<Ice::VariableDeclaration>(Var);
699 VariableDeclarations.push_back(VarDecl);
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700700
Karl Schimpfdf6f9d12014-10-20 14:09:00 -0700701 if (!GV->hasInternalLinkage() && GV->hasInitializer()) {
702 std::string Buffer;
703 raw_string_ostream StrBuf(Buffer);
704 StrBuf << "Can't define external global declaration: " << GV->getName();
705 report_fatal_error(StrBuf.str());
706 }
707
708 if (!GV->hasInitializer()) {
709 if (Ctx->getFlags().AllowUninitializedGlobals)
710 continue;
711 else {
712 std::string Buffer;
713 raw_string_ostream StrBuf(Buffer);
714 StrBuf << "Global declaration missing initializer: " << GV->getName();
715 report_fatal_error(StrBuf.str());
716 }
717 }
718
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700719 const Constant *Initializer = GV->getInitializer();
720 if (const auto CompoundInit = dyn_cast<ConstantStruct>(Initializer)) {
721 for (ConstantStruct::const_op_iterator I = CompoundInit->op_begin(),
722 E = CompoundInit->op_end();
723 I != E; ++I) {
724 if (const auto Init = dyn_cast<Constant>(I)) {
Karl Schimpf9d98d792014-10-13 15:01:08 -0700725 addGlobalInitializer(*VarDecl, Init);
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700726 }
727 }
728 } else {
Karl Schimpf9d98d792014-10-13 15:01:08 -0700729 addGlobalInitializer(*VarDecl, Initializer);
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700730 }
731 }
732}
733
734void LLVM2ICEGlobalsConverter::addGlobalInitializer(
Karl Schimpf9d98d792014-10-13 15:01:08 -0700735 Ice::VariableDeclaration &Global, const Constant *Initializer,
Jan Voungc0d965f2014-11-04 16:55:01 -0800736 bool HasOffset, Ice::RelocOffsetT Offset) {
Karl Schimpf9d98d792014-10-13 15:01:08 -0700737 (void)HasOffset;
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700738 assert(HasOffset || Offset == 0);
739
740 if (const auto CDA = dyn_cast<ConstantDataArray>(Initializer)) {
741 assert(!HasOffset && isa<IntegerType>(CDA->getElementType()) &&
742 (cast<IntegerType>(CDA->getElementType())->getBitWidth() == 8));
Karl Schimpf9d98d792014-10-13 15:01:08 -0700743 Global.addInitializer(new Ice::VariableDeclaration::DataInitializer(
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700744 CDA->getRawDataValues().data(), CDA->getNumElements()));
745 return;
746 }
747
748 if (isa<ConstantAggregateZero>(Initializer)) {
749 if (const auto AT = dyn_cast<ArrayType>(Initializer->getType())) {
750 assert(!HasOffset && isa<IntegerType>(AT->getElementType()) &&
751 (cast<IntegerType>(AT->getElementType())->getBitWidth() == 8));
752 Global.addInitializer(
Karl Schimpf9d98d792014-10-13 15:01:08 -0700753 new Ice::VariableDeclaration::ZeroInitializer(AT->getNumElements()));
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700754 } else {
755 llvm_unreachable("Unhandled constant aggregate zero type");
756 }
757 return;
758 }
759
760 if (const auto Exp = dyn_cast<ConstantExpr>(Initializer)) {
761 switch (Exp->getOpcode()) {
762 case Instruction::Add:
763 assert(!HasOffset);
764 addGlobalInitializer(Global, Exp->getOperand(0), true,
765 getIntegerLiteralConstant(Exp->getOperand(1)));
766 return;
767 case Instruction::PtrToInt: {
768 assert(TypeConverter.convertToIceType(Exp->getType()) ==
769 TypeConverter.getIcePointerType());
770 const auto GV = dyn_cast<GlobalValue>(Exp->getOperand(0));
771 assert(GV);
Karl Schimpf9d98d792014-10-13 15:01:08 -0700772 const Ice::GlobalDeclaration *Addr =
773 getConverter().getGlobalDeclaration(GV);
774 Global.addInitializer(
775 new Ice::VariableDeclaration::RelocInitializer(Addr, Offset));
776 return;
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700777 }
778 default:
779 break;
780 }
781 }
782
783 std::string Buffer;
784 raw_string_ostream StrBuf(Buffer);
785 StrBuf << "Unhandled global initializer: " << Initializer;
786 report_fatal_error(StrBuf.str());
787}
788
Jim Stichnoth989a7032014-08-08 10:13:44 -0700789} // end of anonymous namespace
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700790
Karl Schimpfb164d202014-07-11 10:26:34 -0700791namespace Ice {
792
Karl Schimpf9d98d792014-10-13 15:01:08 -0700793void Converter::nameUnnamedGlobalVariables(Module *Mod) {
794 const IceString &GlobalPrefix = Flags.DefaultGlobalPrefix;
795 if (GlobalPrefix.empty())
796 return;
797 uint32_t NameIndex = 0;
798 Ostream &errs = Ctx->getStrDump();
799 for (auto V = Mod->global_begin(), E = Mod->global_end(); V != E; ++V) {
800 if (!V->hasName()) {
801 V->setName(createUnnamedName(GlobalPrefix, NameIndex));
802 ++NameIndex;
803 } else {
804 checkIfUnnamedNameSafe(V->getName(), "global", GlobalPrefix, errs);
805 }
806 }
807}
808
809void Converter::nameUnnamedFunctions(Module *Mod) {
810 const IceString &FunctionPrefix = Flags.DefaultFunctionPrefix;
811 if (FunctionPrefix.empty())
812 return;
813 uint32_t NameIndex = 0;
814 Ostream &errs = Ctx->getStrDump();
815 for (Function &F : *Mod) {
816 if (!F.hasName()) {
817 F.setName(createUnnamedName(FunctionPrefix, NameIndex));
818 ++NameIndex;
819 } else {
820 checkIfUnnamedNameSafe(F.getName(), "function", FunctionPrefix, errs);
821 }
822 }
823}
824
Karl Schimpfd6064a12014-08-27 15:34:58 -0700825void Converter::convertToIce() {
Jim Stichnoth8363a062014-10-07 10:02:38 -0700826 TimerMarker T(TimerStack::TT_convertToIce, Ctx);
Karl Schimpf9d98d792014-10-13 15:01:08 -0700827 nameUnnamedGlobalVariables(Mod);
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700828 nameUnnamedFunctions(Mod);
Karl Schimpf9d98d792014-10-13 15:01:08 -0700829 installGlobalDeclarations(Mod);
Jim Stichnoth2a063e22014-10-08 11:24:51 -0700830 convertGlobals(Mod);
Karl Schimpfd6064a12014-08-27 15:34:58 -0700831 convertFunctions();
Karl Schimpfb164d202014-07-11 10:26:34 -0700832}
833
Karl Schimpf9d98d792014-10-13 15:01:08 -0700834GlobalDeclaration *Converter::getGlobalDeclaration(const GlobalValue *V) {
835 GlobalDeclarationMapType::const_iterator Pos = GlobalDeclarationMap.find(V);
836 if (Pos == GlobalDeclarationMap.end()) {
837 std::string Buffer;
838 raw_string_ostream StrBuf(Buffer);
839 StrBuf << "Can't find global declaration for: " << V->getName();
840 report_fatal_error(StrBuf.str());
841 }
842 return Pos->second;
843}
844
845void Converter::installGlobalDeclarations(Module *Mod) {
846 const TypeConverter Converter(Mod->getContext());
847 // Install function declarations.
848 for (const Function &Func : *Mod) {
849 FuncSigType Signature;
850 FunctionType *FuncType = Func.getFunctionType();
851 Signature.setReturnType(
852 Converter.convertToIceType(FuncType->getReturnType()));
853 for (size_t I = 0; I < FuncType->getNumParams(); ++I) {
854 Signature.appendArgType(
855 Converter.convertToIceType(FuncType->getParamType(I)));
856 }
857 FunctionDeclaration *IceFunc = FunctionDeclaration::create(
858 Ctx, Signature, Func.getCallingConv(), Func.getLinkage(), Func.empty());
859 IceFunc->setName(Func.getName());
860 GlobalDeclarationMap[&Func] = IceFunc;
861 }
862 // Install global variable declarations.
863 for (Module::const_global_iterator I = Mod->global_begin(),
864 E = Mod->global_end();
865 I != E; ++I) {
866 const GlobalVariable *GV = I;
867 VariableDeclaration *Var = VariableDeclaration::create(Ctx);
868 Var->setName(GV->getName());
869 Var->setAlignment(GV->getAlignment());
870 Var->setIsConstant(GV->isConstant());
Karl Schimpfdf6f9d12014-10-20 14:09:00 -0700871 Var->setLinkage(GV->getLinkage());
Karl Schimpf9d98d792014-10-13 15:01:08 -0700872 GlobalDeclarationMap[GV] = Var;
873 }
874}
875
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700876void Converter::convertGlobals(Module *Mod) {
Karl Schimpf9d98d792014-10-13 15:01:08 -0700877 LLVM2ICEGlobalsConverter GlobalsConverter(*this);
878 Translator::VariableDeclarationListType VariableDeclarations;
879 GlobalsConverter.convertGlobalsToIce(Mod, VariableDeclarations);
880 lowerGlobals(VariableDeclarations);
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700881}
882
Karl Schimpfd6064a12014-08-27 15:34:58 -0700883void Converter::convertFunctions() {
Jim Stichnoth8363a062014-10-07 10:02:38 -0700884 TimerStackIdT StackID = GlobalContext::TSK_Funcs;
Jim Stichnothf44f3712014-10-01 14:05:51 -0700885 for (const Function &I : *Mod) {
886 if (I.empty())
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700887 continue;
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700888
Jim Stichnoth8363a062014-10-07 10:02:38 -0700889 TimerIdT TimerID = 0;
Jim Stichnoth1c44d812014-12-08 14:57:52 -0800890 if (ALLOW_DUMP && Ctx->getFlags().TimeEachFunction) {
Jim Stichnoth8363a062014-10-07 10:02:38 -0700891 TimerID = Ctx->getTimerID(StackID, I.getName());
892 Ctx->pushTimer(TimerID, StackID);
893 }
Karl Schimpf9d98d792014-10-13 15:01:08 -0700894 LLVM2ICEFunctionConverter FunctionConverter(*this);
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700895
Jim Stichnothf44f3712014-10-01 14:05:51 -0700896 Cfg *Fcn = FunctionConverter.convertFunction(&I);
Karl Schimpf8d7abae2014-07-07 14:50:30 -0700897 translateFcn(Fcn);
Jim Stichnoth1c44d812014-12-08 14:57:52 -0800898 if (ALLOW_DUMP && Ctx->getFlags().TimeEachFunction)
Jim Stichnoth8363a062014-10-07 10:02:38 -0700899 Ctx->popTimer(TimerID, StackID);
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700900 }
901
Karl Schimpf8d7abae2014-07-07 14:50:30 -0700902 emitConstants();
Karl Schimpfe1e013c2014-06-27 09:15:29 -0700903}
Karl Schimpfb164d202014-07-11 10:26:34 -0700904
Jim Stichnoth989a7032014-08-08 10:13:44 -0700905} // end of namespace Ice