[llvm-commits] [hlvm] r38282 - in /hlvm/trunk/hlvm: AST/Block.h AST/Node.h AST/Operator.cpp AST/Operator.h CodeGen/LLVMGenerator.cpp Reader/HLVM.rng
Reid Spencer
reid at x10sys.com
Sat Jul 7 17:01:56 PDT 2007
Author: reid
Date: Sat Jul 7 19:01:56 2007
New Revision: 38282
URL: http://llvm.org/viewvc/llvm-project?rev=38282&view=rev
Log:
Make getValue() a virtual function so Block can override it. Provide a
getContainingFunction to Block. Implement code generation for SelectOp.
Modified:
hlvm/trunk/hlvm/AST/Block.h
hlvm/trunk/hlvm/AST/Node.h
hlvm/trunk/hlvm/AST/Operator.cpp
hlvm/trunk/hlvm/AST/Operator.h
hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp
hlvm/trunk/hlvm/Reader/HLVM.rng
Modified: hlvm/trunk/hlvm/AST/Block.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Block.h?rev=38282&r1=38281&r2=38282&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Block.h (original)
+++ hlvm/trunk/hlvm/AST/Block.h Sat Jul 7 19:01:56 2007
@@ -57,6 +57,7 @@
/// @name Accessors
/// @{
public:
+ virtual const Type* getType() const { return this->back()->getType(); }
const std::string& getLabel() const { return label; }
AutoVarOp* getAutoVar(const std::string& name) const;
const Type* getResultType() { return this->back()->getType(); }
Modified: hlvm/trunk/hlvm/AST/Node.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Node.h?rev=38282&r1=38281&r2=38282&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Node.h (original)
+++ hlvm/trunk/hlvm/AST/Node.h Sat Jul 7 19:01:56 2007
@@ -539,7 +539,7 @@
/// @{
public:
// Get the type of the value
- inline const Type* getType() const { return type; }
+ virtual const Type* getType() const { return type; }
static inline bool classof(const Value*) { return true; }
static inline bool classof(const Node* N) { return N->isValue(); }
Modified: hlvm/trunk/hlvm/AST/Operator.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Operator.cpp?rev=38282&r1=38281&r2=38282&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Operator.cpp (original)
+++ hlvm/trunk/hlvm/AST/Operator.cpp Sat Jul 7 19:01:56 2007
@@ -28,6 +28,7 @@
//===----------------------------------------------------------------------===//
#include <hlvm/AST/Operator.h>
+#include <hlvm/AST/LinkageItems.h>
#include <hlvm/Base/Assert.h>
#include <llvm/Support/Casting.h>
@@ -39,6 +40,14 @@
{
}
+Function*
+Operator::getContainingFunction()
+{
+ Node* p = getParent();
+ while (p && !isa<Function>(p)) p = p->getParent();
+ return cast<Function>(p);
+}
+
NilaryOperator::~NilaryOperator()
{
}
Modified: hlvm/trunk/hlvm/AST/Operator.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Operator.h?rev=38282&r1=38281&r2=38282&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Operator.h (original)
+++ hlvm/trunk/hlvm/AST/Operator.h Sat Jul 7 19:01:56 2007
@@ -36,6 +36,7 @@
{
class Type;
+class Function;
/// This class is the abstract base class in the Abstract Syntax Tree for all
/// operators. An Operator is an instruction to the virtual machine to take
@@ -66,6 +67,9 @@
virtual size_t getNumOperands() const = 0;
virtual Operator* getOperand(unsigned opnum) const = 0;
+ /// Return the function containing this operator
+ Function* getContainingFunction();
+
/// Determine if this is a classof some other type.
static inline bool classof(const Operator*) { return true; }
static inline bool classof(const Node* N) { return N->isOperator(); }
Modified: hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp?rev=38282&r1=38281&r2=38282&view=diff
==============================================================================
--- hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp (original)
+++ hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp Sat Jul 7 19:01:56 2007
@@ -1195,16 +1195,45 @@
template<> void
LLVMGeneratorPass::gen<SelectOp>(SelectOp* op)
{
+ hlvmAssert(lops.size() >= 3 && "Too few operands for SelectOp");
+ llvm::Value* op3 = lops.back(); lops.pop_back();
+ llvm::Value* op2 = lops.back(); lops.pop_back();
+ llvm::Value* op1 = lops.back(); lops.pop_back();
+ hlvmAssert(op1->getType() == llvm::Type::BoolTy);
+ hlvmAssert(op2->getType() == op2->getType());
+ hlvmAssert(llvm::isa<llvm::BasicBlock>(op2) ==
+ llvm::isa<llvm::BasicBlock>(op3));
+ if (llvm::isa<llvm::BasicBlock>(op2)) {
+ // both are blocks, emit a BranchInstr
+ new llvm::BranchInst(
+ llvm::cast<llvm::BasicBlock>(op2),
+ llvm::cast<llvm::BasicBlock>(op3),op1,lblk);
+ return;
+ }
+
+ // A this point, we can only be left with a first class type since all HLVM
+ // operators translate to a first class type. Since the select operator
+ // requires first class types, its okay to just use it here.
+ hlvmAssert(op2->getType()->isFirstClassType());
+ new llvm::SelectInst(op1,op2,op3,"select",lblk);
}
template<> void
LLVMGeneratorPass::gen<SwitchOp>(SwitchOp* op)
{
+ hlvmAssert(lops.size() >= 2 && "Too few operands for SwitchOp");
+ llvm::Value* op2 = lops.back(); lops.pop_back();
+ llvm::Value* op1 = lops.back(); lops.pop_back();
+
}
template<> void
LLVMGeneratorPass::gen<LoopOp>(LoopOp* op)
{
+ hlvmAssert(lops.size() >= 3 && "Too few operands for SelectOp");
+ llvm::Value* op3 = lops.back(); lops.pop_back();
+ llvm::Value* op2 = lops.back(); lops.pop_back();
+ llvm::Value* op1 = lops.back(); lops.pop_back();
}
template<> void
Modified: hlvm/trunk/hlvm/Reader/HLVM.rng
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Reader/HLVM.rng?rev=38282&r1=38281&r2=38282&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Reader/HLVM.rng (original)
+++ hlvm/trunk/hlvm/Reader/HLVM.rng Sat Jul 7 19:01:56 2007
@@ -1060,6 +1060,7 @@
<ref name="break.elem"/>
<ref name="continue.elem"/>
<ref name="ret.elem"/>
+ <ref name="call.elem"/>
</choice>
</define>
@@ -1112,4 +1113,13 @@
</element>
</define>
+ <define name="call.elem">
+ <element name="call">
+ <ref name="Named_Element.pat"/>
+ <zeroOrMore>
+ <ref name="Operators.pat"/>
+ </zeroOrMore>
+ </element>
+ </define>
+
</grammar>
More information about the llvm-commits
mailing list