aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Bytecode/Reader
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2006-01-27 11:49:27 +0000
committerReid Spencer <rspencer@reidspencer.com>2006-01-27 11:49:27 +0000
commite2a5fb0e089165f80080c294c1096be4f5739662 (patch)
treec60660fc6f3af672b7f0fafc1816a625beef8fc0 /lib/Bytecode/Reader
parent2f81fb78dc15984af7dbbfc0bb91a63842616c32 (diff)
downloadexternal_llvm-e2a5fb0e089165f80080c294c1096be4f5739662.zip
external_llvm-e2a5fb0e089165f80080c294c1096be4f5739662.tar.gz
external_llvm-e2a5fb0e089165f80080c294c1096be4f5739662.tar.bz2
Fix auto-upgrade of intrinsics to work properly with both assembly and
bytecode reading. This code is crufty, the result of much hacking to get things working correctly. Cleanup patches will follow. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25682 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode/Reader')
-rw-r--r--lib/Bytecode/Reader/Reader.cpp45
-rw-r--r--lib/Bytecode/Reader/Reader.h6
2 files changed, 33 insertions, 18 deletions
diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp
index d142aac..f9ac0ba 100644
--- a/lib/Bytecode/Reader/Reader.cpp
+++ b/lib/Bytecode/Reader/Reader.cpp
@@ -861,7 +861,6 @@ void BytecodeReader::ParseInstruction(std::vector<unsigned> &Oprnds,
Result = new CallInst(F, Params);
if (isTailCall) cast<CallInst>(Result)->setTailCall();
if (CallingConv) cast<CallInst>(Result)->setCallingConv(CallingConv);
- isCall = true;
break;
}
case 56: // Invoke with encoded CC
@@ -1034,13 +1033,6 @@ void BytecodeReader::ParseInstruction(std::vector<unsigned> &Oprnds,
BB->getInstList().push_back(Result);
- if (this->hasUpgradedIntrinsicFunctions && isCall)
- if (Instruction* inst = UpgradeIntrinsicCall(cast<CallInst>(Result))) {
- Result->replaceAllUsesWith(inst);
- Result->eraseFromParent();
- Result = inst;
- }
-
unsigned TypeSlot;
if (Result->getType() == InstTy)
TypeSlot = iType;
@@ -1862,6 +1854,25 @@ void BytecodeReader::ParseFunctionBody(Function* F) {
delete PlaceHolder;
}
+ // If upgraded intrinsic functions were detected during reading of the
+ // module information, then we need to look for instructions that need to
+ // be upgraded. This can't be done while the instructions are read in because
+ // additional instructions inserted mess up the slot numbering.
+ if (!upgradedFunctions.empty()) {
+ for (Function::iterator BI = F->begin(), BE = F->end(); BI != BE; ++BI)
+ for (BasicBlock::iterator II = BI->begin(), IE = BI->end();
+ II != IE; ++II)
+ if (CallInst* CI = dyn_cast<CallInst>(II)) {
+ std::map<Function*,Function*>::iterator FI =
+ upgradedFunctions.find(CI->getCalledFunction());
+ if (FI != upgradedFunctions.end()) {
+ Instruction* newI = UpgradeIntrinsicCall(CI,FI->second);
+ CI->replaceAllUsesWith(newI);
+ CI->eraseFromParent();
+ }
+ }
+ }
+
// Clear out function-level types...
FunctionTypes.clear();
CompactionTypes.clear();
@@ -1937,6 +1948,7 @@ void BytecodeReader::ParseAllFunctionBodies() {
++Fi;
}
LazyFunctionLoadMap.clear();
+
}
/// Parse the global type list
@@ -2055,13 +2067,6 @@ void BytecodeReader::ParseModuleGlobalInfo() {
Function *Func = new Function(FTy, GlobalValue::ExternalLinkage,
"", TheModule);
- // Replace with upgraded intrinsic function, if applicable.
- if (Function* upgrdF = UpgradeIntrinsicFunction(Func)) {
- hasUpgradedIntrinsicFunctions = true;
- Func->eraseFromParent();
- Func = upgrdF;
- }
-
insertValue(Func, (FnSignature & (~0U >> 1)) >> 5, ModuleValues);
// Flags are not used yet.
@@ -2433,6 +2438,16 @@ void BytecodeReader::ParseBytecode(BufPtr Buf, unsigned Length,
if (hasFunctions())
error("Function expected, but bytecode stream ended!");
+ // Look for intrinsic functions to upgrade, upgrade them, and save the
+ // mapping from old function to new for use later when instructions are
+ // converted.
+ for (Module::iterator FI = TheModule->begin(), FE = TheModule->end();
+ FI != FE; ++FI)
+ if (Function* newF = UpgradeIntrinsicFunction(FI)) {
+ upgradedFunctions.insert(std::make_pair(FI,newF));
+ FI->setName("");
+ }
+
// Tell the handler we're done with the module
if (Handler)
Handler->handleModuleEnd(ModuleID);
diff --git a/lib/Bytecode/Reader/Reader.h b/lib/Bytecode/Reader/Reader.h
index 21eb846..ffc251b 100644
--- a/lib/Bytecode/Reader/Reader.h
+++ b/lib/Bytecode/Reader/Reader.h
@@ -323,9 +323,9 @@ private:
/// In release 1.7 we changed intrinsic functions to not be overloaded. There
/// is no bytecode change for this, but to optimize the auto-upgrade of calls
- /// to intrinsic functions, we set this flag to identify when a module has
- /// been read that contains intrinsics that were upgraded.
- bool hasUpgradedIntrinsicFunctions;
+ /// to intrinsic functions, we save a mapping of old function definitions to
+ /// the new ones so call instructions can be upgraded efficiently.
+ std::map<Function*,Function*> upgradedFunctions;
/// CompactionTypes - If a compaction table is active in the current function,
/// this is the mapping that it contains. We keep track of what resolved type