Chromium Code Reviews| Index: src/IceTargetLowering.cpp |
| diff --git a/src/IceTargetLowering.cpp b/src/IceTargetLowering.cpp |
| index dcbb8802924eb948b04a64e69a9877f910e54462..c41a62b20ee99b0d568188a9f3d494421dcae296 100644 |
| --- a/src/IceTargetLowering.cpp |
| +++ b/src/IceTargetLowering.cpp |
| @@ -18,23 +18,43 @@ |
| #include "IceTargetLowering.h" |
| -#include "IceAssemblerARM32.h" |
| -#include "IceAssemblerMIPS32.h" |
| -#include "IceAssemblerX8632.h" |
| -#include "IceAssemblerX8664.h" |
| #include "IceCfg.h" // setError() |
| #include "IceCfgNode.h" |
| +#include "IceGlobalContext.h" |
| #include "IceGlobalInits.h" |
| #include "IceInstVarIter.h" |
| #include "IceOperand.h" |
| #include "IceRegAlloc.h" |
| -#include "IceTargetLoweringARM32.h" |
| -#include "IceTargetLoweringMIPS32.h" |
| -#include "IceTargetLoweringX8632.h" |
| -#include "IceTargetLoweringX8664.h" |
| -namespace Ice { |
| +// We prevent target-specific implementation details from leaking outside their |
| +// implementations by forbidden #include of target-specific header files |
|
Jim Stichnoth
2015/12/30 01:26:42
forbidding
John
2016/01/19 20:37:30
Done.
|
| +// anywhere outside their own files. To create target-specific objects |
| +// (TargetLowering, TargetDataLowering, and TargetHeaderLowering) we use the |
| +// following named constructors. For reference, each target Foo needs to |
| +// implement the following named constructors and initializer: |
| +// |
| +// namespace Foo { |
| +// unique_ptr<Ice::TargetLowering> createTargetLowering(Ice::Cfg *); |
| +// unique_ptr<Ice::TargetDataLowering> |
| +// createTargetDataLowering(Ice::GlobalContext*); |
| +// unique_ptr<Ice::TargetHeaderLowering> |
| +// createTargetHeaderLowering(Ice::GlobalContext *); |
| +// void staticInit(); |
| +// } |
| +#define SUBZERO_TARGET(X) \ |
| + namespace X { \ |
| + std::unique_ptr<::Ice::TargetLowering> \ |
| + createTargetLowering(::Ice::Cfg *Func); \ |
| + std::unique_ptr<::Ice::TargetDataLowering> \ |
| + createTargetDataLowering(::Ice::GlobalContext *Ctx); \ |
| + std::unique_ptr<::Ice::TargetHeaderLowering> \ |
| + createTargetHeaderLowering(::Ice::GlobalContext *Ctx); \ |
| + void staticInit(); \ |
| + } // end of namespace X |
| +#include "llvm/Config/SZTargets.def" |
| +#undef SUBZERO_TARGET |
| +namespace Ice { |
| void LoweringContext::init(CfgNode *N) { |
| Node = N; |
| End = getNode()->getInsts().end(); |
| @@ -96,48 +116,40 @@ Variable *LoweringContext::availabilityGet(Operand *Src) const { |
| return nullptr; |
| } |
| -TargetLowering *TargetLowering::createLowering(TargetArch Target, Cfg *Func) { |
| +std::unique_ptr<TargetLowering> |
| +TargetLowering::createLowering(TargetArch Target, Cfg *Func) { |
| + switch (Target) { |
| + default: |
| + llvm::report_fatal_error("Unsupported target"); |
| #define SUBZERO_TARGET(X) \ |
| - if (Target == Target_##X) \ |
| - return Target##X::create(Func); |
| + case Target_##X: \ |
| + return ::X::createTargetLowering(Func); |
| #include "llvm/Config/SZTargets.def" |
| - |
| - Func->setError("Unsupported target"); |
| - return nullptr; |
| +#undef SUBZERO_TARGET |
| + } |
| } |
| void TargetLowering::staticInit(TargetArch Target) { |
| - // Call the specified target's static initializer. |
| switch (Target) { |
| default: |
| llvm::report_fatal_error("Unsupported target"); |
| - break; |
| #define SUBZERO_TARGET(X) \ |
| case Target_##X: { \ |
| static bool InitGuard##X = false; \ |
| - if (InitGuard##X) \ |
| + if (InitGuard##X) { \ |
| return; \ |
| + } \ |
| InitGuard##X = true; \ |
| - Target##X::staticInit(); \ |
| - } break; |
| -#include "llvm/Config/SZTargets.def" |
| + ::X::staticInit(); \ |
| } |
| +#include "llvm/Config/SZTargets.def" |
| +#undef SUBZERO_TARGET |
| + } // Call the specified target's static initializer. |
|
Jim Stichnoth
2015/12/30 01:26:42
Is this comment out of place?
John
2016/01/19 20:37:30
Done.
|
| } |
| TargetLowering::TargetLowering(Cfg *Func) |
| : Func(Func), Ctx(Func->getContext()), Context() {} |
| -std::unique_ptr<Assembler> TargetLowering::createAssembler(TargetArch Target, |
| - Cfg *Func) { |
| -#define SUBZERO_TARGET(X) \ |
| - if (Target == Target_##X) \ |
| - return std::unique_ptr<Assembler>(new X::Assembler##X()); |
| -#include "llvm/Config/SZTargets.def" |
| - |
| - Func->setError("Unsupported target assembler"); |
| - return nullptr; |
| -} |
| - |
| void TargetLowering::genTargetHelperCalls() { |
| for (CfgNode *Node : Func->getNodes()) { |
| Context.init(Node); |
| @@ -539,12 +551,15 @@ void TargetLowering::emit(const ConstantRelocatable *C) const { |
| std::unique_ptr<TargetDataLowering> |
| TargetDataLowering::createLowering(GlobalContext *Ctx) { |
| TargetArch Target = Ctx->getFlags().getTargetArch(); |
| + switch (Target) { |
| + default: |
| + llvm::report_fatal_error("Unsupported target"); |
| #define SUBZERO_TARGET(X) \ |
| - if (Target == Target_##X) \ |
| - return TargetData##X::create(Ctx); |
| + case Target_##X: \ |
| + return ::X::createTargetDataLowering(Ctx); |
| #include "llvm/Config/SZTargets.def" |
| - |
| - llvm::report_fatal_error("Unsupported target data lowering"); |
| +#undef SUBZERO_TARGET |
| + } |
| } |
| TargetDataLowering::~TargetDataLowering() = default; |
| @@ -661,12 +676,15 @@ void TargetDataLowering::emitGlobal(const VariableDeclaration &Var, |
| std::unique_ptr<TargetHeaderLowering> |
| TargetHeaderLowering::createLowering(GlobalContext *Ctx) { |
| TargetArch Target = Ctx->getFlags().getTargetArch(); |
| + switch (Target) { |
| + default: |
| + llvm::report_fatal_error("Unsupported target"); |
| #define SUBZERO_TARGET(X) \ |
| - if (Target == Target_##X) \ |
| - return TargetHeader##X::create(Ctx); |
| + case Target_##X: \ |
| + return ::X::createTargetHeaderLowering(Ctx); |
| #include "llvm/Config/SZTargets.def" |
| - |
| - llvm::report_fatal_error("Unsupported target header lowering"); |
| +#undef SUBZERO_TARGET |
| + } |
| } |
| TargetHeaderLowering::~TargetHeaderLowering() = default; |