mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-01 15:17:25 +00:00
For PR1146:
Use ParamAttrsList for writing parameter attributes. Since they are sparse now, we also write them sparsely (saves a few bytes). Unfortunately, this is a bytecode file format change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35811 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -23,6 +23,7 @@
|
|||||||
#include "llvm/Constants.h"
|
#include "llvm/Constants.h"
|
||||||
#include "llvm/InlineAsm.h"
|
#include "llvm/InlineAsm.h"
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
|
#include "llvm/ParameterAttributes.h"
|
||||||
#include "llvm/TypeSymbolTable.h"
|
#include "llvm/TypeSymbolTable.h"
|
||||||
#include "llvm/Bytecode/Format.h"
|
#include "llvm/Bytecode/Format.h"
|
||||||
#include "llvm/Config/alloca.h"
|
#include "llvm/Config/alloca.h"
|
||||||
@@ -288,6 +289,8 @@ Value * BytecodeReader::getValue(unsigned type, unsigned oNum, bool Create) {
|
|||||||
if (Num < Locals->size())
|
if (Num < Locals->size())
|
||||||
return Locals->getOperand(Num);
|
return Locals->getOperand(Num);
|
||||||
|
|
||||||
|
// We did not find the value.
|
||||||
|
|
||||||
if (!Create) return 0; // Do not create a placeholder?
|
if (!Create) return 0; // Do not create a placeholder?
|
||||||
|
|
||||||
// Did we already create a place holder?
|
// Did we already create a place holder?
|
||||||
@@ -1005,21 +1008,18 @@ const Type *BytecodeReader::ParseType() {
|
|||||||
}
|
}
|
||||||
case Type::FunctionTyID: {
|
case Type::FunctionTyID: {
|
||||||
const Type *RetType = readType();
|
const Type *RetType = readType();
|
||||||
unsigned RetAttr = read_vbr_uint();
|
|
||||||
|
|
||||||
unsigned NumParams = read_vbr_uint();
|
unsigned NumParams = read_vbr_uint();
|
||||||
|
|
||||||
std::vector<const Type*> Params;
|
std::vector<const Type*> Params;
|
||||||
std::vector<FunctionType::ParameterAttributes> Attrs;
|
|
||||||
Attrs.push_back(FunctionType::ParameterAttributes(RetAttr));
|
|
||||||
while (NumParams--) {
|
while (NumParams--) {
|
||||||
Params.push_back(readType());
|
Params.push_back(readType());
|
||||||
if (Params.back() != Type::VoidTy)
|
|
||||||
Attrs.push_back(FunctionType::ParameterAttributes(read_vbr_uint()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
|
bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
|
||||||
if (isVarArg) Params.pop_back();
|
if (isVarArg)
|
||||||
|
Params.pop_back();
|
||||||
|
|
||||||
|
ParamAttrsList *Attrs = ParseParamAttrsList();
|
||||||
|
|
||||||
Result = FunctionType::get(RetType, Params, isVarArg, Attrs);
|
Result = FunctionType::get(RetType, Params, isVarArg, Attrs);
|
||||||
break;
|
break;
|
||||||
@@ -1076,6 +1076,21 @@ const Type *BytecodeReader::ParseType() {
|
|||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ParamAttrsList *BytecodeReader::ParseParamAttrsList() {
|
||||||
|
unsigned NumAttrs = read_vbr_uint();
|
||||||
|
ParamAttrsList *Attrs = 0;
|
||||||
|
if (NumAttrs) {
|
||||||
|
Attrs = new ParamAttrsList();
|
||||||
|
while (NumAttrs--) {
|
||||||
|
uint16_t index = read_vbr_uint();
|
||||||
|
uint16_t attrs = read_vbr_uint();
|
||||||
|
Attrs->addAttributes(index, attrs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Attrs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ParseTypes - We have to use this weird code to handle recursive
|
// ParseTypes - We have to use this weird code to handle recursive
|
||||||
// types. We know that recursive types will only reference the current slab of
|
// types. We know that recursive types will only reference the current slab of
|
||||||
// values in the type plane, but they can forward reference types before they
|
// values in the type plane, but they can forward reference types before they
|
||||||
@@ -2106,4 +2121,3 @@ bool BytecodeReader::ParseBytecode(volatile BufPtr Buf, unsigned Length,
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
BytecodeHandler::~BytecodeHandler() {}
|
BytecodeHandler::~BytecodeHandler() {}
|
||||||
|
|
||||||
|
|||||||
@@ -236,6 +236,7 @@ protected:
|
|||||||
/// @brief Parse global types
|
/// @brief Parse global types
|
||||||
void ParseGlobalTypes();
|
void ParseGlobalTypes();
|
||||||
|
|
||||||
|
|
||||||
/// @brief Parse a basic block (for LLVM 1.0 basic block blocks)
|
/// @brief Parse a basic block (for LLVM 1.0 basic block blocks)
|
||||||
BasicBlock* ParseBasicBlock(unsigned BlockNo);
|
BasicBlock* ParseBasicBlock(unsigned BlockNo);
|
||||||
|
|
||||||
@@ -264,6 +265,9 @@ protected:
|
|||||||
/// @brief Parse a single type constant
|
/// @brief Parse a single type constant
|
||||||
const Type *ParseType();
|
const Type *ParseType();
|
||||||
|
|
||||||
|
/// @brief Parse a list of parameter attributes
|
||||||
|
ParamAttrsList *ParseParamAttrsList();
|
||||||
|
|
||||||
/// @brief Parse a string constants block
|
/// @brief Parse a string constants block
|
||||||
void ParseStringConstants(unsigned NumEntries, ValueTable &Tab);
|
void ParseStringConstants(unsigned NumEntries, ValueTable &Tab);
|
||||||
|
|
||||||
|
|||||||
@@ -332,6 +332,10 @@ void SlotCalculator::purgeFunction() {
|
|||||||
SC_DEBUG("end purgeFunction!\n");
|
SC_DEBUG("end purgeFunction!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline static bool hasImplicitNull(const Type* Ty) {
|
||||||
|
return Ty != Type::LabelTy && Ty != Type::VoidTy && !isa<OpaqueType>(Ty);
|
||||||
|
}
|
||||||
|
|
||||||
void SlotCalculator::CreateFunctionValueSlot(const Value *V) {
|
void SlotCalculator::CreateFunctionValueSlot(const Value *V) {
|
||||||
assert(!NodeMap.count(V) && "Function-local value can't be inserted!");
|
assert(!NodeMap.count(V) && "Function-local value can't be inserted!");
|
||||||
|
|
||||||
@@ -353,7 +357,7 @@ void SlotCalculator::CreateFunctionValueSlot(const Value *V) {
|
|||||||
// to insert the implicit null value.
|
// to insert the implicit null value.
|
||||||
if (Table[TyPlane].empty()) {
|
if (Table[TyPlane].empty()) {
|
||||||
// Label's and opaque types can't have a null value.
|
// Label's and opaque types can't have a null value.
|
||||||
if (Ty != Type::LabelTy && !isa<OpaqueType>(Ty)) {
|
if (hasImplicitNull(Ty)) {
|
||||||
Value *ZeroInitializer = Constant::getNullValue(Ty);
|
Value *ZeroInitializer = Constant::getNullValue(Ty);
|
||||||
|
|
||||||
// If we are pushing zeroinit, it will be handled below.
|
// If we are pushing zeroinit, it will be handled below.
|
||||||
@@ -370,5 +374,4 @@ void SlotCalculator::CreateFunctionValueSlot(const Value *V) {
|
|||||||
|
|
||||||
SC_DEBUG(" Inserting value [" << TyPlane << "] = " << *V << " slot=" <<
|
SC_DEBUG(" Inserting value [" << TyPlane << "] = " << *V << " slot=" <<
|
||||||
NodeMap[V] << "\n");
|
NodeMap[V] << "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public:
|
|||||||
SlotCalculator(const Module *M);
|
SlotCalculator(const Module *M);
|
||||||
|
|
||||||
/// getSlot - Return the slot number of the specified value in it's type
|
/// getSlot - Return the slot number of the specified value in it's type
|
||||||
/// plane. This returns < 0 on error!
|
/// plane.
|
||||||
///
|
///
|
||||||
unsigned getSlot(const Value *V) const {
|
unsigned getSlot(const Value *V) const {
|
||||||
NodeMapType::const_iterator I = NodeMap.find(V);
|
NodeMapType::const_iterator I = NodeMap.find(V);
|
||||||
|
|||||||
@@ -17,12 +17,13 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#define DEBUG_TYPE "bytecodewriter"
|
#define DEBUG_TYPE "bcwriter"
|
||||||
#include "WriterInternals.h"
|
#include "WriterInternals.h"
|
||||||
#include "llvm/Bytecode/WriteBytecodePass.h"
|
#include "llvm/Bytecode/WriteBytecodePass.h"
|
||||||
#include "llvm/CallingConv.h"
|
#include "llvm/CallingConv.h"
|
||||||
#include "llvm/Constants.h"
|
#include "llvm/Constants.h"
|
||||||
#include "llvm/DerivedTypes.h"
|
#include "llvm/DerivedTypes.h"
|
||||||
|
#include "llvm/ParameterAttributes.h"
|
||||||
#include "llvm/InlineAsm.h"
|
#include "llvm/InlineAsm.h"
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
@@ -197,6 +198,21 @@ inline BytecodeBlock::~BytecodeBlock() { // Do backpatch when block goes out
|
|||||||
//=== Constant Output ===//
|
//=== Constant Output ===//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
void BytecodeWriter::outputParamAttrsList(const ParamAttrsList *Attrs) {
|
||||||
|
if (!Attrs) {
|
||||||
|
output_vbr(unsigned(0));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
unsigned numAttrs = Attrs->size();
|
||||||
|
output_vbr(numAttrs);
|
||||||
|
for (unsigned i = 0; i < numAttrs; ++i) {
|
||||||
|
uint16_t index = Attrs->getParamIndex(i);
|
||||||
|
uint16_t attrs = Attrs->getParamAttrs(index);
|
||||||
|
output_vbr(uint32_t(index));
|
||||||
|
output_vbr(uint32_t(attrs));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void BytecodeWriter::outputType(const Type *T) {
|
void BytecodeWriter::outputType(const Type *T) {
|
||||||
const StructType* STy = dyn_cast<StructType>(T);
|
const StructType* STy = dyn_cast<StructType>(T);
|
||||||
if(STy && STy->isPacked())
|
if(STy && STy->isPacked())
|
||||||
@@ -213,25 +229,23 @@ void BytecodeWriter::outputType(const Type *T) {
|
|||||||
output_vbr(cast<IntegerType>(T)->getBitWidth());
|
output_vbr(cast<IntegerType>(T)->getBitWidth());
|
||||||
break;
|
break;
|
||||||
case Type::FunctionTyID: {
|
case Type::FunctionTyID: {
|
||||||
const FunctionType *MT = cast<FunctionType>(T);
|
const FunctionType *FT = cast<FunctionType>(T);
|
||||||
output_typeid(Table.getTypeSlot(MT->getReturnType()));
|
output_typeid(Table.getTypeSlot(FT->getReturnType()));
|
||||||
output_vbr(unsigned(MT->getParamAttrs(0)));
|
|
||||||
|
|
||||||
// Output the number of arguments to function (+1 if varargs):
|
// Output the number of arguments to function (+1 if varargs):
|
||||||
output_vbr((unsigned)MT->getNumParams()+MT->isVarArg());
|
output_vbr((unsigned)FT->getNumParams()+FT->isVarArg());
|
||||||
|
|
||||||
// Output all of the arguments...
|
// Output all of the arguments...
|
||||||
FunctionType::param_iterator I = MT->param_begin();
|
FunctionType::param_iterator I = FT->param_begin();
|
||||||
unsigned Idx = 1;
|
for (; I != FT->param_end(); ++I)
|
||||||
for (; I != MT->param_end(); ++I) {
|
|
||||||
output_typeid(Table.getTypeSlot(*I));
|
output_typeid(Table.getTypeSlot(*I));
|
||||||
output_vbr(unsigned(MT->getParamAttrs(Idx)));
|
|
||||||
Idx++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Terminate list with VoidTy if we are a varargs function...
|
// Terminate list with VoidTy if we are a varargs function...
|
||||||
if (MT->isVarArg())
|
if (FT->isVarArg())
|
||||||
output_typeid((unsigned)Type::VoidTyID);
|
output_typeid((unsigned)Type::VoidTyID);
|
||||||
|
|
||||||
|
// Put out all the parameter attributes
|
||||||
|
outputParamAttrsList(FT->getParamAttrs());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1107,7 +1121,7 @@ void BytecodeWriter::outputValueSymbolTable(const ValueSymbolTable &VST) {
|
|||||||
|
|
||||||
// Organize the symbol table by type
|
// Organize the symbol table by type
|
||||||
typedef SmallVector<const ValueName*, 8> PlaneMapVector;
|
typedef SmallVector<const ValueName*, 8> PlaneMapVector;
|
||||||
typedef DenseMap<const Type*, PlaneMapVector > PlaneMap;
|
typedef DenseMap<const Type*, PlaneMapVector> PlaneMap;
|
||||||
PlaneMap Planes;
|
PlaneMap Planes;
|
||||||
for (ValueSymbolTable::const_iterator SI = VST.begin(), SE = VST.end();
|
for (ValueSymbolTable::const_iterator SI = VST.begin(), SE = VST.end();
|
||||||
SI != SE; ++SI)
|
SI != SE; ++SI)
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ namespace llvm {
|
|||||||
class InlineAsm;
|
class InlineAsm;
|
||||||
class TypeSymbolTable;
|
class TypeSymbolTable;
|
||||||
class ValueSymbolTable;
|
class ValueSymbolTable;
|
||||||
|
class ParamAttrsList;
|
||||||
|
|
||||||
class BytecodeWriter {
|
class BytecodeWriter {
|
||||||
std::vector<unsigned char> &Out;
|
std::vector<unsigned char> &Out;
|
||||||
@@ -61,6 +62,7 @@ private:
|
|||||||
void outputTypeSymbolTable(const TypeSymbolTable &TST);
|
void outputTypeSymbolTable(const TypeSymbolTable &TST);
|
||||||
void outputValueSymbolTable(const ValueSymbolTable &ST);
|
void outputValueSymbolTable(const ValueSymbolTable &ST);
|
||||||
void outputTypes(unsigned StartNo);
|
void outputTypes(unsigned StartNo);
|
||||||
|
void outputParamAttrsList(const ParamAttrsList* Attrs);
|
||||||
void outputConstantsInPlane(const Value *const*Plane, unsigned PlaneSize,
|
void outputConstantsInPlane(const Value *const*Plane, unsigned PlaneSize,
|
||||||
unsigned StartNo);
|
unsigned StartNo);
|
||||||
void outputConstant(const Constant *CPV);
|
void outputConstant(const Constant *CPV);
|
||||||
|
|||||||
Reference in New Issue
Block a user