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

Side by Side Diff: src/IceTargetLowering.cpp

Issue 1775253003: Cache common constants before lowering. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Clean up code. Created 4 years, 9 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
OLDNEW
1 //===- subzero/src/IceTargetLowering.cpp - Basic lowering implementation --===// 1 //===- subzero/src/IceTargetLowering.cpp - Basic lowering implementation --===//
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 /// \file 10 /// \file
11 /// \brief Implements the skeleton of the TargetLowering class. 11 /// \brief Implements the skeleton of the TargetLowering class.
12 /// 12 ///
13 /// Specifically this invokes the appropriate lowering method for a given 13 /// Specifically this invokes the appropriate lowering method for a given
14 /// instruction kind and driving global register allocation. It also implements 14 /// instruction kind and driving global register allocation. It also implements
15 /// the non-deleted instruction iteration in LoweringContext. 15 /// the non-deleted instruction iteration in LoweringContext.
16 /// 16 ///
17 //===----------------------------------------------------------------------===// 17 //===----------------------------------------------------------------------===//
18 18
19 #include "IceTargetLowering.h" 19 #include "IceTargetLowering.h"
20 #include "IceTargetLowering.def"
20 21
21 #include "IceBitVector.h" 22 #include "IceBitVector.h"
22 #include "IceCfg.h" // setError() 23 #include "IceCfg.h" // setError()
23 #include "IceCfgNode.h" 24 #include "IceCfgNode.h"
24 #include "IceGlobalContext.h" 25 #include "IceGlobalContext.h"
25 #include "IceGlobalInits.h" 26 #include "IceGlobalInits.h"
26 #include "IceInstVarIter.h" 27 #include "IceInstVarIter.h"
27 #include "IceOperand.h" 28 #include "IceOperand.h"
28 #include "IceRegAlloc.h" 29 #include "IceRegAlloc.h"
29 30
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 #define SUBZERO_TARGET(X) \ 253 #define SUBZERO_TARGET(X) \
253 case Target_##X: \ 254 case Target_##X: \
254 return ::X::createTargetLowering(Func); 255 return ::X::createTargetLowering(Func);
255 #include "llvm/Config/SZTargets.def" 256 #include "llvm/Config/SZTargets.def"
256 #undef SUBZERO_TARGET 257 #undef SUBZERO_TARGET
257 } 258 }
258 } 259 }
259 260
260 void TargetLowering::staticInit(GlobalContext *Ctx) { 261 void TargetLowering::staticInit(GlobalContext *Ctx) {
261 const TargetArch Target = Ctx->getFlags().getTargetArch(); 262 const TargetArch Target = Ctx->getFlags().getTargetArch();
263 // Define zero constants used in translation.
264 {
265 #define X(Ty) \
John 2016/03/09 23:26:56 This looks dangerous in the context of the browser
Karl 2016/03/16 22:50:52 Done.
266 ConstZeroForType[IceType_##Ty] = Ctx->getConstantZero(IceType_##Ty);
John 2016/03/09 23:26:56 It would be better if this used ICETYPE_TABLE... Y
Karl 2016/03/16 22:50:52 Since I moved the caching within method getConstan
267 CONSTANT_ZERO_BY_TYPE_TABLE
268 #undef X
269 }
270 // Define runtime helper functions.
Karl 2016/03/16 22:50:52 Moved initialization of helper function names to g
271 {
272 #define X(Tag, Name) \
273 RuntimeHelperFunc[H_##Tag] = Ctx->getConstantExternSym(Name);
274 RUNTIME_HELPER_FUNCTIONS_TABLE
275 #undef X
276 }
262 // Call the specified target's static initializer. 277 // Call the specified target's static initializer.
263 switch (Target) { 278 switch (Target) {
264 default: 279 default:
265 badTargetFatalError(Target); 280 badTargetFatalError(Target);
266 #define SUBZERO_TARGET(X) \ 281 #define SUBZERO_TARGET(X) \
267 case Target_##X: { \ 282 case Target_##X: { \
268 static bool InitGuard##X = false; \ 283 static bool InitGuard##X = false; \
269 if (InitGuard##X) { \ 284 if (InitGuard##X) { \
270 return; \ 285 return; \
271 } \ 286 } \
(...skipping 10 matching lines...) Expand all
282 assert(!Flags.getUseSandboxing() || !Flags.getUseNonsfi()); 297 assert(!Flags.getUseSandboxing() || !Flags.getUseNonsfi());
283 if (Flags.getUseNonsfi()) { 298 if (Flags.getUseNonsfi()) {
284 return TargetLowering::ST_Nonsfi; 299 return TargetLowering::ST_Nonsfi;
285 } 300 }
286 if (Flags.getUseSandboxing()) { 301 if (Flags.getUseSandboxing()) {
287 return TargetLowering::ST_NaCl; 302 return TargetLowering::ST_NaCl;
288 } 303 }
289 return TargetLowering::ST_None; 304 return TargetLowering::ST_None;
290 } 305 }
291 306
307 Constant *TargetLowering::ConstZeroForType[IceType_NUM] = {
Karl 2016/03/16 22:50:52 Removed these initializations and moved to the con
308 #define X(tag, sizeLog2, align, elts, elty, str, rcstr) nullptr,
309 ICETYPE_TABLE
310 #undef X
311 };
312
313 Constant *TargetLowering::RuntimeHelperFunc[H_Num] = {
314 #define X(Tag, Name) nullptr,
315 RUNTIME_HELPER_FUNCTIONS_TABLE
316 #undef X
317 };
318
292 TargetLowering::TargetLowering(Cfg *Func) 319 TargetLowering::TargetLowering(Cfg *Func)
293 : Func(Func), Ctx(Func->getContext()), 320 : Func(Func), Ctx(Func->getContext()),
294 SandboxingType(determineSandboxTypeFromFlags(Ctx->getFlags())) {} 321 SandboxingType(determineSandboxTypeFromFlags(Ctx->getFlags())) {}
295 322
296 TargetLowering::AutoBundle::AutoBundle(TargetLowering *Target, 323 TargetLowering::AutoBundle::AutoBundle(TargetLowering *Target,
297 InstBundleLock::Option Option) 324 InstBundleLock::Option Option)
298 : Target(Target), 325 : Target(Target),
299 NeedSandboxing(Target->Ctx->getFlags().getUseSandboxing()) { 326 NeedSandboxing(Target->Ctx->getFlags().getUseSandboxing()) {
300 assert(!Target->AutoBundling); 327 assert(!Target->AutoBundling);
301 Target->AutoBundling = true; 328 Target->AutoBundling = true;
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 } else { 714 } else {
688 NextStackOffset += Increment; 715 NextStackOffset += Increment;
689 } 716 }
690 if (UsesFramePointer) 717 if (UsesFramePointer)
691 Var->setStackOffset(-NextStackOffset); 718 Var->setStackOffset(-NextStackOffset);
692 else 719 else
693 Var->setStackOffset(SpillAreaSizeBytes - NextStackOffset); 720 Var->setStackOffset(SpillAreaSizeBytes - NextStackOffset);
694 } 721 }
695 } 722 }
696 723
697 InstCall *TargetLowering::makeHelperCall(const IceString &Name, Variable *Dest, 724 InstCall *TargetLowering::makeHelperCall(RuntimeHelperFuncKind Target,
698 SizeT MaxSrcs) { 725 Variable *Dest, SizeT MaxSrcs) {
699 constexpr bool HasTailCall = false; 726 constexpr bool HasTailCall = false;
700 Constant *CallTarget = Ctx->getConstantExternSym(Name); 727 Operand *CallTarget = getRuntimeHelperFunc(Target);
701 InstCall *Call = 728 InstCall *Call =
702 InstCall::create(Func, MaxSrcs, Dest, CallTarget, HasTailCall); 729 InstCall::create(Func, MaxSrcs, Dest, CallTarget, HasTailCall);
703 return Call; 730 return Call;
704 } 731 }
705 732
706 bool TargetLowering::shouldOptimizeMemIntrins() { 733 bool TargetLowering::shouldOptimizeMemIntrins() {
707 return Ctx->getFlags().getOptLevel() >= Opt_1 || 734 return Ctx->getFlags().getOptLevel() >= Opt_1 ||
708 Ctx->getFlags().getForceMemIntrinOpt(); 735 Ctx->getFlags().getForceMemIntrinOpt();
709 } 736 }
710 737
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 case Target_##X: \ 906 case Target_##X: \
880 return ::X::createTargetHeaderLowering(Ctx); 907 return ::X::createTargetHeaderLowering(Ctx);
881 #include "llvm/Config/SZTargets.def" 908 #include "llvm/Config/SZTargets.def"
882 #undef SUBZERO_TARGET 909 #undef SUBZERO_TARGET
883 } 910 }
884 } 911 }
885 912
886 TargetHeaderLowering::~TargetHeaderLowering() = default; 913 TargetHeaderLowering::~TargetHeaderLowering() = default;
887 914
888 } // end of namespace Ice 915 } // end of namespace Ice
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698