mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-21 18:24:23 +00:00
Implement function prefix data as an IR feature.
Previous discussion: http://lists.cs.uiuc.edu/pipermail/llvmdev/2013-July/063909.html Differential Revision: http://llvm-reviews.chandlerc.com/D1191 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190773 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -1106,9 +1106,11 @@ uint64_t BitcodeReader::decodeSignRotatedValue(uint64_t V) {
|
||||
bool BitcodeReader::ResolveGlobalAndAliasInits() {
|
||||
std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInitWorklist;
|
||||
std::vector<std::pair<GlobalAlias*, unsigned> > AliasInitWorklist;
|
||||
std::vector<std::pair<Function*, unsigned> > FunctionPrefixWorklist;
|
||||
|
||||
GlobalInitWorklist.swap(GlobalInits);
|
||||
AliasInitWorklist.swap(AliasInits);
|
||||
FunctionPrefixWorklist.swap(FunctionPrefixes);
|
||||
|
||||
while (!GlobalInitWorklist.empty()) {
|
||||
unsigned ValID = GlobalInitWorklist.back().second;
|
||||
@ -1136,6 +1138,20 @@ bool BitcodeReader::ResolveGlobalAndAliasInits() {
|
||||
}
|
||||
AliasInitWorklist.pop_back();
|
||||
}
|
||||
|
||||
while (!FunctionPrefixWorklist.empty()) {
|
||||
unsigned ValID = FunctionPrefixWorklist.back().second;
|
||||
if (ValID >= ValueList.size()) {
|
||||
FunctionPrefixes.push_back(FunctionPrefixWorklist.back());
|
||||
} else {
|
||||
if (Constant *C = dyn_cast<Constant>(ValueList[ValID]))
|
||||
FunctionPrefixWorklist.back().first->setPrefixData(C);
|
||||
else
|
||||
return Error("Function prefix is not a constant!");
|
||||
}
|
||||
FunctionPrefixWorklist.pop_back();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1881,6 +1897,8 @@ bool BitcodeReader::ParseModule(bool Resume) {
|
||||
if (Record.size() > 9)
|
||||
UnnamedAddr = Record[9];
|
||||
Func->setUnnamedAddr(UnnamedAddr);
|
||||
if (Record.size() > 10 && Record[10] != 0)
|
||||
FunctionPrefixes.push_back(std::make_pair(Func, Record[10]-1));
|
||||
ValueList.push_back(Func);
|
||||
|
||||
// If this is a function with a body, remember the prototype we are
|
||||
|
@ -142,6 +142,7 @@ class BitcodeReader : public GVMaterializer {
|
||||
|
||||
std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInits;
|
||||
std::vector<std::pair<GlobalAlias*, unsigned> > AliasInits;
|
||||
std::vector<std::pair<Function*, unsigned> > FunctionPrefixes;
|
||||
|
||||
/// MAttributes - The set of attributes by index. Index zero in the
|
||||
/// file is for null, and is thus not represented here. As such all indices
|
||||
|
@ -632,7 +632,7 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
|
||||
// Emit the function proto information.
|
||||
for (Module::const_iterator F = M->begin(), E = M->end(); F != E; ++F) {
|
||||
// FUNCTION: [type, callingconv, isproto, linkage, paramattrs, alignment,
|
||||
// section, visibility, gc, unnamed_addr]
|
||||
// section, visibility, gc, unnamed_addr, prefix]
|
||||
Vals.push_back(VE.getTypeID(F->getType()));
|
||||
Vals.push_back(F->getCallingConv());
|
||||
Vals.push_back(F->isDeclaration());
|
||||
@ -643,6 +643,8 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
|
||||
Vals.push_back(getEncodedVisibility(F));
|
||||
Vals.push_back(F->hasGC() ? GCMap[F->getGC()] : 0);
|
||||
Vals.push_back(F->hasUnnamedAddr());
|
||||
Vals.push_back(F->hasPrefixData() ? (VE.getValueID(F->getPrefixData()) + 1)
|
||||
: 0);
|
||||
|
||||
unsigned AbbrevToUse = 0;
|
||||
Stream.EmitRecord(bitc::MODULE_CODE_FUNCTION, Vals, AbbrevToUse);
|
||||
@ -1863,6 +1865,8 @@ static void WriteModuleUseLists(const Module *M, ValueEnumerator &VE,
|
||||
WriteUseList(FI, VE, Stream);
|
||||
if (!FI->isDeclaration())
|
||||
WriteFunctionUseList(FI, VE, Stream);
|
||||
if (FI->hasPrefixData())
|
||||
WriteUseList(FI->getPrefixData(), VE, Stream);
|
||||
}
|
||||
|
||||
// Write the aliases.
|
||||
|
@ -60,6 +60,11 @@ ValueEnumerator::ValueEnumerator(const Module *M) {
|
||||
I != E; ++I)
|
||||
EnumerateValue(I->getAliasee());
|
||||
|
||||
// Enumerate the prefix data constants.
|
||||
for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
|
||||
if (I->hasPrefixData())
|
||||
EnumerateValue(I->getPrefixData());
|
||||
|
||||
// Insert constants and metadata that are named at module level into the slot
|
||||
// pool so that the module symbol table can refer to them...
|
||||
EnumerateValueSymbolTable(M->getValueSymbolTable());
|
||||
|
Reference in New Issue
Block a user