summaryrefslogtreecommitdiffstats
path: root/utils/TableGen/Record.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2008-10-17 01:33:43 +0000
committerDan Gohman <gohman@apple.com>2008-10-17 01:33:43 +0000
commit63f97201dc9dcebbe84d1b73113166c64212b4b8 (patch)
tree718d542a3b0cf7a6c76944afed13d26afbb6a12f /utils/TableGen/Record.cpp
parent74feef261a43392bc85280f66c75fbd4e2ccf73d (diff)
downloadexternal_llvm-63f97201dc9dcebbe84d1b73113166c64212b4b8.zip
external_llvm-63f97201dc9dcebbe84d1b73113166c64212b4b8.tar.gz
external_llvm-63f97201dc9dcebbe84d1b73113166c64212b4b8.tar.bz2
Fun x86 encoding tricks: when adding an immediate value of 128,
use a SUB instruction instead of an ADD, because -128 can be encoded in an 8-bit signed immediate field, while +128 can't be. This avoids the need for a 32-bit immediate field in this case. A similar optimization applies to 64-bit adds with 0x80000000, with the 32-bit signed immediate field. To support this, teach tablegen how to handle 64-bit constants. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57663 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/Record.cpp')
-rw-r--r--utils/TableGen/Record.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp
index 06d9bf2..e173cae 100644
--- a/utils/TableGen/Record.cpp
+++ b/utils/TableGen/Record.cpp
@@ -35,7 +35,7 @@ bool BitRecTy::baseClassOf(const BitsRecTy *RHS) const {
}
Init *BitRecTy::convertValue(IntInit *II) {
- int Val = II->getValue();
+ int64_t Val = II->getValue();
if (Val != 0 && Val != 1) return 0; // Only accept 0 or 1 for a bit!
return new BitInit(Val != 0);
@@ -116,7 +116,7 @@ Init *IntRecTy::convertValue(BitInit *BI) {
}
Init *IntRecTy::convertValue(BitsInit *BI) {
- int Result = 0;
+ int64_t Result = 0;
for (unsigned i = 0, e = BI->getNumBits(); i != e; ++i)
if (BitInit *Bit = dynamic_cast<BitInit*>(BI->getBit(i))) {
Result |= Bit->getValue() << i;
@@ -262,7 +262,7 @@ std::string BitsInit::getAsString() const {
bool BitsInit::printInHex(std::ostream &OS) const {
// First, attempt to convert the value into an integer value...
- int Result = 0;
+ int64_t Result = 0;
for (unsigned i = 0, e = getNumBits(); i != e; ++i)
if (BitInit *Bit = dynamic_cast<BitInit*>(getBit(i))) {
Result |= Bit->getValue() << i;
@@ -338,11 +338,11 @@ Init *IntInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) {
BitsInit *BI = new BitsInit(Bits.size());
for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
- if (Bits[i] >= 32) {
+ if (Bits[i] >= 64) {
delete BI;
return 0;
}
- BI->setBit(i, new BitInit(Value & (1 << Bits[i])));
+ BI->setBit(i, new BitInit(Value & (INT64_C(1) << Bits[i])));
}
return BI;
}
@@ -443,13 +443,13 @@ Init *BinOpInit::Fold() {
IntInit *LHSi = dynamic_cast<IntInit*>(LHS);
IntInit *RHSi = dynamic_cast<IntInit*>(RHS);
if (LHSi && RHSi) {
- int LHSv = LHSi->getValue(), RHSv = RHSi->getValue();
- int Result;
+ int64_t LHSv = LHSi->getValue(), RHSv = RHSi->getValue();
+ int64_t Result;
switch (getOpcode()) {
default: assert(0 && "Bad opcode!");
case SHL: Result = LHSv << RHSv; break;
case SRA: Result = LHSv >> RHSv; break;
- case SRL: Result = (unsigned)LHSv >> (unsigned)RHSv; break;
+ case SRL: Result = (uint64_t)LHSv >> (uint64_t)RHSv; break;
}
return new IntInit(Result);
}
@@ -861,10 +861,10 @@ Record::getValueAsListOfDefs(const std::string &FieldName) const {
}
/// getValueAsInt - This method looks up the specified field and returns its
-/// value as an int, throwing an exception if the field does not exist or if
+/// value as an int64_t, throwing an exception if the field does not exist or if
/// the value is not the right type.
///
-int Record::getValueAsInt(const std::string &FieldName) const {
+int64_t Record::getValueAsInt(const std::string &FieldName) const {
const RecordVal *R = getValue(FieldName);
if (R == 0 || R->getValue() == 0)
throw "Record `" + getName() + "' does not have a field named `" +
@@ -880,10 +880,10 @@ int Record::getValueAsInt(const std::string &FieldName) const {
/// its value as a vector of integers, throwing an exception if the field does
/// not exist or if the value is not the right type.
///
-std::vector<int>
+std::vector<int64_t>
Record::getValueAsListOfInts(const std::string &FieldName) const {
ListInit *List = getValueAsListInit(FieldName);
- std::vector<int> Ints;
+ std::vector<int64_t> Ints;
for (unsigned i = 0; i < List->getSize(); i++) {
if (IntInit *II = dynamic_cast<IntInit*>(List->getElement(i))) {
Ints.push_back(II->getValue());