[llvm-commits] [llvm] r105539 - in /llvm/trunk: include/llvm/Instructions.h lib/Analysis/IPA/GlobalsModRef.cpp lib/Target/CppBackend/CPPBackend.cpp lib/Target/MSIL/MSILWriter.cpp
Bill Wendling
isanbard at gmail.com
Mon Jun 7 12:05:06 PDT 2010
Author: void
Date: Mon Jun 7 14:05:06 2010
New Revision: 105539
URL: http://llvm.org/viewvc/llvm-project?rev=105539&view=rev
Log:
Create new accessors to get arguments for call/invoke instructions. It breaks
encapsulation to force the users of these classes to know about the internal
data structure of the Operands structure. It also can lead to errors, like in
the MSIL writer.
Modified:
llvm/trunk/include/llvm/Instructions.h
llvm/trunk/lib/Analysis/IPA/GlobalsModRef.cpp
llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp
llvm/trunk/lib/Target/MSIL/MSILWriter.cpp
Modified: llvm/trunk/include/llvm/Instructions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Instructions.h?rev=105539&r1=105538&r2=105539&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Instructions.h (original)
+++ llvm/trunk/include/llvm/Instructions.h Mon Jun 7 14:05:06 2010
@@ -940,6 +940,9 @@
/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+ unsigned getNumArgOperands() const { return getNumOperands() - 1; }
+ Value *getArgOperand(unsigned i) const { return getOperand(i + 1); }
+
/// getCallingConv/setCallingConv - Get or set the calling convention of this
/// function call.
CallingConv::ID getCallingConv() const {
@@ -2432,6 +2435,9 @@
/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+ unsigned getNumArgOperands() const { return getNumOperands() - 3; }
+ Value *getArgOperand(unsigned i) const { return getOperand(i); }
+
/// getCallingConv/setCallingConv - Get or set the calling convention of this
/// function call.
CallingConv::ID getCallingConv() const {
Modified: llvm/trunk/lib/Analysis/IPA/GlobalsModRef.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/IPA/GlobalsModRef.cpp?rev=105539&r1=105538&r2=105539&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/IPA/GlobalsModRef.cpp (original)
+++ llvm/trunk/lib/Analysis/IPA/GlobalsModRef.cpp Mon Jun 7 14:05:06 2010
@@ -252,13 +252,13 @@
} else if (CallInst *CI = dyn_cast<CallInst>(*UI)) {
// Make sure that this is just the function being called, not that it is
// passing into the function.
- for (unsigned i = 1, e = CI->getNumOperands(); i != e; ++i)
- if (CI->getOperand(i) == V) return true;
+ for (unsigned i = 0, e = CI->getNumArgOperands(); i != e; ++i)
+ if (CI->getArgOperand(i) == V) return true;
} else if (InvokeInst *II = dyn_cast<InvokeInst>(*UI)) {
// Make sure that this is just the function being called, not that it is
// passing into the function.
- for (unsigned i = 0, e = II->getNumOperands() - 3; i != e; ++i)
- if (II->getOperand(i) == V) return true;
+ for (unsigned i = 0, e = II->getNumArgOperands(); i != e; ++i)
+ if (II->getArgOperand(i) == V) return true;
} else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(*UI)) {
if (CE->getOpcode() == Instruction::GetElementPtr ||
CE->getOpcode() == Instruction::BitCast) {
Modified: llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp?rev=105539&r1=105538&r2=105539&view=diff
==============================================================================
--- llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp (original)
+++ llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp Mon Jun 7 14:05:06 2010
@@ -1150,16 +1150,18 @@
const InvokeInst* inv = cast<InvokeInst>(I);
Out << "std::vector<Value*> " << iName << "_params;";
nl(Out);
- for (unsigned i = 0; i < inv->getNumOperands() - 3; ++i) {
+ for (unsigned i = 0; i < inv->getNumArgOperands(); ++i) {
Out << iName << "_params.push_back("
- << opNames[i] << ");";
+ << getOpName(inv->getArgOperand(i)) << ");";
nl(Out);
}
+ // FIXME: This shouldn't use magic numbers -3, -2, and -1.
Out << "InvokeInst *" << iName << " = InvokeInst::Create("
- << opNames[Ops - 3] << ", "
- << opNames[Ops - 2] << ", "
- << opNames[Ops - 1] << ", "
- << iName << "_params.begin(), " << iName << "_params.end(), \"";
+ << getOpName(inv->getCalledFunction()) << ", "
+ << getOpName(inv->getNormalDest()) << ", "
+ << getOpName(inv->getUnwindDest()) << ", "
+ << iName << "_params.begin(), "
+ << iName << "_params.end(), \"";
printEscapedString(inv->getName());
Out << "\", " << bbname << ");";
nl(Out) << iName << "->setCallingConv(";
Modified: llvm/trunk/lib/Target/MSIL/MSILWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/MSIL/MSILWriter.cpp?rev=105539&r1=105538&r2=105539&view=diff
==============================================================================
--- llvm/trunk/lib/Target/MSIL/MSILWriter.cpp (original)
+++ llvm/trunk/lib/Target/MSIL/MSILWriter.cpp Mon Jun 7 14:05:06 2010
@@ -845,10 +845,11 @@
// Handle intrinsic function.
printIntrinsicCall(cast<IntrinsicInst>(Inst));
} else {
+ const CallInst *CI = cast<CallInst>(Inst);
// Load arguments to stack and call function.
- for (int I = 1, E = Inst->getNumOperands(); I!=E; ++I)
- printValueLoad(Inst->getOperand(I));
- printFunctionCall(Inst->getOperand(0),Inst);
+ for (int I = 0, E = CI->getNumArgOperands(); I!=E; ++I)
+ printValueLoad(CI->getArgOperand(I));
+ printFunctionCall(CI->getCalledFunction(), Inst);
}
}
@@ -1002,8 +1003,8 @@
std::string Label = "leave$normal_"+utostr(getUniqID());
Out << ".try {\n";
// Load arguments
- for (int I = 3, E = Inst->getNumOperands(); I!=E; ++I)
- printValueLoad(Inst->getOperand(I));
+ for (int I = 0, E = Inst->getNumArgOperands(); I!=E; ++I)
+ printValueLoad(Inst->getArgOperand(I));
// Print call instruction
printFunctionCall(Inst->getOperand(0),Inst);
// Save function result and leave "try" block
More information about the llvm-commits
mailing list