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

Side by Side Diff: src/llvm2ice.cpp

Issue 300563003: Subzero: Initial O2 lowering (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Jan's third-round comments Created 6 years, 6 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
« no previous file with comments | « src/IceTargetLoweringX8632.cpp ('k') | tests_lit/llvm2ice_tests/64bit.pnacl.ll » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 ++BBI) { 93 ++BBI) {
94 CurrentNode = mapBasicBlockToNode(BBI); 94 CurrentNode = mapBasicBlockToNode(BBI);
95 convertBasicBlock(BBI); 95 convertBasicBlock(BBI);
96 } 96 }
97 Func->setEntryNode(mapBasicBlockToNode(&F->getEntryBlock())); 97 Func->setEntryNode(mapBasicBlockToNode(&F->getEntryBlock()));
98 Func->computePredecessors(); 98 Func->computePredecessors();
99 99
100 return Func; 100 return Func;
101 } 101 }
102 102
103 // convertConstant() does not use Func or require it to be a valid
104 // Ice::Cfg pointer. As such, it's suitable for e.g. constructing
105 // global initializers.
106 Ice::Constant *convertConstant(const Constant *Const) {
107 if (const GlobalValue *GV = dyn_cast<GlobalValue>(Const)) {
108 return Ctx->getConstantSym(convertType(GV->getType()), 0, GV->getName());
109 } else if (const ConstantInt *CI = dyn_cast<ConstantInt>(Const)) {
110 return Ctx->getConstantInt(convertIntegerType(CI->getType()),
111 CI->getZExtValue());
112 } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(Const)) {
113 Ice::Type Type = convertType(CFP->getType());
114 if (Type == Ice::IceType_f32)
115 return Ctx->getConstantFloat(CFP->getValueAPF().convertToFloat());
116 else if (Type == Ice::IceType_f64)
117 return Ctx->getConstantDouble(CFP->getValueAPF().convertToDouble());
118 llvm_unreachable("Unexpected floating point type");
119 return NULL;
120 } else {
121 llvm_unreachable("Unhandled constant type");
122 return NULL;
123 }
124 }
125
103 private: 126 private:
104 // LLVM values (instructions, etc.) are mapped directly to ICE variables. 127 // LLVM values (instructions, etc.) are mapped directly to ICE variables.
105 // mapValueToIceVar has a version that forces an ICE type on the variable, 128 // mapValueToIceVar has a version that forces an ICE type on the variable,
106 // and a version that just uses convertType on V. 129 // and a version that just uses convertType on V.
107 Ice::Variable *mapValueToIceVar(const Value *V, Ice::Type IceTy) { 130 Ice::Variable *mapValueToIceVar(const Value *V, Ice::Type IceTy) {
108 if (IceTy == Ice::IceType_void) 131 if (IceTy == Ice::IceType_void)
109 return NULL; 132 return NULL;
110 if (VarMap.find(V) == VarMap.end()) { 133 if (VarMap.find(V) == VarMap.end()) {
111 assert(CurrentNode); 134 assert(CurrentNode);
112 VarMap[V] = Func->makeVariable(IceTy, CurrentNode, V->getName()); 135 VarMap[V] = Func->makeVariable(IceTy, CurrentNode, V->getName());
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 Ice::Operand *convertOperand(const Instruction *Inst, unsigned OpNum) { 196 Ice::Operand *convertOperand(const Instruction *Inst, unsigned OpNum) {
174 if (OpNum >= Inst->getNumOperands()) { 197 if (OpNum >= Inst->getNumOperands()) {
175 return NULL; 198 return NULL;
176 } 199 }
177 const Value *Op = Inst->getOperand(OpNum); 200 const Value *Op = Inst->getOperand(OpNum);
178 return convertValue(Op); 201 return convertValue(Op);
179 } 202 }
180 203
181 Ice::Operand *convertValue(const Value *Op) { 204 Ice::Operand *convertValue(const Value *Op) {
182 if (const Constant *Const = dyn_cast<Constant>(Op)) { 205 if (const Constant *Const = dyn_cast<Constant>(Op)) {
183 if (const GlobalValue *GV = dyn_cast<GlobalValue>(Const)) { 206 return convertConstant(Const);
184 return Ctx->getConstantSym(convertType(GV->getType()), 0,
185 GV->getName());
186 } else if (const ConstantInt *CI = dyn_cast<ConstantInt>(Const)) {
187 return Ctx->getConstantInt(convertIntegerType(CI->getType()),
188 CI->getZExtValue());
189 } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(Const)) {
190 Ice::Type Type = convertType(CFP->getType());
191 if (Type == Ice::IceType_f32)
192 return Ctx->getConstantFloat(CFP->getValueAPF().convertToFloat());
193 else if (Type == Ice::IceType_f64)
194 return Ctx->getConstantDouble(CFP->getValueAPF().convertToDouble());
195 llvm_unreachable("Unexpected floating point type");
196 return NULL;
197 } else {
198 llvm_unreachable("Unhandled constant type");
199 return NULL;
200 }
201 } else { 207 } else {
202 return mapValueToIceVar(Op); 208 return mapValueToIceVar(Op);
203 } 209 }
204 } 210 }
205 211
206 // Note: this currently assumes a 1x1 mapping between LLVM IR and Ice 212 // Note: this currently assumes a 1x1 mapping between LLVM IR and Ice
207 // instructions. 213 // instructions.
208 Ice::Inst *convertInstruction(const Instruction *Inst) { 214 Ice::Inst *convertInstruction(const Instruction *Inst) {
209 switch (Inst->getOpcode()) { 215 switch (Inst->getOpcode()) {
210 case Instruction::PHI: 216 case Instruction::PHI:
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 << " sec\n"; 725 << " sec\n";
720 } 726 }
721 } 727 }
722 } 728 }
723 729
724 if (!DisableTranslation && Func) 730 if (!DisableTranslation && Func)
725 Func->getTarget()->emitConstants(); 731 Func->getTarget()->emitConstants();
726 732
727 return ExitStatus; 733 return ExitStatus;
728 } 734 }
OLDNEW
« no previous file with comments | « src/IceTargetLoweringX8632.cpp ('k') | tests_lit/llvm2ice_tests/64bit.pnacl.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698