mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-21 03:29:40 +00:00
Implement the arbitrary bit-width integer feature. The feature allows integers of any bitwidth (up to 64) to be defined instead of just 1, 8, 16, 32, and 64 bit integers. This change does several things: 1. Introduces a new Derived Type, IntegerType, to represent the number of bits in an integer. The Type classes SubclassData field is used to store the number of bits. This allows 2^23 bits in an integer type. 2. Removes the five integer Type::TypeID values for the 1, 8, 16, 32 and 64-bit integers. These are replaced with just IntegerType which is not a primitive any more. 3. Adjust the rest of LLVM to account for this change. Note that while this incremental change lays the foundation for arbitrary bit-width integers, LLVM has not yet been converted to actually deal with them in any significant way. Most optimization passes, for example, will still only deal with the byte-width integer types. Future increments will rectify this situation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33113 91177308-0d34-0410-b5e6-96231b3b80d8
102 lines
3.2 KiB
C++
102 lines
3.2 KiB
C++
//===- DeadTypeElimination.cpp - Eliminate unused types for symbol table --===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This pass is used to cleanup the output of GCC. It eliminate names for types
|
|
// that are unused in the entire translation unit, using the FindUsedTypes pass.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#define DEBUG_TYPE "deadtypeelim"
|
|
#include "llvm/Transforms/IPO.h"
|
|
#include "llvm/Analysis/FindUsedTypes.h"
|
|
#include "llvm/Module.h"
|
|
#include "llvm/TypeSymbolTable.h"
|
|
#include "llvm/DerivedTypes.h"
|
|
#include "llvm/ADT/Statistic.h"
|
|
using namespace llvm;
|
|
|
|
STATISTIC(NumKilled, "Number of unused typenames removed from symtab");
|
|
|
|
namespace {
|
|
struct DTE : public ModulePass {
|
|
// doPassInitialization - For this pass, it removes global symbol table
|
|
// entries for primitive types. These are never used for linking in GCC and
|
|
// they make the output uglier to look at, so we nuke them.
|
|
//
|
|
// Also, initialize instance variables.
|
|
//
|
|
bool runOnModule(Module &M);
|
|
|
|
// getAnalysisUsage - This function needs FindUsedTypes to do its job...
|
|
//
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
AU.addRequired<FindUsedTypes>();
|
|
}
|
|
};
|
|
RegisterPass<DTE> X("deadtypeelim", "Dead Type Elimination");
|
|
}
|
|
|
|
ModulePass *llvm::createDeadTypeEliminationPass() {
|
|
return new DTE();
|
|
}
|
|
|
|
|
|
// ShouldNukeSymtabEntry - Return true if this module level symbol table entry
|
|
// should be eliminated.
|
|
//
|
|
static inline bool ShouldNukeSymtabEntry(const Type *Ty){
|
|
// Nuke all names for primitive types!
|
|
if (Ty->isPrimitiveType() || Ty->isIntegral())
|
|
return true;
|
|
|
|
// Nuke all pointers to primitive types as well...
|
|
if (const PointerType *PT = dyn_cast<PointerType>(Ty))
|
|
if (PT->getElementType()->isPrimitiveType() ||
|
|
PT->getElementType()->isIntegral())
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
// run - For this pass, it removes global symbol table entries for primitive
|
|
// types. These are never used for linking in GCC and they make the output
|
|
// uglier to look at, so we nuke them. Also eliminate types that are never used
|
|
// in the entire program as indicated by FindUsedTypes.
|
|
//
|
|
bool DTE::runOnModule(Module &M) {
|
|
bool Changed = false;
|
|
|
|
TypeSymbolTable &ST = M.getTypeSymbolTable();
|
|
std::set<const Type *> UsedTypes = getAnalysis<FindUsedTypes>().getTypes();
|
|
|
|
// Check the symbol table for superfluous type entries...
|
|
//
|
|
// Grab the 'type' plane of the module symbol...
|
|
TypeSymbolTable::iterator TI = ST.begin();
|
|
TypeSymbolTable::iterator TE = ST.end();
|
|
while ( TI != TE ) {
|
|
// If this entry should be unconditionally removed, or if we detect that
|
|
// the type is not used, remove it.
|
|
const Type *RHS = TI->second;
|
|
if (ShouldNukeSymtabEntry(RHS) || !UsedTypes.count(RHS)) {
|
|
ST.remove(TI++);
|
|
++NumKilled;
|
|
Changed = true;
|
|
} else {
|
|
++TI;
|
|
// We only need to leave one name for each type.
|
|
UsedTypes.erase(RHS);
|
|
}
|
|
}
|
|
|
|
return Changed;
|
|
}
|
|
|
|
// vim: sw=2
|