[llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Wed Jul 7 22:21:01 PDT 2004
Changes in directory reopt/lib/TraceToFunction:
TraceToFunction.cpp updated: 1.72 -> 1.73
---
Log message:
Restructure TraceFn so that instead of having arguments
({ ...live outs... } *liveOut, ...live ins...)
it now has
(...live ins..., ...pointers to live outs...)
createLiveOutType is history.
Also, now we only have to generate store instructions, not gep-store pairs.
This is loosely modelled after the code extractor.
---
Diffs of the changes: (+55 -67)
Index: reopt/lib/TraceToFunction/TraceToFunction.cpp
diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.72 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.73
--- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.72 Wed Jul 7 14:11:25 2004
+++ reopt/lib/TraceToFunction/TraceToFunction.cpp Wed Jul 7 22:19:58 2004
@@ -68,9 +68,11 @@
void threadFLIEdges (Function *F);
void buildFLIMap (Trace &T, FLIMapTy &FLIMap);
- TypeVector createFunctionArgTypeVector (PointerType *ST,
- const LiveVariableVector &S);
- void giveNamesToFunctionArgs (LiveVariableVector LVV, Function *F);
+ TypeVector createFunctionArgTypeVector (const LiveVariableVector &LiveIns,
+ const LiveVariableVector &LiveOuts);
+ void giveNamesToFunctionArgs (const LiveVariableVector &LiveIns,
+ const LiveVariableVector &LiveOuts,
+ Function *F);
void fillInFunctionBody (Trace &T, Function *F, LiveVariableVector &So);
int findOffTracePhiSource (const PHINode *newPN);
void fixupFunctionBodyBB (Trace &T, Function *F, BasicBlock *srcB,
@@ -281,72 +283,70 @@
return NULL;
}
-/// createLiveOutType - Given the live-out set S of a trace, create a
-/// pointer-to-structure type that will encapsulate all the live-outs from S.
+/// createFunctionArgTypeVector - Given the live-in and live-out vectors of a
+/// trace, create a parameter list containing a parameter for each of the
+/// variables in LiveIns and a parameter for a pointer to each of the
+/// variables in LiveOuts.
///
-static PointerType *createLiveOutType (const LiveVariableVector &LVV) {
- TypeVector T;
- unsigned Counter = 0;
- // For each variable in S, make a new entry in T having its type.
- DEBUG (std::cerr << "Live-out values:\n");
- for (LiveVariableVector::const_iterator I = LVV.begin (), E = LVV.end ();
- I != E; ++I) {
- DEBUG (WriteAsOperand (std::cerr, *I, true, true,
- cast<Instruction>(*I)->getParent ()->getParent ()
- ->getParent ());
- std::cerr << " is at position " << Counter++ << "\n");
- T.push_back ((*I)->getType ());
- }
- return PointerType::get (StructType::get (T));
-}
-
-/// createFunctionArgTypeVector - Given the live-in vector LVV of a trace,
-/// create a parameter list containing a parameter for each of the
-/// variables in LVV as well as a pointer-to-structure type PST to fill
-/// in which contains the live-outs.
-///
-TypeVector TraceFunctionBuilder::createFunctionArgTypeVector (PointerType *PST,
- const LiveVariableVector &LVV) {
+TypeVector TraceFunctionBuilder::createFunctionArgTypeVector (const LiveVariableVector &LiveIns, const LiveVariableVector &LiveOuts) {
TypeVector P;
- P.push_back (PST);
- for (LiveVariableVector::const_iterator I = LVV.begin (), E = LVV.end ();
- I != E; ++I)
+ for (LiveVariableVector::const_iterator I = LiveIns.begin (),
+ E = LiveIns.end (); I != E; ++I)
P.push_back ((*I)->getType ());
+ for (LiveVariableVector::const_iterator I = LiveOuts.begin (),
+ E = LiveOuts.end (); I != E; ++I)
+ P.push_back (PointerType::get ((*I)->getType ()));
return P;
}
-/// giveNamesToFunctionArgs - Name the first argument of F "liveOut",
-/// then name the remaining arguments of F according to LVV. As a
-/// side effect, fills in the mapping between live-ins and arguments in
-/// TF->LiveInToArgMap.
+/// giveNamesToFunctionArgs - Name the beginning arguments of F according to
+/// LiveIns, and name the remainder according to LiveOuts. As a side effect,
+/// fills in the mapping between live-ins and arguments in TF->LiveInToArgMap,
+/// and the mapping between live-outs and arguments in TF->LiveOutToArgMap.
///
-void TraceFunctionBuilder::giveNamesToFunctionArgs (LiveVariableVector LVV,
- Function *F) {
+void TraceFunctionBuilder::giveNamesToFunctionArgs (const LiveVariableVector &LiveIns, const LiveVariableVector &LiveOuts, Function *F) {
Function::aiterator argIterator = F->abegin ();
unsigned argPosition = 0;
- argIterator->setName ("liveOut"); // Arg 0 is always the live-out struct.
- ++argPosition;
- ++argIterator;
-
// Fill in & print out mapping of instructions producing live-ins to
// args, and set arg names.
- std::cerr << "\nLive-in values:\n";
- for (LiveVariableVector::iterator I = LVV.begin (), E = LVV.end (); I != E;
- ++I) {
+ DEBUG (std::cerr << "\nLive-in values:\n");
+ for (LiveVariableVector::const_iterator I = LiveIns.begin (),
+ E = LiveIns.end (); I != E; ++I) {
Value *V = *I;
- WriteAsOperand (std::cerr, *I, true, true, TF->MatrixFn->getParent ());
- std::cerr << " is argument # " << argPosition << " (%";
+ DEBUG (WriteAsOperand (std::cerr, V, true, true,
+ TF->MatrixFn->getParent ());
+ std::cerr << " is argument # " << argPosition << " (%");
TF->LiveInToArgMap[V] = &*argIterator;
-
std::string name (V->getName ());
if (name == "")
name = "arg" + utostr (argPosition);
argIterator->setName ("liveIn." + name);
- std::cerr << argIterator->getName () << ")\n";
+ DEBUG (std::cerr << argIterator->getName () << ")\n");
+ ++argPosition;
+ ++argIterator;
+ }
+ DEBUG (std::cerr << "\n");
+
+ // Fill in & print out mapping of instructions producing live-outs to
+ // args, and set arg names.
+ DEBUG (std::cerr << "\nLive-out values:\n");
+ for (LiveVariableVector::const_iterator I = LiveOuts.begin (),
+ E = LiveOuts.end (); I != E; ++I) {
+ Value *V = *I;
+ DEBUG (WriteAsOperand (std::cerr, V, true, true,
+ TF->MatrixFn->getParent ());
+ std::cerr << " is argument # " << argPosition << " (%");
+ TF->LiveOutToArgMap[V] = &*argIterator;
+ std::string name (V->getName ());
+ if (name == "")
+ name = "arg" + utostr (argPosition);
+ argIterator->setName ("liveOut." + name);
+ DEBUG (std::cerr << argIterator->getName () << ")\n");
++argPosition;
++argIterator;
}
+ DEBUG (std::cerr << "\n");
}
/// numberExitBranchesInTrace - Fill in M with pairs that map each
@@ -720,23 +720,12 @@
TF->ReturnBlockForTraceExit[FB] = successor;
// Add the getelementptr/store instruction pairs here that
// correspond to each live-out variable.
- unsigned Slot = 0;
for (LiveVariableVector::iterator SI = So.begin (), SE = So.end ();
- SI != SE; ++SI) {
+ SI != SE; ++SI)
if (dominates (T, cast<Instruction> ((*SI))->getParent (),
- BI->getParent ())) {
- std::vector<Value *> Index;
- Index.push_back (Constant::getNullValue (Type::LongTy)); //long 0
- Index.push_back (ConstantUInt::get (Type::UIntTy, Slot));//uint Slot
- GetElementPtrInst *GEP =
- new GetElementPtrInst (&*F->abegin (), Index,
- "liveOutP" + utostr (BranchNumber[BI])
- + "_" + utostr (i) + "_" + utostr (Slot));
- FB->getInstList ().push_back (GEP);
- FB->getInstList ().push_back (new StoreInst (O2CMap[*SI], GEP));
- }
- ++Slot;
- }
+ BI->getParent ()))
+ FB->getInstList ().push_back
+ (new StoreInst (O2CMap[*SI], TF->LiveOutToArgMap[*SI]));
// Make FB contain a return instruction that returns the
// number of the taken exit-branch. Add it to the end of FB:
FB->getInstList ().push_back
@@ -838,9 +827,8 @@
// function.
getTraceLiveInSet (LiveInSet, TF->LiveInVector, T);
getTraceLiveOutSet (LiveOutSet, TF->LiveOutVector, T);
- TypeVector P =
- createFunctionArgTypeVector (createLiveOutType (TF->LiveOutVector),
- TF->LiveInVector);
+ TypeVector P = createFunctionArgTypeVector (TF->LiveInVector,
+ TF->LiveOutVector);
// Make a new internal Function with return type int and parameter
// list P, in the same Module as the trace's parent function.
@@ -848,7 +836,7 @@
TF->TraceFn = new Function (FunctionType::get (Type::UIntTy, P, false),
GlobalValue::InternalLinkage, name,
T.getModule ());
- giveNamesToFunctionArgs (TF->LiveInVector, TF->TraceFn);
+ giveNamesToFunctionArgs (TF->LiveInVector, TF->LiveOutVector, TF->TraceFn);
fillInFunctionBody (T, TF->TraceFn, TF->LiveOutVector);
return TF;
}
More information about the llvm-commits
mailing list