#include "IceELFObjectWriter.h"
#include "IceGlobalInits.h"
#include "IceInst.h"
-#include "IceInstrumentation.h"
#include "IceInstVarIter.h"
+#include "IceInstrumentation.h"
#include "IceLiveness.h"
#include "IceLoopAnalyzer.h"
#include "IceOperand.h"
namespace Ice {
Cfg::Cfg(GlobalContext *Ctx, uint32_t SequenceNumber)
- : Ctx(Ctx), SequenceNumber(SequenceNumber), VMask(getFlags().getVerbose()),
- FunctionName(), NextInstNumber(Inst::NumberInitial), Live(nullptr) {
- Allocator.reset(new ArenaAllocator());
+ : Allocator(createAllocator()), Ctx(Ctx), SequenceNumber(SequenceNumber),
+ VMask(getFlags().getVerbose()), FunctionName(),
+ NextInstNumber(Inst::NumberInitial), Live(nullptr) {
NodeStrings.reset(new StringPool);
VarStrings.reset(new StringPool);
CfgLocalAllocatorScope _(this);
}
}
+// Called in the initalizer list of Cfg's constructor to create the Allocator
+// and set it as TLS before any other member fields are constructed, since they
+// may depend on it.
+ArenaAllocator *Cfg::createAllocator() {
+ ArenaAllocator *Allocator = new ArenaAllocator();
+ CfgAllocatorTraits::set_current(Allocator);
+ return Allocator;
+}
+
/// Create a string like "foo(i=123:b=9)" indicating the function name, number
/// of high-level instructions, and number of basic blocks. This string is only
/// used for dumping and other diagnostics, and the idea is that given a set of
Cfg(const Cfg &) = delete;
Cfg &operator=(const Cfg &) = delete;
+ std::unique_ptr<ArenaAllocator> Allocator;
+
public:
~Cfg();
CfgVector<Inst *>
findLoopInvariantInstructions(const CfgUnorderedSet<SizeT> &Body);
+ static ArenaAllocator *createAllocator();
+
GlobalContext *Ctx;
uint32_t SequenceNumber; /// output order for emission
OptLevel OptimizationLevel = Opt_m1;
VarList Variables;
VarList Args; /// subset of Variables, in argument order
VarList ImplicitArgs; /// subset of Variables
- std::unique_ptr<ArenaAllocator> Allocator;
// Separate string pools for CfgNode and Variable names, due to a combination
// of the uniqueness requirement, and assumptions in lit tests.
std::unique_ptr<StringPool> NodeStrings;
void CfgAllocatorTraits::set_current(const manager_type *Manager) {
ArenaAllocator *Allocator =
Manager == nullptr ? nullptr : Manager->Allocator.get();
+ set_current(Allocator);
+}
+
+void CfgAllocatorTraits::set_current(ArenaAllocator *Allocator) {
ICE_TLS_SET_FIELD(CfgAllocator, Allocator);
}
+void CfgAllocatorTraits::set_current(nullptr_t) {
+ ICE_TLS_SET_FIELD(CfgAllocator, nullptr);
+}
+
ICE_TLS_DEFINE_FIELD(ArenaAllocator *, LivenessAllocatorTraits,
LivenessAllocator);
static allocator_type current();
static void set_current(const manager_type *Manager);
+ static void set_current(ArenaAllocator *Allocator);
+ static void set_current(nullptr_t);
private:
ICE_TLS_DECLARE_FIELD(ArenaAllocator *, CfgAllocator);