+//---------------------------------------------------------------------------
+// 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<int> MaxConstantsTable(Instruction::OtherOpsEnd);
+
+static int
+MaxConstantForInstr(unsigned llvmOpCode)
+{
+ int modelOpCode = -1;
+
+ if (llvmOpCode >= Instruction::BinaryOpsBegin &&
+ llvmOpCode < Instruction::BinaryOpsEnd)
+ 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::OtherOpsEnd &&
+ "assignments below will be illegal!");
+ for (op = Instruction::TermOpsBegin; op < Instruction::TermOpsEnd; ++op)
+ MaxConstantsTable[op] = MaxConstantForInstr(op);
+ for (op = Instruction::BinaryOpsBegin; op < Instruction::BinaryOpsEnd; ++op)
+ MaxConstantsTable[op] = MaxConstantForInstr(op);
+ for (op = Instruction::MemoryOpsBegin; op < Instruction::MemoryOpsEnd; ++op)
+ MaxConstantsTable[op] = MaxConstantForInstr(op);
+ for (op = Instruction::OtherOpsBegin; op < Instruction::OtherOpsEnd; ++op)
+ MaxConstantsTable[op] = MaxConstantForInstr(op);
+}