llvm.org GIT mirror llvm / ce22477
Enabling the target-independent garbage collection infrastructure by hooking it up to the various compiler pipelines. This doesn't actually add support for any GC algorithms, which means it temporarily breaks a few tests. To be fixed shortly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45669 91177308-0d34-0410-b5e6-96231b3b80d8 Gordon Henriksen 12 years ago
7 changed file(s) with 71 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
117117 std::string getCurrentFunctionEHName(const MachineFunction *MF);
118118
119119 protected:
120 /// getAnalysisUsage - Record analysis usage.
121 ///
122 void getAnalysisUsage(AnalysisUsage &AU) const;
123
120124 /// doInitialization - Set up the AsmPrinter when we are working on a new
121125 /// module. If your pass overrides this, it must make sure to explicitly
122126 /// call this implementation.
2929 class TargetLowering;
3030 class FunctionLoweringInfo;
3131 class HazardRecognizer;
32 class CollectorMetadata;
3233
3334 /// SelectionDAGISel - This is the common base class used for SelectionDAG-based
3435 /// pattern-matching instruction selectors.
4142 AliasAnalysis *AA;
4243 std::vector TopOrder;
4344 unsigned DAGSize;
45 CollectorMetadata *GCI;
4446 static char ID;
4547
4648 explicit SelectionDAGISel(TargetLowering &tli) :
47 FunctionPass((intptr_t)&ID), TLI(tli), DAGSize(0) {}
49 FunctionPass((intptr_t)&ID), TLI(tli), DAGSize(0), GCI(0) {}
4850
4951 TargetLowering &getTargetLowering() { return TLI; }
5052
1515 #include "llvm/DerivedTypes.h"
1616 #include "llvm/Constants.h"
1717 #include "llvm/Module.h"
18 #include "llvm/CodeGen/Collector.h"
19 #include "llvm/CodeGen/CollectorMetadata.h"
1820 #include "llvm/CodeGen/MachineConstantPool.h"
1921 #include "llvm/CodeGen/MachineJumpTableInfo.h"
2022 #include "llvm/CodeGen/MachineModuleInfo.h"
9395 }
9496
9597
98 void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
99 MachineFunctionPass::getAnalysisUsage(AU);
100 AU.addRequired();
101 }
102
96103 bool AsmPrinter::doInitialization(Module &M) {
97104 Mang = new Mangler(M, TAI->getGlobalPrefix());
105
106 CollectorModuleMetadata *CMM = getAnalysisToUpdate();
107 assert(CMM && "AsmPrinter didn't require CollectorModuleMetadata?");
108 for (CollectorModuleMetadata::iterator I = CMM->begin(),
109 E = CMM->end(); I != E; ++I)
110 (*I)->beginAssembly(O, *this, *TAI);
98111
99112 if (!M.getModuleInlineAsm().empty())
100113 O << TAI->getCommentString() << " Start of file scope inline assembly\n"
156169 O << "\t.globl\t" << Target << "\n";
157170 }
158171 }
172
173 CollectorModuleMetadata *CMM = getAnalysisToUpdate();
174 assert(CMM && "AsmPrinter didn't require CollectorModuleMetadata?");
175 for (CollectorModuleMetadata::iterator I = CMM->end(),
176 E = CMM->begin(); I != E; )
177 (*--I)->finishAssembly(O, *this, *TAI);
159178
160179 delete Mang; Mang = 0;
161180 return false;
186186 assembly.
187187
188188 //===---------------------------------------------------------------------===//
189
190 It would be good to detect collector/target compatibility instead of silently
191 doing the wrong thing.
192
193 //===---------------------------------------------------------------------===//
2525 #include "llvm/Intrinsics.h"
2626 #include "llvm/IntrinsicInst.h"
2727 #include "llvm/ParameterAttributes.h"
28 #include "llvm/CodeGen/Collector.h"
2829 #include "llvm/CodeGen/MachineFunction.h"
2930 #include "llvm/CodeGen/MachineFrameInfo.h"
3031 #include "llvm/CodeGen/MachineInstrBuilder.h"
425426 /// FuncInfo - Information about the function as a whole.
426427 ///
427428 FunctionLoweringInfo &FuncInfo;
429
430 /// GCI - Garbage collection metadata for the function.
431 CollectorMetadata *GCI;
428432
429433 SelectionDAGLowering(SelectionDAG &dag, TargetLowering &tli,
430434 AliasAnalysis &aa,
431 FunctionLoweringInfo &funcinfo)
435 FunctionLoweringInfo &funcinfo,
436 CollectorMetadata *gci)
432437 : TLI(tli), DAG(dag), TD(DAG.getTarget().getTargetData()), AA(aa),
433 FuncInfo(funcinfo) {
438 FuncInfo(funcinfo), GCI(gci) {
434439 }
435440
436441 /// getRoot - Return the current virtual root of the Selection DAG.
29062911 DAG.setRoot(Tmp.getValue(1));
29072912 return 0;
29082913 }
2914
2915 case Intrinsic::gcroot:
2916 if (GCI) {
2917 Value *Alloca = I.getOperand(1);
2918 Constant *TypeMap = cast(I.getOperand(2));
2919
2920 FrameIndexSDNode *FI = cast(getValue(Alloca).Val);
2921 GCI->addStackRoot(FI->getIndex(), TypeMap);
2922 }
2923 return 0;
2924
2925 case Intrinsic::gcread:
2926 case Intrinsic::gcwrite:
2927 assert(0 && "Collector failed to lower gcread/gcwrite intrinsics!");
2928 return 0;
2929
29092930 case Intrinsic::flt_rounds: {
29102931 setValue(&I, DAG.getNode(ISD::FLT_ROUNDS, MVT::i32));
29112932 return 0;
43674388
43684389 void SelectionDAGISel::getAnalysisUsage(AnalysisUsage &AU) const {
43694390 AU.addRequired();
4391 AU.addRequired();
43704392 AU.setPreservesAll();
43714393 }
43724394
43774399 AA = &getAnalysis();
43784400
43794401 MachineFunction &MF = MachineFunction::construct(&Fn, TLI.getTargetMachine());
4402 if (MF.getFunction()->hasCollector())
4403 GCI = &getAnalysis().get(*MF.getFunction());
4404 else
4405 GCI = 0;
43804406 RegInfo = &MF.getRegInfo();
43814407 DOUT << "\n\n\n=== " << Fn.getName() << "\n";
43824408
45144540 void SelectionDAGISel::BuildSelectionDAG(SelectionDAG &DAG, BasicBlock *LLVMBB,
45154541 std::vector > &PHINodesToUpdate,
45164542 FunctionLoweringInfo &FuncInfo) {
4517 SelectionDAGLowering SDL(DAG, TLI, *AA, FuncInfo);
4543 SelectionDAGLowering SDL(DAG, TLI, *AA, FuncInfo, GCI);
45184544
45194545 std::vector UnorderedChains;
45204546
47734799 if (!BitTestCases[i].Emitted) {
47744800 SelectionDAG HSDAG(TLI, MF, getAnalysisToUpdate());
47754801 CurDAG = &HSDAG;
4776 SelectionDAGLowering HSDL(HSDAG, TLI, *AA, FuncInfo);
4802 SelectionDAGLowering HSDL(HSDAG, TLI, *AA, FuncInfo, GCI);
47774803 // Set the current basic block to the mbb we wish to insert the code into
47784804 BB = BitTestCases[i].Parent;
47794805 HSDL.setCurrentBasicBlock(BB);
47864812 for (unsigned j = 0, ej = BitTestCases[i].Cases.size(); j != ej; ++j) {
47874813 SelectionDAG BSDAG(TLI, MF, getAnalysisToUpdate());
47884814 CurDAG = &BSDAG;
4789 SelectionDAGLowering BSDL(BSDAG, TLI, *AA, FuncInfo);
4815 SelectionDAGLowering BSDL(BSDAG, TLI, *AA, FuncInfo, GCI);
47904816 // Set the current basic block to the mbb we wish to insert the code into
47914817 BB = BitTestCases[i].Cases[j].ThisBB;
47924818 BSDL.setCurrentBasicBlock(BB);
48434869 if (!JTCases[i].first.Emitted) {
48444870 SelectionDAG HSDAG(TLI, MF, getAnalysisToUpdate());
48454871 CurDAG = &HSDAG;
4846 SelectionDAGLowering HSDL(HSDAG, TLI, *AA, FuncInfo);
4872 SelectionDAGLowering HSDL(HSDAG, TLI, *AA, FuncInfo, GCI);
48474873 // Set the current basic block to the mbb we wish to insert the code into
48484874 BB = JTCases[i].first.HeaderBB;
48494875 HSDL.setCurrentBasicBlock(BB);
48554881
48564882 SelectionDAG JSDAG(TLI, MF, getAnalysisToUpdate());
48574883 CurDAG = &JSDAG;
4858 SelectionDAGLowering JSDL(JSDAG, TLI, *AA, FuncInfo);
4884 SelectionDAGLowering JSDL(JSDAG, TLI, *AA, FuncInfo, GCI);
48594885 // Set the current basic block to the mbb we wish to insert the code into
48604886 BB = JTCases[i].second.MBB;
48614887 JSDL.setCurrentBasicBlock(BB);
49034929 for (unsigned i = 0, e = SwitchCases.size(); i != e; ++i) {
49044930 SelectionDAG SDAG(TLI, MF, getAnalysisToUpdate());
49054931 CurDAG = &SDAG;
4906 SelectionDAGLowering SDL(SDAG, TLI, *AA, FuncInfo);
4932 SelectionDAGLowering SDL(SDAG, TLI, *AA, FuncInfo, GCI);
49074933
49084934 // Set the current basic block to the mbb we wish to insert the code into
49094935 BB = SwitchCases[i].ThisBB;
2727 #include "llvm/Analysis/ConstantsScanner.h"
2828 #include "llvm/Analysis/FindUsedTypes.h"
2929 #include "llvm/Analysis/LoopInfo.h"
30 #include "llvm/CodeGen/Passes.h"
3031 #include "llvm/CodeGen/IntrinsicLowering.h"
3132 #include "llvm/Transforms/Scalar.h"
3233 #include "llvm/Target/TargetMachineRegistry.h"
29452946 bool Fast) {
29462947 if (FileType != TargetMachine::AssemblyFile) return true;
29472948
2948 PM.add(createLowerGCPass());
2949 PM.add(createGCLoweringPass());
29492950 PM.add(createLowerAllocationsPass(true));
29502951 PM.add(createLowerInvokePass());
29512952 PM.add(createCFGSimplificationPass()); // clean up after lower invoke.
29522953 PM.add(new CBackendNameAllUsedStructsAndMergeFunctions());
29532954 PM.add(new CWriter(o));
2955 PM.add(createCollectorMetadataDeleter());
29542956 return false;
29552957 }
2323 #include "llvm/Support/MathExtras.h"
2424 #include "llvm/Transforms/Scalar.h"
2525 #include "llvm/ADT/StringExtras.h"
26 #include "llvm/CodeGen/Passes.h"
2627
2728 namespace {
2829 // TargetMachine for the MSIL
16461647 {
16471648 if (FileType != TargetMachine::AssemblyFile) return true;
16481649 MSILWriter* Writer = new MSILWriter(o);
1649 PM.add(createLowerGCPass());
1650 PM.add(createGCLoweringPass());
16501651 PM.add(createLowerAllocationsPass(true));
16511652 // FIXME: Handle switch trougth native IL instruction "switch"
16521653 PM.add(createLowerSwitchPass());
16531654 PM.add(createCFGSimplificationPass());
16541655 PM.add(new MSILModule(Writer->UsedTypes,Writer->TD));
16551656 PM.add(Writer);
1657 PM.add(createCollectorMetadataDeleter());
16561658 return false;
16571659 }