aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-12-04 21:12:22 -0500
committerAlon Zakai <alonzakai@gmail.com>2013-12-04 21:12:22 -0500
commitc2be06b604f90d31df127ac238ed8905cc9c5b81 (patch)
tree4e4984b3f7d6342849e4562f38eb25cbfa761338
parentc4a784e00fbcb100b47d3568522dda85c60030e8 (diff)
start to finalize legalized data
-rw-r--r--lib/Transforms/NaCl/ExpandI64.cpp41
1 files changed, 32 insertions, 9 deletions
diff --git a/lib/Transforms/NaCl/ExpandI64.cpp b/lib/Transforms/NaCl/ExpandI64.cpp
index fc449fbd6b..ed42a43b81 100644
--- a/lib/Transforms/NaCl/ExpandI64.cpp
+++ b/lib/Transforms/NaCl/ExpandI64.cpp
@@ -49,7 +49,7 @@ namespace {
// This is a ModulePass because the pass recreates functions in
// order to expand i64 arguments to pairs of i32s.
class ExpandI64 : public ModulePass {
- typedef std::vector<Value*> SplitParts;
+ typedef std::vector<Instruction*> SplitParts;
typedef std::map<Instruction*, SplitParts> SplitsMap;
SplitsMap Splits; // old i64 value to new insts
@@ -89,8 +89,8 @@ void ExpandI64::SplitInst(Instruction *I, DataLayout& DL) {
Value *Zero = Constant::getNullValue(T);
Value *Ones = Constant::getAllOnesValue(T);
- Value *Check = CopyDebug(new ICmpInst(I, ICmpInst::ICMP_SLE, Input, Zero), I);
- Value *High = CopyDebug(SelectInst::Create(Check, Ones, Zero, "", I), I);
+ Instruction *Check = CopyDebug(new ICmpInst(I, ICmpInst::ICMP_SLE, Input, Zero), I);
+ Instruction *High = CopyDebug(SelectInst::Create(Check, Ones, Zero, "", I), I);
SplitParts &Split = Splits[I];
Split.push_back(Check);
Split.push_back(High);
@@ -103,12 +103,12 @@ void ExpandI64::SplitInst(Instruction *I, DataLayout& DL) {
Type *I32P = I32->getPointerTo(); // XXX DL->getIntPtrType(I->getContext())
Value *Zero = Constant::getNullValue(I32);
- Value *AI = CopyDebug(new PtrToIntInst(SI->getPointerOperand(), I32, "", I), I);
- Value *P4 = CopyDebug(BinaryOperator::Create(Instruction::Add, AI, ConstantInt::get(I32, 4), "", I), I);
- Value *LP = CopyDebug(new IntToPtrInst(AI, I32P, "", I), I);
- Value *HP = CopyDebug(new IntToPtrInst(P4, I32P, "", I), I);
- Value *SL = CopyDebug(new StoreInst(Zero, LP, I), I); // will be fixed
- Value *SH = CopyDebug(new StoreInst(Zero, HP, I), I); // will be fixed
+ Instruction *AI = CopyDebug(new PtrToIntInst(SI->getPointerOperand(), I32, "", I), I);
+ Instruction *P4 = CopyDebug(BinaryOperator::Create(Instruction::Add, AI, ConstantInt::get(I32, 4), "", I), I);
+ Instruction *LP = CopyDebug(new IntToPtrInst(AI, I32P, "", I), I);
+ Instruction *HP = CopyDebug(new IntToPtrInst(P4, I32P, "", I), I);
+ Instruction *SL = CopyDebug(new StoreInst(Zero, LP, I), I); // will be fixed
+ Instruction *SH = CopyDebug(new StoreInst(Zero, HP, I), I); // will be fixed
SplitParts &Split = Splits[I];
Split.push_back(AI);
Split.push_back(P4);
@@ -122,6 +122,26 @@ void ExpandI64::SplitInst(Instruction *I, DataLayout& DL) {
}
}
+void ExpandI64::FinalizeInst(Instruction *I) {
+ SplitParts &Split = Splits[I];
+ switch (I->getOpcode()) {
+ case Instruction::SExt: {
+ break;
+ }
+ case Instruction::Store: {
+ Instruction *SL = Split[4];
+ Instruction *SH = Split[5];
+
+ Type *I32 = Type::getInt32Ty(I->getContext());
+ Value *Ones = Constant::getAllOnesValue(I32);
+
+ SL->setOperand(0, Ones);
+ SH->setOperand(0, Ones);
+ break;
+ }
+ }
+}
+
bool ExpandI64::runOnModule(Module &M) {
bool Changed = false;
DataLayout DL(&M);
@@ -154,6 +174,9 @@ bool ExpandI64::runOnModule(Module &M) {
// second pass pass - finalize and connect
if (Changed) {
// Finalize each element
+ for (SplitsMap::iterator I = Splits.begin(); I != Splits.end(); I++) {
+ FinalizeInst(I->first);
+ }
// Remove original illegal values
for (SplitsMap::iterator I = Splits.begin(); I != Splits.end(); I++) {