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

Unified 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: Fixes Absolute Relocation Type for x86-64. Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: src/IceOperand.h
diff --git a/src/IceOperand.h b/src/IceOperand.h
index a32ec2b7e2c5e9c99901c6d682fa7c834b5d11cb..ac838d6758a9f5274dd96cad9698ec666b598166 100644
--- a/src/IceOperand.h
+++ b/src/IceOperand.h
@@ -26,6 +26,8 @@
#include "llvm/Support/Format.h"
+#include <limits>
+
namespace Ice {
class Operand {
@@ -247,6 +249,43 @@ inline void ConstantInteger64::dump(const Cfg *, Ostream &Str) const {
Str << static_cast<int64_t>(getValue());
}
+/// RelocOffset allows symbolic references in ConstantRelocatables' offsets,
+/// e.g., 8 + LabelOffset, where label offset is the location (code or data)
+/// of a Label that is only determinable during ELF emission.
+class RelocOffset final {
+ RelocOffset(const RelocOffset &) = delete;
+ RelocOffset &operator=(const RelocOffset &) = delete;
+
+public:
+ static RelocOffset *create(GlobalContext *Ctx) {
+ return new (Ctx->allocate<RelocOffset>()) RelocOffset();
+ }
+
+ static RelocOffset *create(GlobalContext *Ctx, RelocOffsetT Value) {
+ return new (Ctx->allocate<RelocOffset>()) RelocOffset(Value);
+ }
+
+ bool hasOffset() const { return HasOffset; }
+
+ RelocOffsetT getOffset() const {
+ assert(HasOffset);
+ return Offset;
+ }
+
+ void setOffset(const RelocOffsetT Value) {
+ assert(!HasOffset);
+ Offset = Value;
+ HasOffset = true;
+ }
+
+private:
+ RelocOffset() = default;
+ explicit RelocOffset(RelocOffsetT Offset) { setOffset(Offset); }
+
+ bool HasOffset = false;
+ RelocOffsetT Offset;
+};
+
/// RelocatableTuple bundles the parameters that are used to construct an
/// ConstantRelocatable. It is done this way so that ConstantRelocatable can fit
/// into the global constant pool template mechanism.
@@ -255,12 +294,13 @@ class RelocatableTuple {
RelocatableTuple &operator=(const RelocatableTuple &) = delete;
public:
- RelocatableTuple(const RelocOffsetT Offset, const IceString &Name,
+ RelocatableTuple(std::vector<RelocOffset *> OffsetExpr, const IceString &Name,
bool SuppressMangling)
- : Offset(Offset), Name(Name), SuppressMangling(SuppressMangling) {}
+ : OffsetExpr(OffsetExpr), Name(Name), SuppressMangling(SuppressMangling) {
+ }
RelocatableTuple(const RelocatableTuple &) = default;
- const RelocOffsetT Offset;
+ std::vector<RelocOffset *> OffsetExpr;
Jim Stichnoth 2016/02/02 17:13:44 const
John 2016/02/02 19:36:39 Done.
const IceString Name;
bool SuppressMangling;
};
@@ -278,10 +318,24 @@ public:
static ConstantRelocatable *create(GlobalContext *Ctx, Type Ty,
const RelocatableTuple &Tuple) {
return new (Ctx->allocate<ConstantRelocatable>()) ConstantRelocatable(
- Ty, Tuple.Offset, Tuple.Name, Tuple.SuppressMangling);
+ Ty, Tuple.OffsetExpr, Tuple.Name, Tuple.SuppressMangling);
}
- RelocOffsetT getOffset() const { return Offset; }
+ RelocOffsetT getOffset() const {
+ RelocOffsetT Offset = 0;
+ for (const auto *const OffsetReloc : OffsetExpr) {
+ Offset += OffsetReloc->getOffset();
+ }
+ return Offset;
+ }
+
+ void setEmitString(IceString Value) {
Jim Stichnoth 2016/02/02 17:13:44 Generally, Constants should not have setters, sinc
John 2016/02/02 19:36:39 Done.
+ EmitString = std::move(Value);
+ HasEmitString = true;
+ }
+
+ const IceString &getEmitString() const { return EmitString; }
+
const IceString &getName() const { return Name; }
void setSuppressMangling(bool Value) { SuppressMangling = Value; }
bool getSuppressMangling() const { return SuppressMangling; }
@@ -298,12 +352,14 @@ public:
}
private:
- ConstantRelocatable(Type Ty, RelocOffsetT Offset, const IceString &Name,
- bool SuppressMangling)
- : Constant(kConstRelocatable, Ty), Offset(Offset), Name(Name),
- SuppressMangling(SuppressMangling) {}
- const RelocOffsetT Offset; /// fixed offset to add
- const IceString Name; /// optional for debug/dump
+ ConstantRelocatable(Type Ty, std::vector<RelocOffset *> OffsetExpr,
+ const IceString &Name, bool SuppressMangling)
+ : Constant(kConstRelocatable, Ty), OffsetExpr(std::move(OffsetExpr)),
+ Name(Name), SuppressMangling(SuppressMangling) {}
+ bool HasEmitString = false;
+ IceString EmitString;
+ const std::vector<RelocOffset *> OffsetExpr; /// fixed offset to add
+ const IceString Name; /// optional for debug/dump
bool SuppressMangling;
};

Powered by Google App Engine
This is Rietveld 408576698