blob: 4d9598a2448b917379a42116f9665307e8034700 [file] [log] [blame]
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -07001//===- subzero/src/IceTargetLowering.h - Lowering interface -----*- C++ -*-===//
2//
3// The Subzero Code Generator
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Jim Stichnothbbca7542015-02-11 16:08:31 -080010// This file declares the TargetLowering, LoweringContext, and
11// TargetDataLowering classes. TargetLowering is an abstract class
12// used to drive the translation/lowering process. LoweringContext
13// maintains a context for lowering each instruction, offering
14// conveniences such as iterating over non-deleted instructions.
15// TargetDataLowering is an abstract class used to drive the
16// lowering/emission of global initializers, external global
17// declarations, and internal constant pools.
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070018//
19//===----------------------------------------------------------------------===//
20
21#ifndef SUBZERO_SRC_ICETARGETLOWERING_H
22#define SUBZERO_SRC_ICETARGETLOWERING_H
23
24#include "IceDefs.h"
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070025#include "IceInst.h" // for the names of the Inst subtypes
Jan Voung76bb0be2015-05-14 09:26:19 -070026#include "IceOperand.h"
Jim Stichnotha18cc9c2014-09-30 19:10:22 -070027#include "IceTypes.h"
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070028
29namespace Ice {
30
31// LoweringContext makes it easy to iterate through non-deleted
32// instructions in a node, and insert new (lowered) instructions at
33// the current point. Along with the instruction list container and
34// associated iterators, it holds the current node, which is needed
35// when inserting new instructions in order to track whether variables
36// are used as single-block or multi-block.
37class LoweringContext {
Jim Stichnoth7b451a92014-10-15 14:39:23 -070038 LoweringContext(const LoweringContext &) = delete;
39 LoweringContext &operator=(const LoweringContext &) = delete;
40
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070041public:
Jim Stichnothae953202014-12-20 06:17:49 -080042 LoweringContext() : Node(nullptr), LastInserted(nullptr) {}
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070043 ~LoweringContext() {}
44 void init(CfgNode *Node);
45 Inst *getNextInst() const {
46 if (Next == End)
Jim Stichnothae953202014-12-20 06:17:49 -080047 return nullptr;
Jim Stichnoth607e9f02014-11-06 13:32:05 -080048 return Next;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070049 }
Jan Voungc820ddf2014-07-29 14:38:51 -070050 Inst *getNextInst(InstList::iterator &Iter) const {
Jan Vounge6e497d2014-07-30 10:06:03 -070051 advanceForward(Iter);
Jan Voungc820ddf2014-07-29 14:38:51 -070052 if (Iter == End)
Jim Stichnothae953202014-12-20 06:17:49 -080053 return nullptr;
Jim Stichnoth607e9f02014-11-06 13:32:05 -080054 return Iter;
Jan Voungc820ddf2014-07-29 14:38:51 -070055 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070056 CfgNode *getNode() const { return Node; }
57 bool atEnd() const { return Cur == End; }
58 InstList::iterator getCur() const { return Cur; }
Jim Stichnoth5d2fa0c2014-12-01 09:30:55 -080059 InstList::iterator getNext() const { return Next; }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070060 InstList::iterator getEnd() const { return End; }
61 void insert(Inst *Inst);
Jan Vounge6e497d2014-07-30 10:06:03 -070062 Inst *getLastInserted() const;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070063 void advanceCur() { Cur = Next; }
Jan Vounge6e497d2014-07-30 10:06:03 -070064 void advanceNext() { advanceForward(Next); }
Jim Stichnoth336f6c42014-10-30 15:01:31 -070065 void rewind();
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070066 void setInsertPoint(const InstList::iterator &Position) { Next = Position; }
67
68private:
69 // Node is the argument to Inst::updateVars().
70 CfgNode *Node;
Jim Stichnoth98712a32014-10-24 10:59:02 -070071 Inst *LastInserted;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070072 // Cur points to the current instruction being considered. It is
73 // guaranteed to point to a non-deleted instruction, or to be End.
74 InstList::iterator Cur;
75 // Next doubles as a pointer to the next valid instruction (if any),
76 // and the new-instruction insertion point. It is also updated for
77 // the caller in case the lowering consumes more than one high-level
78 // instruction. It is guaranteed to point to a non-deleted
79 // instruction after Cur, or to be End. TODO: Consider separating
80 // the notion of "next valid instruction" and "new instruction
81 // insertion point", to avoid confusion when previously-deleted
82 // instructions come between the two points.
83 InstList::iterator Next;
Jan Vounge6e497d2014-07-30 10:06:03 -070084 // Begin is a copy of Insts.begin(), used if iterators are moved backward.
85 InstList::iterator Begin;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070086 // End is a copy of Insts.end(), used if Next needs to be advanced.
87 InstList::iterator End;
88
Jan Voungc820ddf2014-07-29 14:38:51 -070089 void skipDeleted(InstList::iterator &I) const;
Jan Vounge6e497d2014-07-30 10:06:03 -070090 void advanceForward(InstList::iterator &I) const;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070091};
92
93class TargetLowering {
Jim Stichnothc6ead202015-02-24 09:30:30 -080094 TargetLowering() = delete;
Jim Stichnoth7b451a92014-10-15 14:39:23 -070095 TargetLowering(const TargetLowering &) = delete;
96 TargetLowering &operator=(const TargetLowering &) = delete;
97
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070098public:
Jan Voungb36ad9b2015-04-21 17:01:49 -070099 // TODO(jvoung): return a unique_ptr like the other factory functions.
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700100 static TargetLowering *createLowering(TargetArch Target, Cfg *Func);
Jan Voungec270732015-01-12 17:00:22 -0800101 static std::unique_ptr<Assembler> createAssembler(TargetArch Target,
102 Cfg *Func);
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700103 void translate() {
Jan Voung1f47ad02015-03-20 15:01:26 -0700104 switch (Ctx->getFlags().getOptLevel()) {
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700105 case Opt_m1:
106 translateOm1();
107 break;
108 case Opt_0:
109 translateO0();
110 break;
111 case Opt_1:
112 translateO1();
113 break;
114 case Opt_2:
115 translateO2();
116 break;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700117 }
118 }
119 virtual void translateOm1() {
120 Func->setError("Target doesn't specify Om1 lowering steps.");
121 }
122 virtual void translateO0() {
123 Func->setError("Target doesn't specify O0 lowering steps.");
124 }
125 virtual void translateO1() {
126 Func->setError("Target doesn't specify O1 lowering steps.");
127 }
128 virtual void translateO2() {
129 Func->setError("Target doesn't specify O2 lowering steps.");
130 }
131
Jim Stichnothd97c7df2014-06-04 11:57:08 -0700132 // Tries to do address mode optimization on a single instruction.
133 void doAddressOpt();
Matt Walac3302742014-08-15 16:21:56 -0700134 // Randomly insert NOPs.
135 void doNopInsertion();
Jim Stichnoth336f6c42014-10-30 15:01:31 -0700136 // Lowers a single non-Phi instruction.
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700137 void lower();
Jim Stichnoth336f6c42014-10-30 15:01:31 -0700138 // Does preliminary lowering of the set of Phi instructions in the
139 // current node. The main intention is to do what's needed to keep
140 // the unlowered Phi instructions consistent with the lowered
141 // non-Phi instructions, e.g. to lower 64-bit operands on a 32-bit
142 // target.
143 virtual void prelowerPhis() {}
144 // Lowers a list of "parallel" assignment instructions representing
145 // a topological sort of the Phi instructions.
146 virtual void lowerPhiAssignments(CfgNode *Node,
147 const AssignList &Assignments) = 0;
Jim Stichnothff9c7062014-09-18 04:50:49 -0700148 // Tries to do branch optimization on a single instruction. Returns
149 // true if some optimization was done.
150 virtual bool doBranchOpt(Inst * /*I*/, const CfgNode * /*NextNode*/) {
151 return false;
152 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700153
Jim Stichnoth3d44fe82014-11-01 10:10:18 -0700154 virtual SizeT getNumRegisters() const = 0;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700155 // Returns a variable pre-colored to the specified physical
156 // register. This is generally used to get very direct access to
157 // the register such as in the prolog or epilog or for marking
Jim Stichnoth98712a32014-10-24 10:59:02 -0700158 // scratch registers as killed by a call. If a Type is not
159 // provided, a target-specific default type is used.
160 virtual Variable *getPhysicalRegister(SizeT RegNum,
161 Type Ty = IceType_void) = 0;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700162 // Returns a printable name for the register.
163 virtual IceString getRegName(SizeT RegNum, Type Ty) const = 0;
164
165 virtual bool hasFramePointer() const { return false; }
166 virtual SizeT getFrameOrStackReg() const = 0;
Matt Walad4799f42014-08-14 14:24:12 -0700167 virtual size_t typeWidthInBytesOnStack(Type Ty) const = 0;
Jan Voung0fa6c5a2015-06-01 11:04:04 -0700168
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700169 bool hasComputedFrame() const { return HasComputedFrame; }
Jan Voung44d53e12014-09-11 19:18:03 -0700170 // Returns true if this function calls a function that has the
171 // "returns twice" attribute.
172 bool callsReturnsTwice() const { return CallsReturnsTwice; }
Jim Stichnothdd842db2015-01-27 12:53:53 -0800173 void setCallsReturnsTwice(bool RetTwice) { CallsReturnsTwice = RetTwice; }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700174 int32_t getStackAdjustment() const { return StackAdjustment; }
175 void updateStackAdjustment(int32_t Offset) { StackAdjustment += Offset; }
176 void resetStackAdjustment() { StackAdjustment = 0; }
Jan Voungb36ad9b2015-04-21 17:01:49 -0700177 SizeT makeNextLabelNumber() { return NextLabelNumber++; }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700178 LoweringContext &getContext() { return Context; }
179
180 enum RegSet {
181 RegSet_None = 0,
182 RegSet_CallerSave = 1 << 0,
183 RegSet_CalleeSave = 1 << 1,
184 RegSet_StackPointer = 1 << 2,
185 RegSet_FramePointer = 1 << 3,
186 RegSet_All = ~RegSet_None
187 };
188 typedef uint32_t RegSetMask;
189
190 virtual llvm::SmallBitVector getRegisterSet(RegSetMask Include,
191 RegSetMask Exclude) const = 0;
192 virtual const llvm::SmallBitVector &getRegisterSetForType(Type Ty) const = 0;
Jim Stichnoth70d0a052014-11-14 15:53:46 -0800193 void regAlloc(RegAllocKind Kind);
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700194
Jim Stichnothe6d24782014-12-19 05:42:24 -0800195 virtual void makeRandomRegisterPermutation(
196 llvm::SmallVectorImpl<int32_t> &Permutation,
197 const llvm::SmallBitVector &ExcludeRegisters) const = 0;
198
Jim Stichnoth9738a9e2015-02-23 16:39:06 -0800199 // Save/restore any mutable state for the situation where code
200 // emission needs multiple passes, such as sandboxing or relaxation.
201 // Subclasses may provide their own implementation, but should be
202 // sure to also call the parent class's methods.
203 virtual void snapshotEmitState() {
204 SnapshotStackAdjustment = StackAdjustment;
205 }
206 virtual void rollbackEmitState() {
207 StackAdjustment = SnapshotStackAdjustment;
208 }
209
Jim Stichnoth144cdce2014-09-22 16:02:59 -0700210 virtual void emitVariable(const Variable *Var) const = 0;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700211
Jan Voung76bb0be2015-05-14 09:26:19 -0700212 void emitWithoutPrefix(const ConstantRelocatable *CR) const;
213 void emit(const ConstantRelocatable *CR) const;
214 virtual const char *getConstantPrefix() const = 0;
215
216 virtual void emit(const ConstantUndef *C) const = 0;
217 virtual void emit(const ConstantInteger32 *C) const = 0;
218 virtual void emit(const ConstantInteger64 *C) const = 0;
219 virtual void emit(const ConstantFloat *C) const = 0;
220 virtual void emit(const ConstantDouble *C) const = 0;
221
Matt Wala45a06232014-07-09 16:33:22 -0700222 // Performs target-specific argument lowering.
223 virtual void lowerArguments() = 0;
224
Jim Stichnotha59ae6f2015-05-17 10:11:41 -0700225 virtual void initNodeForLowering(CfgNode *) {}
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700226 virtual void addProlog(CfgNode *Node) = 0;
227 virtual void addEpilog(CfgNode *Node) = 0;
228
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700229 virtual ~TargetLowering() {}
230
231protected:
Jim Stichnothc6ead202015-02-24 09:30:30 -0800232 explicit TargetLowering(Cfg *Func);
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700233 virtual void lowerAlloca(const InstAlloca *Inst) = 0;
234 virtual void lowerArithmetic(const InstArithmetic *Inst) = 0;
235 virtual void lowerAssign(const InstAssign *Inst) = 0;
236 virtual void lowerBr(const InstBr *Inst) = 0;
237 virtual void lowerCall(const InstCall *Inst) = 0;
238 virtual void lowerCast(const InstCast *Inst) = 0;
239 virtual void lowerFcmp(const InstFcmp *Inst) = 0;
Matt Wala49889232014-07-18 12:45:09 -0700240 virtual void lowerExtractElement(const InstExtractElement *Inst) = 0;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700241 virtual void lowerIcmp(const InstIcmp *Inst) = 0;
Matt Wala49889232014-07-18 12:45:09 -0700242 virtual void lowerInsertElement(const InstInsertElement *Inst) = 0;
Jan Voung3bd9f1a2014-06-18 10:50:57 -0700243 virtual void lowerIntrinsicCall(const InstIntrinsicCall *Inst) = 0;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700244 virtual void lowerLoad(const InstLoad *Inst) = 0;
245 virtual void lowerPhi(const InstPhi *Inst) = 0;
246 virtual void lowerRet(const InstRet *Inst) = 0;
247 virtual void lowerSelect(const InstSelect *Inst) = 0;
248 virtual void lowerStore(const InstStore *Inst) = 0;
249 virtual void lowerSwitch(const InstSwitch *Inst) = 0;
250 virtual void lowerUnreachable(const InstUnreachable *Inst) = 0;
251
Jim Stichnothd97c7df2014-06-04 11:57:08 -0700252 virtual void doAddressOptLoad() {}
253 virtual void doAddressOptStore() {}
Matt Walac3302742014-08-15 16:21:56 -0700254 virtual void randomlyInsertNop(float Probability) = 0;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700255 // This gives the target an opportunity to post-process the lowered
Jim Stichnoth70d0a052014-11-14 15:53:46 -0800256 // expansion before returning.
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700257 virtual void postLower() {}
258
Jan Voungb3401d22015-05-18 09:38:21 -0700259 // Find two-address non-SSA instructions and set the DestNonKillable flag
260 // to keep liveness analysis consistent.
261 void inferTwoAddress();
262
Jan Voung0fa6c5a2015-06-01 11:04:04 -0700263 // Make a pass over the Cfg to determine which variables need stack slots
264 // and place them in a sorted list (SortedSpilledVariables). Among those,
265 // vars, classify the spill variables as local to the basic block vs
266 // global (multi-block) in order to compute the parameters GlobalsSize
267 // and SpillAreaSizeBytes (represents locals or general vars if the
268 // coalescing of locals is disallowed) along with alignments required
269 // for variables in each area. We rely on accurate VMetadata in order to
270 // classify a variable as global vs local (otherwise the variable is
271 // conservatively global). The in-args should be initialized to 0.
272 //
273 // This is only a pre-pass and the actual stack slot assignment is
274 // handled separately.
275 //
276 // There may be target-specific Variable types, which will be handled
277 // by TargetVarHook. If the TargetVarHook returns true, then the variable
278 // is skipped and not considered with the rest of the spilled variables.
279 void getVarStackSlotParams(VarList &SortedSpilledVariables,
280 llvm::SmallBitVector &RegsUsed,
281 size_t *GlobalsSize, size_t *SpillAreaSizeBytes,
282 uint32_t *SpillAreaAlignmentBytes,
283 uint32_t *LocalsSlotsAlignmentBytes,
284 std::function<bool(Variable *)> TargetVarHook);
285
286 // Calculate the amount of padding needed to align the local and global
287 // areas to the required alignment. This assumes the globals/locals layout
288 // used by getVarStackSlotParams and assignVarStackSlots.
289 void alignStackSpillAreas(uint32_t SpillAreaStartOffset,
290 uint32_t SpillAreaAlignmentBytes,
291 size_t GlobalsSize,
292 uint32_t LocalsSlotsAlignmentBytes,
293 uint32_t *SpillAreaPaddingBytes,
294 uint32_t *LocalsSlotsPaddingBytes);
295
296 // Make a pass through the SortedSpilledVariables and actually assign
297 // stack slots. SpillAreaPaddingBytes takes into account stack alignment
298 // padding. The SpillArea starts after that amount of padding.
299 // This matches the scheme in getVarStackSlotParams, where there may
300 // be a separate multi-block global var spill area and a local var
301 // spill area.
302 void assignVarStackSlots(VarList &SortedSpilledVariables,
303 size_t SpillAreaPaddingBytes,
304 size_t SpillAreaSizeBytes,
305 size_t GlobalsAndSubsequentPaddingSize,
306 bool UsesFramePointer);
307
308 // Sort the variables in Source based on required alignment.
309 // The variables with the largest alignment need are placed in the front
310 // of the Dest list.
311 void sortVarsByAlignment(VarList &Dest, const VarList &Source) const;
312
Jan Voungb36ad9b2015-04-21 17:01:49 -0700313 // Make a call to an external helper function.
314 InstCall *makeHelperCall(const IceString &Name, Variable *Dest,
315 SizeT MaxSrcs);
316
Jan Voung0fa6c5a2015-06-01 11:04:04 -0700317 void
318 _bundle_lock(InstBundleLock::Option BundleOption = InstBundleLock::Opt_None) {
319 Context.insert(InstBundleLock::create(Func, BundleOption));
320 }
321 void _bundle_unlock() { Context.insert(InstBundleUnlock::create(Func)); }
322
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700323 Cfg *Func;
324 GlobalContext *Ctx;
325 bool HasComputedFrame;
Jan Voung44d53e12014-09-11 19:18:03 -0700326 bool CallsReturnsTwice;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700327 // StackAdjustment keeps track of the current stack offset from its
328 // natural location, as arguments are pushed for a function call.
329 int32_t StackAdjustment;
Jan Voungb36ad9b2015-04-21 17:01:49 -0700330 SizeT NextLabelNumber;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700331 LoweringContext Context;
Jim Stichnoth9738a9e2015-02-23 16:39:06 -0800332
Jim Stichnothc4508792015-03-01 23:12:55 -0800333 // Runtime helper function names
334 const static constexpr char *H_bitcast_16xi1_i16 = "__Sz_bitcast_16xi1_i16";
335 const static constexpr char *H_bitcast_8xi1_i8 = "__Sz_bitcast_8xi1_i8";
336 const static constexpr char *H_bitcast_i16_16xi1 = "__Sz_bitcast_i16_16xi1";
337 const static constexpr char *H_bitcast_i8_8xi1 = "__Sz_bitcast_i8_8xi1";
338 const static constexpr char *H_call_ctpop_i32 = "__popcountsi2";
339 const static constexpr char *H_call_ctpop_i64 = "__popcountdi2";
340 const static constexpr char *H_call_longjmp = "longjmp";
341 const static constexpr char *H_call_memcpy = "memcpy";
342 const static constexpr char *H_call_memmove = "memmove";
343 const static constexpr char *H_call_memset = "memset";
344 const static constexpr char *H_call_read_tp = "__nacl_read_tp";
345 const static constexpr char *H_call_setjmp = "setjmp";
346 const static constexpr char *H_fptosi_f32_i64 = "__Sz_fptosi_f32_i64";
347 const static constexpr char *H_fptosi_f64_i64 = "__Sz_fptosi_f64_i64";
348 const static constexpr char *H_fptoui_4xi32_f32 = "__Sz_fptoui_4xi32_f32";
349 const static constexpr char *H_fptoui_f32_i32 = "__Sz_fptoui_f32_i32";
350 const static constexpr char *H_fptoui_f32_i64 = "__Sz_fptoui_f32_i64";
351 const static constexpr char *H_fptoui_f64_i32 = "__Sz_fptoui_f64_i32";
352 const static constexpr char *H_fptoui_f64_i64 = "__Sz_fptoui_f64_i64";
353 const static constexpr char *H_frem_f32 = "fmodf";
354 const static constexpr char *H_frem_f64 = "fmod";
355 const static constexpr char *H_sdiv_i64 = "__divdi3";
356 const static constexpr char *H_sitofp_i64_f32 = "__Sz_sitofp_i64_f32";
357 const static constexpr char *H_sitofp_i64_f64 = "__Sz_sitofp_i64_f64";
358 const static constexpr char *H_srem_i64 = "__moddi3";
359 const static constexpr char *H_udiv_i64 = "__udivdi3";
360 const static constexpr char *H_uitofp_4xi32_4xf32 = "__Sz_uitofp_4xi32_4xf32";
361 const static constexpr char *H_uitofp_i32_f32 = "__Sz_uitofp_i32_f32";
362 const static constexpr char *H_uitofp_i32_f64 = "__Sz_uitofp_i32_f64";
363 const static constexpr char *H_uitofp_i64_f32 = "__Sz_uitofp_i64_f32";
364 const static constexpr char *H_uitofp_i64_f64 = "__Sz_uitofp_i64_f64";
365 const static constexpr char *H_urem_i64 = "__umoddi3";
366
Jim Stichnoth9738a9e2015-02-23 16:39:06 -0800367private:
368 int32_t SnapshotStackAdjustment;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700369};
370
Jan Voung72984d82015-01-29 14:42:38 -0800371// TargetDataLowering is used for "lowering" data including initializers
372// for global variables, and the internal constant pools. It is separated
373// out from TargetLowering because it does not require a Cfg.
374class TargetDataLowering {
375 TargetDataLowering() = delete;
376 TargetDataLowering(const TargetDataLowering &) = delete;
377 TargetDataLowering &operator=(const TargetDataLowering &) = delete;
Jim Stichnoth7b451a92014-10-15 14:39:23 -0700378
Jim Stichnothde4ca712014-06-29 08:13:48 -0700379public:
Jim Stichnothbbca7542015-02-11 16:08:31 -0800380 static std::unique_ptr<TargetDataLowering> createLowering(GlobalContext *Ctx);
Jan Voung72984d82015-01-29 14:42:38 -0800381 virtual ~TargetDataLowering();
Jan Voung839c4ce2014-07-28 15:19:43 -0700382
John Porto0f86d032015-06-15 07:44:27 -0700383 virtual void lowerGlobals(std::unique_ptr<VariableDeclarationList> Vars) = 0;
384 virtual void lowerConstants() = 0;
Jim Stichnothde4ca712014-06-29 08:13:48 -0700385
386protected:
Jan Voung58eea4d2015-06-15 15:11:56 -0700387 void emitGlobal(const VariableDeclaration &Var);
388
389 // For now, we assume .long is the right directive for emitting 4 byte
390 // emit global relocations. However, LLVM MIPS usually uses .4byte instead.
391 // Perhaps there is some difference when the location is unaligned.
392 const char *getEmit32Directive() { return ".long"; }
393
Jim Stichnothc6ead202015-02-24 09:30:30 -0800394 explicit TargetDataLowering(GlobalContext *Ctx) : Ctx(Ctx) {}
Jim Stichnothde4ca712014-06-29 08:13:48 -0700395 GlobalContext *Ctx;
Jim Stichnothde4ca712014-06-29 08:13:48 -0700396};
397
Jan Voungfb792842015-06-11 15:27:50 -0700398// TargetHeaderLowering is used to "lower" the header of an output file.
399// It writes out the target-specific header attributes. E.g., for ARM
400// this writes out the build attributes (float ABI, etc.).
401class TargetHeaderLowering {
402 TargetHeaderLowering() = delete;
403 TargetHeaderLowering(const TargetHeaderLowering &) = delete;
404 TargetHeaderLowering &operator=(const TargetHeaderLowering &) = delete;
405
406public:
407 static std::unique_ptr<TargetHeaderLowering>
408 createLowering(GlobalContext *Ctx);
409 virtual ~TargetHeaderLowering();
410
411 virtual void lower() {}
412
413protected:
414 explicit TargetHeaderLowering(GlobalContext *Ctx) : Ctx(Ctx) {}
415 GlobalContext *Ctx;
416};
417
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700418} // end of namespace Ice
419
420#endif // SUBZERO_SRC_ICETARGETLOWERING_H