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

Side by Side Diff: src/IceOperand.h

Issue 1651163002: Subzero. Enables moar complex relocation offsets. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Addresses comments. Created 4 years, 10 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/IceOperand.h - High-level operands -----------*- C++ -*-===// 1 //===- subzero/src/IceOperand.h - High-level operands -----------*- C++ -*-===//
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 Declares the Operand class and its target-independent subclasses. 11 /// \brief Declares the Operand class and its target-independent subclasses.
12 /// 12 ///
13 /// The main classes are Variable, which represents an LLVM variable that is 13 /// The main classes are Variable, which represents an LLVM variable that is
14 /// either register- or stack-allocated, and the Constant hierarchy, which 14 /// either register- or stack-allocated, and the Constant hierarchy, which
15 /// represents integer, floating-point, and/or symbolic constants. 15 /// represents integer, floating-point, and/or symbolic constants.
16 /// 16 ///
17 //===----------------------------------------------------------------------===// 17 //===----------------------------------------------------------------------===//
18 18
19 #ifndef SUBZERO_SRC_ICEOPERAND_H 19 #ifndef SUBZERO_SRC_ICEOPERAND_H
20 #define SUBZERO_SRC_ICEOPERAND_H 20 #define SUBZERO_SRC_ICEOPERAND_H
21 21
22 #include "IceCfg.h" 22 #include "IceCfg.h"
23 #include "IceDefs.h" 23 #include "IceDefs.h"
24 #include "IceGlobalContext.h" 24 #include "IceGlobalContext.h"
25 #include "IceTypes.h" 25 #include "IceTypes.h"
26 26
27 #include "llvm/Support/Format.h" 27 #include "llvm/Support/Format.h"
28 28
29 #include <limits>
Jim Stichnoth 2016/02/02 20:57:49 I don't think this is actually necessary, is it?
John 2016/02/03 15:50:41 well, numeric_limits appear in this file. leaving
30
29 namespace Ice { 31 namespace Ice {
30 32
31 class Operand { 33 class Operand {
32 Operand() = delete; 34 Operand() = delete;
33 Operand(const Operand &) = delete; 35 Operand(const Operand &) = delete;
34 Operand &operator=(const Operand &) = delete; 36 Operand &operator=(const Operand &) = delete;
35 37
36 public: 38 public:
37 static constexpr size_t MaxTargetKinds = 10; 39 static constexpr size_t MaxTargetKinds = 10;
38 enum OperandKind { 40 enum OperandKind {
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 bool ConstantInteger32::shouldBeRandomizedOrPooled(const GlobalContext *Ctx); 242 bool ConstantInteger32::shouldBeRandomizedOrPooled(const GlobalContext *Ctx);
241 243
242 template <> 244 template <>
243 inline void ConstantInteger64::dump(const Cfg *, Ostream &Str) const { 245 inline void ConstantInteger64::dump(const Cfg *, Ostream &Str) const {
244 if (!BuildDefs::dump()) 246 if (!BuildDefs::dump())
245 return; 247 return;
246 assert(getType() == IceType_i64); 248 assert(getType() == IceType_i64);
247 Str << static_cast<int64_t>(getValue()); 249 Str << static_cast<int64_t>(getValue());
248 } 250 }
249 251
252 /// RelocOffset allows symbolic references in ConstantRelocatables' offsets,
253 /// e.g., 8 + LabelOffset, where label offset is the location (code or data)
254 /// of a Label that is only determinable during ELF emission.
255 class RelocOffset final {
256 RelocOffset(const RelocOffset &) = delete;
257 RelocOffset &operator=(const RelocOffset &) = delete;
258
259 public:
260 static RelocOffset *create(GlobalContext *Ctx) {
261 return new (Ctx->allocate<RelocOffset>()) RelocOffset();
262 }
263
264 static RelocOffset *create(GlobalContext *Ctx, RelocOffsetT Value) {
265 return new (Ctx->allocate<RelocOffset>()) RelocOffset(Value);
266 }
267
268 bool hasOffset() const { return HasOffset; }
269
270 RelocOffsetT getOffset() const {
271 assert(HasOffset);
272 return Offset;
273 }
274
275 void setOffset(const RelocOffsetT Value) {
276 assert(!HasOffset);
277 Offset = Value;
278 HasOffset = true;
279 }
280
281 private:
282 RelocOffset() = default;
283 explicit RelocOffset(RelocOffsetT Offset) { setOffset(Offset); }
284
285 bool HasOffset = false;
286 RelocOffsetT Offset;
287 };
288
250 /// RelocatableTuple bundles the parameters that are used to construct an 289 /// RelocatableTuple bundles the parameters that are used to construct an
251 /// ConstantRelocatable. It is done this way so that ConstantRelocatable can fit 290 /// ConstantRelocatable. It is done this way so that ConstantRelocatable can fit
252 /// into the global constant pool template mechanism. 291 /// into the global constant pool template mechanism.
253 class RelocatableTuple { 292 class RelocatableTuple {
254 RelocatableTuple() = delete; 293 RelocatableTuple() = delete;
255 RelocatableTuple &operator=(const RelocatableTuple &) = delete; 294 RelocatableTuple &operator=(const RelocatableTuple &) = delete;
256 295
257 public: 296 public:
258 RelocatableTuple(const RelocOffsetT Offset, const IceString &Name, 297 RelocatableTuple(const RelocOffsetArray &OffsetExpr, const IceString &Name,
259 bool SuppressMangling) 298 bool SuppressMangling)
260 : Offset(Offset), Name(Name), SuppressMangling(SuppressMangling) {} 299 : OffsetExpr(OffsetExpr), Name(Name), SuppressMangling(SuppressMangling) {
300 }
301
302 RelocatableTuple(const RelocOffsetArray &OffsetExpr, const IceString &Name,
303 const IceString &EmitString, bool SuppressMangling)
304 : OffsetExpr(OffsetExpr), Name(Name), EmitString(EmitString),
305 SuppressMangling(SuppressMangling) {}
306
261 RelocatableTuple(const RelocatableTuple &) = default; 307 RelocatableTuple(const RelocatableTuple &) = default;
262 308
263 const RelocOffsetT Offset; 309 const RelocOffsetArray OffsetExpr;
264 const IceString Name; 310 const IceString Name;
265 bool SuppressMangling; 311 const IceString EmitString;
312 const bool SuppressMangling;
266 }; 313 };
267 314
268 bool operator==(const RelocatableTuple &A, const RelocatableTuple &B); 315 bool operator==(const RelocatableTuple &A, const RelocatableTuple &B);
269 316
270 /// ConstantRelocatable represents a symbolic constant combined with a fixed 317 /// ConstantRelocatable represents a symbolic constant combined with a fixed
271 /// offset. 318 /// offset.
272 class ConstantRelocatable : public Constant { 319 class ConstantRelocatable : public Constant {
273 ConstantRelocatable() = delete; 320 ConstantRelocatable() = delete;
274 ConstantRelocatable(const ConstantRelocatable &) = delete; 321 ConstantRelocatable(const ConstantRelocatable &) = delete;
275 ConstantRelocatable &operator=(const ConstantRelocatable &) = delete; 322 ConstantRelocatable &operator=(const ConstantRelocatable &) = delete;
276 323
277 public: 324 public:
278 static ConstantRelocatable *create(GlobalContext *Ctx, Type Ty, 325 static ConstantRelocatable *create(GlobalContext *Ctx, Type Ty,
279 const RelocatableTuple &Tuple) { 326 const RelocatableTuple &Tuple) {
280 return new (Ctx->allocate<ConstantRelocatable>()) ConstantRelocatable( 327 return new (Ctx->allocate<ConstantRelocatable>())
281 Ty, Tuple.Offset, Tuple.Name, Tuple.SuppressMangling); 328 ConstantRelocatable(Ty, Tuple.OffsetExpr, Tuple.Name, Tuple.EmitString,
329 Tuple.SuppressMangling);
282 } 330 }
283 331
284 RelocOffsetT getOffset() const { return Offset; } 332 RelocOffsetT getOffset() const {
333 RelocOffsetT Offset = 0;
334 for (const auto *const OffsetReloc : OffsetExpr) {
335 Offset += OffsetReloc->getOffset();
336 }
337 return Offset;
338 }
339
340 const IceString &getEmitString() const { return EmitString; }
341
285 const IceString &getName() const { return Name; } 342 const IceString &getName() const { return Name; }
286 void setSuppressMangling(bool Value) { SuppressMangling = Value; }
287 bool getSuppressMangling() const { return SuppressMangling; } 343 bool getSuppressMangling() const { return SuppressMangling; }
288 using Constant::emit; 344 using Constant::emit;
289 void emit(TargetLowering *Target) const final; 345 void emit(TargetLowering *Target) const final;
290 void emitWithoutPrefix(const TargetLowering *Target, 346 void emitWithoutPrefix(const TargetLowering *Target,
291 const char *Suffix = "") const; 347 const char *Suffix = "") const;
292 using Constant::dump; 348 using Constant::dump;
293 void dump(const Cfg *Func, Ostream &Str) const override; 349 void dump(const Cfg *Func, Ostream &Str) const override;
294 350
295 static bool classof(const Operand *Operand) { 351 static bool classof(const Operand *Operand) {
296 OperandKind Kind = Operand->getKind(); 352 OperandKind Kind = Operand->getKind();
297 return Kind == kConstRelocatable; 353 return Kind == kConstRelocatable;
298 } 354 }
299 355
300 private: 356 private:
301 ConstantRelocatable(Type Ty, RelocOffsetT Offset, const IceString &Name, 357 ConstantRelocatable(Type Ty, const RelocOffsetArray &OffsetExpr,
358 const IceString &Name, const IceString &EmitString,
302 bool SuppressMangling) 359 bool SuppressMangling)
303 : Constant(kConstRelocatable, Ty), Offset(Offset), Name(Name), 360 : Constant(kConstRelocatable, Ty), OffsetExpr(OffsetExpr), Name(Name),
304 SuppressMangling(SuppressMangling) {} 361 EmitString(EmitString), SuppressMangling(SuppressMangling) {}
305 const RelocOffsetT Offset; /// fixed offset to add 362
306 const IceString Name; /// optional for debug/dump 363 const RelocOffsetArray OffsetExpr; /// fixed offset to add
307 bool SuppressMangling; 364 const IceString Name; /// optional for debug/dump
365 const IceString EmitString; /// optional for textual output
Jim Stichnoth 2016/02/02 20:57:49 I would change "output" to "asm" or "emission"
John 2016/02/03 15:50:41 Done.
366 const bool SuppressMangling;
308 }; 367 };
309 368
310 /// ConstantUndef represents an unspecified bit pattern. Although it is legal to 369 /// ConstantUndef represents an unspecified bit pattern. Although it is legal to
311 /// lower ConstantUndef to any value, backends should try to make code 370 /// lower ConstantUndef to any value, backends should try to make code
312 /// generation deterministic by lowering ConstantUndefs to 0. 371 /// generation deterministic by lowering ConstantUndefs to 0.
313 class ConstantUndef : public Constant { 372 class ConstantUndef : public Constant {
314 ConstantUndef() = delete; 373 ConstantUndef() = delete;
315 ConstantUndef(const ConstantUndef &) = delete; 374 ConstantUndef(const ConstantUndef &) = delete;
316 ConstantUndef &operator=(const ConstantUndef &) = delete; 375 ConstantUndef &operator=(const ConstantUndef &) = delete;
317 376
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 private: 805 private:
747 const Cfg *Func; 806 const Cfg *Func;
748 MetadataKind Kind; 807 MetadataKind Kind;
749 CfgVector<VariableTracking> Metadata; 808 CfgVector<VariableTracking> Metadata;
750 const static InstDefList NoDefinitions; 809 const static InstDefList NoDefinitions;
751 }; 810 };
752 811
753 } // end of namespace Ice 812 } // end of namespace Ice
754 813
755 #endif // SUBZERO_SRC_ICEOPERAND_H 814 #endif // SUBZERO_SRC_ICEOPERAND_H
OLDNEW
« src/IceGlobalContext.cpp ('K') | « src/IceInstX86BaseImpl.h ('k') | src/IceOperand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698