Skip to content

Instantly share code, notes, and snippets.

@rednaxelafx
Created June 19, 2012 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rednaxelafx/bdd13666e4796b09f36e to your computer and use it in GitHub Desktop.
Save rednaxelafx/bdd13666e4796b09f36e to your computer and use it in GitHub Desktop.
draft of arithmetic overflow support code in C2
//-----------------------------AddOverflowNode-----------------------------------
// Addition with overflow condition
class AddOverflowNode : public MultiNode {
protected:
AddOverflowNode(Node* c, Node* sum, Node* overflow);
public:
enum {
sum_proj_num = 0, // sum
overflow_proj_num = 1 // overflow condition
};
virtual int Opcode() const;
virtual Node* Identity(PhaseTransform* phase) { return this; }
virtual Node* Ideal(PhaseGVN* phase, bool can_reshape) { return NULL; }
virtual const Type* Value(PhaseTransform* phase) const { return bottom_type(); }
virtual uint hash() const { return Node::hash(); }
virtual bool is_CFG() const { return false; }
virtual uint ideal_reg() const { return NotAMachineReg; }
ProjNode* sum_proj() { return proj_out(sum_proj_num); }
ProjNode* overflow_proj() { return proj_out(overflow_proj_num); }
};
//-----------------------------AddIOverflowNode----------------------------------
// Integer addition with overflow condition
class AddIOverflowNode : public AddOverflowNode {
public:
AddIOverflowNode(Node* c, Node* sum, Node* overflow) : AddOverflowNode(c, sum, oveflow) {}
virtual int Opcode() const;
virtual const Type* bottom_type() const { return TypeTuple::INT_CC; }
virtual Node* match( const ProjNode *proj, const Matcher *m );
static AddIOverflowNode* make(Compile* C, Node* overflow);
};
//=============================================================================
AddOverflowNode::AddOverflowNode(Node* c, Node* sum, Node* overflow) : MultiNode(3) {
init_req(0, c);
init_req(1, sum);
init_req(2, overflow);
}
//------------------------------make------------------------------------------
AddIOverflowNode* AddIOverflowNode::make(Compile* C, Node* overflow) {
Node* n = overflow;
assert(n->Opcode() == Op_CheckAddIOverflow, "only add overflow accepted");
AddIOverflowNode* addovf = new (C, 3) AddIOverflowNode(n->in(0), n->in(1), n->in(2));
Node* sproj = new (C, 1) ProjNode(addovf, AddOverflowNode::sum_proj_num);
Node* oproj = new (C, 1) ProjNode(addovf, AddOverflowNode::overflow_proj_num);
return addovf;
}
//------------------------------match------------------------------------------
// return result(s) along with their RegMask info
Node *AddIOverflowNode::match(const ProjNode* proj, const Matcher* match) {
uint ideal_reg = proj->ideal_reg();
RegMask rm;
if (proj->_con == sum_proj_num) {
rm = RegMask::EMPTY;
} else {
assert(proj->_con == overflow_proj_num, "must be sum or overflow projection");
ideal_reg = Op_RegFlags;
rm = match->overflow_proj_mask();
}
return new (match->C, 1) MachProjNode(this, proj->_con, rm, ideal_reg);
}
diff -r 8c92982cbbc4 src/share/vm/opto/type.cpp
--- a/src/share/vm/opto/type.cpp Fri Jun 15 01:25:19 2012 -0700
+++ b/src/share/vm/opto/type.cpp Tue Jun 19 21:43:09 2012 +0800
@@ -386,6 +386,11 @@
longpair[1] = TypeLong::LONG;
TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
+ const Type **int_cc = TypeTuple::fields(2);
+ int_cc[0] = TypeInt::INT;
+ int_cc[1] = TypeInt::CC;
+ TypeTuple::INT_CC = TypeTuple::make(2, int_cc);
+
_const_basic_type[T_NARROWOOP] = TypeNarrowOop::BOTTOM;
_const_basic_type[T_BOOLEAN] = TypeInt::BOOL;
_const_basic_type[T_CHAR] = TypeInt::CHAR;
@@ -1618,6 +1623,7 @@
const TypeTuple *TypeTuple::START_I2C;
const TypeTuple *TypeTuple::INT_PAIR;
const TypeTuple *TypeTuple::LONG_PAIR;
+const TypeTuple *TypeTuple::INT_CC;
//------------------------------make-------------------------------------------
diff -r 8c92982cbbc4 src/share/vm/opto/type.hpp
--- a/src/share/vm/opto/type.hpp Fri Jun 15 01:25:19 2012 -0700
+++ b/src/share/vm/opto/type.hpp Tue Jun 19 21:43:09 2012 +0800
@@ -549,6 +549,7 @@
static const TypeTuple *START_I2C;
static const TypeTuple *INT_PAIR;
static const TypeTuple *LONG_PAIR;
+ static const TypeTuple *INT_CC;
#ifndef PRODUCT
virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment