[llvm-commits] CVS: llvm/lib/Target/Sparc/SparcInstrInfo.cpp
vadve at cs.uiuc.edu
vadve at cs.uiuc.edu
Mon Sep 16 10:56:01 PDT 2002
Changes in directory llvm/lib/Target/Sparc:
SparcInstrInfo.cpp updated: 1.26 -> 1.27
---
Log message:
Add methods to query about the representation of LLVM quantities (e.g.,
constants). Useful for target-dependent LLVM transformations like
Preselection.
---
Diffs of the changes:
Index: llvm/lib/Target/Sparc/SparcInstrInfo.cpp
diff -u llvm/lib/Target/Sparc/SparcInstrInfo.cpp:1.26 llvm/lib/Target/Sparc/SparcInstrInfo.cpp:1.27
--- llvm/lib/Target/Sparc/SparcInstrInfo.cpp:1.26 Thu Sep 5 13:33:59 2002
+++ llvm/lib/Target/Sparc/SparcInstrInfo.cpp Mon Sep 16 10:55:52 2002
@@ -11,6 +11,7 @@
#include "llvm/Function.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
+#include <stdlib.h>
using std::vector;
static const uint32_t MAXLO = (1 << 10) - 1; // set bits set by %lo(*)
@@ -258,6 +259,61 @@
//---------------------------------------------------------------------------
+// Create a table of LLVM opcode -> max. immediate constant likely to
+// be usable for that operation.
+//---------------------------------------------------------------------------
+
+// Entry == 0 ==> no immediate constant field exists at all.
+// Entry > 0 ==> abs(immediate constant) <= Entry
+//
+vector<unsigned int> MaxConstantsTable(Instruction::NumOtherOps);
+
+static int
+MaxConstantForInstr(unsigned llvmOpCode)
+{
+ int modelOpCode = -1;
+
+ if (llvmOpCode >= Instruction::FirstBinaryOp &&
+ llvmOpCode < Instruction::NumBinaryOps)
+ modelOpCode = ADD;
+ else
+ switch(llvmOpCode) {
+ case Instruction::Ret: modelOpCode = JMPLCALL; break;
+
+ case Instruction::Malloc:
+ case Instruction::Alloca:
+ case Instruction::GetElementPtr:
+ case Instruction::PHINode:
+ case Instruction::Cast:
+ case Instruction::Call: modelOpCode = ADD; break;
+
+ case Instruction::Shl:
+ case Instruction::Shr: modelOpCode = SLLX; break;
+
+ default: break;
+ };
+
+ return (modelOpCode < 0)? 0: SparcMachineInstrDesc[modelOpCode].maxImmedConst;
+}
+
+static void
+InitializeMaxConstantsTable()
+{
+ unsigned op;
+ assert(MaxConstantsTable.size() == Instruction::NumOtherOps &&
+ "assignments below will be illegal!");
+ for (op = Instruction::FirstTermOp; op < Instruction::NumTermOps; ++op)
+ MaxConstantsTable[op] = MaxConstantForInstr(op);
+ for (op = Instruction::FirstBinaryOp; op < Instruction::NumBinaryOps; ++op)
+ MaxConstantsTable[op] = MaxConstantForInstr(op);
+ for (op = Instruction::FirstMemoryOp; op < Instruction::NumMemoryOps; ++op)
+ MaxConstantsTable[op] = MaxConstantForInstr(op);
+ for (op = Instruction::FirstOtherOp; op < Instruction::NumOtherOps; ++op)
+ MaxConstantsTable[op] = MaxConstantForInstr(op);
+}
+
+
+//---------------------------------------------------------------------------
// class UltraSparcInstrInfo
//
// Purpose:
@@ -273,6 +329,29 @@
/*descSize = */ NUM_TOTAL_OPCODES,
/*numRealOpCodes = */ NUM_REAL_OPCODES)
{
+ InitializeMaxConstantsTable();
+}
+
+bool
+UltraSparcInstrInfo::ConstantMayNotFitInImmedField(const Constant* CV,
+ const Instruction* I) const
+{
+ if (I->getOpcode() >= MaxConstantsTable.size()) // user-defined op (or bug!)
+ return true;
+
+ if (isa<ConstantPointerNull>(CV)) // can always use %g0
+ return false;
+
+ if (const ConstantUInt* U = dyn_cast<ConstantUInt>(CV))
+ return (U->getValue() > MaxConstantsTable[I->getOpcode()]);
+
+ if (const ConstantSInt* S = dyn_cast<ConstantSInt>(CV))
+ return (labs(S->getValue()) > (int) MaxConstantsTable[I->getOpcode()]);
+
+ if (isa<ConstantBool>(CV))
+ return (1U > MaxConstantsTable[I->getOpcode()]);
+
+ return true;
}
//
More information about the llvm-commits
mailing list