[llvm-commits] CVS: llvm/lib/VMCore/AutoUpgrade.cpp
Jim Laskey
jlaskey at apple.com
Thu Mar 23 10:03:31 PST 2006
Changes in directory llvm/lib/VMCore:
AutoUpgrade.cpp updated: 1.14 -> 1.15
---
Log message:
Change the argument types of llvm.dbg intrinsics.
---
Diffs of the changes: (+64 -23)
AutoUpgrade.cpp | 87 +++++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 64 insertions(+), 23 deletions(-)
Index: llvm/lib/VMCore/AutoUpgrade.cpp
diff -u llvm/lib/VMCore/AutoUpgrade.cpp:1.14 llvm/lib/VMCore/AutoUpgrade.cpp:1.15
--- llvm/lib/VMCore/AutoUpgrade.cpp:1.14 Tue Mar 14 13:49:57 2006
+++ llvm/lib/VMCore/AutoUpgrade.cpp Thu Mar 23 12:03:20 2006
@@ -76,30 +76,42 @@
break;
case 'd':
if (Name == "llvm.dbg.stoppoint") {
- if (F->getReturnType() != Type::VoidTy) {
+ PointerType *ESP =
+ PointerType::get(StructType::get(std::vector<const Type*>()));
+ if (F->getReturnType() != Type::VoidTy ||
+ F->getFunctionType()->getParamType(2) != ESP) {
return M->getOrInsertFunction(Name, Type::VoidTy,
- Type::UIntTy,
- Type::UIntTy,
- F->getFunctionType()->getParamType(3),
- NULL);
+ Type::UIntTy, Type::UIntTy, ESP, NULL);
}
} else if (Name == "llvm.dbg.func.start") {
- if (F->getReturnType() != Type::VoidTy) {
- return M->getOrInsertFunction(Name, Type::VoidTy,
- F->getFunctionType()->getParamType(0),
- NULL);
+ PointerType *ESP =
+ PointerType::get(StructType::get(std::vector<const Type*>()));
+ if (F->getReturnType() != Type::VoidTy ||
+ F->getFunctionType()->getParamType(0) != ESP) {
+ return M->getOrInsertFunction(Name, Type::VoidTy, ESP, NULL);
}
} else if (Name == "llvm.dbg.region.start") {
- if (F->getReturnType() != Type::VoidTy) {
- return M->getOrInsertFunction(Name, Type::VoidTy, NULL);
+ PointerType *ESP =
+ PointerType::get(StructType::get(std::vector<const Type*>()));
+ if (F->getReturnType() != Type::VoidTy ||
+ F->getFunctionType()->getParamType(0) != ESP) {
+ return M->getOrInsertFunction(Name, Type::VoidTy, ESP, NULL);
}
} else if (Name == "llvm.dbg.region.end") {
- if (F->getReturnType() != Type::VoidTy) {
- return M->getOrInsertFunction(Name, Type::VoidTy, NULL);
+ PointerType *ESP =
+ PointerType::get(StructType::get(std::vector<const Type*>()));
+ if (F->getReturnType() != Type::VoidTy ||
+ F->getFunctionType()->getParamType(0) != ESP) {
+ return M->getOrInsertFunction(Name, Type::VoidTy, ESP, NULL);
}
} else if (Name == "llvm.dbg.declare") {
- F->setName("");
- return NULL;
+ PointerType *ESP =
+ PointerType::get(StructType::get(std::vector<const Type*>()));
+ if (F->getReturnType() != Type::VoidTy ||
+ F->getFunctionType()->getParamType(0) != ESP ||
+ F->getFunctionType()->getParamType(1) != ESP) {
+ return M->getOrInsertFunction(Name, Type::VoidTy, ESP, ESP, NULL);
+ }
}
break;
case 'i':
@@ -142,8 +154,10 @@
// NULL is returned if there is no permutation. It's assumed that the function
// name is in the form "llvm.?????"
static unsigned *getArgumentPermutation(Function* F) {
- // Get the Function's name.
const std::string& Name = F->getName();
+ const FunctionType *FTy = F->getFunctionType();
+ unsigned N = FTy->getNumParams();
+
switch (Name[5]) {
case 'd':
if (Name == "llvm.dbg.stoppoint") {
@@ -151,7 +165,25 @@
assert(F->getFunctionType()->getNumParams() ==
(sizeof(Permutation) / sizeof(unsigned)) &&
"Permutation is wrong length");
- return Permutation;
+ if (N == 4) return Permutation;
+ } else if (Name == "llvm.dbg.region.start") {
+ static unsigned Permutation[] = { 0 };
+ assert(F->getFunctionType()->getNumParams() ==
+ (sizeof(Permutation) / sizeof(unsigned)) &&
+ "Permutation is wrong length");
+ if (N == 0) return Permutation;
+ } else if (Name == "llvm.dbg.region.end") {
+ static unsigned Permutation[] = { 0 };
+ assert(F->getFunctionType()->getNumParams() ==
+ (sizeof(Permutation) / sizeof(unsigned)) &&
+ "Permutation is wrong length");
+ if (N == 0) return Permutation;
+ } else if (Name == "llvm.dbg.declare") {
+ static unsigned Permutation[] = { 0, 0 };
+ assert(F->getFunctionType()->getNumParams() ==
+ (sizeof(Permutation) / sizeof(unsigned)) &&
+ "Permutation is wrong length");
+ if (N == 0) return Permutation;
}
break;
}
@@ -171,6 +203,15 @@
return 0;
}
+// CastArg - Perform the appropriate cast of an upgraded argument.
+//
+static Value *CastArg(Value *Arg, const Type *Ty) {
+ if (Constant *C = dyn_cast<Constant>(Arg)) {
+ return ConstantExpr::getCast(C, Ty);
+ } else {
+ return new CastInst(Arg, Ty, "autoupgrade_cast");
+ }
+}
Instruction* llvm::MakeUpgradedCall(Function *F,
const std::vector<Value*> &Params,
@@ -187,9 +228,9 @@
const Type* opTy = (*PI)->getType();
if (opTy->isSigned()) {
signedArg = true;
- CastInst* cast =
- new CastInst(*PI,opTy->getUnsignedVersion(), "autoupgrade_cast");
- BB->getInstList().push_back(cast);
+ Value *cast = CastArg(*PI, opTy->getUnsignedVersion());
+ if (Instruction *I = dyn_cast<Instruction>(cast))
+ BB->getInstList().push_back(I);
Oprnds.push_back(cast);
}
else
@@ -218,7 +259,7 @@
const FunctionType *NewFnTy = NewFn->getFunctionType();
std::vector<Value*> Oprnds;
- unsigned *Permutation = getArgumentPermutation(NewFn);
+ unsigned *Permutation = getArgumentPermutation(F);
unsigned N = NewFnTy->getNumParams();
if (Permutation) {
@@ -228,7 +269,7 @@
if (p) {
Value *V = CI->getOperand(p);
if (V->getType() != NewFnTy->getParamType(i))
- V = new CastInst(V, NewFnTy->getParamType(i), V->getName(), CI);
+ V = CastArg(V, NewFnTy->getParamType(i));
Oprnds.push_back(V);
} else
Oprnds.push_back(UndefValue::get(NewFnTy->getParamType(i)));
@@ -239,7 +280,7 @@
for (unsigned i = 0; i != N; ++i) {
Value *V = CI->getOperand(i + 1);
if (V->getType() != NewFnTy->getParamType(i))
- V = new CastInst(V, NewFnTy->getParamType(i), V->getName(), CI);
+ V = CastArg(V, NewFnTy->getParamType(i));
Oprnds.push_back(V);
}
}
More information about the llvm-commits
mailing list