OLD | NEW |
1 //===- subzero/src/IceTranslator.cpp - ICE to machine code ------*- C++ -*-===// | 1 //===- subzero/src/IceTranslator.cpp - ICE to machine code ------*- C++ -*-===// |
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 the general driver class for translating ICE to | 10 // This file defines the general driver class for translating ICE to |
11 // machine code. | 11 // machine code. |
12 // | 12 // |
13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
14 | 14 |
15 #include "IceTranslator.h" | 15 #include "IceTranslator.h" |
16 | 16 |
17 #include "IceCfg.h" | 17 #include "IceCfg.h" |
18 #include "IceClFlags.h" | 18 #include "IceClFlags.h" |
19 #include "IceDefs.h" | 19 #include "IceDefs.h" |
20 #include "IceTargetLowering.h" | 20 #include "IceTargetLowering.h" |
21 #include "llvm/IR/Module.h" | 21 #include "llvm/IR/Module.h" |
| 22 #include "llvm/IR/Constant.h" |
| 23 #include "llvm/IR/Constants.h" |
22 | 24 |
23 #include <iostream> | 25 #include <iostream> |
24 | 26 |
25 using namespace Ice; | 27 using namespace Ice; |
26 | 28 |
27 Translator::~Translator() {} | 29 Translator::~Translator() {} |
28 | 30 |
29 namespace { | 31 namespace { |
30 void setValueName(llvm::Value *V, const char *Kind, const IceString &Prefix, | 32 void setValueName(llvm::Value *V, const char *Kind, const IceString &Prefix, |
31 uint32_t &NameIndex, Ostream &errs) { | 33 uint32_t &NameIndex, Ostream &errs) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 << ": " << TEmit.getElapsedSec() << " sec\n"; | 99 << ": " << TEmit.getElapsedSec() << " sec\n"; |
98 } | 100 } |
99 Ctx->dumpStats(Func->getFunctionName()); | 101 Ctx->dumpStats(Func->getFunctionName()); |
100 } | 102 } |
101 } | 103 } |
102 | 104 |
103 void Translator::emitConstants() { | 105 void Translator::emitConstants() { |
104 if (!Ctx->getFlags().DisableTranslation && Func) | 106 if (!Ctx->getFlags().DisableTranslation && Func) |
105 Func->getTarget()->emitConstants(); | 107 Func->getTarget()->emitConstants(); |
106 } | 108 } |
| 109 |
| 110 void Translator::convertGlobals(llvm::Module *Mod) { |
| 111 llvm::OwningPtr<TargetGlobalInitLowering> GlobalLowering( |
| 112 TargetGlobalInitLowering::createLowering(Ctx->getTargetArch(), Ctx)); |
| 113 for (llvm::Module::const_global_iterator I = Mod->global_begin(), |
| 114 E = Mod->global_end(); |
| 115 I != E; ++I) { |
| 116 if (!I->hasInitializer()) |
| 117 continue; |
| 118 const llvm::Constant *Initializer = I->getInitializer(); |
| 119 IceString Name = I->getName(); |
| 120 unsigned Align = I->getAlignment(); |
| 121 uint64_t NumElements = 0; |
| 122 const char *Data = NULL; |
| 123 bool IsInternal = I->hasInternalLinkage(); |
| 124 bool IsConst = I->isConstant(); |
| 125 bool IsZeroInitializer = false; |
| 126 |
| 127 if (const llvm::ConstantDataArray *CDA = |
| 128 llvm::dyn_cast<llvm::ConstantDataArray>(Initializer)) { |
| 129 NumElements = CDA->getNumElements(); |
| 130 assert(llvm::isa<llvm::IntegerType>(CDA->getElementType()) && |
| 131 (llvm::cast<llvm::IntegerType>(CDA->getElementType()) |
| 132 ->getBitWidth() == 8)); |
| 133 Data = CDA->getRawDataValues().data(); |
| 134 } else if (llvm::isa<llvm::ConstantAggregateZero>(Initializer)) { |
| 135 if (const llvm::ArrayType *AT = |
| 136 llvm::dyn_cast<llvm::ArrayType>(Initializer->getType())) { |
| 137 assert(llvm::isa<llvm::IntegerType>(AT->getElementType()) && |
| 138 (llvm::cast<llvm::IntegerType>(AT->getElementType()) |
| 139 ->getBitWidth() == 8)); |
| 140 NumElements = AT->getNumElements(); |
| 141 IsZeroInitializer = true; |
| 142 } else { |
| 143 llvm_unreachable("Unhandled constant aggregate zero type"); |
| 144 } |
| 145 } else { |
| 146 llvm_unreachable("Unhandled global initializer"); |
| 147 } |
| 148 |
| 149 GlobalLowering->lower(Name, Align, IsInternal, IsConst, IsZeroInitializer, |
| 150 NumElements, Data, |
| 151 Ctx->getFlags().DisableTranslation); |
| 152 } |
| 153 GlobalLowering.reset(); |
| 154 } |
OLD | NEW |