mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-02 07:32:52 +00:00
Flesh out a bit more of the bitcode use-list ordering preservation code.
Nothing too interesting at this point, but comments are welcome. Part of rdar://9860654 and PR5680. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146090 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d1bcf0dbc1
commit
32c5981005
@ -1578,17 +1578,99 @@ static void WriteBlockInfo(const ValueEnumerator &VE, BitstreamWriter &Stream) {
|
||||
Stream.ExitBlock();
|
||||
}
|
||||
|
||||
// Sort the Users based on the order in which the reader parses the bitcode
|
||||
// file.
|
||||
static bool bitcodereader_order(const User *lhs, const User *rhs) {
|
||||
// TODO: Implement.
|
||||
return true;
|
||||
}
|
||||
|
||||
static void WriteUseList(const Value *V, const ValueEnumerator &VE,
|
||||
BitstreamWriter &Stream) {
|
||||
|
||||
// One or zero uses can't get out of order.
|
||||
if (V->use_empty() || V->hasNUses(1))
|
||||
return;
|
||||
|
||||
// Make a copy of the in-memory use-list for sorting.
|
||||
unsigned UseListSize = std::distance(V->use_begin(), V->use_end());
|
||||
SmallVector<const User*, 8> UseList;
|
||||
UseList.reserve(UseListSize);
|
||||
for (Value::const_use_iterator I = V->use_begin(), E = V->use_end();
|
||||
I != E; ++I) {
|
||||
const User *U = *I;
|
||||
UseList.push_back(U);
|
||||
}
|
||||
|
||||
// Sort the copy based on the order read by the BitcodeReader.
|
||||
std::sort(UseList.begin(), UseList.end(), bitcodereader_order);
|
||||
|
||||
// TODO: Generate a diff between the BitcodeWriter in-memory use-list and the
|
||||
// sorted list (i.e., the expected BitcodeReader in-memory use-list).
|
||||
|
||||
// TODO: Emit the USELIST_CODE_ENTRYs.
|
||||
}
|
||||
|
||||
static void WriteFunctionUseList(const Function *F, ValueEnumerator &VE,
|
||||
BitstreamWriter &Stream) {
|
||||
VE.incorporateFunction(*F);
|
||||
|
||||
for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end();
|
||||
AI != AE; ++AI)
|
||||
WriteUseList(AI, VE, Stream);
|
||||
for (Function::const_iterator BB = F->begin(), FE = F->end(); BB != FE;
|
||||
++BB) {
|
||||
WriteUseList(BB, VE, Stream);
|
||||
for (BasicBlock::const_iterator II = BB->begin(), IE = BB->end(); II != IE;
|
||||
++II) {
|
||||
WriteUseList(II, VE, Stream);
|
||||
for (User::const_op_iterator OI = II->op_begin(), E = II->op_end();
|
||||
OI != E; ++OI) {
|
||||
if ((isa<Constant>(*OI) && !isa<GlobalValue>(*OI)) ||
|
||||
isa<InlineAsm>(*OI))
|
||||
WriteUseList(*OI, VE, Stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
VE.purgeFunction();
|
||||
}
|
||||
|
||||
// Emit use-lists.
|
||||
static void WriteModuleUseLists(const Module *M, ValueEnumerator &VE,
|
||||
BitstreamWriter &Stream) {
|
||||
Stream.EnterSubblock(bitc::USELIST_BLOCK_ID, 3);
|
||||
|
||||
// Emit a bogus record for testing purposes.
|
||||
SmallVector<uint64_t, 64> Record;
|
||||
Record.push_back(0);
|
||||
Stream.EmitRecord(bitc::USELIST_CODE_ENTRY, Record);
|
||||
// XXX: this modifies the module, but in a way that should never change the
|
||||
// behavior of any pass or codegen in LLVM. The problem is that GVs may
|
||||
// contain entries in the use_list that do not exist in the Module and are
|
||||
// not stored in the .bc file.
|
||||
for (Module::const_global_iterator I = M->global_begin(), E = M->global_end();
|
||||
I != E; ++I)
|
||||
I->removeDeadConstantUsers();
|
||||
|
||||
// Write the global variables.
|
||||
for (Module::const_global_iterator GI = M->global_begin(),
|
||||
GE = M->global_end(); GI != GE; ++GI) {
|
||||
WriteUseList(GI, VE, Stream);
|
||||
|
||||
// TODO: Tons.
|
||||
// Write the global variable initializers.
|
||||
if (GI->hasInitializer())
|
||||
WriteUseList(GI->getInitializer(), VE, Stream);
|
||||
}
|
||||
|
||||
// Write the functions.
|
||||
for (Module::const_iterator FI = M->begin(), FE = M->end(); FI != FE; ++FI) {
|
||||
WriteUseList(FI, VE, Stream);
|
||||
if (!FI->isDeclaration())
|
||||
WriteFunctionUseList(FI, VE, Stream);
|
||||
}
|
||||
|
||||
// Write the aliases.
|
||||
for (Module::const_alias_iterator AI = M->alias_begin(), AE = M->alias_end();
|
||||
AI != AE; ++AI) {
|
||||
WriteUseList(AI, VE, Stream);
|
||||
WriteUseList(AI->getAliasee(), VE, Stream);
|
||||
}
|
||||
|
||||
Stream.ExitBlock();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user