summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Bytecode
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-11-05 22:08:14 +0000
committerChris Lattner <sabre@nondot.org>2005-11-05 22:08:14 +0000
commit575e828aa548c7902d983fc350de13538073a8fb (patch)
tree729a71d872fca98d4916364d38fe55550c58ea2b /llvm/lib/Bytecode
parent6ce0ad3f74b31b96a06531df590cdf178c8e40b5 (diff)
downloadbcm5719-llvm-575e828aa548c7902d983fc350de13538073a8fb.tar.gz
bcm5719-llvm-575e828aa548c7902d983fc350de13538073a8fb.zip
Write/read allocation instruction alignment info to .bc files.
llvm-svn: 24203
Diffstat (limited to 'llvm/lib/Bytecode')
-rw-r--r--llvm/lib/Bytecode/Reader/Reader.cpp22
-rw-r--r--llvm/lib/Bytecode/Writer/Writer.cpp7
2 files changed, 21 insertions, 8 deletions
diff --git a/llvm/lib/Bytecode/Reader/Reader.cpp b/llvm/lib/Bytecode/Reader/Reader.cpp
index daf7577cf00..917727098e7 100644
--- a/llvm/lib/Bytecode/Reader/Reader.cpp
+++ b/llvm/lib/Bytecode/Reader/Reader.cpp
@@ -902,27 +902,33 @@ void BytecodeReader::ParseInstruction(std::vector<unsigned> &Oprnds,
if (CallingConv) cast<InvokeInst>(Result)->setCallingConv(CallingConv);
break;
}
- case Instruction::Malloc:
- if (Oprnds.size() > 2)
+ case Instruction::Malloc: {
+ unsigned Align = 0;
+ if (Oprnds.size() == 2)
+ Align = (1 << Oprnds[1]) >> 1;
+ else if (Oprnds.size() > 2)
error("Invalid malloc instruction!");
if (!isa<PointerType>(InstTy))
error("Invalid malloc instruction!");
Result = new MallocInst(cast<PointerType>(InstTy)->getElementType(),
- Oprnds.size() ? getValue(Type::UIntTyID,
- Oprnds[0]) : 0);
+ getValue(Type::UIntTyID, Oprnds[0]), Align);
break;
+ }
- case Instruction::Alloca:
- if (Oprnds.size() > 2)
+ case Instruction::Alloca: {
+ unsigned Align = 0;
+ if (Oprnds.size() == 2)
+ Align = (1 << Oprnds[1]) >> 1;
+ else if (Oprnds.size() > 2)
error("Invalid alloca instruction!");
if (!isa<PointerType>(InstTy))
error("Invalid alloca instruction!");
Result = new AllocaInst(cast<PointerType>(InstTy)->getElementType(),
- Oprnds.size() ? getValue(Type::UIntTyID,
- Oprnds[0]) :0);
+ getValue(Type::UIntTyID, Oprnds[0]), Align);
break;
+ }
case Instruction::Free:
if (!isa<PointerType>(InstTy))
error("Invalid free instruction!");
diff --git a/llvm/lib/Bytecode/Writer/Writer.cpp b/llvm/lib/Bytecode/Writer/Writer.cpp
index b1f2634296f..d3142318280 100644
--- a/llvm/lib/Bytecode/Writer/Writer.cpp
+++ b/llvm/lib/Bytecode/Writer/Writer.cpp
@@ -693,6 +693,13 @@ void BytecodeWriter::outputInstruction(const Instruction &I) {
assert(Slots[1] != ~0U && "Cast return type unknown?");
if (Slots[1] > MaxOpSlot) MaxOpSlot = Slots[1];
NumOperands++;
+ } else if (const AllocationInst *AI = dyn_cast<AllocationInst>(&I)) {
+ assert(NumOperands == 1 && "Bogus allocation!");
+ if (AI->getAlignment()) {
+ Slots[1] = Log2_32(AI->getAlignment())+1;
+ if (Slots[1] > MaxOpSlot) MaxOpSlot = Slots[1];
+ NumOperands = 2;
+ }
} else if (const GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(&I)) {
// We need to encode the type of sequential type indices into their slot #
unsigned Idx = 1;
OpenPOWER on IntegriCloud