Initial skeleton of Subzero.
This includes just enough code to build the high-level ICE IR and dump it back out again. There is a script szdiff.py that does a fuzzy diff of the input and output for verification. See the comment in szdiff.py for a description of the fuzziness.
Building llvm2ice requires LLVM headers, libs, and tools (e.g. FileCheck) to be present. These default to something like llvm_i686_linux_work/Release+Asserts/ based on the checked-out and built pnacl-llvm code; I'll try to figure out how to more automatically detect the build configuration.
"make check" runs the lit tests.
This CL has under 2000 lines of "interesting" Ice*.{h,cpp} code, plus 600 lines of llvm2ice.cpp driver code, and the rest is tests.
Here is the high-level mapping of source files to functionality:
IceDefs.h, IceTypes.h, IceTypes.cpp:
Commonly used types and utilities.
IceCfg.h, IceCfg.cpp:
Operations at the function level.
IceCfgNode.h, IceCfgNode.cpp:
Operations on basic blocks (nodes).
IceInst.h, IceInst.cpp:
Operations on instructions.
IceOperand.h, IceOperand.cpp:
Operations on operands, such as stack locations, physical registers, and constants.
BUG= none
R=jfb@chromium.org
Review URL: https://codereview.chromium.org/205613002
diff --git a/src/IceOperand.cpp b/src/IceOperand.cpp
new file mode 100644
index 0000000..1009a33
--- /dev/null
+++ b/src/IceOperand.cpp
@@ -0,0 +1,91 @@
+//===- subzero/src/IceOperand.cpp - High-level operand implementation -----===//
+//
+// The Subzero Code Generator
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the Operand class and its
+// target-independent subclasses, primarily for the methods of the
+// Variable class.
+//
+//===----------------------------------------------------------------------===//
+
+#include "IceCfg.h"
+#include "IceInst.h"
+#include "IceOperand.h"
+
+namespace Ice {
+
+bool operator<(const RelocatableTuple &A, const RelocatableTuple &B) {
+ if (A.Offset != B.Offset)
+ return A.Offset < B.Offset;
+ if (A.SuppressMangling != B.SuppressMangling)
+ return A.SuppressMangling < B.SuppressMangling;
+ return A.Name < B.Name;
+}
+
+void Variable::setUse(const Inst *Inst, const CfgNode *Node) {
+ if (DefNode == NULL)
+ return;
+ if (llvm::isa<InstPhi>(Inst) || Node != DefNode)
+ DefNode = NULL;
+}
+
+void Variable::setDefinition(Inst *Inst, const CfgNode *Node) {
+ if (DefNode == NULL)
+ return;
+ // Can first check preexisting DefInst if we care about multi-def vars.
+ DefInst = Inst;
+ if (Node != DefNode)
+ DefNode = NULL;
+}
+
+void Variable::replaceDefinition(Inst *Inst, const CfgNode *Node) {
+ DefInst = NULL;
+ setDefinition(Inst, Node);
+}
+
+void Variable::setIsArg(Cfg *Func) {
+ IsArgument = true;
+ if (DefNode == NULL)
+ return;
+ CfgNode *Entry = Func->getEntryNode();
+ if (DefNode == Entry)
+ return;
+ DefNode = NULL;
+}
+
+IceString Variable::getName() const {
+ if (!Name.empty())
+ return Name;
+ char buf[30];
+ snprintf(buf, llvm::array_lengthof(buf), "__%u", getIndex());
+ return buf;
+}
+
+// ======================== dump routines ======================== //
+
+void Variable::dump(const Cfg *Func) const {
+ Ostream &Str = Func->getContext()->getStrDump();
+ const CfgNode *CurrentNode = Func->getCurrentNode();
+ (void)CurrentNode; // used only in assert()
+ assert(CurrentNode == NULL || DefNode == NULL || DefNode == CurrentNode);
+ Str << "%" << getName();
+}
+
+void Operand::dump(const Cfg *Func) const {
+ Ostream &Str = Func->getContext()->getStrDump();
+ Str << "Operand<?>";
+}
+
+void ConstantRelocatable::dump(const Cfg *Func) const {
+ Ostream &Str = Func->getContext()->getStrDump();
+ Str << "@" << Name;
+ if (Offset)
+ Str << "+" << Offset;
+}
+
+} // end of namespace Ice