Subzero. Introduces a new LoweringContext::insert() method.
Emitting an instruction in Subzero requires a fair amount of
boilerplated code:
Context.insert(<InstType>::create(Func, <Args>...));
The ordeal is worse if one needs access to the recently create
instructionL
auto *Instr = <InstType>::create(Func, <Args>...);
Context.insert(Instr);
Instr->...
This CL introduces a new LoweringContext::insert() method:
template <<InstType>, <Args>...>
<InstType> *LoweringContext::insert(<Args>...) {
auto *New = Inst::create(Node.Cfg, <Args>...);
insert(New);
return New;
}
This is essentially a syntatic sugar that allows instructions to be
emitted by using
Context.insert<InstType>(<Args>...);
The compiler should be able to inline the calls (and get rid of the
return value) when appropriate.
make bloat reviews a small increase in translator code size
BUG=
R=sehr@chromium.org, stichnot@chromium.org
Review URL: https://codereview.chromium.org/1527143003 .
diff --git a/src/IceTargetLowering.h b/src/IceTargetLowering.h
index 045173b..3d139c0 100644
--- a/src/IceTargetLowering.h
+++ b/src/IceTargetLowering.h
@@ -23,11 +23,14 @@
#ifndef SUBZERO_SRC_ICETARGETLOWERING_H
#define SUBZERO_SRC_ICETARGETLOWERING_H
+#include "IceCfgNode.h"
#include "IceDefs.h"
#include "IceInst.h" // for the names of the Inst subtypes
#include "IceOperand.h"
#include "IceTypes.h"
+#include <utility>
+
namespace Ice {
// UnimplementedError is defined as a macro so that we can get actual line
@@ -72,6 +75,11 @@
InstList::iterator getNext() const { return Next; }
InstList::iterator getEnd() const { return End; }
void insert(Inst *Inst);
+ template <typename Inst, typename... Args> Inst *insert(Args &&... A) {
+ auto *New = Inst::create(Node->getCfg(), std::forward<Args>(A)...);
+ insert(New);
+ return New;
+ }
Inst *getLastInserted() const;
void advanceCur() { Cur = Next; }
void advanceNext() { advanceForward(Next); }
@@ -370,9 +378,9 @@
void
_bundle_lock(InstBundleLock::Option BundleOption = InstBundleLock::Opt_None) {
- Context.insert(InstBundleLock::create(Func, BundleOption));
+ Context.insert<InstBundleLock>(BundleOption);
}
- void _bundle_unlock() { Context.insert(InstBundleUnlock::create(Func)); }
+ void _bundle_unlock() { Context.insert<InstBundleUnlock>(); }
void _set_dest_redefined() { Context.getLastInserted()->setDestRedefined(); }
bool shouldOptimizeMemIntrins();