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

Side by Side Diff: src/IceConverter.cpp

Issue 589003002: Subzero: Refactor tracking of Defs and block-local Variables. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: "Mark args as being used in the entry node" was unnecessary. Created 6 years, 3 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/IceCfgNode.cpp ('k') | src/IceDefs.h » ('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/IceConverter.cpp - Converts LLVM to Ice ---------------===// 1 //===- subzero/src/IceConverter.cpp - Converts LLVM to Ice ---------------===//
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 implements the LLVM to ICE converter. 10 // This file implements the LLVM to ICE converter.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // Converter from LLVM to ICE. The entry point is the convertFunction method. 49 // Converter from LLVM to ICE. The entry point is the convertFunction method.
50 // 50 //
51 // Note: this currently assumes that the given IR was verified to be valid PNaCl 51 // Note: this currently assumes that the given IR was verified to be valid PNaCl
52 // bitcode: 52 // bitcode:
53 // https://developers.google.com/native-client/dev/reference/pnacl-bitcode-abi 53 // https://developers.google.com/native-client/dev/reference/pnacl-bitcode-abi
54 // If not, all kinds of assertions may fire. 54 // If not, all kinds of assertions may fire.
55 // 55 //
56 class LLVM2ICEConverter { 56 class LLVM2ICEConverter {
57 public: 57 public:
58 LLVM2ICEConverter(Ice::GlobalContext *Ctx, LLVMContext &LLVMContext) 58 LLVM2ICEConverter(Ice::GlobalContext *Ctx, LLVMContext &LLVMContext)
59 : Ctx(Ctx), Func(NULL), CurrentNode(NULL), TypeConverter(LLVMContext) {} 59 : Ctx(Ctx), Func(NULL), TypeConverter(LLVMContext) {}
60 60
61 // Caller is expected to delete the returned Ice::Cfg object. 61 // Caller is expected to delete the returned Ice::Cfg object.
62 Ice::Cfg *convertFunction(const Function *F) { 62 Ice::Cfg *convertFunction(const Function *F) {
63 VarMap.clear(); 63 VarMap.clear();
64 NodeMap.clear(); 64 NodeMap.clear();
65 Func = new Ice::Cfg(Ctx); 65 Func = new Ice::Cfg(Ctx);
66 Func->setFunctionName(F->getName()); 66 Func->setFunctionName(F->getName());
67 Func->setReturnType(convertToIceType(F->getReturnType())); 67 Func->setReturnType(convertToIceType(F->getReturnType()));
68 Func->setInternal(F->hasInternalLinkage()); 68 Func->setInternal(F->hasInternalLinkage());
69 69
70 // The initial definition/use of each arg is the entry node. 70 // The initial definition/use of each arg is the entry node.
71 CurrentNode = mapBasicBlockToNode(&F->getEntryBlock());
72 for (Function::const_arg_iterator ArgI = F->arg_begin(), 71 for (Function::const_arg_iterator ArgI = F->arg_begin(),
73 ArgE = F->arg_end(); 72 ArgE = F->arg_end();
74 ArgI != ArgE; ++ArgI) { 73 ArgI != ArgE; ++ArgI) {
75 Func->addArg(mapValueToIceVar(ArgI)); 74 Func->addArg(mapValueToIceVar(ArgI));
76 } 75 }
77 76
78 // Make an initial pass through the block list just to resolve the 77 // Make an initial pass through the block list just to resolve the
79 // blocks in the original linearized order. Otherwise the ICE 78 // blocks in the original linearized order. Otherwise the ICE
80 // linearized order will be affected by branch targets in 79 // linearized order will be affected by branch targets in
81 // terminator instructions. 80 // terminator instructions.
82 for (Function::const_iterator BBI = F->begin(), BBE = F->end(); BBI != BBE; 81 for (Function::const_iterator BBI = F->begin(), BBE = F->end(); BBI != BBE;
83 ++BBI) { 82 ++BBI) {
84 mapBasicBlockToNode(BBI); 83 mapBasicBlockToNode(BBI);
85 } 84 }
86 for (Function::const_iterator BBI = F->begin(), BBE = F->end(); BBI != BBE; 85 for (Function::const_iterator BBI = F->begin(), BBE = F->end(); BBI != BBE;
87 ++BBI) { 86 ++BBI) {
88 CurrentNode = mapBasicBlockToNode(BBI);
89 convertBasicBlock(BBI); 87 convertBasicBlock(BBI);
90 } 88 }
91 Func->setEntryNode(mapBasicBlockToNode(&F->getEntryBlock())); 89 Func->setEntryNode(mapBasicBlockToNode(&F->getEntryBlock()));
92 Func->computePredecessors(); 90 Func->computePredecessors();
93 91
94 return Func; 92 return Func;
95 } 93 }
96 94
97 // convertConstant() does not use Func or require it to be a valid 95 // convertConstant() does not use Func or require it to be a valid
98 // Ice::Cfg pointer. As such, it's suitable for e.g. constructing 96 // Ice::Cfg pointer. As such, it's suitable for e.g. constructing
(...skipping 26 matching lines...) Expand all
125 } 123 }
126 124
127 private: 125 private:
128 // LLVM values (instructions, etc.) are mapped directly to ICE variables. 126 // LLVM values (instructions, etc.) are mapped directly to ICE variables.
129 // mapValueToIceVar has a version that forces an ICE type on the variable, 127 // mapValueToIceVar has a version that forces an ICE type on the variable,
130 // and a version that just uses convertToIceType on V. 128 // and a version that just uses convertToIceType on V.
131 Ice::Variable *mapValueToIceVar(const Value *V, Ice::Type IceTy) { 129 Ice::Variable *mapValueToIceVar(const Value *V, Ice::Type IceTy) {
132 if (IceTy == Ice::IceType_void) 130 if (IceTy == Ice::IceType_void)
133 return NULL; 131 return NULL;
134 if (VarMap.find(V) == VarMap.end()) { 132 if (VarMap.find(V) == VarMap.end()) {
135 assert(CurrentNode); 133 VarMap[V] = Func->makeVariable(IceTy, V->getName());
136 VarMap[V] = Func->makeVariable(IceTy, CurrentNode, V->getName());
137 } 134 }
138 return VarMap[V]; 135 return VarMap[V];
139 } 136 }
140 137
141 Ice::Variable *mapValueToIceVar(const Value *V) { 138 Ice::Variable *mapValueToIceVar(const Value *V) {
142 return mapValueToIceVar(V, convertToIceType(V->getType())); 139 return mapValueToIceVar(V, convertToIceType(V->getType()));
143 } 140 }
144 141
145 Ice::CfgNode *mapBasicBlockToNode(const BasicBlock *BB) { 142 Ice::CfgNode *mapBasicBlockToNode(const BasicBlock *BB) {
146 if (NodeMap.find(BB) == NodeMap.end()) { 143 if (NodeMap.find(BB) == NodeMap.end()) {
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 report_fatal_error(StrBuf.str()); 604 report_fatal_error(StrBuf.str());
608 break; 605 break;
609 } 606 }
610 } 607 }
611 } 608 }
612 609
613 private: 610 private:
614 // Data 611 // Data
615 Ice::GlobalContext *Ctx; 612 Ice::GlobalContext *Ctx;
616 Ice::Cfg *Func; 613 Ice::Cfg *Func;
617 Ice::CfgNode *CurrentNode;
618 std::map<const Value *, Ice::Variable *> VarMap; 614 std::map<const Value *, Ice::Variable *> VarMap;
619 std::map<const BasicBlock *, Ice::CfgNode *> NodeMap; 615 std::map<const BasicBlock *, Ice::CfgNode *> NodeMap;
620 Ice::TypeConverter TypeConverter; 616 Ice::TypeConverter TypeConverter;
621 }; 617 };
622 618
623 } // end of anonymous namespace 619 } // end of anonymous namespace
624 620
625 namespace Ice { 621 namespace Ice {
626 622
627 void Converter::convertToIce() { 623 void Converter::convertToIce() {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 << Fcn->getFunctionName() << ": " << TConvert.getElapsedSec() 683 << Fcn->getFunctionName() << ": " << TConvert.getElapsedSec()
688 << " sec\n"; 684 << " sec\n";
689 } 685 }
690 translateFcn(Fcn); 686 translateFcn(Fcn);
691 } 687 }
692 688
693 emitConstants(); 689 emitConstants();
694 } 690 }
695 691
696 } // end of namespace Ice 692 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceCfgNode.cpp ('k') | src/IceDefs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698